| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- #ifndef FILESYSTEM_H_
- #define FILESYSTEM_H_
- namespace gameplay
- {
- /**
- * Defines a set of functions for interacting with the device filesystem.
- */
- class FileSystem
- {
- public:
- /**
- * Destructor.
- */
- ~FileSystem();
- /**
- * 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 "./".
- *
- * @param path The path to the root of the resources folder.
- */
- static void setResourcePath(const char* path);
- /**
- * Returns the currently set resource path.
- *
- * @return The currently set resource path.
- */
- static const char* getResourcePath();
- /**
- * Lists the files in the specified directory and adds the files to the vector. Excludes directories.
- *
- * @param dirPath Directory path relative to the path set in <code>setResourcePath(const char*)</code>.
- * @param files The vector to append the files to.
- *
- * @return True if successful, false if error.
- */
- static bool listFiles(const char* dirPath, std::vector<std::string>& files);
- /**
- * Opens the specified file.
- *
- * The file at the specified location is opened, relative to the currently set
- * resource path.
- *
- * @param path The path to the file to be opened, relative to the currently set resource path.
- * @param mode The mode used to open the file, passed directly to fopen.
- *
- * @see setResourcePath(const char*)
- */
- static FILE* openFile(const char* path, const char* mode);
- /**
- * 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[].
- *
- * @param filePath The path to the file to be read.
- * @param fileSize The size of the file in bytes (optional).
- *
- * @return A newly allocated (NULL-terminated) character array containing the
- * contents of the file, or NULL if the file could not be read.
- */
- static char* readAll(const char* filePath, int* fileSize = NULL);
- private:
- /**
- * Constructor.
- */
- FileSystem();
- };
- }
- #endif
|