From 191565a1b8e8edfdd468f5c77cdbad4520287ff1 Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 6 Nov 2017 15:12:15 -0500 Subject: [PATCH] HLE/NS: Added a function to launch titles installed to the virtual NAND/SD card. It uses AM::GetTitleContentPath to retrieve the path of the program to launch. --- src/core/hle/service/ns/ns.cpp | 23 +++++++++++++++++++++++ src/core/hle/service/ns/ns.h | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/src/core/hle/service/ns/ns.cpp b/src/core/hle/service/ns/ns.cpp index 9e19c38bf9..9616cc8f6b 100644 --- a/src/core/hle/service/ns/ns.cpp +++ b/src/core/hle/service/ns/ns.cpp @@ -2,12 +2,35 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include +#include "core/hle/service/am/am.h" #include "core/hle/service/ns/ns.h" #include "core/hle/service/ns/ns_s.h" +#include "core/loader/loader.h" namespace Service { namespace NS { +Kernel::SharedPtr LaunchTitle(FS::MediaType media_type, u64 title_id) { + std::string path = AM::GetTitleContentPath(media_type, title_id); + auto loader = Loader::GetLoader(path); + + if (!loader) { + LOG_WARNING(Service_NS, "Could not find .app for title 0x%016" PRIx64, title_id); + return nullptr; + } + + Kernel::SharedPtr process; + Loader::ResultStatus result = loader->Load(process); + + if (result != Loader::ResultStatus::Success) { + LOG_WARNING(Service_NS, "Error loading .app for title 0x%016" PRIx64, title_id); + return nullptr; + } + + return process; +} + void InstallInterfaces(SM::ServiceManager& service_manager) { std::make_shared()->InstallAsService(service_manager); } diff --git a/src/core/hle/service/ns/ns.h b/src/core/hle/service/ns/ns.h index c3d67d98c8..6fb171c1a4 100644 --- a/src/core/hle/service/ns/ns.h +++ b/src/core/hle/service/ns/ns.h @@ -4,11 +4,15 @@ #pragma once +#include "core/hle/kernel/process.h" #include "core/hle/service/service.h" namespace Service { namespace NS { +/// Loads and launches the title identified by title_id in the specified media type. +Kernel::SharedPtr LaunchTitle(FS::MediaType media_type, u64 title_id); + /// Registers all NS services with the specified service manager. void InstallInterfaces(SM::ServiceManager& service_manager);