Ticket #3255: t3255_use_datetime_in_simlog_directory_v2.patch
File t3255_use_datetime_in_simlog_directory_v2.patch, 2.0 KB (added by , 9 years ago) |
---|
-
source/ps/Replay.cpp
31 31 #include "scriptinterface/ScriptInterface.h" 32 32 #include "scriptinterface/ScriptStats.h" 33 33 #include "simulation2/Simulation2.h" 34 34 #include "simulation2/helpers/SimulationCommand.h" 35 35 36 #include <ctime> 36 37 #include <sstream> 37 38 #include <fstream> 38 39 #include <iomanip> 39 40 40 #if MSC_VERSION41 #include <process.h>42 #define getpid _getpid // use the non-deprecated function name43 #endif44 45 41 static std::string Hexify(const std::string& s) 46 42 { 47 43 std::stringstream str; 48 44 str << std::hex; 49 45 for (size_t i = 0; i < s.size(); ++i) … … 52 48 } 53 49 54 50 CReplayLogger::CReplayLogger(ScriptInterface& scriptInterface) : 55 51 m_ScriptInterface(scriptInterface) 56 52 { 57 // Construct the directory name based on the PID, to be relatively unique. 58 // Append "-1", "-2" etc if we run multiple matches in a single session, 59 // to avoid accidentally overwriting earlier logs. 60 61 std::wstringstream name; 62 name << getpid(); 63 64 static int run = -1; 65 if (++run) 66 name << "-" << run; 53 // Get current date 54 time_t t = time(NULL); 55 struct tm* now = localtime(&t); 56 char date[12]; 57 sprintf_s(date, ARRAY_SIZE(date), "%04d-%02d-%02d_", 1900+now->tm_year, 1+now->tm_mon, now->tm_mday); 58 59 // Construct a unique directory name based on date and sequential number per date 60 int i = 1; 61 OsPath path; 62 std::stringstream pathname; 63 do 64 { 65 pathname.str(""); 66 pathname.clear(); 67 pathname << date << i++; 68 path = psLogDir() / L"sim_log" / pathname.str() / L"commands.txt"; 69 } while(DirectoryExists(path.Parent())); 67 70 68 OsPath path = psLogDir() / L"sim_log" / name.str() / L"commands.txt";71 // Create directory and commands.txt 69 72 CreateDirectories(path.Parent(), 0700); 70 73 m_Stream = new std::ofstream(OsString(path).c_str(), std::ofstream::out | std::ofstream::trunc); 71 74 } 72 75 73 76 CReplayLogger::~CReplayLogger()