Translations update
[openttd/fttd.git] / src / fios.h
blobad6a387d9614ede5f20d1963d524a6ff51ccb37f
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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 */
10 /** @file fios.h Declarations for savegames operations */
12 #ifndef FIOS_H
13 #define FIOS_H
15 #include "gfx_type.h"
16 #include "company_base.h"
17 #include "gamelog.h"
18 #include "newgrf_config.h"
19 #include "network/core/tcp_content.h"
20 #include "saveload/saveload_data.h"
21 #include "saveload/saveload_error.h"
24 typedef SmallMap<uint, CompanyProperties *> CompanyPropertiesMap;
26 /**
27 * Container for loading in mode SL_LOAD_CHECK.
29 struct LoadCheckData {
30 bool checkable; ///< True if the savegame could be checked by SL_LOAD_CHECK. (Old savegames are not checkable.)
31 SlErrorData error; ///< Error message from loading. INVALID_STRING_ID if no error.
33 SavegameTypeVersion sl_version; ///< Savegame type and version
35 uint32 map_size_x, map_size_y;
36 Date current_date;
38 GameSettings settings;
40 CompanyPropertiesMap companies; ///< Company information.
42 GRFConfig *grfconfig; ///< NewGrf configuration from save.
43 GRFListCompatibility grf_compatibility; ///< Summary state of NewGrfs, whether missing files or only compatible found.
45 Gamelog gamelog; ///< Gamelog
47 LoadCheckData() : grfconfig(NULL), grf_compatibility(GLC_NOT_FOUND), gamelog()
49 this->Clear();
52 /**
53 * Don't leak memory at program exit
55 ~LoadCheckData()
57 this->Clear();
60 /**
61 * Check whether loading the game resulted in errors.
62 * @return true if errors were encountered.
64 bool HasErrors()
66 return this->checkable && this->error.str != INVALID_STRING_ID;
69 /**
70 * Check whether the game uses any NewGrfs.
71 * @return true if NewGrfs are used.
73 bool HasNewGrfs()
75 return this->checkable && this->error.str == INVALID_STRING_ID && this->grfconfig != NULL;
78 void Clear();
81 extern LoadCheckData _load_check_data;
84 enum FileSlots {
85 /**
86 * Slot used for the GRF scanning and such. This slot cannot be reused
87 * as it will otherwise cause issues when pressing "rescan directories".
88 * It can furthermore not be larger than LAST_GRF_SLOT as that complicates
89 * the testing for "too much NewGRFs".
91 CONFIG_SLOT = 0,
92 /** Slot for the sound. */
93 SOUND_SLOT = 1,
94 /** First slot usable for (New)GRFs used during the game. */
95 FIRST_GRF_SLOT = 2,
96 /** Last slot usable for (New)GRFs used during the game. */
97 LAST_GRF_SLOT = 63,
98 /** Maximum number of slots. */
99 MAX_FILE_SLOTS = 64
102 /** Deals with finding savegames */
103 struct FiosItem {
104 FiosType type;
105 uint64 mtime;
106 char title[64];
107 char name[MAX_PATH];
110 /** List of file information. */
111 class FileList {
112 public:
113 ~FileList();
116 * Construct a new entry in the file list.
117 * @return Pointer to the new items to be initialized.
119 inline FiosItem *Append()
121 return this->files.Append();
125 * Get the number of files in the list.
126 * @return The number of files stored in the list.
128 inline uint Length() const
130 return this->files.Length();
134 * Get a pointer to the first file information.
135 * @return Address of the first file information.
137 inline const FiosItem *Begin() const
139 return this->files.Begin();
143 * Get a pointer behind the last file information.
144 * @return Address behind the last file information.
146 inline const FiosItem *End() const
148 return this->files.End();
152 * Get a pointer to the indicated file information. File information must exist.
153 * @return Address of the indicated existing file information.
155 inline const FiosItem *Get(uint index) const
157 return this->files.Get(index);
161 * Get a pointer to the indicated file information. File information must exist.
162 * @return Address of the indicated existing file information.
164 inline FiosItem *Get(uint index)
166 return this->files.Get(index);
169 inline const FiosItem &operator[](uint index) const
171 return this->files[index];
175 * Get a reference to the indicated file information. File information must exist.
176 * @return The requested file information.
178 inline FiosItem &operator[](uint index)
180 return this->files[index];
183 /** Remove all items from the list. */
184 inline void Clear()
186 this->files.Clear();
189 /** Compact the list down to the smallest block size boundary. */
190 inline void Compact()
192 this->files.Compact();
195 void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop);
196 const FiosItem *FindItem(const char *file);
198 SmallVector<FiosItem, 32> files; ///< The list of files.
201 enum SortingBits {
202 SORT_ASCENDING = 0,
203 SORT_DESCENDING = 1,
204 SORT_BY_DATE = 0,
205 SORT_BY_NAME = 2
207 DECLARE_ENUM_AS_BIT_SET(SortingBits)
209 /* Variables to display file lists */
210 extern SortingBits _savegame_sort_order;
212 void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop);
214 void FiosGetSavegameList(SaveLoadOperation fop, FileList &file_list);
215 void FiosGetScenarioList(SaveLoadOperation fop, FileList &file_list);
216 void FiosGetHeightmapList(SaveLoadOperation fop, FileList &file_list);
218 const char *FiosBrowseTo(const FiosItem *item);
220 /* OS-specific functions are taken from their respective files (win32/unix/os2 .c) */
221 bool FiosGetDiskFreeSpace (const char *path, uint64 *tot);
223 const char *FiosGetPath (void);
224 bool FiosDelete(const char *name);
225 void FiosMakeHeightmapName(char *buf, const char *name, size_t size);
226 void FiosMakeSavegameName(char *buf, const char *name, size_t size);
228 FiosType FiosGetSavegameListCallback (SaveLoadOperation fop, const char *file, const char *ext, stringb *title = NULL);
230 int CDECL CompareFiosItems(const FiosItem *a, const FiosItem *b);
232 #endif /* FIOS_H */