OpenTTD Source 20241224-master-gf74b0cf984
|
This file contains functions for building file lists for the save/load dialogs. More...
#include "stdafx.h"
#include "3rdparty/md5/md5.h"
#include "fileio_func.h"
#include "fios.h"
#include "network/network_content.h"
#include "screenshot.h"
#include "string_func.h"
#include "strings_func.h"
#include "tar_type.h"
#include <sys/stat.h>
#include <charconv>
#include <filesystem>
#include "table/strings.h"
#include "safeguards.h"
Go to the source code of this file.
Data Structures | |
class | FiosFileScanner |
Scanner to scan for a particular type of FIOS file. More... | |
struct | ScenarioIdentifier |
Basic data to distinguish a scenario. More... | |
class | ScenarioScanner |
Scanner to find the unique IDs of scenarios. More... | |
Typedefs | |
typedef std::tuple< FiosType, std::string > | FiosGetTypeAndNameProc(SaveLoadOperation fop, const std::string &filename, const std::string_view ext) |
Functions | |
bool | FiosIsRoot (const std::string &path) |
bool | FiosIsHiddenFile (const std::filesystem::path &path) |
void | FiosGetDrives (FileList &file_list) |
std::string | GetOldSaveGameName (const std::string &file) |
std::string | FiosGetCurrentPath () |
Get the current path/working directory. | |
bool | FiosBrowseTo (const FiosItem *item) |
Browse to a new path based on the passed item, starting at _fios_path. | |
static std::string | FiosMakeFilename (const std::string *path, const char *name, const char *ext) |
Construct a filename from its components in destination buffer buf. | |
std::string | FiosMakeSavegameName (const char *name) |
Make a save game or scenario filename from a name. | |
std::string | FiosMakeHeightmapName (const char *name) |
Construct a filename for a height map. | |
bool | FiosDelete (const char *name) |
Delete a file. | |
static void | FiosGetFileList (SaveLoadOperation fop, bool show_dirs, FiosGetTypeAndNameProc *callback_proc, Subdirectory subdir, FileList &file_list) |
Fill the list of the files in a directory, according to some arbitrary rule. | |
static std::string | GetFileTitle (const std::string &file, Subdirectory subdir) |
Get the title of a file, which (if exists) is stored in a file named the same as the data file but with '.title' added to it. | |
std::tuple< FiosType, std::string > | FiosGetSavegameListCallback (SaveLoadOperation fop, const std::string &file, const std::string_view ext) |
Callback for FiosGetFileList. | |
void | FiosGetSavegameList (SaveLoadOperation fop, bool show_dirs, FileList &file_list) |
Get a list of savegames. | |
std::tuple< FiosType, std::string > | FiosGetScenarioListCallback (SaveLoadOperation fop, const std::string &file, const std::string_view ext) |
Callback for FiosGetFileList. | |
void | FiosGetScenarioList (SaveLoadOperation fop, bool show_dirs, FileList &file_list) |
Get a list of scenarios. | |
std::tuple< FiosType, std::string > | FiosGetHeightmapListCallback (SaveLoadOperation, const std::string &file, const std::string_view ext) |
void | FiosGetHeightmapList (SaveLoadOperation fop, bool show_dirs, FileList &file_list) |
Get a list of heightmaps. | |
static std::tuple< FiosType, std::string > | FiosGetTownDataListCallback (SaveLoadOperation fop, const std::string &file, const std::string_view ext) |
Callback for FiosGetTownDataList. | |
void | FiosGetTownDataList (SaveLoadOperation fop, bool show_dirs, FileList &file_list) |
Get a list of town data files. | |
const char * | FiosGetScreenshotDir () |
Get the directory for screenshots. | |
const char * | FindScenario (const ContentInfo *ci, bool md5sum) |
Find a given scenario based on its unique ID. | |
bool | HasScenario (const ContentInfo *ci, bool md5sum) |
Check whether we've got a given scenario based on its unique ID. | |
void | ScanScenarios () |
Force a (re)scan of the scenarios. | |
Variables | |
static std::string * | _fios_path = nullptr |
SortingBits | _savegame_sort_order = SORT_BY_DATE | SORT_DESCENDING |
static ScenarioScanner | _scanner |
Scanner for scenarios. | |
This file contains functions for building file lists for the save/load dialogs.
Definition in file fios.cpp.
typedef std::tuple< FiosType, std::string > FiosGetTypeAndNameProc(SaveLoadOperation fop, const std::string &filename, const std::string_view ext) |
const char * FindScenario | ( | const ContentInfo * | ci, |
bool | md5sum | ||
) |
Find a given scenario based on its unique ID.
ci | The content info to compare it to. |
md5sum | Whether to look at the md5sum or the id. |
nullptr
. Definition at line 690 of file fios.cpp.
References _scanner, ContentInfo::md5sum, ScenarioScanner::Scan(), and ContentInfo::unique_id.
Referenced by ContentInfo::GetTextfile(), and HasScenario().
bool FiosBrowseTo | ( | const FiosItem * | item | ) |
Browse to a new path based on the passed item, starting at _fios_path.
*item | Item telling us what to do. |
true
when the path got changed. Definition at line 143 of file fios.cpp.
Referenced by SaveLoadWindow::OnClick().
bool FiosDelete | ( | const char * | name | ) |
Delete a file.
name | Filename to delete. |
Definition at line 248 of file fios.cpp.
References FioRemove(), and FiosMakeSavegameName().
Referenced by SaveLoadWindow::OnTimeout().
std::string FiosGetCurrentPath | ( | ) |
Get the current path/working directory.
Definition at line 133 of file fios.cpp.
Referenced by SaveLoadWindow::DrawWidget().
|
static |
Fill the list of the files in a directory, according to some arbitrary rule.
fop | Purpose of collecting the list. |
show_dirs | Whether to list directories. |
callback_proc | The function that is called where you need to do the filtering. |
subdir | The directory from where to start (global) searching. |
file_list | Destination of the found files. |
Definition at line 327 of file fios.cpp.
References FS2OTTD(), GetString(), NO_DIRECTORY, OTTD2FS(), FileScanner::Scan(), and SetDParamStr().
Referenced by FiosGetHeightmapList(), FiosGetSavegameList(), FiosGetScenarioList(), and FiosGetTownDataList().
void FiosGetHeightmapList | ( | SaveLoadOperation | fop, |
bool | show_dirs, | ||
FileList & | file_list | ||
) |
Get a list of heightmaps.
fop | Purpose of collecting the list. |
show_dirs | Whether to show directories. |
file_list | Destination of the found files. |
Definition at line 549 of file fios.cpp.
References FiosGetFileList(), HEIGHTMAP_DIR, and NO_DIRECTORY.
Referenced by FileList::BuildFileList().
std::tuple< FiosType, std::string > FiosGetHeightmapListCallback | ( | SaveLoadOperation | fop, |
const std::string & | file, | ||
const std::string_view | ext | ||
) |
void FiosGetSavegameList | ( | SaveLoadOperation | fop, |
bool | show_dirs, | ||
FileList & | file_list | ||
) |
Get a list of savegames.
fop | Purpose of collecting the list. |
show_dirs | Whether to show directories. |
file_list | Destination of the found files. |
Definition at line 442 of file fios.cpp.
References FiosGetFileList(), FiosGetSavegameListCallback(), NO_DIRECTORY, and SAVE_DIR.
Referenced by FileList::BuildFileList().
std::tuple< FiosType, std::string > FiosGetSavegameListCallback | ( | SaveLoadOperation | fop, |
const std::string & | file, | ||
const std::string_view | ext | ||
) |
Callback for FiosGetFileList.
It tells if a file is a savegame or not.
fop | Purpose of collecting the list. |
file | Name of the file to check. |
ext | A pointer to the extension identifier inside file |
Definition at line 413 of file fios.cpp.
References GetFileTitle(), SAVE_DIR, SLO_LOAD, and StrEqualsIgnoreCase().
Referenced by FiosGetSavegameList(), and openttd_main().
void FiosGetScenarioList | ( | SaveLoadOperation | fop, |
bool | show_dirs, | ||
FileList & | file_list | ||
) |
Get a list of scenarios.
fop | Purpose of collecting the list. |
show_dirs | Whether to show directories. |
file_list | Destination of the found files. |
Definition at line 489 of file fios.cpp.
References FiosGetFileList(), FiosGetScenarioListCallback(), NO_DIRECTORY, SCENARIO_DIR, and SLO_LOAD.
Referenced by FileList::BuildFileList().
std::tuple< FiosType, std::string > FiosGetScenarioListCallback | ( | SaveLoadOperation | fop, |
const std::string & | file, | ||
const std::string_view | ext | ||
) |
Callback for FiosGetFileList.
It tells if a file is a scenario or not.
fop | Purpose of collecting the list. |
file | Name of the file to check. |
ext | A pointer to the extension identifier inside file |
Definition at line 462 of file fios.cpp.
References GetFileTitle(), SCENARIO_DIR, SLO_LOAD, and StrEqualsIgnoreCase().
Referenced by FiosGetScenarioList(), and openttd_main().
const char * FiosGetScreenshotDir | ( | ) |
Get the directory for screenshots.
Definition at line 602 of file fios.cpp.
References SCREENSHOT_DIR.
Referenced by NewGRFProfiler::GetOutputFilename(), and MakeScreenshotName().
void FiosGetTownDataList | ( | SaveLoadOperation | fop, |
bool | show_dirs, | ||
FileList & | file_list | ||
) |
Get a list of town data files.
fop | Purpose of collecting the list. |
show_dirs | Whether to show directories. |
file_list | Destination of the found files. |
Definition at line 585 of file fios.cpp.
References FiosGetFileList(), FiosGetTownDataListCallback(), HEIGHTMAP_DIR, and NO_DIRECTORY.
Referenced by FileList::BuildFileList().
|
static |
Callback for FiosGetTownDataList.
fop | Purpose of collecting the list. |
file | Name of the file to check. |
Definition at line 568 of file fios.cpp.
References GetFileTitle(), SAVE_DIR, SLO_LOAD, and StrEqualsIgnoreCase().
Referenced by FiosGetTownDataList().
|
extern |
|
static |
Construct a filename from its components in destination buffer buf.
path | Directory path, may be nullptr . |
name | Filename. |
ext | Filename extension (use "" for no extension). |
Definition at line 201 of file fios.cpp.
References StrEqualsIgnoreCase().
Referenced by FiosMakeHeightmapName(), and FiosMakeSavegameName().
std::string FiosMakeHeightmapName | ( | const char * | name | ) |
Construct a filename for a height map.
name | Filename. |
Definition at line 235 of file fios.cpp.
References FiosMakeFilename(), and GetCurrentScreenshotExtension().
Referenced by SaveLoadWindow::OnTimeout().
std::string FiosMakeSavegameName | ( | const char * | name | ) |
Make a save game or scenario filename from a name.
name | Name of the file. |
Definition at line 223 of file fios.cpp.
References FiosMakeFilename().
Referenced by FiosDelete(), and SaveLoadWindow::OnTimeout().
|
static |
Get the title of a file, which (if exists) is stored in a file named the same as the data file but with '.title' added to it.
file | filename to get the title for |
subdir | the sub directory to search in |
Definition at line 392 of file fios.cpp.
References FioFOpenFile(), lengthof, and StrMakeValid().
Referenced by FiosGetSavegameListCallback(), FiosGetScenarioListCallback(), and FiosGetTownDataListCallback().
|
extern |
Definition at line 309 of file oldloader.cpp.
bool HasScenario | ( | const ContentInfo * | ci, |
bool | md5sum | ||
) |
Check whether we've got a given scenario based on its unique ID.
ci | The content info to compare it to. |
md5sum | Whether to look at the md5sum or the id. |
Definition at line 710 of file fios.cpp.
References FindScenario().
Referenced by ClientNetworkContentSocketHandler::Receive_SERVER_INFO().
void ScanScenarios | ( | ) |
Force a (re)scan of the scenarios.
Definition at line 718 of file fios.cpp.
References _scanner, and ScenarioScanner::Scan().
Referenced by NetworkContentDownloadStatusWindow::Close().
SortingBits _savegame_sort_order = SORT_BY_DATE | SORT_DESCENDING |
|
static |
Scanner for scenarios.
Definition at line 682 of file fios.cpp.
Referenced by FindScenario(), and ScanScenarios().