mixfile.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/wwlib/mixfile.h $*
  25. * *
  26. * $Author:: Steve_t $*
  27. * *
  28. * $Modtime:: 9/07/01 5:29p $*
  29. * *
  30. * $Revision:: 4 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #ifndef MIXFILE_H
  36. #define MIXFILE_H
  37. #ifndef ALWAYS_H
  38. #include "always.h"
  39. #endif
  40. #ifndef FFACTORY_H
  41. #include "ffactory.h"
  42. #endif
  43. #ifndef WWSTRING_H
  44. #include "wwstring.h"
  45. #endif
  46. #include "vector.h"
  47. class FileClass;
  48. /*
  49. **
  50. */
  51. class MixFileFactoryClass : public FileFactoryClass {
  52. public:
  53. MixFileFactoryClass( const char * mix_filename, FileFactoryClass * factory );
  54. virtual ~MixFileFactoryClass( void );
  55. //
  56. // Inherited
  57. //
  58. virtual FileClass * Get_File( char const *filename );
  59. virtual void Return_File( FileClass *file );
  60. //
  61. // Filename access
  62. //
  63. bool Build_Filename_List (DynamicVectorClass<StringClass> &list);
  64. bool Build_Ordered_Filename_List (DynamicVectorClass<StringClass> &list); // ordered by offset in mixfile
  65. bool Build_Internal_Filename_List (void) { return Build_Filename_List (FilenameList); }
  66. void Get_Filename_List (DynamicVectorClass<StringClass> **list) { *list = &FilenameList; }
  67. void Get_Filename_List (DynamicVectorClass<StringClass> &list) { list = FilenameList; }
  68. //
  69. // Content control
  70. //
  71. void Add_File (const char *full_path, const char *filename);
  72. void Delete_File (const char *filename);
  73. void Flush_Changes (void);
  74. //
  75. // Information
  76. //
  77. bool Is_Valid (void) const { return IsValid; }
  78. private:
  79. //
  80. // Utility functions
  81. //
  82. bool Get_Temp_Filename (const char *path, StringClass &full_path);
  83. static int File_Offset_Compare(const void * a, const void * b);
  84. struct FileInfoStruct {
  85. bool operator== (const FileInfoStruct &src) { return false; }
  86. bool operator!= (const FileInfoStruct &src) { return true; }
  87. unsigned long CRC; // CRC code for embedded file.
  88. unsigned long Offset; // Offset from start of data section.
  89. unsigned long Size; // Size of data subfile.
  90. };
  91. struct AddInfoStruct {
  92. bool operator== (const AddInfoStruct &src) { return false; }
  93. bool operator!= (const AddInfoStruct &src) { return true; }
  94. StringClass FullPath;
  95. StringClass Filename;
  96. };
  97. FileFactoryClass * Factory;
  98. DynamicVectorClass<FileInfoStruct> FileInfo;
  99. StringClass MixFilename;
  100. int BaseOffset;
  101. int FileCount;
  102. int NamesOffset;
  103. bool IsValid;
  104. DynamicVectorClass<StringClass> FilenameList;
  105. DynamicVectorClass<AddInfoStruct> PendingAddFileList;
  106. bool IsModified;
  107. };
  108. /*
  109. **
  110. */
  111. class MixFileCreator {
  112. public:
  113. MixFileCreator( const char * filename );
  114. ~MixFileCreator( void );
  115. void Add_File( const char * source_filename, const char * saved_filename = NULL );
  116. void Add_File( const char * filename, FileClass *file );
  117. private:
  118. static int File_Info_Compare(const void * a, const void * b);
  119. struct FileInfoStruct {
  120. bool operator== (const FileInfoStruct &src) { return false; }
  121. bool operator!= (const FileInfoStruct &src) { return true; }
  122. unsigned long CRC; // CRC code for embedded file.
  123. unsigned long Offset; // Offset from start of data section.
  124. unsigned long Size; // Size of data subfile.
  125. StringClass Filename;
  126. };
  127. DynamicVectorClass<FileInfoStruct> FileInfo;
  128. FileClass * MixFile;
  129. };
  130. /*
  131. **
  132. */
  133. void Setup_Mix_File( void );
  134. #endif