@@ -72,6 +72,24 @@ bool IsValidLuaFile(const std::wstring &path, std::string &firstLine)
72
72
return true ;
73
73
}
74
74
75
+ bool InsertPath (std::vector<std::wstring> &commandLine, std::wstring path)
76
+ {
77
+ DWORD requiredLength = GetShortPathName (path.c_str (), nullptr , 0 );
78
+ if (requiredLength == 0 )
79
+ {
80
+ return false ;
81
+ }
82
+
83
+ std::wstring shortPath (requiredLength, L' \0 ' );
84
+ requiredLength = GetShortPathName (path.c_str (), shortPath.data (), requiredLength);
85
+ if (requiredLength == 0 )
86
+ {
87
+ return false ;
88
+ }
89
+
90
+ commandLine.insert (commandLine.begin () + 1 , shortPath);
91
+ }
92
+
75
93
bool FindLaunchLua (std::wstring basePath, std::vector<std::wstring> &commandLine, std::string &firstLine)
76
94
{
77
95
// Unify path separator characters
@@ -93,16 +111,14 @@ bool FindLaunchLua(std::wstring basePath, std::vector<std::wstring> &commandLine
93
111
std::wstring launchPath = basePath + L" \\ Launch.lua" ;
94
112
if (IsValidLuaFile (launchPath, firstLine))
95
113
{
96
- commandLine.insert (commandLine.begin () + 1 , launchPath);
97
- return true ;
114
+ return InsertPath (commandLine, launchPath);
98
115
}
99
116
100
117
// Look for src\\Launch.lua
101
118
launchPath = basePath + L" \\ src\\ Launch.lua" ;
102
119
if (IsValidLuaFile (launchPath, firstLine))
103
120
{
104
- commandLine.insert (commandLine.begin () + 1 , launchPath);
105
- return true ;
121
+ return InsertPath (commandLine, launchPath);
106
122
}
107
123
108
124
// If the base path ends with "runtime" then strip that off, append "src" and look for Launch.lua there
@@ -125,8 +141,7 @@ bool FindLaunchLua(std::wstring basePath, std::vector<std::wstring> &commandLine
125
141
launchPath = parentPath + L" \\ src\\ Launch.lua" ;
126
142
if (IsValidLuaFile (launchPath, firstLine))
127
143
{
128
- commandLine.insert (commandLine.begin () + 1 , launchPath);
129
- return true ;
144
+ return InsertPath (commandLine, launchPath);
130
145
}
131
146
}
132
147
}
@@ -219,21 +234,21 @@ bool InsertLaunchLua(std::vector<std::wstring> &commandLine, std::string &firstL
219
234
return false ;
220
235
}
221
236
222
- std::vector<std::string> ConvertToUTF8 (std::vector<std::wstring> commandLine)
237
+ std::vector<std::string> ConvertToACP (std::vector<std::wstring> commandLine)
223
238
{
224
- std::vector<std::string> commandLineUTF8 ;
239
+ std::vector<std::string> commandLineACP ;
225
240
if (commandLine.size () > 0 )
226
241
{
227
- commandLineUTF8 .reserve (commandLine.size ());
242
+ commandLineACP .reserve (commandLine.size ());
228
243
for (const std::wstring ¶m : commandLine)
229
244
{
230
- int dwUTF8Size = WideCharToMultiByte (CP_UTF8 , 0 , param.c_str (), (int )param.size (), NULL , 0 , NULL , NULL );
231
- std::string paramUTF8 (dwUTF8Size , 0 );
232
- WideCharToMultiByte (CP_UTF8 , 0 , param.c_str (), (int )param.size (), paramUTF8 .data (), dwUTF8Size , NULL , NULL );
233
- commandLineUTF8 .emplace_back (std::move (paramUTF8 ));
245
+ int dwACPSize = WideCharToMultiByte (CP_ACP , 0 , param.c_str (), (int )param.size (), NULL , 0 , NULL , NULL );
246
+ std::string paramACP (dwACPSize , 0 );
247
+ WideCharToMultiByte (CP_ACP , 0 , param.c_str (), (int )param.size (), paramACP .data (), dwACPSize , NULL , NULL );
248
+ commandLineACP .emplace_back (std::move (paramACP ));
234
249
}
235
250
}
236
- return commandLineUTF8 ;
251
+ return commandLineACP ;
237
252
}
238
253
239
254
void InitConsole ()
@@ -300,18 +315,18 @@ int CALLBACK wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance
300
315
}
301
316
302
317
// Create a utf8 version of the commandline parameters
303
- std::vector<std::string> commandLineUTF8 = ConvertToUTF8 (commandLine);
318
+ std::vector<std::string> commandLineACP = ConvertToACP (commandLine);
304
319
305
320
// Remove the first commandline argument as the scripts don't care about that.
306
- commandLineUTF8 .erase (commandLineUTF8 .begin ());
321
+ commandLineACP .erase (commandLineACP .begin ());
307
322
308
323
// Convert the commandline parameters to a form the DLL can understand
309
324
size_t dwTotalParamSize = 0 ;
310
- for (const std::string ¶m : commandLineUTF8 )
325
+ for (const std::string ¶m : commandLineACP )
311
326
{
312
327
dwTotalParamSize += param.size () + 1 ;
313
328
}
314
- size_t dwNumParams = commandLineUTF8 .size ();
329
+ size_t dwNumParams = commandLineACP .size ();
315
330
std::unique_ptr<char []> pParamBuf = std::make_unique<char []>(dwTotalParamSize);
316
331
char *pCurParamBufLoc = pParamBuf.get ();
317
332
@@ -320,7 +335,7 @@ int CALLBACK wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance
320
335
{
321
336
ppParamList[i] = pCurParamBufLoc;
322
337
323
- const std::string ¶m = commandLineUTF8 [i];
338
+ const std::string ¶m = commandLineACP [i];
324
339
memcpy (pCurParamBufLoc, param.c_str (), param.size () + 1 );
325
340
pCurParamBufLoc += param.size () + 1 ;
326
341
}
0 commit comments