From 1c16700372528665876654da85f486105cb24e71 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 23 Jul 2018 17:19:40 -0400 Subject: nro: Remove unused forward declaration This isn't used anywhere in the header. --- src/core/loader/nro.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/core/loader/nro.h b/src/core/loader/nro.h index 5f3fc40d2..0024ce42b 100644 --- a/src/core/loader/nro.h +++ b/src/core/loader/nro.h @@ -13,8 +13,6 @@ namespace Loader { -struct AssetHeader; - /// Loads an NRO file class AppLoader_NRO final : public AppLoader, Linker { public: -- cgit v1.2.3 From ac8133b9eea3ad66468aaacc093f494d5e46dbbd Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 23 Jul 2018 17:20:29 -0400 Subject: nro: Make constructor explicit Makes it consistent with the other Apploader constructors, and prevents implicit conversions. --- src/core/loader/nro.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/loader/nro.h b/src/core/loader/nro.h index 0024ce42b..fe6104754 100644 --- a/src/core/loader/nro.h +++ b/src/core/loader/nro.h @@ -16,7 +16,7 @@ namespace Loader { /// Loads an NRO file class AppLoader_NRO final : public AppLoader, Linker { public: - AppLoader_NRO(FileSys::VirtualFile file); + explicit AppLoader_NRO(FileSys::VirtualFile file); /** * Returns the type of the file -- cgit v1.2.3 From 2b497e58306b98eddaf74a3a1fecc6fdd8b8c855 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 23 Jul 2018 17:24:27 -0400 Subject: nro: Make bracing consistent Makes the code more uniform, and also braces cases where the body of an unbraced conditional travels more than one line. --- src/core/loader/nro.cpp | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index 44158655c..f6f12c31c 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp @@ -68,22 +68,27 @@ static_assert(sizeof(AssetHeader) == 0x38, "AssetHeader has incorrect size."); AppLoader_NRO::AppLoader_NRO(FileSys::VirtualFile file) : AppLoader(file) { NroHeader nro_header{}; - if (file->ReadObject(&nro_header) != sizeof(NroHeader)) + if (file->ReadObject(&nro_header) != sizeof(NroHeader)) { return; + } if (file->GetSize() >= nro_header.file_size + sizeof(AssetHeader)) { - u64 offset = nro_header.file_size; + const u64 offset = nro_header.file_size; AssetHeader asset_header{}; - if (file->ReadObject(&asset_header, offset) != sizeof(AssetHeader)) + if (file->ReadObject(&asset_header, offset) != sizeof(AssetHeader)) { return; + } - if (asset_header.format_version != 0) + if (asset_header.format_version != 0) { LOG_WARNING(Loader, "NRO Asset Header has format {}, currently supported format is 0. If " "strange glitches occur with metadata, check NRO assets.", asset_header.format_version); - if (asset_header.magic != Common::MakeMagic('A', 'S', 'E', 'T')) + } + + if (asset_header.magic != Common::MakeMagic('A', 'S', 'E', 'T')) { return; + } if (asset_header.nacp.size > 0) { nacp = std::make_unique(std::make_shared( @@ -130,8 +135,9 @@ bool AppLoader_NRO::LoadNro(FileSys::VirtualFile file, VAddr load_base) { // Build program image Kernel::SharedPtr codeset = Kernel::CodeSet::Create(""); std::vector program_image = file->ReadBytes(PageAlignSize(nro_header.file_size)); - if (program_image.size() != PageAlignSize(nro_header.file_size)) + if (program_image.size() != PageAlignSize(nro_header.file_size)) { return {}; + } for (std::size_t i = 0; i < nro_header.segments.size(); ++i) { codeset->segments[i].addr = nro_header.segments[i].offset; @@ -187,29 +193,37 @@ ResultStatus AppLoader_NRO::Load(Kernel::SharedPtr& process) { } ResultStatus AppLoader_NRO::ReadIcon(std::vector& buffer) { - if (icon_data.empty()) + if (icon_data.empty()) { return ResultStatus::ErrorNotUsed; + } + buffer = icon_data; return ResultStatus::Success; } ResultStatus AppLoader_NRO::ReadProgramId(u64& out_program_id) { - if (nacp == nullptr) + if (nacp == nullptr) { return ResultStatus::ErrorNotUsed; + } + out_program_id = nacp->GetTitleId(); return ResultStatus::Success; } ResultStatus AppLoader_NRO::ReadRomFS(FileSys::VirtualFile& dir) { - if (romfs == nullptr) + if (romfs == nullptr) { return ResultStatus::ErrorNotUsed; + } + dir = romfs; return ResultStatus::Success; } ResultStatus AppLoader_NRO::ReadTitle(std::string& title) { - if (nacp == nullptr) + if (nacp == nullptr) { return ResultStatus::ErrorNotUsed; + } + title = nacp->GetApplicationName(); return ResultStatus::Success; } -- cgit v1.2.3 From 1b4d0ac20e3577b8a330a1e79881edaa0dd0143a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 23 Jul 2018 17:27:50 -0400 Subject: nro: Replace inclusion with a forward declaration It's sufficient to use a forward declaration instead of a direct inclusion here. --- src/core/loader/nro.cpp | 3 +++ src/core/loader/nro.h | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index f6f12c31c..7d3ec2a76 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp @@ -6,6 +6,7 @@ #include #include "common/common_funcs.h" +#include "common/common_types.h" #include "common/file_util.h" #include "common/logging/log.h" #include "common/swap.h" @@ -106,6 +107,8 @@ AppLoader_NRO::AppLoader_NRO(FileSys::VirtualFile file) : AppLoader(file) { } } +AppLoader_NRO::~AppLoader_NRO() = default; + FileType AppLoader_NRO::IdentifyType(const FileSys::VirtualFile& file) { // Read NSO header NroHeader nro_header{}; diff --git a/src/core/loader/nro.h b/src/core/loader/nro.h index fe6104754..04a0f497e 100644 --- a/src/core/loader/nro.h +++ b/src/core/loader/nro.h @@ -6,17 +6,21 @@ #include #include "common/common_types.h" -#include "core/file_sys/control_metadata.h" #include "core/hle/kernel/kernel.h" #include "core/loader/linker.h" #include "core/loader/loader.h" +namespace FileSys { +class NACP; +} + namespace Loader { /// Loads an NRO file class AppLoader_NRO final : public AppLoader, Linker { public: explicit AppLoader_NRO(FileSys::VirtualFile file); + ~AppLoader_NRO() override; /** * Returns the type of the file -- cgit v1.2.3