ezEngine  Milestone 7
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 &, ezMutex
Event
 

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.
 
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 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.
 

Private Member Functions

 EZ_DISALLOW_COPY_AND_ASSIGN (ezOSFile)
 
ezResult InternalOpen (const char *szFile, ezFileMode::Enum OpenMode)
 
void InternalClose ()
 
ezResult InternalWrite (const void *pBuffer, ezUInt64 uiBytes)
 
ezUInt64 InternalRead (void *pBuffer, ezUInt64 uiBytes)
 
ezUInt64 InternalGetFilePosition () const
 
void InternalSetFilePosition (ezInt64 iDistance, ezFilePos::Enum Pos) const
 

Static Private Member Functions

static bool InternalExistsFile (const char *szFile)
 
static bool InternalExistsDirectory (const char *szDirectory)
 
static ezResult InternalDeleteFile (const char *szFile)
 
static ezResult InternalCreateDirectory (const char *szFile)
 

Private Attributes

ezFileMode::Enum m_FileMode
 Stores the mode with which the file was opened.
 
ezStringBuilder m_sFileName
 Stores the (cleaned up) filename that was used to open the file.
 
ezInt32 m_iFileID
 Stores the value of s_FileCounter when the ezOSFile is created.
 
ezOSFileData m_FileData
 Platform specific data about the open file.
 

Static Private Attributes

static Event s_FileEvents
 Manages all the Event Handlers for the OSFile events.
 
static ezString64 s_ApplicationPath
 The application binaries' path.
 
static ezAtomicInteger32 s_FileCounter
 Counts how many different files are touched.225.
 

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.


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