diff options
| author | 2018-08-11 10:35:47 +1000 | |
|---|---|---|
| committer | 2018-08-11 10:35:47 +1000 | |
| commit | b76ddb7647cbb390cce4143d91a1db171b0fa503 (patch) | |
| tree | a6e2e334e82b035923c41458150604dd5fb31d65 /src/core/loader | |
| parent | Added IsUserRegistrationRequestPermitted (diff) | |
| parent | Merge pull request #1007 from MerryMage/dynarmic (diff) | |
| download | yuzu-b76ddb7647cbb390cce4143d91a1db171b0fa503.tar.gz yuzu-b76ddb7647cbb390cce4143d91a1db171b0fa503.tar.xz yuzu-b76ddb7647cbb390cce4143d91a1db171b0fa503.zip | |
Merge remote-tracking branch 'origin/master' into better-account
Diffstat (limited to 'src/core/loader')
| -rw-r--r-- | src/core/loader/deconstructed_rom_directory.cpp | 68 | ||||
| -rw-r--r-- | src/core/loader/deconstructed_rom_directory.h | 7 | ||||
| -rw-r--r-- | src/core/loader/loader.cpp | 6 | ||||
| -rw-r--r-- | src/core/loader/loader.h | 10 | ||||
| -rw-r--r-- | src/core/loader/nca.cpp | 4 | ||||
| -rw-r--r-- | src/core/loader/nca.h | 2 | ||||
| -rw-r--r-- | src/core/loader/xci.cpp | 33 | ||||
| -rw-r--r-- | src/core/loader/xci.h | 5 |
8 files changed, 115 insertions, 20 deletions
diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp index 9a8cdd0ff..915d525b0 100644 --- a/src/core/loader/deconstructed_rom_directory.cpp +++ b/src/core/loader/deconstructed_rom_directory.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include "common/file_util.h" | 7 | #include "common/file_util.h" |
| 8 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 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/gdbstub/gdbstub.h" | 11 | #include "core/gdbstub/gdbstub.h" |
| 11 | #include "core/hle/kernel/process.h" | 12 | #include "core/hle/kernel/process.h" |
| 12 | #include "core/hle/kernel/resource_limit.h" | 13 | #include "core/hle/kernel/resource_limit.h" |
| @@ -17,8 +18,50 @@ | |||
| 17 | 18 | ||
| 18 | namespace Loader { | 19 | namespace Loader { |
| 19 | 20 | ||
| 20 | AppLoader_DeconstructedRomDirectory::AppLoader_DeconstructedRomDirectory(FileSys::VirtualFile file) | 21 | AppLoader_DeconstructedRomDirectory::AppLoader_DeconstructedRomDirectory(FileSys::VirtualFile file_) |
| 21 | : AppLoader(std::move(file)) {} | 22 | : AppLoader(std::move(file_)) { |
| 23 | const auto dir = file->GetContainingDirectory(); | ||
| 24 | |||
| 25 | // Icon | ||
| 26 | FileSys::VirtualFile icon_file = nullptr; | ||
| 27 | for (const auto& language : FileSys::LANGUAGE_NAMES) { | ||
| 28 | icon_file = dir->GetFile("icon_" + std::string(language) + ".dat"); | ||
| 29 | if (icon_file != nullptr) { | ||
| 30 | icon_data = icon_file->ReadAllBytes(); | ||
| 31 | break; | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | if (icon_data.empty()) { | ||
| 36 | // Any png, jpeg, or bmp file | ||
| 37 | const auto& files = dir->GetFiles(); | ||
| 38 | const auto icon_iter = | ||
| 39 | std::find_if(files.begin(), files.end(), [](const FileSys::VirtualFile& file) { | ||
| 40 | return file->GetExtension() == "png" || file->GetExtension() == "jpg" || | ||
| 41 | file->GetExtension() == "bmp" || file->GetExtension() == "jpeg"; | ||
| 42 | }); | ||
| 43 | if (icon_iter != files.end()) | ||
| 44 | icon_data = (*icon_iter)->ReadAllBytes(); | ||
| 45 | } | ||
| 46 | |||
| 47 | // Metadata | ||
| 48 | FileSys::VirtualFile nacp_file = dir->GetFile("control.nacp"); | ||
| 49 | if (nacp_file == nullptr) { | ||
| 50 | const auto& files = dir->GetFiles(); | ||
| 51 | const auto nacp_iter = | ||
| 52 | std::find_if(files.begin(), files.end(), [](const FileSys::VirtualFile& file) { | ||
| 53 | return file->GetExtension() == "nacp"; | ||
| 54 | }); | ||
| 55 | if (nacp_iter != files.end()) | ||
| 56 | nacp_file = *nacp_iter; | ||
| 57 | } | ||
| 58 | |||
| 59 | if (nacp_file != nullptr) { | ||
| 60 | FileSys::NACP nacp(nacp_file); | ||
| 61 | title_id = nacp.GetTitleId(); | ||
| 62 | name = nacp.GetApplicationName(); | ||
| 63 | } | ||
| 64 | } | ||
| 22 | 65 | ||
| 23 | AppLoader_DeconstructedRomDirectory::AppLoader_DeconstructedRomDirectory( | 66 | AppLoader_DeconstructedRomDirectory::AppLoader_DeconstructedRomDirectory( |
| 24 | FileSys::VirtualDir directory) | 67 | FileSys::VirtualDir directory) |
| @@ -105,4 +148,25 @@ ResultStatus AppLoader_DeconstructedRomDirectory::ReadRomFS(FileSys::VirtualFile | |||
| 105 | return ResultStatus::Success; | 148 | return ResultStatus::Success; |
| 106 | } | 149 | } |
| 107 | 150 | ||
| 151 | ResultStatus AppLoader_DeconstructedRomDirectory::ReadIcon(std::vector<u8>& buffer) { | ||
| 152 | if (icon_data.empty()) | ||
| 153 | return ResultStatus::ErrorNotUsed; | ||
| 154 | buffer = icon_data; | ||
| 155 | return ResultStatus::Success; | ||
| 156 | } | ||
| 157 | |||
| 158 | ResultStatus AppLoader_DeconstructedRomDirectory::ReadProgramId(u64& out_program_id) { | ||
| 159 | if (name.empty()) | ||
| 160 | return ResultStatus::ErrorNotUsed; | ||
| 161 | out_program_id = title_id; | ||
| 162 | return ResultStatus::Success; | ||
| 163 | } | ||
| 164 | |||
| 165 | ResultStatus AppLoader_DeconstructedRomDirectory::ReadTitle(std::string& title) { | ||
| 166 | if (name.empty()) | ||
| 167 | return ResultStatus::ErrorNotUsed; | ||
| 168 | title = name; | ||
| 169 | return ResultStatus::Success; | ||
| 170 | } | ||
| 171 | |||
| 108 | } // namespace Loader | 172 | } // namespace Loader |
diff --git a/src/core/loader/deconstructed_rom_directory.h b/src/core/loader/deconstructed_rom_directory.h index 7d5433563..b20804f75 100644 --- a/src/core/loader/deconstructed_rom_directory.h +++ b/src/core/loader/deconstructed_rom_directory.h | |||
| @@ -39,11 +39,18 @@ public: | |||
| 39 | ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; | 39 | ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; |
| 40 | 40 | ||
| 41 | ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; | 41 | ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; |
| 42 | ResultStatus ReadIcon(std::vector<u8>& buffer) override; | ||
| 43 | ResultStatus ReadProgramId(u64& out_program_id) override; | ||
| 44 | ResultStatus ReadTitle(std::string& title) override; | ||
| 42 | 45 | ||
| 43 | private: | 46 | private: |
| 44 | FileSys::ProgramMetadata metadata; | 47 | FileSys::ProgramMetadata metadata; |
| 45 | FileSys::VirtualFile romfs; | 48 | FileSys::VirtualFile romfs; |
| 46 | FileSys::VirtualDir dir; | 49 | FileSys::VirtualDir dir; |
| 50 | |||
| 51 | std::vector<u8> icon_data; | ||
| 52 | std::string name; | ||
| 53 | u64 title_id{}; | ||
| 47 | }; | 54 | }; |
| 48 | 55 | ||
| 49 | } // namespace Loader | 56 | } // namespace Loader |
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index 57e6c0365..a288654df 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp | |||
| @@ -43,10 +43,6 @@ FileType IdentifyFile(FileSys::VirtualFile file) { | |||
| 43 | return FileType::Unknown; | 43 | return FileType::Unknown; |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | FileType IdentifyFile(const std::string& file_name) { | ||
| 47 | return IdentifyFile(std::make_shared<FileSys::RealVfsFile>(file_name)); | ||
| 48 | } | ||
| 49 | |||
| 50 | FileType GuessFromFilename(const std::string& name) { | 46 | FileType GuessFromFilename(const std::string& name) { |
| 51 | if (name == "main") | 47 | if (name == "main") |
| 52 | return FileType::DeconstructedRomDirectory; | 48 | return FileType::DeconstructedRomDirectory; |
| @@ -68,7 +64,7 @@ FileType GuessFromFilename(const std::string& name) { | |||
| 68 | return FileType::Unknown; | 64 | return FileType::Unknown; |
| 69 | } | 65 | } |
| 70 | 66 | ||
| 71 | const char* GetFileTypeString(FileType type) { | 67 | std::string GetFileTypeString(FileType type) { |
| 72 | switch (type) { | 68 | switch (type) { |
| 73 | case FileType::ELF: | 69 | case FileType::ELF: |
| 74 | return "ELF"; | 70 | return "ELF"; |
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index e69ab85ef..6a9e5a68b 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h | |||
| @@ -43,14 +43,6 @@ enum class FileType { | |||
| 43 | FileType IdentifyFile(FileSys::VirtualFile file); | 43 | FileType IdentifyFile(FileSys::VirtualFile file); |
| 44 | 44 | ||
| 45 | /** | 45 | /** |
| 46 | * Identifies the type of a bootable file based on the magic value in its header. | ||
| 47 | * @param file_name path to file | ||
| 48 | * @return FileType of file. Note: this will return FileType::Unknown if it is unable to determine | ||
| 49 | * a filetype, and will never return FileType::Error. | ||
| 50 | */ | ||
| 51 | FileType IdentifyFile(const std::string& file_name); | ||
| 52 | |||
| 53 | /** | ||
| 54 | * Guess the type of a bootable file from its name | 46 | * Guess the type of a bootable file from its name |
| 55 | * @param name String name of bootable file | 47 | * @param name String name of bootable file |
| 56 | * @return FileType of file. Note: this will return FileType::Unknown if it is unable to determine | 48 | * @return FileType of file. Note: this will return FileType::Unknown if it is unable to determine |
| @@ -61,7 +53,7 @@ FileType GuessFromFilename(const std::string& name); | |||
| 61 | /** | 53 | /** |
| 62 | * Convert a FileType into a string which can be displayed to the user. | 54 | * Convert a FileType into a string which can be displayed to the user. |
| 63 | */ | 55 | */ |
| 64 | const char* GetFileTypeString(FileType type); | 56 | std::string GetFileTypeString(FileType type); |
| 65 | 57 | ||
| 66 | /// Return type for functions in Loader namespace | 58 | /// Return type for functions in Loader namespace |
| 67 | enum class ResultStatus { | 59 | enum class ResultStatus { |
diff --git a/src/core/loader/nca.cpp b/src/core/loader/nca.cpp index dbc67c0b5..46f5cd393 100644 --- a/src/core/loader/nca.cpp +++ b/src/core/loader/nca.cpp | |||
| @@ -77,8 +77,8 @@ ResultStatus AppLoader_NCA::ReadRomFS(FileSys::VirtualFile& dir) { | |||
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | ResultStatus AppLoader_NCA::ReadProgramId(u64& out_program_id) { | 79 | ResultStatus AppLoader_NCA::ReadProgramId(u64& out_program_id) { |
| 80 | if (nca == nullptr) | 80 | if (nca == nullptr || nca->GetStatus() != ResultStatus::Success) |
| 81 | return ResultStatus::ErrorNotLoaded; | 81 | return ResultStatus::ErrorInvalidFormat; |
| 82 | out_program_id = nca->GetTitleId(); | 82 | out_program_id = nca->GetTitleId(); |
| 83 | return ResultStatus::Success; | 83 | return ResultStatus::Success; |
| 84 | } | 84 | } |
diff --git a/src/core/loader/nca.h b/src/core/loader/nca.h index 0fd2d0417..7f7d8ea0b 100644 --- a/src/core/loader/nca.h +++ b/src/core/loader/nca.h | |||
| @@ -33,7 +33,6 @@ public: | |||
| 33 | ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; | 33 | ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; |
| 34 | 34 | ||
| 35 | ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; | 35 | ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; |
| 36 | |||
| 37 | ResultStatus ReadProgramId(u64& out_program_id) override; | 36 | ResultStatus ReadProgramId(u64& out_program_id) override; |
| 38 | 37 | ||
| 39 | ~AppLoader_NCA(); | 38 | ~AppLoader_NCA(); |
| @@ -41,6 +40,7 @@ public: | |||
| 41 | private: | 40 | private: |
| 42 | FileSys::ProgramMetadata metadata; | 41 | FileSys::ProgramMetadata metadata; |
| 43 | 42 | ||
| 43 | FileSys::NCAHeader header; | ||
| 44 | std::unique_ptr<FileSys::NCA> nca; | 44 | std::unique_ptr<FileSys::NCA> nca; |
| 45 | std::unique_ptr<AppLoader_DeconstructedRomDirectory> directory_loader; | 45 | std::unique_ptr<AppLoader_DeconstructedRomDirectory> directory_loader; |
| 46 | }; | 46 | }; |
diff --git a/src/core/loader/xci.cpp b/src/core/loader/xci.cpp index eb4dee2c2..d3fe24419 100644 --- a/src/core/loader/xci.cpp +++ b/src/core/loader/xci.cpp | |||
| @@ -26,7 +26,25 @@ namespace Loader { | |||
| 26 | AppLoader_XCI::AppLoader_XCI(FileSys::VirtualFile file) | 26 | AppLoader_XCI::AppLoader_XCI(FileSys::VirtualFile file) |
| 27 | : AppLoader(file), xci(std::make_unique<FileSys::XCI>(file)), | 27 | : AppLoader(file), xci(std::make_unique<FileSys::XCI>(file)), |
| 28 | nca_loader(std::make_unique<AppLoader_NCA>( | 28 | nca_loader(std::make_unique<AppLoader_NCA>( |
| 29 | xci->GetNCAFileByType(FileSys::NCAContentType::Program))) {} | 29 | xci->GetNCAFileByType(FileSys::NCAContentType::Program))) { |
| 30 | if (xci->GetStatus() != ResultStatus::Success) | ||
| 31 | return; | ||
| 32 | const auto control_nca = xci->GetNCAByType(FileSys::NCAContentType::Control); | ||
| 33 | if (control_nca == nullptr || control_nca->GetStatus() != ResultStatus::Success) | ||
| 34 | return; | ||
| 35 | const auto romfs = FileSys::ExtractRomFS(control_nca->GetRomFS()); | ||
| 36 | if (romfs == nullptr) | ||
| 37 | return; | ||
| 38 | for (const auto& language : FileSys::LANGUAGE_NAMES) { | ||
| 39 | icon_file = romfs->GetFile("icon_" + std::string(language) + ".dat"); | ||
| 40 | if (icon_file != nullptr) | ||
| 41 | break; | ||
| 42 | } | ||
| 43 | const auto nacp_raw = romfs->GetFile("control.nacp"); | ||
| 44 | if (nacp_raw == nullptr) | ||
| 45 | return; | ||
| 46 | nacp_file = std::make_shared<FileSys::NACP>(nacp_raw); | ||
| 47 | } | ||
| 30 | 48 | ||
| 31 | AppLoader_XCI::~AppLoader_XCI() = default; | 49 | AppLoader_XCI::~AppLoader_XCI() = default; |
| 32 | 50 | ||
| @@ -71,4 +89,17 @@ ResultStatus AppLoader_XCI::ReadProgramId(u64& out_program_id) { | |||
| 71 | return nca_loader->ReadProgramId(out_program_id); | 89 | return nca_loader->ReadProgramId(out_program_id); |
| 72 | } | 90 | } |
| 73 | 91 | ||
| 92 | ResultStatus AppLoader_XCI::ReadIcon(std::vector<u8>& buffer) { | ||
| 93 | if (icon_file == nullptr) | ||
| 94 | return ResultStatus::ErrorInvalidFormat; | ||
| 95 | buffer = icon_file->ReadAllBytes(); | ||
| 96 | return ResultStatus::Success; | ||
| 97 | } | ||
| 98 | |||
| 99 | ResultStatus AppLoader_XCI::ReadTitle(std::string& title) { | ||
| 100 | if (nacp_file == nullptr) | ||
| 101 | return ResultStatus::ErrorInvalidFormat; | ||
| 102 | title = nacp_file->GetApplicationName(); | ||
| 103 | return ResultStatus::Success; | ||
| 104 | } | ||
| 74 | } // namespace Loader | 105 | } // namespace Loader |
diff --git a/src/core/loader/xci.h b/src/core/loader/xci.h index 0dbcfbdf8..973833050 100644 --- a/src/core/loader/xci.h +++ b/src/core/loader/xci.h | |||
| @@ -33,12 +33,17 @@ public: | |||
| 33 | 33 | ||
| 34 | ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; | 34 | ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; |
| 35 | ResultStatus ReadProgramId(u64& out_program_id) override; | 35 | ResultStatus ReadProgramId(u64& out_program_id) override; |
| 36 | ResultStatus ReadIcon(std::vector<u8>& buffer) override; | ||
| 37 | ResultStatus ReadTitle(std::string& title) override; | ||
| 36 | 38 | ||
| 37 | private: | 39 | private: |
| 38 | FileSys::ProgramMetadata metadata; | 40 | FileSys::ProgramMetadata metadata; |
| 39 | 41 | ||
| 40 | std::unique_ptr<FileSys::XCI> xci; | 42 | std::unique_ptr<FileSys::XCI> xci; |
| 41 | std::unique_ptr<AppLoader_NCA> nca_loader; | 43 | std::unique_ptr<AppLoader_NCA> nca_loader; |
| 44 | |||
| 45 | FileSys::VirtualFile icon_file; | ||
| 46 | std::shared_ptr<FileSys::NACP> nacp_file; | ||
| 42 | }; | 47 | }; |
| 43 | 48 | ||
| 44 | } // namespace Loader | 49 | } // namespace Loader |