#include "launchapp.h" #include "gsPlatform.h" launchApp::launchApp(FilePath &file) { this->exeMap["default"] = file; } void launchApp::platformApp(string platform, FilePath &file) { this->exeMap[platform] = file; } void launchApp::setCommandLine(string commandLine) { this->commandline = commandLine; } int launchApp::run(bool test, int deftest, string prompt, string header, bool wait) { gsPlatform platform; FilePath exePath; string runLine; if (test) { // if user didn't want it then cancel if (MessageBox(0, prompt.c_str(), header.c_str(), MB_YESNO | MB_ICONQUESTION | MB_SYSTEMMODAL | (deftest == 0 ? MB_DEFBUTTON1 : MB_DEFBUTTON2)) == IDNO) { return 0; } } // get the executable for this platform exePath = this->exeMap[platform.platformString()]; // if we didn't get it, get the default if (exePath.isEmpty()) { exePath = this->exeMap["default"]; } // couldn't find a path if (exePath.isEmpty()) { return -1; } // prepare process information fields STARTUPINFO startup; PROCESS_INFORMATION process; ZeroMemory(&startup, sizeof(STARTUPINFO)); startup.cb = sizeof(STARTUPINFO); process.hProcess = 0; // build command line if required if (this->commandline != "") { runLine = exePath.pathString() + " " + this->commandline; } // execute the process if (!CreateProcess((LPSTR) exePath.cString(), runLine != "" ? (LPSTR) runLine.c_str() : NULL, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, &startup, &process) == 0) { DWORD error = GetLastError(); /*char buffer[20]; sprintf(buffer, "%lu", error); MessageBox(0, buffer, "Failed", MB_OK);*/ return -2; } if (wait) { WaitForSingleObject(process.hProcess, INFINITE); } // success: return a positive number return 1; }