| 312 | int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nShowCmd) { |
| 313 | #else |
| 314 | int main(int argc, char* argv[]) { |
| 315 | #endif |
| 316 | #ifdef WIN32 |
| 317 | // force UTF-8 |
| 318 | std::setlocale(LC_ALL, ".utf8"); |
| 319 | #endif |
| 320 | // initialize steam context |
| 321 | if (SteamAPI_RestartAppIfNecessary(DFHACK_STEAM_APPID)) { |
| 322 | exit(0); |
| 323 | } |
| 324 | |
| 325 | bool nowait = false; |
| 326 | #ifdef WIN32 |
| 327 | std::wstring cmdline(lpCmdLine); |
| 328 | if (cmdline.find(L"--nowait") != std::wstring::npos) |
| 329 | nowait = true; |
| 330 | #else |
| 331 | for (int idx = 0; idx < argc; ++idx) { |
| 332 | if (strcmp(argv[idx], "--nowait") == 0) |
| 333 | nowait = true; |
| 334 | } |
| 335 | #endif |
| 336 | |
| 337 | if (waitForDF(nowait)) |
| 338 | exit(0); |
| 339 | |
| 340 | if (!SteamAPI_Init()) { |
| 341 | // could not initialize steam context, attempt fallback launch |
| 342 | exit(wrap_launch(launch_direct) ? 0 : 1); |
| 343 | } |
| 344 | |
| 345 | #ifdef WIN32 |
| 346 | bool wine_detected = is_running_on_wine(); |
| 347 | #endif |
| 348 | |
| 349 | bool df_detected = SteamApps()->BIsAppInstalled(DF_STEAM_APPID); |
| 350 | |
| 351 | if (!df_detected) { |
| 352 | // Steam DF is not installed. Assume DF is installed in same directory as DFHack and do a fallback launch |
| 353 | exit(wrap_launch(launch_direct) ? 0 : 1); |
| 354 | } |
| 355 | |
| 356 | // obtain DF and DFHack app paths |
| 357 | |
| 358 | auto get_app_path_from_steam = [] (AppId_t appid) -> std::optional<std::filesystem::path> { |
| 359 | constexpr auto BUFSIZE = 2048; |
| 360 | char buf[BUFSIZE] = ""; |
| 361 | int bytes = SteamApps()->GetAppInstallDir(appid, (char*)&buf, BUFSIZE); |
| 362 | if (bytes <= 0) |
| 363 | return std::nullopt; |
| 364 | // steam API includes one or more null terminators after the path, so trim those off |
| 365 | for (; bytes > 0 && buf[bytes-1] == '\0'; bytes--); |
| 366 | return std::string(buf, bytes); |
| 367 | }; |
| 368 | |
| 369 | auto opt_dfhack_install_folder = get_app_path_from_steam(DFHACK_STEAM_APPID); |
| 370 | auto opt_df_install_folder = get_app_path_from_steam(DF_STEAM_APPID); |
| 371 |
nothing calls this directly
no test coverage detected