diff --git a/host/platform/Windows/src/platform.c b/host/platform/Windows/src/platform.c index 6748c233..9cc6faaa 100644 --- a/host/platform/Windows/src/platform.c +++ b/host/platform/Windows/src/platform.c @@ -58,6 +58,7 @@ struct AppState char executable[MAX_PATH + 1]; char systemLogDir[MAX_PATH]; + char systemTempDir[MAX_PATH]; char * osVersion; HWND messageWnd; UINT shellHookMsg; @@ -299,6 +300,11 @@ static BOOL WINAPI CtrlHandler(DWORD dwCtrlType) return FALSE; } +const char * getSystemTempDirectory(void) +{ + return app.systemTempDir; +} + const char *getSystemLogDirectory(void) { return app.systemLogDir; @@ -340,6 +346,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine GetModuleFileName(NULL, app.executable, sizeof(app.executable)); populateSystemLogDirectory(); + GetTempPathA(sizeof(app.systemTempDir), app.systemTempDir); if (HandleService(app.argc, app.argv)) return LG_HOST_EXIT_FAILED; diff --git a/host/platform/Windows/src/platform.h b/host/platform/Windows/src/platform.h index 1060a16a..b7fb3c5d 100644 --- a/host/platform/Windows/src/platform.h +++ b/host/platform/Windows/src/platform.h @@ -51,5 +51,6 @@ struct MSG_CALL_FUNCTION }; bool windowsSetupAPI(void); -const char *getSystemLogDirectory(void); +const char * getSystemTempDirectory(void); +const char * getSystemLogDirectory(void); LRESULT sendAppMessage(UINT Msg, WPARAM wParam, LPARAM lParam); diff --git a/host/platform/Windows/src/service.c b/host/platform/Windows/src/service.c index 83202e31..9efa9b1b 100644 --- a/host/platform/Windows/src/service.c +++ b/host/platform/Windows/src/service.c @@ -78,7 +78,13 @@ void doLogReal(const char * fmt, ...) static void setupLogging(void) { char logFilePath[MAX_PATH]; - if (!PathCombineA(logFilePath, getSystemLogDirectory(), LOG_NAME)) + + // remove the old service log file if it exists + if (PathCombineA(logFilePath, getSystemLogDirectory(), LOG_NAME)) + unlink(logFilePath); + + // open the service file in the temp directory as we usually do not need it + if (!PathCombineA(logFilePath, getSystemTempDirectory(), LOG_NAME)) strcpy(logFilePath, LOG_NAME); service.logFile = fopen(logFilePath, "a+"); setbuf(service.logFile, NULL);