From 6a7263367495db63b7a676227b7ca7a2b080065e Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Wed, 6 Mar 2024 13:11:48 +1100 Subject: [PATCH] [host] windows: move the service log to the temp directory Often this log is provided instead of the actual host log, as this log is largely useless for debugging this moves it to the temp directory out of view of the user. --- host/platform/Windows/src/platform.c | 7 +++++++ host/platform/Windows/src/platform.h | 3 ++- host/platform/Windows/src/service.c | 8 +++++++- 3 files changed, 16 insertions(+), 2 deletions(-) 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);