* Return the savegameformat of the game. Whether it was created with ZLIB compression * uncompressed, or another type * @param full_name Name of the savegame format. If empty it picks the first available one * @return Pair containing reference to SaveLoadFormat struct giving all characteristics of this type of savegame, and a compression level to use. */
| 2847 | * @return Pair containing reference to SaveLoadFormat struct giving all characteristics of this type of savegame, and a compression level to use. |
| 2848 | */ |
| 2849 | static std::pair<const SaveLoadFormat &, uint8_t> GetSavegameFormat(std::string_view full_name) |
| 2850 | { |
| 2851 | /* Find default savegame format, the highest one with which files can be written. */ |
| 2852 | auto it = std::find_if(std::rbegin(_saveload_formats), std::rend(_saveload_formats), [](const auto &slf) { return slf.init_write != nullptr; }); |
| 2853 | if (it == std::rend(_saveload_formats)) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR, "no writeable savegame formats"); |
| 2854 | |
| 2855 | const SaveLoadFormat &def = *it; |
| 2856 | |
| 2857 | if (!full_name.empty()) { |
| 2858 | /* Get the ":..." of the compression level out of the way */ |
| 2859 | size_t separator = full_name.find(':'); |
| 2860 | bool has_comp_level = separator != std::string::npos; |
| 2861 | std::string_view name = has_comp_level ? full_name.substr(0, separator) : full_name; |
| 2862 | |
| 2863 | for (const auto &slf : _saveload_formats) { |
| 2864 | if (slf.init_write != nullptr && name == slf.name) { |
| 2865 | if (has_comp_level) { |
| 2866 | auto complevel = full_name.substr(separator + 1); |
| 2867 | |
| 2868 | /* Get the level and determine whether all went fine. */ |
| 2869 | auto level = ParseInteger<uint8_t>(complevel); |
| 2870 | if (!level.has_value() || *level != Clamp(*level, slf.min_compression, slf.max_compression)) { |
| 2871 | ShowErrorMessage( |
| 2872 | GetEncodedString(STR_CONFIG_ERROR), |
| 2873 | GetEncodedString(STR_CONFIG_ERROR_INVALID_SAVEGAME_COMPRESSION_LEVEL, complevel), |
| 2874 | WL_CRITICAL); |
| 2875 | } else { |
| 2876 | return {slf, *level}; |
| 2877 | } |
| 2878 | } |
| 2879 | return {slf, slf.default_compression}; |
| 2880 | } |
| 2881 | } |
| 2882 | |
| 2883 | ShowErrorMessage( |
| 2884 | GetEncodedString(STR_CONFIG_ERROR), |
| 2885 | GetEncodedString(STR_CONFIG_ERROR_INVALID_SAVEGAME_COMPRESSION_ALGORITHM, name, def.name), |
| 2886 | WL_CRITICAL); |
| 2887 | } |
| 2888 | return {def, def.default_compression}; |
| 2889 | } |
| 2890 | |
| 2891 | /* actual loader/saver function */ |
| 2892 | void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settings); |
no test coverage detected