OpenTTD Source  1.11.0-beta2
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"
17 
18 
24 };
25 
27 
31 struct LoadCheckData {
32  bool checkable;
34  char *error_data;
35 
36  uint32 map_size_x, map_size_y;
37  Date current_date;
38 
39  GameSettings settings;
40 
42 
45 
48 
49  LoadCheckData() : error_data(nullptr), grfconfig(nullptr),
51  {
52  this->Clear();
53  }
54 
59  {
60  this->Clear();
61  }
62 
67  bool HasErrors()
68  {
69  return this->checkable && this->error != INVALID_STRING_ID;
70  }
71 
76  bool HasNewGrfs()
77  {
78  return this->checkable && this->error == INVALID_STRING_ID && this->grfconfig != nullptr;
79  }
80 
81  void Clear();
82 };
83 
85 
86 
87 enum FileSlots {
100 };
101 
103 struct FiosItem {
104  FiosType type;
105  uint64 mtime;
106  char title[64];
107  char name[MAX_PATH];
108  bool operator< (const FiosItem &other) const;
109 };
110 
112 class FileList {
113 public:
114  ~FileList();
115 
120  inline FiosItem *Append()
121  {
122  return &this->files.emplace_back();
123  }
124 
129  inline size_t Length() const
130  {
131  return this->files.size();
132  }
133 
138  inline const FiosItem *Begin() const
139  {
140  return this->files.data();
141  }
142 
147  inline const FiosItem *End() const
148  {
149  return this->Begin() + this->Length();
150  }
151 
156  inline const FiosItem *Get(size_t index) const
157  {
158  return this->files.data() + index;
159  }
160 
165  inline FiosItem *Get(size_t index)
166  {
167  return this->files.data() + index;
168  }
169 
170  inline const FiosItem &operator[](size_t index) const
171  {
172  return this->files[index];
173  }
174 
179  inline FiosItem &operator[](size_t index)
180  {
181  return this->files[index];
182  }
183 
185  inline void Clear()
186  {
187  this->files.clear();
188  }
189 
191  inline void Compact()
192  {
193  this->files.shrink_to_fit();
194  }
195 
196  void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop);
197  const FiosItem *FindItem(const char *file);
198 
199  std::vector<FiosItem> files;
200 };
201 
202 enum SortingBits {
203  SORT_ASCENDING = 0,
204  SORT_DESCENDING = 1,
205  SORT_BY_DATE = 0,
206  SORT_BY_NAME = 2
207 };
208 DECLARE_ENUM_AS_BIT_SET(SortingBits)
209 
210 /* Variables to display file lists */
211 extern SortingBits _savegame_sort_order;
212 
213 void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop);
214 
215 void FiosGetSavegameList(SaveLoadOperation fop, FileList &file_list);
216 void FiosGetScenarioList(SaveLoadOperation fop, FileList &file_list);
217 void FiosGetHeightmapList(SaveLoadOperation fop, FileList &file_list);
218 
219 const char *FiosBrowseTo(const FiosItem *item);
220 
221 StringID FiosGetDescText(const char **path, uint64 *total_free);
222 bool FiosDelete(const char *name);
223 std::string FiosMakeHeightmapName(const char *name);
224 std::string FiosMakeSavegameName(const char *name);
225 
226 FiosType FiosGetSavegameListCallback(SaveLoadOperation fop, const std::string &file, const char *ext, char *title, const char *last);
227 
228 #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:32
FileList::End
const FiosItem * End() const
Get a pointer behind the last file information.
Definition: fios.h:147
SLIWD_RESCAN_FILES
@ SLIWD_RESCAN_FILES
Rescan all files (when changed directory, ...)
Definition: fios.h:21
FileList::Compact
void Compact()
Compact the list down to the smallest block size boundary.
Definition: fios.h:191
LoadCheckData::gamelog_action
struct LoggedAction * gamelog_action
Gamelog actions.
Definition: fios.h:46
company_base.h
SaveLoadOperation
SaveLoadOperation
Operation performed on the file.
Definition: fileio_type.h:47
_load_check_data
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
Definition: fios_gui.cpp:38
FIRST_GRF_SLOT
@ FIRST_GRF_SLOT
First slot usable for (New)GRFs used during the game.
Definition: fios.h:97
LoadCheckData::grfconfig
GRFConfig * grfconfig
NewGrf configuration from save.
Definition: fios.h:43
FiosGetScenarioList
void FiosGetScenarioList(SaveLoadOperation fop, FileList &file_list)
Get a list of scenarios.
Definition: fios.cpp:549
LoadCheckData::HasErrors
bool HasErrors()
Check whether loading the game resulted in errors.
Definition: fios.h:67
FiosGetHeightmapList
void FiosGetHeightmapList(SaveLoadOperation fop, FileList &file_list)
Get a list of heightmaps.
Definition: fios.cpp:611
newgrf_config.h
FiosGetDescText
StringID FiosGetDescText(const char **path, uint64 *total_free)
Get descriptive texts.
Definition: fios.cpp:141
FileList
List of file information.
Definition: fios.h:112
SmallMap< uint, CompanyProperties * >
FileList::Clear
void Clear()
Remove all items from the list.
Definition: fios.h:185
FileList::Get
FiosItem * Get(size_t index)
Get a pointer to the indicated file information.
Definition: fios.h:165
LoadCheckData::~LoadCheckData
~LoadCheckData()
Don't leak memory at program exit.
Definition: fios.h:58
AbstractFileType
AbstractFileType
The different abstract types of files that the system knows about.
Definition: fileio_type.h:16
tcp_content.h
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition: newgrf_config.h:152
FileList::Get
const FiosItem * Get(size_t index) const
Get a pointer to the indicated file information.
Definition: fios.h:156
CONFIG_SLOT
@ CONFIG_SLOT
Slot used for the GRF scanning and such.
Definition: fios.h:93
SLIWD_FILTER_CHANGES
@ SLIWD_FILTER_CHANGES
The filename filter has changed (via the editbox)
Definition: fios.h:23
LoadCheckData::error_data
char * error_data
Data to pass to SetDParamStr when displaying error.
Definition: fios.h:34
LoadCheckData::gamelog_actions
uint gamelog_actions
Number of gamelog actions.
Definition: fios.h:47
FileList::BuildFileList
void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Construct a file list with the given kind of files, for the stated purpose.
Definition: fios.cpp:76
Date
int32 Date
The type to store our dates in.
Definition: date_type.h:14
FiosMakeHeightmapName
std::string FiosMakeHeightmapName(const char *name)
Construct a filename for a height map.
Definition: fios.cpp:245
FiosItem
Deals with finding savegames.
Definition: fios.h:103
FiosMakeSavegameName
std::string FiosMakeSavegameName(const char *name)
Make a save game or scenario filename from a name.
Definition: fios.cpp:233
FileList::files
std::vector< FiosItem > files
The list of files.
Definition: fios.h:199
MAX_FILE_SLOTS
@ MAX_FILE_SLOTS
Maximum number of slots.
Definition: fios.h:99
FileList::FindItem
const FiosItem * FindItem(const char *file)
Find file information of a file by its name from the file list.
Definition: fios.cpp:108
GameSettings
All settings together for the game.
Definition: settings_type.h:548
SLIWD_SELECTION_CHANGES
@ SLIWD_SELECTION_CHANGES
File selection has changed (user click, ...)
Definition: fios.h:22
FiosDelete
bool FiosDelete(const char *name)
Delete a file.
Definition: fios.cpp:258
ShowSaveLoadDialog
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Launch save/load dialog in the given mode.
Definition: fios_gui.cpp:920
FiosGetSavegameList
void FiosGetSavegameList(SaveLoadOperation fop, FileList &file_list)
Get a list of savegames.
Definition: fios.cpp:500
FileList::Append
FiosItem * Append()
Construct a new entry in the file list.
Definition: fios.h:120
LoadCheckData::error
StringID error
Error message from loading. INVALID_STRING_ID if no error.
Definition: fios.h:33
LoadCheckData
Container for loading in mode SL_LOAD_CHECK.
Definition: fios.h:31
LoadCheckData::companies
CompanyPropertiesMap companies
Company information.
Definition: fios.h:41
FileList::operator[]
FiosItem & operator[](size_t index)
Get a reference to the indicated file information.
Definition: fios.h:179
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
LoadCheckData::Clear
void Clear()
Reset read data.
Definition: fios_gui.cpp:47
LoadCheckData::grf_compatibility
GRFListCompatibility grf_compatibility
Summary state of NewGrfs, whether missing files or only compatible found.
Definition: fios.h:44
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
FiosBrowseTo
const char * FiosBrowseTo(const FiosItem *item)
Browse to a new path based on the passed item, starting at #_fios_path.
Definition: fios.cpp:152
SOUND_SLOT
@ SOUND_SLOT
Slot for the sound.
Definition: fios.h:95
LoadCheckData::HasNewGrfs
bool HasNewGrfs()
Check whether the game uses any NewGrfs.
Definition: fios.h:76
FileList::Begin
const FiosItem * Begin() const
Get a pointer to the first file information.
Definition: fios.h:138
gfx_type.h
SaveLoadInvalidateWindowData
SaveLoadInvalidateWindowData
Special values for save-load window for the data parameter of InvalidateWindowData.
Definition: fios.h:20
FileSlots
FileSlots
Definition: fios.h:87
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
LoggedAction
Contains information about one logged action that caused at least one logged change.
Definition: gamelog_internal.h:80
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
FileList::Length
size_t Length() const
Get the number of files in the list.
Definition: fios.h:129
FiosItem::operator<
bool operator<(const FiosItem &other) const
Compare two FiosItem's.
Definition: fios.cpp:53
FiosGetSavegameListCallback
FiosType FiosGetSavegameListCallback(SaveLoadOperation fop, const std::string &file, const char *ext, char *title, const char *last)
Callback for FiosGetFileList.
Definition: fios.cpp:467