diaglog.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/diaglog.cpp $*
  25. * *
  26. * $Author:: Patrick $*
  27. * *
  28. * $Modtime:: 1/02/02 3:35p $*
  29. * *
  30. * $Revision:: 5 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "diaglog.h"
  36. #include "ffactory.h"
  37. #include "wwfile.h"
  38. #include "timemgr.h"
  39. #include <WTYPES.H> // for SYSTEMTIME
  40. FileClass * _DiagLogFile = NULL;
  41. /*
  42. **
  43. */
  44. void DiagLogClass::Init( void )
  45. {
  46. FileClass * file = NULL;
  47. for ( int i = 0; i < 100; i++ ) {
  48. StringClass filename;
  49. filename.Format( "DIAGLOG%03d.TXT", i );
  50. file = _TheWritingFileFactory->Get_File( filename );
  51. if ( file == NULL || !file->Is_Available() ) {
  52. break;
  53. }
  54. _TheWritingFileFactory->Return_File( file );
  55. file = NULL;
  56. }
  57. if ( file != NULL ) {
  58. file->Close();
  59. file->Open(FileClass::WRITE);
  60. _DiagLogFile = file;
  61. }
  62. SYSTEMTIME dt;
  63. ::GetSystemTime( &dt );
  64. StringClass dt_string;
  65. dt_string.Format( "%02d/%02d/%02d %02d:%02d:%02d", dt.wMonth, dt.wDay, dt.wYear, dt.wHour, dt.wMinute, dt.wSecond );
  66. DIAG_LOG(( "OPEN", "%s", (const char *)dt_string ));
  67. }
  68. void DiagLogClass::Shutdown( void )
  69. {
  70. if ( _DiagLogFile != NULL ) {
  71. SYSTEMTIME dt;
  72. ::GetSystemTime( &dt );
  73. StringClass dt_string;
  74. dt_string.Format( "%02d/%02d/%02d %02d:%02d:%02d", dt.wMonth, dt.wDay, dt.wYear, dt.wHour, dt.wMinute, dt.wSecond );
  75. DIAG_LOG(( "CLOS", "%s", (const char *)dt_string ));
  76. _DiagLogFile->Close();
  77. _TheWritingFileFactory->Return_File( _DiagLogFile );
  78. _DiagLogFile = NULL;
  79. }
  80. }
  81. void DiagLogClass::Log_Timed( const char * type, const char * format, ... )
  82. {
  83. if ( _DiagLogFile != NULL ) {
  84. va_list arg_list;
  85. va_start (arg_list, format);
  86. StringClass data;
  87. data.Format_Args( format, arg_list );
  88. va_end (arg_list);
  89. StringClass line;
  90. float time = TimeManager::Get_Total_Seconds();
  91. line.Format( "%s; %1.2f; %s%c%c", type, time, data, 0x0D, 0x0A );
  92. _DiagLogFile->Write( line, ::strlen( line ) );
  93. }
  94. }