From 3e5c3d0f166b432b1e56e6e3a286feb21281bc7a Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Wed, 19 Sep 2018 21:59:44 -0400 Subject: vfs_layered: Add LayeredVfsDirectory Reads multiple dirs through as if a waterfall. --- src/core/file_sys/vfs_layered.cpp | 128 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 src/core/file_sys/vfs_layered.cpp (limited to 'src/core/file_sys/vfs_layered.cpp') diff --git a/src/core/file_sys/vfs_layered.cpp b/src/core/file_sys/vfs_layered.cpp new file mode 100644 index 000000000..802f49384 --- /dev/null +++ b/src/core/file_sys/vfs_layered.cpp @@ -0,0 +1,128 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include +#include "core/file_sys/vfs_layered.h" + +namespace FileSys { + +VirtualDir LayerDirectories(std::vector dirs, std::string name) { + if (dirs.empty()) + return nullptr; + if (dirs.size() == 1) + return dirs[0]; + + return std::shared_ptr(new LayeredVfsDirectory(std::move(dirs), std::move(name))); +} + +LayeredVfsDirectory::LayeredVfsDirectory(std::vector dirs, std::string name) + : dirs(std::move(dirs)), name(std::move(name)) {} + +std::shared_ptr LayeredVfsDirectory::GetFileRelative(std::string_view path) const { + VirtualFile file; + for (const auto& layer : dirs) { + file = layer->GetFileRelative(path); + if (file != nullptr) + return file; + } + + return nullptr; +} + +std::shared_ptr LayeredVfsDirectory::GetDirectoryRelative( + std::string_view path) const { + std::vector out; + for (const auto& layer : dirs) { + const auto dir = layer->GetDirectoryRelative(path); + if (dir != nullptr) + out.push_back(dir); + } + + return LayerDirectories(out); +} + +std::shared_ptr LayeredVfsDirectory::GetFile(std::string_view name) const { + return GetFileRelative(name); +} + +std::shared_ptr LayeredVfsDirectory::GetSubdirectory(std::string_view name) const { + return GetDirectoryRelative(name); +} + +std::string LayeredVfsDirectory::GetFullPath() const { + return dirs[0]->GetFullPath(); +} + +std::vector> LayeredVfsDirectory::GetFiles() const { + std::vector out; + for (const auto& layer : dirs) { + for (const auto& file : layer->GetFiles()) { + if (std::find_if(out.begin(), out.end(), [&file](const VirtualFile& comp) { + return comp->GetName() == file->GetName(); + }) == out.end()) + out.push_back(file); + } + } + + return out; +} + +std::vector> LayeredVfsDirectory::GetSubdirectories() const { + std::vector names; + for (const auto& layer : dirs) { + for (const auto& sd : layer->GetSubdirectories()) { + if (std::find(names.begin(), names.end(), sd->GetName()) == names.end()) + names.push_back(sd->GetName()); + } + } + + std::vector out; + for (const auto& subdir : names) + out.push_back(GetSubdirectory(subdir)); + + return out; +} + +bool LayeredVfsDirectory::IsWritable() const { + return false; +} + +bool LayeredVfsDirectory::IsReadable() const { + return true; +} + +std::string LayeredVfsDirectory::GetName() const { + return name.empty() ? dirs[0]->GetName() : name; +} + +std::shared_ptr LayeredVfsDirectory::GetParentDirectory() const { + return dirs[0]->GetParentDirectory(); +} + +std::shared_ptr LayeredVfsDirectory::CreateSubdirectory(std::string_view name) { + return nullptr; +} + +std::shared_ptr LayeredVfsDirectory::CreateFile(std::string_view name) { + return nullptr; +} + +bool LayeredVfsDirectory::DeleteSubdirectory(std::string_view name) { + return false; +} + +bool LayeredVfsDirectory::DeleteFile(std::string_view name) { + return false; +} + +bool LayeredVfsDirectory::Rename(std::string_view name_) { + name = name_; + return true; +} + +bool LayeredVfsDirectory::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) { + return false; +} +} // namespace FileSys -- cgit v1.2.3