Add a option to disable/enable this feature under "SdCaffine->Advanced Settings->Enable Save Redirection"

This commit is contained in:
Lekoopapaul 2024-05-29 22:24:09 +02:00
parent ed641b2e85
commit d2922bcd3a
4 changed files with 44 additions and 29 deletions

View File

@ -3,6 +3,7 @@
bool gAutoApplySingleModpack = DEFAULT_AUTO_APPLY_SINGLE_MODPACK; bool gAutoApplySingleModpack = DEFAULT_AUTO_APPLY_SINGLE_MODPACK;
bool gSkipPrepareIfSingleModpack = DEFAULT_SKIP_PREPARE_IF_SINGLE_MODPACK; bool gSkipPrepareIfSingleModpack = DEFAULT_SKIP_PREPARE_IF_SINGLE_MODPACK;
bool gSDCafiineEnabled = DEFAULT_SDCAFIINE_ENABLED; bool gSDCafiineEnabled = DEFAULT_SDCAFIINE_ENABLED;
bool gSaveRedirectionEnabled = DEFAULT_SAVE_REDIRECTION_ENABLED;
CRLayerHandle gContentLayerHandle = 0; CRLayerHandle gContentLayerHandle = 0;

View File

@ -8,14 +8,17 @@
#define AUTO_APPLY_SINGLE_MODPACK_STRING "autoApplySingleModpack" #define AUTO_APPLY_SINGLE_MODPACK_STRING "autoApplySingleModpack"
#define SKIP_PREPARE_FOR_SINGLE_MODPACK_STRING "skipPrepareForSingleModpack" #define SKIP_PREPARE_FOR_SINGLE_MODPACK_STRING "skipPrepareForSingleModpack"
#define SDCAFIINE_ENABLED_STRING "sdCafiineEnabled" #define SDCAFIINE_ENABLED_STRING "sdCafiineEnabled"
#define SAVE_REDIRECTION_ENABLED_STRING "saveRedirectionEnabled"
#define DEFAULT_AUTO_APPLY_SINGLE_MODPACK false #define DEFAULT_AUTO_APPLY_SINGLE_MODPACK false
#define DEFAULT_SKIP_PREPARE_IF_SINGLE_MODPACK false #define DEFAULT_SKIP_PREPARE_IF_SINGLE_MODPACK false
#define DEFAULT_SDCAFIINE_ENABLED true #define DEFAULT_SDCAFIINE_ENABLED true
#define DEFAULT_SAVE_REDIRECTION_ENABLED true
extern bool gAutoApplySingleModpack; extern bool gAutoApplySingleModpack;
extern bool gSkipPrepareIfSingleModpack; extern bool gSkipPrepareIfSingleModpack;
extern bool gSDCafiineEnabled; extern bool gSDCafiineEnabled;
extern bool gSaveRedirectionEnabled;
extern CRLayerHandle gAocLayerHandle; extern CRLayerHandle gAocLayerHandle;
extern CRLayerHandle gContentLayerHandle; extern CRLayerHandle gContentLayerHandle;

View File

@ -13,10 +13,10 @@
#include <malloc.h> #include <malloc.h>
#include <map> #include <map>
#include <memory/mappedmemory.h> #include <memory/mappedmemory.h>
#include <nn/act.h>
#include <string> #include <string>
#include <utils/logger.h> #include <utils/logger.h>
#include <wups/storage.h> #include <wups/storage.h>
#include <nn/act.h>
#define TEXT_SEL(x, text1, text2) ((x) ? (text1) : (text2)) #define TEXT_SEL(x, text1, text2) ((x) ? (text1) : (text2))
@ -317,6 +317,7 @@ void HandleMultiModPacks(uint64_t titleID) {
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 ReplaceContent(const std::string &basePath, const std::string &modpack) {
if (gSaveRedirectionEnabled) {
bool saveRes = ReplaceContentInternal(basePath, "save", &gSaveLayerHandle, FS_LAYER_TYPE_SAVE_REPLACE); bool saveRes = ReplaceContentInternal(basePath, "save", &gSaveLayerHandle, FS_LAYER_TYPE_SAVE_REPLACE);
if (!saveRes) { if (!saveRes) {
@ -342,6 +343,7 @@ bool ReplaceContent(const std::string &basePath, const std::string &modpack) {
} }
return false; return false;
} }
}
bool contentRes = ReplaceContentInternal(basePath, "content", &gContentLayerHandle, FS_LAYER_TYPE_CONTENT_MERGE); bool contentRes = ReplaceContentInternal(basePath, "content", &gContentLayerHandle, FS_LAYER_TYPE_CONTENT_MERGE);
bool aocRes = ReplaceContentInternal(basePath, "aoc", &gAocLayerHandle, FS_LAYER_TYPE_AOC_MERGE); bool aocRes = ReplaceContentInternal(basePath, "aoc", &gAocLayerHandle, FS_LAYER_TYPE_AOC_MERGE);

View File

@ -18,6 +18,8 @@ static void bool_item_callback(ConfigItemBoolean *item, bool newValue) {
gSkipPrepareIfSingleModpack = newValue; gSkipPrepareIfSingleModpack = newValue;
} else if (std::string_view(SDCAFIINE_ENABLED_STRING) == item->identifier) { } else if (std::string_view(SDCAFIINE_ENABLED_STRING) == item->identifier) {
gSDCafiineEnabled = newValue; gSDCafiineEnabled = newValue;
} else if (std::string_view(SAVE_REDIRECTION_ENABLED_STRING) == item->identifier) {
gSaveRedirectionEnabled = newValue;
} else { } else {
DEBUG_FUNCTION_LINE_WARN("Unexpected boolean item: %s", item->identifier); DEBUG_FUNCTION_LINE_WARN("Unexpected boolean item: %s", item->identifier);
return; return;
@ -50,6 +52,11 @@ static WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHa
"Skip \"Preparing modpack...\" screen", "Skip \"Preparing modpack...\" screen",
DEFAULT_SKIP_PREPARE_IF_SINGLE_MODPACK, gSkipPrepareIfSingleModpack, DEFAULT_SKIP_PREPARE_IF_SINGLE_MODPACK, gSkipPrepareIfSingleModpack,
&bool_item_callback)); &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)); root.add(std::move(advancedSettings));
} catch (std::exception &e) { } 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) { 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); 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) { if ((err = WUPSStorageAPI::SaveStorage()) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to save storage: %s (%d)", WUPSStorageAPI_GetStatusStr(err), err); DEBUG_FUNCTION_LINE_ERR("Failed to save storage: %s (%d)", WUPSStorageAPI_GetStatusStr(err), err);
} }