From 4f540343e63eb60f209ce7e8ce26db10c16ab4e6 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Mon, 14 Dec 2009 20:57:04 +0000 Subject: Use GetModuleFileNameW to get the (Unicode) path to the Doom executable. This hopefully fixes problems with Unicode directory names. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1747 --- setup/execute.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'setup') diff --git a/setup/execute.c b/setup/execute.c index 8c4580e8..59f561be 100644 --- a/setup/execute.c +++ b/setup/execute.c @@ -185,29 +185,38 @@ static void ConcatWCString(wchar_t *buf, const char *value) static wchar_t *BuildCommandLine(const char *program, const char *arg) { + wchar_t exe_path[MAX_PATH]; wchar_t *result; - char *sep; + wchar_t *sep; + + // Get the path to this .exe file. + + GetModuleFileNameW(NULL, exe_path, MAX_PATH); - result = calloc(strlen(myargv[0]) + strlen(program) + strlen(arg) + 6, + // Allocate buffer to contain result string. + + result = calloc(wcslen(exe_path) + strlen(program) + strlen(arg) + 6, sizeof(wchar_t)); wcscpy(result, L"\""); - sep = strrchr(myargv[0], DIR_SEPARATOR); + // Copy the path part of the filename (including ending \) + // into the result buffer: + + sep = wcsrchr(exe_path, DIR_SEPARATOR); if (sep != NULL) { - ConcatWCString(result, myargv[0]); - - // Cut off the string after the last directory separator, - // before appending the actual program. - - result[sep - myargv[0] + 2] = '\0'; - + wcsncpy(result + 1, exe_path, sep - exe_path + 1); + result[sep - exe_path + 2] = '\0'; } + // Concatenate the name of the program: + ConcatWCString(result, program); + // End of program name, start of argument: + wcscat(result, L"\" \""); ConcatWCString(result, arg); -- cgit v1.2.3