diff options
| author | 2018-08-25 22:42:54 -0400 | |
|---|---|---|
| committer | 2018-09-04 14:29:19 -0400 | |
| commit | e4e55d064edd71fbf359dec9d6b5efad4f0d6c91 (patch) | |
| tree | 2ab6e2d16084e7071d89139e6ab25b2c11a31990 /src/core | |
| parent | qt: Add UI support for NSP files (diff) | |
| download | yuzu-e4e55d064edd71fbf359dec9d6b5efad4f0d6c91.tar.gz yuzu-e4e55d064edd71fbf359dec9d6b5efad4f0d6c91.tar.xz yuzu-e4e55d064edd71fbf359dec9d6b5efad4f0d6c91.zip | |
nsp: Comply with style and performance guidelines
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/crypto/key_manager.cpp | 2 | ||||
| -rw-r--r-- | src/core/file_sys/card_image.cpp | 1 | ||||
| -rw-r--r-- | src/core/file_sys/card_image.h | 2 | ||||
| -rw-r--r-- | src/core/file_sys/submission_package.cpp | 57 | ||||
| -rw-r--r-- | src/core/file_sys/submission_package.h | 2 | ||||
| -rw-r--r-- | src/core/loader/nsp.cpp | 11 | ||||
| -rw-r--r-- | src/core/loader/nsp.h | 2 |
7 files changed, 48 insertions, 29 deletions
diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp index bd4b3d7c7..6f27f990b 100644 --- a/src/core/crypto/key_manager.cpp +++ b/src/core/crypto/key_manager.cpp | |||
| @@ -237,7 +237,7 @@ void KeyManager::SetKey(S128KeyType id, Key128 key, u64 field1, u64 field2) { | |||
| 237 | Key128 rights_id; | 237 | Key128 rights_id; |
| 238 | std::memcpy(rights_id.data(), &field2, sizeof(u64)); | 238 | std::memcpy(rights_id.data(), &field2, sizeof(u64)); |
| 239 | std::memcpy(rights_id.data() + sizeof(u64), &field1, sizeof(u64)); | 239 | std::memcpy(rights_id.data() + sizeof(u64), &field1, sizeof(u64)); |
| 240 | WriteKeyToFile(true, fmt::format("{}", Common::HexArrayToString(rights_id)), key); | 240 | WriteKeyToFile(true, Common::HexArrayToString(rights_id), key); |
| 241 | } | 241 | } |
| 242 | const auto iter2 = std::find_if( | 242 | const auto iter2 = std::find_if( |
| 243 | s128_file_id.begin(), s128_file_id.end(), | 243 | s128_file_id.begin(), s128_file_id.end(), |
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 @@ | |||
| 12 | #include "core/file_sys/content_archive.h" | 12 | #include "core/file_sys/content_archive.h" |
| 13 | #include "core/file_sys/nca_metadata.h" | 13 | #include "core/file_sys/nca_metadata.h" |
| 14 | #include "core/file_sys/partition_filesystem.h" | 14 | #include "core/file_sys/partition_filesystem.h" |
| 15 | #include "core/file_sys/submission_package.h" | ||
| 15 | #include "core/file_sys/vfs_offset.h" | 16 | #include "core/file_sys/vfs_offset.h" |
| 16 | #include "core/loader/loader.h" | 17 | #include "core/loader/loader.h" |
| 17 | 18 | ||
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 @@ | |||
| 11 | #include "common/swap.h" | 11 | #include "common/swap.h" |
| 12 | #include "core/file_sys/vfs.h" | 12 | #include "core/file_sys/vfs.h" |
| 13 | #include "core/loader/loader.h" | 13 | #include "core/loader/loader.h" |
| 14 | #include "submission_package.h" | ||
| 15 | 14 | ||
| 16 | namespace Loader { | 15 | namespace Loader { |
| 17 | enum class ResultStatus : u16; | 16 | enum class ResultStatus : u16; |
| @@ -21,6 +20,7 @@ namespace FileSys { | |||
| 21 | 20 | ||
| 22 | class NCA; | 21 | class NCA; |
| 23 | enum class NCAContentType : u8; | 22 | enum class NCAContentType : u8; |
| 23 | class NSP; | ||
| 24 | 24 | ||
| 25 | enum class GamecardSize : u8 { | 25 | enum class GamecardSize : u8 { |
| 26 | S_1GB = 0xFA, | 26 | 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_) | |||
| 72 | 72 | ||
| 73 | ncas_title[ContentRecordType::Meta] = nca; | 73 | ncas_title[ContentRecordType::Meta] = nca; |
| 74 | for (const auto& rec : cnmt.GetContentRecords()) { | 74 | for (const auto& rec : cnmt.GetContentRecords()) { |
| 75 | const auto next_file = pfs->GetFile( | 75 | const auto id_string = Common::HexArrayToString(rec.nca_id, false); |
| 76 | fmt::format("{}.nca", Common::HexArrayToString(rec.nca_id, false))); | 76 | const auto next_file = pfs->GetFile(fmt::format("{}.nca", id_string)); |
| 77 | if (next_file == nullptr) { | 77 | if (next_file == nullptr) { |
| 78 | LOG_WARNING(Service_FS, | 78 | LOG_WARNING(Service_FS, |
| 79 | "NCA with ID {}.nca is listed in content metadata, but cannot " | 79 | "NCA with ID {}.nca is listed in content metadata, but cannot " |
| 80 | "be found in PFS. NSP appears to be corrupted.", | 80 | "be found in PFS. NSP appears to be corrupted.", |
| 81 | Common::HexArrayToString(rec.nca_id, false)); | 81 | id_string); |
| 82 | continue; | 82 | continue; |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | const auto next_nca = std::make_shared<NCA>(next_file); | 85 | auto next_nca = std::make_shared<NCA>(next_file); |
| 86 | if (next_nca->GetType() == NCAContentType::Program) | 86 | if (next_nca->GetType() == NCAContentType::Program) |
| 87 | program_status[cnmt.GetTitleID()] = next_nca->GetStatus(); | 87 | program_status[cnmt.GetTitleID()] = next_nca->GetStatus(); |
| 88 | if (next_nca->GetStatus() == Loader::ResultStatus::Success) | 88 | if (next_nca->GetStatus() == Loader::ResultStatus::Success) |
| 89 | ncas_title[rec.type] = next_nca; | 89 | ncas_title[rec.type] = std::move(next_nca); |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | break; | 92 | break; |
| @@ -95,14 +95,17 @@ NSP::NSP(VirtualFile file_) | |||
| 95 | } | 95 | } |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | NSP::~NSP() = default; | ||
| 99 | |||
| 98 | Loader::ResultStatus NSP::GetStatus() const { | 100 | Loader::ResultStatus NSP::GetStatus() const { |
| 99 | return status; | 101 | return status; |
| 100 | } | 102 | } |
| 101 | 103 | ||
| 102 | Loader::ResultStatus NSP::GetProgramStatus(u64 title_id) const { | 104 | Loader::ResultStatus NSP::GetProgramStatus(u64 title_id) const { |
| 103 | if (program_status.find(title_id) != program_status.end()) | 105 | const auto iter = program_status.find(title_id); |
| 104 | return program_status.at(title_id); | 106 | if (iter == program_status.end()) |
| 105 | return Loader::ResultStatus::ErrorNSPMissingProgramNCA; | 107 | return Loader::ResultStatus::ErrorNSPMissingProgramNCA; |
| 108 | return iter->second; | ||
| 106 | } | 109 | } |
| 107 | 110 | ||
| 108 | u64 NSP::GetFirstTitleID() const { | 111 | u64 NSP::GetFirstTitleID() const { |
| @@ -112,16 +115,19 @@ u64 NSP::GetFirstTitleID() const { | |||
| 112 | } | 115 | } |
| 113 | 116 | ||
| 114 | u64 NSP::GetProgramTitleID() const { | 117 | u64 NSP::GetProgramTitleID() const { |
| 115 | auto out = GetFirstTitleID(); | 118 | const auto out = GetFirstTitleID(); |
| 116 | for (const auto other_tid : GetTitleIDs()) { | 119 | if ((out & 0x800) == 0) |
| 117 | if ((out & 0x800) != 0) | 120 | return out; |
| 118 | out = other_tid; | 121 | |
| 119 | } | 122 | const auto ids = GetTitleIDs(); |
| 120 | return out; | 123 | const auto iter = |
| 124 | std::find_if(ids.begin(), ids.end(), [](u64 tid) { return (tid & 0x800) == 0; }); | ||
| 125 | return iter == ids.end() ? out : *iter; | ||
| 121 | } | 126 | } |
| 122 | 127 | ||
| 123 | std::vector<u64> NSP::GetTitleIDs() const { | 128 | std::vector<u64> NSP::GetTitleIDs() const { |
| 124 | std::vector<u64> out; | 129 | std::vector<u64> out; |
| 130 | out.reserve(ncas.size()); | ||
| 125 | for (const auto& kv : ncas) | 131 | for (const auto& kv : ncas) |
| 126 | out.push_back(kv.first); | 132 | out.push_back(kv.first); |
| 127 | return out; | 133 | return out; |
| @@ -156,7 +162,7 @@ std::multimap<u64, std::shared_ptr<NCA>> NSP::GetNCAsByTitleID() const { | |||
| 156 | std::multimap<u64, std::shared_ptr<NCA>> out; | 162 | std::multimap<u64, std::shared_ptr<NCA>> out; |
| 157 | for (const auto& map : ncas) { | 163 | for (const auto& map : ncas) { |
| 158 | for (const auto& inner_map : map.second) | 164 | for (const auto& inner_map : map.second) |
| 159 | out.insert({map.first, inner_map.second}); | 165 | out.emplace(map.first, inner_map.second); |
| 160 | } | 166 | } |
| 161 | return out; | 167 | return out; |
| 162 | } | 168 | } |
| @@ -168,13 +174,16 @@ std::map<u64, std::map<ContentRecordType, std::shared_ptr<NCA>>> NSP::GetNCAs() | |||
| 168 | std::shared_ptr<NCA> NSP::GetNCA(u64 title_id, ContentRecordType type) const { | 174 | std::shared_ptr<NCA> NSP::GetNCA(u64 title_id, ContentRecordType type) const { |
| 169 | if (extracted) | 175 | if (extracted) |
| 170 | LOG_WARNING(Service_FS, "called on an NSP that is of type extracted."); | 176 | LOG_WARNING(Service_FS, "called on an NSP that is of type extracted."); |
| 171 | if (ncas.find(title_id) != ncas.end()) { | ||
| 172 | const auto& inner_map = ncas.at(title_id); | ||
| 173 | if (inner_map.find(type) != inner_map.end()) | ||
| 174 | return inner_map.at(type); | ||
| 175 | } | ||
| 176 | 177 | ||
| 177 | return nullptr; | 178 | const auto title_id_iter = ncas.find(title_id); |
| 179 | if (title_id_iter == ncas.end()) | ||
| 180 | return nullptr; | ||
| 181 | |||
| 182 | const auto type_iter = title_id_iter->second.find(type); | ||
| 183 | if (type_iter == title_id_iter->second.end()) | ||
| 184 | return nullptr; | ||
| 185 | |||
| 186 | return type_iter->second; | ||
| 178 | } | 187 | } |
| 179 | 188 | ||
| 180 | VirtualFile NSP::GetNCAFile(u64 title_id, ContentRecordType type) const { | 189 | VirtualFile NSP::GetNCAFile(u64 title_id, ContentRecordType type) const { |
| @@ -197,9 +206,9 @@ std::vector<Core::Crypto::Key128> NSP::GetTitlekey() const { | |||
| 197 | continue; | 206 | continue; |
| 198 | } | 207 | } |
| 199 | 208 | ||
| 200 | Core::Crypto::Key128 key{}; | 209 | out.emplace_back(); |
| 201 | ticket_file->Read(key.data(), key.size(), Core::Crypto::TICKET_FILE_TITLEKEY_OFFSET); | 210 | ticket_file->Read(out.back().data(), out.back().size(), |
| 202 | out.push_back(key); | 211 | Core::Crypto::TICKET_FILE_TITLEKEY_OFFSET); |
| 203 | } | 212 | } |
| 204 | return out; | 213 | return out; |
| 205 | } | 214 | } |
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 @@ | |||
| 10 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 11 | #include "common/swap.h" | 11 | #include "common/swap.h" |
| 12 | #include "core/file_sys/content_archive.h" | 12 | #include "core/file_sys/content_archive.h" |
| 13 | #include "core/file_sys/romfs_factory.h" | ||
| 13 | #include "core/file_sys/vfs.h" | 14 | #include "core/file_sys/vfs.h" |
| 14 | #include "core/loader/loader.h" | 15 | #include "core/loader/loader.h" |
| 15 | #include "romfs_factory.h" | 16 | #include "romfs_factory.h" |
| @@ -19,6 +20,7 @@ namespace FileSys { | |||
| 19 | class NSP : public ReadOnlyVfsDirectory { | 20 | class NSP : public ReadOnlyVfsDirectory { |
| 20 | public: | 21 | public: |
| 21 | explicit NSP(VirtualFile file); | 22 | explicit NSP(VirtualFile file); |
| 23 | ~NSP(); | ||
| 22 | 24 | ||
| 23 | Loader::ResultStatus GetStatus() const; | 25 | Loader::ResultStatus GetStatus() const; |
| 24 | Loader::ResultStatus GetProgramStatus(u64 title_id) const; | 26 | Loader::ResultStatus GetProgramStatus(u64 title_id) const; |
diff --git a/src/core/loader/nsp.cpp b/src/core/loader/nsp.cpp index 75d9fc1bc..b59d40052 100644 --- a/src/core/loader/nsp.cpp +++ b/src/core/loader/nsp.cpp | |||
| @@ -21,22 +21,27 @@ namespace Loader { | |||
| 21 | AppLoader_NSP::AppLoader_NSP(FileSys::VirtualFile file) | 21 | AppLoader_NSP::AppLoader_NSP(FileSys::VirtualFile file) |
| 22 | : AppLoader(file), nsp(std::make_unique<FileSys::NSP>(file)), | 22 | : AppLoader(file), nsp(std::make_unique<FileSys::NSP>(file)), |
| 23 | title_id(nsp->GetProgramTitleID()) { | 23 | title_id(nsp->GetProgramTitleID()) { |
| 24 | |||
| 24 | if (nsp->GetStatus() != ResultStatus::Success) | 25 | if (nsp->GetStatus() != ResultStatus::Success) |
| 25 | return; | 26 | return; |
| 26 | if (nsp->IsExtractedType()) | 27 | if (nsp->IsExtractedType()) |
| 27 | return; | 28 | return; |
| 29 | |||
| 28 | const auto control_nca = | 30 | const auto control_nca = |
| 29 | nsp->GetNCA(nsp->GetFirstTitleID(), FileSys::ContentRecordType::Control); | 31 | nsp->GetNCA(nsp->GetFirstTitleID(), FileSys::ContentRecordType::Control); |
| 30 | if (control_nca == nullptr || control_nca->GetStatus() != ResultStatus::Success) | 32 | if (control_nca == nullptr || control_nca->GetStatus() != ResultStatus::Success) |
| 31 | return; | 33 | return; |
| 34 | |||
| 32 | const auto romfs = FileSys::ExtractRomFS(control_nca->GetRomFS()); | 35 | const auto romfs = FileSys::ExtractRomFS(control_nca->GetRomFS()); |
| 33 | if (romfs == nullptr) | 36 | if (romfs == nullptr) |
| 34 | return; | 37 | return; |
| 38 | |||
| 35 | for (const auto& language : FileSys::LANGUAGE_NAMES) { | 39 | for (const auto& language : FileSys::LANGUAGE_NAMES) { |
| 36 | icon_file = romfs->GetFile("icon_" + std::string(language) + ".dat"); | 40 | icon_file = romfs->GetFile("icon_" + std::string(language) + ".dat"); |
| 37 | if (icon_file != nullptr) | 41 | if (icon_file != nullptr) |
| 38 | break; | 42 | break; |
| 39 | } | 43 | } |
| 44 | |||
| 40 | const auto nacp_raw = romfs->GetFile("control.nacp"); | 45 | const auto nacp_raw = romfs->GetFile("control.nacp"); |
| 41 | if (nacp_raw == nullptr) | 46 | if (nacp_raw == nullptr) |
| 42 | return; | 47 | return; |
| @@ -51,15 +56,17 @@ FileType AppLoader_NSP::IdentifyType(const FileSys::VirtualFile& file) { | |||
| 51 | if (nsp.GetStatus() == ResultStatus::Success) { | 56 | if (nsp.GetStatus() == ResultStatus::Success) { |
| 52 | // Extracted Type case | 57 | // Extracted Type case |
| 53 | if (nsp.IsExtractedType() && nsp.GetExeFS() != nullptr && | 58 | if (nsp.IsExtractedType() && nsp.GetExeFS() != nullptr && |
| 54 | FileSys::IsDirectoryExeFS(nsp.GetExeFS()) && nsp.GetRomFS() != nullptr) | 59 | FileSys::IsDirectoryExeFS(nsp.GetExeFS()) && nsp.GetRomFS() != nullptr) { |
| 55 | return FileType::NSP; | 60 | return FileType::NSP; |
| 61 | } | ||
| 56 | 62 | ||
| 57 | // Non-Ectracted Type case | 63 | // Non-Ectracted Type case |
| 58 | if (!nsp.IsExtractedType() && | 64 | if (!nsp.IsExtractedType() && |
| 59 | nsp.GetNCA(nsp.GetFirstTitleID(), FileSys::ContentRecordType::Program) != nullptr && | 65 | nsp.GetNCA(nsp.GetFirstTitleID(), FileSys::ContentRecordType::Program) != nullptr && |
| 60 | AppLoader_NCA::IdentifyType(nsp.GetNCAFile( | 66 | AppLoader_NCA::IdentifyType(nsp.GetNCAFile( |
| 61 | nsp.GetFirstTitleID(), FileSys::ContentRecordType::Program)) == FileType::NCA) | 67 | nsp.GetFirstTitleID(), FileSys::ContentRecordType::Program)) == FileType::NCA) { |
| 62 | return FileType::NSP; | 68 | return FileType::NSP; |
| 69 | } | ||
| 63 | } | 70 | } |
| 64 | 71 | ||
| 65 | return FileType::Error; | 72 | return FileType::Error; |
diff --git a/src/core/loader/nsp.h b/src/core/loader/nsp.h index 785feaf37..7ef810499 100644 --- a/src/core/loader/nsp.h +++ b/src/core/loader/nsp.h | |||
| @@ -22,7 +22,7 @@ class AppLoader_NCA; | |||
| 22 | class AppLoader_NSP final : public AppLoader { | 22 | class AppLoader_NSP final : public AppLoader { |
| 23 | public: | 23 | public: |
| 24 | explicit AppLoader_NSP(FileSys::VirtualFile file); | 24 | explicit AppLoader_NSP(FileSys::VirtualFile file); |
| 25 | ~AppLoader_NSP(); | 25 | ~AppLoader_NSP() override; |
| 26 | 26 | ||
| 27 | /** | 27 | /** |
| 28 | * Returns the type of the file | 28 | * Returns the type of the file |