|
OpenTTD
|
Functions for Standard In/Out file operations. More...
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... | |
Macros | |
| #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) |
| Seek in the current file. | |
| void | FioSeekToFile (uint8 slot, size_t pos) |
| Switch to a different file and seek to a position. | |
| size_t | FioGetPos () |
| Get position in the current file. | |
| const char * | FioGetFilename (uint8 slot) |
| Get the filename associated with a slot. | |
| byte | FioReadByte () |
| Read a byte from the file. | |
| uint16 | FioReadWord () |
| Read a word (16 bits) from the file (in low endian format). | |
| uint32 | FioReadDword () |
| Read a double word (32 bits) from the file (in low endian format). | |
| void | FioCloseAll () |
| Close all slotted open files. | |
| void | FioOpenFile (int slot, const char *filename, Subdirectory subdir) |
| Open a slotted file. | |
| void | FioReadBlock (void *ptr, size_t size) |
| Read a block. | |
| void | FioSkipBytes (int n) |
| Skip n bytes ahead in the file. | |
| 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, Subdirectory subdir, size_t *filesize=NULL) |
| Opens a OpenTTD file somewhere in a personal or global directory. | |
| bool | FioCheckFileExists (const char *filename, Subdirectory subdir) |
| Check whether the given file exists. | |
| char * | FioGetFullPath (char *buf, const char *last, Searchpath sp, Subdirectory subdir, const char *filename) |
| char * | FioFindFullPath (char *buf, const char *last, Subdirectory subdir, const char *filename) |
| Find a path to the filename in one of the search directories. | |
| char * | FioAppendDirectory (char *buf, const char *last, Searchpath sp, Subdirectory subdir) |
| char * | FioGetDirectory (char *buf, const char *last, Subdirectory subdir) |
| const char * | FiosGetScreenshotDir () |
| Get the directory for screenshots. | |
| void | SanitizeFilename (char *filename) |
| Sanitizes a filename, i.e. | |
| bool | AppendPathSeparator (char *buf, const char *last) |
| 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) |
| Load a file into memory. | |
| bool | FileExists (const char *filename) |
| Test whether the given filename exists. | |
| const char * | FioTarFirstDir (const char *tarname, Subdirectory subdir) |
| Find the first directory in a tar archive. | |
| void | FioTarAddLink (const char *src, const char *dest, Subdirectory subdir) |
| bool | ExtractTar (const char *tar_filename, Subdirectory subdir) |
| 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 search paths OpenTTD could search through. | |
| const 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, |
| const char * | last | ||
| ) |
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 |
| last | the last element of buf. |
Definition at line 573 of file fileio.cpp.
References seprintf().
Referenced by BuildWithFullPath(), DetermineBasePaths(), DeterminePaths(), DoScanWorkingDirectory(), 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 1197 of file fileio.cpp.
References _config_file, _do_scan_working_directory, _highscore_file, _log_file, _windows_file, AI_DIR, AI_LIBRARY_DIR, AppendPathSeparator(), AUTOSAVE_DIR, BASE_DIR, BASESET_DIR, DEBUG, DetermineBasePaths(), FileExists(), FioCreateDirectory(), FioFindFullPath(), FOR_ALL_SEARCHPATHS, free(), GAME_DIR, GAME_LIBRARY_DIR, HEIGHTMAP_DIR, IsValidSearchPath(), lastof, lengthof, NEWGRF_DIR, SAVE_DIR, SCENARIO_DIR, SCREENSHOT_DIR, seprintf(), SP_AUTODOWNLOAD_DIR, SP_BINARY_DIR, SP_INSTALLATION_DIR, SP_PERSONAL_DIR, SP_SHARED_DIR, SP_WORKING_DIR, str_fmt(), and stredup().
Referenced by openttd_main().
| bool ExtractTar | ( | const char * | tar_filename, |
| Subdirectory | subdir | ||
| ) |
Extract the tar with the given filename in the directory where the tar resides.
| tar_filename | the name of the tar to extract. |
| subdir | The sub directory the tar is in. |
Definition at line 950 of file fileio.cpp.
References DEBUG, FioCreateDirectory(), FioFOpenFileTar(), lastof, lengthof, min(), and strecpy().
Referenced by ClientNetworkContentSocketHandler::AfterDownload().
| bool FileExists | ( | const char * | filename | ) |
Test whether the given filename exists.
| filename | the file to test. |
Definition at line 326 of file fileio.cpp.
References OTTD2FS().
Referenced by DeterminePaths(), FioFindFullPath(), ScriptInstance::LoadCompatibilityScripts(), and MakeScreenshotName().
| bool FioCheckFileExists | ( | const char * | filename, |
| Subdirectory | subdir | ||
| ) |
Check whether the given file exists.
| filename | the file to try for existence. |
| subdir | the subdirectory to look in |
Definition at line 312 of file fileio.cpp.
References FioFCloseFile(), and FioFOpenFile().
Referenced by ScriptScanner::AddFile(), FillGRFDetails(), GetTextfile(), GRFLoadConfig(), LoadNewGRF(), and LoadTranslations().
| void FioCloseAll | ( | ) |
Close all slotted open files.
Definition at line 213 of file fileio.cpp.
References FioCloseFile(), Fio::handles, and lengthof.
Referenced by ShutdownGame().
| char* FioFindFullPath | ( | char * | buf, |
| const char * | last, | ||
| Subdirectory | subdir, | ||
| const char * | filename | ||
| ) |
Find a path to the filename in one of the search directories.
| buf | [out] Destination buffer for the path. |
| last | End of the destination buffer. |
| subdir | Subdirectory to try. |
| filename | Filename to look for. |
NULL. Definition at line 364 of file fileio.cpp.
References FileExists(), FOR_ALL_SEARCHPATHS, NUM_SUBDIRS, and strtolower().
Referenced by DeterminePaths().
| FILE* FioFOpenFile | ( | const char * | filename, |
| const char * | mode, | ||
| Subdirectory | subdir, | ||
| size_t * | filesize | ||
| ) |
Opens a OpenTTD file somewhere in a personal or global directory.
| filename | Name of the file to open. |
| subdir | Subdirectory to open. |
| filename | Name of the file to open. |
NULL if the file is not available. Definition at line 474 of file fileio.cpp.
References BASESET_DIR, FioFOpenFile(), FioFOpenFileTar(), FOR_ALL_SEARCHPATHS, lastof, NEWGRF_DIR, NO_DIRECTORY, NUM_SUBDIRS, OLD_DATA_DIR, OLD_GM_DIR, strecpy(), and strtolower().
Referenced by ScriptFileChecksumCreator::AddFile(), ScenarioScanner::AddFile(), CalcGRFMD5Sum(), MD5File::CheckMD5(), GraphicsSet::CheckMD5(), debug_print(), DisplaySplashImage(), FioCheckFileExists(), FioFOpenFile(), FioOpenFile(), GetFileTitle(), Squirrel::LoadFile(), TextfileWindow::LoadTextfile(), IniFile::OpenFile(), ReadHeightmapBMP(), ReadHeightmapPNG(), ReadRawLanguageStrings(), SaveOrLoad(), and CrashLog::WriteCrashLog().
| const char* FioGetFilename | ( | uint8 | slot | ) |
Get the filename associated with a slot.
| slot | Index of queried file. |
Definition at line 78 of file fileio.cpp.
References Fio::shortnames.
Referenced by DecodeSingleSprite(), LoadNewGRFSound(), SpriteAlignerWindow::SetStringParameters(), and WarnCorruptSprite().
| size_t FioGetPos | ( | ) |
Get position in the current file.
Definition at line 68 of file fileio.cpp.
References Fio::buffer_end, and Fio::pos.
Referenced by DefineGotoLabel(), FioReadBlock(), FioSeekTo(), GetGRFContainerVersion(), LoadNewGRFSound(), LoadNextSprite(), and ReadGRFSpriteOffsets().
| void FioOpenFile | ( | int | slot, |
| const char * | filename, | ||
| Subdirectory | subdir | ||
| ) |
Open a slotted file.
| slot | Index to assign. |
| filename | Name of the file at the disk. |
| subdir | The sub directory to search this file in. |
Definition at line 250 of file fileio.cpp.
References Fio::filenames, FioCloseFile(), FioFOpenFile(), FioSeekToFile(), Fio::handles, Fio::shortnames, stredup(), strtolower(), and usererror().
Referenced by LoadGrfFile(), LoadGrfFileIndexed(), and LoadNewGRFFile().
| void FioReadBlock | ( | void * | ptr, |
| size_t | size | ||
| ) |
Read a block.
| ptr | Destination buffer. |
| size | Number of bytes to read. |
Definition at line 187 of file fileio.cpp.
References Fio::cur_fh, FioGetPos(), FioSeekTo(), and Fio::pos.
Referenced by LoadNewGRFSound(), and ReadRecolourSprite().
| byte FioReadByte | ( | ) |
Read a byte from the file.
Definition at line 133 of file fileio.cpp.
References Fio::buffer_end, Fio::buffer_start, Fio::cur_fh, FIO_BUFFER_SIZE, and Fio::pos.
Referenced by DecodeSingleSprite(), FioReadWord(), FioSkipBytes(), GetGRFContainerVersion(), LoadGrfFile(), LoadGrfFileIndexed(), LoadNewGRFFile(), LoadNewGRFSound(), LoadNextSprite(), and SkipSpriteData().
| uint32 FioReadDword | ( | ) |
Read a double word (32 bits) from the file (in low endian format).
Definition at line 176 of file fileio.cpp.
References FioReadWord().
Referenced by ImportGRFSound(), LoadNewGRFFile(), LoadNewGRFSound(), LoadNextSprite(), and ReadGRFSpriteOffsets().
| uint16 FioReadWord | ( | ) |
Read a word (16 bits) from the file (in low endian format).
Definition at line 166 of file fileio.cpp.
References FioReadByte().
Referenced by FioReadDword(), GetGRFContainerVersion(), ImportGRFSound(), LoadNewGRFFile(), LoadNewGRFSound(), and LoadNextSprite().
| void FioSeekTo | ( | size_t | pos, |
| int | mode | ||
| ) |
Seek in the current file.
| pos | New position. |
| mode | Type of seek (SEEK_CUR means pos is relative to current position, SEEK_SET means pos is absolute). |
Definition at line 88 of file fileio.cpp.
References Fio::buffer_end, Fio::buffer_start, Fio::cur_fh, DEBUG, Fio::filename, FIO_BUFFER_SIZE, FioGetPos(), and Fio::pos.
Referenced by FioReadBlock(), FioSeekToFile(), GetGRFContainerVersion(), and ReadGRFSpriteOffsets().
| void FioSeekToFile | ( | uint8 | slot, |
| size_t | pos | ||
| ) |
Switch to a different file and seek to a position.
| slot | Slot number of the new file. |
| pos | New absolute position in the new file. |
Definition at line 115 of file fileio.cpp.
References Fio::cur_fh, Fio::filename, Fio::filenames, FioSeekTo(), and Fio::handles.
Referenced by FioOpenFile(), and LoadNewGRFSound().
| const char* FiosGetScreenshotDir | ( | ) |
Get the directory for screenshots.
Definition at line 643 of file fios.cpp.
References SCREENSHOT_DIR.
Referenced by MakeScreenshotName().
| void FioSkipBytes | ( | int | n | ) |
Skip n bytes ahead in the file.
| n | Number of bytes to skip reading. |
Definition at line 150 of file fileio.cpp.
References Fio::buffer_end, FioReadByte(), and min().
Referenced by LoadNewGRFFile(), LoadNewGRFSound(), LoadNextSprite(), ReadGRFSpriteOffsets(), and SkipSpriteData().
| const char* FioTarFirstDir | ( | const char * | tarname, |
| Subdirectory | subdir | ||
| ) |
Find the first directory in a tar archive.
| tarname | the name of the tar archive to look in. |
| subdir | the subdirectory to look in. |
Definition at line 618 of file fileio.cpp.
|
inlinestatic |
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* ReadFileToMem | ( | const char * | filename, |
| size_t * | lenp, | ||
| size_t | maxsize | ||
| ) |
Load a file into memory.
| filename | Name of the file to load. |
| lenp | [out] Length of loaded data. |
| maxsize | Maximum size to load. |
NULL if loading failed. Definition at line 1345 of file fileio.cpp.
References free().
Referenced by ReadLanguagePack().
| void SanitizeFilename | ( | char * | filename | ) |
Sanitizes a filename, i.e.
removes all illegal characters from it.
| filename | the "\0" terminated filename |
Definition at line 1323 of file fileio.cpp.
Referenced by GenerateDefaultSaveName().
|
inlinestatic |
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 147 of file fileio_func.h.
References OTTD2FS().
Referenced by FiosGetFileList(), GetLanguageList(), and ScanPath().
| const char* _searchpaths[NUM_SEARCHPATHS] |
The search paths 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 299 of file fileio.cpp.
Referenced by IsValidSearchPath().
1.8.1.2