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/loader.cpp | |
| 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/loader.cpp')
| -rw-r--r-- | src/core/loader/loader.cpp | 50 |
1 files changed, 7 insertions, 43 deletions
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 |