FileSystem.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #ifndef FILESYSTEM_H_
  2. #define FILESYSTEM_H_
  3. namespace gameplay
  4. {
  5. /**
  6. * Defines a set of functions for interacting with the device filesystem.
  7. */
  8. class FileSystem
  9. {
  10. public:
  11. /**
  12. * Destructor.
  13. */
  14. ~FileSystem();
  15. /**
  16. * Sets the path to the root of the resources folder for the game.
  17. *
  18. * Once set, all resource/file loading will load from the given path.
  19. * The default resource path is "./".
  20. *
  21. * @param path The path to the root of the resources folder.
  22. */
  23. static void setResourcePath(const char* path);
  24. /**
  25. * Returns the currently set resource path.
  26. *
  27. * @return The currently set resource path.
  28. */
  29. static const char* getResourcePath();
  30. /**
  31. * Lists the files in the specified directory and adds the files to the vector. Excludes directories.
  32. *
  33. * @param dirPath Directory path relative to the path set in <code>setResourcePath(const char*)</code>.
  34. * @param files The vector to append the files to.
  35. *
  36. * @return True if successful, false if error.
  37. */
  38. static bool listFiles(const char* dirPath, std::vector<std::string>& files);
  39. /**
  40. * Opens the specified file.
  41. *
  42. * The file at the specified location is opened, relative to the currently set
  43. * resource path.
  44. *
  45. * @param path The path to the file to be opened, relative to the currently set resource path.
  46. * @param mode The mode used to open the file, passed directly to fopen.
  47. *
  48. * @see setResourcePath(const char*)
  49. */
  50. static FILE* openFile(const char* path, const char* mode);
  51. /**
  52. * Reads the entire contents of the specified file and returns its contents.
  53. *
  54. * The returned character array is allocated with new[] and must therefore
  55. * deleted by the caller using delete[].
  56. *
  57. * @param filePath The path to the file to be read.
  58. * @param fileSize The size of the file in bytes (optional).
  59. *
  60. * @return A newly allocated (NULL-terminated) character array containing the
  61. * contents of the file, or NULL if the file could not be read.
  62. */
  63. static char* readAll(const char* filePath, int* fileSize = NULL);
  64. private:
  65. /**
  66. * Constructor.
  67. */
  68. FileSystem();
  69. };
  70. }
  71. #endif