commit
125a0e5a07
@ -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
|
@ -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
|
Loading…
Reference in New Issue