| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- /*
- ** Command & Conquer Renegade(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /***********************************************************************************************
- *** 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 ***
- ***********************************************************************************************
- * *
- * Project Name : LevelEdit *
- * *
- * $Archive:: /Commando/Code/Tools/LevelEdit/PresetLogger.cpp $*
- * *
- * Author:: Patrick Smith *
- * *
- * $Modtime:: 6/14/02 6:20p $*
- * *
- * $Revision:: 4 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "stdafx.h"
- #include "presetlogger.h"
- #include "textfile.h"
- #include "wwstring.h"
- #include "preset.h"
- #include "definitionfactorymgr.h"
- #include "definitionfactory.h"
- //////////////////////////////////////////////////////////////////////////
- //
- // Log_Created
- //
- //////////////////////////////////////////////////////////////////////////
- void
- PresetLoggerClass::Log_Created (PresetClass *preset)
- {
- //
- // Try to open the log file
- //
- TextFileClass file;
- if (Open_Log_File (file)) {
- //
- // Lookup the users name
- //
- char computer_name[256];
- DWORD size = sizeof (computer_name);
- ::GetComputerName (computer_name, &size);
- //
- // Determine what type of preset this is
- //
- StringClass type_name;
- DefinitionFactoryClass *factory = DefinitionFactoryMgrClass::Find_Factory (preset->Get_Class_ID ());
- if (factory != NULL) {
- type_name = factory->Get_Name ();
- }
-
- //
- // Build a log entry with relevant information about the operation
- //
- StringClass message;
- message.Format ("(%s) Created: %s, Type: %s", computer_name, (const char *)preset->Get_Name (), (const char *)type_name);
- //
- // Write the entry to the end of the log
- //
- file.Seek (0, SEEK_END);
- file.Write_Line (message);
- //
- // Close the file
- //
- file.Close ();
- }
- return ;
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Log_Moved
- //
- //////////////////////////////////////////////////////////////////////////
- void
- PresetLoggerClass::Log_Moved (PresetClass *preset, const char *new_parent_name)
- {
- //
- // Try to open the log file
- //
- TextFileClass file;
- if (Open_Log_File (file)) {
-
- //
- // Determine what the parent's name should be
- //
- CString real_parent_name = new_parent_name;
- if (new_parent_name == NULL) {
- real_parent_name = "Root";
- }
- //
- // Lookup the users name
- //
- char computer_name[256];
- DWORD size = sizeof (computer_name);
- ::GetComputerName (computer_name, &size);
- //
- // Write an entry to the end of the log
- //
- StringClass message;
- message.Format ("(%s) Moved: %s. New Parent: %s", computer_name, (const char *)preset->Get_Name (), (const char *)real_parent_name);
- file.Seek (0, SEEK_END);
- file.Write_Line (message);
- //
- // Close the file
- //
- file.Close ();
- }
- return ;
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Log_Renamed
- //
- //////////////////////////////////////////////////////////////////////////
- void
- PresetLoggerClass::Log_Renamed (const char *old_name, const char *new_name)
- {
- //
- // Try to open the log file
- //
- TextFileClass file;
- if (Open_Log_File (file)) {
-
- //
- // Lookup the users name
- //
- char computer_name[256];
- DWORD size = sizeof (computer_name);
- ::GetComputerName (computer_name, &size);
- //
- // Write an entry to the end of the log
- //
- StringClass message;
- message.Format ("(%s) Renamed: Old Name: %s, New Name: %s", computer_name, old_name, new_name);
- file.Seek (0, SEEK_END);
- file.Write_Line (message);
- //
- // Close the file
- //
- file.Close ();
- }
- return ;
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Log_Deleted
- //
- //////////////////////////////////////////////////////////////////////////
- void
- PresetLoggerClass::Log_Deleted (const char *preset_name)
- {
- //
- // Try to open the log file
- //
- TextFileClass file;
- if (Open_Log_File (file)) {
- //
- // Lookup the users name
- //
- char computer_name[256];
- DWORD size = sizeof (computer_name);
- ::GetComputerName (computer_name, &size);
-
- //
- // Write an entry to the end of the log
- //
- StringClass message;
- message.Format ("(%s) Deleted: %s", computer_name, preset_name);
- file.Seek (0, SEEK_END);
- file.Write_Line (message);
- //
- // Close the file
- //
- file.Close ();
- }
- return ;
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Log_File_Reference_Changed
- //
- //////////////////////////////////////////////////////////////////////////
- void
- PresetLoggerClass::Log_File_Reference_Changed
- (
- PresetClass * preset,
- const char * param_name,
- const char * new_value
- )
- {
- //
- // Try to open the log file
- //
- TextFileClass file;
- if (Open_Log_File (file)) {
-
- //
- // Write an entry to the end of the log
- //
- StringClass message;
- message.Format ("Reference Changed: Preset: %s. Param: %s. Value: %s", (const char *)preset->Get_Name (), param_name, new_value);
- file.Seek (0, SEEK_END);
- file.Write_Line (message);
- //
- // Close the file
- //
- file.Close ();
- }
- return ;
- }
- //////////////////////////////////////////////////////////////////////////
- //
- // Open_Log_File
- //
- //////////////////////////////////////////////////////////////////////////
- bool
- PresetLoggerClass::Open_Log_File (TextFileClass &file_obj)
- {
- bool retval = false;
- HANDLE file = INVALID_HANDLE_VALUE;
-
- //
- // Try 10 times to open the file
- //
- #ifndef PUBLIC_EDITOR_VER
- for (int index = 0; index < 10; index ++) {
-
- //
- // Try to open the file exclusively
- //
- file = ::CreateFile ( "\\\\mobius\\project7\\projects\\renegade\\asset management\\logs\\presets.log",
- GENERIC_WRITE,
- FILE_SHARE_READ,
- NULL,
- OPEN_ALWAYS,
- 0L,
- NULL);
- //
- // If we succeeded then break out of the loop
- //
- if (file != INVALID_HANDLE_VALUE) {
- break;
- }
- //
- // Wait a quarter of a second before we try again.
- //
- ::Sleep (250);
- }
- #endif //PUBLIC_EDITOR_VER
-
- if (file != INVALID_HANDLE_VALUE) {
- file_obj.Attach (file);
- retval = true;
- }
-
- return retval;
- }
|