Skip to content

Commit

Permalink
remove windows specific code
Browse files Browse the repository at this point in the history
  • Loading branch information
Zealot111 committed Jan 15, 2019
1 parent f4a6ee9 commit 4bcb3c2
Showing 1 changed file with 24 additions and 27 deletions.
51 changes: 24 additions & 27 deletions extension/OcapReplaySaver2/OcapReplaySaver2/OcapReplaySaver2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ v 4.0.0.6 2018-12-09 Zealot fixed crash after mission saved

#define LOG_NAME "ocaplog\\ocap-main.%datetime{%Y%M%d_%H%m%s}.log"
#define LOG_NAME_EXT "ocaplog\\ocap-ext.%datetime{%Y%M%d_%H%m%s}.log"
#define REPLAY_TMP "%Y_%m_%d__%H_%M_%S_"

#define REPLAY_FILEMASK "%Y_%m_%d__%H_%M_"
#define CONFIG_NAME L"OcapReplaySaver2.cfg.json"
#define CONFIG_NAME_SAMPLE L"OcapReplaySaver2.cfg.json.sample"
#define CONFIG_NAME "ocap\\OcapReplaySaver2.cfg.json"
#define CONFIG_NAME_SAMPLE "ocap\\OcapReplaySaver2.cfg.json.sample"

#define CMD_NEW_UNIT ":NEW:UNIT:" // новый юнит зарегистрирована ocap
#define CMD_NEW_VEH ":NEW:VEH:" // новая техника зарегистрирована ocap
Expand Down Expand Up @@ -330,12 +331,22 @@ void prepareMarkerFrames(int frames) {

}

std::string getFileName(const char * mask, const char * name, const char * ext)
{
std::time_t t = std::time(nullptr);
std::tm tm;
localtime_s(&tm, &t);
std::stringstream ss;
ss << std::put_time(&tm, mask) << name << ".json";
return ss.str();
}

std::string generateResultFileName(const std::string &name) {
return getFileName(REPLAY_FILEMASK, name.c_str(), ".json");
}

std::string saveCurrentReplayToTempFile() {
char tPath[MAX_PATH] = { 0 };
char tName[MAX_PATH] = { 0 };
GetTempPathA(MAX_PATH, tPath);
GetTempFileNameA(tPath, "ocap", 0, tName);
std::string tName = "ocap\\" + getFileName(REPLAY_TMP, "ocap", ".tmp");

fstream currentReplay(tName, fstream::out | fstream::binary);
if (!currentReplay.is_open()) {
Expand All @@ -353,32 +364,18 @@ std::string saveCurrentReplayToTempFile() {

}

std::string generateResultFileName(const std::string &name) {
std::time_t t = std::time(nullptr);
std::tm tm;
localtime_s(&tm, &t);
std::stringstream ss;
ss << std::put_time(&tm, REPLAY_FILEMASK) << name << ".json";
return ss.str();
}

#pragma region Вычитка конфига
void readWriteConfig(HMODULE hModule) {
wchar_t szPath[MAX_PATH], szDirPath[_MAX_DIR];
GetModuleFileNameW(hModule, szPath, MAX_PATH);
_wsplitpath_s(szPath, 0, 0, szDirPath, _MAX_DIR, 0, 0, 0, 0);
wstring path(szDirPath), path_sample(szDirPath);
path += CONFIG_NAME;
path_sample += CONFIG_NAME_SAMPLE;
if (!std::ifstream(path_sample)) {
LOG(INFO) << "Creating sample config file: " << converter.to_bytes(path_sample);
void readWriteConfig() {
if (!std::ifstream(CONFIG_NAME_SAMPLE)) {
LOG(INFO) << "Creating sample config file: " << CONFIG_NAME_SAMPLE;
json j = { { "addFileUrl", config.addFileUrl },{ "dbInsertUrl", config.dbInsertUrl },{ "httpRequestTimeout", config.httpRequestTimeout }, {"traceLog", config.traceLog} };
std::ofstream out(path_sample, ofstream::out | ofstream::binary);
std::ofstream out(CONFIG_NAME_SAMPLE, ofstream::out | ofstream::binary);
out << j.dump(4) << endl;
}
LOG(INFO) << "Trying to read config file:" << converter.to_bytes(path);
LOG(INFO) << "Trying to read config file:" << CONFIG_NAME;
bool cfgOpened = false;
ifstream cfg(path, ifstream::in | ifstream::binary);
ifstream cfg(CONFIG_NAME, ifstream::in | ifstream::binary);

json jcfg;
if (!cfg.is_open()) {
Expand Down Expand Up @@ -886,7 +883,7 @@ BOOL APIENTRY DllMain(HMODULE hModule,
{
case DLL_PROCESS_ATTACH: {
initialize_logger(true);
readWriteConfig(hModule);
readWriteConfig();
break;
}

Expand Down

0 comments on commit 4bcb3c2

Please sign in to comment.