vfs_layered.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <memory>
  6. #include "core/file_sys/vfs.h"
  7. namespace FileSys {
  8. // Wrapper function to allow for more efficient handling of dirs.size() == 0, 1 cases.
  9. VirtualDir LayerDirectories(std::vector<VirtualDir> dirs, std::string name = "");
  10. // Class that stacks multiple VfsDirectories on top of each other, attempting to read from the first
  11. // one and falling back to the one after. The highest priority directory (overwrites all others)
  12. // should be element 0 in the dirs vector.
  13. class LayeredVfsDirectory : public VfsDirectory {
  14. friend VirtualDir LayerDirectories(std::vector<VirtualDir> dirs, std::string name);
  15. LayeredVfsDirectory(std::vector<VirtualDir> dirs, std::string name);
  16. public:
  17. ~LayeredVfsDirectory() override;
  18. std::shared_ptr<VfsFile> GetFileRelative(std::string_view path) const override;
  19. std::shared_ptr<VfsDirectory> GetDirectoryRelative(std::string_view path) const override;
  20. std::shared_ptr<VfsFile> GetFile(std::string_view name) const override;
  21. std::shared_ptr<VfsDirectory> GetSubdirectory(std::string_view name) const override;
  22. std::string GetFullPath() const override;
  23. std::vector<std::shared_ptr<VfsFile>> GetFiles() const override;
  24. std::vector<std::shared_ptr<VfsDirectory>> GetSubdirectories() const override;
  25. bool IsWritable() const override;
  26. bool IsReadable() const override;
  27. std::string GetName() const override;
  28. std::shared_ptr<VfsDirectory> GetParentDirectory() const override;
  29. std::shared_ptr<VfsDirectory> CreateSubdirectory(std::string_view name) override;
  30. std::shared_ptr<VfsFile> CreateFile(std::string_view name) override;
  31. bool DeleteSubdirectory(std::string_view name) override;
  32. bool DeleteFile(std::string_view name) override;
  33. bool Rename(std::string_view name) override;
  34. protected:
  35. bool ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) override;
  36. private:
  37. std::vector<VirtualDir> dirs;
  38. std::string name;
  39. };
  40. } // namespace FileSys