FileMgr.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : LevelEdit *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/LevelEdit/FileMgr.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 1/29/02 11:48a $*
  29. * *
  30. * $Revision:: 17 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __FILEMGR_H
  39. #define __FILEMGR_H
  40. #include "vector.h"
  41. #include "bittype.h"
  42. #include "listtypes.h"
  43. ///////////////////////////////////////////////////////////////////////
  44. // Forward declarations
  45. ///////////////////////////////////////////////////////////////////////
  46. class RenderObjClass;
  47. class PresetClass;
  48. class AssetDatabaseClass;
  49. class NodeClass;
  50. ///////////////////////////////////////////////////////////////////////
  51. // Constants
  52. ///////////////////////////////////////////////////////////////////////
  53. extern const char *SPECIAL_USER_FOLDER;
  54. extern const char *PROXY_TESTS_FOLDER;
  55. ///////////////////////////////////////////////////////////////////////////
  56. //
  57. // FileInfoStruct
  58. //
  59. ///////////////////////////////////////////////////////////////////////////
  60. struct FileInfoStruct
  61. {
  62. public:
  63. //////////////////////////////////////////////////////////
  64. // Public constructors/destructors
  65. //////////////////////////////////////////////////////////
  66. FileInfoStruct (void)
  67. : m_SubdirImportant (false) { }
  68. FileInfoStruct (const CString &filename, bool subdir_important)
  69. : m_Filename (filename),
  70. m_SubdirImportant (subdir_important) { }
  71. //////////////////////////////////////////////////////////
  72. // Public operators
  73. //////////////////////////////////////////////////////////
  74. bool operator== (const FileInfoStruct &src) { return false; }
  75. bool operator!= (const FileInfoStruct &src) { return true; }
  76. //////////////////////////////////////////////////////////
  77. // Public fields
  78. //////////////////////////////////////////////////////////
  79. CString m_Filename;
  80. bool m_SubdirImportant;
  81. };
  82. typedef DynamicVectorClass<FileInfoStruct> FILE_LIST;
  83. ///////////////////////////////////////////////////////////////////////////
  84. //
  85. // LevelFileStruct
  86. //
  87. // Struct definition for a level editor file. This is used by the manager
  88. // to represent a file.
  89. //
  90. struct LevelFileStruct
  91. {
  92. public:
  93. //////////////////////////////////////////////////////////
  94. // Public constructors/destructors
  95. //////////////////////////////////////////////////////////
  96. LevelFileStruct (void)
  97. : m_SubdirImportant (false),
  98. m_RefCount (1L) { }
  99. virtual ~LevelFileStruct (void) { }
  100. //////////////////////////////////////////////////////////
  101. // Public fields
  102. //////////////////////////////////////////////////////////
  103. CString m_Filename;
  104. ULONG m_RefCount;
  105. bool m_SubdirImportant;
  106. };
  107. ///////////////////////////////////////////////////////////////////////////
  108. //
  109. // FileMgrClass
  110. //
  111. // Class definition for a level editor file manager which controls:
  112. // - Versioning
  113. // - Reference counting
  114. // - VSS integration
  115. //
  116. ///////////////////////////////////////////////////////////////////////////
  117. class FileMgrClass
  118. {
  119. public:
  120. //////////////////////////////////////////////////////////
  121. // Public constructors/destructors
  122. //////////////////////////////////////////////////////////
  123. FileMgrClass (void);
  124. virtual ~FileMgrClass (void) { Free_Data (); }
  125. //////////////////////////////////////////////////////////
  126. // Public Methods
  127. //////////////////////////////////////////////////////////
  128. //
  129. // Initialization routines
  130. //
  131. void Initialize (void);
  132. //
  133. // Enumeration routines
  134. //
  135. int Get_File_Count (void) const { return m_FileList.Count (); }
  136. CString Get_File_Name (int index) const { return m_FileList[index]->m_Filename; }
  137. bool Is_File_Path_Important (int index) const { return m_FileList[index]->m_SubdirImportant; }
  138. //
  139. // Management
  140. //
  141. void Update (NodeClass *node, bool add_node = true);
  142. void Update (PresetClass *preset, bool add_node = true);
  143. void Add_Asset (LPCTSTR filename);
  144. void Remove_Asset (LPCTSTR filename);
  145. int Add_File (LPCTSTR filename, bool subdir_important = false);
  146. bool Remove_File (int prop_index);
  147. int Find_File (LPCTSTR filename) const;
  148. void Build_File_List (LPCTSTR start_path, RenderObjClass *prender_obj, FILE_LIST &file_list);
  149. void Find_Files (LPCTSTR path, LPCTSTR wildcard, DynamicVectorClass<CString> &file_list, bool brecurse);
  150. //
  151. // File base path management
  152. //
  153. void Set_Base_Path (LPCTSTR base);
  154. LPCTSTR Get_Base_Path (void) const { return m_BasePath; }
  155. //
  156. // Preset library information
  157. //
  158. void Get_Preset_Library_Path (uint32 class_id, bool is_temp, CString &path);
  159. //
  160. // Texture methods
  161. //
  162. bool Update_Texture_Cache (LPCTSTR start_path, RenderObjClass *prender_obj);
  163. int Build_Texture_List (LPCTSTR start_path, RenderObjClass *prender_obj, DynamicVectorClass<CString> &texture_list, bool brecurse = true);
  164. const CString & Get_Texture_Cache_Path (void) const { return m_TextureCachePath; }
  165. //
  166. // File information
  167. //
  168. bool Does_File_Exist (LPCTSTR filename, bool bupdate_from_vss = false);
  169. CString Make_Full_Path (LPCTSTR rel_path);
  170. CString Make_Relative_Path (LPCTSTR full_path);
  171. bool Is_Path_Valid (LPCTSTR path);
  172. bool Is_Empty_Path (LPCTSTR path);
  173. bool Is_Path_In_Asset_Tree (LPCTSTR path);
  174. bool Determine_File_Location (LPCTSTR full_path, CString &real_location);
  175. //
  176. // Include file methods
  177. //
  178. void Build_Global_Include_List (void);
  179. bool Update_Global_Include_File_List (void);
  180. DynamicVectorClass<CString> & Get_Global_Include_File_List (void) { return m_GlobalIncludeFiles; }
  181. DynamicVectorClass<CString> & Get_Include_File_List (void) { return m_IncludeFiles; }
  182. void Build_Include_List (LPCTSTR ini_filename, DynamicVectorClass<CString> &list);
  183. //
  184. // VSS integration methods
  185. //
  186. bool Initialize_VSS (LPCTSTR ini_file_path, LPCTSTR username = NULL, LPCTSTR password = NULL);
  187. int Build_Update_List (DynamicVectorClass<LevelFileStruct *> &update_list);
  188. bool Update_Files (DynamicVectorClass<LevelFileStruct *> *pupdate_list = NULL);
  189. bool Update_File (int index);
  190. bool Update_File (LPCTSTR filename);
  191. bool Update_All_Files (LPCTSTR dest_path, LPCTSTR search_mask);
  192. bool Update_Model (LPCTSTR local_path, LPCTSTR new_filename);
  193. bool Add_Files_To_Database (LPCTSTR filename);
  194. bool Add_File_To_Database (LPCTSTR filename);
  195. bool Is_VSS_Integration_Enabled (void) { return m_bVSSInitialized; }
  196. bool Is_File_In_VSS (LPCTSTR filename);
  197. bool Get_Subproject (LPCTSTR path);
  198. AssetDatabaseClass & Get_Database_Interface (void) { return *m_DatabaseInterface; }
  199. void Set_Read_Only_VSS (bool bread_only = true) { m_bReadOnlyVSS = bread_only; }
  200. bool Is_VSS_Read_Only (void) { return m_bReadOnlyVSS; }
  201. bool Is_Special_User (void) { return m_IsSpecialUser; }
  202. bool Update_Asset_Tree (void);
  203. void Build_Dependency_List (LPCTSTR filename, UniqueListClass<CString> &list);
  204. //
  205. // Static member data
  206. //
  207. static bool _bAutoUpdateOn;
  208. protected:
  209. //////////////////////////////////////////////////////////
  210. // Protected methods
  211. //////////////////////////////////////////////////////////
  212. void Free_Data (void);
  213. CDialog * m_pUpdateDlg;
  214. CString m_CurrentFile;
  215. void Add_Files_To_Database (void);
  216. friend UINT fnUpdateVSSThread (LPVOID pParam);
  217. private:
  218. //////////////////////////////////////////////////////////
  219. // Private member data
  220. //////////////////////////////////////////////////////////
  221. DynamicVectorClass<LevelFileStruct *> m_FileList;
  222. CString m_BasePath;
  223. CString m_TextureCachePath;
  224. AssetDatabaseClass * m_DatabaseInterface;
  225. bool m_bVSSInitialized;
  226. bool m_bReadOnlyVSS;
  227. bool m_IsSpecialUser;
  228. DynamicVectorClass<CString> m_GlobalIncludeFiles;
  229. DynamicVectorClass<CString> m_IncludeFiles;
  230. };
  231. #endif //__FILEMGR_H