From b7f952ad802f1dc2aeadc2319457b1c3b064379b Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Mon, 10 Jan 2022 23:22:26 +0100 Subject: [PATCH] Extended idFileSystem::ListFilesTree to recursive .resources files --- neo/framework/Common_localize.cpp | 2 +- neo/framework/DeclManager.cpp | 2 +- neo/framework/FileSystem.cpp | 44 ++++++++++++++++--------------- neo/framework/FileSystem.h | 29 +++++++++++++++++++- 4 files changed, 53 insertions(+), 24 deletions(-) diff --git a/neo/framework/Common_localize.cpp b/neo/framework/Common_localize.cpp index e18d5429..c5e00227 100644 --- a/neo/framework/Common_localize.cpp +++ b/neo/framework/Common_localize.cpp @@ -430,7 +430,7 @@ CONSOLE_COMMAND( localizeGuis, "localize guis", NULL ) } else { - files = fileSystem->ListFilesTree( "guis", "*.pd", true, "d3xp" ); + files = fileSystem->ListFilesTree( "guis", "*.pd", true, false, "d3xp" ); } for( int i = 0; i < files->GetNumFiles(); i++ ) diff --git a/neo/framework/DeclManager.cpp b/neo/framework/DeclManager.cpp index 4e903df9..2d9f4026 100644 --- a/neo/framework/DeclManager.cpp +++ b/neo/framework/DeclManager.cpp @@ -2765,7 +2765,7 @@ void idDeclManagerLocal::ExportModelsToTrenchBroom_f( const idCmdArgs& args ) int totalModelsCount = 0; - idFileList* files = fileSystem->ListFilesTree( "generated", ".blwo|.base|.bmd5mesh", true ); + idFileList* files = fileSystem->ListFilesTree( "generated", ".blwo|.base|.bmd5mesh", true, true ); for( int f = 0; f < files->GetList().Num(); f++ ) { diff --git a/neo/framework/FileSystem.cpp b/neo/framework/FileSystem.cpp index bef7166c..ebd56dc9 100644 --- a/neo/framework/FileSystem.cpp +++ b/neo/framework/FileSystem.cpp @@ -136,7 +136,7 @@ public: virtual void Shutdown( bool reloading ); virtual bool IsInitialized() const; virtual idFileList* ListFiles( const char* relativePath, const char* extension, bool sort = false, bool fullRelativePath = false, const char* gamedir = NULL ); - virtual idFileList* ListFilesTree( const char* relativePath, const char* extension, bool sort = false, const char* gamedir = NULL ); + virtual idFileList* ListFilesTree( const char* relativePath, const char* extension, bool sort = false, bool allowSubdirsForResourcePaks = false, const char* gamedir = NULL ); virtual void FreeFileList( idFileList* fileList ); virtual const char* OSPathToRelativePath( const char* OSPath ); virtual const char* RelativePathToOSPath( const char* relativePath, const char* basePath ); @@ -279,9 +279,10 @@ private: void CopyFile( idFile* src, const char* toOSPath ); int AddUnique( const char* name, idStrList& list, idHashIndex& hashIndex ) const; void GetExtensionList( const char* extension, idStrList& extensionList ) const; - int GetFileList( const char* relativePath, const idStrList& extensions, idStrList& list, idHashIndex& hashIndex, bool fullRelativePath, const char* gamedir = NULL ); - int GetFileListTree( const char* relativePath, const idStrList& extensions, idStrList& list, idHashIndex& hashIndex, const char* gamedir = NULL ); + // RB: added bool allowSubdirsForResourcePaks + int GetFileList( const char* relativePath, const idStrList& extensions, idStrList& list, idHashIndex& hashIndex, bool fullRelativePath, bool allowSubdirsForResourcePaks = false, const char* gamedir = NULL ); + int GetFileListTree( const char* relativePath, const idStrList& extensions, idStrList& list, idHashIndex& hashIndex, bool allowSubdirsForResourcePaks = false, const char* gamedir = NULL ); void AddGameDirectory( const char* path, const char* dir ); int AddResourceFile( const char* resourceFileName ); @@ -2225,7 +2226,7 @@ Does not clear the list first so this can be used to progressively build a file When 'sort' is true only the new files added to the list are sorted. =============== */ -int idFileSystemLocal::GetFileList( const char* relativePath, const idStrList& extensions, idStrList& list, idHashIndex& hashIndex, bool fullRelativePath, const char* gamedir ) +int idFileSystemLocal::GetFileList( const char* relativePath, const idStrList& extensions, idStrList& list, idHashIndex& hashIndex, bool fullRelativePath, bool allowSubdirsForResourcePaks, const char* gamedir ) { if( !IsInitialized() ) { @@ -2279,21 +2280,22 @@ int idFileSystemLocal::GetFileList( const char* relativePath, const idStrList& e // make sure the file is not in a subdirectory int j = pathLength; - // RB: FIXME expose this to an option for exportModelsToTrenchBroom + // RB: expose this to an option for exportModelsToTrenchBroom // so it doesn't break loading of sounds -#if 1 - for( ; rt.filename[j + 1] != '\0'; j++ ) + if( !allowSubdirsForResourcePaks ) { - if( rt.filename[ j ] == '/' ) + for( ; rt.filename[j + 1] != '\0'; j++ ) { - break; + if( rt.filename[ j ] == '/' ) + { + break; + } + } + if( rt.filename[ j + 1 ] ) + { + continue; } } - if( rt.filename[ j + 1 ] ) - { - continue; - } -#endif // check for extension match for( j = 0; j < extensions.Num(); j++ ) @@ -2391,7 +2393,7 @@ idFileList* idFileSystemLocal::ListFiles( const char* relativePath, const char* GetExtensionList( extension, extensionList ); - GetFileList( relativePath, extensionList, fileList->list, hashIndex, fullRelativePath, gamedir ); + GetFileList( relativePath, extensionList, fileList->list, hashIndex, fullRelativePath, false, gamedir ); if( sort ) { @@ -2406,7 +2408,7 @@ idFileList* idFileSystemLocal::ListFiles( const char* relativePath, const char* idFileSystemLocal::GetFileListTree =============== */ -int idFileSystemLocal::GetFileListTree( const char* relativePath, const idStrList& extensions, idStrList& list, idHashIndex& hashIndex, const char* gamedir ) +int idFileSystemLocal::GetFileListTree( const char* relativePath, const idStrList& extensions, idStrList& list, idHashIndex& hashIndex, bool allowSubdirsForResourcePaks, const char* gamedir ) { int i; idStrList slash, folders( 128 ); @@ -2414,7 +2416,7 @@ int idFileSystemLocal::GetFileListTree( const char* relativePath, const idStrLis // recurse through the subdirectories slash.Append( "/" ); - GetFileList( relativePath, slash, folders, folderHashIndex, true, gamedir ); + GetFileList( relativePath, slash, folders, folderHashIndex, true, allowSubdirsForResourcePaks, gamedir ); for( i = 0; i < folders.Num(); i++ ) { if( folders[i][0] == '.' ) @@ -2425,11 +2427,11 @@ int idFileSystemLocal::GetFileListTree( const char* relativePath, const idStrLis { continue; } - GetFileListTree( folders[i], extensions, list, hashIndex, gamedir ); + GetFileListTree( folders[i], extensions, list, hashIndex, allowSubdirsForResourcePaks, gamedir ); } // list files in the current directory - GetFileList( relativePath, extensions, list, hashIndex, true, gamedir ); + GetFileList( relativePath, extensions, list, hashIndex, true, allowSubdirsForResourcePaks, gamedir ); return list.Num(); } @@ -2439,7 +2441,7 @@ int idFileSystemLocal::GetFileListTree( const char* relativePath, const idStrLis idFileSystemLocal::ListFilesTree =============== */ -idFileList* idFileSystemLocal::ListFilesTree( const char* relativePath, const char* extension, bool sort, const char* gamedir ) +idFileList* idFileSystemLocal::ListFilesTree( const char* relativePath, const char* extension, bool sort, bool allowSubdirsForResourcePaks, const char* gamedir ) { idHashIndex hashIndex( 4096, 4096 ); idStrList extensionList; @@ -2450,7 +2452,7 @@ idFileList* idFileSystemLocal::ListFilesTree( const char* relativePath, const ch GetExtensionList( extension, extensionList ); - GetFileListTree( relativePath, extensionList, fileList->list, hashIndex, gamedir ); + GetFileListTree( relativePath, extensionList, fileList->list, hashIndex, allowSubdirsForResourcePaks, gamedir ); if( sort ) { diff --git a/neo/framework/FileSystem.h b/neo/framework/FileSystem.h index bdf8a4b3..8798fd74 100644 --- a/neo/framework/FileSystem.h +++ b/neo/framework/FileSystem.h @@ -98,36 +98,48 @@ class idFileSystem { public: virtual ~idFileSystem() {} + // Initializes the file system. virtual void Init() = 0; + // Restarts the file system. virtual void Restart() = 0; + // Shutdown the file system. virtual void Shutdown( bool reloading ) = 0; + // Returns true if the file system is initialized. virtual bool IsInitialized() const = 0; + // Lists files with the given extension in the given directory. // Directory should not have either a leading or trailing '/' // The returned files will not include any directories or '/' unless fullRelativePath is set. // The extension must include a leading dot and may not contain wildcards. // If extension is "/", only subdirectories will be returned. virtual idFileList* ListFiles( const char* relativePath, const char* extension, bool sort = false, bool fullRelativePath = false, const char* gamedir = NULL ) = 0; + // Lists files in the given directory and all subdirectories with the given extension. // Directory should not have either a leading or trailing '/' // The returned files include a full relative path. // The extension must include a leading dot and may not contain wildcards. - virtual idFileList* ListFilesTree( const char* relativePath, const char* extension, bool sort = false, const char* gamedir = NULL ) = 0; + virtual idFileList* ListFilesTree( const char* relativePath, const char* extension, bool sort = false, bool allowSubdirsForResourcePaks = false, const char* gamedir = NULL ) = 0; + // Frees the given file list. virtual void FreeFileList( idFileList* fileList ) = 0; + // Converts a relative path to a full OS path. virtual const char* OSPathToRelativePath( const char* OSPath ) = 0; + // Converts a full OS path to a relative path. virtual const char* RelativePathToOSPath( const char* relativePath, const char* basePath = "fs_basepath" ) = 0; + // Builds a full OS path from the given components. virtual const char* BuildOSPath( const char* base, const char* game, const char* relativePath ) = 0; virtual const char* BuildOSPath( const char* base, const char* relativePath ) = 0; + // Creates the given OS path for as far as it doesn't exist already. virtual void CreateOSPath( const char* OSPath ) = 0; + // Reads a complete file. // Returns the length of the file, or -1 on failure. // A null buffer will just return the file length without loading. @@ -136,35 +148,50 @@ public: // A 0 byte will always be appended at the end, so string ops are safe. // The buffer should be considered read-only, because it may be cached for other uses. virtual int ReadFile( const char* relativePath, void** buffer, ID_TIME_T* timestamp = NULL ) = 0; + // Frees the memory allocated by ReadFile. virtual void FreeFile( void* buffer ) = 0; + // Writes a complete file, will create any needed subdirectories. // Returns the length of the file, or -1 on failure. virtual int WriteFile( const char* relativePath, const void* buffer, int size, const char* basePath = "fs_savepath" ) = 0; + // Removes the given file. virtual void RemoveFile( const char* relativePath ) = 0; + // Removes the specified directory. virtual bool RemoveDir( const char* relativePath ) = 0; + // Renames a file, taken from idTech5 (minus the fsPath_t) virtual bool RenameFile( const char* relativePath, const char* newName, const char* basePath = "fs_savepath" ) = 0; + // Opens a file for reading. virtual idFile* OpenFileRead( const char* relativePath, bool allowCopyFiles = true, const char* gamedir = NULL ) = 0; + // Opens a file for reading, reads the file completely in memory and returns an idFile_Memory obj. virtual idFile* OpenFileReadMemory( const char* relativePath, bool allowCopyFiles = true, const char* gamedir = NULL ) = 0; + // Opens a file for writing, will create any needed subdirectories. virtual idFile* OpenFileWrite( const char* relativePath, const char* basePath = "fs_savepath" ) = 0; + // Opens a file for writing at the end. virtual idFile* OpenFileAppend( const char* filename, bool sync = false, const char* basePath = "fs_basepath" ) = 0; + // Opens a file for reading, writing, or appending depending on the value of mode. virtual idFile* OpenFileByMode( const char* relativePath, fsMode_t mode ) = 0; + // Opens a file for reading from a full OS path. virtual idFile* OpenExplicitFileRead( const char* OSPath ) = 0; + // Opens a file for writing to a full OS path. virtual idFile* OpenExplicitFileWrite( const char* OSPath ) = 0; + // opens a zip container virtual idFile_Cached* OpenExplicitPakFile( const char* OSPath ) = 0; + // Closes a file. virtual void CloseFile( idFile* f ) = 0; + // look for a dynamic module virtual void FindDLL( const char* basename, char dllPath[ MAX_OSPATH ] ) = 0;