diff options
Diffstat (limited to 'src/core/file_sys')
| -rw-r--r-- | src/core/file_sys/submission_package.cpp | 89 | ||||
| -rw-r--r-- | src/core/file_sys/submission_package.h | 2 |
2 files changed, 48 insertions, 43 deletions
diff --git a/src/core/file_sys/submission_package.cpp b/src/core/file_sys/submission_package.cpp index b1ebab17f..b4d738d94 100644 --- a/src/core/file_sys/submission_package.cpp +++ b/src/core/file_sys/submission_package.cpp | |||
| @@ -71,49 +71,7 @@ NSP::NSP(VirtualFile file_) | |||
| 71 | const auto files = pfs->GetFiles(); | 71 | const auto files = pfs->GetFiles(); |
| 72 | 72 | ||
| 73 | SetTicketKeys(files); | 73 | SetTicketKeys(files); |
| 74 | 74 | ReadNCAs(files); | |
| 75 | for (const auto& outer_file : files) { | ||
| 76 | if (outer_file->GetName().substr(outer_file->GetName().size() - 9) != ".cnmt.nca") { | ||
| 77 | continue; | ||
| 78 | } | ||
| 79 | |||
| 80 | const auto nca = std::make_shared<NCA>(outer_file); | ||
| 81 | if (nca->GetStatus() != Loader::ResultStatus::Success) { | ||
| 82 | program_status[nca->GetTitleId()] = nca->GetStatus(); | ||
| 83 | continue; | ||
| 84 | } | ||
| 85 | |||
| 86 | const auto section0 = nca->GetSubdirectories()[0]; | ||
| 87 | |||
| 88 | for (const auto& inner_file : section0->GetFiles()) { | ||
| 89 | if (inner_file->GetExtension() != "cnmt") | ||
| 90 | continue; | ||
| 91 | |||
| 92 | const CNMT cnmt(inner_file); | ||
| 93 | auto& ncas_title = ncas[cnmt.GetTitleID()]; | ||
| 94 | |||
| 95 | ncas_title[ContentRecordType::Meta] = nca; | ||
| 96 | for (const auto& rec : cnmt.GetContentRecords()) { | ||
| 97 | const auto id_string = Common::HexArrayToString(rec.nca_id, false); | ||
| 98 | const auto next_file = pfs->GetFile(fmt::format("{}.nca", id_string)); | ||
| 99 | if (next_file == nullptr) { | ||
| 100 | LOG_WARNING(Service_FS, | ||
| 101 | "NCA with ID {}.nca is listed in content metadata, but cannot " | ||
| 102 | "be found in PFS. NSP appears to be corrupted.", | ||
| 103 | id_string); | ||
| 104 | continue; | ||
| 105 | } | ||
| 106 | |||
| 107 | auto next_nca = std::make_shared<NCA>(next_file); | ||
| 108 | if (next_nca->GetType() == NCAContentType::Program) | ||
| 109 | program_status[cnmt.GetTitleID()] = next_nca->GetStatus(); | ||
| 110 | if (next_nca->GetStatus() == Loader::ResultStatus::Success) | ||
| 111 | ncas_title[rec.type] = std::move(next_nca); | ||
| 112 | } | ||
| 113 | |||
| 114 | break; | ||
| 115 | } | ||
| 116 | } | ||
| 117 | } | 75 | } |
| 118 | 76 | ||
| 119 | NSP::~NSP() = default; | 77 | NSP::~NSP() = default; |
| @@ -253,4 +211,49 @@ VirtualDir NSP::GetParentDirectory() const { | |||
| 253 | bool NSP::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) { | 211 | bool NSP::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) { |
| 254 | return false; | 212 | return false; |
| 255 | } | 213 | } |
| 214 | |||
| 215 | void NSP::ReadNCAs(const std::vector<VirtualFile>& files) { | ||
| 216 | for (const auto& outer_file : files) { | ||
| 217 | if (outer_file->GetName().substr(outer_file->GetName().size() - 9) != ".cnmt.nca") { | ||
| 218 | continue; | ||
| 219 | } | ||
| 220 | |||
| 221 | const auto nca = std::make_shared<NCA>(outer_file); | ||
| 222 | if (nca->GetStatus() != Loader::ResultStatus::Success) { | ||
| 223 | program_status[nca->GetTitleId()] = nca->GetStatus(); | ||
| 224 | continue; | ||
| 225 | } | ||
| 226 | |||
| 227 | const auto section0 = nca->GetSubdirectories()[0]; | ||
| 228 | |||
| 229 | for (const auto& inner_file : section0->GetFiles()) { | ||
| 230 | if (inner_file->GetExtension() != "cnmt") | ||
| 231 | continue; | ||
| 232 | |||
| 233 | const CNMT cnmt(inner_file); | ||
| 234 | auto& ncas_title = ncas[cnmt.GetTitleID()]; | ||
| 235 | |||
| 236 | ncas_title[ContentRecordType::Meta] = nca; | ||
| 237 | for (const auto& rec : cnmt.GetContentRecords()) { | ||
| 238 | const auto id_string = Common::HexArrayToString(rec.nca_id, false); | ||
| 239 | const auto next_file = pfs->GetFile(fmt::format("{}.nca", id_string)); | ||
| 240 | if (next_file == nullptr) { | ||
| 241 | LOG_WARNING(Service_FS, | ||
| 242 | "NCA with ID {}.nca is listed in content metadata, but cannot " | ||
| 243 | "be found in PFS. NSP appears to be corrupted.", | ||
| 244 | id_string); | ||
| 245 | continue; | ||
| 246 | } | ||
| 247 | |||
| 248 | auto next_nca = std::make_shared<NCA>(next_file); | ||
| 249 | if (next_nca->GetType() == NCAContentType::Program) | ||
| 250 | program_status[cnmt.GetTitleID()] = next_nca->GetStatus(); | ||
| 251 | if (next_nca->GetStatus() == Loader::ResultStatus::Success) | ||
| 252 | ncas_title[rec.type] = std::move(next_nca); | ||
| 253 | } | ||
| 254 | |||
| 255 | break; | ||
| 256 | } | ||
| 257 | } | ||
| 258 | } | ||
| 256 | } // namespace FileSys | 259 | } // namespace FileSys |
diff --git a/src/core/file_sys/submission_package.h b/src/core/file_sys/submission_package.h index e85a2b76e..7c7cebf33 100644 --- a/src/core/file_sys/submission_package.h +++ b/src/core/file_sys/submission_package.h | |||
| @@ -59,6 +59,8 @@ protected: | |||
| 59 | bool ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) override; | 59 | bool ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) override; |
| 60 | 60 | ||
| 61 | private: | 61 | private: |
| 62 | void ReadNCAs(const std::vector<VirtualFile>& files); | ||
| 63 | |||
| 62 | VirtualFile file; | 64 | VirtualFile file; |
| 63 | 65 | ||
| 64 | bool extracted; | 66 | bool extracted; |