From d2922bcd3a252e7a11a52b0ebcf43a5c7e574a41 Mon Sep 17 00:00:00 2001 From: Lekoopapaul Date: Wed, 29 May 2024 22:24:09 +0200 Subject: [PATCH] Add a option to disable/enable this feature under "SdCaffine->Advanced Settings->Enable Save Redirection" --- src/globals.cpp | 1 + src/globals.h | 3 +++ src/modpackSelector.cpp | 58 +++++++++++++++++++++-------------------- src/utils/config.cpp | 11 +++++++- 4 files changed, 44 insertions(+), 29 deletions(-) diff --git a/src/globals.cpp b/src/globals.cpp index 64abece..e9a22f9 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -3,6 +3,7 @@ bool gAutoApplySingleModpack = DEFAULT_AUTO_APPLY_SINGLE_MODPACK; bool gSkipPrepareIfSingleModpack = DEFAULT_SKIP_PREPARE_IF_SINGLE_MODPACK; bool gSDCafiineEnabled = DEFAULT_SDCAFIINE_ENABLED; +bool gSaveRedirectionEnabled = DEFAULT_SAVE_REDIRECTION_ENABLED; CRLayerHandle gContentLayerHandle = 0; diff --git a/src/globals.h b/src/globals.h index 1696443..91d00c9 100644 --- a/src/globals.h +++ b/src/globals.h @@ -8,14 +8,17 @@ #define AUTO_APPLY_SINGLE_MODPACK_STRING "autoApplySingleModpack" #define SKIP_PREPARE_FOR_SINGLE_MODPACK_STRING "skipPrepareForSingleModpack" #define SDCAFIINE_ENABLED_STRING "sdCafiineEnabled" +#define SAVE_REDIRECTION_ENABLED_STRING "saveRedirectionEnabled" #define DEFAULT_AUTO_APPLY_SINGLE_MODPACK false #define DEFAULT_SKIP_PREPARE_IF_SINGLE_MODPACK false #define DEFAULT_SDCAFIINE_ENABLED true +#define DEFAULT_SAVE_REDIRECTION_ENABLED true extern bool gAutoApplySingleModpack; extern bool gSkipPrepareIfSingleModpack; extern bool gSDCafiineEnabled; +extern bool gSaveRedirectionEnabled; extern CRLayerHandle gAocLayerHandle; extern CRLayerHandle gContentLayerHandle; diff --git a/src/modpackSelector.cpp b/src/modpackSelector.cpp index 960bb4a..e9ccbbd 100644 --- a/src/modpackSelector.cpp +++ b/src/modpackSelector.cpp @@ -13,10 +13,10 @@ #include #include #include +#include #include #include #include -#include #define TEXT_SEL(x, text1, text2) ((x) ? (text1) : (text2)) @@ -314,37 +314,39 @@ void HandleMultiModPacks(uint64_t titleID) { KPADShutdown(); } -bool ReplaceContentInternal(const std::string &basePath, const std::string &subdir, CRLayerHandle *layerHandle,FSLayerType layerType); +bool ReplaceContentInternal(const std::string &basePath, const std::string &subdir, CRLayerHandle *layerHandle, FSLayerType layerType); bool ReplaceContent(const std::string &basePath, const std::string &modpack) { - bool saveRes = ReplaceContentInternal(basePath, "save", &gSaveLayerHandle,FS_LAYER_TYPE_SAVE_REPLACE); + if (gSaveRedirectionEnabled) { + bool saveRes = ReplaceContentInternal(basePath, "save", &gSaveLayerHandle, FS_LAYER_TYPE_SAVE_REPLACE); - if(!saveRes){ + if (!saveRes) { - auto screenWasAllocated = screenBuffer_0 != nullptr; + auto screenWasAllocated = screenBuffer_0 != nullptr; - if (!ScreenInit()) { - OSFatal("SDCafiine plugin: Failed to apply the modpack."); + if (!ScreenInit()) { + OSFatal("SDCafiine plugin: Failed to apply the modpack."); + } + uint32_t sleepTime = 3000; + DEBUG_FUNCTION_LINE_ERR("Failed to apply the save redirection. Starting without mods."); + OSScreenClearBufferEx(SCREEN_TV, 0); + OSScreenClearBufferEx(SCREEN_DRC, 0); + console_print_pos(-2, -1, "SDCafiine plugin " VERSION VERSION_EXTRA); + console_print_pos(-2, 1, "Failed to apply the save redirection. Starting without mods..."); + + OSScreenFlipBuffersEx(SCREEN_TV); + OSScreenFlipBuffersEx(SCREEN_DRC); + + OSSleepTicks(OSMillisecondsToTicks(sleepTime)); + if (!screenWasAllocated) { + ScreenDeInit(); + } + return false; } - uint32_t sleepTime = 3000; - DEBUG_FUNCTION_LINE_ERR("Failed to apply the save redirection. Starting without mods."); - OSScreenClearBufferEx(SCREEN_TV, 0); - OSScreenClearBufferEx(SCREEN_DRC, 0); - console_print_pos(-2, -1, "SDCafiine plugin " VERSION VERSION_EXTRA); - console_print_pos(-2, 1, "Failed to apply the save redirection. Starting without mods..."); - - OSScreenFlipBuffersEx(SCREEN_TV); - OSScreenFlipBuffersEx(SCREEN_DRC); - - OSSleepTicks(OSMillisecondsToTicks(sleepTime)); - if (!screenWasAllocated) { - ScreenDeInit(); - } - return false; } - bool contentRes = ReplaceContentInternal(basePath, "content", &gContentLayerHandle,FS_LAYER_TYPE_CONTENT_MERGE); - bool aocRes = ReplaceContentInternal(basePath, "aoc", &gAocLayerHandle,FS_LAYER_TYPE_AOC_MERGE); + bool contentRes = ReplaceContentInternal(basePath, "content", &gContentLayerHandle, FS_LAYER_TYPE_CONTENT_MERGE); + bool aocRes = ReplaceContentInternal(basePath, "aoc", &gAocLayerHandle, FS_LAYER_TYPE_AOC_MERGE); if (!contentRes && !aocRes) { auto screenWasAllocated = screenBuffer_0 != nullptr; @@ -406,10 +408,10 @@ bool ReplaceContent(const std::string &basePath, const std::string &modpack) { return true; } -bool ReplaceContentInternal(const std::string &basePath, const std::string &subdir, CRLayerHandle *layerHandle,FSLayerType layerType) { +bool ReplaceContentInternal(const std::string &basePath, const std::string &subdir, CRLayerHandle *layerHandle, FSLayerType layerType) { std::string layerName = "SDCafiine Plus /vol/" + subdir; std::string fullPath = basePath + "/" + subdir; - if(layerType == FS_LAYER_TYPE_SAVE_REPLACE){ + if (layerType == FS_LAYER_TYPE_SAVE_REPLACE) { nn::act::Initialize(); nn::act::PersistentId id = nn::act::GetPersistentId(); nn::act::Finalize(); @@ -418,8 +420,8 @@ bool ReplaceContentInternal(const std::string &basePath, const std::string &subd snprintf(user, 9, "%08x", 0x80000000 | id); mkdir(fullPath.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); - mkdir((fullPath+"/"+"common").c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); - mkdir((fullPath+"/"+user).c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + mkdir((fullPath + "/" + "common").c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + mkdir((fullPath + "/" + user).c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); } struct stat st {}; if (stat(fullPath.c_str(), &st) < 0) { diff --git a/src/utils/config.cpp b/src/utils/config.cpp index 898e149..2d8e14f 100644 --- a/src/utils/config.cpp +++ b/src/utils/config.cpp @@ -18,6 +18,8 @@ static void bool_item_callback(ConfigItemBoolean *item, bool newValue) { gSkipPrepareIfSingleModpack = newValue; } else if (std::string_view(SDCAFIINE_ENABLED_STRING) == item->identifier) { gSDCafiineEnabled = newValue; + } else if (std::string_view(SAVE_REDIRECTION_ENABLED_STRING) == item->identifier) { + gSaveRedirectionEnabled = newValue; } else { DEBUG_FUNCTION_LINE_WARN("Unexpected boolean item: %s", item->identifier); return; @@ -50,6 +52,11 @@ static WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHa "Skip \"Preparing modpack...\" screen", DEFAULT_SKIP_PREPARE_IF_SINGLE_MODPACK, gSkipPrepareIfSingleModpack, &bool_item_callback)); + + advancedSettings.add(WUPSConfigItemBoolean::Create(SAVE_REDIRECTION_ENABLED_STRING, + "Enable Save Redirection (game needs to be restarted)", + DEFAULT_SAVE_REDIRECTION_ENABLED, gSaveRedirectionEnabled, + &bool_item_callback)); root.add(std::move(advancedSettings)); } catch (std::exception &e) { @@ -79,7 +86,9 @@ void InitStorageAndConfig() { if ((err = WUPSStorageAPI::GetOrStoreDefault(SKIP_PREPARE_FOR_SINGLE_MODPACK_STRING, gSkipPrepareIfSingleModpack, DEFAULT_SKIP_PREPARE_IF_SINGLE_MODPACK)) != WUPS_STORAGE_ERROR_SUCCESS) { DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\": %s (%d)", gSkipPrepareIfSingleModpack, WUPSStorageAPI_GetStatusStr(err), err); } - + if ((err = WUPSStorageAPI::GetOrStoreDefault(SAVE_REDIRECTION_ENABLED_STRING, gSaveRedirectionEnabled, DEFAULT_SAVE_REDIRECTION_ENABLED)) != WUPS_STORAGE_ERROR_SUCCESS) { + DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\": %s (%d)", gSaveRedirectionEnabled, WUPSStorageAPI_GetStatusStr(err), err); + } if ((err = WUPSStorageAPI::SaveStorage()) != WUPS_STORAGE_ERROR_SUCCESS) { DEBUG_FUNCTION_LINE_ERR("Failed to save storage: %s (%d)", WUPSStorageAPI_GetStatusStr(err), err); }