Xors3d Engine
File System

Functions

void xChangeDir (const char *path)
 Sets directory as current.
void xCloseDir (int handle)
 Closes previously opened directory.
void xCloseFile (xFile *file)
 Closes opened file.
int xCopyFile (const char *pathSrc, const char *pathDest)
 Copies file from source path to destination.
int xCreateDir (const char *path)
 Creates new directory.
const char * xCurrentDir ()
 Returns current directory path.
int xDeleteDir (const char *path)
 Deletes directory.
int xDeleteFile (const char *path)
 Deletes file.
int xEof (xFile *file)
 Checks to see if the End of File of an opened file or stream has been reached.
int xFileCreationTime (const char *path)
 Returns the time the file was created.
const char * xFileCreationTimeStr (const char *path)
 Returns the time the file was created.
int xFileModificationTime (const char *path)
 Returns the time the file was last modified.
const char * xFileModificationTimeStr (const char *path)
 Returns the time the file was last modified.
int xFilePos (xFile *file)
 Returns the current position within a file that is being processed following xReadFile(), xWriteFile() or xOpenFile()
int xFileSize (const char *path)
 Returns the size of the file.
int xFileType (const char *path)
 Checks the filename you pass and determines if it exists and whether or not it is a valid filename or if it is a directory.
xPackFile * xMountPackFile (const char *path, const char *mountpoint="", const char *password="")
 Mounts a zip file as a part of the file system and returns its handle.
const char * xNextFile (int handle)
 Returns the next file or folder from the currently open directory.
xFile * xOpenFile (const char *path)
 Opens the designated file and prepares it to be updated. The file must exists since this function will not create a new file.
int xReadByte (xFile *file)
 Reads byte value from file (1 byte)
int xReadDir (const char *path)
 Returns a directory handle. You will use the xNextFile() to iterate through each file entry (use xFileType() to see if it is a file or folder).
xFile * xReadFile (const char *path)
 Opens the designated filename and prepares it to be read from.
float xReadFloat (xFile *file)
 Reads float value from file (4 bytes)
int xReadInt (xFile *file)
 Reads integer value from file (4 bytes)
const char * xReadLine (xFile *file, int ls_flag=0)
 Reads a line from file. Line should be terminated with a line separator specified with ls_flag parameter.
int xReadShort (xFile *file)
 Reads short integer value from file (2 bytes)
const char * xReadString (xFile *file)
 Reads a string value from file.
void xSeekFile (xFile *file, int offset)
 Sets current position in file.
void xUnmountPackFile (xPackFile *packfile)
 Unmounts a pack file from the file system.
void xWriteByte (xFile *file, int value)
 Writes a byte value into file (1 byte)
xFile * xWriteFile (const char *path)
 Opens the designated filename and prepares it to be written to.
void xWriteFloat (xFile *file, float value)
 Writes a float value into file (4 bytes)
void xWriteInt (xFile *file, int value)
 Writes an integer value into file (4 bytes)
void xWriteLine (xFile *file, const char *value, int ls_flag=0)
 Writes a line to file. Line is terminated with a line separator specified with ls_flag parameter.
void xWriteShort (xFile *file, int value)
 Writes a short integer value into file (2 bytes)
void xWriteString (xFile *file, const char *value)
 Writes a string into file.

Function Documentation

xPackFile* xMountPackFile ( const char *  path,
const char *  mountpoint = "",
const char *  password = "" 
)

Mounts a zip file as a part of the file system and returns its handle.

Use a zip file as a pack of your resources. Use of packs allows to compress the resources and to encrypt them with a password. Once mounted pack file becomes visible for the engine as a part of the file system. The second parameter is a mount point which is the location in the file system structure where a mounted pack file appears.

When you load some media, the engine searches that media in the mounted pack files first. For instance, the pack was mounted by using following

xMountPackFile("textures.zip", "textures\", "super_password");

Since now a pack file "textures.zip" is seen as a "textures\" directory.

If you load some texture by using

xLoadTexture("textures\something.dds");

the engine will try to load a texture "something.dds" from the pack mounted before since its mount point is "textures\". If there isn't such texture in the pack, the engine will try to load it from the disk using the path "textures\something.dds".

Such system allows you to develop and release your applications with ease. During development use loading from the disk. Before release pack your media and mount the packs using proper mount points.

Note:
: You can only read from packs (i.e. xReadFile(), xFileType() and xFileSize(), etc) You can't create, delete or change files in the packs.
Parameters:
pathA path to the pack file.
mountpointMount point of the pack file.
passwordA password of the pack file.
void xUnmountPackFile ( xPackFile *  packfile)

Unmounts a pack file from the file system.

Parameters:
packfilePackfile handle.
xFile* xOpenFile ( const char *  path)

Opens the designated file and prepares it to be updated. The file must exists since this function will not create a new file.

Parameters:
pathFilename to opens
xFile* xReadFile ( const char *  path)

Opens the designated filename and prepares it to be read from.

Parameters:
pathFilename to opens
xFile* xWriteFile ( const char *  path)

Opens the designated filename and prepares it to be written to.

Parameters:
pathFilename to opens
void xCloseFile ( xFile *  file)

Closes opened file.

Parameters:
fileFile handle
int xFilePos ( xFile *  file)

Returns the current position within a file that is being processed following xReadFile(), xWriteFile() or xOpenFile()

Parameters:
fileFile handle
void xSeekFile ( xFile *  file,
int  offset 
)

Sets current position in file.

Parameters:
fileFile handle
offsetOffset in bytes from the start of file
int xFileType ( const char *  path)

Checks the filename you pass and determines if it exists and whether or not it is a valid filename or if it is a directory.

The values to be returned: 0 - The file doesn't exist 1 - The file exists 2 - The file is not a file - but a directory

Parameters:
pathFilename to check
int xFileSize ( const char *  path)

Returns the size of the file.

Parameters:
pathFilename to check
int xFileCreationTime ( const char *  path)

Returns the time the file was created.

The time to be returned is the number of seconds since the beginning of January 1, 1970.

Note:
This function will return the modification time for the files from the packs.
Parameters:
pathFilename to check
const char* xFileCreationTimeStr ( const char *  path)

Returns the time the file was created.

The time to be returned is a string in format "MM/DD/YYYY hh:mm:ss".

Note:
This function will return the modification time for the files from the packs.
Parameters:
pathFilename to check
int xFileModificationTime ( const char *  path)

Returns the time the file was last modified.

The time to be returned is the number of seconds since the beginning of January 1, 1970.

Parameters:
pathFilename to check
const char* xFileModificationTimeStr ( const char *  path)

Returns the time the file was last modified.

The time to be returned is a string in format "MM/DD/YYYY hh:mm:ss".

Parameters:
pathFilename to check
int xReadDir ( const char *  path)

Returns a directory handle. You will use the xNextFile() to iterate through each file entry (use xFileType() to see if it is a file or folder).

Parameters:
pathDirectory path
void xCloseDir ( int  handle)

Closes previously opened directory.

Parameters:
handleDirectory handle
const char* xNextFile ( int  handle)

Returns the next file or folder from the currently open directory.

Parameters:
handleDirectory handle
const char* xCurrentDir ( )

Returns current directory path.

void xChangeDir ( const char *  path)

Sets directory as current.

Parameters:
pathDirectory path
int xCreateDir ( const char *  path)

Creates new directory.

Parameters:
pathDirectory path
int xDeleteDir ( const char *  path)

Deletes directory.

Parameters:
pathDirectory path
int xCopyFile ( const char *  pathSrc,
const char *  pathDest 
)

Copies file from source path to destination.

Parameters:
pathSrcSource file
pathDestDestination file
int xDeleteFile ( const char *  path)

Deletes file.

Parameters:
pathFilename to delete
int xEof ( xFile *  file)

Checks to see if the End of File of an opened file or stream has been reached.

Parameters:
fileFile handle
int xReadByte ( xFile *  file)

Reads byte value from file (1 byte)

Parameters:
fileFile handle
int xReadShort ( xFile *  file)

Reads short integer value from file (2 bytes)

Parameters:
fileFile handle
int xReadInt ( xFile *  file)

Reads integer value from file (4 bytes)

Parameters:
fileFile handle
float xReadFloat ( xFile *  file)

Reads float value from file (4 bytes)

Parameters:
fileFile handle
const char* xReadString ( xFile *  file)

Reads a string value from file.

Each string is stored in the file as a 4 byte integer followed by the characters that form the string. The integer contains the number of characters in the string, i.e. its length. Note, that Carriage Return, Line Feed and Null characters are not use to indicate the end of the string.

Parameters:
fileFile handle
const char* xReadLine ( xFile *  file,
int  ls_flag = 0 
)

Reads a line from file. Line should be terminated with a line separator specified with ls_flag parameter.

Parameters:
fileFile handle.
ls_flagLine separator. Default value is 0 (LS_NUL). See 'Line separtor types' for more information.
void xWriteByte ( xFile *  file,
int  value 
)

Writes a byte value into file (1 byte)

Parameters:
fileFile handle
valueValue to write
void xWriteShort ( xFile *  file,
int  value 
)

Writes a short integer value into file (2 bytes)

Parameters:
fileFile handle
valueValue to write
void xWriteInt ( xFile *  file,
int  value 
)

Writes an integer value into file (4 bytes)

Parameters:
fileFile handle
valueValue to write
void xWriteFloat ( xFile *  file,
float  value 
)

Writes a float value into file (4 bytes)

Parameters:
fileFile handle
valueValue to write
void xWriteString ( xFile *  file,
const char *  value 
)

Writes a string into file.

Each string is stored in the file as a 4 byte integer followed by the characters that form the string

Parameters:
fileFile handle
valueValue to write
void xWriteLine ( xFile *  file,
const char *  value,
int  ls_flag = 0 
)

Writes a line to file. Line is terminated with a line separator specified with ls_flag parameter.

Parameters:
fileFile handle
valueValue to write
ls_flagLine separator. Default value is 0 (LS_NUL). See 'Line separtor types' for more information.