| 158 | #ifdef WIN32 |
| 159 | |
| 160 | DWORD findDwarfFortressProcess() { |
| 161 | PROCESSENTRY32W entry; |
| 162 | entry.dwSize = sizeof(PROCESSENTRY32W); |
| 163 | |
| 164 | const auto snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL); |
| 165 | |
| 166 | if (!Process32FirstW(snapshot, &entry)) |
| 167 | { |
| 168 | CloseHandle(snapshot); |
| 169 | return -1; |
| 170 | } |
| 171 | |
| 172 | do { |
| 173 | std::wstring executableName(entry.szExeFile); |
| 174 | if (executableName == L"Dwarf Fortress.exe") |
| 175 | { |
| 176 | CloseHandle(snapshot); |
| 177 | return entry.th32ProcessID; |
| 178 | } |
| 179 | } while (Process32NextW(snapshot, &entry)); |
| 180 | |
| 181 | CloseHandle(snapshot); |
| 182 | return -1; |
| 183 | } |
| 184 | |
| 185 | bool waitForDF(bool nowait) { |
| 186 | DWORD df_pid = findDwarfFortressProcess(); |