Functions for Standard In/Out file operations. More...
#include "fileio_type.h"
#include <sys/types.h>
#include <dirent.h>
Go to the source code of this file.
Data Structures | |
class | FileScanner |
Helper for scanning for files with a given name. More... | |
class | TarScanner |
Helper for scanning for files with tar as extension. More... | |
Defines | |
#define | FOR_ALL_SEARCHPATHS(sp) for (sp = SP_FIRST_DIR; sp < NUM_SEARCHPATHS; sp++) if (IsValidSearchPath(sp)) |
Iterator for all the search paths. | |
Functions | |
void | FioSeekTo (size_t pos, int mode) |
void | FioSeekToFile (uint8 slot, size_t pos) |
size_t | FioGetPos () |
const char * | FioGetFilename (uint8 slot) |
byte | FioReadByte () |
uint16 | FioReadWord () |
uint32 | FioReadDword () |
void | FioCloseAll () |
void | FioOpenFile (int slot, const char *filename) |
void | FioReadBlock (void *ptr, size_t size) |
void | FioSkipBytes (int n) |
void | FioCreateDirectory (const char *filename) |
Create a directory with the given name. | |
static bool | IsValidSearchPath (Searchpath sp) |
Checks whether the given search path is a valid search path. | |
void | FioFCloseFile (FILE *f) |
Close a file in a safe way. | |
FILE * | FioFOpenFile (const char *filename, const char *mode="rb", Subdirectory subdir=DATA_DIR, size_t *filesize=NULL) |
Opens OpenTTD files somewhere in a personal or global directory. | |
bool | FioCheckFileExists (const char *filename, Subdirectory subdir=DATA_DIR) |
Check whether the given file exists. | |
char * | FioGetFullPath (char *buf, size_t buflen, Searchpath sp, Subdirectory subdir, const char *filename) |
char * | FioFindFullPath (char *buf, size_t buflen, Subdirectory subdir, const char *filename) |
char * | FioAppendDirectory (char *buf, size_t buflen, Searchpath sp, Subdirectory subdir) |
char * | FioGetDirectory (char *buf, size_t buflen, Subdirectory subdir) |
void | SanitizeFilename (char *filename) |
Sanitizes a filename, i.e. | |
bool | AppendPathSeparator (char *buf, size_t buflen) |
Appends, if necessary, the path separator character to the end of the string. | |
void | DeterminePaths (const char *exe) |
Acquire the base paths (personal dir and game data dir), fill all other paths (save dir, autosave dir etc) and make the save and scenario directories. | |
void * | ReadFileToMem (const char *filename, size_t *lenp, size_t maxsize) |
bool | FileExists (const char *filename) |
const char * | FioTarFirstDir (const char *tarname) |
void | FioTarAddLink (const char *src, const char *dest) |
bool | ExtractTar (const char *tar_filename) |
Extract the tar with the given filename in the directory where the tar resides. | |
static DIR * | ttd_opendir (const char *path) |
A wrapper around opendir() which will convert the string from OPENTTD encoding to that of the filesystem. | |
Variables | |
const char * | _searchpaths [NUM_SEARCHPATHS] |
The searchpaths OpenTTD could search through. | |
char * | _personal_dir |
custom directory for personal settings, saves, newgrf, etc. |
Functions for Standard In/Out file operations.
Definition in file fileio_func.h.
bool AppendPathSeparator | ( | char * | buf, | |
size_t | buflen | |||
) |
Appends, if necessary, the path separator character to the end of the string.
It does not add the path separator to zero-sized strings.
buf | string to append the separator to | |
buflen | the length of the buf |
Definition at line 453 of file fileio.cpp.
Referenced by BuildWithFullPath(), DetermineBasePaths(), FileScanner::Scan(), and ScanPath().
void DeterminePaths | ( | const char * | exe | ) |
Acquire the base paths (personal dir and game data dir), fill all other paths (save dir, autosave dir etc) and make the save and scenario directories.
exe | the path from the current path to the executable |
Definition at line 958 of file fileio.cpp.
References AI_DIR, AI_LIBRARY_DIR, AUTOSAVE_DIR, BASE_DIR, DATA_DIR, DetermineBasePaths(), TarScanner::DoScan(), FioCreateDirectory(), FOR_ALL_SEARCHPATHS, GM_DIR, HEIGHTMAP_DIR, IsValidSearchPath(), lengthof, SAVE_DIR, SCENARIO_DIR, SP_AUTODOWNLOAD_DIR, SP_BINARY_DIR, SP_INSTALLATION_DIR, SP_PERSONAL_DIR, SP_SHARED_DIR, and SP_WORKING_DIR.
bool ExtractTar | ( | const char * | tar_filename | ) |
Extract the tar with the given filename in the directory where the tar resides.
tar_filename | the name of the tar to extract. |
Definition at line 772 of file fileio.cpp.
References FioCreateDirectory(), lastof, lengthof, min(), and strecpy().
Referenced by ClientNetworkContentSocketHandler::AfterDownload().
bool FioCheckFileExists | ( | const char * | filename, | |
Subdirectory | subdir | |||
) |
Check whether the given file exists.
filename | the file to try for existance | |
subdir | the subdirectory to look in |
Definition at line 247 of file fileio.cpp.
References FioFCloseFile(), and FioFOpenFile().
Referenced by ScriptScanner::ScanDir().
void FioCreateDirectory | ( | const char * | name | ) |
Create a directory with the given name.
name | the new name of the directory |
Definition at line 425 of file fileio.cpp.
References ttd_strlcpy().
Referenced by DeterminePaths(), and ExtractTar().
static bool IsValidSearchPath | ( | Searchpath | sp | ) | [inline, static] |
Checks whether the given search path is a valid search path.
sp | the search path to check |
Definition at line 43 of file fileio_func.h.
References _searchpaths.
Referenced by DeterminePaths().
void SanitizeFilename | ( | char * | filename | ) |
Sanitizes a filename, i.e.
removes all illegal characters from it.
filename | the "\0" terminated filename |
Definition at line 1045 of file fileio.cpp.
Referenced by GenerateDefaultSaveName().
static DIR* ttd_opendir | ( | const char * | path | ) | [inline, static] |
A wrapper around opendir() which will convert the string from OPENTTD encoding to that of the filesystem.
For all purposes this function behaves the same as the original opendir function
path | string to open directory of |
Definition at line 141 of file fileio_func.h.
Referenced by FiosGetFileList(), GetLanguageList(), ScriptScanner::ScanDir(), and ScanPath().
const char* _searchpaths[NUM_SEARCHPATHS] |
The searchpaths OpenTTD could search through.
At least one of the slots has to be filled with a path. NULL paths tell that there is no such path for the current operating system.
Definition at line 234 of file fileio.cpp.
Referenced by IsValidSearchPath().