FileSystem.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. * Opens the specified file.
  32. *
  33. * The file at the specified location is opened, relative to the currently set
  34. * resource path.
  35. *
  36. * @param path The path to the file to be opened, relative to the currently set resource path.
  37. * @param mode The mode used to open the file, passed directly to fopen.
  38. *
  39. * @see setResourcePath(const char*)
  40. */
  41. static FILE* openFile(const char* path, const char* mode);
  42. /**
  43. * Reads the entire contents of the specified file and returns its contents.
  44. *
  45. * The returned character array is allocated with new[] and must therefore
  46. * deleted by the caller using delete[].
  47. *
  48. * @param filePath The path to the file to be read.
  49. * @param fileSize The size of the file in bytes (optional).
  50. *
  51. * @return A newly allocated (NULL-terminated) character array containing the
  52. * contents of the file, or NULL if the file could not be read.
  53. */
  54. static char* readAll(const char* filePath, int* fileSize = NULL);
  55. private:
  56. /**
  57. * Constructor.
  58. */
  59. FileSystem();
  60. };
  61. }
  62. #endif