29 PRAGMA48(GCC diagnostic ignored
"-Wshadow")
32 #include <SDL_system.h>
39 #if defined(WIN32) || defined(__linux__) || \
40 defined(__linux) || defined(__APPLE__)
41 const int timeOut = 10;
52 const std::string &arg1,
const std::string &arg2,
58 STARTUPINFO siStartupInfo;
59 PROCESS_INFORMATION piProcessInfo;
60 memset(&siStartupInfo, 0,
sizeof(siStartupInfo));
61 memset(&piProcessInfo, 0,
sizeof(piProcessInfo));
62 siStartupInfo.cb =
sizeof(siStartupInfo);
64 std::string args(std::string(pathName).append(
" ").append(arg1));
66 args.append(
" ").append(arg2);
68 if (CreateProcess(pathName.c_str(),
const_cast<char*
>(args.c_str()),
69 nullptr,
nullptr,
false, CREATE_DEFAULT_ERROR_MODE,
nullptr,
nullptr,
70 &siStartupInfo, &piProcessInfo) !=
false)
72 if (!WaitForSingleObject(piProcessInfo.hProcess, timeOut * 1000))
74 if (GetExitCodeProcess(piProcessInfo.hProcess, &ret))
76 CloseHandle(piProcessInfo.hProcess);
77 CloseHandle(piProcessInfo.hThread);
81 TerminateProcess(piProcessInfo.hProcess, -1);
84 CloseHandle(piProcessInfo.hProcess);
85 CloseHandle(piProcessInfo.hThread);
90 const std::string &arg1,
const std::string &arg2)
92 STARTUPINFO siStartupInfo;
93 PROCESS_INFORMATION piProcessInfo;
94 memset(&siStartupInfo, 0,
sizeof(siStartupInfo));
95 memset(&piProcessInfo, 0,
sizeof(piProcessInfo));
96 siStartupInfo.cb =
sizeof(siStartupInfo);
97 std::string args(std::string(pathName).append(
" ").append(arg1));
99 args.append(
" ").append(arg2);
101 bool res = CreateProcess(pathName.c_str(),
const_cast<char*
>(
102 args.c_str()),
nullptr,
nullptr,
false,
103 CREATE_DEFAULT_ERROR_MODE,
nullptr,
nullptr, &siStartupInfo,
106 CloseHandle(piProcessInfo.hProcess);
107 CloseHandle(piProcessInfo.hThread);
112 #elif defined __linux__ || defined __linux || defined __APPLE__
114 #include <sys/types.h>
115 #include <sys/stat.h>
116 #include <sys/wait.h>
119 int execFileWait(
const std::string &pathName,
const std::string &name,
120 const std::string &arg1,
const std::string &arg2,
129 if ((mon_pid = fork()) == -1)
133 else if (mon_pid == 0)
136 if ((pid = fork()) == -1)
144 execl(pathName.c_str(), name.c_str(),
145 arg1.c_str(),
static_cast<char *
>(
nullptr));
149 execl(pathName.c_str(), name.c_str(), arg1.c_str(),
150 arg2.c_str(),
static_cast<char *
>(
nullptr));
157 if ((sleep_pid = fork()) == -1)
161 else if (sleep_pid == 0)
164 execl(
"/bin/true",
"/bin/true",
static_cast<char *
>(
nullptr));
169 const pid_t exited_pid =
wait(&status);
171 if (exited_pid == pid)
173 kill(sleep_pid, SIGKILL);
174 if (WIFEXITED(status))
175 ret = WEXITSTATUS(status);
183 execl(
"/bin/true",
"/bin/true",
static_cast<char *
>(
nullptr));
188 waitpid(mon_pid, &status, 0);
189 if (WIFEXITED(status))
190 return WEXITSTATUS(status);
195 bool execFile(
const std::string &pathName,
const std::string &name,
196 const std::string &arg1,
const std::string &arg2)
200 if (stat(pathName.c_str(), &statbuf) != 0)
204 if ((pid = fork()) == -1)
212 execl(pathName.c_str(), name.c_str(),
213 arg1.c_str(),
static_cast<char *
>(
nullptr));
217 execl(pathName.c_str(), name.c_str(), arg1.c_str(),
218 arg2.c_str(),
static_cast<char *
>(
nullptr));
222 PRAGMACLANG6(GCC diagnostic ignored
"-Wunreachable-code-return")
253 return reinterpret_cast<int64_t
>(ShellExecute(
nullptr,
"open",
255 nullptr,
nullptr, SW_SHOWNORMAL)) > 32;
260 return reinterpret_cast<int32_t
>(ShellExecute(
nullptr,
"open",
262 nullptr,
nullptr, SW_SHOWNORMAL)) > 32;
264 #elif defined ANDROID
268 PRAGMA48(GCC diagnostic ignored
"-Wshadow")
269 #include <SDL_screenkeyboard.h>
284 #elif defined __APPLE__
287 return execFile(
"/usr/bin/open",
"/usr/bin/open",
url,
"");
289 #elif defined __OpenBSD__ || defined __FreeBSD__ || defined __DragonFly__
292 return execFile(
"/usr/local/bin/xdg-open",
293 "/usr/local/bin/xdg-open",
url,
"");
295 #elif defined __linux__ || defined __linux
298 return execFile(
"/usr/bin/xdg-open",
"/usr/bin/xdg-open",
url,
"");
300 #elif defined __native_client__
306 naclPostMessage(
"open-browser",
url);
320 HANDLE hCurrentProcess = GetCurrentProcess();
322 SetPriorityClass(hCurrentProcess, ABOVE_NORMAL_PRIORITY_CLASS);
324 SetPriorityClass(hCurrentProcess, BELOW_NORMAL_PRIORITY_CLASS);
#define PRAGMACLANG6(str)
bool wait(InputEvent &event)
bool url(InputEvent &event)
void setPriority(const bool big)
int execFileWait(const std::string &pathName, const std::string &name, const std::string &arg1, const std::string &arg2, int waitTime)
bool openBrowser(std::string url)
bool execFile(const std::string &pathName, const std::string &name, const std::string &arg1, const std::string &arg2)
std::string & replaceAll(std::string &context, const std::string &from, const std::string &to)