diff options
| author | 2018-09-25 17:38:16 -0400 | |
|---|---|---|
| committer | 2018-09-25 20:06:01 -0400 | |
| commit | 28bef31ea80478fe58bc4eeaf1b245005f15b36a (patch) | |
| tree | 8ccdb13e155d15b44893a0477984cc83bdf41224 /src | |
| parent | vfs_static: Remove template byte parameter from StaticVfsFile (diff) | |
| download | yuzu-28bef31ea80478fe58bc4eeaf1b245005f15b36a.tar.gz yuzu-28bef31ea80478fe58bc4eeaf1b245005f15b36a.tar.xz yuzu-28bef31ea80478fe58bc4eeaf1b245005f15b36a.zip | |
vfs_concat/vfs_layered: Remove friend declarations from ConcatenatedVfsFile
Given these are only added to the class to allow those functions to
access the private constructor, it's a better approach to just make them
static functions in the interface, to make the dependency explicit.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/core.cpp | 2 | ||||
| -rw-r--r-- | src/core/file_sys/patch_manager.cpp | 5 | ||||
| -rw-r--r-- | src/core/file_sys/registered_cache.cpp | 2 | ||||
| -rw-r--r-- | src/core/file_sys/romfs.cpp | 2 | ||||
| -rw-r--r-- | src/core/file_sys/vfs_concat.cpp | 67 | ||||
| -rw-r--r-- | src/core/file_sys/vfs_concat.h | 19 | ||||
| -rw-r--r-- | src/core/file_sys/vfs_layered.cpp | 15 | ||||
| -rw-r--r-- | src/core/file_sys/vfs_layered.h | 8 |
8 files changed, 59 insertions, 61 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp index 50f0a42fb..7666354dc 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp | |||
| @@ -64,7 +64,7 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs, | |||
| 64 | if (concat.empty()) | 64 | if (concat.empty()) |
| 65 | return nullptr; | 65 | return nullptr; |
| 66 | 66 | ||
| 67 | return FileSys::ConcatenateFiles(concat, dir->GetName()); | 67 | return FileSys::ConcatenatedVfsFile::MakeConcatenatedFile(concat, dir->GetName()); |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | return vfs->OpenFile(path, FileSys::Mode::Read); | 70 | return vfs->OpenFile(path, FileSys::Mode::Read); |
diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index af3f9a78f..561ad67a7 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp | |||
| @@ -90,10 +90,9 @@ static void ApplyLayeredFS(VirtualFile& romfs, u64 title_id, ContentRecordType t | |||
| 90 | 90 | ||
| 91 | layers.push_back(std::move(extracted)); | 91 | layers.push_back(std::move(extracted)); |
| 92 | 92 | ||
| 93 | const auto layered = LayerDirectories(layers); | 93 | auto layered = LayeredVfsDirectory::MakeLayeredDirectory(std::move(layers)); |
| 94 | |||
| 95 | if (layered != nullptr) { | 94 | if (layered != nullptr) { |
| 96 | auto packed = CreateRomFS(layered); | 95 | auto packed = CreateRomFS(std::move(layered)); |
| 97 | 96 | ||
| 98 | if (packed != nullptr) { | 97 | if (packed != nullptr) { |
| 99 | LOG_INFO(Loader, " RomFS: LayeredFS patches applied successfully"); | 98 | LOG_INFO(Loader, " RomFS: LayeredFS patches applied successfully"); |
diff --git a/src/core/file_sys/registered_cache.cpp b/src/core/file_sys/registered_cache.cpp index 653ef2e7b..e9b040689 100644 --- a/src/core/file_sys/registered_cache.cpp +++ b/src/core/file_sys/registered_cache.cpp | |||
| @@ -125,7 +125,7 @@ VirtualFile RegisteredCache::OpenFileOrDirectoryConcat(const VirtualDir& dir, | |||
| 125 | if (concat.empty()) | 125 | if (concat.empty()) |
| 126 | return nullptr; | 126 | return nullptr; |
| 127 | 127 | ||
| 128 | file = FileSys::ConcatenateFiles(concat, concat.front()->GetName()); | 128 | file = ConcatenatedVfsFile::MakeConcatenatedFile(concat, concat.front()->GetName()); |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | return file; | 131 | return file; |
diff --git a/src/core/file_sys/romfs.cpp b/src/core/file_sys/romfs.cpp index 7804ef56d..5910f7046 100644 --- a/src/core/file_sys/romfs.cpp +++ b/src/core/file_sys/romfs.cpp | |||
| @@ -134,7 +134,7 @@ VirtualFile CreateRomFS(VirtualDir dir) { | |||
| 134 | return nullptr; | 134 | return nullptr; |
| 135 | 135 | ||
| 136 | RomFSBuildContext ctx{dir}; | 136 | RomFSBuildContext ctx{dir}; |
| 137 | return ConcatenateFiles(0, ctx.Build(), dir->GetName()); | 137 | return ConcatenatedVfsFile::MakeConcatenatedFile(0, ctx.Build(), dir->GetName()); |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | } // namespace FileSys | 140 | } // namespace FileSys |
diff --git a/src/core/file_sys/vfs_concat.cpp b/src/core/file_sys/vfs_concat.cpp index 8a0df508e..16d801c0c 100644 --- a/src/core/file_sys/vfs_concat.cpp +++ b/src/core/file_sys/vfs_concat.cpp | |||
| @@ -39,6 +39,41 @@ ConcatenatedVfsFile::ConcatenatedVfsFile(std::map<u64, VirtualFile> files_, std: | |||
| 39 | 39 | ||
| 40 | ConcatenatedVfsFile::~ConcatenatedVfsFile() = default; | 40 | ConcatenatedVfsFile::~ConcatenatedVfsFile() = default; |
| 41 | 41 | ||
| 42 | VirtualFile ConcatenatedVfsFile::MakeConcatenatedFile(std::vector<VirtualFile> files, | ||
| 43 | std::string name) { | ||
| 44 | if (files.empty()) | ||
| 45 | return nullptr; | ||
| 46 | if (files.size() == 1) | ||
| 47 | return files[0]; | ||
| 48 | |||
| 49 | return std::shared_ptr<VfsFile>(new ConcatenatedVfsFile(std::move(files), std::move(name))); | ||
| 50 | } | ||
| 51 | |||
| 52 | VirtualFile ConcatenatedVfsFile::MakeConcatenatedFile(u8 filler_byte, | ||
| 53 | std::map<u64, VirtualFile> files, | ||
| 54 | std::string name) { | ||
| 55 | if (files.empty()) | ||
| 56 | return nullptr; | ||
| 57 | if (files.size() == 1) | ||
| 58 | return files.begin()->second; | ||
| 59 | |||
| 60 | const auto last_valid = --files.end(); | ||
| 61 | for (auto iter = files.begin(); iter != last_valid;) { | ||
| 62 | const auto old = iter++; | ||
| 63 | if (old->first + old->second->GetSize() != iter->first) { | ||
| 64 | files.emplace(old->first + old->second->GetSize(), | ||
| 65 | std::make_shared<StaticVfsFile>(filler_byte, iter->first - old->first - | ||
| 66 | old->second->GetSize())); | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | // Ensure the map starts at offset 0 (start of file), otherwise pad to fill. | ||
| 71 | if (files.begin()->first != 0) | ||
| 72 | files.emplace(0, std::make_shared<StaticVfsFile>(filler_byte, files.begin()->first)); | ||
| 73 | |||
| 74 | return std::shared_ptr<VfsFile>(new ConcatenatedVfsFile(std::move(files), std::move(name))); | ||
| 75 | } | ||
| 76 | |||
| 42 | std::string ConcatenatedVfsFile::GetName() const { | 77 | std::string ConcatenatedVfsFile::GetName() const { |
| 43 | if (files.empty()) | 78 | if (files.empty()) |
| 44 | return ""; | 79 | return ""; |
| @@ -101,36 +136,4 @@ bool ConcatenatedVfsFile::Rename(std::string_view name) { | |||
| 101 | return false; | 136 | return false; |
| 102 | } | 137 | } |
| 103 | 138 | ||
| 104 | VirtualFile ConcatenateFiles(std::vector<VirtualFile> files, std::string name) { | ||
| 105 | if (files.empty()) | ||
| 106 | return nullptr; | ||
| 107 | if (files.size() == 1) | ||
| 108 | return files[0]; | ||
| 109 | |||
| 110 | return std::shared_ptr<VfsFile>(new ConcatenatedVfsFile(std::move(files), std::move(name))); | ||
| 111 | } | ||
| 112 | |||
| 113 | VirtualFile ConcatenateFiles(u8 filler_byte, std::map<u64, VirtualFile> files, std::string name) { | ||
| 114 | if (files.empty()) | ||
| 115 | return nullptr; | ||
| 116 | if (files.size() == 1) | ||
| 117 | return files.begin()->second; | ||
| 118 | |||
| 119 | const auto last_valid = --files.end(); | ||
| 120 | for (auto iter = files.begin(); iter != last_valid;) { | ||
| 121 | const auto old = iter++; | ||
| 122 | if (old->first + old->second->GetSize() != iter->first) { | ||
| 123 | files.emplace(old->first + old->second->GetSize(), | ||
| 124 | std::make_shared<StaticVfsFile>(filler_byte, iter->first - old->first - | ||
| 125 | old->second->GetSize())); | ||
| 126 | } | ||
| 127 | } | ||
| 128 | |||
| 129 | // Ensure the map starts at offset 0 (start of file), otherwise pad to fill. | ||
| 130 | if (files.begin()->first != 0) | ||
| 131 | files.emplace(0, std::make_shared<StaticVfsFile>(filler_byte, files.begin()->first)); | ||
| 132 | |||
| 133 | return std::shared_ptr<VfsFile>(new ConcatenatedVfsFile(std::move(files), std::move(name))); | ||
| 134 | } | ||
| 135 | |||
| 136 | } // namespace FileSys | 139 | } // namespace FileSys |
diff --git a/src/core/file_sys/vfs_concat.h b/src/core/file_sys/vfs_concat.h index 17fa40ade..c90f9d5d1 100644 --- a/src/core/file_sys/vfs_concat.h +++ b/src/core/file_sys/vfs_concat.h | |||
| @@ -14,16 +14,20 @@ namespace FileSys { | |||
| 14 | // Class that wraps multiple vfs files and concatenates them, making reads seamless. Currently | 14 | // Class that wraps multiple vfs files and concatenates them, making reads seamless. Currently |
| 15 | // read-only. | 15 | // read-only. |
| 16 | class ConcatenatedVfsFile : public VfsFile { | 16 | class ConcatenatedVfsFile : public VfsFile { |
| 17 | friend VirtualFile ConcatenateFiles(std::vector<VirtualFile> files, std::string name); | ||
| 18 | friend VirtualFile ConcatenateFiles(u8 filler_byte, std::map<u64, VirtualFile> files, | ||
| 19 | std::string name); | ||
| 20 | |||
| 21 | ConcatenatedVfsFile(std::vector<VirtualFile> files, std::string name); | 17 | ConcatenatedVfsFile(std::vector<VirtualFile> files, std::string name); |
| 22 | ConcatenatedVfsFile(std::map<u64, VirtualFile> files, std::string name); | 18 | ConcatenatedVfsFile(std::map<u64, VirtualFile> files, std::string name); |
| 23 | 19 | ||
| 24 | public: | 20 | public: |
| 25 | ~ConcatenatedVfsFile() override; | 21 | ~ConcatenatedVfsFile() override; |
| 26 | 22 | ||
| 23 | /// Wrapper function to allow for more efficient handling of files.size() == 0, 1 cases. | ||
| 24 | static VirtualFile MakeConcatenatedFile(std::vector<VirtualFile> files, std::string name); | ||
| 25 | |||
| 26 | /// Convenience function that turns a map of offsets to files into a concatenated file, filling | ||
| 27 | /// gaps with a given filler byte. | ||
| 28 | static VirtualFile MakeConcatenatedFile(u8 filler_byte, std::map<u64, VirtualFile> files, | ||
| 29 | std::string name); | ||
| 30 | |||
| 27 | std::string GetName() const override; | 31 | std::string GetName() const override; |
| 28 | std::size_t GetSize() const override; | 32 | std::size_t GetSize() const override; |
| 29 | bool Resize(std::size_t new_size) override; | 33 | bool Resize(std::size_t new_size) override; |
| @@ -40,11 +44,4 @@ private: | |||
| 40 | std::string name; | 44 | std::string name; |
| 41 | }; | 45 | }; |
| 42 | 46 | ||
| 43 | // Wrapper function to allow for more efficient handling of files.size() == 0, 1 cases. | ||
| 44 | VirtualFile ConcatenateFiles(std::vector<VirtualFile> files, std::string name); | ||
| 45 | |||
| 46 | // Convenience function that turns a map of offsets to files into a concatenated file, filling gaps | ||
| 47 | // with a given filler byte. | ||
| 48 | VirtualFile ConcatenateFiles(u8 filler_byte, std::map<u64, VirtualFile> files, std::string name); | ||
| 49 | |||
| 50 | } // namespace FileSys | 47 | } // namespace FileSys |
diff --git a/src/core/file_sys/vfs_layered.cpp b/src/core/file_sys/vfs_layered.cpp index 45563d7ae..bfee01725 100644 --- a/src/core/file_sys/vfs_layered.cpp +++ b/src/core/file_sys/vfs_layered.cpp | |||
| @@ -8,7 +8,13 @@ | |||
| 8 | 8 | ||
| 9 | namespace FileSys { | 9 | namespace FileSys { |
| 10 | 10 | ||
| 11 | VirtualDir LayerDirectories(std::vector<VirtualDir> dirs, std::string name) { | 11 | LayeredVfsDirectory::LayeredVfsDirectory(std::vector<VirtualDir> dirs, std::string name) |
| 12 | : dirs(std::move(dirs)), name(std::move(name)) {} | ||
| 13 | |||
| 14 | LayeredVfsDirectory::~LayeredVfsDirectory() = default; | ||
| 15 | |||
| 16 | VirtualDir LayeredVfsDirectory::MakeLayeredDirectory(std::vector<VirtualDir> dirs, | ||
| 17 | std::string name) { | ||
| 12 | if (dirs.empty()) | 18 | if (dirs.empty()) |
| 13 | return nullptr; | 19 | return nullptr; |
| 14 | if (dirs.size() == 1) | 20 | if (dirs.size() == 1) |
| @@ -17,11 +23,6 @@ VirtualDir LayerDirectories(std::vector<VirtualDir> dirs, std::string name) { | |||
| 17 | return std::shared_ptr<VfsDirectory>(new LayeredVfsDirectory(std::move(dirs), std::move(name))); | 23 | return std::shared_ptr<VfsDirectory>(new LayeredVfsDirectory(std::move(dirs), std::move(name))); |
| 18 | } | 24 | } |
| 19 | 25 | ||
| 20 | LayeredVfsDirectory::LayeredVfsDirectory(std::vector<VirtualDir> dirs, std::string name) | ||
| 21 | : dirs(std::move(dirs)), name(std::move(name)) {} | ||
| 22 | |||
| 23 | LayeredVfsDirectory::~LayeredVfsDirectory() = default; | ||
| 24 | |||
| 25 | std::shared_ptr<VfsFile> LayeredVfsDirectory::GetFileRelative(std::string_view path) const { | 26 | std::shared_ptr<VfsFile> LayeredVfsDirectory::GetFileRelative(std::string_view path) const { |
| 26 | for (const auto& layer : dirs) { | 27 | for (const auto& layer : dirs) { |
| 27 | const auto file = layer->GetFileRelative(path); | 28 | const auto file = layer->GetFileRelative(path); |
| @@ -41,7 +42,7 @@ std::shared_ptr<VfsDirectory> LayeredVfsDirectory::GetDirectoryRelative( | |||
| 41 | out.push_back(std::move(dir)); | 42 | out.push_back(std::move(dir)); |
| 42 | } | 43 | } |
| 43 | 44 | ||
| 44 | return LayerDirectories(std::move(out)); | 45 | return MakeLayeredDirectory(std::move(out)); |
| 45 | } | 46 | } |
| 46 | 47 | ||
| 47 | std::shared_ptr<VfsFile> LayeredVfsDirectory::GetFile(std::string_view name) const { | 48 | std::shared_ptr<VfsFile> LayeredVfsDirectory::GetFile(std::string_view name) const { |
diff --git a/src/core/file_sys/vfs_layered.h b/src/core/file_sys/vfs_layered.h index 4f6e341ab..d85310f57 100644 --- a/src/core/file_sys/vfs_layered.h +++ b/src/core/file_sys/vfs_layered.h | |||
| @@ -9,20 +9,18 @@ | |||
| 9 | 9 | ||
| 10 | namespace FileSys { | 10 | namespace FileSys { |
| 11 | 11 | ||
| 12 | // Wrapper function to allow for more efficient handling of dirs.size() == 0, 1 cases. | ||
| 13 | VirtualDir LayerDirectories(std::vector<VirtualDir> dirs, std::string name = ""); | ||
| 14 | |||
| 15 | // Class that stacks multiple VfsDirectories on top of each other, attempting to read from the first | 12 | // Class that stacks multiple VfsDirectories on top of each other, attempting to read from the first |
| 16 | // one and falling back to the one after. The highest priority directory (overwrites all others) | 13 | // one and falling back to the one after. The highest priority directory (overwrites all others) |
| 17 | // should be element 0 in the dirs vector. | 14 | // should be element 0 in the dirs vector. |
| 18 | class LayeredVfsDirectory : public VfsDirectory { | 15 | class LayeredVfsDirectory : public VfsDirectory { |
| 19 | friend VirtualDir LayerDirectories(std::vector<VirtualDir> dirs, std::string name); | ||
| 20 | |||
| 21 | LayeredVfsDirectory(std::vector<VirtualDir> dirs, std::string name); | 16 | LayeredVfsDirectory(std::vector<VirtualDir> dirs, std::string name); |
| 22 | 17 | ||
| 23 | public: | 18 | public: |
| 24 | ~LayeredVfsDirectory() override; | 19 | ~LayeredVfsDirectory() override; |
| 25 | 20 | ||
| 21 | /// Wrapper function to allow for more efficient handling of dirs.size() == 0, 1 cases. | ||
| 22 | static VirtualDir MakeLayeredDirectory(std::vector<VirtualDir> dirs, std::string name = ""); | ||
| 23 | |||
| 26 | std::shared_ptr<VfsFile> GetFileRelative(std::string_view path) const override; | 24 | std::shared_ptr<VfsFile> GetFileRelative(std::string_view path) const override; |
| 27 | std::shared_ptr<VfsDirectory> GetDirectoryRelative(std::string_view path) const override; | 25 | std::shared_ptr<VfsDirectory> GetDirectoryRelative(std::string_view path) const override; |
| 28 | std::shared_ptr<VfsFile> GetFile(std::string_view name) const override; | 26 | std::shared_ptr<VfsFile> GetFile(std::string_view name) const override; |