skinpackagemgr.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 : commando *
  23. * *
  24. * $Archive:: /Commando/Code/commando/skinpackagemgr.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 1/07/02 10:56a $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "skinpackagemgr.h"
  36. #include "registry.h"
  37. #include "_globals.h"
  38. /////////////////////////////////////////////////////////////////////
  39. // Local constants
  40. /////////////////////////////////////////////////////////////////////
  41. static const char * SKIN_DICTIONARY_FILENAME = "skindictionary.ini";
  42. static const char * CURR_SKIN_REG_VALUE = "CurrSkinPackage";
  43. //////////////////////////////////////////////////////////////////////
  44. // Static member initialization
  45. //////////////////////////////////////////////////////////////////////
  46. DynamicVectorClass<SkinPackageClass> SkinPackageMgrClass::PackageList;
  47. SkinPackageClass SkinPackageMgrClass::CurrentPackage;
  48. /////////////////////////////////////////////////////////////////////
  49. //
  50. // Initialize
  51. //
  52. //////////////////////////////////////////////////////////////////////
  53. void
  54. SkinPackageMgrClass::Initialize (void)
  55. {
  56. Shutdown ();
  57. //
  58. // Get the currently selected package name from the registry
  59. //
  60. RegistryClass registry (APPLICATION_SUB_KEY_NAME_OPTIONS);
  61. if (registry.Is_Valid ()) {
  62. //
  63. // Get the current package name from the registry
  64. //
  65. StringClass package_filename;
  66. registry.Get_String (CURR_SKIN_REG_VALUE, package_filename, "default.pkg");
  67. //
  68. // Initialize the current package
  69. //
  70. CurrentPackage.Set_Package_Filename (package_filename);
  71. }
  72. return ;
  73. }
  74. /////////////////////////////////////////////////////////////////////
  75. //
  76. // Shutdown
  77. //
  78. //////////////////////////////////////////////////////////////////////
  79. void
  80. SkinPackageMgrClass::Shutdown (void)
  81. {
  82. Reset_List ();
  83. return ;
  84. }
  85. //////////////////////////////////////////////////////////////////////
  86. //
  87. // Build_List
  88. //
  89. //////////////////////////////////////////////////////////////////////
  90. void
  91. SkinPackageMgrClass::Build_List (void)
  92. {
  93. WIN32_FIND_DATA find_info = { 0 };
  94. BOOL keep_going = TRUE;
  95. HANDLE file_find = NULL;
  96. //
  97. // Build a list of all the saved games we know about
  98. //
  99. for (file_find = ::FindFirstFile ("*.pkg", &find_info);
  100. (file_find != INVALID_HANDLE_VALUE) && keep_going;
  101. keep_going = ::FindNextFile (file_find, &find_info))
  102. {
  103. //
  104. // Create the package from the data in this mix file
  105. //
  106. SkinPackageClass package;
  107. package.Set_Package_Filename (find_info.cFileName);
  108. //
  109. // Add the package to our list
  110. //
  111. PackageList.Add (package);
  112. }
  113. if (file_find != INVALID_HANDLE_VALUE) {
  114. ::FindClose (file_find);
  115. }
  116. return ;
  117. }
  118. //////////////////////////////////////////////////////////////////////
  119. //
  120. // Reset_List
  121. //
  122. //////////////////////////////////////////////////////////////////////
  123. void
  124. SkinPackageMgrClass::Reset_List (void)
  125. {
  126. PackageList.Delete_All ();
  127. return ;
  128. }
  129. //////////////////////////////////////////////////////////////////////
  130. //
  131. // Set_Current_Package
  132. //
  133. //////////////////////////////////////////////////////////////////////
  134. void
  135. SkinPackageMgrClass::Set_Current_Package (const char *package_filename)
  136. {
  137. //
  138. // Initialize the current package
  139. //
  140. CurrentPackage.Set_Package_Filename (package_filename);
  141. //
  142. // Write the name of hte package to the registry
  143. //
  144. RegistryClass registry (APPLICATION_SUB_KEY_NAME_OPTIONS);
  145. if (registry.Is_Valid ()) {
  146. registry.Set_String (CURR_SKIN_REG_VALUE, package_filename);
  147. }
  148. return ;
  149. }
  150. //////////////////////////////////////////////////////////////////////
  151. //
  152. // Set_Current_Package
  153. //
  154. //////////////////////////////////////////////////////////////////////
  155. void
  156. SkinPackageMgrClass::Set_Current_Package (int index)
  157. {
  158. Set_Current_Package (PackageList[index].Get_Package_Filename ());
  159. return ;
  160. }