diff options
Diffstat (limited to '')
| -rw-r--r-- | src/core/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/core/file_sys/patch_manager.cpp | 5 | ||||
| -rw-r--r-- | src/core/file_sys/vfs_cached.cpp | 63 | ||||
| -rw-r--r-- | src/core/file_sys/vfs_cached.h | 31 |
4 files changed, 99 insertions, 2 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 45328158f..e8bf68866 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -106,6 +106,8 @@ add_library(core STATIC | |||
| 106 | file_sys/system_archive/time_zone_binary.h | 106 | file_sys/system_archive/time_zone_binary.h |
| 107 | file_sys/vfs.cpp | 107 | file_sys/vfs.cpp |
| 108 | file_sys/vfs.h | 108 | file_sys/vfs.h |
| 109 | file_sys/vfs_cached.cpp | ||
| 110 | file_sys/vfs_cached.h | ||
| 109 | file_sys/vfs_concat.cpp | 111 | file_sys/vfs_concat.cpp |
| 110 | file_sys/vfs_concat.h | 112 | file_sys/vfs_concat.h |
| 111 | file_sys/vfs_layered.cpp | 113 | file_sys/vfs_layered.cpp |
diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index 4c80e13a9..f786f2add 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp | |||
| @@ -21,6 +21,7 @@ | |||
| 21 | #include "core/file_sys/patch_manager.h" | 21 | #include "core/file_sys/patch_manager.h" |
| 22 | #include "core/file_sys/registered_cache.h" | 22 | #include "core/file_sys/registered_cache.h" |
| 23 | #include "core/file_sys/romfs.h" | 23 | #include "core/file_sys/romfs.h" |
| 24 | #include "core/file_sys/vfs_cached.h" | ||
| 24 | #include "core/file_sys/vfs_layered.h" | 25 | #include "core/file_sys/vfs_layered.h" |
| 25 | #include "core/file_sys/vfs_vector.h" | 26 | #include "core/file_sys/vfs_vector.h" |
| 26 | #include "core/hle/service/filesystem/filesystem.h" | 27 | #include "core/hle/service/filesystem/filesystem.h" |
| @@ -380,11 +381,11 @@ static void ApplyLayeredFS(VirtualFile& romfs, u64 title_id, ContentRecordType t | |||
| 380 | 381 | ||
| 381 | auto romfs_dir = FindSubdirectoryCaseless(subdir, "romfs"); | 382 | auto romfs_dir = FindSubdirectoryCaseless(subdir, "romfs"); |
| 382 | if (romfs_dir != nullptr) | 383 | if (romfs_dir != nullptr) |
| 383 | layers.push_back(std::move(romfs_dir)); | 384 | layers.push_back(std::make_shared<CachedVfsDirectory>(romfs_dir)); |
| 384 | 385 | ||
| 385 | auto ext_dir = FindSubdirectoryCaseless(subdir, "romfs_ext"); | 386 | auto ext_dir = FindSubdirectoryCaseless(subdir, "romfs_ext"); |
| 386 | if (ext_dir != nullptr) | 387 | if (ext_dir != nullptr) |
| 387 | layers_ext.push_back(std::move(ext_dir)); | 388 | layers_ext.push_back(std::make_shared<CachedVfsDirectory>(ext_dir)); |
| 388 | } | 389 | } |
| 389 | 390 | ||
| 390 | // When there are no layers to apply, return early as there is no need to rebuild the RomFS | 391 | // When there are no layers to apply, return early as there is no need to rebuild the RomFS |
diff --git a/src/core/file_sys/vfs_cached.cpp b/src/core/file_sys/vfs_cached.cpp new file mode 100644 index 000000000..c3154ee81 --- /dev/null +++ b/src/core/file_sys/vfs_cached.cpp | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include "core/file_sys/vfs_cached.h" | ||
| 5 | #include "core/file_sys/vfs_types.h" | ||
| 6 | |||
| 7 | namespace FileSys { | ||
| 8 | |||
| 9 | CachedVfsDirectory::CachedVfsDirectory(VirtualDir& source_dir) | ||
| 10 | : name(source_dir->GetName()), parent(source_dir->GetParentDirectory()) { | ||
| 11 | for (auto& dir : source_dir->GetSubdirectories()) { | ||
| 12 | dirs.emplace(dir->GetName(), std::make_shared<CachedVfsDirectory>(dir)); | ||
| 13 | } | ||
| 14 | for (auto& file : source_dir->GetFiles()) { | ||
| 15 | files.emplace(file->GetName(), file); | ||
| 16 | } | ||
| 17 | } | ||
| 18 | |||
| 19 | CachedVfsDirectory::~CachedVfsDirectory() = default; | ||
| 20 | |||
| 21 | VirtualFile CachedVfsDirectory::GetFile(std::string_view file_name) const { | ||
| 22 | auto it = files.find(file_name); | ||
| 23 | if (it != files.end()) { | ||
| 24 | return it->second; | ||
| 25 | } | ||
| 26 | |||
| 27 | return nullptr; | ||
| 28 | } | ||
| 29 | |||
| 30 | VirtualDir CachedVfsDirectory::GetSubdirectory(std::string_view dir_name) const { | ||
| 31 | auto it = dirs.find(dir_name); | ||
| 32 | if (it != dirs.end()) { | ||
| 33 | return it->second; | ||
| 34 | } | ||
| 35 | |||
| 36 | return nullptr; | ||
| 37 | } | ||
| 38 | |||
| 39 | std::vector<VirtualFile> CachedVfsDirectory::GetFiles() const { | ||
| 40 | std::vector<VirtualFile> out; | ||
| 41 | for (auto& [file_name, file] : files) { | ||
| 42 | out.push_back(file); | ||
| 43 | } | ||
| 44 | return out; | ||
| 45 | } | ||
| 46 | |||
| 47 | std::vector<VirtualDir> CachedVfsDirectory::GetSubdirectories() const { | ||
| 48 | std::vector<VirtualDir> out; | ||
| 49 | for (auto& [dir_name, dir] : dirs) { | ||
| 50 | out.push_back(dir); | ||
| 51 | } | ||
| 52 | return out; | ||
| 53 | } | ||
| 54 | |||
| 55 | std::string CachedVfsDirectory::GetName() const { | ||
| 56 | return name; | ||
| 57 | } | ||
| 58 | |||
| 59 | VirtualDir CachedVfsDirectory::GetParentDirectory() const { | ||
| 60 | return parent; | ||
| 61 | } | ||
| 62 | |||
| 63 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/vfs_cached.h b/src/core/file_sys/vfs_cached.h new file mode 100644 index 000000000..113acac12 --- /dev/null +++ b/src/core/file_sys/vfs_cached.h | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include <string_view> | ||
| 7 | #include <vector> | ||
| 8 | #include "core/file_sys/vfs.h" | ||
| 9 | |||
| 10 | namespace FileSys { | ||
| 11 | |||
| 12 | class CachedVfsDirectory : public ReadOnlyVfsDirectory { | ||
| 13 | public: | ||
| 14 | CachedVfsDirectory(VirtualDir& source_directory); | ||
| 15 | |||
| 16 | ~CachedVfsDirectory() override; | ||
| 17 | VirtualFile GetFile(std::string_view file_name) const override; | ||
| 18 | VirtualDir GetSubdirectory(std::string_view dir_name) const override; | ||
| 19 | std::vector<VirtualFile> GetFiles() const override; | ||
| 20 | std::vector<VirtualDir> GetSubdirectories() const override; | ||
| 21 | std::string GetName() const override; | ||
| 22 | VirtualDir GetParentDirectory() const override; | ||
| 23 | |||
| 24 | private: | ||
| 25 | std::string name; | ||
| 26 | VirtualDir parent; | ||
| 27 | std::map<std::string, VirtualDir, std::less<>> dirs; | ||
| 28 | std::map<std::string, VirtualFile, std::less<>> files; | ||
| 29 | }; | ||
| 30 | |||
| 31 | } // namespace FileSys | ||