Debian Codegraph @

Source/Core/DiscIO/FileSystemGCWii.h

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