* We have written the whole game into memory, _memory_savegame, now find * and appropriate compressor and start writing to file. */
| 2987 | * and appropriate compressor and start writing to file. |
| 2988 | */ |
| 2989 | static SaveOrLoadResult SaveFileToDisk(bool threaded) |
| 2990 | { |
| 2991 | try { |
| 2992 | auto [fmt, compression] = GetSavegameFormat(_savegame_format); |
| 2993 | |
| 2994 | /* We have written our stuff to memory, now write it to file! */ |
| 2995 | uint32_t hdr[2] = { fmt.tag, TO_BE32(SAVEGAME_VERSION << 16) }; |
| 2996 | _sl.sf->Write((uint8_t*)hdr, sizeof(hdr)); |
| 2997 | |
| 2998 | _sl.sf = fmt.init_write(_sl.sf, compression); |
| 2999 | _sl.dumper->Flush(_sl.sf); |
| 3000 | |
| 3001 | ClearSaveLoadState(); |
| 3002 | |
| 3003 | if (threaded) SetAsyncSaveFinish(SaveFileDone); |
| 3004 | |
| 3005 | return SL_OK; |
| 3006 | } catch (...) { |
| 3007 | ClearSaveLoadState(); |
| 3008 | |
| 3009 | AsyncSaveFinishProc asfp = SaveFileDone; |
| 3010 | |
| 3011 | /* We don't want to shout when saving is just |
| 3012 | * cancelled due to a client disconnecting. */ |
| 3013 | if (_sl.error_str != STR_NETWORK_ERROR_LOSTCONNECTION) { |
| 3014 | /* Skip the "colour" character */ |
| 3015 | Debug(sl, 0, "{}", GetSaveLoadErrorType().GetDecodedString().substr(3) + GetSaveLoadErrorMessage().GetDecodedString()); |
| 3016 | asfp = SaveFileError; |
| 3017 | } |
| 3018 | |
| 3019 | if (threaded) { |
| 3020 | SetAsyncSaveFinish(asfp); |
| 3021 | } else { |
| 3022 | asfp(); |
| 3023 | } |
| 3024 | return SL_ERROR; |
| 3025 | } |
| 3026 | } |
| 3027 | |
| 3028 | void WaitTillSaved() |
| 3029 | { |
no test coverage detected