diff --git a/src/backends/windows/system.c b/src/backends/windows/system.c index a4899f03..7a0141c5 100644 --- a/src/backends/windows/system.c +++ b/src/backends/windows/system.c @@ -649,26 +649,33 @@ void Sys_RedirectStdout(void) { char *cur; - char *home; char *old; + char dir[MAX_OSPATH]; char path_stdout[MAX_OSPATH]; char path_stderr[MAX_OSPATH]; + const char *tmp; - home = Sys_GetHomeDir(); + if (is_portable) { + tmp = Sys_GetBinaryDir(); + Q_strlcpy(dir, tmp, sizeof(dir)); + } else { + tmp = Sys_GetHomeDir(); + Q_strlcpy(dir, tmp, sizeof(dir)); + } - if (home == NULL) + if (dir == NULL) { return; } - cur = old = home; + cur = old = dir; while (cur != NULL) { if ((cur - old) > 1) { *cur = '\0'; - Sys_Mkdir(home); + Sys_Mkdir(dir); *cur = '/'; } @@ -676,8 +683,8 @@ Sys_RedirectStdout(void) cur = strchr(old + 1, '/'); } - snprintf(path_stdout, sizeof(path_stdout), "%s/%s", home, "stdout.txt"); - snprintf(path_stderr, sizeof(path_stderr), "%s/%s", home, "stderr.txt"); + snprintf(path_stdout, sizeof(path_stdout), "%s/%s", dir, "stdout.txt"); + snprintf(path_stderr, sizeof(path_stderr), "%s/%s", dir, "stderr.txt"); freopen(path_stdout, "w", stdout); freopen(path_stderr, "w", stderr); @@ -758,15 +765,13 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, /* Are we portable? */ for (int i = 0; i < argc; i++) { if (strcmp(argv[i], "-portable") == 0) { - portable = true; + is_portable = true; } } /* Need to redirect stdout before anything happens. */ #ifndef DEDICATED_ONLY - if (!is_portable) { - Sys_RedirectStdout; - } + Sys_RedirectStdout(); #endif printf("Yamagi Quake II v%s\n", YQ2VERSION);