summaryrefslogtreecommitdiffstats
path: root/src/core/file_sys
diff options
context:
space:
mode:
authorZach Hilman <zachhilman@gmail.com>2018-08-26 04:42:54 +0200
committerZach Hilman <zachhilman@gmail.com>2018-09-04 20:29:19 +0200
commite4e55d064edd71fbf359dec9d6b5efad4f0d6c91 (patch)
tree2ab6e2d16084e7071d89139e6ab25b2c11a31990 /src/core/file_sys
parentqt: Add UI support for NSP files (diff)
downloadyuzu-e4e55d064edd71fbf359dec9d6b5efad4f0d6c91.tar
yuzu-e4e55d064edd71fbf359dec9d6b5efad4f0d6c91.tar.gz
yuzu-e4e55d064edd71fbf359dec9d6b5efad4f0d6c91.tar.bz2
yuzu-e4e55d064edd71fbf359dec9d6b5efad4f0d6c91.tar.lz
yuzu-e4e55d064edd71fbf359dec9d6b5efad4f0d6c91.tar.xz
yuzu-e4e55d064edd71fbf359dec9d6b5efad4f0d6c91.tar.zst
yuzu-e4e55d064edd71fbf359dec9d6b5efad4f0d6c91.zip
Diffstat (limited to 'src/core/file_sys')
-rw-r--r--src/core/file_sys/card_image.cpp1
-rw-r--r--src/core/file_sys/card_image.h2
-rw-r--r--src/core/file_sys/submission_package.cpp57
-rw-r--r--src/core/file_sys/submission_package.h2
4 files changed, 37 insertions, 25 deletions
diff --git a/src/core/file_sys/card_image.cpp b/src/core/file_sys/card_image.cpp
index d0f1afac0..e07ac8503 100644
--- a/src/core/file_sys/card_image.cpp
+++ b/src/core/file_sys/card_image.cpp
@@ -12,6 +12,7 @@
#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"
diff --git a/src/core/file_sys/card_image.h b/src/core/file_sys/card_image.h
index b73f1d900..4d07d3d05 100644
--- a/src/core/file_sys/card_image.h
+++ b/src/core/file_sys/card_image.h
@@ -11,7 +11,6 @@
#include "common/swap.h"
#include "core/file_sys/vfs.h"
#include "core/loader/loader.h"
-#include "submission_package.h"
namespace Loader {
enum class ResultStatus : u16;
@@ -21,6 +20,7 @@ namespace FileSys {
class NCA;
enum class NCAContentType : u8;
+class NSP;
enum class GamecardSize : u8 {
S_1GB = 0xFA,
diff --git a/src/core/file_sys/submission_package.cpp b/src/core/file_sys/submission_package.cpp
index 660771cf8..ce05a5845 100644
--- a/src/core/file_sys/submission_package.cpp
+++ b/src/core/file_sys/submission_package.cpp
@@ -72,21 +72,21 @@ NSP::NSP(VirtualFile file_)
ncas_title[ContentRecordType::Meta] = nca;
for (const auto& rec : cnmt.GetContentRecords()) {
- const auto next_file = pfs->GetFile(
- fmt::format("{}.nca", Common::HexArrayToString(rec.nca_id, false)));
+ const auto id_string = Common::HexArrayToString(rec.nca_id, false);
+ const auto next_file = pfs->GetFile(fmt::format("{}.nca", id_string));
if (next_file == nullptr) {
LOG_WARNING(Service_FS,
"NCA with ID {}.nca is listed in content metadata, but cannot "
"be found in PFS. NSP appears to be corrupted.",
- Common::HexArrayToString(rec.nca_id, false));
+ id_string);
continue;
}
- const auto next_nca = std::make_shared<NCA>(next_file);
+ auto next_nca = std::make_shared<NCA>(next_file);
if (next_nca->GetType() == NCAContentType::Program)
program_status[cnmt.GetTitleID()] = next_nca->GetStatus();
if (next_nca->GetStatus() == Loader::ResultStatus::Success)
- ncas_title[rec.type] = next_nca;
+ ncas_title[rec.type] = std::move(next_nca);
}
break;
@@ -95,14 +95,17 @@ NSP::NSP(VirtualFile file_)
}
}
+NSP::~NSP() = default;
+
Loader::ResultStatus NSP::GetStatus() const {
return status;
}
Loader::ResultStatus NSP::GetProgramStatus(u64 title_id) const {
- if (program_status.find(title_id) != program_status.end())
- return program_status.at(title_id);
- return Loader::ResultStatus::ErrorNSPMissingProgramNCA;
+ const auto iter = program_status.find(title_id);
+ if (iter == program_status.end())
+ return Loader::ResultStatus::ErrorNSPMissingProgramNCA;
+ return iter->second;
}
u64 NSP::GetFirstTitleID() const {
@@ -112,16 +115,19 @@ u64 NSP::GetFirstTitleID() const {
}
u64 NSP::GetProgramTitleID() const {
- auto out = GetFirstTitleID();
- for (const auto other_tid : GetTitleIDs()) {
- if ((out & 0x800) != 0)
- out = other_tid;
- }
- return out;
+ const auto out = GetFirstTitleID();
+ if ((out & 0x800) == 0)
+ return out;
+
+ const auto ids = GetTitleIDs();
+ const auto iter =
+ std::find_if(ids.begin(), ids.end(), [](u64 tid) { return (tid & 0x800) == 0; });
+ return iter == ids.end() ? out : *iter;
}
std::vector<u64> NSP::GetTitleIDs() const {
std::vector<u64> out;
+ out.reserve(ncas.size());
for (const auto& kv : ncas)
out.push_back(kv.first);
return out;
@@ -156,7 +162,7 @@ std::multimap<u64, std::shared_ptr<NCA>> NSP::GetNCAsByTitleID() const {
std::multimap<u64, std::shared_ptr<NCA>> out;
for (const auto& map : ncas) {
for (const auto& inner_map : map.second)
- out.insert({map.first, inner_map.second});
+ out.emplace(map.first, inner_map.second);
}
return out;
}
@@ -168,13 +174,16 @@ std::map<u64, std::map<ContentRecordType, std::shared_ptr<NCA>>> NSP::GetNCAs()
std::shared_ptr<NCA> NSP::GetNCA(u64 title_id, ContentRecordType type) const {
if (extracted)
LOG_WARNING(Service_FS, "called on an NSP that is of type extracted.");
- if (ncas.find(title_id) != ncas.end()) {
- const auto& inner_map = ncas.at(title_id);
- if (inner_map.find(type) != inner_map.end())
- return inner_map.at(type);
- }
- return nullptr;
+ const auto title_id_iter = ncas.find(title_id);
+ if (title_id_iter == ncas.end())
+ return nullptr;
+
+ const auto type_iter = title_id_iter->second.find(type);
+ if (type_iter == title_id_iter->second.end())
+ return nullptr;
+
+ return type_iter->second;
}
VirtualFile NSP::GetNCAFile(u64 title_id, ContentRecordType type) const {
@@ -197,9 +206,9 @@ std::vector<Core::Crypto::Key128> NSP::GetTitlekey() const {
continue;
}
- Core::Crypto::Key128 key{};
- ticket_file->Read(key.data(), key.size(), Core::Crypto::TICKET_FILE_TITLEKEY_OFFSET);
- out.push_back(key);
+ out.emplace_back();
+ ticket_file->Read(out.back().data(), out.back().size(),
+ Core::Crypto::TICKET_FILE_TITLEKEY_OFFSET);
}
return out;
}
diff --git a/src/core/file_sys/submission_package.h b/src/core/file_sys/submission_package.h
index 7b520df57..482a8b71f 100644
--- a/src/core/file_sys/submission_package.h
+++ b/src/core/file_sys/submission_package.h
@@ -10,6 +10,7 @@
#include "common/common_types.h"
#include "common/swap.h"
#include "core/file_sys/content_archive.h"
+#include "core/file_sys/romfs_factory.h"
#include "core/file_sys/vfs.h"
#include "core/loader/loader.h"
#include "romfs_factory.h"
@@ -19,6 +20,7 @@ namespace FileSys {
class NSP : public ReadOnlyVfsDirectory {
public:
explicit NSP(VirtualFile file);
+ ~NSP();
Loader::ResultStatus GetStatus() const;
Loader::ResultStatus GetProgramStatus(u64 title_id) const;