Merge pull request #6269 from lioncash/file-shadow

file_sys: Resolve cases of variable shadowing
This commit is contained in:
bunnei 2021-05-02 15:12:07 -07:00 committed by GitHub
commit c17a59b58e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 132 additions and 114 deletions

View File

@ -176,26 +176,30 @@ u64 XCI::GetProgramTitleID() const {
u32 XCI::GetSystemUpdateVersion() { u32 XCI::GetSystemUpdateVersion() {
const auto update = GetPartition(XCIPartition::Update); const auto update = GetPartition(XCIPartition::Update);
if (update == nullptr) if (update == nullptr) {
return 0; return 0;
}
for (const auto& file : update->GetFiles()) { for (const auto& update_file : update->GetFiles()) {
NCA nca{file, nullptr, 0}; NCA nca{update_file, nullptr, 0};
if (nca.GetStatus() != Loader::ResultStatus::Success) if (nca.GetStatus() != Loader::ResultStatus::Success) {
continue; continue;
}
if (nca.GetType() == NCAContentType::Meta && nca.GetTitleId() == 0x0100000000000816) { if (nca.GetType() == NCAContentType::Meta && nca.GetTitleId() == 0x0100000000000816) {
const auto dir = nca.GetSubdirectories()[0]; const auto dir = nca.GetSubdirectories()[0];
const auto cnmt = dir->GetFile("SystemUpdate_0100000000000816.cnmt"); const auto cnmt = dir->GetFile("SystemUpdate_0100000000000816.cnmt");
if (cnmt == nullptr) if (cnmt == nullptr) {
continue; continue;
}
CNMT cnmt_data{cnmt}; CNMT cnmt_data{cnmt};
const auto metas = cnmt_data.GetMetaRecords(); const auto metas = cnmt_data.GetMetaRecords();
if (metas.empty()) if (metas.empty()) {
continue; continue;
}
return metas[0].title_version; return metas[0].title_version;
} }
@ -262,8 +266,8 @@ VirtualDir XCI::ConcatenatedPseudoDirectory() {
if (part == nullptr) if (part == nullptr)
continue; continue;
for (const auto& file : part->GetFiles()) for (const auto& part_file : part->GetFiles())
out->AddFile(file); out->AddFile(part_file);
} }
return out; return out;
@ -283,12 +287,12 @@ Loader::ResultStatus XCI::AddNCAFromPartition(XCIPartition part) {
return Loader::ResultStatus::ErrorXCIMissingPartition; return Loader::ResultStatus::ErrorXCIMissingPartition;
} }
for (const VirtualFile& file : partition->GetFiles()) { for (const VirtualFile& partition_file : partition->GetFiles()) {
if (file->GetExtension() != "nca") { if (partition_file->GetExtension() != "nca") {
continue; continue;
} }
auto nca = std::make_shared<NCA>(file, nullptr, 0); auto nca = std::make_shared<NCA>(partition_file, nullptr, 0);
if (nca->IsUpdate()) { if (nca->IsUpdate()) {
continue; continue;
} }

View File

@ -5,6 +5,7 @@
#include <algorithm> #include <algorithm>
#include <cstring> #include <cstring>
#include <optional> #include <optional>
#include <ranges>
#include <utility> #include <utility>
#include "common/logging/log.h" #include "common/logging/log.h"
@ -136,12 +137,11 @@ NCA::NCA(VirtualFile file_, VirtualFile bktr_base_romfs_, u64 bktr_base_ivfc_off
return; return;
} }
has_rights_id = std::any_of(header.rights_id.begin(), header.rights_id.end(), has_rights_id = std::ranges::any_of(header.rights_id, [](char c) { return c != '\0'; });
[](char c) { return c != '\0'; });
const std::vector<NCASectionHeader> sections = ReadSectionHeaders(); const std::vector<NCASectionHeader> sections = ReadSectionHeaders();
is_update = std::any_of(sections.begin(), sections.end(), [](const NCASectionHeader& header) { is_update = std::ranges::any_of(sections, [](const NCASectionHeader& nca_header) {
return header.raw.header.crypto_type == NCASectionCryptoType::BKTR; return nca_header.raw.header.crypto_type == NCASectionCryptoType::BKTR;
}); });
if (!ReadSections(sections, bktr_base_ivfc_offset)) { if (!ReadSections(sections, bktr_base_ivfc_offset)) {
@ -202,8 +202,9 @@ bool NCA::HandlePotentialHeaderDecryption() {
std::vector<NCASectionHeader> NCA::ReadSectionHeaders() const { std::vector<NCASectionHeader> NCA::ReadSectionHeaders() const {
const std::ptrdiff_t number_sections = const std::ptrdiff_t number_sections =
std::count_if(std::begin(header.section_tables), std::end(header.section_tables), std::ranges::count_if(header.section_tables, [](const NCASectionTableEntry& entry) {
[](NCASectionTableEntry entry) { return entry.media_offset > 0; }); return entry.media_offset > 0;
});
std::vector<NCASectionHeader> sections(number_sections); std::vector<NCASectionHeader> sections(number_sections);
const auto length_sections = SECTION_HEADER_SIZE * number_sections; const auto length_sections = SECTION_HEADER_SIZE * number_sections;
@ -312,11 +313,11 @@ bool NCA::ReadRomFSSection(const NCASectionHeader& section, const NCASectionTabl
} }
std::vector<RelocationBucket> relocation_buckets(relocation_buckets_raw.size()); std::vector<RelocationBucket> relocation_buckets(relocation_buckets_raw.size());
std::transform(relocation_buckets_raw.begin(), relocation_buckets_raw.end(), std::ranges::transform(relocation_buckets_raw, relocation_buckets.begin(),
relocation_buckets.begin(), &ConvertRelocationBucketRaw); &ConvertRelocationBucketRaw);
std::vector<SubsectionBucket> subsection_buckets(subsection_buckets_raw.size()); std::vector<SubsectionBucket> subsection_buckets(subsection_buckets_raw.size());
std::transform(subsection_buckets_raw.begin(), subsection_buckets_raw.end(), std::ranges::transform(subsection_buckets_raw, subsection_buckets.begin(),
subsection_buckets.begin(), &ConvertSubsectionBucketRaw); &ConvertSubsectionBucketRaw);
u32 ctr_low; u32 ctr_low;
std::memcpy(&ctr_low, section.raw.section_ctr.data(), sizeof(ctr_low)); std::memcpy(&ctr_low, section.raw.section_ctr.data(), sizeof(ctr_low));

View File

@ -126,16 +126,17 @@ static u64 romfs_get_hash_table_count(u64 num_entries) {
return count; return count;
} }
void RomFSBuildContext::VisitDirectory(VirtualDir root_romfs, VirtualDir ext, void RomFSBuildContext::VisitDirectory(VirtualDir root_romfs, VirtualDir ext_dir,
std::shared_ptr<RomFSBuildDirectoryContext> parent) { std::shared_ptr<RomFSBuildDirectoryContext> parent) {
std::vector<std::shared_ptr<RomFSBuildDirectoryContext>> child_dirs; std::vector<std::shared_ptr<RomFSBuildDirectoryContext>> child_dirs;
VirtualDir dir; VirtualDir dir;
if (parent->path_len == 0) if (parent->path_len == 0) {
dir = root_romfs; dir = root_romfs;
else } else {
dir = root_romfs->GetDirectoryRelative(parent->path); dir = root_romfs->GetDirectoryRelative(parent->path);
}
const auto entries = dir->GetEntries(); const auto entries = dir->GetEntries();
@ -147,8 +148,9 @@ void RomFSBuildContext::VisitDirectory(VirtualDir root_romfs, VirtualDir ext,
child->path_len = child->cur_path_ofs + static_cast<u32>(kv.first.size()); child->path_len = child->cur_path_ofs + static_cast<u32>(kv.first.size());
child->path = parent->path + "/" + kv.first; child->path = parent->path + "/" + kv.first;
if (ext != nullptr && ext->GetFileRelative(child->path + ".stub") != nullptr) if (ext_dir != nullptr && ext_dir->GetFileRelative(child->path + ".stub") != nullptr) {
continue; continue;
}
// Sanity check on path_len // Sanity check on path_len
ASSERT(child->path_len < FS_MAX_PATH); ASSERT(child->path_len < FS_MAX_PATH);
@ -163,21 +165,20 @@ void RomFSBuildContext::VisitDirectory(VirtualDir root_romfs, VirtualDir ext,
child->path_len = child->cur_path_ofs + static_cast<u32>(kv.first.size()); child->path_len = child->cur_path_ofs + static_cast<u32>(kv.first.size());
child->path = parent->path + "/" + kv.first; child->path = parent->path + "/" + kv.first;
if (ext != nullptr && ext->GetFileRelative(child->path + ".stub") != nullptr) if (ext_dir != nullptr && ext_dir->GetFileRelative(child->path + ".stub") != nullptr) {
continue; continue;
}
// Sanity check on path_len // Sanity check on path_len
ASSERT(child->path_len < FS_MAX_PATH); ASSERT(child->path_len < FS_MAX_PATH);
child->source = root_romfs->GetFileRelative(child->path); child->source = root_romfs->GetFileRelative(child->path);
if (ext != nullptr) { if (ext_dir != nullptr) {
const auto ips = ext->GetFileRelative(child->path + ".ips"); if (const auto ips = ext_dir->GetFileRelative(child->path + ".ips")) {
if (auto patched = PatchIPS(child->source, ips)) {
if (ips != nullptr) {
auto patched = PatchIPS(child->source, ips);
if (patched != nullptr)
child->source = std::move(patched); child->source = std::move(patched);
}
} }
} }
@ -188,7 +189,7 @@ void RomFSBuildContext::VisitDirectory(VirtualDir root_romfs, VirtualDir ext,
} }
for (auto& child : child_dirs) { for (auto& child : child_dirs) {
this->VisitDirectory(root_romfs, ext, child); this->VisitDirectory(root_romfs, ext_dir, child);
} }
} }

View File

@ -59,7 +59,7 @@ private:
u64 file_hash_table_size = 0; u64 file_hash_table_size = 0;
u64 file_partition_size = 0; u64 file_partition_size = 0;
void VisitDirectory(VirtualDir filesys, VirtualDir ext, void VisitDirectory(VirtualDir filesys, VirtualDir ext_dir,
std::shared_ptr<RomFSBuildDirectoryContext> parent); std::shared_ptr<RomFSBuildDirectoryContext> parent);
bool AddDirectory(std::shared_ptr<RomFSBuildDirectoryContext> parent_dir_ctx, bool AddDirectory(std::shared_ptr<RomFSBuildDirectoryContext> parent_dir_ctx,

View File

@ -83,11 +83,14 @@ BKTR::~BKTR() = default;
std::size_t BKTR::Read(u8* data, std::size_t length, std::size_t offset) const { std::size_t BKTR::Read(u8* data, std::size_t length, std::size_t offset) const {
// Read out of bounds. // Read out of bounds.
if (offset >= relocation.size) if (offset >= relocation.size) {
return 0; return 0;
const auto relocation = GetRelocationEntry(offset); }
const auto section_offset = offset - relocation.address_patch + relocation.address_source;
const auto bktr_read = relocation.from_patch; const auto relocation_entry = GetRelocationEntry(offset);
const auto section_offset =
offset - relocation_entry.address_patch + relocation_entry.address_source;
const auto bktr_read = relocation_entry.from_patch;
const auto next_relocation = GetNextRelocationEntry(offset); const auto next_relocation = GetNextRelocationEntry(offset);
@ -106,15 +109,16 @@ std::size_t BKTR::Read(u8* data, std::size_t length, std::size_t offset) const {
return bktr_romfs->Read(data, length, section_offset); return bktr_romfs->Read(data, length, section_offset);
} }
const auto subsection = GetSubsectionEntry(section_offset); const auto subsection_entry = GetSubsectionEntry(section_offset);
Core::Crypto::AESCipher<Core::Crypto::Key128> cipher(key, Core::Crypto::Mode::CTR); Core::Crypto::AESCipher<Core::Crypto::Key128> cipher(key, Core::Crypto::Mode::CTR);
// Calculate AES IV // Calculate AES IV
std::array<u8, 16> iv{}; std::array<u8, 16> iv{};
auto subsection_ctr = subsection.ctr; auto subsection_ctr = subsection_entry.ctr;
auto offset_iv = section_offset + base_offset; auto offset_iv = section_offset + base_offset;
for (std::size_t i = 0; i < section_ctr.size(); ++i) for (std::size_t i = 0; i < section_ctr.size(); ++i) {
iv[i] = section_ctr[0x8 - i - 1]; iv[i] = section_ctr[0x8 - i - 1];
}
offset_iv >>= 4; offset_iv >>= 4;
for (std::size_t i = 0; i < sizeof(u64); ++i) { for (std::size_t i = 0; i < sizeof(u64); ++i) {
iv[0xF - i] = static_cast<u8>(offset_iv & 0xFF); iv[0xF - i] = static_cast<u8>(offset_iv & 0xFF);

View File

@ -281,14 +281,14 @@ NcaID PlaceholderCache::Generate() {
return out; return out;
} }
VirtualFile RegisteredCache::OpenFileOrDirectoryConcat(const VirtualDir& dir, VirtualFile RegisteredCache::OpenFileOrDirectoryConcat(const VirtualDir& open_dir,
std::string_view path) const { std::string_view path) const {
const auto file = dir->GetFileRelative(path); const auto file = open_dir->GetFileRelative(path);
if (file != nullptr) { if (file != nullptr) {
return file; return file;
} }
const auto nca_dir = dir->GetDirectoryRelative(path); const auto nca_dir = open_dir->GetDirectoryRelative(path);
if (nca_dir == nullptr) { if (nca_dir == nullptr) {
return nullptr; return nullptr;
} }
@ -431,13 +431,15 @@ void RegisteredCache::ProcessFiles(const std::vector<NcaID>& ids) {
} }
void RegisteredCache::AccumulateYuzuMeta() { void RegisteredCache::AccumulateYuzuMeta() {
const auto dir = this->dir->GetSubdirectory("yuzu_meta"); const auto meta_dir = dir->GetSubdirectory("yuzu_meta");
if (dir == nullptr) if (meta_dir == nullptr) {
return; return;
}
for (const auto& file : dir->GetFiles()) { for (const auto& file : meta_dir->GetFiles()) {
if (file->GetExtension() != "cnmt") if (file->GetExtension() != "cnmt") {
continue; continue;
}
CNMT cnmt(file); CNMT cnmt(file);
yuzu_meta.insert_or_assign(cnmt.GetTitleID(), std::move(cnmt)); yuzu_meta.insert_or_assign(cnmt.GetTitleID(), std::move(cnmt));
@ -445,8 +447,10 @@ void RegisteredCache::AccumulateYuzuMeta() {
} }
void RegisteredCache::Refresh() { void RegisteredCache::Refresh() {
if (dir == nullptr) if (dir == nullptr) {
return; return;
}
const auto ids = AccumulateFiles(); const auto ids = AccumulateFiles();
ProcessFiles(ids); ProcessFiles(ids);
AccumulateYuzuMeta(); AccumulateYuzuMeta();
@ -566,7 +570,7 @@ InstallResult RegisteredCache::InstallEntry(const NSP& nsp, bool overwrite_if_ex
} }
const auto meta_id_raw = (*meta_iter)->GetName().substr(0, 32); const auto meta_id_raw = (*meta_iter)->GetName().substr(0, 32);
const auto meta_id = Common::HexStringToArray<16>(meta_id_raw); const auto meta_id_data = Common::HexStringToArray<16>(meta_id_raw);
if ((*meta_iter)->GetSubdirectories().empty()) { if ((*meta_iter)->GetSubdirectories().empty()) {
LOG_ERROR(Loader, LOG_ERROR(Loader,
@ -591,7 +595,7 @@ InstallResult RegisteredCache::InstallEntry(const NSP& nsp, bool overwrite_if_ex
const auto result = RemoveExistingEntry(title_id); const auto result = RemoveExistingEntry(title_id);
// Install Metadata File // Install Metadata File
const auto res = RawInstallNCA(**meta_iter, copy, overwrite_if_exists, meta_id); const auto res = RawInstallNCA(**meta_iter, copy, overwrite_if_exists, meta_id_data);
if (res != InstallResult::Success) { if (res != InstallResult::Success) {
return res; return res;
} }
@ -741,15 +745,15 @@ InstallResult RegisteredCache::RawInstallNCA(const NCA& nca, const VfsCopyFuncti
bool RegisteredCache::RawInstallYuzuMeta(const CNMT& cnmt) { bool RegisteredCache::RawInstallYuzuMeta(const CNMT& cnmt) {
// Reasoning behind this method can be found in the comment for InstallEntry, NCA overload. // Reasoning behind this method can be found in the comment for InstallEntry, NCA overload.
const auto dir = this->dir->CreateDirectoryRelative("yuzu_meta"); const auto meta_dir = dir->CreateDirectoryRelative("yuzu_meta");
const auto filename = GetCNMTName(cnmt.GetType(), cnmt.GetTitleID()); const auto filename = GetCNMTName(cnmt.GetType(), cnmt.GetTitleID());
if (dir->GetFile(filename) == nullptr) { if (meta_dir->GetFile(filename) == nullptr) {
auto out = dir->CreateFile(filename); auto out = meta_dir->CreateFile(filename);
const auto buffer = cnmt.Serialize(); const auto buffer = cnmt.Serialize();
out->Resize(buffer.size()); out->Resize(buffer.size());
out->WriteBytes(buffer); out->WriteBytes(buffer);
} else { } else {
auto out = dir->GetFile(filename); auto out = meta_dir->GetFile(filename);
CNMT old_cnmt(out); CNMT old_cnmt(out);
// Returns true on change // Returns true on change
if (old_cnmt.UnionRecords(cnmt)) { if (old_cnmt.UnionRecords(cnmt)) {

View File

@ -182,7 +182,7 @@ private:
void AccumulateYuzuMeta(); void AccumulateYuzuMeta();
std::optional<NcaID> GetNcaIDFromMetadata(u64 title_id, ContentRecordType type) const; std::optional<NcaID> GetNcaIDFromMetadata(u64 title_id, ContentRecordType type) const;
VirtualFile GetFileAtID(NcaID id) const; VirtualFile GetFileAtID(NcaID id) const;
VirtualFile OpenFileOrDirectoryConcat(const VirtualDir& dir, std::string_view path) const; VirtualFile OpenFileOrDirectoryConcat(const VirtualDir& open_dir, std::string_view path) const;
InstallResult RawInstallNCA(const NCA& nca, const VfsCopyFunction& copy, InstallResult RawInstallNCA(const NCA& nca, const VfsCopyFunction& copy,
bool overwrite_if_exists, std::optional<NcaID> override_id = {}); bool overwrite_if_exists, std::optional<NcaID> override_id = {});
bool RawInstallYuzuMeta(const CNMT& cnmt); bool RawInstallYuzuMeta(const CNMT& cnmt);

View File

@ -33,8 +33,8 @@ RomFSFactory::RomFSFactory(Loader::AppLoader& app_loader, ContentProvider& provi
RomFSFactory::~RomFSFactory() = default; RomFSFactory::~RomFSFactory() = default;
void RomFSFactory::SetPackedUpdate(VirtualFile update_raw) { void RomFSFactory::SetPackedUpdate(VirtualFile update_raw_file) {
this->update_raw = std::move(update_raw); update_raw = std::move(update_raw_file);
} }
ResultVal<VirtualFile> RomFSFactory::OpenCurrentProcess(u64 current_process_title_id) const { ResultVal<VirtualFile> RomFSFactory::OpenCurrentProcess(u64 current_process_title_id) const {

View File

@ -40,7 +40,7 @@ public:
Service::FileSystem::FileSystemController& controller); Service::FileSystem::FileSystemController& controller);
~RomFSFactory(); ~RomFSFactory();
void SetPackedUpdate(VirtualFile update_raw); void SetPackedUpdate(VirtualFile update_raw_file);
[[nodiscard]] ResultVal<VirtualFile> OpenCurrentProcess(u64 current_process_title_id) const; [[nodiscard]] ResultVal<VirtualFile> OpenCurrentProcess(u64 current_process_title_id) const;
[[nodiscard]] ResultVal<VirtualFile> OpenPatchedRomFS(u64 title_id, [[nodiscard]] ResultVal<VirtualFile> OpenPatchedRomFS(u64 title_id,
ContentRecordType type) const; ContentRecordType type) const;

View File

@ -170,26 +170,30 @@ std::string SaveDataFactory::GetFullPath(Core::System& system, SaveDataSpaceId s
SaveDataSize SaveDataFactory::ReadSaveDataSize(SaveDataType type, u64 title_id, SaveDataSize SaveDataFactory::ReadSaveDataSize(SaveDataType type, u64 title_id,
u128 user_id) const { u128 user_id) const {
const auto path = GetFullPath(system, SaveDataSpaceId::NandUser, type, title_id, user_id, 0); const auto path = GetFullPath(system, SaveDataSpaceId::NandUser, type, title_id, user_id, 0);
const auto dir = GetOrCreateDirectoryRelative(this->dir, path); const auto relative_dir = GetOrCreateDirectoryRelative(dir, path);
const auto size_file = dir->GetFile(SAVE_DATA_SIZE_FILENAME); const auto size_file = relative_dir->GetFile(SAVE_DATA_SIZE_FILENAME);
if (size_file == nullptr || size_file->GetSize() < sizeof(SaveDataSize)) if (size_file == nullptr || size_file->GetSize() < sizeof(SaveDataSize)) {
return {0, 0}; return {0, 0};
}
SaveDataSize out; SaveDataSize out;
if (size_file->ReadObject(&out) != sizeof(SaveDataSize)) if (size_file->ReadObject(&out) != sizeof(SaveDataSize)) {
return {0, 0}; return {0, 0};
}
return out; return out;
} }
void SaveDataFactory::WriteSaveDataSize(SaveDataType type, u64 title_id, u128 user_id, void SaveDataFactory::WriteSaveDataSize(SaveDataType type, u64 title_id, u128 user_id,
SaveDataSize new_value) const { SaveDataSize new_value) const {
const auto path = GetFullPath(system, SaveDataSpaceId::NandUser, type, title_id, user_id, 0); const auto path = GetFullPath(system, SaveDataSpaceId::NandUser, type, title_id, user_id, 0);
const auto dir = GetOrCreateDirectoryRelative(this->dir, path); const auto relative_dir = GetOrCreateDirectoryRelative(dir, path);
const auto size_file = dir->CreateFile(SAVE_DATA_SIZE_FILENAME); const auto size_file = relative_dir->CreateFile(SAVE_DATA_SIZE_FILENAME);
if (size_file == nullptr) if (size_file == nullptr) {
return; return;
}
size_file->Resize(sizeof(SaveDataSize)); size_file->Resize(sizeof(SaveDataSize));
size_file->WriteObject(new_value); size_file->WriteObject(new_value);

View File

@ -232,15 +232,15 @@ void NSP::SetTicketKeys(const std::vector<VirtualFile>& files) {
void NSP::InitializeExeFSAndRomFS(const std::vector<VirtualFile>& files) { void NSP::InitializeExeFSAndRomFS(const std::vector<VirtualFile>& files) {
exefs = pfs; exefs = pfs;
const auto romfs_iter = std::find_if(files.begin(), files.end(), [](const VirtualFile& file) { const auto iter = std::find_if(files.begin(), files.end(), [](const VirtualFile& entry) {
return file->GetName().rfind(".romfs") != std::string::npos; return entry->GetName().rfind(".romfs") != std::string::npos;
}); });
if (romfs_iter == files.end()) { if (iter == files.end()) {
return; return;
} }
romfs = *romfs_iter; romfs = *iter;
} }
void NSP::ReadNCAs(const std::vector<VirtualFile>& files) { void NSP::ReadNCAs(const std::vector<VirtualFile>& files) {

View File

@ -136,7 +136,7 @@ std::size_t ConcatenatedVfsFile::Write(const u8* data, std::size_t length, std::
return 0; return 0;
} }
bool ConcatenatedVfsFile::Rename(std::string_view name) { bool ConcatenatedVfsFile::Rename(std::string_view new_name) {
return false; return false;
} }

View File

@ -36,7 +36,7 @@ public:
bool IsReadable() const override; bool IsReadable() const override;
std::size_t Read(u8* data, std::size_t length, std::size_t offset) const override; std::size_t Read(u8* data, std::size_t length, std::size_t offset) const override;
std::size_t Write(const u8* data, std::size_t length, std::size_t offset) override; std::size_t Write(const u8* data, std::size_t length, std::size_t offset) override;
bool Rename(std::string_view name) override; bool Rename(std::string_view new_name) override;
private: private:
// Maps starting offset to file -- more efficient. // Maps starting offset to file -- more efficient.

View File

@ -45,12 +45,12 @@ VirtualDir LayeredVfsDirectory::GetDirectoryRelative(std::string_view path) cons
return MakeLayeredDirectory(std::move(out)); return MakeLayeredDirectory(std::move(out));
} }
VirtualFile LayeredVfsDirectory::GetFile(std::string_view name) const { VirtualFile LayeredVfsDirectory::GetFile(std::string_view file_name) const {
return GetFileRelative(name); return GetFileRelative(file_name);
} }
VirtualDir LayeredVfsDirectory::GetSubdirectory(std::string_view name) const { VirtualDir LayeredVfsDirectory::GetSubdirectory(std::string_view subdir_name) const {
return GetDirectoryRelative(name); return GetDirectoryRelative(subdir_name);
} }
std::string LayeredVfsDirectory::GetFullPath() const { std::string LayeredVfsDirectory::GetFullPath() const {
@ -105,24 +105,24 @@ VirtualDir LayeredVfsDirectory::GetParentDirectory() const {
return dirs[0]->GetParentDirectory(); return dirs[0]->GetParentDirectory();
} }
VirtualDir LayeredVfsDirectory::CreateSubdirectory(std::string_view name) { VirtualDir LayeredVfsDirectory::CreateSubdirectory(std::string_view subdir_name) {
return nullptr; return nullptr;
} }
VirtualFile LayeredVfsDirectory::CreateFile(std::string_view name) { VirtualFile LayeredVfsDirectory::CreateFile(std::string_view file_name) {
return nullptr; return nullptr;
} }
bool LayeredVfsDirectory::DeleteSubdirectory(std::string_view name) { bool LayeredVfsDirectory::DeleteSubdirectory(std::string_view subdir_name) {
return false; return false;
} }
bool LayeredVfsDirectory::DeleteFile(std::string_view name) { bool LayeredVfsDirectory::DeleteFile(std::string_view file_name) {
return false; return false;
} }
bool LayeredVfsDirectory::Rename(std::string_view name_) { bool LayeredVfsDirectory::Rename(std::string_view new_name) {
name = name_; name = new_name;
return true; return true;
} }

View File

@ -23,8 +23,8 @@ public:
VirtualFile GetFileRelative(std::string_view path) const override; VirtualFile GetFileRelative(std::string_view path) const override;
VirtualDir GetDirectoryRelative(std::string_view path) const override; VirtualDir GetDirectoryRelative(std::string_view path) const override;
VirtualFile GetFile(std::string_view name) const override; VirtualFile GetFile(std::string_view file_name) const override;
VirtualDir GetSubdirectory(std::string_view name) const override; VirtualDir GetSubdirectory(std::string_view subdir_name) const override;
std::string GetFullPath() const override; std::string GetFullPath() const override;
std::vector<VirtualFile> GetFiles() const override; std::vector<VirtualFile> GetFiles() const override;
@ -33,11 +33,11 @@ public:
bool IsReadable() const override; bool IsReadable() const override;
std::string GetName() const override; std::string GetName() const override;
VirtualDir GetParentDirectory() const override; VirtualDir GetParentDirectory() const override;
VirtualDir CreateSubdirectory(std::string_view name) override; VirtualDir CreateSubdirectory(std::string_view subdir_name) override;
VirtualFile CreateFile(std::string_view name) override; VirtualFile CreateFile(std::string_view file_name) override;
bool DeleteSubdirectory(std::string_view name) override; bool DeleteSubdirectory(std::string_view subdir_name) override;
bool DeleteFile(std::string_view name) override; bool DeleteFile(std::string_view file_name) override;
bool Rename(std::string_view name) override; bool Rename(std::string_view new_name) override;
private: private:
std::vector<VirtualDir> dirs; std::vector<VirtualDir> dirs;

View File

@ -84,8 +84,8 @@ std::size_t OffsetVfsFile::WriteBytes(const std::vector<u8>& data, std::size_t r
return file->Write(data.data(), TrimToFit(data.size(), r_offset), offset + r_offset); return file->Write(data.data(), TrimToFit(data.size(), r_offset), offset + r_offset);
} }
bool OffsetVfsFile::Rename(std::string_view name) { bool OffsetVfsFile::Rename(std::string_view new_name) {
return file->Rename(name); return file->Rename(new_name);
} }
std::size_t OffsetVfsFile::GetOffset() const { std::size_t OffsetVfsFile::GetOffset() const {

View File

@ -35,7 +35,7 @@ public:
bool WriteByte(u8 data, std::size_t offset) override; bool WriteByte(u8 data, std::size_t offset) override;
std::size_t WriteBytes(const std::vector<u8>& data, std::size_t offset) override; std::size_t WriteBytes(const std::vector<u8>& data, std::size_t offset) override;
bool Rename(std::string_view name) override; bool Rename(std::string_view new_name) override;
std::size_t GetOffset() const; std::size_t GetOffset() const;

View File

@ -358,16 +358,16 @@ RealVfsDirectory::RealVfsDirectory(RealVfsFilesystem& base_, const std::string&
RealVfsDirectory::~RealVfsDirectory() = default; RealVfsDirectory::~RealVfsDirectory() = default;
VirtualFile RealVfsDirectory::GetFileRelative(std::string_view path) const { VirtualFile RealVfsDirectory::GetFileRelative(std::string_view relative_path) const {
const auto full_path = FS::SanitizePath(this->path + DIR_SEP + std::string(path)); const auto full_path = FS::SanitizePath(path + DIR_SEP + std::string(relative_path));
if (!FS::Exists(full_path) || FS::IsDirectory(full_path)) { if (!FS::Exists(full_path) || FS::IsDirectory(full_path)) {
return nullptr; return nullptr;
} }
return base.OpenFile(full_path, perms); return base.OpenFile(full_path, perms);
} }
VirtualDir RealVfsDirectory::GetDirectoryRelative(std::string_view path) const { VirtualDir RealVfsDirectory::GetDirectoryRelative(std::string_view relative_path) const {
const auto full_path = FS::SanitizePath(this->path + DIR_SEP + std::string(path)); const auto full_path = FS::SanitizePath(path + DIR_SEP + std::string(relative_path));
if (!FS::Exists(full_path) || !FS::IsDirectory(full_path)) { if (!FS::Exists(full_path) || !FS::IsDirectory(full_path)) {
return nullptr; return nullptr;
} }
@ -382,13 +382,13 @@ VirtualDir RealVfsDirectory::GetSubdirectory(std::string_view name) const {
return GetDirectoryRelative(name); return GetDirectoryRelative(name);
} }
VirtualFile RealVfsDirectory::CreateFileRelative(std::string_view path) { VirtualFile RealVfsDirectory::CreateFileRelative(std::string_view relative_path) {
const auto full_path = FS::SanitizePath(this->path + DIR_SEP + std::string(path)); const auto full_path = FS::SanitizePath(path + DIR_SEP + std::string(relative_path));
return base.CreateFile(full_path, perms); return base.CreateFile(full_path, perms);
} }
VirtualDir RealVfsDirectory::CreateDirectoryRelative(std::string_view path) { VirtualDir RealVfsDirectory::CreateDirectoryRelative(std::string_view relative_path) {
const auto full_path = FS::SanitizePath(this->path + DIR_SEP + std::string(path)); const auto full_path = FS::SanitizePath(path + DIR_SEP + std::string(relative_path));
return base.CreateDirectory(full_path, perms); return base.CreateDirectory(full_path, perms);
} }

View File

@ -79,12 +79,12 @@ class RealVfsDirectory : public VfsDirectory {
public: public:
~RealVfsDirectory() override; ~RealVfsDirectory() override;
VirtualFile GetFileRelative(std::string_view path) const override; VirtualFile GetFileRelative(std::string_view relative_path) const override;
VirtualDir GetDirectoryRelative(std::string_view path) const override; VirtualDir GetDirectoryRelative(std::string_view relative_path) const override;
VirtualFile GetFile(std::string_view name) const override; VirtualFile GetFile(std::string_view name) const override;
VirtualDir GetSubdirectory(std::string_view name) const override; VirtualDir GetSubdirectory(std::string_view name) const override;
VirtualFile CreateFileRelative(std::string_view path) override; VirtualFile CreateFileRelative(std::string_view relative_path) override;
VirtualDir CreateDirectoryRelative(std::string_view path) override; VirtualDir CreateDirectoryRelative(std::string_view relative_path) override;
bool DeleteSubdirectoryRecursive(std::string_view name) override; bool DeleteSubdirectoryRecursive(std::string_view name) override;
std::vector<VirtualFile> GetFiles() const override; std::vector<VirtualFile> GetFiles() const override;
std::vector<VirtualDir> GetSubdirectories() const override; std::vector<VirtualDir> GetSubdirectories() const override;

View File

@ -103,12 +103,12 @@ static bool FindAndRemoveVectorElement(std::vector<T>& vec, std::string_view nam
return true; return true;
} }
bool VectorVfsDirectory::DeleteSubdirectory(std::string_view name) { bool VectorVfsDirectory::DeleteSubdirectory(std::string_view subdir_name) {
return FindAndRemoveVectorElement(dirs, name); return FindAndRemoveVectorElement(dirs, subdir_name);
} }
bool VectorVfsDirectory::DeleteFile(std::string_view name) { bool VectorVfsDirectory::DeleteFile(std::string_view file_name) {
return FindAndRemoveVectorElement(files, name); return FindAndRemoveVectorElement(files, file_name);
} }
bool VectorVfsDirectory::Rename(std::string_view name_) { bool VectorVfsDirectory::Rename(std::string_view name_) {
@ -116,11 +116,11 @@ bool VectorVfsDirectory::Rename(std::string_view name_) {
return true; return true;
} }
VirtualDir VectorVfsDirectory::CreateSubdirectory(std::string_view name) { VirtualDir VectorVfsDirectory::CreateSubdirectory(std::string_view subdir_name) {
return nullptr; return nullptr;
} }
VirtualFile VectorVfsDirectory::CreateFile(std::string_view name) { VirtualFile VectorVfsDirectory::CreateFile(std::string_view file_name) {
return nullptr; return nullptr;
} }

View File

@ -112,11 +112,11 @@ public:
bool IsReadable() const override; bool IsReadable() const override;
std::string GetName() const override; std::string GetName() const override;
VirtualDir GetParentDirectory() const override; VirtualDir GetParentDirectory() const override;
bool DeleteSubdirectory(std::string_view name) override; bool DeleteSubdirectory(std::string_view subdir_name) override;
bool DeleteFile(std::string_view name) override; bool DeleteFile(std::string_view file_name) override;
bool Rename(std::string_view name) override; bool Rename(std::string_view name) override;
VirtualDir CreateSubdirectory(std::string_view name) override; VirtualDir CreateSubdirectory(std::string_view subdir_name) override;
VirtualFile CreateFile(std::string_view name) override; VirtualFile CreateFile(std::string_view file_name) override;
virtual void AddFile(VirtualFile file); virtual void AddFile(VirtualFile file);
virtual void AddDirectory(VirtualDir dir); virtual void AddDirectory(VirtualDir dir);