FileSystemGCWii.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright 2008 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <cstddef>
  5. #include <map>
  6. #include <memory>
  7. #include <optional>
  8. #include <string>
  9. #include <string_view>
  10. #include <vector>
  11. #include "Common/CommonTypes.h"
  12. #include "DiscIO/Filesystem.h"
  13. namespace DiscIO
  14. {
  15. class VolumeDisc;
  16. struct Partition;
  17. class FileInfoGCWii : public FileInfo
  18. {
  19. public:
  20. // None of the constructors take ownership of FST pointers
  21. // Set everything manually
  22. FileInfoGCWii(const u8* fst, u8 offset_shift, u32 index, u32 total_file_infos);
  23. // For the root object only
  24. FileInfoGCWii(const u8* fst, u8 offset_shift);
  25. // Copy another object
  26. FileInfoGCWii(const FileInfoGCWii& file_info) = default;
  27. // Copy data that is common to the whole file system
  28. FileInfoGCWii(const FileInfoGCWii& file_info, u32 index);
  29. ~FileInfoGCWii() override;
  30. std::unique_ptr<FileInfo> clone() const override;
  31. const_iterator begin() const override;
  32. const_iterator end() const override;
  33. u64 GetOffset() const override;
  34. u32 GetSize() const override;
  35. bool IsRoot() const override;
  36. bool IsDirectory() const override;
  37. u32 GetTotalChildren() const override;
  38. std::string GetName() const override;
  39. bool NameCaseInsensitiveEquals(std::string_view other) const override;
  40. std::string GetPath() const override;
  41. bool IsValid(u64 fst_size, const FileInfoGCWii& parent_directory) const;
  42. protected:
  43. uintptr_t GetAddress() const override;
  44. FileInfo& operator++() override;
  45. private:
  46. enum class EntryProperty
  47. {
  48. // NAME_OFFSET's lower 3 bytes are the name's offset within the name table.
  49. // NAME_OFFSET's upper 1 byte is 1 for directories and 0 for files.
  50. NAME_OFFSET = 0,
  51. // For files, FILE_OFFSET is the file offset in the partition,
  52. // and for directories, it's the FST index of the parent directory.
  53. // The root directory has its parent directory index set to 0.
  54. FILE_OFFSET = 1,
  55. // For files, FILE_SIZE is the file size, and for directories,
  56. // it's the FST index of the next entry that isn't in the directory.
  57. FILE_SIZE = 2
  58. };
  59. // For files, returns the index of the next item. For directories,
  60. // returns the index of the next item that isn't inside it.
  61. u32 GetNextIndex() const;
  62. // Returns one of the three properties of this FST entry.
  63. // Read the comments in EntryProperty for details.
  64. u32 Get(EntryProperty entry_property) const;
  65. // Returns the name offset, excluding the directory identification byte
  66. u64 GetNameOffset() const;
  67. const u8* m_fst;
  68. u8 m_offset_shift;
  69. u32 m_index;
  70. u32 m_total_file_infos;
  71. };
  72. class FileSystemGCWii : public FileSystem
  73. {
  74. public:
  75. FileSystemGCWii(const VolumeDisc* volume, const Partition& partition);
  76. ~FileSystemGCWii() override;
  77. bool IsValid() const override { return m_valid; }
  78. const FileInfo& GetRoot() const override;
  79. std::unique_ptr<FileInfo> FindFileInfo(std::string_view path) const override;
  80. std::unique_ptr<FileInfo> FindFileInfo(u64 disc_offset) const override;
  81. private:
  82. bool m_valid;
  83. std::vector<u8> m_file_system_table;
  84. FileInfoGCWii m_root;
  85. // Maps the end offset of files to FST indexes
  86. mutable std::map<u64, u32> m_offset_file_info_cache;
  87. std::unique_ptr<FileInfo> FindFileInfo(std::string_view path, const FileInfo& file_info) const;
  88. };
  89. } // namespace DiscIO