OpenTTD Source  14.0-beta3
fios.h
Go to the documentation of this file.
1 /*
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/>.
6  */
7 
10 #ifndef FIOS_H
11 #define FIOS_H
12 
13 #include "gfx_type.h"
14 #include "company_base.h"
15 #include "newgrf_config.h"
16 #include "gamelog.h"
19 
20 
26 };
27 
28 using CompanyPropertiesMap = std::map<uint, std::unique_ptr<CompanyProperties>>;
29 
33 struct LoadCheckData {
34  bool checkable;
36  std::string error_msg;
37 
38  uint32_t map_size_x, map_size_y;
39  TimerGameCalendar::Date current_date;
40 
41  GameSettings settings;
42 
43  CompanyPropertiesMap companies;
44 
47 
49 
50  LoadCheckData() : grfconfig(nullptr),
52  {
53  }
54 
59  bool HasErrors()
60  {
61  return this->checkable && this->error != INVALID_STRING_ID;
62  }
63 
68  bool HasNewGrfs()
69  {
70  return this->checkable && this->error == INVALID_STRING_ID && this->grfconfig != nullptr;
71  }
72 
73  void Clear();
74 };
75 
77 
79 struct FiosItem {
80  FiosType type;
81  uint64_t mtime;
82  std::string title;
83  std::string name;
84  bool operator< (const FiosItem &other) const;
85 };
86 
88 class FileList : public std::vector<FiosItem> {
89 public:
90  void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop, bool show_dirs);
91  const FiosItem *FindItem(const std::string_view file);
92 };
93 
94 enum SortingBits {
95  SORT_ASCENDING = 0,
96  SORT_DESCENDING = 1,
97  SORT_BY_DATE = 0,
98  SORT_BY_NAME = 2
99 };
100 DECLARE_ENUM_AS_BIT_SET(SortingBits)
101 
102 /* Variables to display file lists */
103 extern SortingBits _savegame_sort_order;
104 
105 void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop);
106 
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 
111 bool FiosBrowseTo(const FiosItem *item);
112 
113 std::string FiosGetCurrentPath();
114 std::optional<uint64_t> FiosGetDiskFreeSpace(const std::string &path);
115 bool FiosDelete(const char *name);
116 std::string FiosMakeHeightmapName(const char *name);
117 std::string FiosMakeSavegameName(const char *name);
118 
119 std::tuple<FiosType, std::string> FiosGetSavegameListCallback(SaveLoadOperation fop, const std::string &file, const std::string_view ext);
120 std::tuple<FiosType, std::string> FiosGetScenarioListCallback(SaveLoadOperation fop, const std::string &file, const std::string_view ext);
121 std::tuple<FiosType, std::string> FiosGetHeightmapListCallback(SaveLoadOperation fop, const std::string &file, const std::string_view ext);
122 
123 void ScanScenarios();
124 const char *FindScenario(const ContentInfo *ci, bool md5sum);
125 
130  FiosNumberedSaveName(const std::string &prefix);
131  std::string Filename();
132  std::string Extension();
133 private:
134  std::string prefix;
135  int number;
136 };
137 
138 #endif /* FIOS_H */
LoadCheckData::checkable
bool checkable
True if the savegame could be checked by SL_LOAD_CHECK. (Old savegames are not checkable....
Definition: fios.h:34
LoadCheckData::error_msg
std::string error_msg
Data to pass to SetDParamStr when displaying error.
Definition: fios.h:36
SLIWD_RESCAN_FILES
@ SLIWD_RESCAN_FILES
Rescan all files (when changed directory, ...)
Definition: fios.h:23
FiosGetCurrentPath
std::string FiosGetCurrentPath()
Get the current path/working directory.
Definition: fios.cpp:133
company_base.h
timer_game_calendar.h
FiosNumberedSaveName::FiosNumberedSaveName
FiosNumberedSaveName(const std::string &prefix)
Constructs FiosNumberedSaveName.
Definition: fios.cpp:725
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
SaveLoadOperation
SaveLoadOperation
Operation performed on the file.
Definition: fileio_type.h:47
FiosGetScenarioList
void FiosGetScenarioList(SaveLoadOperation fop, bool show_dirs, FileList &file_list)
Get a list of scenarios.
Definition: fios.cpp:520
FiosBrowseTo
bool FiosBrowseTo(const FiosItem *item)
Browse to a new path based on the passed item, starting at #_fios_path.
Definition: fios.cpp:143
_load_check_data
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
Definition: fios_gui.cpp:40
LoadCheckData::grfconfig
GRFConfig * grfconfig
NewGrf configuration from save.
Definition: fios.h:45
StrongType::Typedef
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition: strong_typedef_type.hpp:150
LoadCheckData::HasErrors
bool HasErrors()
Check whether loading the game resulted in errors.
Definition: fios.h:59
newgrf_config.h
gamelog.h
FileList
List of file information.
Definition: fios.h:88
FiosGetScenarioListCallback
std::tuple< FiosType, std::string > FiosGetScenarioListCallback(SaveLoadOperation fop, const std::string &file, const std::string_view ext)
Callback for FiosGetFileList.
Definition: fios.cpp:493
FileList::FindItem
const FiosItem * FindItem(const std::string_view file)
Find file information of a file by its name from the file list.
Definition: fios.cpp:102
AbstractFileType
AbstractFileType
The different abstract types of files that the system knows about.
Definition: fileio_type.h:16
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition: newgrf_config.h:147
SLIWD_FILTER_CHANGES
@ SLIWD_FILTER_CHANGES
The filename filter has changed (via the editbox)
Definition: fios.h:25
tcp_content_type.h
ContentInfo
Container for all important information about a piece of content.
Definition: tcp_content_type.h:52
FiosMakeHeightmapName
std::string FiosMakeHeightmapName(const char *name)
Construct a filename for a height map.
Definition: fios.cpp:234
FiosItem
Deals with finding savegames.
Definition: fios.h:79
FiosMakeSavegameName
std::string FiosMakeSavegameName(const char *name)
Make a save game or scenario filename from a name.
Definition: fios.cpp:222
GameSettings
All settings together for the game.
Definition: settings_type.h:617
SLIWD_SELECTION_CHANGES
@ SLIWD_SELECTION_CHANGES
File selection has changed (user click, ...)
Definition: fios.h:24
FiosGetSavegameListCallback
std::tuple< FiosType, std::string > FiosGetSavegameListCallback(SaveLoadOperation fop, const std::string &file, const std::string_view ext)
Callback for FiosGetFileList.
Definition: fios.cpp:444
FiosDelete
bool FiosDelete(const char *name)
Delete a file.
Definition: fios.cpp:247
ShowSaveLoadDialog
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Launch save/load dialog in the given mode.
Definition: fios_gui.cpp:914
LoadCheckData::error
StringID error
Error message from loading. INVALID_STRING_ID if no error.
Definition: fios.h:35
LoadCheckData
Container for loading in mode SL_LOAD_CHECK.
Definition: fios.h:33
FiosGetHeightmapList
void FiosGetHeightmapList(SaveLoadOperation fop, bool show_dirs, FileList &file_list)
Get a list of heightmaps.
Definition: fios.cpp:580
LoadCheckData::companies
CompanyPropertiesMap companies
Company information.
Definition: fios.h:43
FiosNumberedSaveName
A savegame name automatically numbered.
Definition: fios.h:129
LoadCheckData::Clear
void Clear()
Reset read data.
Definition: fios_gui.cpp:48
FindScenario
const char * FindScenario(const ContentInfo *ci, bool md5sum)
Find a given scenario based on its unique ID.
Definition: fios.cpp:688
LoadCheckData::grf_compatibility
GRFListCompatibility grf_compatibility
Summary state of NewGrfs, whether missing files or only compatible found.
Definition: fios.h:46
FiosType
FiosType
Elements of a file system that are recognized.
Definition: fileio_type.h:67
DECLARE_ENUM_AS_BIT_SET
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
Definition: company_manager_face.h:29
LoadCheckData::gamelog
Gamelog gamelog
Gamelog actions.
Definition: fios.h:48
Gamelog
Definition: gamelog.h:49
LoadCheckData::HasNewGrfs
bool HasNewGrfs()
Check whether the game uses any NewGrfs.
Definition: fios.h:68
FiosNumberedSaveName::Extension
std::string Extension()
Generate an extension for a savegame name.
Definition: fios.cpp:772
gfx_type.h
FiosGetSavegameList
void FiosGetSavegameList(SaveLoadOperation fop, bool show_dirs, FileList &file_list)
Get a list of savegames.
Definition: fios.cpp:473
SaveLoadInvalidateWindowData
SaveLoadInvalidateWindowData
Special values for save-load window for the data parameter of InvalidateWindowData.
Definition: fios.h:22
FiosNumberedSaveName::Filename
std::string Filename()
Generate a savegame name and number according to _settings_client.gui.max_num_autosaves.
Definition: fios.cpp:762
GLC_NOT_FOUND
@ GLC_NOT_FOUND
At least one GRF couldn't be found (higher priority than GLC_COMPATIBLE)
Definition: newgrf_config.h:55
GRFListCompatibility
GRFListCompatibility
Status of post-gameload GRF compatibility check.
Definition: newgrf_config.h:52
FileList::BuildFileList
void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop, bool show_dirs)
Construct a file list with the given kind of files, for the stated purpose.
Definition: fios.cpp:70
ScanScenarios
void ScanScenarios()
Force a (re)scan of the scenarios.
Definition: fios.cpp:716
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
FiosItem::operator<
bool operator<(const FiosItem &other) const
Compare two FiosItem's.
Definition: fios.cpp:51