2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 /** @file fios.h Declarations for savegames operations */
14 #include "company_base.h"
15 #include "newgrf_config.h"
17 #include "network/core/tcp_content_type.h"
18 #include "timer/timer_game_calendar.h"
21 /** Special values for save-load window for the data parameter of #InvalidateWindowData. */
22 enum SaveLoadInvalidateWindowData
{
23 SLIWD_RESCAN_FILES
, ///< Rescan all files (when changed directory, ...)
24 SLIWD_SELECTION_CHANGES
, ///< File selection has changed (user click, ...)
25 SLIWD_FILTER_CHANGES
, ///< The filename filter has changed (via the editbox)
28 using CompanyPropertiesMap
= std::map
<uint
, std::unique_ptr
<CompanyProperties
>>;
31 * Container for loading in mode SL_LOAD_CHECK.
33 struct LoadCheckData
{
34 bool checkable
; ///< True if the savegame could be checked by SL_LOAD_CHECK. (Old savegames are not checkable.)
35 StringID error
; ///< Error message from loading. INVALID_STRING_ID if no error.
36 std::string error_msg
; ///< Data to pass to SetDParamStr when displaying #error.
38 uint32_t map_size_x
, map_size_y
;
39 TimerGameCalendar::Date current_date
;
41 GameSettings settings
;
43 CompanyPropertiesMap companies
; ///< Company information.
45 GRFConfig
*grfconfig
; ///< NewGrf configuration from save.
46 GRFListCompatibility grf_compatibility
; ///< Summary state of NewGrfs, whether missing files or only compatible found.
48 Gamelog gamelog
; ///< Gamelog actions
50 LoadCheckData() : grfconfig(nullptr),
51 grf_compatibility(GLC_NOT_FOUND
)
56 * Check whether loading the game resulted in errors.
57 * @return true if errors were encountered.
61 return this->checkable
&& this->error
!= INVALID_STRING_ID
;
65 * Check whether the game uses any NewGrfs.
66 * @return true if NewGrfs are used.
70 return this->checkable
&& this->error
== INVALID_STRING_ID
&& this->grfconfig
!= nullptr;
76 extern LoadCheckData _load_check_data
;
78 /** Deals with finding savegames */
84 bool operator< (const FiosItem
&other
) const;
87 /** List of file information. */
88 class FileList
: public std::vector
<FiosItem
> {
90 void BuildFileList(AbstractFileType abstract_filetype
, SaveLoadOperation fop
, bool show_dirs
);
91 const FiosItem
*FindItem(const std::string_view file
);
100 DECLARE_ENUM_AS_BIT_SET(SortingBits
)
102 /* Variables to display file lists */
103 extern SortingBits _savegame_sort_order
;
105 void ShowSaveLoadDialog(AbstractFileType abstract_filetype
, SaveLoadOperation fop
);
107 void FiosGetSavegameList(SaveLoadOperation fop
, bool show_dirs
, FileList
&file_list
);
108 void FiosGetScenarioList(SaveLoadOperation fop
, bool show_dirs
, FileList
&file_list
);
109 void FiosGetHeightmapList(SaveLoadOperation fop
, bool show_dirs
, FileList
&file_list
);
110 void FiosGetTownDataList(SaveLoadOperation fop
, bool show_dirs
, FileList
&file_list
);
112 bool FiosBrowseTo(const FiosItem
*item
);
114 std::string
FiosGetCurrentPath();
115 std::optional
<uint64_t> FiosGetDiskFreeSpace(const std::string
&path
);
116 bool FiosDelete(const char *name
);
117 std::string
FiosMakeHeightmapName(const char *name
);
118 std::string
FiosMakeSavegameName(const char *name
);
120 std::tuple
<FiosType
, std::string
> FiosGetSavegameListCallback(SaveLoadOperation fop
, const std::string
&file
, const std::string_view ext
);
121 std::tuple
<FiosType
, std::string
> FiosGetScenarioListCallback(SaveLoadOperation fop
, const std::string
&file
, const std::string_view ext
);
122 std::tuple
<FiosType
, std::string
> FiosGetHeightmapListCallback(SaveLoadOperation fop
, const std::string
&file
, const std::string_view ext
);
124 void ScanScenarios();
125 const char *FindScenario(const ContentInfo
*ci
, bool md5sum
);
128 * A savegame name automatically numbered.
130 struct FiosNumberedSaveName
{
131 FiosNumberedSaveName(const std::string
&prefix
);
132 std::string
Filename();
133 std::string
Extension();