diff options
Diffstat (limited to 'src/core/file_sys/card_image.cpp')
-rw-r--r-- | src/core/file_sys/card_image.cpp | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/src/core/file_sys/card_image.cpp b/src/core/file_sys/card_image.cpp index d61a2ebe1..edfc1bbd4 100644 --- a/src/core/file_sys/card_image.cpp +++ b/src/core/file_sys/card_image.cpp @@ -9,7 +9,10 @@ #include "common/logging/log.h" #include "core/file_sys/card_image.h" +#include "core/file_sys/content_archive.h" +#include "core/file_sys/nca_metadata.h" #include "core/file_sys/partition_filesystem.h" +#include "core/file_sys/submission_package.h" #include "core/file_sys/vfs_offset.h" #include "core/loader/loader.h" @@ -38,20 +41,25 @@ XCI::XCI(VirtualFile file_) : file(std::move(file_)), partitions(0x4) { for (XCIPartition partition : {XCIPartition::Update, XCIPartition::Normal, XCIPartition::Secure, XCIPartition::Logo}) { - auto raw = main_hfs.GetFile(partition_names[static_cast<size_t>(partition)]); + auto raw = main_hfs.GetFile(partition_names[static_cast<std::size_t>(partition)]); if (raw != nullptr) - partitions[static_cast<size_t>(partition)] = std::make_shared<PartitionFilesystem>(raw); + partitions[static_cast<std::size_t>(partition)] = + std::make_shared<PartitionFilesystem>(raw); } - program_nca_status = Loader::ResultStatus::ErrorXCIMissingProgramNCA; + secure_partition = std::make_shared<NSP>( + main_hfs.GetFile(partition_names[static_cast<std::size_t>(XCIPartition::Secure)])); - auto result = AddNCAFromPartition(XCIPartition::Secure); - if (result != Loader::ResultStatus::Success) { - status = result; - return; - } + const auto secure_ncas = secure_partition->GetNCAsCollapsed(); + std::copy(secure_ncas.begin(), secure_ncas.end(), std::back_inserter(ncas)); - result = AddNCAFromPartition(XCIPartition::Update); + program = + secure_partition->GetNCA(secure_partition->GetProgramTitleID(), ContentRecordType::Program); + program_nca_status = secure_partition->GetProgramStatus(secure_partition->GetProgramTitleID()); + if (program_nca_status == Loader::ResultStatus::ErrorNSPMissingProgramNCA) + program_nca_status = Loader::ResultStatus::ErrorXCIMissingProgramNCA; + + auto result = AddNCAFromPartition(XCIPartition::Update); if (result != Loader::ResultStatus::Success) { status = result; return; @@ -74,6 +82,8 @@ XCI::XCI(VirtualFile file_) : file(std::move(file_)), partitions(0x4) { status = Loader::ResultStatus::Success; } +XCI::~XCI() = default; + Loader::ResultStatus XCI::GetStatus() const { return status; } @@ -83,7 +93,11 @@ Loader::ResultStatus XCI::GetProgramNCAStatus() const { } VirtualDir XCI::GetPartition(XCIPartition partition) const { - return partitions[static_cast<size_t>(partition)]; + return partitions[static_cast<std::size_t>(partition)]; +} + +std::shared_ptr<NSP> XCI::GetSecurePartitionNSP() const { + return secure_partition; } VirtualDir XCI::GetSecurePartition() const { @@ -102,6 +116,20 @@ VirtualDir XCI::GetLogoPartition() const { return GetPartition(XCIPartition::Logo); } +u64 XCI::GetProgramTitleID() const { + return secure_partition->GetProgramTitleID(); +} + +std::shared_ptr<NCA> XCI::GetProgramNCA() const { + return program; +} + +VirtualFile XCI::GetProgramNCAFile() const { + if (GetProgramNCA() == nullptr) + return nullptr; + return GetProgramNCA()->GetBaseFile(); +} + const std::vector<std::shared_ptr<NCA>>& XCI::GetNCAs() const { return ncas; } @@ -141,11 +169,11 @@ bool XCI::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) { } Loader::ResultStatus XCI::AddNCAFromPartition(XCIPartition part) { - if (partitions[static_cast<size_t>(part)] == nullptr) { + if (partitions[static_cast<std::size_t>(part)] == nullptr) { return Loader::ResultStatus::ErrorXCIMissingPartition; } - for (const VirtualFile& file : partitions[static_cast<size_t>(part)]->GetFiles()) { + for (const VirtualFile& file : partitions[static_cast<std::size_t>(part)]->GetFiles()) { if (file->GetExtension() != "nca") continue; auto nca = std::make_shared<NCA>(file); @@ -160,7 +188,7 @@ Loader::ResultStatus XCI::AddNCAFromPartition(XCIPartition part) { } else { const u16 error_id = static_cast<u16>(nca->GetStatus()); LOG_CRITICAL(Loader, "Could not load NCA {}/{}, failed with error code {:04X} ({})", - partition_names[static_cast<size_t>(part)], nca->GetName(), error_id, + partition_names[static_cast<std::size_t>(part)], nca->GetName(), error_id, nca->GetStatus()); } } |