don't relaunch launchdf if it's already running

develop
Myk Taylor 2023-05-19 20:41:52 -07:00
parent a5a6b70a51
commit 8c01f3efe0
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
2 changed files with 34 additions and 3 deletions

@ -88,7 +88,9 @@ void DFSteam::cleanup(color_ostream& out) {
} }
#ifdef WIN32 #ifdef WIN32
#include <process.h>
#include <windows.h> #include <windows.h>
#include <TlHelp32.h>
static bool is_running_on_wine() { static bool is_running_on_wine() {
typedef const char* (CDECL wine_get_version)(void); typedef const char* (CDECL wine_get_version)(void);
static wine_get_version* pwine_get_version; static wine_get_version* pwine_get_version;
@ -100,12 +102,41 @@ static bool is_running_on_wine() {
return !!pwine_get_version; return !!pwine_get_version;
} }
static DWORD findProcess(LPWSTR name) {
PROCESSENTRY32W entry;
entry.dwSize = sizeof(PROCESSENTRY32W);
const auto snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (!Process32FirstW(snapshot, &entry)) {
CloseHandle(snapshot);
return -1;
}
do {
std::wstring executableName(entry.szExeFile);
if (executableName == name) {
CloseHandle(snapshot);
return entry.th32ProcessID;
}
}
while (Process32NextW(snapshot, &entry));
CloseHandle(snapshot);
return -1;
}
static bool launchDFHack(color_ostream& out) { static bool launchDFHack(color_ostream& out) {
if (is_running_on_wine()) { if (is_running_on_wine()) {
DEBUG(dfsteam, out).print("not attempting to re-launch DFHack on wine\n"); DEBUG(dfsteam, out).print("not attempting to re-launch DFHack on wine\n");
return false; return false;
} }
if (findProcess(L"launchdf.exe") != -1) {
DEBUG(dfsteam, out).print("launchdf.exe already running\n");
return true;
}
STARTUPINFOW si; STARTUPINFOW si;
PROCESS_INFORMATION pi; PROCESS_INFORMATION pi;

@ -139,6 +139,9 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
exit(0); exit(0);
} }
if (waitForDF())
exit(0);
if (!SteamAPI_Init()) if (!SteamAPI_Init())
{ {
// could not initialize steam context, attempt fallback launch // could not initialize steam context, attempt fallback launch
@ -151,9 +154,6 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
exit(0); exit(0);
} }
if (waitForDF())
exit(0);
bool wine = is_running_on_wine(); bool wine = is_running_on_wine();
if (wine) if (wine)