diff options
| author | 2016-05-17 23:06:33 +0100 | |
|---|---|---|
| committer | 2016-05-21 17:09:56 +0100 | |
| commit | 8fc9c0312660aa8b74a1251f02dfedc84da5b96b (patch) | |
| tree | 490fc1f96a96654b59c933c864aa792161399cbb /src/core/loader | |
| parent | Appveyor: Restore working directory after test_script (#1835) (diff) | |
| download | yuzu-8fc9c0312660aa8b74a1251f02dfedc84da5b96b.tar.gz yuzu-8fc9c0312660aa8b74a1251f02dfedc84da5b96b.tar.xz yuzu-8fc9c0312660aa8b74a1251f02dfedc84da5b96b.zip | |
Loader, Frontends: Refactor loader creation and game loading
This allows frontends to keep a single loader and use it multiple times
e.g. for code loading and SMDH parsing.
Diffstat (limited to 'src/core/loader')
| -rw-r--r-- | src/core/loader/3dsx.cpp | 3 | ||||
| -rw-r--r-- | src/core/loader/loader.cpp | 50 | ||||
| -rw-r--r-- | src/core/loader/loader.h | 6 | ||||
| -rw-r--r-- | src/core/loader/ncch.cpp | 9 |
4 files changed, 21 insertions, 47 deletions
diff --git a/src/core/loader/3dsx.cpp b/src/core/loader/3dsx.cpp index 98e7ab48f..a16411e14 100644 --- a/src/core/loader/3dsx.cpp +++ b/src/core/loader/3dsx.cpp | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | #include "core/file_sys/archive_romfs.h" | 10 | #include "core/file_sys/archive_romfs.h" |
| 11 | #include "core/hle/kernel/process.h" | 11 | #include "core/hle/kernel/process.h" |
| 12 | #include "core/hle/kernel/resource_limit.h" | 12 | #include "core/hle/kernel/resource_limit.h" |
| 13 | #include "core/hle/service/fs/archive.h" | ||
| 13 | #include "core/loader/3dsx.h" | 14 | #include "core/loader/3dsx.h" |
| 14 | #include "core/memory.h" | 15 | #include "core/memory.h" |
| 15 | 16 | ||
| @@ -263,6 +264,8 @@ ResultStatus AppLoader_THREEDSX::Load() { | |||
| 263 | 264 | ||
| 264 | Kernel::g_current_process->Run(48, Kernel::DEFAULT_STACK_SIZE); | 265 | Kernel::g_current_process->Run(48, Kernel::DEFAULT_STACK_SIZE); |
| 265 | 266 | ||
| 267 | Service::FS::RegisterArchiveType(std::make_unique<FileSys::ArchiveFactory_RomFS>(*this), Service::FS::ArchiveIdCode::RomFS); | ||
| 268 | |||
| 266 | is_loaded = true; | 269 | is_loaded = true; |
| 267 | return ResultStatus::Success; | 270 | return ResultStatus::Success; |
| 268 | } | 271 | } |
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index af3f62248..c82688026 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp | |||
| @@ -8,9 +8,7 @@ | |||
| 8 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 9 | #include "common/string_util.h" | 9 | #include "common/string_util.h" |
| 10 | 10 | ||
| 11 | #include "core/file_sys/archive_romfs.h" | ||
| 12 | #include "core/hle/kernel/process.h" | 11 | #include "core/hle/kernel/process.h" |
| 13 | #include "core/hle/service/fs/archive.h" | ||
| 14 | #include "core/loader/3dsx.h" | 12 | #include "core/loader/3dsx.h" |
| 15 | #include "core/loader/elf.h" | 13 | #include "core/loader/elf.h" |
| 16 | #include "core/loader/ncch.h" | 14 | #include "core/loader/ncch.h" |
| @@ -67,6 +65,9 @@ FileType GuessFromExtension(const std::string& extension_) { | |||
| 67 | if (extension == ".3dsx") | 65 | if (extension == ".3dsx") |
| 68 | return FileType::THREEDSX; | 66 | return FileType::THREEDSX; |
| 69 | 67 | ||
| 68 | if (extension == ".cia") | ||
| 69 | return FileType::CIA; | ||
| 70 | |||
| 70 | return FileType::Unknown; | 71 | return FileType::Unknown; |
| 71 | } | 72 | } |
| 72 | 73 | ||
| @@ -108,15 +109,15 @@ std::unique_ptr<AppLoader> GetLoader(FileUtil::IOFile&& file, FileType type, | |||
| 108 | return std::make_unique<AppLoader_NCCH>(std::move(file), filepath); | 109 | return std::make_unique<AppLoader_NCCH>(std::move(file), filepath); |
| 109 | 110 | ||
| 110 | default: | 111 | default: |
| 111 | return std::unique_ptr<AppLoader>(); | 112 | return nullptr; |
| 112 | } | 113 | } |
| 113 | } | 114 | } |
| 114 | 115 | ||
| 115 | ResultStatus LoadFile(const std::string& filename) { | 116 | std::unique_ptr<AppLoader> GetFileLoader(const std::string& filename) { |
| 116 | FileUtil::IOFile file(filename, "rb"); | 117 | FileUtil::IOFile file(filename, "rb"); |
| 117 | if (!file.IsOpen()) { | 118 | if (!file.IsOpen()) { |
| 118 | LOG_ERROR(Loader, "Failed to load file %s", filename.c_str()); | 119 | LOG_ERROR(Loader, "Failed to load file %s", filename.c_str()); |
| 119 | return ResultStatus::Error; | 120 | return nullptr; |
| 120 | } | 121 | } |
| 121 | 122 | ||
| 122 | std::string filename_filename, filename_extension; | 123 | std::string filename_filename, filename_extension; |
| @@ -133,44 +134,7 @@ ResultStatus LoadFile(const std::string& filename) { | |||
| 133 | 134 | ||
| 134 | LOG_INFO(Loader, "Loading file %s as %s...", filename.c_str(), GetFileTypeString(type)); | 135 | LOG_INFO(Loader, "Loading file %s as %s...", filename.c_str(), GetFileTypeString(type)); |
| 135 | 136 | ||
| 136 | std::unique_ptr<AppLoader> app_loader = GetLoader(std::move(file), type, filename_filename, filename); | 137 | return GetLoader(std::move(file), type, filename_filename, filename); |
| 137 | |||
| 138 | switch (type) { | ||
| 139 | |||
| 140 | // 3DSX file format... | ||
| 141 | // or NCCH/NCSD container formats... | ||
| 142 | case FileType::THREEDSX: | ||
| 143 | case FileType::CXI: | ||
| 144 | case FileType::CCI: | ||
| 145 | { | ||
| 146 | // Load application and RomFS | ||
| 147 | ResultStatus result = app_loader->Load(); | ||
| 148 | if (ResultStatus::Success == result) { | ||
| 149 | Service::FS::RegisterArchiveType(std::make_unique<FileSys::ArchiveFactory_RomFS>(*app_loader), Service::FS::ArchiveIdCode::RomFS); | ||
| 150 | return ResultStatus::Success; | ||
| 151 | } | ||
| 152 | return result; | ||
| 153 | } | ||
| 154 | |||
| 155 | // Standard ELF file format... | ||
| 156 | case FileType::ELF: | ||
| 157 | return app_loader->Load(); | ||
| 158 | |||
| 159 | // CIA file format... | ||
| 160 | case FileType::CIA: | ||
| 161 | return ResultStatus::ErrorNotImplemented; | ||
| 162 | |||
| 163 | // Error occurred durring IdentifyFile... | ||
| 164 | case FileType::Error: | ||
| 165 | |||
| 166 | // IdentifyFile could know identify file type... | ||
| 167 | case FileType::Unknown: | ||
| 168 | { | ||
| 169 | LOG_CRITICAL(Loader, "File %s is of unknown type.", filename.c_str()); | ||
| 170 | return ResultStatus::ErrorInvalidFormat; | ||
| 171 | } | ||
| 172 | } | ||
| 173 | return ResultStatus::Error; | ||
| 174 | } | 138 | } |
| 175 | 139 | ||
| 176 | } // namespace Loader | 140 | } // namespace Loader |
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 9d3e9ed3b..4a4bd7c77 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h | |||
| @@ -207,10 +207,10 @@ extern const std::initializer_list<Kernel::AddressMapping> default_address_mappi | |||
| 207 | std::unique_ptr<AppLoader> GetLoader(FileUtil::IOFile&& file, FileType type, const std::string& filename, const std::string& filepath); | 207 | std::unique_ptr<AppLoader> GetLoader(FileUtil::IOFile&& file, FileType type, const std::string& filename, const std::string& filepath); |
| 208 | 208 | ||
| 209 | /** | 209 | /** |
| 210 | * Identifies and loads a bootable file | 210 | * Identifies a bootable file and return a suitable loader |
| 211 | * @param filename String filename of bootable file | 211 | * @param filename String filename of bootable file |
| 212 | * @return ResultStatus result of function | 212 | * @return best loader for this file |
| 213 | */ | 213 | */ |
| 214 | ResultStatus LoadFile(const std::string& filename); | 214 | std::unique_ptr<AppLoader> GetFileLoader(const std::string& filename); |
| 215 | 215 | ||
| 216 | } // namespace | 216 | } // namespace |
diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp index 7391bdb26..fca091ff9 100644 --- a/src/core/loader/ncch.cpp +++ b/src/core/loader/ncch.cpp | |||
| @@ -10,8 +10,10 @@ | |||
| 10 | #include "common/string_util.h" | 10 | #include "common/string_util.h" |
| 11 | #include "common/swap.h" | 11 | #include "common/swap.h" |
| 12 | 12 | ||
| 13 | #include "core/file_sys/archive_romfs.h" | ||
| 13 | #include "core/hle/kernel/process.h" | 14 | #include "core/hle/kernel/process.h" |
| 14 | #include "core/hle/kernel/resource_limit.h" | 15 | #include "core/hle/kernel/resource_limit.h" |
| 16 | #include "core/hle/service/fs/archive.h" | ||
| 15 | #include "core/loader/ncch.h" | 17 | #include "core/loader/ncch.h" |
| 16 | #include "core/memory.h" | 18 | #include "core/memory.h" |
| 17 | 19 | ||
| @@ -303,7 +305,12 @@ ResultStatus AppLoader_NCCH::Load() { | |||
| 303 | 305 | ||
| 304 | is_loaded = true; // Set state to loaded | 306 | is_loaded = true; // Set state to loaded |
| 305 | 307 | ||
| 306 | return LoadExec(); // Load the executable into memory for booting | 308 | result = LoadExec(); // Load the executable into memory for booting |
| 309 | if (ResultStatus::Success != result) | ||
| 310 | return result; | ||
| 311 | |||
| 312 | Service::FS::RegisterArchiveType(std::make_unique<FileSys::ArchiveFactory_RomFS>(*this), Service::FS::ArchiveIdCode::RomFS); | ||
| 313 | return ResultStatus::Success; | ||
| 307 | } | 314 | } |
| 308 | 315 | ||
| 309 | ResultStatus AppLoader_NCCH::ReadCode(std::vector<u8>& buffer) { | 316 | ResultStatus AppLoader_NCCH::ReadCode(std::vector<u8>& buffer) { |