BsFileSystem.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #pragma once
  2. #include "BsPrerequisitesUtil.h"
  3. namespace BansheeEngine
  4. {
  5. /**
  6. * @brief Utility class for dealing with files.
  7. */
  8. class BS_UTILITY_EXPORT FileSystem
  9. {
  10. public:
  11. /**
  12. * @brief Opens a file and returns a data stream capable of reading or writing to that file.
  13. *
  14. * @param fullPath Full path to a file.
  15. * @param readOnly (optional) If true, returned stream will only be readable.
  16. */
  17. static DataStreamPtr openFile(const Path& fullPath, bool readOnly = true);
  18. /**
  19. * @brief Opens a file and returns a data stream capable of reading and writing to that file.
  20. * If file doesn't exist new one will be created.
  21. *
  22. * @param fullPath Full path to a file.
  23. */
  24. static DataStreamPtr createAndOpenFile(const Path& fullPath);
  25. /**
  26. * @brief Returns the size of a file in bytes.
  27. *
  28. * @param fullPath Full path to a file.
  29. */
  30. static UINT64 getFileSize(const Path& fullPath);
  31. /**
  32. * @brief Deletes a file or a folder at the specified path.
  33. *
  34. * @param fullPath Full path to a file or a folder..
  35. * @param recursively (optional) If true, folders will have their contents
  36. * deleted as well. Otherwise an exception will be
  37. * thrown for non-empty folders.
  38. */
  39. static void remove(const Path& fullPath, bool recursively = true);
  40. /**
  41. * @brief Moves a file or a folder from one to another path. This
  42. * can also be used as a rename operation.
  43. *
  44. * @param oldPath Full path to the old file/folder.
  45. * @param newPath Full path to the new file/folder.
  46. * @param overwriteExisting (optional) If true, any existing file/folder at the new location will be overwritten,
  47. * otherwise an exception will be thrown if a file/folder already exists.
  48. */
  49. static void move(const Path& oldPath, const Path& newPath, bool overwriteExisting = true);
  50. /**
  51. * @brief Makes a copy of a file or a folder in the specified path.
  52. *
  53. * @param oldPath Full path to the old file/folder.
  54. * @param newPath Full path to the new file/folder.
  55. * @param overwriteExisting (optional) If true, any existing file/folder at the new location will be overwritten,
  56. * otherwise an exception will be thrown if a file/folder already exists.
  57. */
  58. static void copy(const Path& oldPath, const Path& newPath, bool overwriteExisting = true);
  59. /**
  60. * @brief Creates a folder at the specified path.
  61. *
  62. * @param fullPath Full path to a full folder to create.
  63. */
  64. static void createDir(const Path& fullPath);
  65. /**
  66. * @brief Returns true if a file or a folder exists at the specified path.
  67. *
  68. * @param fullPath Full path to a file or folder.
  69. */
  70. static bool exists(const Path& fullPath);
  71. /**
  72. * @brief Returns true if a file exists at the specified path.
  73. *
  74. * @param fullPath Full path to a file or folder.
  75. */
  76. static bool isFile(const Path& fullPath);
  77. /**
  78. * @brief Returns true if a folder exists at the specified path.
  79. *
  80. * @param fullPath Full path to a file or folder.
  81. */
  82. static bool isDirectory(const Path& fullPath);
  83. /**
  84. * @brief Returns all files or folders located in the specified folder.
  85. *
  86. * @param dirPath Full path to the folder to retrieve children files/folders from.
  87. * @param [out] files Full paths to all files located directly in specified folder.
  88. * @param [out] directories Full paths to all folders located directly in specified folder.
  89. */
  90. static void getChildren(const Path& dirPath, Vector<Path>& files, Vector<Path>& directories);
  91. /**
  92. * @brief Returns the last modified time of a file or a folder at the specified path.
  93. *
  94. * @param fullPath Full path to a file or a folder.
  95. */
  96. static std::time_t getLastModifiedTime(const Path& fullPath);
  97. /**
  98. * @brief Returns the path to the currently working directory.
  99. */
  100. static Path getWorkingDirectoryPath();
  101. };
  102. }