mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-10 23:02:03 +00:00
- made some adjustments to the RFS parser for the file system.
It's still not active but now should produce correct results when working inside the file system. What it is missing is a file scanner that picks the data it needs to process.
This commit is contained in:
parent
c54ae1be83
commit
f44d309558
4 changed files with 36 additions and 75 deletions
|
@ -32,6 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#include "misc.h"
|
||||
#include "globals.h"
|
||||
#include "sound.h"
|
||||
#include "filesystem/resourcefile.h"
|
||||
|
||||
BEGIN_BLD_NS
|
||||
|
||||
|
@ -61,8 +62,7 @@ struct define_t
|
|||
|
||||
define_t gCmdDefines[kMaxCmdLineDefines];
|
||||
|
||||
void sub_11DF0(char *fileName, char flags, int ID);
|
||||
void sub_11C10(char *pzScriptDir, char *fileName, char flags, int ID);
|
||||
void addMemoryResource(char *fileName, char flags, int ID);
|
||||
|
||||
struct tag_t {
|
||||
const char *_value;
|
||||
|
@ -609,8 +609,15 @@ void ParseScript(const char *scriptFileName)
|
|||
break;
|
||||
}
|
||||
|
||||
if (dword_44CE0[gParseLevel] == 0) {
|
||||
sub_11C10(zScriptDirectory, inp, nFlags, ID);
|
||||
if (dword_44CE0[gParseLevel] == 0)
|
||||
{
|
||||
// In the RFS files I have seen the outermost directory is not part of what goes into the file system.
|
||||
auto inp1 = strchr(inp, '\\');
|
||||
if (!inp1 || !fileSystem.CreatePathlessCopy(inp1 + 1, ID, nFlags))
|
||||
{
|
||||
// I'll activate this when I find evidence that it is needed. Otherwise the risk of picking up unwanted data is too high.
|
||||
//fileSystem.CreatePathlessCopy(inp, ID, nFlags);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -868,7 +875,7 @@ void ParseScript(const char *scriptFileName)
|
|||
else
|
||||
{
|
||||
if (dword_44CE0[gParseLevel] == 0) {
|
||||
sub_11DF0(fileName, nFlags, ID);
|
||||
addMemoryResource(fileName, nFlags, ID);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -880,65 +887,15 @@ void ParseScript(const char *scriptFileName)
|
|||
rfs.Close();
|
||||
}
|
||||
|
||||
void sub_11C10(char *pzScriptDir, char *fileName, char flags, int ID)
|
||||
void addMemoryResource(char *filePath, char flags, int ID)
|
||||
{
|
||||
#if 0 // This needs a more sophisticated approach inside the file system backend if it ever gets activated
|
||||
char zDirectory[BMAX_PATH];
|
||||
char zFilename[BMAX_PATH];
|
||||
char zType[BMAX_PATH];
|
||||
BDIR* dirr;
|
||||
struct Bdirent* dirent;
|
||||
dirr = Bopendir("./");
|
||||
if (dirr)
|
||||
{
|
||||
while ((dirent = Breaddir(dirr)))
|
||||
{
|
||||
if (!Bwildmatch(dirent->name, fileName))
|
||||
continue;
|
||||
|
||||
SplitPath(dirent->name, zDirectory, zFilename, zType);
|
||||
|
||||
if (!Bstrcasecmp(zType, "RAW") || !Bstrcasecmp(zType, "SFX") || !Bstrcasecmp(zType, "MID") || !Bstrcasecmp(zType, "TMB"))
|
||||
gSoundRes.AddExternalResource(zFilename, zType, ID, flags, dirent->name);
|
||||
else
|
||||
gSysRes.AddExternalResource(zFilename, zType, ID, flags, dirent->name);
|
||||
}
|
||||
Bclosedir(dirr);
|
||||
}
|
||||
dirr = Bopendir(pzScriptDir);
|
||||
if (dirr)
|
||||
{
|
||||
while ((dirent = Breaddir(dirr)))
|
||||
{
|
||||
if (!Bwildmatch(dirent->name, fileName))
|
||||
continue;
|
||||
|
||||
SplitPath(dirent->name, zDirectory, zFilename, zType);
|
||||
|
||||
if (!Bstrcasecmp(zType, "RAW") || !Bstrcasecmp(zType, "SFX") || !Bstrcasecmp(zType, "MID") || !Bstrcasecmp(zType, "TMB"))
|
||||
gSoundRes.AddExternalResource(zFilename, zType, ID, flags, dirent->name);
|
||||
else
|
||||
gSysRes.AddExternalResource(zFilename, zType, ID, flags, dirent->name);
|
||||
}
|
||||
Bclosedir(dirr);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void sub_11DF0(char *filePath, char flags, int ID)
|
||||
{
|
||||
#if 0 // This needs a more sophisticated approach inside the file system backend if it ever gets activated
|
||||
char zDirectory[BMAX_PATH];
|
||||
char zFilename[BMAX_PATH];
|
||||
char zType[BMAX_PATH];
|
||||
|
||||
SplitPath(filePath, zDirectory, zFilename, zType);
|
||||
|
||||
if (!Bstrcasecmp(zType, "RAW") || !Bstrcasecmp(zType, "SFX") || !Bstrcasecmp(zType, "MID") || !Bstrcasecmp(zType, "TMB"))
|
||||
gSoundRes.AddFromBuffer(zFilename, zType, buffer, nBytes, ID, flags);
|
||||
else
|
||||
gSysRes.AddFromBuffer(zFilename, zType, buffer, nBytes, ID, flags);
|
||||
#endif
|
||||
fileSystem.AddFromBuffer(zFilename, zType, buffer, nBytes, ID, flags);
|
||||
}
|
||||
|
||||
END_BLD_NS
|
||||
|
|
|
@ -1856,7 +1856,8 @@ static int parsedefinitions_game(scriptfile *pScript, int firstPass)
|
|||
|
||||
if (!firstPass)
|
||||
{
|
||||
gSysRes.AddExternalResource(resName, resType, resID);
|
||||
FStringf name("%s.%s", resName, resType);
|
||||
fileSystem.CreatePathlessCopy(resName, resID, 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -911,36 +911,39 @@ FResourceLump *FileSystem::Lookup(unsigned int id, const char *type)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
void FileSystem::AddExternalResource(const char *name, const char *type, int id, int flags, const char *pzDirectory)
|
||||
bool FileSystem::CreatePathlessCopy(const char *name, int id, int flags)
|
||||
{
|
||||
FString name2, type2, filename, path;
|
||||
|
||||
if (strlen(type) > 0)
|
||||
filename.Format("%s.%s", name, type);
|
||||
else
|
||||
filename.Format("%s", name);
|
||||
|
||||
if (pzDirectory)
|
||||
path.Format("%s/%s", pzDirectory, filename);
|
||||
else
|
||||
path = filename;
|
||||
FString name2, type2, path;
|
||||
|
||||
// The old code said 'filename' and ignored the path, this looked like a bug.
|
||||
auto lump = FindFile(path);
|
||||
if (lump < 0) return; // Does not exist.
|
||||
auto lump = FindFile(name);
|
||||
if (lump < 0) return false; // Does not exist.
|
||||
|
||||
auto oldlump = FileInfo[lump].lump;
|
||||
FName filename = oldlump->LumpName[FResourceLump::BaseNameType];
|
||||
FName fullname = oldlump->LumpName[FResourceLump::FullNameType];
|
||||
|
||||
// If the lump we are about to add already got the right properties, do nothing, aside from loading/locking as requested
|
||||
if (filename == fullname && (id == 0 || id == oldlump->ResourceId))
|
||||
{
|
||||
if (flags & DICT_LOCK) oldlump->Lock();
|
||||
else if (flags & DICT_LOAD) oldlump->Get();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if a lump with this name already exists.
|
||||
// Blood does not allow re-replacing external resources.
|
||||
auto prevlump = FindFile(filename);
|
||||
if (prevlump >= 0 && FileInfo[prevlump].rfnum == -1) return;
|
||||
if (prevlump >= 0 && FileInfo[prevlump].rfnum == -1) return true;
|
||||
|
||||
// Create a clone of the resource to give it new lookup properties.
|
||||
auto newlump = new FClonedLump(FileInfo[lump].lump);
|
||||
newlump->LumpNameSetup(filename);
|
||||
newlump->LumpNameSetup(filename.GetChars());
|
||||
newlump->ResourceId = id;
|
||||
if (flags & DICT_LOCK) newlump->Lock();
|
||||
else if (flags & DICT_LOAD) newlump->Get();
|
||||
AddLump(newlump);
|
||||
return true;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
|
@ -123,7 +123,7 @@ public:
|
|||
static const void *Load(FResourceLump *lump);
|
||||
FResourceLump *Lookup(const char *name, const char *type);
|
||||
FResourceLump *Lookup(unsigned int id, const char *type);
|
||||
void AddExternalResource(const char *name, const char *type, int id, int flags = 0, const char *pzDirectory = nullptr);
|
||||
bool CreatePathlessCopy(const char *name, int id, int flags);
|
||||
|
||||
FileReader OpenFileReader(int file); // opens a reader that redirects to the containing file's one.
|
||||
FileReader ReopenFileReader(int file, bool alwayscache = false); // opens an independent reader.
|
||||
|
|
Loading…
Reference in a new issue