#include <FileSystem.h>
Public Types | |
enum | StreamMode { READ = 1, WRITE = 2 } |
enum | DialogMode { OPEN, SAVE } |
Public Member Functions | |
~FileSystem () | |
Static Public Member Functions | |
static void | setResourcePath (const char *path) |
static const char * | getResourcePath () |
static void | loadResourceAliases (const char *aliasFilePath) |
static void | loadResourceAliases (Properties *properties) |
static std::string | displayFileDialog (size_t dialogMode, const char *title, const char *filterDescription, const char *filterExtensions, const char *initialDirectory) |
static const char * | resolvePath (const char *path) |
static bool | listFiles (const char *dirPath, std::vector< std::string > &files) |
static bool | fileExists (const char *filePath) |
static Stream * | open (const char *path, size_t streamMode=READ) |
static FILE * | openFile (const char *filePath, const char *mode) |
static char * | readAll (const char *filePath, int *fileSize=NULL) |
static bool | isAbsolutePath (const char *filePath) |
static void | setAssetPath (const char *path) |
static const char * | getAssetPath () |
static void | createFileFromAsset (const char *path) |
static std::string | getDirectoryName (const char *path) |
static std::string | getExtension (const char *path) |
Defines a set of functions for interacting with the device file system.
Mode flags for displaying a dialog.
Mode flags for opening a stream.
Destructor.
static void gameplay::FileSystem::createFileFromAsset | ( | const char * | path | ) | [static] |
Creates a file on the file system from the specified asset (Android-specific).
path | The path to the file. |
static std::string gameplay::FileSystem::displayFileDialog | ( | size_t | dialogMode, |
const char * | title, | ||
const char * | filterDescription, | ||
const char * | filterExtensions, | ||
const char * | initialDirectory | ||
) | [static] |
Displays an open or save dialog using the native platform dialog system.
dialogMode | The mode of the dialog. (Ex. OPEN or SAVE) |
title | The title of the dialog. (Ex. Select File or Save File) |
filterDescription | The file filter description. (Ex. All Files or Image Files) |
filterExtensions | The extensions to filter on. (Ex. png;bmp) |
initialDirectory | The initial directory to start. NULL runs from the executable directory. |
static bool gameplay::FileSystem::fileExists | ( | const char * | filePath | ) | [static] |
Checks if the file at the given path exists.
filePath | The path to the file. |
true
if the file exists; false
otherwise. static const char* gameplay::FileSystem::getAssetPath | ( | ) | [static] |
Returns the currently set asset root path.
static std::string gameplay::FileSystem::getDirectoryName | ( | const char * | path | ) | [static] |
Returns the directory name up to and including the trailing '/'.
This is a lexical method so it does not verify that the directory exists. Back slashes will be converted to forward slashes.
path | The file path. May be relative or absolute, forward or back slashes. May be NULL. |
static std::string gameplay::FileSystem::getExtension | ( | const char * | path | ) | [static] |
Returns the extension of the given file path.
The extension returned includes all character after and including the last '.' in the file path. The extension is returned as all uppercase.
If the path does not contain an extension, an empty string is returned.
path | File path. |
static const char* gameplay::FileSystem::getResourcePath | ( | ) | [static] |
Returns the currently set resource path.
static bool gameplay::FileSystem::isAbsolutePath | ( | const char * | filePath | ) | [static] |
Determines if the file path is an absolute path for the current platform.
filePath | The file path to test. |
static bool gameplay::FileSystem::listFiles | ( | const char * | dirPath, |
std::vector< std::string > & | files | ||
) | [static] |
Lists the files in the specified directory and adds the files to the vector. Excludes directories.
dirPath | Directory path relative to the path set in setResourcePath(const char*) . |
files | The vector to append the files to. |
static void gameplay::FileSystem::loadResourceAliases | ( | const char * | aliasFilePath | ) | [static] |
Loads a properties file containing a list of filesystem aliases.
The specified aliases file is a valid properties file that contains one or more namespaces with a list of filesystem aliases that will be used to establish soft links to files when reading files through this class.
This can be helpful for managing loading of resources that may change from one platform to another (such as texture formats). An aliases file per-platform can be maintained and asset loading code can refer to the alias name instead of the actual hard file name.
aliasFilePath | Path to a properties file containing filesystem aliases. |
static void gameplay::FileSystem::loadResourceAliases | ( | Properties * | properties | ) | [static] |
Loads a set of filesystem aliases from the given Properties object.
The specified properties object contains a single namespace with a list of filesystem aliases that will be used to establish soft links to files when reading files through this class.
This can be helpful for managing loading of resources that may change from one platform to another (such as texture formats). An aliases file per-platform can be maintained and asset loading code can refer to the alias name instead of the actual hard file name.
properties | Properties object containing filesystem aliases. |
static Stream* gameplay::FileSystem::open | ( | const char * | path, |
size_t | streamMode = READ |
||
) | [static] |
Opens a byte stream for the given resource path.
If path
is a file path, the file at the specified location is opened relative to the currently set resource path.
path | The path to the resource to be opened, relative to the currently set resource path. |
streamMode | The stream mode used to open the file. |
static FILE* gameplay::FileSystem::openFile | ( | const char * | filePath, |
const char * | mode | ||
) | [static] |
Opens the specified file.
The file at the specified location is opened, relative to the currently set resource path.
filePath | The path to the file to be opened, relative to the currently set resource path. |
mode | The mode used to open the file, passed directly to fopen. |
static char* gameplay::FileSystem::readAll | ( | const char * | filePath, |
int * | fileSize = NULL |
||
) | [static] |
Reads the entire contents of the specified file and returns its contents.
The returned character array is allocated with new[] and must therefore deleted by the caller using delete[].
filePath | The path to the file to be read. |
fileSize | The size of the file in bytes (optional). |
static const char* gameplay::FileSystem::resolvePath | ( | const char * | path | ) | [static] |
Resolves a filesystem path.
If the specified path is a filesystem alias, the alias will be resolved and the physical file will be returned.
Note that this method does not convert a relative path to an absolute filesystem path.
path | Path to resolve. |
static void gameplay::FileSystem::setAssetPath | ( | const char * | path | ) | [static] |
Sets the asset root path for the game on platforms that have separate assets (currently just Android).
Once set, all asset paths will be loaded relative to the given path. The default asset path is an empty string ("").
path | The asset root path. |
static void gameplay::FileSystem::setResourcePath | ( | const char * | path | ) | [static] |
Sets the path to the root of the resources folder for the game.
Once set, all resource/file loading will load from the given path. The default resource path is "./".
path | The path to the root of the resources folder. |