# fios.cpp File Reference

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

`#include "stdafx.h"`
`#include "openttd.h"`
`#include "core/sort_func.hpp"`
`#include "fios.h"`
`#include "fileio_func.h"`
`#include "tar_type.h"`
`#include "string_func.h"`
`#include <sys/stat.h>`
`#include <unistd.h>`
`#include "table/strings.h"`

Go to the source code of this file.

## Data Structures
class | FiosFileScanner
| Scanner to scan for a particular type of FIOS file. More...
## Typedefs
typedef FiosType | fios_getlist_callback_proc (SaveLoadDialogMode mode, const char *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 ()
bool | FiosGetDiskFreeSpace (const char *path, uint64 *tot)
void | GetOldSaveGameName (const char *file, char *title, const char *last)
int CDECL | CompareFiosItems (const FiosItem *da, const FiosItem *db)
| Compare two FiosItem's.
void | FiosFreeSavegameList ()
| Clear the list.
StringID | FiosGetDescText (const char **path, uint64 *total_free)
| Get descriptive texts.
const char * | FiosBrowseTo (const FiosItem *item)
void | FiosMakeSavegameName (char *buf, const char *name, size_t size)
bool | FiosDelete (const char *name)
bool | FileExists (const char *filename)
static void | FiosGetFileList (SaveLoadDialogMode mode, fios_getlist_callback_proc *callback_proc, Subdirectory subdir)
| Fill the list of the files in a directory, according to some arbitrary rule.
static void | GetFileTitle (const char *file, char *title, const char *last)
| 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.
FiosType | FiosGetSavegameListCallback (SaveLoadDialogMode mode, const char *file, const char *ext, char *title, const char *last)
| Callback for FiosGetFileList.
void | FiosGetSavegameList (SaveLoadDialogMode mode)
| Get a list of savegames.
static FiosType | FiosGetScenarioListCallback (SaveLoadDialogMode mode, const char *file, const char *ext, char *title, const char *last)
| Callback for FiosGetFileList.
void | FiosGetScenarioList (SaveLoadDialogMode mode)
| Get a list of scenarios.
static FiosType | FiosGetHeightmapListCallback (SaveLoadDialogMode mode, const char *file, const char *ext, char *title, const char *last)
void | FiosGetHeightmapList (SaveLoadDialogMode mode)
## Variables
SmallVector< FiosItem, 32 > | _fios_items
| defined in fios.cpp
static char * | _fios_path
SmallFiosItem | _file_to_saveload

## Detailed Description

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

Definition in file fios.cpp.

## Function Documentation

int CDECL CompareFiosItems | ( | const FiosItem * | da,
|  | const FiosItem * | db |
| ) |  |  |

Compare two FiosItem's.

Used with sort when sorting the file list.

Parameters:

  | da | A pointer to the first FiosItem to compare.
  | db | A pointer to the second FiosItem to compare.

Returns:
  -1, 0 or 1, depending on how the two items should be sorted.

Definition at line 52 of file fios.cpp.

Referenced by FiosGetFileList().

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 NULL)

Returns:
  StringID describing the path (free space or failure)

Definition at line 80 of file fios.cpp.

static void FiosGetFileList | ( | SaveLoadDialogMode | mode,
|  | fios_getlist_callback_proc * | callback_proc,
|  | Subdirectory | subdir |
| ) |  |  | `[static]`

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

Parameters:

  | mode | The mode we are in. Some modes don't allow 'parent'.
  | callback_proc | The function that is called where you need to do the filtering.
  | subdir | The directory from where to start (global) searching.

Definition at line 267 of file fios.cpp.

References SmallVector< T, S >::Append(), SmallVector< T, S >::Begin(), SmallVector< T, S >::Clear(), SmallVector< T, S >::Compact(), CompareFiosItems(), FS2OTTD(), SmallVector< T, S >::Get(), lastof, SmallVector< T, S >::Length(), lengthof, NO_DIRECTORY, QSortT(), FileScanner::Scan(), str_validate(), strecpy(), and ttd_opendir().

Referenced by FiosGetSavegameList(), and FiosGetScenarioList().

void FiosGetSavegameList | ( | SaveLoadDialogMode | mode | ) |

Get a list of savegames.

Parameters:

  | mode | Save/load mode.

Returns:
  A pointer to an array of FiosItem representing all the files to be shown in the save/load dialog.

See also:
  FiosGetFileList

Definition at line 397 of file fios.cpp.

References FiosGetFileList(), FiosGetSavegameListCallback(), NO_DIRECTORY, and SAVE_DIR.

FiosType FiosGetSavegameListCallback | ( | SaveLoadDialogMode | mode,
|  | const char * | file,
|  | const char * | ext,
|  | char * | title,
|  | const char * | last |
| ) |  |  |

Callback for FiosGetFileList.

It tells if a file is a savegame or not.

Parameters:

  | mode | Save/load mode.
  | 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; NULL to skip the lookup
  | last | Last available byte in buffer (to prevent buffer overflows); not used when title == NULL

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

See also:
  FiosGetFileList

  FiosGetSavegameList

Definition at line 368 of file fios.cpp.

References GetFileTitle().

Referenced by FiosGetSavegameList().

void FiosGetScenarioList | ( | SaveLoadDialogMode | mode | ) |

Get a list of scenarios.

Parameters:

  | mode | Save/load mode.

Returns:
  A pointer to an array of FiosItem representing all the files to be shown in the save/load dialog.

See also:
  FiosGetFileList

Definition at line 449 of file fios.cpp.

References FiosGetFileList(), FiosGetScenarioListCallback(), NO_DIRECTORY, and SCENARIO_DIR.

static FiosType FiosGetScenarioListCallback | ( | SaveLoadDialogMode | mode,
|  | const char * | file,
|  | const char * | ext,
|  | char * | title,
|  | const char * | last |
| ) |  |  | `[static]`

Callback for FiosGetFileList.

It tells if a file is a scenario or not.

Parameters:

  | mode | Save/load mode.
  | 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 422 of file fios.cpp.

References GetFileTitle().

Referenced by FiosGetScenarioList().

static void GetFileTitle | ( | const char * | file,
|  | char * | title,
|  | const char * | last |
| ) |  |  | `[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

Definition at line 341 of file fios.cpp.

References FioFCloseFile(), FioFOpenFile(), lastof, str_validate(), strecat(), and strecpy().

Referenced by FiosGetSavegameListCallback(), and FiosGetScenarioListCallback().