void InGameMenu::Save() { DebugLogger() << "InGameMenu::Save"; HumanClientApp* app = HumanClientApp::GetApp(); if (!app) return; if (!app->CanSaveNow()) { ErrorLogger() << "InGameMenu::Save aborting; Client app can't save now"; return; } const std::string SAVE_GAME_EXTENSION = app->SinglePlayerGame() ? SP_SAVE_FILE_EXTENSION : MP_SAVE_FILE_EXTENSION; try { std::string filename; // When saving in multiplayer, you cannot see the old saves or // browse directories, only give a save file name. if (app->SinglePlayerGame()) { DebugLogger() << "... running save file dialog"; SaveFileDialog dlg(SAVE_GAME_EXTENSION); dlg.Run(); filename = dlg.Result(); } else { /// Multiplayer save. Talk to the server. filename = app->SelectSaveFile(); } if (!filename.empty()) { if (!app->CanSaveNow()) { ErrorLogger() << "InGameMenu::Save aborting; Client app can't save now"; throw std::runtime_error(UserString("UNABLE_TO_SAVE_NOW_TRY_AGAIN")); } DebugLogger() << "... initiating save to " << filename ; app->SaveGame(filename); CloseClicked(); DebugLogger() << "... save done"; } } catch (const std::exception& e) { ErrorLogger() << "Exception thrown attempting save: " << e.what(); ClientUI::MessageBox(e.what(), true); } }
void InGameMenu::Save() { Logger().debugStream() << "InGameMenu::Save"; HumanClientApp* app = HumanClientApp::GetApp(); if (!app) return; if (!app->CanSaveNow()) { Logger().errorStream() << "InGameMenu::Save aborting; Client app can't save now"; return; } const std::string SAVE_GAME_EXTENSION = HumanClientApp::GetApp()->SinglePlayerGame() ? SP_SAVE_FILE_EXTENSION : MP_SAVE_FILE_EXTENSION; std::vector<std::pair<std::string, std::string> > save_file_types; save_file_types.push_back(std::make_pair(UserString("GAME_MENU_SAVE_FILES"), "*" + SAVE_GAME_EXTENSION)); try { Logger().debugStream() << "... getting save path string"; std::string path_string = PathString(GetSaveDir()); Logger().debugStream() << "... got save path string: " << path_string; Logger().debugStream() << "... running file dialog"; FileDlg dlg(path_string, "", true, false, save_file_types); dlg.Run(); if (!dlg.Result().empty()) { if (!app->CanSaveNow()) { Logger().errorStream() << "InGameMenu::Save aborting; Client app can't save now"; throw std::runtime_error(UserString("UNABLE_TO_SAVE_NOW_TRY_AGAIN")); } Logger().debugStream() << "... initiating save"; app->SaveGame(*dlg.Result().begin()); CloseClicked(); Logger().debugStream() << "... save done"; } } catch (const std::exception& e) { Logger().errorStream() << "Exception thrown attempting save: " << e.what(); ClientUI::MessageBox(e.what(), true); } }