OpenTTD Source  20241120-master-g6d3adc6169
FileHandle Class Reference

Data Structures

struct  FileDeleter
 Helper to close a FILE * with a std::unique_ptr. More...
 

Public Member Functions

void Close ()
 
 operator FILE * ()
 

Static Public Member Functions

static std::optional< FileHandleOpen (const std::string &filename, const std::string &mode)
 Open an RAII file handle if possible. More...
 

Private Member Functions

 FileHandle (FILE *f)
 

Private Attributes

std::unique_ptr< FILE, FileDeleterf
 

Detailed Description

Definition at line 158 of file fileio_type.h.

Member Function Documentation

◆ Open()

std::optional< FileHandle > FileHandle::Open ( const std::string &  filename,
const std::string &  mode 
)
static

Open an RAII file handle if possible.

Simplified FileHandle::Open which ignores OTTD2FS.

The canonical RAII-way is for FileHandle to open the file and throw an exception on failure, but we don't want that.

Parameters
filenameUTF-8 encoded filename to open.
modeMode to open file.
Returns
FileHandle, or std::nullopt on failure.

Required as settingsgen does not include all of the fileio system.

Parameters
filenameUTF-8 encoded filename to open.
modeMode to open file.
Returns
FileHandle, or std::nullopt on failure.

Definition at line 1170 of file fileio.cpp.

References OTTD2FS().

Referenced by AppendFile(), ClientNetworkContentSocketHandler::BeforeDownload(), CompareFiles(), FioFOpenFileTar(), GetLanguageFileHeader(), GunzipFile(), DLSFile::LoadFile(), LoadFromHighScore(), main(), MakeBMPImage(), SettingsIniFile::OpenFile(), ReadFileToMem(), and SaveToHighScore().


The documentation for this class was generated from the following files: