summaryrefslogtreecommitdiffstats
path: root/src/core/loader/loader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/loader/loader.cpp')
-rw-r--r--src/core/loader/loader.cpp51
1 files changed, 31 insertions, 20 deletions
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp
index b1907cd55..0d4c1d351 100644
--- a/src/core/loader/loader.cpp
+++ b/src/core/loader/loader.cpp
@@ -6,7 +6,6 @@
#include <string>
#include "common/logging/log.h"
-#include "common/make_unique.h"
#include "common/string_util.h"
#include "core/file_sys/archive_romfs.h"
@@ -91,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()) {
@@ -112,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(Common::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;
@@ -128,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(Common::make_unique<FileSys::ArchiveFactory_RomFS>(app_loader), Service::FS::ArchiveIdCode::RomFS);
- }
- return result;
- }
+ return app_loader->Load();
// CIA file format...
case FileType::CIA: