|
|
|
@ -8,9 +8,7 @@
|
|
|
|
|
#include "common/logging/log.h"
|
|
|
|
|
#include "common/string_util.h"
|
|
|
|
|
|
|
|
|
|
#include "core/file_sys/archive_romfs.h"
|
|
|
|
|
#include "core/hle/kernel/process.h"
|
|
|
|
|
#include "core/hle/service/fs/archive.h"
|
|
|
|
|
#include "core/loader/3dsx.h"
|
|
|
|
|
#include "core/loader/elf.h"
|
|
|
|
|
#include "core/loader/ncch.h"
|
|
|
|
@ -67,6 +65,9 @@ FileType GuessFromExtension(const std::string& extension_) {
|
|
|
|
|
if (extension == ".3dsx")
|
|
|
|
|
return FileType::THREEDSX;
|
|
|
|
|
|
|
|
|
|
if (extension == ".cia")
|
|
|
|
|
return FileType::CIA;
|
|
|
|
|
|
|
|
|
|
return FileType::Unknown;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -108,15 +109,15 @@ std::unique_ptr<AppLoader> GetLoader(FileUtil::IOFile&& file, FileType type,
|
|
|
|
|
return std::make_unique<AppLoader_NCCH>(std::move(file), filepath);
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return std::unique_ptr<AppLoader>();
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ResultStatus LoadFile(const std::string& filename) {
|
|
|
|
|
std::unique_ptr<AppLoader> GetFileLoader(const std::string& filename) {
|
|
|
|
|
FileUtil::IOFile file(filename, "rb");
|
|
|
|
|
if (!file.IsOpen()) {
|
|
|
|
|
LOG_ERROR(Loader, "Failed to load file %s", filename.c_str());
|
|
|
|
|
return ResultStatus::Error;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string filename_filename, filename_extension;
|
|
|
|
@ -133,44 +134,7 @@ 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...
|
|
|
|
|
// or NCCH/NCSD container formats...
|
|
|
|
|
case FileType::THREEDSX:
|
|
|
|
|
case FileType::CXI:
|
|
|
|
|
case FileType::CCI:
|
|
|
|
|
{
|
|
|
|
|
// 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 ResultStatus::Success;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Standard ELF file format...
|
|
|
|
|
case FileType::ELF:
|
|
|
|
|
return app_loader->Load();
|
|
|
|
|
|
|
|
|
|
// CIA file format...
|
|
|
|
|
case FileType::CIA:
|
|
|
|
|
return ResultStatus::ErrorNotImplemented;
|
|
|
|
|
|
|
|
|
|
// Error occurred durring IdentifyFile...
|
|
|
|
|
case FileType::Error:
|
|
|
|
|
|
|
|
|
|
// IdentifyFile could know identify file type...
|
|
|
|
|
case FileType::Unknown:
|
|
|
|
|
{
|
|
|
|
|
LOG_CRITICAL(Loader, "File %s is of unknown type.", filename.c_str());
|
|
|
|
|
return ResultStatus::ErrorInvalidFormat;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ResultStatus::Error;
|
|
|
|
|
return GetLoader(std::move(file), type, filename_filename, filename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Loader
|
|
|
|
|