summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorLiam <byteslice@airmail.cc>2023-06-03 14:42:52 +0200
committerLiam <byteslice@airmail.cc>2023-06-03 14:50:54 +0200
commit790f91fcc57458ef63db7bf1baccc9d9ca2d57ce (patch)
treeb5612c33c77edf6a98ee4eea7f663233d8649ca1 /src/core
parentMerge pull request #10575 from bm01/issue-template (diff)
downloadyuzu-790f91fcc57458ef63db7bf1baccc9d9ca2d57ce.tar
yuzu-790f91fcc57458ef63db7bf1baccc9d9ca2d57ce.tar.gz
yuzu-790f91fcc57458ef63db7bf1baccc9d9ca2d57ce.tar.bz2
yuzu-790f91fcc57458ef63db7bf1baccc9d9ca2d57ce.tar.lz
yuzu-790f91fcc57458ef63db7bf1baccc9d9ca2d57ce.tar.xz
yuzu-790f91fcc57458ef63db7bf1baccc9d9ca2d57ce.tar.zst
yuzu-790f91fcc57458ef63db7bf1baccc9d9ca2d57ce.zip
Diffstat (limited to 'src/core')
-rw-r--r--src/core/CMakeLists.txt2
-rw-r--r--src/core/file_sys/patch_manager.cpp5
-rw-r--r--src/core/file_sys/vfs_cached.cpp63
-rw-r--r--src/core/file_sys/vfs_cached.h31
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
file_sys/system_archive/time_zone_binary.h
file_sys/vfs.cpp
file_sys/vfs.h
+ file_sys/vfs_cached.cpp
+ file_sys/vfs_cached.h
file_sys/vfs_concat.cpp
file_sys/vfs_concat.h
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 @@
#include "core/file_sys/patch_manager.h"
#include "core/file_sys/registered_cache.h"
#include "core/file_sys/romfs.h"
+#include "core/file_sys/vfs_cached.h"
#include "core/file_sys/vfs_layered.h"
#include "core/file_sys/vfs_vector.h"
#include "core/hle/service/filesystem/filesystem.h"
@@ -380,11 +381,11 @@ static void ApplyLayeredFS(VirtualFile& romfs, u64 title_id, ContentRecordType t
auto romfs_dir = FindSubdirectoryCaseless(subdir, "romfs");
if (romfs_dir != nullptr)
- layers.push_back(std::move(romfs_dir));
+ layers.push_back(std::make_shared<CachedVfsDirectory>(romfs_dir));
auto ext_dir = FindSubdirectoryCaseless(subdir, "romfs_ext");
if (ext_dir != nullptr)
- layers_ext.push_back(std::move(ext_dir));
+ layers_ext.push_back(std::make_shared<CachedVfsDirectory>(ext_dir));
}
// 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 @@
+// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "core/file_sys/vfs_cached.h"
+#include "core/file_sys/vfs_types.h"
+
+namespace FileSys {
+
+CachedVfsDirectory::CachedVfsDirectory(VirtualDir& source_dir)
+ : name(source_dir->GetName()), parent(source_dir->GetParentDirectory()) {
+ for (auto& dir : source_dir->GetSubdirectories()) {
+ dirs.emplace(dir->GetName(), std::make_shared<CachedVfsDirectory>(dir));
+ }
+ for (auto& file : source_dir->GetFiles()) {
+ files.emplace(file->GetName(), file);
+ }
+}
+
+CachedVfsDirectory::~CachedVfsDirectory() = default;
+
+VirtualFile CachedVfsDirectory::GetFile(std::string_view file_name) const {
+ auto it = files.find(file_name);
+ if (it != files.end()) {
+ return it->second;
+ }
+
+ return nullptr;
+}
+
+VirtualDir CachedVfsDirectory::GetSubdirectory(std::string_view dir_name) const {
+ auto it = dirs.find(dir_name);
+ if (it != dirs.end()) {
+ return it->second;
+ }
+
+ return nullptr;
+}
+
+std::vector<VirtualFile> CachedVfsDirectory::GetFiles() const {
+ std::vector<VirtualFile> out;
+ for (auto& [file_name, file] : files) {
+ out.push_back(file);
+ }
+ return out;
+}
+
+std::vector<VirtualDir> CachedVfsDirectory::GetSubdirectories() const {
+ std::vector<VirtualDir> out;
+ for (auto& [dir_name, dir] : dirs) {
+ out.push_back(dir);
+ }
+ return out;
+}
+
+std::string CachedVfsDirectory::GetName() const {
+ return name;
+}
+
+VirtualDir CachedVfsDirectory::GetParentDirectory() const {
+ return parent;
+}
+
+} // 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 @@
+// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#include <string_view>
+#include <vector>
+#include "core/file_sys/vfs.h"
+
+namespace FileSys {
+
+class CachedVfsDirectory : public ReadOnlyVfsDirectory {
+public:
+ CachedVfsDirectory(VirtualDir& source_directory);
+
+ ~CachedVfsDirectory() override;
+ VirtualFile GetFile(std::string_view file_name) const override;
+ VirtualDir GetSubdirectory(std::string_view dir_name) const override;
+ std::vector<VirtualFile> GetFiles() const override;
+ std::vector<VirtualDir> GetSubdirectories() const override;
+ std::string GetName() const override;
+ VirtualDir GetParentDirectory() const override;
+
+private:
+ std::string name;
+ VirtualDir parent;
+ std::map<std::string, VirtualDir, std::less<>> dirs;
+ std::map<std::string, VirtualFile, std::less<>> files;
+};
+
+} // namespace FileSys