2
0
mirror of https://github.com/Thracky/GlosSI.git synced 2024-11-03 09:40:18 +00:00
note to self: sleep more
This commit is contained in:
Peter Repukat 2018-03-12 22:48:58 +01:00
parent 0588c8c5a0
commit ce4c137a48
3 changed files with 30 additions and 27 deletions

Binary file not shown.

View File

@ -192,7 +192,7 @@ void SteamTarget::launchApplication()
const QString appName = QDir::toNativeSeparators(QString::fromStdString(launch_app_path_)).split('\\').last();
connect(&launch_check_timer_, &QTimer::timeout, [appName]()
{
if (!IsProcessRunning(appName.toStdWString().c_str()))
if (!process_alive::IsProcessRunning(appName.toStdWString().c_str()))
SteamTarget::quit();
});
QTimer::singleShot(10000, this, [this]()
@ -220,7 +220,7 @@ void SteamTarget::launchApplication()
{
connect(&launch_check_timer_, &QTimer::timeout, [pid]()
{
if (!IsProcessRunning(pid))
if (!process_alive::IsProcessRunning(pid))
SteamTarget::quit();
});
QTimer::singleShot(10000, this, [this]()

View File

@ -2,34 +2,37 @@
#include <Windows.h>
#include <tlhelp32.h>
//stolen from: https://stackoverflow.com/questions/1591342/c-how-to-determine-if-a-windows-process-is-running
inline bool IsProcessRunning(const wchar_t *processName)
namespace process_alive
{
bool exists = false;
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
//stolen from: https://stackoverflow.com/questions/1591342/c-how-to-determine-if-a-windows-process-is-running
inline bool IsProcessRunning(const wchar_t *processName)
{
bool exists = false;
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
const HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
const HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (Process32First(snapshot, &entry))
do {
if (!_wcsicmp(entry.szExeFile, processName))
{
exists = true;
break;
}
} while (Process32Next(snapshot, &entry));
if (Process32First(snapshot, &entry))
do {
if (!_wcsicmp(entry.szExeFile, processName))
{
exists = true;
break;
}
} while (Process32Next(snapshot, &entry));
CloseHandle(snapshot);
return exists;
}
CloseHandle(snapshot);
return exists;
}
inline BOOL IsProcessRunning(DWORD pid)
{
const HANDLE process = OpenProcess(SYNCHRONIZE, FALSE, pid);
if (process == nullptr)
return false;
const DWORD ret = WaitForSingleObject(process, 0);
CloseHandle(process);
return ret == WAIT_TIMEOUT;
inline BOOL IsProcessRunning(DWORD pid)
{
const HANDLE process = OpenProcess(SYNCHRONIZE, FALSE, pid);
if (process == nullptr)
return false;
const DWORD ret = WaitForSingleObject(process, 0);
CloseHandle(process);
return ret == WAIT_TIMEOUT;
}
}