33 if (pos < 0) UserError(
"Cannot read file '{}'",
filename);
40 auto t =
filename.rfind(PATHSEPCHAR);
41 std::string name_without_path =
filename.substr(t != std::string::npos ? t + 1 : 0);
45 this->
SeekTo(
static_cast<size_t>(pos), SEEK_SET);
82 return this->
GetPos() >= this->GetEndPos();
92 if (mode == SEEK_CUR)
pos += this->
GetPos();
95 if (fseek(*this->
file_handle, this->pos, SEEK_SET) < 0) {
115 if (size == 0)
return 0;
137 return (this->
ReadWord() << 16) | b;
159 if (n <= remaining) {
162 this->
SeekTo(n, SEEK_CUR);
void ReadBlock(void *ptr, size_t size)
Read a block.
size_t start_pos
Start position of file. May be non-zero if file is within a tar file.
size_t GetPos() const
Get position in the file.
RandomAccessFile(const std::string &filename, Subdirectory subdir)
Create the RandomAccesFile.
std::optional< FileHandle > file_handle
File handle of the open file.
bool AtEndOfFile() const
Test if we have reached the end of the file.
uint8_t buffer_start[BUFFER_SIZE]
Local buffer when read from file.
const std::string & GetFilename() const
Get the filename of the opened file with the path from the SubDirectory and the extension.
void SeekTo(size_t pos, int mode)
Seek in the current file.
std::string filename
Full name of the file; relative path to subdir plus the extension of the file.
static constexpr int BUFFER_SIZE
The number of bytes to allocate for the buffer.
uint8_t ReadByte()
Read a byte from the file.
const std::string & GetSimplifiedFilename() const
Get the simplified filename of the opened file.
std::string simplified_filename
Simplified lowecase name of the file; only the name, no path or extension.
uint32_t ReadDword()
Read a double word (32 bits) from the file (in low endian format).
size_t pos
Position in the file of the end of the read buffer.
size_t end_pos
End position of file.
uint8_t * buffer
Current position within the local buffer.
uint8_t * buffer_end
Last valid byte of buffer.
void SkipBytes(size_t n)
Skip n bytes ahead in the file.
uint16_t ReadWord()
Read a word (16 bits) from the file (in low endian format).
Functions related to debugging.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
Error reporting related functions.
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.
Functions for Standard In/Out file operations.
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Class related to random access to files.
A number of safeguards to prevent using unsafe methods.
Definition of base types and functions in a cross-platform compatible way.
Functions related to low-level strings.