OpenTTD Source: src/fios.cpp File Reference

OpenTTD Source 13.1

Data Structures | Typedefs | Functions | Variables
fios.cpp File Reference
`#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 <functional>`
`#include <optional>`
`#include <charconv>`
`#include <unistd.h>`
`#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 FiosType | fios_getlist_callback_proc(SaveLoadOperation fop, const std::string &filename, const char *ext, char *title, const char *last)

## Functions
bool | FiosIsRoot (const char *path)
bool | FiosIsValidFile (const char *path, const struct dirent *ent, struct stat *sb)
bool | FiosIsHiddenFile (const struct dirent *ent)
void | FiosGetDrives (FileList &file_list)
bool | FiosGetDiskFreeSpace (const char *path, uint64 *tot)
void | GetOldSaveGameName (const std::string &file, char *title, const char *last)
StringID | FiosGetDescText (const char **path, uint64 *total_free)
| Get descriptive texts. More...
const char * | FiosBrowseTo (const FiosItem *item)
| Browse to a new path based on the passed item, starting at #_fios_path. More...
static std::string | FiosMakeFilename (const std::string *path, const char *name, const char *ext)
| Construct a filename from its components in destination buffer buf. More...
std::string | FiosMakeSavegameName (const char *name)
| Make a save game or scenario filename from a name. More...
std::string | FiosMakeHeightmapName (const char *name)
| Construct a filename for a height map. More...
bool | FiosDelete (const char *name)
| Delete a file. More...
static void | FiosGetFileList (SaveLoadOperation fop, fios_getlist_callback_proc *callback_proc, Subdirectory subdir, FileList &file_list)
| Fill the list of the files in a directory, according to some arbitrary rule. More...
static void | GetFileTitle (const std::string &file, char *title, const char *last, 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. More...
FiosType | FiosGetSavegameListCallback (SaveLoadOperation fop, const std::string &file, const char *ext, char *title, const char *last)
| Callback for FiosGetFileList. More...
void | FiosGetSavegameList (SaveLoadOperation fop, FileList &file_list)
| Get a list of savegames. More...
static FiosType | FiosGetScenarioListCallback (SaveLoadOperation fop, const std::string &file, const char *ext, char *title, const char *last)
| Callback for FiosGetFileList. More...
void | FiosGetScenarioList (SaveLoadOperation fop, FileList &file_list)
| Get a list of scenarios. More...
static FiosType | FiosGetHeightmapListCallback (SaveLoadOperation fop, const std::string &file, const char *ext, char *title, const char *last)
void | FiosGetHeightmapList (SaveLoadOperation fop, FileList &file_list)
| Get a list of heightmaps. More...
const char * | FiosGetScreenshotDir ()
| Get the directory for screenshots. More...
const char * | FindScenario (const ContentInfo *ci, bool md5sum)
| Find a given scenario based on its unique ID. More...
bool | HasScenario (const ContentInfo *ci, bool md5sum)
| Check whether we've got a given scenario based on its unique ID. More...
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.

## Detailed Description

This file contains functions for building file lists for the save/load dialogs.

Definition in file fios.cpp.

## Function Documentation

## ◆ FindScenario()

const char* FindScenario | ( | const ContentInfo * | ci,
|  | bool | md5sum
| ) |  |

Find a given scenario based on its unique ID.

Parameters

  ci | The content info to compare it to.
  md5sum | Whether to look at the md5sum or the id.

Returns
  The filename of the file, else `nullptr`.

Definition at line 717 of file fios.cpp.

References _scanner, ContentInfo::md5sum, ScenarioScanner::Scan(), and ContentInfo::unique_id.

Referenced by HasScenario().

## ◆ FiosBrowseTo()

const char* FiosBrowseTo | ( | const FiosItem * | item | ) |

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

Parameters

  *item | Item telling us what to do.

Returns
  A filename w/path if we reached a file, otherwise `nullptr`.

Definition at line 150 of file fios.cpp.

## ◆ FiosDelete()

bool FiosDelete | ( | const char * | name | ) |

Delete a file.

Parameters

  name | Filename to delete.

Returns
  Whether the file deletion was successful.

Definition at line 256 of file fios.cpp.

References FiosMakeSavegameName().

Referenced by SaveLoadWindow::OnTimeout().

## ◆ FiosGetDescText()

StringID FiosGetDescText | ( | const char ** | path,
|  | uint64 * | total_free
| ) |  |

Get descriptive texts.

Returns the path and free space left on the device

Parameters

  path | string describing the path
  total_free | total free space in megabytes, optional (can be nullptr)

Returns
  StringID describing the path (free space or failure)

Definition at line 139 of file fios.cpp.

## ◆ FiosGetFileList()

static void FiosGetFileList | ( | SaveLoadOperation | fop,
|  | fios_getlist_callback_proc * | callback_proc,
|  | Subdirectory | subdir,
|  | FileList & | file_list
| ) |  |
| static

Fill the list of the files in a directory, according to some arbitrary rule.

Parameters

  fop | Purpose of collecting the list.
  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 359 of file fios.cpp.

## ◆ FiosGetHeightmapList()

void FiosGetHeightmapList | ( | SaveLoadOperation | fop,
|  | FileList & | file_list
| ) |  |

Get a list of heightmaps.

Parameters

  fop | Purpose of collecting the list.
  file_list | Destination of the found files.

Definition at line 608 of file fios.cpp.

Referenced by FileList::BuildFileList().

## ◆ FiosGetSavegameList()

void FiosGetSavegameList | ( | SaveLoadOperation | fop,
|  | FileList & | file_list
| ) |  |

Get a list of savegames.

Parameters

  fop | Purpose of collecting the list.
  file_list | Destination of the found files.

See also
  FiosGetFileList

Definition at line 498 of file fios.cpp.

Referenced by FileList::BuildFileList().

## ◆ FiosGetSavegameListCallback()

FiosType FiosGetSavegameListCallback | ( | SaveLoadOperation | fop,
|  | const std::string & | file,
|  | const char * | ext,
|  | char * | title,
|  | const char * | last
| ) |  |

Callback for FiosGetFileList.

It tells if a file is a savegame or not.

Parameters

  fop | Purpose of collecting the list.
  file | Name of the file to check.
  ext | A pointer to the extension identifier inside file
  title | Buffer if a callback wants to lookup the title of the file; nullptr to skip the lookup
  last | Last available byte in buffer (to prevent buffer overflows); not used when title == nullptr

Returns
  a FIOS_TYPE_* type of the found file, FIOS_TYPE_INVALID if not a savegame

See also
  FiosGetFileList
  FiosGetSavegameList

Definition at line 465 of file fios.cpp.

## ◆ FiosGetScenarioList()

void FiosGetScenarioList | ( | SaveLoadOperation | fop,
|  | FileList & | file_list
| ) |  |

Get a list of scenarios.

Parameters

  fop | Purpose of collecting the list.
  file_list | Destination of the found files.

See also
  FiosGetFileList

Definition at line 547 of file fios.cpp.

Referenced by FileList::BuildFileList().

## ◆ FiosGetScenarioListCallback()

static FiosType FiosGetScenarioListCallback | ( | SaveLoadOperation | fop,
|  | const std::string & | file,
|  | const char * | ext,
|  | char * | title,
|  | const char * | last
| ) |  |
| static

Callback for FiosGetFileList.

It tells if a file is a scenario or not.

Parameters

  fop | Purpose of collecting the list.
  file | Name of the file to check.
  ext | A pointer to the extension identifier inside file
  title | Buffer if a callback wants to lookup the title of the file
  last | Last available byte in buffer (to prevent buffer overflows)

Returns
  a FIOS_TYPE_* type of the found file, FIOS_TYPE_INVALID if not a scenario

See also
  FiosGetFileList
  FiosGetScenarioList

Definition at line 520 of file fios.cpp.

References GetFileTitle(), and SCENARIO_DIR.

## ◆ FiosGetScreenshotDir()

const char* FiosGetScreenshotDir | ( |  | ) |

Get the directory for screenshots.

Returns
  path to screenshots

Definition at line 625 of file fios.cpp.

## ◆ FiosMakeFilename()

static std::string FiosMakeFilename | ( | const std::string * | path,
|  | const char * | name,
|  | const char * | ext
| ) |  |
| static

Construct a filename from its components in destination buffer buf.

Parameters

  path | Directory path, may be `nullptr`.
  name | Filename.
  ext | Filename extension (use `""` for no extension).

Returns
  The completed filename.

Definition at line 207 of file fios.cpp.

Referenced by FiosMakeHeightmapName().

## ◆ FiosMakeHeightmapName()

std::string FiosMakeHeightmapName | ( | const char * | name | ) |

Construct a filename for a height map.

Parameters

  name | Filename.

Returns
  The completed filename.

Definition at line 243 of file fios.cpp.

References FiosMakeFilename(), and GetCurrentScreenshotExtension().

Referenced by SaveLoadWindow::OnTimeout().

## ◆ FiosMakeSavegameName()

std::string FiosMakeSavegameName | ( | const char * | name | ) |

Make a save game or scenario filename from a name.

Parameters

  buf | Destination buffer for saving the filename.
  name | Name of the file.
  last | Last element of buffer buf.

Returns
  The completed filename.

Definition at line 231 of file fios.cpp.

Referenced by FiosDelete(), and SaveLoadWindow::OnTimeout().

## ◆ GetFileTitle()

static void GetFileTitle | ( | const std::string & | file,
|  | char * | title,
|  | const char * | last,
|  | Subdirectory | subdir
| ) |  |
| 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.

Parameters

  file | filename to get the title for
  title | the title buffer to fill
  last | the last element in the title buffer
  subdir | the sub directory to search in

Definition at line 439 of file fios.cpp.

References FioFOpenFile(), and FileScanner::subdir.

Referenced by FiosGetScenarioListCallback().

## ◆ HasScenario()

bool HasScenario | ( | const ContentInfo * | ci,
|  | bool | md5sum
| ) |  |

Check whether we've got a given scenario based on its unique ID.

Parameters

  ci | The content info to compare it to.
  md5sum | Whether to look at the md5sum or the id.

Returns
  True iff we've got the scenario.

Definition at line 737 of file fios.cpp.

References FindScenario().

Referenced by ClientNetworkContentSocketHandler::Receive_SERVER_INFO().