OpenTTD Source 20260820-master-g39da062c0c
fios.h File Reference

Declarations for savegames operations. More...

#include "gfx_type.h"
#include "company_base.h"
#include "newgrf_config.h"
#include "gamelog.h"
#include "network/core/tcp_content_type.h"
#include "timer/timer_game_calendar.h"

Go to the source code of this file.

Data Structures

struct  LoadCheckData
 Container for loading in mode SL_LOAD_CHECK. More...
struct  FiosItem
 Deals with finding savegames. More...
class  FileList
 List of file information. More...
struct  FiosNumberedSaveName
 A savegame name automatically numbered. More...

Typedefs

using CompanyPropertiesMap = std::map<uint, std::unique_ptr<CompanyProperties>>

Enumerations

enum  SaveLoadInvalidateWindowData : uint8_t { SLIWD_RESCAN_FILES , SLIWD_SELECTION_CHANGES , SLIWD_FILTER_CHANGES }
 Special values for save-load window for the data parameter of InvalidateWindowData. More...
enum class  DirectoryCreateResult : uint8_t { Success , AlreadyExists , PermissionDenied , OtherError }
 Outcome of a directory creation attempt. More...

Functions

bool FiosItemSorter (const FiosItem &a, const FiosItem &b)
 Sorts the FiosItems based on the savegame sorter and order.
bool FiosItemNameSorter (const FiosItem &a, const FiosItem &b)
 Sort files by their name.
bool FiosItemModificationDateSorter (const FiosItem &a, const FiosItem &b)
 Sort files by their modification date, and name when they are equal.
void ShowSaveLoadDialog (AbstractFileType abstract_filetype, SaveLoadOperation fop)
 Launch save/load dialog in the given mode.
void FiosGetSavegameList (SaveLoadOperation fop, bool show_dirs, FileList &file_list)
 Get a list of savegames.
void FiosGetScenarioList (SaveLoadOperation fop, bool show_dirs, FileList &file_list)
 Get a list of scenarios.
void FiosGetHeightmapList (SaveLoadOperation fop, bool show_dirs, FileList &file_list)
 Get a list of heightmaps.
void FiosGetTownDataList (SaveLoadOperation fop, bool show_dirs, FileList &file_list)
 Get a list of town data files.
bool FiosBrowseTo (const FiosItem *item)
 Browse to a new path based on the passed item, starting at #_fios_path.
std::string FiosGetCurrentPath ()
 Get the current path/working directory.
std::optional< uint64_t > FiosGetDiskFreeSpace (const std::string &path)
std::string FiosMakeHeightmapName (std::string_view name)
 Construct a filename for a height map.
std::string FiosMakeSavegameName (std::string_view name)
 Make a save game or scenario filename from a name.
DirectoryCreateResult FiosCreateDirectory (std::string_view name)
 Create a new subdirectory inside the current FIOS path.
std::tuple< FiosType, std::string > FiosGetSavegameListCallback (SaveLoadOperation fop, std::string_view file, std::string_view ext)
 Callback for FiosGetFileList.
std::tuple< FiosType, std::string > FiosGetScenarioListCallback (SaveLoadOperation fop, std::string_view file, std::string_view ext)
 Callback for FiosGetFileList.
std::tuple< FiosType, std::string > FiosGetHeightmapListCallback (SaveLoadOperation fop, std::string_view file, std::string_view ext)
void ScanScenarios ()
 Force a (re)scan of the scenarios.
std::optional< std::string_view > FindScenario (const ContentInfo &ci, bool md5sum)
 Find a given scenario based on its unique ID.

Variables

LoadCheckData _load_check_data
 Data loaded from save during SL_LOAD_CHECK.

Detailed Description

Declarations for savegames operations.

Definition in file fios.h.

Typedef Documentation

◆ CompanyPropertiesMap

using CompanyPropertiesMap = std::map<uint, std::unique_ptr<CompanyProperties>>

Definition at line 36 of file fios.h.

Enumeration Type Documentation

◆ DirectoryCreateResult

enum class DirectoryCreateResult : uint8_t
strong

Outcome of a directory creation attempt.

Enumerator
Success 

Directory was created.

AlreadyExists 

A file or directory with that name already exists.

PermissionDenied 

The OS rejected the operation for permission reasons.

OtherError 

Any other filesystem error.

Definition at line 29 of file fios.h.

◆ SaveLoadInvalidateWindowData

Special values for save-load window for the data parameter of InvalidateWindowData.

Enumerator
SLIWD_RESCAN_FILES 

Rescan all files (when changed directory, ...).

SLIWD_SELECTION_CHANGES 

File selection has changed (user click, ...).

SLIWD_FILTER_CHANGES 

The filename filter has changed (via the editbox).

Definition at line 22 of file fios.h.

Function Documentation

◆ FindScenario()

std::optional< std::string_view > FindScenario ( const ContentInfo & ci,
bool md5sum )

Find a given scenario based on its unique ID.

Parameters
ciThe content info to compare it to.
md5sumWhether to look at the md5sum or the id.
Returns
The filename of the file, else std::nullopt.

Definition at line 685 of file fios.cpp.

References _scanner, ContentInfo::md5sum, and ContentInfo::unique_id.

Referenced by ContentInfo::GetTextfile(), and HasScenario().

◆ FiosBrowseTo()

bool FiosBrowseTo ( const FiosItem * item)

Browse to a new path based on the passed item, starting at #_fios_path.

Parameters
*itemItem telling us what to do.
Returns
true when the path got changed.

Definition at line 165 of file fios.cpp.

References FiosType::detailed, FiosDirect, FiosDirectory, FiosDrive, FiosParent, and Invalid.

Referenced by ConChangeDirectory(), and SaveLoadWindow::OnClick().

◆ FiosCreateDirectory()

DirectoryCreateResult FiosCreateDirectory ( std::string_view name)

Create a new subdirectory inside the current FIOS path.

The caller must validate the name against path traversal. This function only reports the OS-level result.

Parameters
nameName of the directory to create (a single path segment, not a path).
Returns
The outcome of the creation attempt.

Definition at line 134 of file fios.cpp.

References AlreadyExists, OtherError, OTTD2FS(), PermissionDenied, and Success.

Referenced by SaveLoadWindow::HandleNewDirectoryRequest().

◆ FiosGetCurrentPath()

std::string FiosGetCurrentPath ( )

Get the current path/working directory.

Returns
The current path.

Definition at line 123 of file fios.cpp.

Referenced by ConPrintWorkingDirectory(), and SaveLoadWindow::DrawWidget().

◆ FiosGetDiskFreeSpace()

std::optional< uint64_t > FiosGetDiskFreeSpace ( const std::string & path)

Definition at line 70 of file unix.cpp.

◆ FiosGetHeightmapList()

void FiosGetHeightmapList ( SaveLoadOperation fop,
bool show_dirs,
FileList & file_list )

Get a list of heightmaps.

Parameters
fopPurpose of collecting the list.
show_dirsWhether to show directories.
file_listDestination of the found files.

Definition at line 548 of file fios.cpp.

References FiosGetFileList(), Heightmap, and None.

Referenced by FileList::BuildFileList().

◆ FiosGetHeightmapListCallback()

std::tuple< FiosType, std::string > FiosGetHeightmapListCallback ( SaveLoadOperation fop,
std::string_view file,
std::string_view ext )

Definition at line 502 of file fios.cpp.

◆ FiosGetSavegameList()

void FiosGetSavegameList ( SaveLoadOperation fop,
bool show_dirs,
FileList & file_list )

Get a list of savegames.

Parameters
fopPurpose of collecting the list.
show_dirsWhether to show directories.
file_listDestination of the found files.
See also
FiosGetFileList

Definition at line 441 of file fios.cpp.

References FiosGetFileList(), FiosGetSavegameListCallback(), None, and Save.

Referenced by FileList::BuildFileList().

◆ FiosGetSavegameListCallback()

std::tuple< FiosType, std::string > FiosGetSavegameListCallback ( SaveLoadOperation fop,
std::string_view file,
std::string_view ext )

Callback for FiosGetFileList.

It tells if a file is a savegame or not.

Parameters
fopPurpose of collecting the list.
fileName of the file to check.
extA pointer to the extension identifier inside file
Returns
a FIOS_TYPE_* type of the found file, FIOS_TYPE_INVALID if not a savegame, and the title of the file (if any).
See also
FiosGetFileList
FiosGetSavegameList

Definition at line 412 of file fios.cpp.

References GetFileTitle(), Load, Save, and StrEqualsIgnoreCase().

Referenced by FiosGetSavegameList(), and openttd_main().

◆ FiosGetScenarioList()

void FiosGetScenarioList ( SaveLoadOperation fop,
bool show_dirs,
FileList & file_list )

Get a list of scenarios.

Parameters
fopPurpose of collecting the list.
show_dirsWhether to show directories.
file_listDestination of the found files.
See also
FiosGetFileList

Definition at line 488 of file fios.cpp.

References FiosGetFileList(), FiosGetScenarioListCallback(), Load, None, and Scenario.

Referenced by FileList::BuildFileList().

◆ FiosGetScenarioListCallback()

std::tuple< FiosType, std::string > FiosGetScenarioListCallback ( SaveLoadOperation fop,
std::string_view file,
std::string_view ext )

Callback for FiosGetFileList.

It tells if a file is a scenario or not.

Parameters
fopPurpose of collecting the list.
fileName of the file to check.
extA pointer to the extension identifier inside file
Returns
a FIOS_TYPE_* type of the found file, FIOS_TYPE_INVALID if not a scenario and the title of the file (if any).
See also
FiosGetFileList
FiosGetScenarioList

Definition at line 461 of file fios.cpp.

References GetFileTitle(), Load, Scenario, and StrEqualsIgnoreCase().

Referenced by FiosGetScenarioList(), and openttd_main().

◆ FiosGetTownDataList()

void FiosGetTownDataList ( SaveLoadOperation fop,
bool show_dirs,
FileList & file_list )

Get a list of town data files.

Parameters
fopPurpose of collecting the list.
show_dirsWhether to show directories.
file_listDestination of the found files.

Definition at line 585 of file fios.cpp.

References FiosGetFileList(), FiosGetTownDataListCallback(), Heightmap, and None.

Referenced by FileList::BuildFileList().

◆ FiosItemModificationDateSorter()

bool FiosItemModificationDateSorter ( const FiosItem & a,
const FiosItem & b )

Sort files by their modification date, and name when they are equal.

Comparison helper for the sorter, comparing a to b.

Parameters
aThe first element.
bThe second element.
Returns
true if the first element is less than the second element.

Definition at line 45 of file fios.cpp.

References FiosItemNameSorter().

Referenced by FiosItemSorter(), and FiosNumberedSaveName::FiosNumberedSaveName().

◆ FiosItemNameSorter()

bool FiosItemNameSorter ( const FiosItem & a,
const FiosItem & b )

Sort files by their name.

Comparison helper for the sorter, comparing a to b.

Parameters
aThe first element.
bThe second element.
Returns
true if the first element is less than the second element.

Definition at line 39 of file fios.cpp.

References EncodedString::GetDecodedString(), and StrNaturalCompare().

Referenced by FiosGetFileList(), FiosItemModificationDateSorter(), and FiosItemSorter().

◆ FiosItemSorter()

bool FiosItemSorter ( const FiosItem & a,
const FiosItem & b )

Sorts the FiosItems based on the savegame sorter and order.

Comparison helper for the sorter, comparing a to b.

Parameters
aThe first element.
bThe second element.
Returns
true if the first element is less than the second element.

Definition at line 57 of file fios_gui.cpp.

References _savegame_sorter, _savegame_sorter_ascending, Date, FiosItemModificationDateSorter(), FiosItemNameSorter(), and Name.

Referenced by FiosGetFileList(), and SortSaveGameList().

◆ FiosMakeHeightmapName()

std::string FiosMakeHeightmapName ( std::string_view name)

Construct a filename for a height map.

Parameters
nameFilename.
Returns
The completed filename.

Definition at line 251 of file fios.cpp.

References FiosMakeFilename(), and GetCurrentScreenshotExtension().

Referenced by SaveLoadWindow::OnTimeout().

◆ FiosMakeSavegameName()

std::string FiosMakeSavegameName ( std::string_view name)

Make a save game or scenario filename from a name.

Parameters
nameName of the file.
Returns
The completed filename.

Definition at line 239 of file fios.cpp.

References Editor, and FiosMakeFilename().

Referenced by SaveLoadWindow::OnTimeout().

◆ ScanScenarios()

void ScanScenarios ( )

Force a (re)scan of the scenarios.

Definition at line 713 of file fios.cpp.

References _scanner.

Referenced by NetworkContentDownloadStatusWindow::Close().

◆ ShowSaveLoadDialog()

void ShowSaveLoadDialog ( AbstractFileType abstract_filetype,
SaveLoadOperation fop )

Launch save/load dialog in the given mode.

Parameters
abstract_filetypeKind of file to handle.
fopFile operation to perform (load or save).

Definition at line 1103 of file fios_gui.cpp.

References _load_dialog_desc, _load_heightmap_dialog_desc, _load_town_data_dialog_desc, _save_dialog_desc, CloseWindowById(), Heightmap, Save, and TownData.

Referenced by MenuClickSaveLoad(), FoundTownWindow::OnClick(), NetworkStartServerWindow::OnClick(), SelectGameWindow::OnClick(), and MainToolbarWindow::OnHotkey().

Variable Documentation

◆ _load_check_data