@@ -77,10 +77,11 @@ v 4.0.0.6 2018-12-09 Zealot fixed crash after mission saved
7777
7878#define LOG_NAME "ocaplog\\ocap-main.%datetime{%Y%M%d_%H%m%s}.log"
7979#define LOG_NAME_EXT "ocaplog\\ocap-ext.%datetime{%Y%M%d_%H%m%s}.log"
80+ #define REPLAY_TMP "%Y_%m_%d__%H_%M_%S_"
8081
8182#define REPLAY_FILEMASK "%Y_%m_%d__%H_%M_"
82- #define CONFIG_NAME L" OcapReplaySaver2.cfg.json"
83- #define CONFIG_NAME_SAMPLE L" OcapReplaySaver2.cfg.json.sample"
83+ #define CONFIG_NAME "ocap\\ OcapReplaySaver2.cfg.json"
84+ #define CONFIG_NAME_SAMPLE "ocap\\ OcapReplaySaver2.cfg.json.sample"
8485
8586#define CMD_NEW_UNIT ":NEW:UNIT:" // новый юнит зарегистрирована ocap
8687#define CMD_NEW_VEH ":NEW:VEH:" // новая техника зарегистрирована ocap
@@ -330,12 +331,22 @@ void prepareMarkerFrames(int frames) {
330331
331332}
332333
334+ std::string getFileName(const char * mask, const char * name, const char * ext)
335+ {
336+ std::time_t t = std::time(nullptr);
337+ std::tm tm;
338+ localtime_s(&tm, &t);
339+ std::stringstream ss;
340+ ss << std::put_time(&tm, mask) << name << ".json";
341+ return ss.str();
342+ }
343+
344+ std::string generateResultFileName(const std::string &name) {
345+ return getFileName(REPLAY_FILEMASK, name.c_str(), ".json");
346+ }
333347
334348std::string saveCurrentReplayToTempFile() {
335- char tPath[MAX_PATH] = { 0 };
336- char tName[MAX_PATH] = { 0 };
337- GetTempPathA(MAX_PATH, tPath);
338- GetTempFileNameA(tPath, "ocap", 0, tName);
349+ std::string tName = "ocap\\" + getFileName(REPLAY_TMP, "ocap", ".tmp");
339350
340351 fstream currentReplay(tName, fstream::out | fstream::binary);
341352 if (!currentReplay.is_open()) {
@@ -353,32 +364,18 @@ std::string saveCurrentReplayToTempFile() {
353364
354365}
355366
356- std::string generateResultFileName(const std::string &name) {
357- std::time_t t = std::time(nullptr);
358- std::tm tm;
359- localtime_s(&tm, &t);
360- std::stringstream ss;
361- ss << std::put_time(&tm, REPLAY_FILEMASK) << name << ".json";
362- return ss.str();
363- }
364367
365368#pragma region Вычитка конфига
366- void readWriteConfig(HMODULE hModule) {
367- wchar_t szPath[MAX_PATH], szDirPath[_MAX_DIR];
368- GetModuleFileNameW(hModule, szPath, MAX_PATH);
369- _wsplitpath_s(szPath, 0, 0, szDirPath, _MAX_DIR, 0, 0, 0, 0);
370- wstring path(szDirPath), path_sample(szDirPath);
371- path += CONFIG_NAME;
372- path_sample += CONFIG_NAME_SAMPLE;
373- if (!std::ifstream(path_sample)) {
374- LOG(INFO) << "Creating sample config file: " << converter.to_bytes(path_sample);
369+ void readWriteConfig() {
370+ if (!std::ifstream(CONFIG_NAME_SAMPLE)) {
371+ LOG(INFO) << "Creating sample config file: " << CONFIG_NAME_SAMPLE;
375372 json j = { { "addFileUrl", config.addFileUrl },{ "dbInsertUrl", config.dbInsertUrl },{ "httpRequestTimeout", config.httpRequestTimeout }, {"traceLog", config.traceLog} };
376- std::ofstream out(path_sample , ofstream::out | ofstream::binary);
373+ std::ofstream out(CONFIG_NAME_SAMPLE , ofstream::out | ofstream::binary);
377374 out << j.dump(4) << endl;
378375 }
379- LOG(INFO) << "Trying to read config file:" << converter.to_bytes(path) ;
376+ LOG(INFO) << "Trying to read config file:" << CONFIG_NAME ;
380377 bool cfgOpened = false;
381- ifstream cfg(path , ifstream::in | ifstream::binary);
378+ ifstream cfg(CONFIG_NAME , ifstream::in | ifstream::binary);
382379
383380 json jcfg;
384381 if (!cfg.is_open()) {
@@ -886,7 +883,7 @@ BOOL APIENTRY DllMain(HMODULE hModule,
886883 {
887884 case DLL_PROCESS_ATTACH: {
888885 initialize_logger(true);
889- readWriteConfig(hModule );
886+ readWriteConfig();
890887 break;
891888 }
892889
0 commit comments