From 77c684c1140f6bf3fb7d4560d06d2efb1a2ee5e2 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Fri, 6 Jul 2018 10:51:32 -0400 Subject: Virtual Filesystem (#597) * Add VfsFile and VfsDirectory classes * Finish abstract Vfs classes * Implement RealVfsFile (computer fs backend) * Finish RealVfsFile and RealVfsDirectory * Finished OffsetVfsFile * More changes * Fix import paths * Major refactor * Remove double const * Use experimental/filesystem or filesystem depending on compiler * Port partition_filesystem * More changes * More Overhaul * FSP_SRV fixes * Fixes and testing * Try to get filesystem to compile * Filesystem on linux * Remove std::filesystem and document/test * Compile fixes * Missing include * Bug fixes * Fixes * Rename v_file and v_dir * clang-format fix * Rename NGLOG_* to LOG_* * Most review changes * Fix TODO * Guess 'main' to be Directory by filename --- src/core/file_sys/program_metadata.cpp | 43 +++++++++++++--------------------- 1 file changed, 16 insertions(+), 27 deletions(-) (limited to 'src/core/file_sys/program_metadata.cpp') diff --git a/src/core/file_sys/program_metadata.cpp b/src/core/file_sys/program_metadata.cpp index 226811115..63d4b6e4f 100644 --- a/src/core/file_sys/program_metadata.cpp +++ b/src/core/file_sys/program_metadata.cpp @@ -9,40 +9,29 @@ namespace FileSys { -Loader::ResultStatus ProgramMetadata::Load(const std::string& file_path) { - FileUtil::IOFile file(file_path, "rb"); - if (!file.IsOpen()) +Loader::ResultStatus ProgramMetadata::Load(VirtualFile file) { + size_t total_size = static_cast(file->GetSize()); + if (total_size < sizeof(Header)) return Loader::ResultStatus::Error; - std::vector file_data(file.GetSize()); - - if (!file.ReadBytes(file_data.data(), file_data.size())) + // TODO(DarkLordZach): Use ReadObject when Header/AcidHeader becomes trivially copyable. + std::vector npdm_header_data = file->ReadBytes(sizeof(Header)); + if (sizeof(Header) != npdm_header_data.size()) return Loader::ResultStatus::Error; + std::memcpy(&npdm_header, npdm_header_data.data(), sizeof(Header)); - Loader::ResultStatus result = Load(file_data); - if (result != Loader::ResultStatus::Success) - LOG_ERROR(Service_FS, "Failed to load NPDM from file {}!", file_path); - - return result; -} - -Loader::ResultStatus ProgramMetadata::Load(const std::vector file_data, size_t offset) { - size_t total_size = static_cast(file_data.size() - offset); - if (total_size < sizeof(Header)) + std::vector acid_header_data = file->ReadBytes(sizeof(AcidHeader), npdm_header.acid_offset); + if (sizeof(AcidHeader) != acid_header_data.size()) return Loader::ResultStatus::Error; + std::memcpy(&acid_header, acid_header_data.data(), sizeof(AcidHeader)); - size_t header_offset = offset; - memcpy(&npdm_header, &file_data[offset], sizeof(Header)); - - size_t aci_offset = header_offset + npdm_header.aci_offset; - size_t acid_offset = header_offset + npdm_header.acid_offset; - memcpy(&aci_header, &file_data[aci_offset], sizeof(AciHeader)); - memcpy(&acid_header, &file_data[acid_offset], sizeof(AcidHeader)); + if (sizeof(AciHeader) != file->ReadObject(&aci_header, npdm_header.aci_offset)) + return Loader::ResultStatus::Error; - size_t fac_offset = acid_offset + acid_header.fac_offset; - size_t fah_offset = aci_offset + aci_header.fah_offset; - memcpy(&acid_file_access, &file_data[fac_offset], sizeof(FileAccessControl)); - memcpy(&aci_file_access, &file_data[fah_offset], sizeof(FileAccessHeader)); + if (sizeof(FileAccessControl) != file->ReadObject(&acid_file_access, acid_header.fac_offset)) + return Loader::ResultStatus::Error; + if (sizeof(FileAccessHeader) != file->ReadObject(&aci_file_access, aci_header.fah_offset)) + return Loader::ResultStatus::Error; return Loader::ResultStatus::Success; } -- cgit v1.2.3