diff options
| author | 2018-10-06 23:58:24 -0400 | |
|---|---|---|
| committer | 2018-10-06 23:58:24 -0400 | |
| commit | 6e4d2e672d1083f29186ea0ddcb33cd634e360e3 (patch) | |
| tree | cbd20aab8705f8efac340c509ca71b08865a1417 /src/core/loader | |
| parent | Merge pull request #1446 from bunnei/fast_fermi_copy (diff) | |
| parent | romfs_factory: Extract packed update setter to new function (diff) | |
| download | yuzu-6e4d2e672d1083f29186ea0ddcb33cd634e360e3.tar.gz yuzu-6e4d2e672d1083f29186ea0ddcb33cd634e360e3.tar.xz yuzu-6e4d2e672d1083f29186ea0ddcb33cd634e360e3.zip | |
Merge pull request #1396 from DarkLordZach/packed-updates
loader: Add support for packed updates
Diffstat (limited to 'src/core/loader')
| -rw-r--r-- | src/core/loader/loader.cpp | 3 | ||||
| -rw-r--r-- | src/core/loader/loader.h | 14 | ||||
| -rw-r--r-- | src/core/loader/nax.cpp | 4 | ||||
| -rw-r--r-- | src/core/loader/nax.h | 1 | ||||
| -rw-r--r-- | src/core/loader/nsp.cpp | 32 | ||||
| -rw-r--r-- | src/core/loader/nsp.h | 4 | ||||
| -rw-r--r-- | src/core/loader/xci.cpp | 36 | ||||
| -rw-r--r-- | src/core/loader/xci.h | 4 |
8 files changed, 89 insertions, 9 deletions
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index f2a183ba1..91659ec17 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp | |||
| @@ -93,7 +93,7 @@ std::string GetFileTypeString(FileType type) { | |||
| 93 | return "unknown"; | 93 | return "unknown"; |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | constexpr std::array<const char*, 58> RESULT_MESSAGES{ | 96 | constexpr std::array<const char*, 59> RESULT_MESSAGES{ |
| 97 | "The operation completed successfully.", | 97 | "The operation completed successfully.", |
| 98 | "The loader requested to load is already loaded.", | 98 | "The loader requested to load is already loaded.", |
| 99 | "The operation is not implemented.", | 99 | "The operation is not implemented.", |
| @@ -152,6 +152,7 @@ constexpr std::array<const char*, 58> RESULT_MESSAGES{ | |||
| 152 | "The BKTR-type NCA has a bad Relocation bucket.", | 152 | "The BKTR-type NCA has a bad Relocation bucket.", |
| 153 | "The BKTR-type NCA has a bad Subsection bucket.", | 153 | "The BKTR-type NCA has a bad Subsection bucket.", |
| 154 | "The BKTR-type NCA is missing the base RomFS.", | 154 | "The BKTR-type NCA is missing the base RomFS.", |
| 155 | "The NSP or XCI does not contain an update in addition to the base game.", | ||
| 155 | }; | 156 | }; |
| 156 | 157 | ||
| 157 | std::ostream& operator<<(std::ostream& os, ResultStatus status) { | 158 | std::ostream& operator<<(std::ostream& os, ResultStatus status) { |
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 20e66109b..0e0333db5 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h | |||
| @@ -114,6 +114,7 @@ enum class ResultStatus : u16 { | |||
| 114 | ErrorBadRelocationBuckets, | 114 | ErrorBadRelocationBuckets, |
| 115 | ErrorBadSubsectionBuckets, | 115 | ErrorBadSubsectionBuckets, |
| 116 | ErrorMissingBKTRBaseRomFS, | 116 | ErrorMissingBKTRBaseRomFS, |
| 117 | ErrorNoPackedUpdate, | ||
| 117 | }; | 118 | }; |
| 118 | 119 | ||
| 119 | std::ostream& operator<<(std::ostream& os, ResultStatus status); | 120 | std::ostream& operator<<(std::ostream& os, ResultStatus status); |
| @@ -196,10 +197,19 @@ public: | |||
| 196 | /** | 197 | /** |
| 197 | * Get the RomFS of the application | 198 | * Get the RomFS of the application |
| 198 | * Since the RomFS can be huge, we return a file reference instead of copying to a buffer | 199 | * Since the RomFS can be huge, we return a file reference instead of copying to a buffer |
| 199 | * @param dir The directory containing the RomFS | 200 | * @param file The directory containing the RomFS |
| 200 | * @return ResultStatus result of function | 201 | * @return ResultStatus result of function |
| 201 | */ | 202 | */ |
| 202 | virtual ResultStatus ReadRomFS(FileSys::VirtualFile& dir) { | 203 | virtual ResultStatus ReadRomFS(FileSys::VirtualFile& file) { |
| 204 | return ResultStatus::ErrorNotImplemented; | ||
| 205 | } | ||
| 206 | |||
| 207 | /** | ||
| 208 | * Get the raw update of the application, should it come packed with one | ||
| 209 | * @param file The raw update NCA file (Program-type | ||
| 210 | * @return ResultStatus result of function | ||
| 211 | */ | ||
| 212 | virtual ResultStatus ReadUpdateRaw(FileSys::VirtualFile& file) { | ||
| 203 | return ResultStatus::ErrorNotImplemented; | 213 | return ResultStatus::ErrorNotImplemented; |
| 204 | } | 214 | } |
| 205 | 215 | ||
diff --git a/src/core/loader/nax.cpp b/src/core/loader/nax.cpp index 073fb9d2f..42f4a777b 100644 --- a/src/core/loader/nax.cpp +++ b/src/core/loader/nax.cpp | |||
| @@ -72,6 +72,10 @@ ResultStatus AppLoader_NAX::ReadRomFS(FileSys::VirtualFile& dir) { | |||
| 72 | return nca_loader->ReadRomFS(dir); | 72 | return nca_loader->ReadRomFS(dir); |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | u64 AppLoader_NAX::ReadRomFSIVFCOffset() const { | ||
| 76 | return nca_loader->ReadRomFSIVFCOffset(); | ||
| 77 | } | ||
| 78 | |||
| 75 | ResultStatus AppLoader_NAX::ReadProgramId(u64& out_program_id) { | 79 | ResultStatus AppLoader_NAX::ReadProgramId(u64& out_program_id) { |
| 76 | return nca_loader->ReadProgramId(out_program_id); | 80 | return nca_loader->ReadProgramId(out_program_id); |
| 77 | } | 81 | } |
diff --git a/src/core/loader/nax.h b/src/core/loader/nax.h index fc3c01876..b4d93bd01 100644 --- a/src/core/loader/nax.h +++ b/src/core/loader/nax.h | |||
| @@ -36,6 +36,7 @@ public: | |||
| 36 | ResultStatus Load(Kernel::Process& process) override; | 36 | ResultStatus Load(Kernel::Process& process) override; |
| 37 | 37 | ||
| 38 | ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; | 38 | ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; |
| 39 | u64 ReadRomFSIVFCOffset() const override; | ||
| 39 | ResultStatus ReadProgramId(u64& out_program_id) override; | 40 | ResultStatus ReadProgramId(u64& out_program_id) override; |
| 40 | 41 | ||
| 41 | private: | 42 | private: |
diff --git a/src/core/loader/nsp.cpp b/src/core/loader/nsp.cpp index b7ba77ef4..5534ce01c 100644 --- a/src/core/loader/nsp.cpp +++ b/src/core/loader/nsp.cpp | |||
| @@ -10,8 +10,10 @@ | |||
| 10 | #include "core/file_sys/control_metadata.h" | 10 | #include "core/file_sys/control_metadata.h" |
| 11 | #include "core/file_sys/nca_metadata.h" | 11 | #include "core/file_sys/nca_metadata.h" |
| 12 | #include "core/file_sys/patch_manager.h" | 12 | #include "core/file_sys/patch_manager.h" |
| 13 | #include "core/file_sys/registered_cache.h" | ||
| 13 | #include "core/file_sys/submission_package.h" | 14 | #include "core/file_sys/submission_package.h" |
| 14 | #include "core/hle/kernel/process.h" | 15 | #include "core/hle/kernel/process.h" |
| 16 | #include "core/hle/service/filesystem/filesystem.h" | ||
| 15 | #include "core/loader/deconstructed_rom_directory.h" | 17 | #include "core/loader/deconstructed_rom_directory.h" |
| 16 | #include "core/loader/nca.h" | 18 | #include "core/loader/nca.h" |
| 17 | #include "core/loader/nsp.h" | 19 | #include "core/loader/nsp.h" |
| @@ -91,13 +93,39 @@ ResultStatus AppLoader_NSP::Load(Kernel::Process& process) { | |||
| 91 | if (result != ResultStatus::Success) | 93 | if (result != ResultStatus::Success) |
| 92 | return result; | 94 | return result; |
| 93 | 95 | ||
| 96 | FileSys::VirtualFile update_raw; | ||
| 97 | if (ReadUpdateRaw(update_raw) == ResultStatus::Success && update_raw != nullptr) | ||
| 98 | Service::FileSystem::SetPackedUpdate(std::move(update_raw)); | ||
| 99 | |||
| 94 | is_loaded = true; | 100 | is_loaded = true; |
| 95 | 101 | ||
| 96 | return ResultStatus::Success; | 102 | return ResultStatus::Success; |
| 97 | } | 103 | } |
| 98 | 104 | ||
| 99 | ResultStatus AppLoader_NSP::ReadRomFS(FileSys::VirtualFile& dir) { | 105 | ResultStatus AppLoader_NSP::ReadRomFS(FileSys::VirtualFile& file) { |
| 100 | return secondary_loader->ReadRomFS(dir); | 106 | return secondary_loader->ReadRomFS(file); |
| 107 | } | ||
| 108 | |||
| 109 | u64 AppLoader_NSP::ReadRomFSIVFCOffset() const { | ||
| 110 | return secondary_loader->ReadRomFSIVFCOffset(); | ||
| 111 | } | ||
| 112 | |||
| 113 | ResultStatus AppLoader_NSP::ReadUpdateRaw(FileSys::VirtualFile& file) { | ||
| 114 | if (nsp->IsExtractedType()) | ||
| 115 | return ResultStatus::ErrorNoPackedUpdate; | ||
| 116 | |||
| 117 | const auto read = | ||
| 118 | nsp->GetNCAFile(FileSys::GetUpdateTitleID(title_id), FileSys::ContentRecordType::Program); | ||
| 119 | |||
| 120 | if (read == nullptr) | ||
| 121 | return ResultStatus::ErrorNoPackedUpdate; | ||
| 122 | const auto nca_test = std::make_shared<FileSys::NCA>(read); | ||
| 123 | |||
| 124 | if (nca_test->GetStatus() != ResultStatus::ErrorMissingBKTRBaseRomFS) | ||
| 125 | return nca_test->GetStatus(); | ||
| 126 | |||
| 127 | file = read; | ||
| 128 | return ResultStatus::Success; | ||
| 101 | } | 129 | } |
| 102 | 130 | ||
| 103 | ResultStatus AppLoader_NSP::ReadProgramId(u64& out_program_id) { | 131 | ResultStatus AppLoader_NSP::ReadProgramId(u64& out_program_id) { |
diff --git a/src/core/loader/nsp.h b/src/core/loader/nsp.h index eac9b819a..b006594a6 100644 --- a/src/core/loader/nsp.h +++ b/src/core/loader/nsp.h | |||
| @@ -37,7 +37,9 @@ public: | |||
| 37 | 37 | ||
| 38 | ResultStatus Load(Kernel::Process& process) override; | 38 | ResultStatus Load(Kernel::Process& process) override; |
| 39 | 39 | ||
| 40 | ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; | 40 | ResultStatus ReadRomFS(FileSys::VirtualFile& file) override; |
| 41 | u64 ReadRomFSIVFCOffset() const override; | ||
| 42 | ResultStatus ReadUpdateRaw(FileSys::VirtualFile& file) override; | ||
| 41 | ResultStatus ReadProgramId(u64& out_program_id) override; | 43 | ResultStatus ReadProgramId(u64& out_program_id) override; |
| 42 | ResultStatus ReadIcon(std::vector<u8>& buffer) override; | 44 | ResultStatus ReadIcon(std::vector<u8>& buffer) override; |
| 43 | ResultStatus ReadTitle(std::string& title) override; | 45 | ResultStatus ReadTitle(std::string& title) override; |
diff --git a/src/core/loader/xci.cpp b/src/core/loader/xci.cpp index eda67a8c8..ee5452eb9 100644 --- a/src/core/loader/xci.cpp +++ b/src/core/loader/xci.cpp | |||
| @@ -9,7 +9,11 @@ | |||
| 9 | #include "core/file_sys/content_archive.h" | 9 | #include "core/file_sys/content_archive.h" |
| 10 | #include "core/file_sys/control_metadata.h" | 10 | #include "core/file_sys/control_metadata.h" |
| 11 | #include "core/file_sys/patch_manager.h" | 11 | #include "core/file_sys/patch_manager.h" |
| 12 | #include "core/file_sys/registered_cache.h" | ||
| 13 | #include "core/file_sys/romfs.h" | ||
| 14 | #include "core/file_sys/submission_package.h" | ||
| 12 | #include "core/hle/kernel/process.h" | 15 | #include "core/hle/kernel/process.h" |
| 16 | #include "core/hle/service/filesystem/filesystem.h" | ||
| 13 | #include "core/loader/nca.h" | 17 | #include "core/loader/nca.h" |
| 14 | #include "core/loader/xci.h" | 18 | #include "core/loader/xci.h" |
| 15 | 19 | ||
| @@ -63,13 +67,41 @@ ResultStatus AppLoader_XCI::Load(Kernel::Process& process) { | |||
| 63 | if (result != ResultStatus::Success) | 67 | if (result != ResultStatus::Success) |
| 64 | return result; | 68 | return result; |
| 65 | 69 | ||
| 70 | FileSys::VirtualFile update_raw; | ||
| 71 | if (ReadUpdateRaw(update_raw) == ResultStatus::Success && update_raw != nullptr) | ||
| 72 | Service::FileSystem::SetPackedUpdate(std::move(update_raw)); | ||
| 73 | |||
| 66 | is_loaded = true; | 74 | is_loaded = true; |
| 67 | 75 | ||
| 68 | return ResultStatus::Success; | 76 | return ResultStatus::Success; |
| 69 | } | 77 | } |
| 70 | 78 | ||
| 71 | ResultStatus AppLoader_XCI::ReadRomFS(FileSys::VirtualFile& dir) { | 79 | ResultStatus AppLoader_XCI::ReadRomFS(FileSys::VirtualFile& file) { |
| 72 | return nca_loader->ReadRomFS(dir); | 80 | return nca_loader->ReadRomFS(file); |
| 81 | } | ||
| 82 | |||
| 83 | u64 AppLoader_XCI::ReadRomFSIVFCOffset() const { | ||
| 84 | return nca_loader->ReadRomFSIVFCOffset(); | ||
| 85 | } | ||
| 86 | |||
| 87 | ResultStatus AppLoader_XCI::ReadUpdateRaw(FileSys::VirtualFile& file) { | ||
| 88 | u64 program_id{}; | ||
| 89 | nca_loader->ReadProgramId(program_id); | ||
| 90 | if (program_id == 0) | ||
| 91 | return ResultStatus::ErrorXCIMissingProgramNCA; | ||
| 92 | |||
| 93 | const auto read = xci->GetSecurePartitionNSP()->GetNCAFile( | ||
| 94 | FileSys::GetUpdateTitleID(program_id), FileSys::ContentRecordType::Program); | ||
| 95 | |||
| 96 | if (read == nullptr) | ||
| 97 | return ResultStatus::ErrorNoPackedUpdate; | ||
| 98 | const auto nca_test = std::make_shared<FileSys::NCA>(read); | ||
| 99 | |||
| 100 | if (nca_test->GetStatus() != ResultStatus::ErrorMissingBKTRBaseRomFS) | ||
| 101 | return nca_test->GetStatus(); | ||
| 102 | |||
| 103 | file = read; | ||
| 104 | return ResultStatus::Success; | ||
| 73 | } | 105 | } |
| 74 | 106 | ||
| 75 | ResultStatus AppLoader_XCI::ReadProgramId(u64& out_program_id) { | 107 | ResultStatus AppLoader_XCI::ReadProgramId(u64& out_program_id) { |
diff --git a/src/core/loader/xci.h b/src/core/loader/xci.h index 17e47b658..770ed1437 100644 --- a/src/core/loader/xci.h +++ b/src/core/loader/xci.h | |||
| @@ -37,7 +37,9 @@ public: | |||
| 37 | 37 | ||
| 38 | ResultStatus Load(Kernel::Process& process) override; | 38 | ResultStatus Load(Kernel::Process& process) override; |
| 39 | 39 | ||
| 40 | ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; | 40 | ResultStatus ReadRomFS(FileSys::VirtualFile& file) override; |
| 41 | u64 ReadRomFSIVFCOffset() const override; | ||
| 42 | ResultStatus ReadUpdateRaw(FileSys::VirtualFile& file) override; | ||
| 41 | ResultStatus ReadProgramId(u64& out_program_id) override; | 43 | ResultStatus ReadProgramId(u64& out_program_id) override; |
| 42 | ResultStatus ReadIcon(std::vector<u8>& buffer) override; | 44 | ResultStatus ReadIcon(std::vector<u8>& buffer) override; |
| 43 | ResultStatus ReadTitle(std::string& title) override; | 45 | ResultStatus ReadTitle(std::string& title) override; |