BsFileSystem.h 3.7 KB

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