From a1fb8a91c8bc2e5c6d8980505a958550864906d6 Mon Sep 17 00:00:00 2001 From: HamletDuFromage <61667930+HamletDuFromage@users.noreply.github.com> Date: Sat, 11 Sep 2021 19:55:25 +0200 Subject: [PATCH] Add arguments support to Daybreak (#1616) * Add arguments support to Daybreak * Check if Daybreak is run as NRO --- troposphere/daybreak/source/main.cpp | 5 ++++- troposphere/daybreak/source/ui.cpp | 29 +++++++++++++++++++++++++--- troposphere/daybreak/source/ui.hpp | 3 ++- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/troposphere/daybreak/source/main.cpp b/troposphere/daybreak/source/main.cpp index 0eb1d04bc..88d2db247 100644 --- a/troposphere/daybreak/source/main.cpp +++ b/troposphere/daybreak/source/main.cpp @@ -261,7 +261,10 @@ class Daybreak : public CApplication { int main(int argc, char **argv) { /* Initialize the menu. */ - dbk::InitializeMenu(FramebufferWidth, FramebufferHeight); + if (argc > 1) + dbk::InitializeMenu(FramebufferWidth, FramebufferHeight, argv[1]); + else + dbk::InitializeMenu(FramebufferWidth, FramebufferHeight); Daybreak daybreak; daybreak.run(); diff --git a/troposphere/daybreak/source/ui.cpp b/troposphere/daybreak/source/ui.cpp index c59b638e9..408b4a010 100644 --- a/troposphere/daybreak/source/ui.cpp +++ b/troposphere/daybreak/source/ui.cpp @@ -1216,7 +1216,7 @@ namespace dbk { } } - void InitializeMenu(u32 screen_width, u32 screen_height) { + bool InitializeMenu(u32 screen_width, u32 screen_height) { Result rc = 0; /* Configure and initialize the gamepad. */ @@ -1237,7 +1237,7 @@ namespace dbk { u64 version; if (R_FAILED(rc = splGetConfig(static_cast(ExosphereApiVersionConfigItem), &version))) { ChangeMenu(std::make_shared("Atmosphere not found", "Daybreak requires Atmosphere to be installed.", rc)); - return; + return false; } const u32 version_micro = (version >> 40) & 0xff; @@ -1248,7 +1248,13 @@ namespace dbk { const bool ams_supports_sysupdate_api = EncodeVersion(version_major, version_minor, version_micro) >= EncodeVersion(0, 14, 0); if (!ams_supports_sysupdate_api) { ChangeMenu(std::make_shared("Outdated Atmosphere version", "Daybreak requires Atmosphere 0.14.0 or later.", rc)); - return; + return false; + } + + /* Ensure DayBreak is ran as a NRO. */ + if (envIsNso()) { + ChangeMenu(std::make_shared("Unsupported Environment", "Please launch Daybreak via the Homebrew menu.", rc)); + return false; } /* Attempt to get the supported version. */ @@ -1263,6 +1269,23 @@ namespace dbk { /* Change the current menu to the main menu. */ g_current_menu = std::make_shared(); + + return true; + } + + bool InitializeMenu(u32 screen_width, u32 screen_height, const char *update_path) { + if (InitializeMenu(screen_width, screen_height)) { + + /* Set the update path. */ + strncpy(g_update_path, update_path, sizeof(g_update_path)); + + /* Change the menu. */ + ChangeMenu(std::make_shared(g_current_menu)); + + return true; + } + + return false; } void UpdateMenu(u64 ns) { diff --git a/troposphere/daybreak/source/ui.hpp b/troposphere/daybreak/source/ui.hpp index 481ad4069..211a0c43d 100644 --- a/troposphere/daybreak/source/ui.hpp +++ b/troposphere/daybreak/source/ui.hpp @@ -263,7 +263,8 @@ namespace dbk { virtual void Draw(NVGcontext *vg, u64 ns) override; }; - void InitializeMenu(u32 screen_width, u32 screen_height); + bool InitializeMenu(u32 screen_width, u32 screen_height); + bool InitializeMenu(u32 screen_width, u32 screen_height, const char *update_path); void UpdateMenu(u64 ns); void RenderMenu(NVGcontext *vg, u64 ns); bool IsExitRequested();