summaryrefslogtreecommitdiffstats
path: root/src/core/loader/loader.cpp
diff options
context:
space:
mode:
authorwwylele <wwylele@gmail.com>2016-04-13 23:04:05 +0200
committerwwylele <wwylele@gmail.com>2016-05-04 12:02:49 +0200
commit5d5dd66d9222ced82dd61747ef4078fc1eae2496 (patch)
treee7495d933b0fbdc767426fc18940f95b7817c8ab /src/core/loader/loader.cpp
parentMerge pull request #1726 from MerryMage/read-write-region (diff)
downloadyuzu-5d5dd66d9222ced82dd61747ef4078fc1eae2496.tar
yuzu-5d5dd66d9222ced82dd61747ef4078fc1eae2496.tar.gz
yuzu-5d5dd66d9222ced82dd61747ef4078fc1eae2496.tar.bz2
yuzu-5d5dd66d9222ced82dd61747ef4078fc1eae2496.tar.lz
yuzu-5d5dd66d9222ced82dd61747ef4078fc1eae2496.tar.xz
yuzu-5d5dd66d9222ced82dd61747ef4078fc1eae2496.tar.zst
yuzu-5d5dd66d9222ced82dd61747ef4078fc1eae2496.zip
Diffstat (limited to 'src/core/loader/loader.cpp')
-rw-r--r--src/core/loader/loader.cpp50
1 files changed, 31 insertions, 19 deletions
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp
index 886501c41..0d4c1d351 100644
--- a/src/core/loader/loader.cpp
+++ b/src/core/loader/loader.cpp
@@ -90,6 +90,28 @@ const char* GetFileTypeString(FileType type) {
return "unknown";
}
+std::unique_ptr<AppLoader> GetLoader(FileUtil::IOFile&& file, FileType type,
+ const std::string& filename, const std::string& filepath) {
+ switch (type) {
+
+ // 3DSX file format.
+ case FileType::THREEDSX:
+ return std::make_unique<AppLoader_THREEDSX>(std::move(file), filename, filepath);
+
+ // Standard ELF file format.
+ case FileType::ELF:
+ return std::make_unique<AppLoader_ELF>(std::move(file), filename);
+
+ // NCCH/NCSD container formats.
+ case FileType::CXI:
+ case FileType::CCI:
+ return std::make_unique<AppLoader_NCCH>(std::move(file), filepath);
+
+ default:
+ return std::unique_ptr<AppLoader>();
+ }
+}
+
ResultStatus LoadFile(const std::string& filename) {
FileUtil::IOFile file(filename, "rb");
if (!file.IsOpen()) {
@@ -111,15 +133,19 @@ ResultStatus LoadFile(const std::string& filename) {
LOG_INFO(Loader, "Loading file %s as %s...", filename.c_str(), GetFileTypeString(type));
+ std::unique_ptr<AppLoader> app_loader = GetLoader(std::move(file), type, filename_filename, filename);
+
switch (type) {
- //3DSX file format...
+ // 3DSX file format...
+ // or NCCH/NCSD container formats...
case FileType::THREEDSX:
+ case FileType::CXI:
+ case FileType::CCI:
{
- AppLoader_THREEDSX app_loader(std::move(file), filename_filename, filename);
// Load application and RomFS
- if (ResultStatus::Success == app_loader.Load()) {
- Service::FS::RegisterArchiveType(std::make_unique<FileSys::ArchiveFactory_RomFS>(app_loader), Service::FS::ArchiveIdCode::RomFS);
+ if (ResultStatus::Success == app_loader->Load()) {
+ Service::FS::RegisterArchiveType(std::make_unique<FileSys::ArchiveFactory_RomFS>(*app_loader), Service::FS::ArchiveIdCode::RomFS);
return ResultStatus::Success;
}
break;
@@ -127,21 +153,7 @@ ResultStatus LoadFile(const std::string& filename) {
// Standard ELF file format...
case FileType::ELF:
- return AppLoader_ELF(std::move(file), filename_filename).Load();
-
- // NCCH/NCSD container formats...
- case FileType::CXI:
- case FileType::CCI:
- {
- AppLoader_NCCH app_loader(std::move(file), filename);
-
- // Load application and RomFS
- ResultStatus result = app_loader.Load();
- if (ResultStatus::Success == result) {
- Service::FS::RegisterArchiveType(std::make_unique<FileSys::ArchiveFactory_RomFS>(app_loader), Service::FS::ArchiveIdCode::RomFS);
- }
- return result;
- }
+ return app_loader->Load();
// CIA file format...
case FileType::CIA: