1 | #include "launchapp.h"
|
---|
2 |
|
---|
3 | #include "gsPlatform.h"
|
---|
4 |
|
---|
5 | launchApp::launchApp(FilePath &file)
|
---|
6 | { this->exeMap["default"] = file;
|
---|
7 | }
|
---|
8 |
|
---|
9 | void launchApp::platformApp(string platform, FilePath &file)
|
---|
10 | { this->exeMap[platform] = file;
|
---|
11 | }
|
---|
12 |
|
---|
13 | int launchApp::run(bool test, int deftest, string prompt, string header, bool wait)
|
---|
14 | { gsPlatform platform;
|
---|
15 | FilePath exePath;
|
---|
16 |
|
---|
17 | if (test)
|
---|
18 | { // if user didn't want it then cancel
|
---|
19 | if (MessageBox(0, prompt.c_str(), header.c_str(),
|
---|
20 | MB_YESNO | MB_ICONQUESTION | MB_SYSTEMMODAL |
|
---|
21 | (deftest == 0 ? MB_DEFBUTTON1 : MB_DEFBUTTON2)) == IDNO)
|
---|
22 | { return 0;
|
---|
23 | }
|
---|
24 | }
|
---|
25 |
|
---|
26 | // get the executable for this platform
|
---|
27 | exePath = this->exeMap[platform.platformString()];
|
---|
28 |
|
---|
29 | // if we didn't get it, get the default
|
---|
30 | if (exePath.isEmpty())
|
---|
31 | { exePath = this->exeMap["default"];
|
---|
32 | }
|
---|
33 |
|
---|
34 | // couldn't find a path
|
---|
35 | if (exePath.isEmpty())
|
---|
36 | { return -1;
|
---|
37 | }
|
---|
38 |
|
---|
39 | // prepare process information fields
|
---|
40 | STARTUPINFO startup;
|
---|
41 | PROCESS_INFORMATION process;
|
---|
42 | startup.cb = sizeof(STARTUPINFO);
|
---|
43 | process.hProcess = 0;
|
---|
44 |
|
---|
45 | // execute the process
|
---|
46 | if (CreateProcess(exePath.cString(), NULL, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &process) == 0)
|
---|
47 | { DWORD error = GetLastError();
|
---|
48 | return -2;
|
---|
49 | }
|
---|
50 |
|
---|
51 | if (wait)
|
---|
52 | { WaitForSingleObject(process.hProcess, INFINITE);
|
---|
53 | }
|
---|
54 |
|
---|
55 | // success: return a positive number
|
---|
56 | return 1;
|
---|
57 | } |
---|