diff options
| author | 2018-10-03 01:11:12 -0400 | |
|---|---|---|
| committer | 2018-10-03 01:11:16 -0400 | |
| commit | 0d83f8f2558b45923b072cf535bf7da9e5c24aea (patch) | |
| tree | c5d98622d1b21562db945237c7b645f14526f539 /src/core/file_sys | |
| parent | Merge pull request #1330 from raven02/tlds (diff) | |
| download | yuzu-0d83f8f2558b45923b072cf535bf7da9e5c24aea.tar.gz yuzu-0d83f8f2558b45923b072cf535bf7da9e5c24aea.tar.xz yuzu-0d83f8f2558b45923b072cf535bf7da9e5c24aea.zip | |
submission_package: Invert conditionals within NSP's constructor to reduce nesting
We can use early continues here to reduce the amount of nesting.
Diffstat (limited to 'src/core/file_sys')
| -rw-r--r-- | src/core/file_sys/submission_package.cpp | 94 |
1 files changed, 49 insertions, 45 deletions
diff --git a/src/core/file_sys/submission_package.cpp b/src/core/file_sys/submission_package.cpp index 11264878d..6ff43fa77 100644 --- a/src/core/file_sys/submission_package.cpp +++ b/src/core/file_sys/submission_package.cpp | |||
| @@ -45,62 +45,66 @@ NSP::NSP(VirtualFile file_) | |||
| 45 | 45 | ||
| 46 | Core::Crypto::KeyManager keys; | 46 | Core::Crypto::KeyManager keys; |
| 47 | for (const auto& ticket_file : files) { | 47 | for (const auto& ticket_file : files) { |
| 48 | if (ticket_file->GetExtension() == "tik") { | 48 | if (ticket_file->GetExtension() != "tik") { |
| 49 | if (ticket_file == nullptr || | 49 | continue; |
| 50 | ticket_file->GetSize() < | 50 | } |
| 51 | Core::Crypto::TICKET_FILE_TITLEKEY_OFFSET + sizeof(Core::Crypto::Key128)) { | ||
| 52 | continue; | ||
| 53 | } | ||
| 54 | 51 | ||
| 55 | Core::Crypto::Key128 key{}; | 52 | if (ticket_file == nullptr || |
| 56 | ticket_file->Read(key.data(), key.size(), Core::Crypto::TICKET_FILE_TITLEKEY_OFFSET); | 53 | ticket_file->GetSize() < |
| 57 | std::string_view name_only(ticket_file->GetName()); | 54 | Core::Crypto::TICKET_FILE_TITLEKEY_OFFSET + sizeof(Core::Crypto::Key128)) { |
| 58 | name_only.remove_suffix(4); | 55 | continue; |
| 59 | const auto rights_id_raw = Common::HexStringToArray<16>(name_only); | ||
| 60 | u128 rights_id; | ||
| 61 | std::memcpy(rights_id.data(), rights_id_raw.data(), sizeof(u128)); | ||
| 62 | keys.SetKey(Core::Crypto::S128KeyType::Titlekey, key, rights_id[1], rights_id[0]); | ||
| 63 | } | 56 | } |
| 57 | |||
| 58 | Core::Crypto::Key128 key{}; | ||
| 59 | ticket_file->Read(key.data(), key.size(), Core::Crypto::TICKET_FILE_TITLEKEY_OFFSET); | ||
| 60 | std::string_view name_only(ticket_file->GetName()); | ||
| 61 | name_only.remove_suffix(4); | ||
| 62 | const auto rights_id_raw = Common::HexStringToArray<16>(name_only); | ||
| 63 | u128 rights_id; | ||
| 64 | std::memcpy(rights_id.data(), rights_id_raw.data(), sizeof(u128)); | ||
| 65 | keys.SetKey(Core::Crypto::S128KeyType::Titlekey, key, rights_id[1], rights_id[0]); | ||
| 64 | } | 66 | } |
| 65 | 67 | ||
| 66 | for (const auto& outer_file : files) { | 68 | for (const auto& outer_file : files) { |
| 67 | if (outer_file->GetName().substr(outer_file->GetName().size() - 9) == ".cnmt.nca") { | 69 | if (outer_file->GetName().substr(outer_file->GetName().size() - 9) != ".cnmt.nca") { |
| 68 | const auto nca = std::make_shared<NCA>(outer_file); | 70 | continue; |
| 69 | if (nca->GetStatus() != Loader::ResultStatus::Success) { | 71 | } |
| 70 | program_status[nca->GetTitleId()] = nca->GetStatus(); | ||
| 71 | continue; | ||
| 72 | } | ||
| 73 | 72 | ||
| 74 | const auto section0 = nca->GetSubdirectories()[0]; | 73 | const auto nca = std::make_shared<NCA>(outer_file); |
| 74 | if (nca->GetStatus() != Loader::ResultStatus::Success) { | ||
| 75 | program_status[nca->GetTitleId()] = nca->GetStatus(); | ||
| 76 | continue; | ||
| 77 | } | ||
| 75 | 78 | ||
| 76 | for (const auto& inner_file : section0->GetFiles()) { | 79 | const auto section0 = nca->GetSubdirectories()[0]; |
| 77 | if (inner_file->GetExtension() != "cnmt") | ||
| 78 | continue; | ||
| 79 | 80 | ||
| 80 | const CNMT cnmt(inner_file); | 81 | for (const auto& inner_file : section0->GetFiles()) { |
| 81 | auto& ncas_title = ncas[cnmt.GetTitleID()]; | 82 | if (inner_file->GetExtension() != "cnmt") |
| 82 | 83 | continue; | |
| 83 | ncas_title[ContentRecordType::Meta] = nca; | 84 | |
| 84 | for (const auto& rec : cnmt.GetContentRecords()) { | 85 | const CNMT cnmt(inner_file); |
| 85 | const auto id_string = Common::HexArrayToString(rec.nca_id, false); | 86 | auto& ncas_title = ncas[cnmt.GetTitleID()]; |
| 86 | const auto next_file = pfs->GetFile(fmt::format("{}.nca", id_string)); | 87 | |
| 87 | if (next_file == nullptr) { | 88 | ncas_title[ContentRecordType::Meta] = nca; |
| 88 | LOG_WARNING(Service_FS, | 89 | for (const auto& rec : cnmt.GetContentRecords()) { |
| 89 | "NCA with ID {}.nca is listed in content metadata, but cannot " | 90 | const auto id_string = Common::HexArrayToString(rec.nca_id, false); |
| 90 | "be found in PFS. NSP appears to be corrupted.", | 91 | const auto next_file = pfs->GetFile(fmt::format("{}.nca", id_string)); |
| 91 | id_string); | 92 | if (next_file == nullptr) { |
| 92 | continue; | 93 | LOG_WARNING(Service_FS, |
| 93 | } | 94 | "NCA with ID {}.nca is listed in content metadata, but cannot " |
| 94 | 95 | "be found in PFS. NSP appears to be corrupted.", | |
| 95 | auto next_nca = std::make_shared<NCA>(next_file); | 96 | id_string); |
| 96 | if (next_nca->GetType() == NCAContentType::Program) | 97 | continue; |
| 97 | program_status[cnmt.GetTitleID()] = next_nca->GetStatus(); | ||
| 98 | if (next_nca->GetStatus() == Loader::ResultStatus::Success) | ||
| 99 | ncas_title[rec.type] = std::move(next_nca); | ||
| 100 | } | 98 | } |
| 101 | 99 | ||
| 102 | break; | 100 | auto next_nca = std::make_shared<NCA>(next_file); |
| 101 | if (next_nca->GetType() == NCAContentType::Program) | ||
| 102 | program_status[cnmt.GetTitleID()] = next_nca->GetStatus(); | ||
| 103 | if (next_nca->GetStatus() == Loader::ResultStatus::Success) | ||
| 104 | ncas_title[rec.type] = std::move(next_nca); | ||
| 103 | } | 105 | } |
| 106 | |||
| 107 | break; | ||
| 104 | } | 108 | } |
| 105 | } | 109 | } |
| 106 | } | 110 | } |