overview wiki api reference download
 All Classes Functions Variables Typedefs Enumerations Enumerator
Public Types | Public Member Functions | Static Public Member Functions
gameplay::FileSystem Class Reference

#include <FileSystem.h>

List of all members.

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 Streamopen (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)

Detailed Description

Defines a set of functions for interacting with the device file system.


Member Enumeration Documentation

Mode flags for displaying a dialog.

Mode flags for opening a stream.


Constructor & Destructor Documentation

Destructor.


Member Function Documentation

static void gameplay::FileSystem::createFileFromAsset ( const char *  path) [static]

Creates a file on the file system from the specified asset (Android-specific).

Parameters:
pathThe 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.

Parameters:
dialogModeThe mode of the dialog. (Ex. OPEN or SAVE)
titleThe title of the dialog. (Ex. Select File or Save File)
filterDescriptionThe file filter description. (Ex. All Files or Image Files)
filterExtensionsThe extensions to filter on. (Ex. png;bmp)
initialDirectoryThe initial directory to start. NULL runs from the executable directory.
Returns:
The file that is opened or saved, or an empty string if canceled.
static bool gameplay::FileSystem::fileExists ( const char *  filePath) [static]

Checks if the file at the given path exists.

Parameters:
filePathThe path to the file.
Returns:
true if the file exists; false otherwise.
static const char* gameplay::FileSystem::getAssetPath ( ) [static]

Returns the currently set asset root path.

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.

  • "res/image.png" will return "res/"
  • "image.png" will return ""
  • "c:\foo\bar\image.png" will return "c:/foo/bar/"
Parameters:
pathThe file path. May be relative or absolute, forward or back slashes. May be NULL.
Returns:
The directory name with the trailing '/'. Returns "" if path is NULL or the path does not contain a directory.
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.

Parameters:
pathFile path.
Returns:
The file extension, all uppercase, including the '.'.
static const char* gameplay::FileSystem::getResourcePath ( ) [static]

Returns the currently set resource path.

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.

Parameters:
filePathThe file path to test.
Returns:
True if the path is an absolute path or false otherwise.
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.

Parameters:
dirPathDirectory path relative to the path set in setResourcePath(const char*).
filesThe vector to append the files to.
Returns:
True if successful, false if error.
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.

Parameters:
aliasFilePathPath to a properties file containing filesystem aliases.
See also:
Properties
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.

Parameters:
propertiesProperties object containing filesystem aliases.
See also:
Properties
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.

Parameters:
pathThe path to the resource to be opened, relative to the currently set resource path.
streamModeThe stream mode used to open the file.
Returns:
A stream that can be used to read or write to the file depending on the mode. Returns NULL if there was an error. (Request mode not supported).
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.

Parameters:
filePathThe path to the file to be opened, relative to the currently set resource path.
modeThe mode used to open the file, passed directly to fopen.
Returns:
A pointer to a FILE object that can be used to identify the stream or NULL on error.
See also:
setResourcePath(const char*)
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[].

Parameters:
filePathThe path to the file to be read.
fileSizeThe size of the file in bytes (optional).
Returns:
A newly allocated (NULL-terminated) character array containing the contents of the file, or NULL if the file could not be read.
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.

Parameters:
pathPath to resolve.
Returns:
The resolved file path.
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 ("").

Parameters:
pathThe 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 "./".

Parameters:
pathThe path to the root of the resources folder.
 All Classes Functions Variables Typedefs Enumerations Enumerator