mixfile.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. ** Command & Conquer Renegade(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_Internal_Filename_List (void) { return Build_Filename_List (FilenameList); }
  65. void Get_Filename_List (DynamicVectorClass<StringClass> **list) { *list = &FilenameList; }
  66. void Get_Filename_List (DynamicVectorClass<StringClass> &list) { list = FilenameList; }
  67. //
  68. // Content control
  69. //
  70. void Add_File (const char *full_path, const char *filename);
  71. void Delete_File (const char *filename);
  72. void Flush_Changes (void);
  73. //
  74. // Information
  75. //
  76. bool Is_Valid (void) const { return IsValid; }
  77. private:
  78. //
  79. // Utility functions
  80. //
  81. bool Get_Temp_Filename (const char *path, StringClass &full_path);
  82. struct FileInfoStruct {
  83. bool operator== (const FileInfoStruct &src) { return false; }
  84. bool operator!= (const FileInfoStruct &src) { return true; }
  85. unsigned long CRC; // CRC code for embedded file.
  86. unsigned long Offset; // Offset from start of data section.
  87. unsigned long Size; // Size of data subfile.
  88. };
  89. struct AddInfoStruct {
  90. bool operator== (const AddInfoStruct &src) { return false; }
  91. bool operator!= (const AddInfoStruct &src) { return true; }
  92. StringClass FullPath;
  93. StringClass Filename;
  94. };
  95. FileFactoryClass * Factory;
  96. DynamicVectorClass<FileInfoStruct> FileInfo;
  97. StringClass MixFilename;
  98. int BaseOffset;
  99. int FileCount;
  100. int NamesOffset;
  101. bool IsValid;
  102. DynamicVectorClass<StringClass> FilenameList;
  103. DynamicVectorClass<AddInfoStruct> PendingAddFileList;
  104. bool IsModified;
  105. };
  106. /*
  107. **
  108. */
  109. class MixFileCreator {
  110. public:
  111. MixFileCreator( const char * filename );
  112. ~MixFileCreator( void );
  113. void Add_File( const char * source_filename, const char * saved_filename = NULL );
  114. void Add_File( const char * filename, FileClass *file );
  115. private:
  116. static int File_Info_Compare(const void * a, const void * b);
  117. struct FileInfoStruct {
  118. bool operator== (const FileInfoStruct &src) { return false; }
  119. bool operator!= (const FileInfoStruct &src) { return true; }
  120. unsigned long CRC; // CRC code for embedded file.
  121. unsigned long Offset; // Offset from start of data section.
  122. unsigned long Size; // Size of data subfile.
  123. StringClass Filename;
  124. };
  125. DynamicVectorClass<FileInfoStruct> FileInfo;
  126. FileClass * MixFile;
  127. };
  128. /*
  129. **
  130. */
  131. void Setup_Mix_File( void );
  132. #endif