ref: 4f540343e63eb60f209ce7e8ce26db10c16ab4e6
parent: ef736b3d42749e505491ef579c5374a51feb9cc8
author: Simon Howard <[email protected]>
date: Mon Dec 14 15:57:04 EST 2009
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
--- a/setup/execute.c
+++ b/setup/execute.c
@@ -185,28 +185,37 @@
static wchar_t *BuildCommandLine(const char *program, const char *arg)
{
+ wchar_t exe_path[MAX_PATH];
wchar_t *result;
- char *sep;
+ wchar_t *sep;
- result = calloc(strlen(myargv[0]) + strlen(program) + strlen(arg) + 6,
+ // Get the path to this .exe file.
+
+ GetModuleFileNameW(NULL, exe_path, MAX_PATH);
+
+ // 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"\" \"");