assetpackagemgr.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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/assetpackagemgr.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 1/31/02 2:01p $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "stdafx.h"
  36. #include "assetpackagemgr.h"
  37. #include "utils.h"
  38. #include "regkeys.h"
  39. #include "choosemodpackagedialog.h"
  40. #include "editorbuild.h"
  41. #include "leveledit.h"
  42. #include "filelocations.h"
  43. //////////////////////////////////////////////////////////////////////
  44. // Static member initialization
  45. //////////////////////////////////////////////////////////////////////
  46. StringClass AssetPackageMgrClass::CurrentPackageName;
  47. StringClass AssetPackageMgrClass::CurrentPackagePath;
  48. //////////////////////////////////////////////////////////////////////
  49. //
  50. // Initialize
  51. //
  52. //////////////////////////////////////////////////////////////////////
  53. void
  54. AssetPackageMgrClass::Initialize (void)
  55. {
  56. //
  57. // Read the current package name from the registy
  58. //
  59. CString package_name = theApp.GetProfileString (CONFIG_KEY, CURRENT_PACKAGE_NAME, "");
  60. Set_Current_Package (package_name);
  61. return ;
  62. }
  63. //////////////////////////////////////////////////////////////////////
  64. //
  65. // Shutdown
  66. //
  67. //////////////////////////////////////////////////////////////////////
  68. void
  69. AssetPackageMgrClass::Shutdown (void)
  70. {
  71. return ;
  72. }
  73. //////////////////////////////////////////////////////////////////////
  74. //
  75. // Set_Current_Package
  76. //
  77. //////////////////////////////////////////////////////////////////////
  78. void
  79. AssetPackageMgrClass::Set_Current_Package (const char *name)
  80. {
  81. StringClass path = (const char *)::Get_Startup_Directory ();
  82. //
  83. // Save the package name and the path to the package directory
  84. //
  85. CurrentPackageName = name;
  86. CurrentPackagePath = ::Make_Path (path, name);
  87. if (CurrentPackageName.Get_Length () > 0) {
  88. _pThe3DAssetManager->Set_Current_Directory (CurrentPackagePath);
  89. }
  90. return ;
  91. }
  92. //////////////////////////////////////////////////////////////////////
  93. //
  94. // Build_Package_List
  95. //
  96. //////////////////////////////////////////////////////////////////////
  97. void
  98. AssetPackageMgrClass::Build_Package_List (STRING_LIST &list)
  99. {
  100. StringClass path = (const char *)::Get_Startup_Directory ();
  101. StringClass search_path = ::Make_Path (path, "*.*");
  102. //
  103. // Search for all sub-directories in our current folder
  104. //
  105. WIN32_FIND_DATA find_info = { 0 };
  106. BOOL keep_going = TRUE;
  107. HANDLE file_find = NULL;
  108. for (file_find = ::FindFirstFile (search_path, &find_info);
  109. (file_find != INVALID_HANDLE_VALUE) && keep_going;
  110. keep_going = ::FindNextFile (file_find, &find_info))
  111. {
  112. if ( find_info.cFileName[0] != '.' &&
  113. (find_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)
  114. {
  115. //
  116. // Add this sub-directory to the list
  117. //
  118. list.Add (find_info.cFileName);
  119. }
  120. }
  121. //
  122. // Close the search handle
  123. //
  124. if (file_find != INVALID_HANDLE_VALUE) {
  125. ::FindClose (file_find);
  126. }
  127. return ;
  128. }
  129. //////////////////////////////////////////////////////////////////////
  130. //
  131. // Show_Package_Selection_UI
  132. //
  133. //////////////////////////////////////////////////////////////////////
  134. void
  135. AssetPackageMgrClass::Show_Package_Selection_UI (void)
  136. {
  137. #ifdef PUBLIC_EDITOR_VER
  138. ChooseModPackageDialogClass dialog;
  139. dialog.DoModal ();
  140. #endif //PUBLIC_EDITOR_VER
  141. return ;
  142. }
  143. //////////////////////////////////////////////////////////////////////
  144. //
  145. // Create_Package
  146. //
  147. //////////////////////////////////////////////////////////////////////
  148. void
  149. AssetPackageMgrClass::Create_Package (const char *name)
  150. {
  151. StringClass path = (const char *)::Get_Startup_Directory ();
  152. StringClass new_path = ::Make_Path (path, name);
  153. //
  154. // Attempt to create the directory
  155. //
  156. if (::CreateDirectory (new_path, NULL) == FALSE) {
  157. //
  158. // Warn the user on error
  159. //
  160. CString message;
  161. message.Format ("Unable to create the directory: %s", (const char *)new_path);
  162. ::MessageBox (NULL, message, "File Error", MB_ICONERROR | MB_OK | MB_TOPMOST);
  163. } else {
  164. //
  165. // Make a directory for the levels to be stored in
  166. //
  167. CString levels_full_path = ::Make_Path (new_path, LEVELS_ASSET_DIR);
  168. ::CreateDirectory (levels_full_path, NULL);
  169. }
  170. return ;
  171. }