ezEngine  Milestone 9
ezOSFile Class Reference

This is an abstraction for the most important file operations. More...

#include <OSFile.h>

Classes

struct  EventData
 The data that is sent through the event interface. More...
 
struct  EventType
 Describes the types of events that ezOSFile sends. More...
 

Public Types

typedef ezEvent< const EventData &, ezMutexEvent
 

Public Member Functions

ezResult Open (const char *szFile, ezFileMode::Enum OpenMode)
 Opens a file for reading or writing. Returns true if the file could be opened successfully.
 
bool IsOpen () const
 Returns true if a file is currently open.
 
void Close ()
 Closes the file, if it is currently opened.
 
ezResult Write (const void *pBuffer, ezUInt64 uiBytes)
 Writes the given number of bytes from the buffer into the file. Returns true if all data was successfully written.
 
ezUInt64 Read (void *pBuffer, ezUInt64 uiBytes)
 Reads up to the given number of bytes from the file. Returns the actual number of bytes that was read.
 
ezUInt64 ReadAll (ezDynamicArray< ezUInt8 > &out_FileContent)
 Reads the entire file content into the given array.
 
const char * GetOpenFileName () const
 Returns the name of the file that is currently opened. Returns an empty string, if no file is open.
 
ezUInt64 GetFilePosition () const
 Returns the position in the file at which read/write operations will occur.
 
void SetFilePosition (ezInt64 iDistance, ezFilePos::Enum Pos) const
 Sets the position where in the file to read/write next.
 
ezUInt64 GetFileSize () const
 Returns the current total size of the file.
 
const ezOSFileData & GetFileData () const
 This will return the platform specific file data (handles etc.), if you really want to be able to wreak havoc.
 

Static Public Member Functions

static bool ExistsFile (const char *szFile)
 Checks whether the given file exists.
 
static bool ExistsDirectory (const char *szDirectory)
 Checks whether the given file exists.
 
static ezResult DeleteFile (const char *szFile)
 Deletes the given file. Returns EZ_SUCCESS, if the file was deleted or did not exist in the first place. Returns EZ_FAILURE.
 
static ezResult CreateDirectoryStructure (const char *szDirectory)
 Creates the given directory structure (meaning all directories in the path, that do not exist). Returns false, if any directory could not be created.
 
static ezResult CopyFile (const char *szSource, const char *szDestination)
 Copies the source file into the destination file.
 
static ezResult GetFileStats (const char *szFileOrFolder, ezFileStats &out_Stats)
 Gets the stats about the given file or folder. Returns false, if the stats could not be determined.
 
static ezResult GetFileCasing (const char *szFileOrFolder, ezStringBuilder &out_sCorrectSpelling)
 Useful on systems that are not strict about the casing of file names. Determines the correct name of a file.
 
static const char * GetApplicationDirectory ()
 Returns the path in which the applications binary file is located.
 
static ezString GetUserDataFolder (const char *szSubFolder=nullptr)
 Returns the folder into which user data may be safely written. More...
 
static void AddEventHandler (Event::Handler handler)
 Allows to register a function as an event receiver. All receivers will be notified in the order that they registered.
 
static void RemoveEventHandler (Event::Handler handler)
 Unregisters a previously registered receiver. It is an error to unregister a receiver that was not registered.
 

Detailed Description

This is an abstraction for the most important file operations.

Instances of ezOSFile can be used for reading and writing files. All paths must be absolute paths, relative paths and current working directories are not supported, since that cannot be guaranteed to work equally on all platforms under all circumstances. A few static functions allow to query the most important data about files, to delete files and create directories.

Member Function Documentation

◆ GetUserDataFolder()

ezString ezOSFile::GetUserDataFolder ( const char *  szSubFolder = nullptr)
static

Returns the folder into which user data may be safely written.

On Windows this is typically the appdata% folder. If szSubFolder is specified, it will be appended to the result.


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