bool TryClassifyFile(const std::string &path, ClassifiedFile * result) { try { auto fs = FileStream(path, FILE_MODE_OPEN); return TryClassifyFile(&fs, result); } catch (Exception) { return false; } }
static bool OpenParkAutoDetectFormat(const utf8 * path) { ClassifiedFile info; if (TryClassifyFile(path, &info)) { if (info.Type == FILE_TYPE::SAVED_GAME || info.Type == FILE_TYPE::SCENARIO) { std::unique_ptr<IParkImporter> parkImporter; if (info.Version <= 2) { parkImporter.reset(ParkImporter::CreateS4()); } else { parkImporter.reset(ParkImporter::CreateS6()); } if (info.Type == FILE_TYPE::SAVED_GAME) { try { parkImporter->LoadSavedGame(path); parkImporter->Import(); game_fix_save_vars(); sprite_position_tween_reset(); gScreenAge = 0; gLastAutoSaveUpdate = AUTOSAVE_PAUSE; game_load_init(); return true; } catch (const Exception &) { Console::Error::WriteLine("Error loading saved game."); } } else { try { parkImporter->LoadScenario(path); parkImporter->Import(); game_fix_save_vars(); sprite_position_tween_reset(); gScreenAge = 0; gLastAutoSaveUpdate = AUTOSAVE_PAUSE; scenario_begin(); return true; } catch (const Exception &) { Console::Error::WriteLine("Error loading scenario."); } } } else { Console::Error::WriteLine("Invalid file type."); } } else { Console::Error::WriteLine("Unable to detect file type."); } return false; }