Fixed a bug when the log file was not created in the program's folder when launched from the scheduler.

This commit is contained in:
2021-12-19 06:23:32 +03:00
parent 5137eed759
commit 01eb9075b4
2 changed files with 7 additions and 9 deletions

View File

@@ -36,18 +36,16 @@ void OpenLogFile() {
fs::path log_path = lpszPath; fs::path log_path = lpszPath;
log_path.replace_extension(L".log"); log_path.replace_extension(L".log");
std::wstring logname = log_path.stem() += L".log"; fs::path bak_path = log_path;
std::wstring backupname = log_path.stem() += L".bak"; bak_path.replace_extension(L".bak");
if (fs::exists(logname)) { if (fs::exists(log_path)) fs::rename(log_path, bak_path);
fs::rename(logname, backupname);
}
logfile.open(logname); logfile.open(log_path);
if (logfile.is_open()) { if (logfile.is_open()) {
diag_log(L"Starting logging."); diag_log(L"Starting logging.");
diag_log(L"logfile:", logname); diag_log(L"logfile:", log_path);
diag_log(logname, L"successfully opened."); diag_log(log_path, L"successfully opened.");
} else { } else {
MessageBoxW(NULL, L"Can't open logfile! Working without logging.", L"WARNING", MB_OK | MB_ICONWARNING); MessageBoxW(NULL, L"Can't open logfile! Working without logging.", L"WARNING", MB_OK | MB_ICONWARNING);
} }

View File

@@ -36,7 +36,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141_xp</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>