reportmgr.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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/reportmgr.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 9/10/01 8:53a $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "stdafx.h"
  36. #include "reportmgr.h"
  37. #include "textfile.h"
  38. #include "nodemgr.h"
  39. #include "preset.h"
  40. #include "listtypes.h"
  41. #include "hashtemplate.h"
  42. #include "node.h"
  43. #include "filemgr.h"
  44. #include "translatedb.h"
  45. #include "translateobj.h"
  46. //////////////////////////////////////////////////////////////////////
  47. // Static member initialization
  48. //////////////////////////////////////////////////////////////////////
  49. HashTemplateClass<StringClass, bool> ReportMgrClass::FilenameHash;
  50. //////////////////////////////////////////////////////////////////////
  51. //
  52. // Export_File_Usage_Report
  53. //
  54. //////////////////////////////////////////////////////////////////////
  55. void
  56. ReportMgrClass::Export_File_Usage_Report (const char *filename)
  57. {
  58. //
  59. // Open the text file
  60. //
  61. TextFileClass file;
  62. file.Set_Name (filename);
  63. if (file.Open (FileClass::WRITE)) {
  64. STRING_LIST file_list;
  65. file_list.Set_Growth_Step (500);
  66. //
  67. // Loop over all the nodes in the current level
  68. //
  69. for ( NodeClass *node = NodeMgrClass::Get_First ();
  70. node != NULL;
  71. node = NodeMgrClass::Get_Next (node))
  72. {
  73. PresetClass *preset = node->Get_Preset ();
  74. if (preset != NULL) {
  75. //
  76. // Build a list of definitions this preset depends on
  77. //
  78. DEFINITION_LIST definition_list;
  79. preset->Collect_Definitions (definition_list);
  80. //
  81. // Add all the files from these definitions to our list
  82. //
  83. for (int index = 0; index < definition_list.Count (); index ++) {
  84. Add_Definition_Dependencies (definition_list[index], file_list);
  85. }
  86. }
  87. }
  88. //
  89. // Create a temporary hash that we can use to determine if
  90. // a filename has already been written to the file...
  91. //
  92. HashTemplateClass<StringClass, bool> filename_hash;
  93. //
  94. // Now add all W3D file-depenedencies to this list
  95. //
  96. for (int index = 0; index < file_list.Count (); index ++) {
  97. StringClass filename (file_list[index], true);
  98. //
  99. // If this is a W3D file, then enumerate its dependencies...
  100. //
  101. if (::Is_W3D_Filename (filename)) {
  102. UniqueListClass<CString> dep_list;
  103. ::Get_File_Mgr ()->Build_Dependency_List (filename, dep_list);
  104. for (int new_index = 0; new_index < dep_list.Count (); new_index ++) {
  105. CString rel_path = ::Get_File_Mgr ()->Make_Relative_Path (dep_list[new_index]);
  106. StringClass lower_name (rel_path, true);
  107. ::strlwr (lower_name.Peek_Buffer ());
  108. //
  109. // Don't add this file to the list if its already there
  110. //
  111. if (filename_hash.Exists (lower_name) == false) {
  112. file_list.Add (CString (lower_name));
  113. filename_hash.Insert (lower_name, true);
  114. }
  115. }
  116. }
  117. }
  118. //
  119. // Reset the has
  120. //
  121. filename_hash.Remove_All ();
  122. //
  123. // Now write all the file names to the text file
  124. //
  125. for (index = 0; index < file_list.Count (); index ++) {
  126. StringClass lower_name (file_list[index], true);
  127. ::strlwr (lower_name.Peek_Buffer ());
  128. //
  129. // Only write this filename to the file if it
  130. // hasn't already been written
  131. //
  132. if (filename_hash.Exists (lower_name) == false) {
  133. file.Write_Line (lower_name);
  134. filename_hash.Insert (lower_name, true);
  135. }
  136. }
  137. }
  138. return ;
  139. }
  140. ///////////////////////////////////////////////////////////////////////
  141. //
  142. // Add_Definition_Dependencies
  143. //
  144. ///////////////////////////////////////////////////////////////////////
  145. void
  146. ReportMgrClass::Add_Definition_Dependencies (DefinitionClass *definition, STRING_LIST &list)
  147. {
  148. if (definition == NULL) {
  149. return ;
  150. }
  151. //
  152. // Find all 'filename' parameters to this definition.
  153. //
  154. int count = definition->Get_Parameter_Count ();
  155. for (int index = 0; index < count; index ++) {
  156. ParameterClass *parameter = definition->Lock_Parameter (index);
  157. if ( parameter->Get_Type () == ParameterClass::TYPE_FILENAME ||
  158. parameter->Get_Type () == ParameterClass::TYPE_SOUND_FILENAME) {
  159. //
  160. // Add this filename dependency to the list
  161. //
  162. CString filename = ((FilenameParameterClass *)parameter)->Get_String ();
  163. CString full_path = ::Get_File_Mgr ()->Make_Full_Path (filename);
  164. if ( ::Get_File_Mgr ()->Is_Path_Valid (full_path) &&
  165. ::Get_File_Mgr ()->Is_Empty_Path (full_path) == false)
  166. {
  167. CString lower_filename = ::Get_File_Mgr ()->Make_Relative_Path (full_path);
  168. lower_filename.MakeLower ();
  169. //
  170. // Add this filename to the list (if its not already there)
  171. //
  172. if (FilenameHash.Exists (StringClass (lower_filename, true)) == false) {
  173. list.Add (lower_filename);
  174. FilenameHash.Insert (StringClass (lower_filename, true), true);
  175. }
  176. }
  177. } else if (parameter->Get_Type () == ParameterClass::TYPE_MODELDEFINITIONID) {
  178. //
  179. // If this is param references a physics-definition, then add all its dependencies as well..
  180. //
  181. DefinitionClass *phys_def = NULL;
  182. phys_def = DefinitionMgrClass::Find_Definition (((ModelDefParameterClass *)parameter)->Get_Value (), false);
  183. Add_Definition_Dependencies (phys_def, list);
  184. } else if (parameter->As_DefParameterClass () != NULL) {
  185. DefinitionClass *sub_def = DefinitionMgrClass::Find_Definition (parameter->As_DefParameterClass ()->Get_Value (), false);
  186. Add_Definition_Dependencies (sub_def, list);
  187. }
  188. }
  189. return ;
  190. }
  191. //////////////////////////////////////////////////////////////////////
  192. //
  193. // Export_Missing_Translation_Report
  194. //
  195. //////////////////////////////////////////////////////////////////////
  196. void
  197. ReportMgrClass::Export_Missing_Translation_Report (const char *filename, int lang_id)
  198. {
  199. //
  200. // Open the text file
  201. //
  202. TextFileClass file;
  203. file.Set_Name (filename);
  204. if (file.Open (FileClass::WRITE)) {
  205. //
  206. // Loop over all the string objects
  207. //
  208. int count = TranslateDBClass::Get_Object_Count ();
  209. for (int index = 0; index < count; index ++) {
  210. //
  211. // Does this string contain the necessary translation?
  212. //
  213. TDBObjClass *object = TranslateDBClass::Get_Object (index);
  214. if ( object != NULL &&
  215. object->As_StringTwiddlerClass () == NULL &&
  216. object->Contains_Translation (lang_id) == false)
  217. {
  218. file.Write_Line (object->Get_ID_Desc ());
  219. }
  220. }
  221. }
  222. return ;
  223. }