void CCregLoadSaveHandler::SaveGame(const std::string& file) { logOutput.Print("Saving game"); try { std::ofstream ofs(filesystem.LocateFile(file, FileSystem::WRITE).c_str(), std::ios::out|std::ios::binary); if (ofs.bad() || !ofs.is_open()) { throw content_error("Unable to save game to file \"" + file + "\""); } std::string scriptText = gameSetup->gameSetupText; WriteString(ofs, scriptText); WriteString(ofs, modName); WriteString(ofs, mapName); CGameStateCollector* gsc = new CGameStateCollector(); creg::COutputStreamSerializer os; os.SavePackage(&ofs, gsc, gsc->GetClass()); PrintSize("Game",ofs.tellp()); int aistart = ofs.tellp(); eoh->Save(&ofs); PrintSize("AIs", ((int)ofs.tellp())-aistart); } catch (content_error& e) { logOutput.Print("Save failed(content error): %s", e.what()); } catch (std::exception& e) { logOutput.Print("Save failed: %s", e.what()); } catch (char*& e) { logOutput.Print("Save failed: %s", e); } catch (...) { logOutput.Print("Save failed(unknown error)"); } }
void CLoadSaveHandler::SaveGame(std::string file) { LoadStartPicture(teamHandler->Team(gu->myTeam)->side); PrintLoadMsg("Saving game"); try { std::ofstream ofs(filesystem.LocateFile(file, FileSystem::WRITE).c_str(), std::ios::out|std::ios::binary); if (ofs.bad() || !ofs.is_open()) { handleerror(0,"Couldnt save game to file",file.c_str(),0); return; } std::string scriptText; if (gameSetup) { scriptText = gameSetup->gameSetupText; } WriteString(ofs, scriptText); WriteString(ofs, modName); WriteString(ofs, mapName); CGameStateCollector *gsc = new CGameStateCollector(); creg::COutputStreamSerializer os; os.SavePackage(&ofs, gsc, gsc->GetClass()); PrintSize("Game",ofs.tellp()); int aistart = ofs.tellp(); for (int a=0;a<MAX_TEAMS;a++) grouphandlers[a]->Save(&ofs); globalAI->Save(&ofs); PrintSize("AIs",((int)ofs.tellp())-aistart); } catch (content_error &e) { logOutput.Print("Save faild(content error): %s",e.what()); } catch (std::exception &e) { logOutput.Print("Save faild: %s",e.what()); } catch (char* &e) { logOutput.Print("Save faild: %s",e); } catch (...) { logOutput.Print("Save faild(unknwon error)"); } UnloadStartPicture(); }