Filesystem.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /**
  2. * Copyright (c) 2006-2022 LOVE Development Team
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. **/
  20. #ifndef LOVE_FILESYSTEM_PHYSFS_FILESYSTEM_H
  21. #define LOVE_FILESYSTEM_PHYSFS_FILESYSTEM_H
  22. // STD
  23. #include <cstdlib>
  24. #include <cstring>
  25. #include <map>
  26. // LOVE
  27. #include "filesystem/Filesystem.h"
  28. namespace love
  29. {
  30. namespace filesystem
  31. {
  32. namespace physfs
  33. {
  34. class Filesystem final : public love::filesystem::Filesystem
  35. {
  36. public:
  37. Filesystem();
  38. virtual ~Filesystem();
  39. // Implements Module.
  40. const char *getName() const override;
  41. void init(const char *arg0) override;
  42. void setFused(bool fused) override;
  43. bool isFused() const override;
  44. bool setupWriteDirectory() override;
  45. bool setIdentity(const char *ident, bool appendToPath = false) override;
  46. const char *getIdentity() const override;
  47. bool setSource(const char *source) override;
  48. const char *getSource() const override;
  49. bool mount(const char *archive, const char *mountpoint, bool appendToPath = false) override;
  50. bool mount(Data *data, const char *archivename, const char *mountpoint, bool appendToPath = false) override;
  51. bool mountFullPath(const char *archive, const char *mountpoint, MountPermissions permissions, bool appendToPath = false) override;
  52. bool mountCommonPath(CommonPath path, const char *mountpoint, MountPermissions permissions, bool appendToPath = false) override;
  53. bool unmount(const char *archive) override;
  54. bool unmount(Data *data) override;
  55. bool unmount(CommonPath path) override;
  56. bool unmountFullPath(const char *fullpath) override;
  57. love::filesystem::File *newFile(const char *filename, File::Mode mode = File::MODE_CLOSED) const override;
  58. std::string getFullCommonPath(CommonPath path) override;
  59. const char *getWorkingDirectory() override;
  60. std::string getUserDirectory() override;
  61. std::string getAppdataDirectory() override;
  62. std::string getSaveDirectory() override;
  63. std::string getSourceBaseDirectory() const override;
  64. std::string getRealDirectory(const char *filename) const override;
  65. bool getInfo(const char *filepath, Info &info) const override;
  66. bool createDirectory(const char *dir) override;
  67. bool remove(const char *file) override;
  68. FileData *read(const char *filename, int64 size) const override;
  69. FileData *read(const char *filename) const override;
  70. void write(const char *filename, const void *data, int64 size) const override;
  71. void append(const char *filename, const void *data, int64 size) const override;
  72. bool getDirectoryItems(const char *dir, std::vector<std::string> &items) override;
  73. void setSymlinksEnabled(bool enable) override;
  74. bool areSymlinksEnabled() const override;
  75. std::vector<std::string> &getRequirePath() override;
  76. std::vector<std::string> &getCRequirePath() override;
  77. void allowMountingForPath(const std::string &path) override;
  78. private:
  79. struct CommonPathMountInfo
  80. {
  81. bool mounted;
  82. std::string mountPoint;
  83. MountPermissions permissions;
  84. };
  85. bool mountCommonPathInternal(CommonPath path, const char *mountpoint, MountPermissions permissions, bool appendToPath, bool createDir);
  86. // Contains the current working directory (UTF8).
  87. std::string cwd;
  88. // This name will be used to create the folder in the appdata folder.
  89. std::string saveIdentity;
  90. bool appendIdentityToPath;
  91. // The full path to the source of the game.
  92. std::string gameSource;
  93. // Allow saving outside of the LOVE_APPDATA_FOLDER for release 'builds'
  94. bool fused;
  95. bool fusedSet;
  96. // Search path for require
  97. std::vector<std::string> requirePath;
  98. std::vector<std::string> cRequirePath;
  99. std::vector<std::string> allowedMountPaths;
  100. std::map<std::string, StrongRef<Data>> mountedData;
  101. std::string fullPaths[COMMONPATH_MAX_ENUM];
  102. CommonPathMountInfo commonPathMountInfo[COMMONPATH_MAX_ENUM];
  103. bool saveDirectoryNeedsMounting;
  104. }; // Filesystem
  105. } // physfs
  106. } // filesystem
  107. } // love
  108. #endif // LOVE_FILESYSTEM_PHYSFS_FILESYSTEM_H