ArchiveFileSystem.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. //----------------------------------------------------------------------------
  24. //
  25. // Westwood Studios Pacific.
  26. //
  27. // Confidential Information
  28. // Copyright (C) 2001 - All Rights Reserved
  29. //
  30. //----------------------------------------------------------------------------
  31. //
  32. // Project: Generals
  33. //
  34. // Module: Archive files
  35. //
  36. // File name: Common/ArchiveFileSystem.h
  37. //
  38. // Created: 11/26/01 TR
  39. //
  40. //----------------------------------------------------------------------------
  41. #pragma once
  42. #ifndef __ARCHIVEFILESYSTEM_H_
  43. #define __ARCHIVEFILESYSTEM_H_
  44. #define MUSIC_BIG "Music.big"
  45. //----------------------------------------------------------------------------
  46. // Includes
  47. //----------------------------------------------------------------------------
  48. #include "Common/SubsystemInterface.h"
  49. #include "Common/AsciiString.h"
  50. #include "Common/FileSystem.h" // for typedefs, etc.
  51. #include "Common/STLTypedefs.h"
  52. //----------------------------------------------------------------------------
  53. // Forward References
  54. //----------------------------------------------------------------------------
  55. class File;
  56. class ArchiveFile;
  57. //----------------------------------------------------------------------------
  58. // Type Defines
  59. //----------------------------------------------------------------------------
  60. //===============================
  61. // ArchiveFileSystem
  62. //===============================
  63. /**
  64. * Creates and manages ArchiveFile interfaces. ArchiveFiles can be accessed
  65. * by calling the openArchiveFile() member. ArchiveFiles can be accessed by
  66. * name or by File interface.
  67. *
  68. * openFile() member searches all Archive files for the specified sub file.
  69. */
  70. //===============================
  71. class ArchivedDirectoryInfo;
  72. class DetailedArchivedDirectoryInfo;
  73. class ArchivedFileInfo;
  74. typedef std::map<AsciiString, DetailedArchivedDirectoryInfo> DetailedArchivedDirectoryInfoMap;
  75. typedef std::map<AsciiString, ArchivedDirectoryInfo> ArchivedDirectoryInfoMap;
  76. typedef std::map<AsciiString, ArchivedFileInfo> ArchivedFileInfoMap;
  77. typedef std::map<AsciiString, ArchiveFile *> ArchiveFileMap;
  78. typedef std::map<AsciiString, AsciiString> ArchivedFileLocationMap; // first string is the file name, second one is the archive filename.
  79. class ArchivedDirectoryInfo
  80. {
  81. public:
  82. AsciiString m_directoryName;
  83. ArchivedDirectoryInfoMap m_directories;
  84. ArchivedFileLocationMap m_files;
  85. void clear()
  86. {
  87. m_directoryName.clear();
  88. m_directories.clear();
  89. m_files.clear();
  90. }
  91. };
  92. class DetailedArchivedDirectoryInfo
  93. {
  94. public:
  95. AsciiString m_directoryName;
  96. DetailedArchivedDirectoryInfoMap m_directories;
  97. ArchivedFileInfoMap m_files;
  98. void clear()
  99. {
  100. m_directoryName.clear();
  101. m_directories.clear();
  102. m_files.clear();
  103. }
  104. };
  105. class ArchivedFileInfo
  106. {
  107. public:
  108. AsciiString m_filename;
  109. AsciiString m_archiveFilename;
  110. UnsignedInt m_offset;
  111. UnsignedInt m_size;
  112. ArchivedFileInfo()
  113. {
  114. clear();
  115. }
  116. void clear()
  117. {
  118. m_filename.clear();
  119. m_archiveFilename.clear();
  120. m_offset = 0;
  121. m_size = 0;
  122. }
  123. };
  124. class ArchiveFileSystem : public SubsystemInterface
  125. {
  126. public:
  127. ArchiveFileSystem();
  128. virtual ~ArchiveFileSystem();
  129. virtual void init( void ) = 0;
  130. virtual void update( void ) = 0;
  131. virtual void reset( void ) = 0;
  132. virtual void postProcessLoad( void ) = 0;
  133. // ArchiveFile operations
  134. virtual ArchiveFile* openArchiveFile( const Char *filename ) = 0; ///< Create new or return existing Archive file from file name
  135. virtual void closeArchiveFile( const Char *filename ) = 0; ///< Close the one specified big file.
  136. virtual void closeAllArchiveFiles( void ) = 0; ///< Close all Archivefiles currently open
  137. // File operations
  138. virtual File* openFile( const Char *filename, Int access = 0); ///< Search Archive files for specified file name and open it if found
  139. virtual void closeAllFiles( void ) = 0; ///< Close all files associated with ArchiveFiles
  140. virtual Bool doesFileExist(const Char *filename) const; ///< return true if that file exists in an archive file somewhere.
  141. 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.
  142. Bool getFileInfo(const AsciiString& filename, FileInfo *fileInfo) const; ///< see FileSystem.h
  143. virtual Bool loadBigFilesFromDirectory(AsciiString dir, AsciiString fileMask, Bool overwrite = FALSE) = 0;
  144. // Unprotected this for copy-protection routines
  145. AsciiString getArchiveFilenameForFile(const AsciiString& filename) const;
  146. void loadMods( void );
  147. protected:
  148. virtual void loadIntoDirectoryTree(const ArchiveFile *archiveFile, const AsciiString& archiveFilename, Bool overwrite = FALSE); ///< load the archive file's header information and apply it to the global archive directory tree.
  149. ArchiveFileMap m_archiveFileMap;
  150. ArchivedDirectoryInfo m_rootDirectory;
  151. };
  152. extern ArchiveFileSystem *TheArchiveFileSystem;
  153. //----------------------------------------------------------------------------
  154. // Inlining
  155. //----------------------------------------------------------------------------
  156. #endif // __ARCHIVEFILESYSTEM_H_