[1543] | 1 | #include "launchapp.h"
|
---|
[1548] | 2 |
|
---|
| 3 | #include "gsPlatform.h"
|
---|
| 4 |
|
---|
[1543] | 5 | launchApp::launchApp(FilePath &file)
|
---|
[1548] | 6 | { this->exeMap["default"] = file;
|
---|
| 7 | }
|
---|
| 8 |
|
---|
| 9 | void launchApp::platformApp(string platform, FilePath &file)
|
---|
| 10 | { this->exeMap[platform] = file;
|
---|
| 11 | }
|
---|
| 12 |
|
---|
| 13 | void launchApp::setCommandLine(string commandLine)
|
---|
| 14 | { this->commandline = commandLine;
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | int launchApp::run(bool test, int deftest, string prompt, string header, bool wait)
|
---|
| 18 | { gsPlatform platform;
|
---|
| 19 | FilePath exePath;
|
---|
| 20 | string runLine;
|
---|
| 21 |
|
---|
| 22 | if (test)
|
---|
| 23 | { // if user didn't want it then cancel
|
---|
| 24 | if (MessageBox(0, prompt.c_str(), header.c_str(),
|
---|
| 25 | MB_YESNO | MB_ICONQUESTION | MB_SYSTEMMODAL |
|
---|
| 26 | (deftest == 0 ? MB_DEFBUTTON1 : MB_DEFBUTTON2)) == IDNO)
|
---|
| 27 | { return 0;
|
---|
| 28 | }
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | // get the executable for this platform
|
---|
| 32 | exePath = this->exeMap[platform.platformString()];
|
---|
| 33 |
|
---|
| 34 | // if we didn't get it, get the default
|
---|
| 35 | if (exePath.isEmpty())
|
---|
| 36 | { exePath = this->exeMap["default"];
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | // couldn't find a path
|
---|
| 40 | if (exePath.isEmpty())
|
---|
| 41 | { return -1;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | // prepare process information fields
|
---|
| 45 | STARTUPINFO startup;
|
---|
| 46 | PROCESS_INFORMATION process;
|
---|
| 47 | ZeroMemory(&startup, sizeof(STARTUPINFO));
|
---|
| 48 | startup.cb = sizeof(STARTUPINFO);
|
---|
| 49 | process.hProcess = 0;
|
---|
| 50 |
|
---|
| 51 | // build command line if required
|
---|
| 52 | if (this->commandline != "")
|
---|
| 53 | { runLine = exePath.pathString() + " " + this->commandline;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | // execute the process
|
---|
| 57 | if (!CreateProcess((LPSTR) exePath.cString(),
|
---|
| 58 | runLine != "" ? (LPSTR) runLine.c_str() : NULL,
|
---|
| 59 | NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL,
|
---|
| 60 | &startup, &process) == 0)
|
---|
| 61 | { DWORD error = GetLastError();
|
---|
| 62 | /*char buffer[20];
|
---|
| 63 | sprintf(buffer, "%lu", error);
|
---|
| 64 | MessageBox(0, buffer, "Failed", MB_OK);*/
|
---|
| 65 | return -2;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | if (wait)
|
---|
| 69 | { WaitForSingleObject(process.hProcess, INFINITE);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | // success: return a positive number
|
---|
| 73 | return 1;
|
---|
[1543] | 74 | }
|
---|
| 75 |
|
---|