OpenTTD
|
This file contains functions for building file lists for the save/load dialogs. More...
#include "stdafx.h"
#include "fios.h"
#include "fileio_func.h"
#include "tar_type.h"
#include "screenshot.h"
#include "string_func.h"
#include <sys/stat.h>
#include <unistd.h>
#include "table/strings.h"
#include "safeguards.h"
#include "network/network_content.h"
#include "3rdparty/md5/md5.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 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 (FileList &file_list) |
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. | |
StringID | FiosGetDescText (const char **path, uint64 *total_free) |
Get descriptive texts. | |
const char * | FiosBrowseTo (const FiosItem *item) |
Browse to a new path based on the passed item, starting at #_fios_path. | |
static void | FiosMakeFilename (char *buf, const char *path, const char *name, const char *ext, const char *last) |
Construct a filename from its components in destination buffer buf. | |
void | FiosMakeSavegameName (char *buf, const char *name, const char *last) |
Make a save game or scenario filename from a name. | |
void | FiosMakeHeightmapName (char *buf, const char *name, const char *last) |
Construct a filename for a height map. | |
bool | FiosDelete (const char *name) |
Delete a file. | |
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. | |
static void | GetFileTitle (const char *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. | |
FiosType | FiosGetSavegameListCallback (SaveLoadOperation fop, const char *file, const char *ext, char *title, const char *last) |
Callback for FiosGetFileList. | |
void | FiosGetSavegameList (SaveLoadOperation fop, FileList &file_list) |
Get a list of savegames. | |
static FiosType | FiosGetScenarioListCallback (SaveLoadOperation fop, const char *file, const char *ext, char *title, const char *last) |
Callback for FiosGetFileList. | |
void | FiosGetScenarioList (SaveLoadOperation fop, FileList &file_list) |
Get a list of scenarios. | |
static FiosType | FiosGetHeightmapListCallback (SaveLoadOperation fop, const char *file, const char *ext, char *title, const char *last) |
void | FiosGetHeightmapList (SaveLoadOperation fop, FileList &file_list) |
Get a list of heightmaps. | |
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 char * | _fios_path |
static const char * | _fios_path_last |
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.
Compare two FiosItem's.
Used with sort when sorting the file list.
da | A pointer to the first FiosItem to compare. |
db | A pointer to the second FiosItem to compare. |
Definition at line 52 of file fios.cpp.
Referenced by FiosGetFileList(), and SortSaveGameList().
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. |
NULL
. Definition at line 745 of file fios.cpp.
References SmallVector< T, S >::Begin(), SmallVector< T, S >::End(), ContentInfo::md5sum, ScenarioScanner::Scan(), and ContentInfo::unique_id.
Referenced by ContentInfo::GetTextfile(), and HasScenario().
const char* 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. |
NULL
. Definition at line 152 of file fios.cpp.
References seprintf(), and strecat().
Referenced by SaveLoadWindow::OnClick().
bool FiosDelete | ( | const char * | name | ) |
Delete a file.
name | Filename to delete. |
Definition at line 269 of file fios.cpp.
References FiosMakeSavegameName(), and lastof.
Referenced by SaveLoadWindow::OnTimeout().
StringID FiosGetDescText | ( | const char ** | path, |
uint64 * | total_free | ||
) |
Get descriptive texts.
Returns the path and free space left on the device
path | string describing the path |
total_free | total free space in megabytes, optional (can be NULL) |
Definition at line 141 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. |
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 357 of file fios.cpp.
References FileList::Append(), SmallVector< T, S >::Begin(), FileList::Clear(), FileList::Compact(), CompareFiosItems(), FileList::files, FS2OTTD(), FileList::Get(), lastof, FileList::Length(), SmallVector< T, S >::Length(), NO_DIRECTORY, QSortT(), FileScanner::Scan(), seprintf(), str_validate(), strecpy(), and ttd_opendir().
Referenced by FiosGetHeightmapList(), FiosGetSavegameList(), and FiosGetScenarioList().
void FiosGetHeightmapList | ( | SaveLoadOperation | fop, |
FileList & | file_list | ||
) |
Get a list of heightmaps.
fop | Purpose of collecting the list. |
file_list | Destination of the found files. |
Definition at line 618 of file fios.cpp.
References FiosGetFileList(), HEIGHTMAP_DIR, lastof, NO_DIRECTORY, and FileScanner::subdir.
Referenced by FileList::BuildFileList().
void FiosGetSavegameList | ( | SaveLoadOperation | fop, |
FileList & | file_list | ||
) |
Get a list of savegames.
fop | Purpose of collecting the list. |
file_list | Destination of the found files. |
Definition at line 492 of file fios.cpp.
References FiosGetFileList(), FiosGetSavegameListCallback(), NO_DIRECTORY, and SAVE_DIR.
Referenced by FileList::BuildFileList().
FiosType FiosGetSavegameListCallback | ( | SaveLoadOperation | fop, |
const char * | file, | ||
const char * | ext, | ||
char * | title, | ||
const char * | last | ||
) |
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 |
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 |
Definition at line 459 of file fios.cpp.
References GetFileTitle(), SAVE_DIR, and SLO_LOAD.
Referenced by FiosGetSavegameList(), and openttd_main().
void FiosGetScenarioList | ( | SaveLoadOperation | fop, |
FileList & | file_list | ||
) |
Get a list of scenarios.
fop | Purpose of collecting the list. |
file_list | Destination of the found files. |
Definition at line 547 of file fios.cpp.
References FiosGetFileList(), FiosGetScenarioListCallback(), lastof, NO_DIRECTORY, SCENARIO_DIR, SLO_LOAD, and FileScanner::subdir.
Referenced by FileList::BuildFileList().
|
static |
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 |
title | Buffer if a callback wants to lookup the title of the file |
last | Last available byte in buffer (to prevent buffer overflows) |
Definition at line 520 of file fios.cpp.
References GetFileTitle(), SCENARIO_DIR, and SLO_LOAD.
Referenced by FiosGetScenarioList().
const char* FiosGetScreenshotDir | ( | ) |
Get the directory for screenshots.
Definition at line 643 of file fios.cpp.
References SCREENSHOT_DIR.
Referenced by MakeScreenshotName().
|
static |
Construct a filename from its components in destination buffer buf.
buf | Destination buffer. |
path | Directory path, may be NULL . |
name | Filename. |
ext | Filename extension (use "" for no extension). |
last | Last element of buffer buf. |
Definition at line 212 of file fios.cpp.
References seprintf().
Referenced by FiosMakeHeightmapName(), and FiosMakeSavegameName().
void FiosMakeHeightmapName | ( | char * | buf, |
const char * | name, | ||
const char * | last | ||
) |
Construct a filename for a height map.
buf | Destination buffer. |
name | Filename. |
last | Last element of buffer buf. |
Definition at line 255 of file fios.cpp.
References FiosMakeFilename(), GetCurrentScreenshotExtension(), lastof, and strecpy().
Referenced by SaveLoadWindow::OnTimeout().
void FiosMakeSavegameName | ( | char * | buf, |
const char * | name, | ||
const char * | last | ||
) |
Make a save game or scenario filename from a name.
buf | Destination buffer for saving the filename. |
name | Name of the file. |
last | Last element of buffer buf. |
Definition at line 242 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 |
title | the title buffer to fill |
last | the last element in the title buffer |
subdir | the sub directory to search in |
Definition at line 432 of file fios.cpp.
References FioFCloseFile(), FioFOpenFile(), lastof, str_validate(), strecat(), and strecpy().
Referenced by FiosGetSavegameListCallback(), and FiosGetScenarioListCallback().
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 765 of file fios.cpp.
References FindScenario().