PresetLogger.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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/PresetLogger.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 6/14/02 6:20p $*
  29. * *
  30. * $Revision:: 4 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "stdafx.h"
  36. #include "presetlogger.h"
  37. #include "textfile.h"
  38. #include "wwstring.h"
  39. #include "preset.h"
  40. #include "definitionfactorymgr.h"
  41. #include "definitionfactory.h"
  42. //////////////////////////////////////////////////////////////////////////
  43. //
  44. // Log_Created
  45. //
  46. //////////////////////////////////////////////////////////////////////////
  47. void
  48. PresetLoggerClass::Log_Created (PresetClass *preset)
  49. {
  50. //
  51. // Try to open the log file
  52. //
  53. TextFileClass file;
  54. if (Open_Log_File (file)) {
  55. //
  56. // Lookup the users name
  57. //
  58. char computer_name[256];
  59. DWORD size = sizeof (computer_name);
  60. ::GetComputerName (computer_name, &size);
  61. //
  62. // Determine what type of preset this is
  63. //
  64. StringClass type_name;
  65. DefinitionFactoryClass *factory = DefinitionFactoryMgrClass::Find_Factory (preset->Get_Class_ID ());
  66. if (factory != NULL) {
  67. type_name = factory->Get_Name ();
  68. }
  69. //
  70. // Build a log entry with relevant information about the operation
  71. //
  72. StringClass message;
  73. message.Format ("(%s) Created: %s, Type: %s", computer_name, (const char *)preset->Get_Name (), (const char *)type_name);
  74. //
  75. // Write the entry to the end of the log
  76. //
  77. file.Seek (0, SEEK_END);
  78. file.Write_Line (message);
  79. //
  80. // Close the file
  81. //
  82. file.Close ();
  83. }
  84. return ;
  85. }
  86. //////////////////////////////////////////////////////////////////////////
  87. //
  88. // Log_Moved
  89. //
  90. //////////////////////////////////////////////////////////////////////////
  91. void
  92. PresetLoggerClass::Log_Moved (PresetClass *preset, const char *new_parent_name)
  93. {
  94. //
  95. // Try to open the log file
  96. //
  97. TextFileClass file;
  98. if (Open_Log_File (file)) {
  99. //
  100. // Determine what the parent's name should be
  101. //
  102. CString real_parent_name = new_parent_name;
  103. if (new_parent_name == NULL) {
  104. real_parent_name = "Root";
  105. }
  106. //
  107. // Lookup the users name
  108. //
  109. char computer_name[256];
  110. DWORD size = sizeof (computer_name);
  111. ::GetComputerName (computer_name, &size);
  112. //
  113. // Write an entry to the end of the log
  114. //
  115. StringClass message;
  116. message.Format ("(%s) Moved: %s. New Parent: %s", computer_name, (const char *)preset->Get_Name (), (const char *)real_parent_name);
  117. file.Seek (0, SEEK_END);
  118. file.Write_Line (message);
  119. //
  120. // Close the file
  121. //
  122. file.Close ();
  123. }
  124. return ;
  125. }
  126. //////////////////////////////////////////////////////////////////////////
  127. //
  128. // Log_Renamed
  129. //
  130. //////////////////////////////////////////////////////////////////////////
  131. void
  132. PresetLoggerClass::Log_Renamed (const char *old_name, const char *new_name)
  133. {
  134. //
  135. // Try to open the log file
  136. //
  137. TextFileClass file;
  138. if (Open_Log_File (file)) {
  139. //
  140. // Lookup the users name
  141. //
  142. char computer_name[256];
  143. DWORD size = sizeof (computer_name);
  144. ::GetComputerName (computer_name, &size);
  145. //
  146. // Write an entry to the end of the log
  147. //
  148. StringClass message;
  149. message.Format ("(%s) Renamed: Old Name: %s, New Name: %s", computer_name, old_name, new_name);
  150. file.Seek (0, SEEK_END);
  151. file.Write_Line (message);
  152. //
  153. // Close the file
  154. //
  155. file.Close ();
  156. }
  157. return ;
  158. }
  159. //////////////////////////////////////////////////////////////////////////
  160. //
  161. // Log_Deleted
  162. //
  163. //////////////////////////////////////////////////////////////////////////
  164. void
  165. PresetLoggerClass::Log_Deleted (const char *preset_name)
  166. {
  167. //
  168. // Try to open the log file
  169. //
  170. TextFileClass file;
  171. if (Open_Log_File (file)) {
  172. //
  173. // Lookup the users name
  174. //
  175. char computer_name[256];
  176. DWORD size = sizeof (computer_name);
  177. ::GetComputerName (computer_name, &size);
  178. //
  179. // Write an entry to the end of the log
  180. //
  181. StringClass message;
  182. message.Format ("(%s) Deleted: %s", computer_name, preset_name);
  183. file.Seek (0, SEEK_END);
  184. file.Write_Line (message);
  185. //
  186. // Close the file
  187. //
  188. file.Close ();
  189. }
  190. return ;
  191. }
  192. //////////////////////////////////////////////////////////////////////////
  193. //
  194. // Log_File_Reference_Changed
  195. //
  196. //////////////////////////////////////////////////////////////////////////
  197. void
  198. PresetLoggerClass::Log_File_Reference_Changed
  199. (
  200. PresetClass * preset,
  201. const char * param_name,
  202. const char * new_value
  203. )
  204. {
  205. //
  206. // Try to open the log file
  207. //
  208. TextFileClass file;
  209. if (Open_Log_File (file)) {
  210. //
  211. // Write an entry to the end of the log
  212. //
  213. StringClass message;
  214. message.Format ("Reference Changed: Preset: %s. Param: %s. Value: %s", (const char *)preset->Get_Name (), param_name, new_value);
  215. file.Seek (0, SEEK_END);
  216. file.Write_Line (message);
  217. //
  218. // Close the file
  219. //
  220. file.Close ();
  221. }
  222. return ;
  223. }
  224. //////////////////////////////////////////////////////////////////////////
  225. //
  226. // Open_Log_File
  227. //
  228. //////////////////////////////////////////////////////////////////////////
  229. bool
  230. PresetLoggerClass::Open_Log_File (TextFileClass &file_obj)
  231. {
  232. bool retval = false;
  233. HANDLE file = INVALID_HANDLE_VALUE;
  234. //
  235. // Try 10 times to open the file
  236. //
  237. #ifndef PUBLIC_EDITOR_VER
  238. for (int index = 0; index < 10; index ++) {
  239. //
  240. // Try to open the file exclusively
  241. //
  242. file = ::CreateFile ( "\\\\mobius\\project7\\projects\\renegade\\asset management\\logs\\presets.log",
  243. GENERIC_WRITE,
  244. FILE_SHARE_READ,
  245. NULL,
  246. OPEN_ALWAYS,
  247. 0L,
  248. NULL);
  249. //
  250. // If we succeeded then break out of the loop
  251. //
  252. if (file != INVALID_HANDLE_VALUE) {
  253. break;
  254. }
  255. //
  256. // Wait a quarter of a second before we try again.
  257. //
  258. ::Sleep (250);
  259. }
  260. #endif //PUBLIC_EDITOR_VER
  261. if (file != INVALID_HANDLE_VALUE) {
  262. file_obj.Attach (file);
  263. retval = true;
  264. }
  265. return retval;
  266. }