BsFileSystem.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 Creates a folder at the specified path.
  52. *
  53. * @param fullPath Full path to a full folder to create.
  54. */
  55. static void createDir(const Path& fullPath);
  56. /**
  57. * @brief Returns true if a file or a folder exists at the specified path.
  58. *
  59. * @param fullPath Full path to a file or folder.
  60. */
  61. static bool exists(const Path& fullPath);
  62. /**
  63. * @brief Returns true if a file exists at the specified path.
  64. *
  65. * @param fullPath Full path to a file or folder.
  66. */
  67. static bool isFile(const Path& fullPath);
  68. /**
  69. * @brief Returns true if a folder exists at the specified path.
  70. *
  71. * @param fullPath Full path to a file or folder.
  72. */
  73. static bool isDirectory(const Path& fullPath);
  74. /**
  75. * @brief Returns all files or folders located in the specified folder.
  76. *
  77. * @param dirPath Full path to the folder to retrieve children files/folders from.
  78. * @param [out] files Full paths to all files located directly in specified folder.
  79. * @param [out] directories Full paths to all folders located directly in specified folder.
  80. */
  81. static void getChildren(const Path& dirPath, Vector<Path>& files, Vector<Path>& directories);
  82. /**
  83. * @brief Returns the last modified time of a file or a folder at the specified path.
  84. *
  85. * @param fullPath Full path to a file or a folder.
  86. */
  87. static std::time_t getLastModifiedTime(const Path& fullPath);
  88. /**
  89. * @brief Returns the path to the currently working directory.
  90. */
  91. static Path getWorkingDirectoryPath();
  92. };
  93. }