Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ target_include_directories(corei_main INTERFACE "Main")
target_sources(corei_libraries_include PRIVATE
Libraries/Include/Lib/BaseType.h
Libraries/Include/Lib/BaseTypeCore.h
Libraries/Include/Lib/PathUtil.h
Libraries/Include/Lib/trig.h
Libraries/Include/rts/debug.h
Libraries/Include/rts/profile.h
Expand Down
1 change: 1 addition & 0 deletions Core/GameEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ set(GAMEENGINE_SRC
Source/Common/INI/INIDamageFX.cpp
Source/Common/INI/INIDrawGroupInfo.cpp
Source/Common/INI/INIGameData.cpp
Source/Common/INI/INIFileSystem.cpp
Source/Common/INI/INIMapCache.cpp
Source/Common/INI/INIMapData.cpp
Source/Common/INI/INIMappedImage.cpp
Expand Down
13 changes: 12 additions & 1 deletion Core/GameEngine/Include/Common/ArchiveFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class File;

class ArchiveFile
{
typedef std::hash_map<AsciiString, ArchivedFileInfo*, rts::hash_path, rts::equal_to_path> ArchivedFileInfoPtrHashMap; // Archived file name to archived file info ptr

public:
ArchiveFile();
virtual ~ArchiveFile();
Expand All @@ -60,13 +62,22 @@ class ArchiveFile
void attachFile(File *file);

void getFileListInDirectory(const AsciiString& currentDirectory, const AsciiString& originalDirectory, const AsciiString& searchName, FilenameList &filenameList, Bool searchSubdirectories) const;
void getFileListInDirectory(const DetailedArchivedDirectoryInfo *dirInfo, const AsciiString& currentDirectory, const AsciiString& searchName, FilenameList &filenameList, Bool searchSubdirectories) const;

void addFile(const AsciiString& path, const ArchivedFileInfo *fileInfo); ///< add this file to our directory tree.
Bool ignoreFile(const AsciiString& filename, Bool ignore);
Bool ignoreDirectory(const AsciiString& directory, Bool ignore);

protected:
void getFileListInDirectory(const DetailedArchivedDirectoryInfo *dirInfo, const AsciiString& currentDirectory, const AsciiString& searchName, FilenameList &filenameList, Bool searchSubdirectories) const;
const ArchivedFileInfo * getArchivedFileInfo(const AsciiString& filename) const; ///< return the ArchivedFileInfo from the directory tree.

private:
void ignoreDirectory(DetailedArchivedDirectoryInfo *dirInfo, Bool ignore);

protected:
File *m_file; ///< file pointer to the archive file on disk. Kept open so we don't have to continuously open and close the file all the time.

private:
DetailedArchivedDirectoryInfo m_rootDirectory;
ArchivedFileInfoPtrHashMap m_absFilenameToFileInfo;
};
15 changes: 12 additions & 3 deletions Core/GameEngine/Include/Common/ArchiveFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ class DetailedArchivedDirectoryInfo
AsciiString m_directoryName;
DetailedArchivedDirectoryInfoMap m_directories;
ArchivedFileInfoMap m_files;
Bool m_ignore;

DetailedArchivedDirectoryInfo()
: m_ignore(false)
{
}
};

class ArchivedFileInfo
Expand All @@ -111,10 +117,12 @@ class ArchivedFileInfo
AsciiString m_archiveFilename;
UnsignedInt m_offset;
UnsignedInt m_size;
Bool m_ignore;

ArchivedFileInfo()
: m_offset(0)
, m_size(0)
, m_ignore(false)
{
}
};
Expand Down Expand Up @@ -143,11 +151,11 @@ class ArchiveFileSystem : public SubsystemInterface

virtual Bool loadBigFilesFromDirectory(AsciiString dir, AsciiString fileMask, Bool overwrite = FALSE) = 0;

// Unprotected this for copy-protection routines
ArchiveFile* getArchiveFile(const AsciiString& filename, FileInstance instance = 0) const;

void loadMods();

Bool ignoreFile(const AsciiString& filename, Bool ignore = true); ///< Ignore all file instances with this name in the Archive System.
Bool ignoreDirectory(const AsciiString& directory, Bool ignore = true); ///< Ignore this directory and all its contents in the Archive System.

ArchivedDirectoryInfo* friend_getArchivedDirectoryInfo(const Char* directory);

protected:
Expand All @@ -160,6 +168,7 @@ class ArchiveFileSystem : public SubsystemInterface
AsciiString lastToken; ///< Synonymous for file name if the search directory was a file path
};

ArchiveFile* getArchiveFile(const AsciiString& filename, FileInstance instance = 0) const;
ArchivedDirectoryInfoResult getArchivedDirectoryInfo(const Char* directory);

virtual void loadIntoDirectoryTree(ArchiveFile *archiveFile, Bool overwrite = FALSE); ///< load the archive file's header information and apply it to the global archive directory tree.
Expand Down
13 changes: 10 additions & 3 deletions Core/GameEngine/Include/Common/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
// Type Defines
//----------------------------------------------------------------------------

typedef std::set<AsciiString, rts::less_than_nocase<AsciiString>/**/> FilenameList;
typedef std::set<AsciiString, rts::less_than_path> FilenameList;
typedef FilenameList::iterator FilenameListIter;
typedef UnsignedByte FileInstance;

Expand Down Expand Up @@ -136,6 +136,10 @@ struct FileInfo {
// from multiple threads.
//
// TheSuperHackers @feature Mauller 24/04/2026 Add extension removal functions
//
// TheSuperHackers @feature xezon 26/07/2026 Implements ignore functionality for files and directories in the local
// and archive file systems. Can be called at any time during engine runtime. Can be controlled by data with
// FileSystemIgnore definitions in Data/INI/FileSystem.ini .
//===============================
class FileSystem : public SubsystemInterface
{
Expand All @@ -157,6 +161,9 @@ class FileSystem : public SubsystemInterface

Bool createDirectory(AsciiString directory); ///< create a directory of the given name.

Bool ignoreFile(const AsciiString& filename, Bool ignore = true); ///< Ignore this file.
Bool ignoreDirectory(const AsciiString& directory, Bool ignore = true); ///< Ignore this directory and all its contents.

static AsciiString normalizePath(const AsciiString& path); ///< normalizes a file path. The path can refer to a directory. File path must be absolute, but does not need to exist. Returns an empty string on failure.
static Bool isPathInDirectory(const AsciiString& testPath, const AsciiString& basePath); ///< determines if a file path is within a base path. Both paths must be absolute, but do not need to exist.

Expand All @@ -173,8 +180,8 @@ class FileSystem : public SubsystemInterface
};
typedef std::hash_map<
rts::string_key<AsciiString>, FileExistData,
rts::string_key_hash<AsciiString>,
rts::string_key_equal<AsciiString>/**/> FileExistMap;
rts::string_key_hash_path,
rts::string_key_equal_to_path> FileExistMap;

mutable FileExistMap m_fileExist;
mutable FastCriticalSectionClass m_fileExistMutex;
Expand Down
1 change: 1 addition & 0 deletions Core/GameEngine/Include/Common/GameCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

// ----------------------------------------------------------------------------------------------
#include "Lib/BaseType.h"
#include "Lib/PathUtil.h"
#include "WWLib/WWCommon.h"
#include "Common/GameDefines.h"

Expand Down
17 changes: 15 additions & 2 deletions Core/GameEngine/Include/Common/INI.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,29 @@ class INI
INI& operator=(const INI&) FUNCTION_DELETE;

public:

typedef UnsignedInt LoadFlags;
enum LoadFlags_ CPP_11( : UnsignedInt)
{
LoadFlags_SearchSubDirs = 1 << 0,
LoadFlags_ExpectFileFound = 1 << 1,
};

public:

INI();

// TheSuperHackers @feature xezon 19/08/2025
// Load a specific INI file by name and/or INI files from a directory (and its subdirectories).
// For example "Data\INI\Armor" loads "Data\INI\Armor.ini" and all *.ini files in "Data\INI\Armor".
// Throws if not a single INI file is found or one is not read correctly.
UnsignedInt loadFileDirectory( AsciiString fileDirName, INILoadType loadType, Xfer *pXfer, Bool subdirs = TRUE );
UnsignedInt loadFileDirectory( AsciiString fileDirName, INILoadType loadType, Xfer *pXfer,
LoadFlags loadFlags = LoadFlags_SearchSubDirs | LoadFlags_ExpectFileFound );

// Load INI files from a directory (and its subdirectories).
// Throws if one INI file is not read correctly.
UnsignedInt loadDirectory( AsciiString dirName, INILoadType loadType, Xfer *pXfer, Bool subdirs = TRUE );
UnsignedInt loadDirectory( AsciiString dirName, INILoadType loadType, Xfer *pXfer,
LoadFlags loadFlags = LoadFlags_SearchSubDirs );

// Load one specific INI file by name.
// Throws if the INI file is not found or is not read correctly.
Expand Down Expand Up @@ -213,6 +225,7 @@ class INI
static void parseTerrainRoadDefinition( INI *ini );
static void parseTerrainBridgeDefinition( INI *ini );
static void parseMetaMapDefinition( INI *ini );
static void parseFileSystemIgnoreDefinition( INI* ini );
static void parseFXListDefinition( INI *ini );
static void parseObjectCreationListDefinition( INI* ini );
static void parseMultiplayerSettingsDefinition( INI* ini );
Expand Down
36 changes: 36 additions & 0 deletions Core/GameEngine/Include/Common/LocalFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@

class LocalFileSystem : public SubsystemInterface
{
struct IgnoreFileData
{
};

typedef std::hash_map<
rts::string_key<AsciiString>, IgnoreFileData,
rts::string_key_hash_path,
rts::string_key_equal_to_path> IgnoreFileHashMap;

protected:
typedef Int IgnoreFileTestFlags;
enum IgnoreFileTestFlags_
{
IgnoreFileTestFlags_SkipParentDirectories = 1 << 0,
};

public:
virtual ~LocalFileSystem() override {}

Expand All @@ -43,7 +59,27 @@ class LocalFileSystem : public SubsystemInterface
virtual Bool createDirectory(AsciiString directory) = 0; ///< see FileSystem.h
virtual AsciiString normalizePath(const AsciiString& filePath) const = 0; ///< see FileSystem.h

Bool ignoreFile(const AsciiString& filename, Bool ignore = true); ///< Ignore this file on the disk.
Bool ignoreDirectory(const AsciiString& directory, Bool ignore = true); ///< Ignore this directory and all its contents on the disk.

protected:
Bool isFileIgnored(const Char* filename, IgnoreFileTestFlags flags = 0) const; ///< Whether the given file or its parent directories are ignored.
Bool isDirectoryIgnored(const Char* directory, IgnoreFileTestFlags flags = 0) const; ///< Whether the given directory or its parent directories are ignored.

private:
Bool isDirectoryIgnoredRecursive(AsciiString& directory, IgnoreFileTestFlags flags) const;
Bool isFileIgnoredInternal(const Char* filename) const;
Bool isDirectoryIgnoredInternal(const Char* directory) const;
Bool hasIgnoredFile() const;
Bool hasIgnoredDirectory() const;

static void trimLastPathSegmentInplace(AsciiString& path); ///< Removes trailing path segment until and including the last slash.
static void trimTrailingSlash(AsciiString& path); ///< Remove trailing forward or backward slashes.

IgnoreFileHashMap m_ignoreFileHashMap;
IgnoreFileHashMap m_ignoreDirectoryHashMap;
Comment thread
xezon marked this conversation as resolved.
mutable FastCriticalSectionClass m_ignoreFileMutex;
mutable FastCriticalSectionClass m_ignoreDirectoryMutex;
};

extern LocalFileSystem *TheLocalFileSystem;
Loading
Loading