Skip to content
Closed
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
2 changes: 2 additions & 0 deletions Core/GameEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ set(GAMEENGINE_SRC
# Include/Common/BattleHonors.h
# Include/Common/BezFwdIterator.h
# Include/Common/BezierSegment.h
Include/Common/BIGFileSystem.h
# Include/Common/BitFlags.h
# Include/Common/BitFlagsIO.h
# Include/Common/BorderColors.h
Expand Down Expand Up @@ -644,6 +645,7 @@ set(GAMEENGINE_SRC
Source/Common/System/ArchiveFile.cpp
Source/Common/System/ArchiveFileSystem.cpp
Source/Common/System/AsciiString.cpp
Source/Common/System/BIGFileSystem.cpp
# Source/Common/System/BuildAssistant.cpp
# Source/Common/System/CriticalSection.cpp
# Source/Common/System/DataChunk.cpp
Expand Down
29 changes: 19 additions & 10 deletions Core/GameEngine/Include/Common/ArchiveFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,35 @@ class File;
class ArchiveFile
{
public:
ArchiveFile();
virtual ~ArchiveFile();
ArchiveFile(AsciiString name, AsciiString path);
~ArchiveFile();

virtual Bool getFileInfo( const AsciiString& filename, FileInfo *fileInfo) const = 0; ///< fill in the fileInfo struct with info about the file requested.
virtual File* openFile( const Char *filename, Int access = 0) = 0; ///< Open the specified file within the archive file
virtual void closeAllFiles() = 0; ///< Close all file opened in this archive file
virtual AsciiString getName() = 0; ///< Returns the name of the archive file
virtual AsciiString getPath() = 0; ///< Returns full path and name of archive file
virtual void setSearchPriority( Int new_priority ) = 0; ///< Set this archive file's search priority
virtual void close() = 0; ///< Close this archive file
Bool getFileInfo( const AsciiString& filename, FileInfo *fileInfo) const; ///< fill in the fileInfo struct with info about the file requested.
File* openFile( const Char *filename, Int access = 0); ///< Open the specified file within the archive file
void closeAllFiles(); ///< Close all file opened in this archive file
AsciiString getName(); ///< Returns the name of the archive file
AsciiString getPath(); ///< Returns full path and name of archive file
void setSearchPriority( Int new_priority ); ///< Set this archive file's search priority
void close(); ///< Close this archive file
void attachFile(File *file);
void setPriority(Int priority) { m_priority = priority; }
Int getPriority() const { return m_priority; }

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.

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.

protected:
Int m_priority = ARCHIVE_PRIORITY_RETAIL; ///< lookup priority in the archive file system, lower wins
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.
FileInfo m_fileInfo; ///< file info of the archive file on disk.
AsciiString m_name; ///< archive file name
AsciiString m_path; ///< archive file path

private:
DetailedArchivedDirectoryInfo m_rootDirectory;
};
51 changes: 46 additions & 5 deletions Core/GameEngine/Include/Common/ArchiveFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,28 @@ class ArchivedFileInfo
};


// Lookup priority of an archive, lower wins. The archive mounted first wins on equal priority.
enum ArchivePriority
{
ARCHIVE_PRIORITY_MOD = 0, ///< -mod and -modDir, 0 to 999, a later one is lower and wins
ARCHIVE_PRIORITY_GAME_FOLDER = 1000, ///< BIGs of the Zero Hour folder that are not retail, in name order
ARCHIVE_PRIORITY_GAME_FOLDER_GENERALS = 1100, ///< BIGs of the Generals data (ZH_Generals or the Generals install) that are not retail
ARCHIVE_PRIORITY_LIST = 100000, ///< the archives list of settings.json, 100000 plus the position in the list
ARCHIVE_PRIORITY_RETAIL = 3000000, ///< Zero Hour retail and official patch BIGs
ARCHIVE_PRIORITY_RETAIL_GENERALS = 3000100 ///< Generals retail and official patch BIGs
};

// One entry of the archives list in settings.json, see ArchiveFileSystem::parseMountEntry
struct ArchiveMountEntry
{
enum Kind { KIND_BIG, KIND_BIG_GLOB };
enum Base { BASE_GAME, BASE_USER, BASE_ABSOLUTE };

Kind m_kind;
Base m_base;
AsciiString m_path; ///< with backslashes, relative to the base, the BASE_ABSOLUTE path is complete
};

class ArchiveFileSystem : public SubsystemInterface
{
public:
Expand All @@ -141,12 +163,22 @@ class ArchiveFileSystem : public SubsystemInterface
void getFileListInDirectory(const AsciiString& currentDirectory, const AsciiString& originalDirectory, const AsciiString& searchName, FilenameList &filenameList, Bool searchSubdirectories) const; ///< search the given directory for files matching the searchName (egs. *.ini, *.rep). Possibly search subdirectories. Scans each Archive file.
Bool getFileInfo(const AsciiString& filename, FileInfo *fileInfo, FileInstance instance = 0) const; ///< see FileSystem.h

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

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

/// Parses an entry of the archives list: "game:<path>", "user:<path>" or an absolute path. A path ending in .big is one BIG,
/// a last component with * or ? and ending in .big is a set of BIGs, a path ending in a slash is every BIG in that folder.
/// Returns FALSE and a reason for an entry that is not valid.
static Bool parseMountEntry(const AsciiString& text, ArchiveMountEntry* entry, AsciiString* reason);

/// TRUE for the retail archives and the official patches of Zero Hour and Generals, in every language.
static Bool isGeneralsArchivePath(const AsciiString& path, Bool generalsFolder); ///< TRUE for the Generals archives: the Generals install folder, or a ZH_Generals folder

static Bool isRetailArchive(const AsciiString& path, Bool generalsFolder, Bool zeroHour);

void loadMods();
/// BIGs of the game folders that are not retail, which are mounted above the archives list
const std::vector<AsciiString>& getGameFolderArchives() const { return m_gameFolderArchives; }

ArchivedDirectoryInfo* friend_getArchivedDirectoryInfo(const Char* directory);

Expand All @@ -160,11 +192,20 @@ 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, Bool sortedByName = FALSE); ///< load the archive file's header information and apply it to the global archive directory tree. sortedByName inserts by archive filename order (addon number convention), ignoring overwrite.
virtual void loadIntoDirectoryTree(ArchiveFile *archiveFile, Int priority = ARCHIVE_PRIORITY_RETAIL); ///< load the archive file's header information and apply it to the global archive directory tree. The lowest priority number wins, the first mounted wins on equal priority.

Int getNextModPriority() { return m_nextModPriority > ARCHIVE_PRIORITY_MOD ? m_nextModPriority-- : ARCHIVE_PRIORITY_MOD; } ///< -mod and -modDir: a later one wins
Int getGameFolderArchivePriority(const AsciiString& path, Bool generalsFolder, Bool zeroHour); ///< retail archives are the bottom, any other BIG of the game folders ranks above the archives list

void mountListedArchive(const ArchiveMountEntry& entry, Int priority);

ArchiveFileMap m_archiveFileMap;
std::vector<AsciiString> m_gameFolderArchives;
AsciiString m_generalsBaseSource; ///< where the Generals data came from, for the log
Int m_nextModPriority = ARCHIVE_PRIORITY_MOD + 999;
ArchivedDirectoryInfo m_rootDirectory;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
// //
////////////////////////////////////////////////////////////////////////////////

//////// Win32BIGFileSystem.h ///////////////////////////
//////// BIGFileSystem.h ///////////////////////////
// Bryan Cleveland, August 2002
/////////////////////////////////////////////////////////////

#pragma once

#include "Common/ArchiveFileSystem.h"

class Win32BIGFileSystem : public ArchiveFileSystem
class BIGFileSystem : public ArchiveFileSystem
{
public:
Win32BIGFileSystem();
virtual ~Win32BIGFileSystem() override;
BIGFileSystem();
virtual ~BIGFileSystem() override;

virtual void init() override;
virtual void update() override;
Expand All @@ -49,7 +49,9 @@ class Win32BIGFileSystem : public ArchiveFileSystem
virtual void closeArchiveFile(const Char *filename) override;
virtual void closeAllFiles() override; ///< Close all files associated with ArchiveFiles

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

virtual void loadMods() override;
protected:

};
8 changes: 8 additions & 0 deletions Core/GameEngine/Include/Common/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ typedef UnsignedByte FileInstance;

struct FileInfo {

FileInfo()
: sizeHigh(0)
, sizeLow(0)
, timestampHigh(0)
, timestampLow(0)
{
}

Int64 size() const { return (Int64)sizeHigh << 32 | sizeLow; }
Int64 timestamp() const { return (Int64)timestampHigh << 32 | timestampLow; }

Expand Down
Loading
Loading