OpenTTD Source 20261112-master-gbcbec5e63f
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef FIOS_H
11#define FIOS_H
12
13#include "company_base.h"
14#include "newgrf_config.h"
15#include "gamelog.h"
18
19
26
34
35using CompanyPropertiesMap = std::map<uint, std::unique_ptr<CompanyProperties>>;
36
40struct LoadCheckData {
41 bool checkable = false;
43 std::string error_msg{};
44
45 uint32_t map_size_x = 0;
46 uint32_t map_size_y = 0;
47 TimerGameCalendar::Date current_date{};
48
51
52 CompanyPropertiesMap companies{};
53
54 GRFConfigList grfconfig{};
56
58
59 LoadCheckData() {}
60
65 bool HasErrors()
66 {
67 return this->checkable && this->error != INVALID_STRING_ID;
68 }
69
75 {
76 return this->checkable && this->error == INVALID_STRING_ID && !this->grfconfig.empty();
77 }
78
79 void Clear();
80};
81
83
85struct FiosItem {
86 FiosType type;
87 int64_t mtime;
88 EncodedString title;
89 std::string name;
90};
91
93class FileList : public std::vector<FiosItem> {
94public:
95 void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop, bool show_dirs);
96 const FiosItem *FindItem(std::string_view file);
97};
98bool FiosItemSorter(const FiosItem &a, const FiosItem &b);
99bool FiosItemNameSorter(const FiosItem &a, const FiosItem &b);
100bool FiosItemModificationDateSorter(const FiosItem &a, const FiosItem &b);
101
102void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop);
103
104void FiosGetSavegameList(SaveLoadOperation fop, bool show_dirs, FileList &file_list);
105void FiosGetScenarioList(SaveLoadOperation fop, bool show_dirs, FileList &file_list);
106void FiosGetHeightmapList(SaveLoadOperation fop, bool show_dirs, FileList &file_list);
107void FiosGetTownDataList(SaveLoadOperation fop, bool show_dirs, FileList &file_list);
108
109bool FiosBrowseTo(const FiosItem *item);
110
111std::string FiosGetCurrentPath();
112std::optional<uint64_t> FiosGetDiskFreeSpace(const std::string &path);
113std::string FiosMakeHeightmapName(std::string_view name);
114std::string FiosMakeSavegameName(std::string_view name);
115DirectoryCreateResult FiosCreateDirectory(std::string_view name);
116
117std::tuple<FiosType, std::string> FiosGetSavegameListCallback(SaveLoadOperation fop, std::string_view file, std::string_view ext);
118std::tuple<FiosType, std::string> FiosGetScenarioListCallback(SaveLoadOperation fop, std::string_view file, std::string_view ext);
119std::tuple<FiosType, std::string> FiosGetHeightmapListCallback(SaveLoadOperation fop, std::string_view file, std::string_view ext);
120
121void ScanScenarios();
122std::optional<std::string_view> FindScenario(const ContentInfo &ci, bool md5sum);
123
128 FiosNumberedSaveName(const std::string &prefix);
129 std::string Filename();
130 std::string Extension();
131private:
132 std::string prefix;
133 int number;
134};
135
136#endif /* FIOS_H */
Container for an encoded string, created by GetEncodedString.
List of file information.
Definition fios.h:93
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:57
const FiosItem * FindItem(std::string_view file)
Find file information of a file by its name from the file list.
Definition fios.cpp:93
StrongType::Typedef< int32_t, struct YearTag< struct Calendar >, StrongType::Compare, StrongType::Integer > Year
StrongType::Typedef< int32_t, DateTag< struct Calendar >, StrongType::Compare, StrongType::Integer > Date
Definition of stuff that is very close to a company, like the company struct itself.
SaveLoadOperation
Operation performed on the file.
Definition fileio_type.h:51
AbstractFileType
The different abstract types of files that the system knows about.
Definition fileio_type.h:16
bool FiosItemSorter(const FiosItem &a, const FiosItem &b)
Sorts the FiosItems based on the savegame sorter and order.
Definition fios_gui.cpp:57
std::tuple< FiosType, std::string > FiosGetScenarioListCallback(SaveLoadOperation fop, std::string_view file, std::string_view ext)
Callback for FiosGetFileList.
Definition fios.cpp:461
DirectoryCreateResult
Outcome of a directory creation attempt.
Definition fios.h:28
@ PermissionDenied
The OS rejected the operation for permission reasons.
Definition fios.h:31
@ Success
Directory was created.
Definition fios.h:29
@ OtherError
Any other filesystem error.
Definition fios.h:32
@ AlreadyExists
A file or directory with that name already exists.
Definition fios.h:30
bool FiosItemModificationDateSorter(const FiosItem &a, const FiosItem &b)
Sort files by their modification date, and name when they are equal.
Definition fios.cpp:45
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Launch save/load dialog in the given mode.
std::optional< std::string_view > FindScenario(const ContentInfo &ci, bool md5sum)
Find a given scenario based on its unique ID.
Definition fios.cpp:685
std::string FiosMakeSavegameName(std::string_view name)
Make a save game or scenario filename from a name.
Definition fios.cpp:239
bool FiosItemNameSorter(const FiosItem &a, const FiosItem &b)
Sort files by their name.
Definition fios.cpp:39
std::tuple< FiosType, std::string > FiosGetSavegameListCallback(SaveLoadOperation fop, std::string_view file, std::string_view ext)
Callback for FiosGetFileList.
Definition fios.cpp:412
std::string FiosGetCurrentPath()
Get the current path/working directory.
Definition fios.cpp:123
SaveLoadInvalidateWindowData
Special values for save-load window for the data parameter of InvalidateWindowData.
Definition fios.h:21
@ SLIWD_FILTER_CHANGES
The filename filter has changed (via the editbox).
Definition fios.h:24
@ SLIWD_SELECTION_CHANGES
File selection has changed (user click, ...).
Definition fios.h:23
@ SLIWD_RESCAN_FILES
Rescan all files (when changed directory, ...).
Definition fios.h:22
void FiosGetSavegameList(SaveLoadOperation fop, bool show_dirs, FileList &file_list)
Get a list of savegames.
Definition fios.cpp:441
void FiosGetHeightmapList(SaveLoadOperation fop, bool show_dirs, FileList &file_list)
Get a list of heightmaps.
Definition fios.cpp:548
void ScanScenarios()
Force a (re)scan of the scenarios.
Definition fios.cpp:713
std::string FiosMakeHeightmapName(std::string_view name)
Construct a filename for a height map.
Definition fios.cpp:251
void FiosGetScenarioList(SaveLoadOperation fop, bool show_dirs, FileList &file_list)
Get a list of scenarios.
Definition fios.cpp:488
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
Definition fios_gui.cpp:42
DirectoryCreateResult FiosCreateDirectory(std::string_view name)
Create a new subdirectory inside the current FIOS path.
Definition fios.cpp:134
bool FiosBrowseTo(const FiosItem *item)
Browse to a new path based on the passed item, starting at _fios_path.
Definition fios.cpp:165
void FiosGetTownDataList(SaveLoadOperation fop, bool show_dirs, FileList &file_list)
Get a list of town data files.
Definition fios.cpp:585
Functions to be called to log fundamental changes to the game.
LandscapeType
Landscape types.
Functions to find and configure NewGRFs.
GRFListCompatibility
Status of post-gameload GRF compatibility check.
@ NotFound
At least one GRF couldn't be found (higher priority than GRFListCompatibility::Compatible).
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > StringID
Numeric value that represents a string, independent of the selected language.
static constexpr StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames).
Container for all important information about a piece of content.
Deals with finding savegames.
Definition fios.h:85
std::string Filename()
Generate a savegame name and number according to _settings_client.gui.max_num_autosaves.
Definition fios.cpp:755
FiosNumberedSaveName(const std::string &prefix)
Constructs FiosNumberedSaveName.
Definition fios.cpp:722
std::string Extension()
Generate an extension for a savegame name.
Definition fios.cpp:765
Elements of a file system that are recognized.
Definition fileio_type.h:62
Container for loading in mode SL_LOAD_CHECK.
Definition fios.h:40
bool checkable
True if the savegame could be checked by SL_LOAD_CHECK. (Old savegames are not checkable....
Definition fios.h:41
bool HasNewGrfs()
Check whether the game uses any NewGrfs.
Definition fios.h:74
std::string error_msg
Data to pass to string parameters when displaying error.
Definition fios.h:43
TimerGameCalendar::Year starting_year
Starting date.
Definition fios.h:50
CompanyPropertiesMap companies
Company information.
Definition fios.h:52
StringID error
Error message from loading. INVALID_STRING_ID if no error.
Definition fios.h:42
Gamelog gamelog
Gamelog actions.
Definition fios.h:57
bool HasErrors()
Check whether loading the game resulted in errors.
Definition fios.h:65
void Clear()
Reset read data.
Definition fios_gui.cpp:72
GRFListCompatibility grf_compatibility
Summary state of NewGrfs, whether missing files or only compatible found.
Definition fios.h:55
LandscapeType landscape
Landscape type.
Definition fios.h:49
GRFConfigList grfconfig
NewGrf configuration from save.
Definition fios.h:54
Basic types related to the content on the content server.
Definition of the game-calendar-timer.