OpenTTD Source
20241108-master-g80f628063a
|
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... | |
Functions | |
std::optional< FileHandle > | FioFOpenFile (const std::string &filename, const char *mode, Subdirectory subdir, size_t *filesize=nullptr) |
Opens a OpenTTD file somewhere in a personal or global directory. More... | |
bool | FioCheckFileExists (const std::string &filename, Subdirectory subdir) |
Check whether the given file exists. More... | |
std::string | FioFindFullPath (Subdirectory subdir, const std::string &filename) |
Find a path to the filename in one of the search directories. More... | |
std::string | FioGetDirectory (Searchpath sp, Subdirectory subdir) |
std::string | FioFindDirectory (Subdirectory subdir) |
void | FioCreateDirectory (const std::string &name) |
Create a directory with the given name If the parent directory does not exist, it will try to create that as well. More... | |
bool | FioRemove (const std::string &filename) |
Remove a file. More... | |
const char * | FiosGetScreenshotDir () |
Get the directory for screenshots. More... | |
void | SanitizeFilename (std::string &filename) |
Sanitizes a filename, i.e. More... | |
void | AppendPathSeparator (std::string &buf) |
Appends, if necessary, the path separator character to the end of the string. More... | |
void | DeterminePaths (const char *exe, bool only_local_path) |
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. More... | |
std::unique_ptr< char[]> | ReadFileToMem (const std::string &filename, size_t &lenp, size_t maxsize) |
Load a file into memory. More... | |
bool | FileExists (const std::string &filename) |
Test whether the given filename exists. More... | |
bool | ExtractTar (const std::string &tar_filename, Subdirectory subdir) |
Extract the tar with the given filename in the directory where the tar resides. More... | |
Variables | |
std::string | _personal_dir |
custom directory for personal settings, saves, newgrf, etc. | |
std::vector< Searchpath > | _valid_searchpaths |
Functions for Standard In/Out file operations.
Definition in file fileio_func.h.
void AppendPathSeparator | ( | std::string & | buf | ) |
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 |
Definition at line 346 of file fileio.cpp.
Referenced by FileScanner::Scan().
void DeterminePaths | ( | const char * | exe, |
bool | only_local_path | ||
) |
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 |
only_local_path | Whether we shouldn't fill searchpaths with global folders. |
Definition at line 878 of file fileio.cpp.
References DetermineBasePaths().
bool ExtractTar | ( | const std::string & | 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 590 of file fileio.cpp.
bool FileExists | ( | const std::string & | filename | ) |
Test whether the given filename exists.
filename | the file to test. |
Definition at line 132 of file fileio.cpp.
References OTTD2FS().
Referenced by NetworkHTTPInitialize().
bool FioCheckFileExists | ( | const std::string & | 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 121 of file fileio.cpp.
References FioFOpenFile().
Referenced by FillGRFDetails(), GetMusicCatEntryData(), GetMusicCatEntryName(), GRFLoadConfig(), and SaveLoadWindow::OnTimeout().
void FioCreateDirectory | ( | const std::string & | name | ) |
Create a directory with the given name If the parent directory does not exist, it will try to create that as well.
name | the new name of the directory |
Definition at line 316 of file fileio.cpp.
References OTTD2FS().
std::string FioFindFullPath | ( | Subdirectory | subdir, |
const std::string & | filename | ||
) |
Find a path to the filename in one of the search directories.
subdir | Subdirectory to try. |
filename | Filename to look for. |
Definition at line 144 of file fileio.cpp.
References NUM_SUBDIRS.
Referenced by GetDefaultTruetypeFontFile(), MidiFile::GetSMFFile(), DriverFactoryBase::MarkVideoDriverOperational(), and DriverFactoryBase::SelectDriverImpl().
std::optional<FileHandle> FioFOpenFile | ( | const std::string & | 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. |
nullptr
if the file is not available. Definition at line 242 of file fileio.cpp.
References NO_DIRECTORY, and NUM_SUBDIRS.
Referenced by _ValidateSignatureFile(), ScenarioScanner::AddFile(), ScriptFileChecksumCreator::AddFile(), CalcGRFMD5Sum(), CalculateHashV1(), GraphicsSet::CheckMD5(), MD5File::CheckMD5(), DebugPrint(), FioCheckFileExists(), GetFileTitle(), MidiFile::LoadFile(), Squirrel::LoadFile(), TextfileWindow::LoadTextfile(), LoadTownData(), IniFile::OpenFile(), RandomAccessFile::RandomAccessFile(), ReadRawLanguageStrings(), MidiFile::ReadSMFHeader(), DriverFactoryBase::SelectDriverImpl(), CrashLog::WriteCrashLog(), and MidiFile::WriteSMF().
bool FioRemove | ( | const std::string & | filename | ) |
Remove a file.
filename | Filename to remove. |
Definition at line 328 of file fileio.cpp.
References Debug, and OTTD2FS().
Referenced by ClientNetworkContentSocketHandler::AfterDownload(), FiosDelete(), DriverFactoryBase::MarkVideoDriverOperational(), and DriverFactoryBase::SelectDriverImpl().
const char* FiosGetScreenshotDir | ( | ) |
Get the directory for screenshots.
Definition at line 602 of file fios.cpp.
Referenced by NewGRFProfiler::GetOutputFilename().
std::unique_ptr<char[]> ReadFileToMem | ( | const std::string & | filename, |
size_t & | lenp, | ||
size_t | maxsize | ||
) |
Load a file into memory.
filename | Name of the file to load. | |
[out] | lenp | Length of loaded data. |
maxsize | Maximum size to load. |
nullptr
if loading failed. Definition at line 1025 of file fileio.cpp.
References FileHandle::Open().
Referenced by ReadLanguagePack().
void SanitizeFilename | ( | std::string & | filename | ) |
Sanitizes a filename, i.e.
removes all illegal characters from it.
filename | the filename |
Definition at line 1003 of file fileio.cpp.