diff options
Diffstat (limited to 'src/core/loader/xci.cpp')
| -rw-r--r-- | src/core/loader/xci.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/core/loader/xci.cpp b/src/core/loader/xci.cpp new file mode 100644 index 000000000..eb4dee2c2 --- /dev/null +++ b/src/core/loader/xci.cpp | |||
| @@ -0,0 +1,74 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "common/file_util.h" | ||
| 8 | #include "common/logging/log.h" | ||
| 9 | #include "common/string_util.h" | ||
| 10 | #include "common/swap.h" | ||
| 11 | #include "core/core.h" | ||
| 12 | #include "core/file_sys/content_archive.h" | ||
| 13 | #include "core/file_sys/control_metadata.h" | ||
| 14 | #include "core/file_sys/program_metadata.h" | ||
| 15 | #include "core/file_sys/romfs.h" | ||
| 16 | #include "core/gdbstub/gdbstub.h" | ||
| 17 | #include "core/hle/kernel/process.h" | ||
| 18 | #include "core/hle/kernel/resource_limit.h" | ||
| 19 | #include "core/hle/service/filesystem/filesystem.h" | ||
| 20 | #include "core/loader/nso.h" | ||
| 21 | #include "core/loader/xci.h" | ||
| 22 | #include "core/memory.h" | ||
| 23 | |||
| 24 | namespace Loader { | ||
| 25 | |||
| 26 | AppLoader_XCI::AppLoader_XCI(FileSys::VirtualFile file) | ||
| 27 | : AppLoader(file), xci(std::make_unique<FileSys::XCI>(file)), | ||
| 28 | nca_loader(std::make_unique<AppLoader_NCA>( | ||
| 29 | xci->GetNCAFileByType(FileSys::NCAContentType::Program))) {} | ||
| 30 | |||
| 31 | AppLoader_XCI::~AppLoader_XCI() = default; | ||
| 32 | |||
| 33 | FileType AppLoader_XCI::IdentifyType(const FileSys::VirtualFile& file) { | ||
| 34 | FileSys::XCI xci(file); | ||
| 35 | |||
| 36 | if (xci.GetStatus() == ResultStatus::Success && | ||
| 37 | xci.GetNCAByType(FileSys::NCAContentType::Program) != nullptr && | ||
| 38 | AppLoader_NCA::IdentifyType(xci.GetNCAFileByType(FileSys::NCAContentType::Program)) == | ||
| 39 | FileType::NCA) { | ||
| 40 | return FileType::XCI; | ||
| 41 | } | ||
| 42 | |||
| 43 | return FileType::Error; | ||
| 44 | } | ||
| 45 | |||
| 46 | ResultStatus AppLoader_XCI::Load(Kernel::SharedPtr<Kernel::Process>& process) { | ||
| 47 | if (is_loaded) { | ||
| 48 | return ResultStatus::ErrorAlreadyLoaded; | ||
| 49 | } | ||
| 50 | |||
| 51 | if (xci->GetNCAFileByType(FileSys::NCAContentType::Program) == nullptr) { | ||
| 52 | if (!Core::Crypto::KeyManager::KeyFileExists(false)) | ||
| 53 | return ResultStatus::ErrorMissingKeys; | ||
| 54 | return ResultStatus::ErrorDecrypting; | ||
| 55 | } | ||
| 56 | |||
| 57 | auto result = nca_loader->Load(process); | ||
| 58 | if (result != ResultStatus::Success) | ||
| 59 | return result; | ||
| 60 | |||
| 61 | is_loaded = true; | ||
| 62 | |||
| 63 | return ResultStatus::Success; | ||
| 64 | } | ||
| 65 | |||
| 66 | ResultStatus AppLoader_XCI::ReadRomFS(FileSys::VirtualFile& dir) { | ||
| 67 | return nca_loader->ReadRomFS(dir); | ||
| 68 | } | ||
| 69 | |||
| 70 | ResultStatus AppLoader_XCI::ReadProgramId(u64& out_program_id) { | ||
| 71 | return nca_loader->ReadProgramId(out_program_id); | ||
| 72 | } | ||
| 73 | |||
| 74 | } // namespace Loader | ||