From c0a2308edb67a6d7d440a33915aeeacfd12ff673 Mon Sep 17 00:00:00 2001 From: Maschell Date: Thu, 26 Jan 2023 13:21:35 +0100 Subject: [PATCH] OSFatal when the Notification Module is missing --- src/config.cpp | 5 +++++ src/config.h | 2 +- src/main.cpp | 9 +++------ src/retain_vars.cpp | 2 ++ src/retain_vars.hpp | 2 ++ src/utils/utils.cpp | 29 +++++++++++++++++++++++++++++ src/utils/utils.h | 2 ++ 7 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index 034fc70..7dcc677 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -1,7 +1,9 @@ #include "config.h" +#include "common.h" #include "retain_vars.hpp" #include "utils/WUPSConfigItemButtonCombo.h" #include "utils/logger.h" +#include "utils/utils.h" #include #include #include @@ -146,6 +148,9 @@ void boolItemCallback(ConfigItemBoolean *item, bool newValue) { DEBUG_FUNCTION_LINE("New value in %s changed: %d", item->configId, newValue); if (std::string_view(item->configId) == ENABLED_CONFIG_STRING) { gEnabled = newValue; + if (gEnabled) { + InitNotificationModule(); + } WUPS_StoreBool(nullptr, item->configId, gEnabled); } else if (std::string_view(item->configId) == RESERVED_BIT_USAGE_CONFIG_STRING) { gReservedBitUsage = newValue; diff --git a/src/config.h b/src/config.h index 52357f1..ad36c65 100644 --- a/src/config.h +++ b/src/config.h @@ -7,4 +7,4 @@ #define SCREEN_CONFIG_STRING "screen" #define RESERVED_BIT_USAGE_CONFIG_STRING "reservedBitUsage" -void InitConfig(); \ No newline at end of file +void InitConfig(); diff --git a/src/main.cpp b/src/main.cpp index 17c2b3d..e4572d3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,13 +23,10 @@ WUPS_USE_WUT_DEVOPTAB(); // Gets called once the loader exists. INITIALIZE_PLUGIN() { initLogging(); - - NotificationModuleStatus res; - if ((res = NotificationModule_InitLibrary()) != NOTIFICATION_MODULE_RESULT_SUCCESS) { - DEBUG_FUNCTION_LINE_ERR("NotificationModule_InitLibrary failed: %s", NotificationModule_GetStatusStr(res)); - } - InitConfig(); + if (gEnabled) { + InitNotificationModule(); + } } DEINITIALIZE_PLUGIN() { diff --git a/src/retain_vars.cpp b/src/retain_vars.cpp index 1e9bdc3..0ec3e51 100644 --- a/src/retain_vars.cpp +++ b/src/retain_vars.cpp @@ -25,3 +25,5 @@ int32_t gThreadPriorityIncrease = 1; bool gBlockDRCScreenshots = false; bool gBlockScreenshots = false; + +bool gInitNotificationModule = false; diff --git a/src/retain_vars.hpp b/src/retain_vars.hpp index e3d55d4..68ec228 100644 --- a/src/retain_vars.hpp +++ b/src/retain_vars.hpp @@ -28,3 +28,5 @@ extern int32_t gThreadPriorityIncrease; extern bool gBlockDRCScreenshots; extern bool gBlockScreenshots; + +extern bool gInitNotificationModule; diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index 36c29b5..c53ebcc 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -1,4 +1,5 @@ #include "StringTools.h" +#include "config.h" #include "logger.h" #include "retain_vars.hpp" #include @@ -78,6 +79,34 @@ std::string GetSanitizedNameOfCurrentApplication() { return result; } + +void InitNotificationModule() { + if (gInitNotificationModule) { + return; + } + NotificationModuleStatus res; + if ((res = NotificationModule_InitLibrary()) != NOTIFICATION_MODULE_RESULT_SUCCESS) { + gInitNotificationModule = true; + std::string error = string_format("Failed to init Screenshot Plugin: \n" + "NotificationModule_InitLibrary returned:\n%s\n\n" + "Please update to latest Aroma before using the plugin.\n\n" + "The plugin has been disabled. You need to enable again in the\n" + "config menu after updating\n\n" + "Hold the POWER button of your CONSOLE for 5 seconds to shut down.", + NotificationModule_GetStatusStr(res)); + gEnabled = false; + WUPSStorageError storageRes = WUPS_OpenStorage(); + if (storageRes == WUPS_STORAGE_ERROR_SUCCESS) { + if (WUPS_StoreBool(nullptr, ENABLED_CONFIG_STRING, gEnabled) != WUPS_STORAGE_ERROR_SUCCESS) { + DEBUG_FUNCTION_LINE_ERR("Failed to store value"); + } + WUPS_CloseStorage(); + } + + OSFatal(error.c_str()); + } +} + void ApplyGameSpecificPatches() { uint64_t titleID = OSGetTitleID(); // Mario Kart 8 has noticeable slowdown when taking screenshots in multiplayer diff --git a/src/utils/utils.h b/src/utils/utils.h index f83dc35..67d5e59 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -17,3 +17,5 @@ inline uint8_t RGBComponentToSRGB(uint8_t ci) { std::string GetSanitizedNameOfCurrentApplication(); void ApplyGameSpecificPatches(); + +void InitNotificationModule(); \ No newline at end of file