2018-06-21 11:16:23 -04:00
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-07-20 00:10:21 -04:00
|
|
|
#include <utility>
|
2018-06-21 11:16:23 -04:00
|
|
|
|
|
|
|
#include "common/file_util.h"
|
|
|
|
#include "common/logging/log.h"
|
2018-07-18 21:07:11 -04:00
|
|
|
#include "core/file_sys/content_archive.h"
|
2018-08-20 20:36:36 -04:00
|
|
|
#include "core/file_sys/romfs_factory.h"
|
2018-06-21 11:16:23 -04:00
|
|
|
#include "core/hle/kernel/process.h"
|
|
|
|
#include "core/hle/service/filesystem/filesystem.h"
|
2018-08-14 22:37:12 -04:00
|
|
|
#include "core/loader/deconstructed_rom_directory.h"
|
2018-06-21 11:16:23 -04:00
|
|
|
#include "core/loader/nca.h"
|
|
|
|
|
|
|
|
namespace Loader {
|
|
|
|
|
2018-08-05 18:27:05 -04:00
|
|
|
AppLoader_NCA::AppLoader_NCA(FileSys::VirtualFile file_)
|
|
|
|
: AppLoader(std::move(file_)), nca(std::make_unique<FileSys::NCA>(file)) {}
|
2018-06-21 11:16:23 -04:00
|
|
|
|
2018-08-14 22:37:12 -04:00
|
|
|
AppLoader_NCA::~AppLoader_NCA() = default;
|
|
|
|
|
2018-07-18 21:07:11 -04:00
|
|
|
FileType AppLoader_NCA::IdentifyType(const FileSys::VirtualFile& file) {
|
2018-07-27 23:55:23 -04:00
|
|
|
FileSys::NCA nca(file);
|
2018-07-07 23:24:51 -04:00
|
|
|
|
2018-07-27 23:55:23 -04:00
|
|
|
if (nca.GetStatus() == ResultStatus::Success &&
|
|
|
|
nca.GetType() == FileSys::NCAContentType::Program)
|
2018-06-21 11:16:23 -04:00
|
|
|
return FileType::NCA;
|
|
|
|
|
|
|
|
return FileType::Error;
|
|
|
|
}
|
|
|
|
|
2019-04-09 17:03:04 -04:00
|
|
|
AppLoader_NCA::LoadResult AppLoader_NCA::Load(Kernel::Process& process) {
|
2018-06-21 11:16:23 -04:00
|
|
|
if (is_loaded) {
|
2019-04-09 17:03:04 -04:00
|
|
|
return {ResultStatus::ErrorAlreadyLoaded, {}};
|
2018-06-21 11:16:23 -04:00
|
|
|
}
|
|
|
|
|
2018-08-05 18:27:05 -04:00
|
|
|
const auto result = nca->GetStatus();
|
2018-06-21 11:16:23 -04:00
|
|
|
if (result != ResultStatus::Success) {
|
2019-04-09 17:03:04 -04:00
|
|
|
return {result, {}};
|
2018-06-21 11:16:23 -04:00
|
|
|
}
|
|
|
|
|
2019-04-09 17:03:04 -04:00
|
|
|
if (nca->GetType() != FileSys::NCAContentType::Program) {
|
|
|
|
return {ResultStatus::ErrorNCANotProgram, {}};
|
|
|
|
}
|
2018-07-18 21:07:11 -04:00
|
|
|
|
2018-08-05 18:27:05 -04:00
|
|
|
const auto exefs = nca->GetExeFS();
|
2019-04-09 17:03:04 -04:00
|
|
|
if (exefs == nullptr) {
|
|
|
|
return {ResultStatus::ErrorNoExeFS, {}};
|
|
|
|
}
|
2018-07-18 21:07:11 -04:00
|
|
|
|
2018-08-25 19:04:48 -04:00
|
|
|
directory_loader = std::make_unique<AppLoader_DeconstructedRomDirectory>(exefs, true);
|
2018-06-21 11:16:23 -04:00
|
|
|
|
2018-08-05 18:27:05 -04:00
|
|
|
const auto load_result = directory_loader->Load(process);
|
2019-04-09 17:03:04 -04:00
|
|
|
if (load_result.first != ResultStatus::Success) {
|
2018-08-05 18:27:05 -04:00
|
|
|
return load_result;
|
2019-04-09 17:03:04 -04:00
|
|
|
}
|
2018-06-21 11:16:23 -04:00
|
|
|
|
2019-04-09 17:03:04 -04:00
|
|
|
if (nca->GetRomFS() != nullptr && nca->GetRomFS()->GetSize() > 0) {
|
2018-07-17 15:42:15 -04:00
|
|
|
Service::FileSystem::RegisterRomFS(std::make_unique<FileSys::RomFSFactory>(*this));
|
2019-04-09 17:03:04 -04:00
|
|
|
}
|
2018-07-07 23:24:51 -04:00
|
|
|
|
2018-06-21 11:16:23 -04:00
|
|
|
is_loaded = true;
|
2019-04-09 17:03:04 -04:00
|
|
|
return load_result;
|
2018-07-07 23:24:51 -04:00
|
|
|
}
|
|
|
|
|
2018-07-18 21:07:11 -04:00
|
|
|
ResultStatus AppLoader_NCA::ReadRomFS(FileSys::VirtualFile& dir) {
|
2018-07-27 23:55:23 -04:00
|
|
|
if (nca == nullptr)
|
2018-08-09 21:06:44 -04:00
|
|
|
return ResultStatus::ErrorNotInitialized;
|
2018-07-27 23:55:23 -04:00
|
|
|
if (nca->GetRomFS() == nullptr || nca->GetRomFS()->GetSize() == 0)
|
2018-08-09 21:06:44 -04:00
|
|
|
return ResultStatus::ErrorNoRomFS;
|
2018-07-18 21:07:11 -04:00
|
|
|
dir = nca->GetRomFS();
|
2018-06-21 11:16:23 -04:00
|
|
|
return ResultStatus::Success;
|
|
|
|
}
|
|
|
|
|
2018-08-28 22:37:42 -04:00
|
|
|
u64 AppLoader_NCA::ReadRomFSIVFCOffset() const {
|
|
|
|
if (nca == nullptr)
|
|
|
|
return 0;
|
|
|
|
return nca->GetBaseIVFCOffset();
|
|
|
|
}
|
|
|
|
|
2018-07-27 23:55:23 -04:00
|
|
|
ResultStatus AppLoader_NCA::ReadProgramId(u64& out_program_id) {
|
2018-07-28 12:32:16 -04:00
|
|
|
if (nca == nullptr || nca->GetStatus() != ResultStatus::Success)
|
2018-08-09 21:06:44 -04:00
|
|
|
return ResultStatus::ErrorNotInitialized;
|
2018-07-27 23:55:23 -04:00
|
|
|
out_program_id = nca->GetTitleId();
|
|
|
|
return ResultStatus::Success;
|
|
|
|
}
|
|
|
|
|
2019-01-15 15:56:52 -05:00
|
|
|
ResultStatus AppLoader_NCA::ReadBanner(std::vector<u8>& buffer) {
|
|
|
|
if (nca == nullptr || nca->GetStatus() != ResultStatus::Success)
|
|
|
|
return ResultStatus::ErrorNotInitialized;
|
|
|
|
const auto logo = nca->GetLogoPartition();
|
|
|
|
if (logo == nullptr)
|
|
|
|
return ResultStatus::ErrorNoIcon;
|
|
|
|
buffer = logo->GetFile("StartupMovie.gif")->ReadAllBytes();
|
|
|
|
return ResultStatus::Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultStatus AppLoader_NCA::ReadLogo(std::vector<u8>& buffer) {
|
|
|
|
if (nca == nullptr || nca->GetStatus() != ResultStatus::Success)
|
|
|
|
return ResultStatus::ErrorNotInitialized;
|
|
|
|
const auto logo = nca->GetLogoPartition();
|
|
|
|
if (logo == nullptr)
|
|
|
|
return ResultStatus::ErrorNoIcon;
|
|
|
|
buffer = logo->GetFile("NintendoLogo.png")->ReadAllBytes();
|
|
|
|
return ResultStatus::Success;
|
|
|
|
}
|
2019-05-26 11:40:41 -04:00
|
|
|
|
|
|
|
ResultStatus AppLoader_NCA::ReadNSOModules(Modules& modules) {
|
|
|
|
if (directory_loader == nullptr) {
|
|
|
|
return ResultStatus::ErrorNotInitialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
return directory_loader->ReadNSOModules(modules);
|
|
|
|
}
|
|
|
|
|
2018-06-21 11:16:23 -04:00
|
|
|
} // namespace Loader
|