* Saves the current save. */
| 122 | * Saves the current save. |
| 123 | */ |
| 124 | void SaveGameState::init() |
| 125 | { |
| 126 | // Make sure message is shown (if any) |
| 127 | State::init(); |
| 128 | blit(); |
| 129 | _game->getScreen()->flip(); |
| 130 | _game->popState(); |
| 131 | |
| 132 | switch (_type) |
| 133 | { |
| 134 | case SAVE_DEFAULT: |
| 135 | // manual save, close the save screen |
| 136 | _game->popState(); |
| 137 | if (!_game->getSavedGame()->isIronman()) |
| 138 | { |
| 139 | // and pause screen too |
| 140 | _game->popState(); |
| 141 | } |
| 142 | break; |
| 143 | case SAVE_QUICK: |
| 144 | case SAVE_AUTO_GEOSCAPE: |
| 145 | case SAVE_AUTO_BATTLESCAPE: |
| 146 | // automatic save, give it a default name |
| 147 | _game->getSavedGame()->setName(Language::fsToWstr(_filename)); |
| 148 | default: |
| 149 | break; |
| 150 | } |
| 151 | |
| 152 | // Save the game |
| 153 | try |
| 154 | { |
| 155 | std::string backup = _filename + ".bak"; |
| 156 | _game->getSavedGame()->save(backup); |
| 157 | std::string fullPath = Options::getUserFolder() + _filename; |
| 158 | std::string bakPath = Options::getUserFolder() + backup; |
| 159 | if (!CrossPlatform::moveFile(bakPath, fullPath)) |
| 160 | { |
| 161 | throw Exception("Save backed up in " + backup); |
| 162 | } |
| 163 | |
| 164 | if (_type == SAVE_IRONMAN_END) |
| 165 | { |
| 166 | Screen::updateScale(Options::geoscapeScale, Options::geoscapeScale, Options::baseXGeoscape, Options::baseYGeoscape, true); |
| 167 | _game->getScreen()->resetDisplay(false); |
| 168 | |
| 169 | _game->setState(new MainMenuState(_game)); |
| 170 | _game->setSavedGame(0); |
| 171 | } |
| 172 | } |
| 173 | catch (Exception &e) |
| 174 | { |
| 175 | Log(LOG_ERROR) << e.what(); |
| 176 | std::wostringstream error; |
| 177 | error << tr("STR_SAVE_UNSUCCESSFUL") << L'\x02' << Language::fsToWstr(e.what()); |
| 178 | if (_origin != OPT_BATTLESCAPE) |
| 179 | _game->pushState(new ErrorMessageState(_game, error.str(), _palette, Palette::blockOffset(8) + 10, "BACK01.SCR", 6)); |
| 180 | else |
| 181 | _game->pushState(new ErrorMessageState(_game, error.str(), _palette, Palette::blockOffset(0), "TAC00.SCR", -1)); |
nothing calls this directly
no test coverage detected