@@ -18,6 +18,7 @@ enum LauncherError : int {
18
18
E_OS_ERROR = -1 ,
19
19
E_APP_NOT_FOUND = -2 ,
20
20
E_MODENGINE_NOT_FOUND = -3 ,
21
+ E_CREATE_PROCESS_FAILED = -4 ,
21
22
};
22
23
23
24
struct LaunchTargetParams {
@@ -55,7 +56,7 @@ namespace platform {
55
56
std::wstring get_env_var (const std::wstring& name)
56
57
{
57
58
size_t buffer_size = GetEnvironmentVariableW (name.c_str (), nullptr , 0 );
58
- wchar_t buffer[buffer_size + 1 ];
59
+ auto * buffer = new wchar_t [buffer_size + 1 ];
59
60
60
61
std::wstring value;
61
62
@@ -64,6 +65,8 @@ std::wstring get_env_var(const std::wstring& name)
64
65
value.append (buffer, len);
65
66
}
66
67
68
+ delete buffer;
69
+
67
70
return value;
68
71
}
69
72
@@ -75,16 +78,20 @@ void set_env_var(const std::wstring& name, const std::wstring& value)
75
78
fs::path get_launcher_directory ()
76
79
{
77
80
size_t buffer_size = GetModuleFileNameW (nullptr , nullptr , 0 );
78
- wchar_t buffer[buffer_size + 1 ];
81
+ auto * buffer = new wchar_t [buffer_size + 1 ];
82
+
83
+ fs::path path = fs::current_path ();
79
84
80
85
if (buffer_size > 0 ) {
81
86
size_t len = GetModuleFileNameW (nullptr , buffer, buffer_size + 1 );
82
87
fs::path launcher_path (std::wstring_view { buffer, len });
83
88
84
- return launcher_path.parent_path ();
89
+ path = launcher_path.parent_path ();
85
90
}
86
91
87
- return fs::current_path ();
92
+ delete buffer;
93
+
94
+ return path;
88
95
}
89
96
90
97
}
@@ -207,9 +214,7 @@ int main()
207
214
std::wstring cmd_str = app_cmd.native ();
208
215
size_t cmd_len = cmd_str.length ();
209
216
210
- wchar_t cmd[cmd_len + 1 ];
211
- cmd[cmd_len] = 0 ;
212
-
217
+ wchar_t cmd[cmd_len + 1 ] = {};
213
218
wcsncpy_s (cmd, cmd_str.c_str (), cmd_len);
214
219
215
220
auto proc_flags = 0 ;
@@ -227,12 +232,15 @@ int main()
227
232
fs::absolute (modengine_dll_path).native ().c_str (),
228
233
reinterpret_cast <PDETOUR_CREATE_PROCESS_ROUTINEW>(create_process_addr));
229
234
235
+ auto status = E_OK;
236
+
230
237
if (!success) {
231
238
logger->error (" Couldn't create process: {:x}" , GetLastError ());
239
+ status = E_CREATE_PROCESS_FAILED;
232
240
}
233
241
234
242
CloseHandle (pi .hProcess );
235
243
CloseHandle (pi .hThread );
236
244
237
- return E_OK ;
245
+ return status ;
238
246
}
0 commit comments