Ticket #3255: t3255_use_datetime_in_simlog_directory.patch

File t3255_use_datetime_in_simlog_directory.patch, 1.8 KB (added by elexis, 9 years ago)
  • source/ps/Replay.cpp

     
    3131#include "scriptinterface/ScriptInterface.h"
    3232#include "scriptinterface/ScriptStats.h"
    3333#include "simulation2/Simulation2.h"
    3434#include "simulation2/helpers/SimulationCommand.h"
    3535
     36#include <ctime>
    3637#include <sstream>
    3738#include <fstream>
    3839#include <iomanip>
    3940
    4041#if MSC_VERSION
    4142#include <process.h>
    42 #define getpid _getpid // use the non-deprecated function name
    4343#endif
    4444
    4545static std::string Hexify(const std::string& s)
    4646{
    4747    std::stringstream str;
     
    5252}
    5353
    5454CReplayLogger::CReplayLogger(ScriptInterface& scriptInterface) :
    5555    m_ScriptInterface(scriptInterface)
    5656{
    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;
     57    // Get current date and time
     58    time_t t = time(NULL);
     59    struct tm* now = localtime(&t);
     60    char currentDateTime[20];
     61    sprintf_s(currentDateTime, ARRAY_SIZE(currentDateTime), "%04d-%02d-%02d_%02d-%02d-%02d", 1900+now->tm_year, 1+now->tm_mon, now->tm_mday, now->tm_hour, now->tm_min, now->tm_sec);
    6762
    68     OsPath path = psLogDir() / L"sim_log" / name.str() / L"commands.txt";
     63    // Create commands.txt
     64    OsPath path = psLogDir() / L"sim_log" / currentDateTime / L"commands.txt";
    6965    CreateDirectories(path.Parent(), 0700);
    7066    m_Stream = new std::ofstream(OsString(path).c_str(), std::ofstream::out | std::ofstream::trunc);
    7167}
    7268
    7369CReplayLogger::~CReplayLogger()