diff options
author | Simon Howard | 2009-12-14 20:57:04 +0000 |
---|---|---|
committer | Simon Howard | 2009-12-14 20:57:04 +0000 |
commit | 4f540343e63eb60f209ce7e8ce26db10c16ab4e6 (patch) | |
tree | d5243a1b00bf34991c00c0461af5235828cb1e12 /setup/execute.c | |
parent | ef736b3d42749e505491ef579c5374a51feb9cc8 (diff) | |
download | chocolate-doom-4f540343e63eb60f209ce7e8ce26db10c16ab4e6.tar.gz chocolate-doom-4f540343e63eb60f209ce7e8ce26db10c16ab4e6.tar.bz2 chocolate-doom-4f540343e63eb60f209ce7e8ce26db10c16ab4e6.zip |
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
Diffstat (limited to 'setup/execute.c')
-rw-r--r-- | setup/execute.c | 29 |
1 files changed, 19 insertions, 10 deletions
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); |