mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2025-07-21 13:25:45 +00:00
vfs: add vfs_cached for romfs build
This commit is contained in:
parent
0d2b417484
commit
3fd364d3bb
4 changed files with 99 additions and 2 deletions
63
src/core/file_sys/vfs_cached.cpp
Normal file
63
src/core/file_sys/vfs_cached.cpp
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue