diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bacae03..92c8c80 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: clang-format: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: clang-format run: | docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./src @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-22.04 needs: clang-format steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: create version.h run: | git_hash=$(git rev-parse --short "$GITHUB_SHA") @@ -48,7 +48,7 @@ jobs: - name: zip artifact run: zip -r ${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip *.wps - name: Create Release - uses: "softprops/action-gh-release@v1" + uses: "softprops/action-gh-release@v2" with: tag_name: ${{ env.REPOSITORY_NAME }}-${{ env.DATETIME }} draft: false diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 35adf5f..720b388 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -6,7 +6,7 @@ jobs: clang-format: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: clang-format run: | docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./src @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-22.04 needs: clang-format steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: build binary with logging run: | docker build . -t builder @@ -25,7 +25,7 @@ jobs: runs-on: ubuntu-22.04 needs: clang-format steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: create version.h run: | git_hash=$(git rev-parse --short "${{ github.event.pull_request.head.sha }}") diff --git a/Dockerfile b/Dockerfile index d1fc717..6e6f9b7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,10 @@ -FROM ghcr.io/wiiu-env/devkitppc:20230621 +FROM ghcr.io/wiiu-env/devkitppc:20240423 -COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:20230719 /artifacts $DEVKITPRO -COPY --from=ghcr.io/wiiu-env/librpxloader:20230621 /artifacts $DEVKITPRO +COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:20240425 /artifacts $DEVKITPRO +COPY --from=ghcr.io/wiiu-env/librpxloader:20240425 /artifacts $DEVKITPRO COPY --from=ghcr.io/wiiu-env/libsdutils:20230621 /artifacts $DEVKITPRO COPY --from=ghcr.io/wiiu-env/libwuhbutils:20230621 /artifacts $DEVKITPRO -COPY --from=ghcr.io/wiiu-env/libcontentredirection:20230621 /artifacts $DEVKITPRO +COPY --from=ghcr.io/wiiu-env/libcontentredirection:20240424 /artifacts $DEVKITPRO COPY --from=ghcr.io/wiiu-env/libnotifications:20230621 /artifacts $DEVKITPRO WORKDIR project diff --git a/Makefile b/Makefile index 625c688..172fe26 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ CFLAGS := -Wall -O2 -ffunction-sections \ CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ -D__WUPS__ -CXXFLAGS := $(CFLAGS) -fno-exceptions -fno-rtti -std=c++20 +CXXFLAGS := $(CFLAGS) -std=c++20 ASFLAGS := -g $(ARCH) LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) $(WUPSSPECS) diff --git a/src/SaveRedirection.cpp b/src/SaveRedirection.cpp index dc48065..46cbbc0 100644 --- a/src/SaveRedirection.cpp +++ b/src/SaveRedirection.cpp @@ -48,14 +48,10 @@ void CopyExistingFiles() { nn::act::PersistentId persistentId = nn::act::GetPersistentId(); nn::act::Finalize(); - std::string common = getBaseSavePathFS() + "/common"; - std::string commonLegacy = getBaseSavePathLegacyFS() + "/common"; - std::string commonOriginal = "fs:/vol/save/common"; - std::string user = string_format("%s/%08X", getBaseSavePathFS().c_str(), 0x80000000 | persistentId); - std::string userLegacy = string_format("%s/%08X", getBaseSavePathLegacyFS().c_str(), 0x80000000 | persistentId); - std::string userOriginal = string_format("fs:/vol/save/%08X", 0x80000000 | persistentId); - - FSUtils::CreateSubfolder(common.c_str()); + std::string user = string_format("%s/%08X", getBaseSavePathFS().c_str(), 0x80000000 | persistentId); + std::string userLegacy = string_format("%s/%08X", getBaseSavePathLegacyFS().c_str(), 0x80000000 | persistentId); + std::string userOriginal = string_format("fs:/vol/save/%08X", 0x80000000 | persistentId); + FSUtils::CreateSubfolder(user.c_str()); auto BaristaAccountSaveFilePathNew = user + "/BaristaAccountSaveFile.dat"; @@ -78,48 +74,6 @@ void CopyExistingFiles() { } } } - - auto BaristaCommonSaveFile = common + "/BaristaCommonSaveFile.dat"; - auto BaristaCommonSaveFileOriginal = commonOriginal + "/BaristaCommonSaveFile.dat"; - auto BaristaCommonSaveFileLegacy = commonLegacy + "/BaristaCommonSaveFile.dat"; - if (!FSUtils::CheckFile(BaristaCommonSaveFile.c_str())) { - if (FSUtils::CheckFile(BaristaCommonSaveFileLegacy.c_str())) { - DEBUG_FUNCTION_LINE("Copy %s to %s", BaristaCommonSaveFileLegacy.c_str(), BaristaCommonSaveFile.c_str()); - if (!FSUtils::copyFile(BaristaCommonSaveFileLegacy, BaristaCommonSaveFile)) { - DEBUG_FUNCTION_LINE_ERR("Failed to copy file: %s -> %s", BaristaCommonSaveFileLegacy.c_str(), BaristaCommonSaveFile.c_str()); - } else { - if (remove(BaristaCommonSaveFileLegacy.c_str()) < 0) { - DEBUG_FUNCTION_LINE_ERR("Failed to delete %s", BaristaCommonSaveFileLegacy.c_str()); - } - } - } else { - DEBUG_FUNCTION_LINE("Copy %s to %s", BaristaCommonSaveFileOriginal.c_str(), BaristaCommonSaveFile.c_str()); - if (!FSUtils::copyFile(BaristaCommonSaveFileOriginal, BaristaCommonSaveFile)) { - DEBUG_FUNCTION_LINE_ERR("Failed to copy file: %s -> %s", BaristaCommonSaveFileOriginal.c_str(), BaristaCommonSaveFile.c_str()); - } - } - } - - auto BaristaIconDataBase = common + "/BaristaIconDataBase.dat"; - auto BaristaIconDataBaseOriginal = commonOriginal + "/BaristaIconDataBase.dat"; - auto BaristaIconDataBaseLegacy = commonLegacy + "/BaristaIconDataBase.dat"; - if (!FSUtils::CheckFile(BaristaIconDataBase.c_str())) { - if (FSUtils::CheckFile(BaristaIconDataBaseLegacy.c_str())) { - DEBUG_FUNCTION_LINE("Copy %s to %s", BaristaIconDataBaseLegacy.c_str(), BaristaIconDataBase.c_str()); - if (!FSUtils::copyFile(BaristaIconDataBaseLegacy, BaristaIconDataBase)) { - DEBUG_FUNCTION_LINE_ERR("Failed to copy file: %s -> %s", BaristaIconDataBaseLegacy.c_str(), BaristaIconDataBase.c_str()); - } else { - if (remove(BaristaIconDataBaseLegacy.c_str()) < 0) { - DEBUG_FUNCTION_LINE_ERR("Failed to delete %s", BaristaIconDataBaseLegacy.c_str()); - } - } - } else { - DEBUG_FUNCTION_LINE("Copy %s to %s", BaristaIconDataBaseOriginal.c_str(), BaristaIconDataBase.c_str()); - if (!FSUtils::copyFile(BaristaIconDataBaseOriginal, BaristaIconDataBase)) { - DEBUG_FUNCTION_LINE_ERR("Failed to copy file: %s -> %s", BaristaIconDataBaseOriginal.c_str(), BaristaIconDataBase.c_str()); - } - } - } } void initSaveData() { @@ -128,7 +82,7 @@ void initSaveData() { std::string replaceDir = getBaseSavePathFS(); DEBUG_FUNCTION_LINE("Setup save redirection: %s -> %s", "/vol/save", replaceDir.c_str()); - auto res = ContentRedirection_AddFSLayer(&saveLayer, "homp_save_redirection", replaceDir.c_str(), FS_LAYER_TYPE_SAVE_REPLACE); + auto res = ContentRedirection_AddFSLayer(&saveLayer, "homp_save_redirection", replaceDir.c_str(), FS_LAYER_TYPE_SAVE_REPLACE_IGNORE_VOL_SAVE_COMMON); if (res != CONTENT_REDIRECTION_RESULT_SUCCESS) { DEBUG_FUNCTION_LINE_ERR("Failed to add save FS Layer: %d", res); } @@ -145,25 +99,6 @@ DECL_FUNCTION(int32_t, LoadConsoleAccount__Q2_2nn3actFUc13ACTLoadOptionPCcb, nn: return result; } -DECL_FUNCTION(SAVEStatus, SAVEGetSharedSaveDataPath, uint64_t titleID, const char *path, char *buffer, uint32_t bufferSize) { - if (titleID == 0x0005001010040000L || // Wii U Menu JPN - titleID == 0x0005001010040100L || // Wii U Menu USA - titleID == 0x0005001010040200L) { // Wii U Menu EUR - if (buffer != nullptr) { - std::string commonReplacement = getBaseSavePath() + "/common"; - auto BaristaCommonSaveFile = "fs:" + commonReplacement + "/BaristaCommonSaveFile.dat"; - auto BaristaIconDataBase = "fs:" + commonReplacement + "/BaristaIconDataBase.dat"; - if (FSUtils::CheckFile(BaristaCommonSaveFile.c_str()) && - FSUtils::CheckFile(BaristaIconDataBase.c_str())) { - snprintf(buffer, bufferSize, "%s/%s", commonReplacement.c_str(), path); - DEBUG_FUNCTION_LINE("Redirect Wii U Menu common path to %s", commonReplacement.c_str()); - return SAVE_STATUS_OK; - } - } - } - return real_SAVEGetSharedSaveDataPath(titleID, path, buffer, bufferSize); -} - extern bool gHideHomebrew; extern bool sSDIsMounted; DECL_FUNCTION(int32_t, SAVEInit) { @@ -194,14 +129,12 @@ DECL_FUNCTION(FSError, FSGetLastErrorCodeForViewer, FSClient *client) { } if ((uint32_t) res == 1503030) { // If we encounter error 1503030 when running the Wii U Menu we probably hit a Wii U Menu save related issue - // Either the sd card is write locked or the save on the sd card it corrupted. Let the user now about this.. + // Either the sd card is write locked or the save on the sd card it corrupted. Let the user now about this. - std::string deleteHint = string_format("If not write locked, delete \"sd:" HOMEBREW_ON_MENU_PLUGIN_DATA_PATH_BASE "/%s/save/common/BaristaIconDataBase.dat\".", gSerialId.c_str()); - std::string deleteHint2 = string_format("If deleting this file doesn't fix the error code, delete this directory: \"sd:" HOMEBREW_ON_MENU_PLUGIN_DATA_PATH_BASE "/%s\".", gSerialId.c_str()); + std::string deleteHint = string_format("If not write locked, backup and delete this directory: \"sd:" HOMEBREW_ON_MENU_PLUGIN_DATA_PATH_BASE "/%s\".", gSerialId.c_str()); NotificationModuleHandle handle; NotificationModule_AddDynamicNotification("Caution: This resets the order of application on the Wii U Menu when using Aroma.", &handle); - NotificationModule_AddDynamicNotification(deleteHint2.c_str(), &handle); NotificationModule_AddDynamicNotification("", &handle); NotificationModule_AddDynamicNotification(deleteHint.c_str(), &handle); NotificationModule_AddDynamicNotification("", &handle); @@ -213,5 +146,4 @@ DECL_FUNCTION(FSError, FSGetLastErrorCodeForViewer, FSClient *client) { WUPS_MUST_REPLACE_FOR_PROCESS(SAVEInit, WUPS_LOADER_LIBRARY_NN_SAVE, SAVEInit, WUPS_FP_TARGET_PROCESS_WII_U_MENU); WUPS_MUST_REPLACE_FOR_PROCESS(LoadConsoleAccount__Q2_2nn3actFUc13ACTLoadOptionPCcb, WUPS_LOADER_LIBRARY_NN_ACT, LoadConsoleAccount__Q2_2nn3actFUc13ACTLoadOptionPCcb, WUPS_FP_TARGET_PROCESS_WII_U_MENU); -WUPS_MUST_REPLACE_FOR_PROCESS(FSGetLastErrorCodeForViewer, WUPS_LOADER_LIBRARY_COREINIT, FSGetLastErrorCodeForViewer, WUPS_FP_TARGET_PROCESS_WII_U_MENU); -WUPS_MUST_REPLACE(SAVEGetSharedSaveDataPath, WUPS_LOADER_LIBRARY_NN_SAVE, SAVEGetSharedSaveDataPath); \ No newline at end of file +WUPS_MUST_REPLACE_FOR_PROCESS(FSGetLastErrorCodeForViewer, WUPS_LOADER_LIBRARY_COREINIT, FSGetLastErrorCodeForViewer, WUPS_FP_TARGET_PROCESS_WII_U_MENU); \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 66efb92..6f29eec 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -43,7 +43,7 @@ typedef struct ACPMetaData { char bootlogo[28604]; } ACPMetaData; -WUPS_PLUGIN_NAME("Homebrew in Wii U menu"); +WUPS_PLUGIN_NAME("Homebrew on Wii U menu"); WUPS_PLUGIN_DESCRIPTION("Allows the user to load homebrew from the Wii U menu"); WUPS_PLUGIN_VERSION(VERSION_FULL); WUPS_PLUGIN_AUTHOR("Maschell"); @@ -52,9 +52,9 @@ WUPS_PLUGIN_LICENSE("GPL"); #define UPPER_TITLE_ID_HOMEBREW 0x0005000F #define TITLE_ID_HOMEBREW_MASK (((uint64_t) UPPER_TITLE_ID_HOMEBREW) << 32) -ACPMetaXml gLaunchXML __attribute__((section(".data"))); -MCPTitleListType current_launched_title_info __attribute__((section(".data"))); -BOOL gHomebrewLaunched __attribute__((section(".data"))); +ACPMetaXml gLaunchXML = {}; +MCPTitleListType current_launched_title_info = {}; +BOOL gHomebrewLaunched = {}; std::mutex fileInfosMutex; std::forward_list> fileInfos; @@ -79,9 +79,14 @@ WUPS_USE_STORAGE("homebrew_on_menu"); // Use the storage API #define HOMEBREW_LAUNCHER_PATH HOMEBREW_APPS_DIRECTORY "/" HOMEBREW_LAUNCHER_FILENAME #define HOMEBREW_LAUNCHER_PATH2 HOMEBREW_APPS_DIRECTORY "/" HOMEBREW_LAUNCHER_OPTIONAL_DIRECTORY "/" HOMEBREW_LAUNCHER_FILENAME -bool gHideHomebrew = false; -bool gPreferWUHBOverRPX = true; -bool gHideAllRPX = false; + +#define DEFAULT_HIDE_HOMEBREW_VALUE false +#define DEFAULT_PREFER_WUHB_OVER_RPX_VALUE true +#define DEFAULT_HIDE_ALL_RPX_VALUE false +bool gHideHomebrew = DEFAULT_HIDE_HOMEBREW_VALUE; +bool gPreferWUHBOverRPX = DEFAULT_PREFER_WUHB_OVER_RPX_VALUE; +bool gHideAllRPX = DEFAULT_HIDE_ALL_RPX_VALUE; + bool prevHideValue = false; bool prevPreferWUHBOverRPXValue = false; bool prevHideAllRPX = false; @@ -90,6 +95,9 @@ bool gHomebrewLauncherExists = false; std::vector gIgnorePatterns; +WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHandle rootHandle); +void ConfigMenuClosedCallback(); + INITIALIZE_PLUGIN() { memset((void *) ¤t_launched_title_info, 0, sizeof(current_launched_title_info)); memset((void *) &gLaunchXML, 0, sizeof(gLaunchXML)); @@ -98,86 +106,67 @@ INITIALIZE_PLUGIN() { gSerialId = {}; if (!Utils::GetSerialId(gSerialId) || gSerialId.empty()) { DEBUG_FUNCTION_LINE_ERR("Homebrew on Menu Plugin: Failed to get the serial id"); - OSFatal("Homebrew on Menu Plugin: Failed to get the serial id"); + OSFatal("Homebrew on menu plugin: Failed to get the serial id"); } // Use libwuhbutils. WUHBUtilsStatus error; if ((error = WUHBUtils_InitLibrary()) != WUHB_UTILS_RESULT_SUCCESS) { - DEBUG_FUNCTION_LINE_ERR("Homebrew on Menu Plugin: Failed to init WUHBUtils. Error %s [%d]", WUHBUtils_GetStatusStr(error), error); - OSFatal("Homebrew on Menu Plugin: Failed to init WUHBUtils."); + DEBUG_FUNCTION_LINE_ERR("Homebrew on menu plugin: Failed to init WUHBUtils. Error %s [%d]", WUHBUtils_GetStatusStr(error), error); + OSFatal("Homebrew on menu plugin: Failed to init WUHBUtils."); } // Use libcontentredirection. ContentRedirectionStatus error2; if ((error2 = ContentRedirection_InitLibrary()) != CONTENT_REDIRECTION_RESULT_SUCCESS) { - DEBUG_FUNCTION_LINE_ERR("Homebrew on Menu Plugin: Failed to init ContentRedirection. Error %s [%d]", ContentRedirection_GetStatusStr(error2), error2); - OSFatal("Homebrew on Menu Plugin: Failed to init ContentRedirection."); + DEBUG_FUNCTION_LINE_ERR("Homebrew on menu plugin: Failed to init ContentRedirection. Error %s [%d]", ContentRedirection_GetStatusStr(error2), error2); + OSFatal("Homebrew on menu plugin: Failed to init ContentRedirection."); } // Use librpxloader. RPXLoaderStatus error3; if ((error3 = RPXLoader_InitLibrary()) != RPX_LOADER_RESULT_SUCCESS) { - DEBUG_FUNCTION_LINE_ERR("Homebrew on Menu Plugin: Failed to init RPXLoader. Error %s [%d]", RPXLoader_GetStatusStr(error3), error3); - OSFatal("Homebrew on Menu Plugin: Failed to init RPXLoader."); + DEBUG_FUNCTION_LINE_ERR("Homebrew on menu plugin: Failed to init RPXLoader. Error %s [%d]", RPXLoader_GetStatusStr(error3), error3); + OSFatal("Homebrew on menu plugin: Failed to init RPXLoader."); } // Use libnotifications. NotificationModuleStatus error4; if ((error4 = NotificationModule_InitLibrary()) != NOTIFICATION_MODULE_RESULT_SUCCESS) { - DEBUG_FUNCTION_LINE_ERR("Homebrew on Menu Plugin: Failed to init NotificationModule. Error %s [%d]", NotificationModule_GetStatusStr(error4), error4); - OSFatal("Homebrew on Menu Plugin: Failed to init NotificationModule."); + DEBUG_FUNCTION_LINE_ERR("Homebrew on menu plugin: Failed to init NotificationModule. Error %s [%d]", NotificationModule_GetStatusStr(error4), error4); + OSFatal("Homebrew on menu plugin: Failed to init NotificationModule."); } - // Open storage to read values - WUPSStorageError storageRes = WUPS_OpenStorage(); - if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { - DEBUG_FUNCTION_LINE_ERR("Failed to open storage %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); - } else { - // Try to get value from storage - if ((storageRes = WUPS_GetBool(nullptr, HIDE_HOMEBREW_STRING, &gHideHomebrew)) == WUPS_STORAGE_ERROR_NOT_FOUND) { - // Add the value to the storage if it's missing. - storageRes = WUPS_StoreBool(nullptr, HIDE_HOMEBREW_STRING, gHideHomebrew); - if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { - DEBUG_FUNCTION_LINE_ERR("Failed to store bool %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); - } - } else { - if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { - DEBUG_FUNCTION_LINE_ERR("Failed to get bool %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); - } - } + WUPSConfigAPIOptionsV1 configOptions = {.name = "Homebrew On Wii U Menu Plugin"}; + if (WUPSConfigAPI_Init(configOptions, ConfigMenuOpenedCallback, ConfigMenuClosedCallback) != WUPSCONFIG_API_RESULT_SUCCESS) { + DEBUG_FUNCTION_LINE_ERR("Failed to init config api"); + } - if ((storageRes = WUPS_GetBool(nullptr, PREFER_WUHB_OVER_RPX_STRING, &gPreferWUHBOverRPX)) == WUPS_STORAGE_ERROR_NOT_FOUND) { - // Add the value to the storage if it's missing. - storageRes = WUPS_StoreBool(nullptr, PREFER_WUHB_OVER_RPX_STRING, gPreferWUHBOverRPX); - if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { - DEBUG_FUNCTION_LINE_ERR("Failed to store bool %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); - } - } else { - if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { - DEBUG_FUNCTION_LINE_ERR("Failed to get bool %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); - } - } + WUPSStorageError storageError; + storageError = WUPSStorageAPI::GetOrStoreDefault(HIDE_HOMEBREW_STRING, gHideHomebrew, DEFAULT_HIDE_HOMEBREW_VALUE); + if (storageError != WUPS_STORAGE_ERROR_SUCCESS) { + DEBUG_FUNCTION_LINE_ERR("Failed to get or set default bool: %s", WUPSStorageAPI::GetStatusStr(storageError).data()); + } - if ((storageRes = WUPS_GetBool(nullptr, HIDE_ALL_RPX_STRING, &gHideAllRPX)) == WUPS_STORAGE_ERROR_NOT_FOUND) { - // Add the value to the storage if it's missing. - storageRes = WUPS_StoreBool(nullptr, HIDE_ALL_RPX_STRING, gHideAllRPX); - if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { - DEBUG_FUNCTION_LINE_ERR("Failed to store bool %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); - } - } else { - if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { - DEBUG_FUNCTION_LINE_ERR("Failed to get bool %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); - } - } + storageError = WUPSStorageAPI::GetOrStoreDefault(PREFER_WUHB_OVER_RPX_STRING, gPreferWUHBOverRPX, DEFAULT_PREFER_WUHB_OVER_RPX_VALUE); + if (storageError != WUPS_STORAGE_ERROR_SUCCESS) { + DEBUG_FUNCTION_LINE_ERR("Failed to get or set default bool: %s", WUPSStorageAPI::GetStatusStr(storageError).data()); + } - prevHideValue = gHideHomebrew; - prevPreferWUHBOverRPXValue = gPreferWUHBOverRPX; - prevHideAllRPX = gHideAllRPX; + storageError = WUPSStorageAPI::GetOrStoreDefault(HIDE_ALL_RPX_STRING, gHideAllRPX, DEFAULT_HIDE_ALL_RPX_VALUE); + if (storageError != WUPS_STORAGE_ERROR_SUCCESS) { + DEBUG_FUNCTION_LINE_ERR("Failed to get or set default bool: %s", WUPSStorageAPI::GetStatusStr(storageError).data()); + } - // Close storage - WUPS_CloseStorage(); + // save storage + storageError = WUPSStorageAPI::SaveStorage(); + if (storageError != WUPS_STORAGE_ERROR_SUCCESS) { + DEBUG_FUNCTION_LINE_ERR("Failed to save storage: %s", WUPSStorageAPI::GetStatusStr(storageError).data()); } + + prevHideValue = gHideHomebrew; + prevPreferWUHBOverRPXValue = gPreferWUHBOverRPX; + prevHideAllRPX = gHideAllRPX; } void hideHomebrewChanged(ConfigItemBoolean *item, bool newValue) { @@ -185,9 +174,9 @@ void hideHomebrewChanged(ConfigItemBoolean *item, bool newValue) { gHideHomebrew = newValue; // If the value has changed, we store it in the storage. - WUPSStorageError storageRes = WUPS_StoreBool(nullptr, HIDE_HOMEBREW_STRING, gHideHomebrew); + WUPSStorageError storageRes = WUPSStorageAPI::Store(HIDE_HOMEBREW_STRING, gHideHomebrew); if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { - DEBUG_FUNCTION_LINE_ERR("Failed to store bool: %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); + DEBUG_FUNCTION_LINE_ERR("Failed to store bool: %s", WUPSStorageAPI::GetStatusStr(storageRes).data()); } } @@ -196,9 +185,9 @@ void preferWUHBOverRPXChanged(ConfigItemBoolean *item, bool newValue) { gPreferWUHBOverRPX = newValue; // If the value has changed, we store it in the storage. - WUPSStorageError storageRes = WUPS_StoreBool(nullptr, PREFER_WUHB_OVER_RPX_STRING, gPreferWUHBOverRPX); + WUPSStorageError storageRes = WUPSStorageAPI::Store(PREFER_WUHB_OVER_RPX_STRING, gPreferWUHBOverRPX); if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { - DEBUG_FUNCTION_LINE_ERR("Failed to store bool: %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); + DEBUG_FUNCTION_LINE_ERR("Failed to store bool: %s", WUPSStorageAPI::GetStatusStr(storageRes).data()); } } @@ -207,46 +196,46 @@ void hideAllRPXChanged(ConfigItemBoolean *item, bool newValue) { gHideAllRPX = newValue; // If the value has changed, we store it in the storage. - WUPSStorageError storageRes = WUPS_StoreBool(nullptr, HIDE_ALL_RPX_STRING, gHideAllRPX); + WUPSStorageError storageRes = WUPSStorageAPI::Store(HIDE_ALL_RPX_STRING, gHideAllRPX); if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { - DEBUG_FUNCTION_LINE_ERR("Failed to store bool: %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); + DEBUG_FUNCTION_LINE_ERR("Failed to store bool: %s", WUPSStorageAPI::GetStatusStr(storageRes).data()); } } -WUPS_GET_CONFIG() { - // We open the storage so we can persist the configuration the user did. - WUPSStorageError storageRes; - DEBUG_FUNCTION_LINE_ERR("In WUPS_GET_CONFIG"); - if ((storageRes = WUPS_OpenStorage()) != WUPS_STORAGE_ERROR_SUCCESS) { - DEBUG_FUNCTION_LINE_ERR("Failed to open storage %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); - return 0; - } +WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHandle rootHandle) { + try { + WUPSConfigCategory root = WUPSConfigCategory(rootHandle); - WUPSConfigHandle config; - WUPSConfig_CreateHandled(&config, "Homebrew on Menu"); - - WUPSConfigCategoryHandle cat; - WUPSConfig_AddCategoryByNameHandled(config, "Features", &cat); - - WUPSConfigItemBoolean_AddToCategoryHandled(config, cat, HIDE_HOMEBREW_STRING, + root.add(WUPSConfigItemBoolean::Create(HIDE_HOMEBREW_STRING, gHomebrewLauncherExists ? "Hide all homebrew except Homebrew Launcher" : "Hide all homebrew", - gHideHomebrew, &hideHomebrewChanged); + DEFAULT_HIDE_HOMEBREW_VALUE, gHideHomebrew, + &hideHomebrewChanged)); - WUPSConfigItemBoolean_AddToCategoryHandled(config, cat, PREFER_WUHB_OVER_RPX_STRING, "Prefer .wuhb over .rpx", gPreferWUHBOverRPX, &preferWUHBOverRPXChanged); - WUPSConfigItemBoolean_AddToCategoryHandled(config, cat, HIDE_ALL_RPX_STRING, "Hide all .rpx", gHideAllRPX, &hideAllRPXChanged); + root.add(WUPSConfigItemBoolean::Create(PREFER_WUHB_OVER_RPX_STRING, + "Prefer .wuhb over .rpx", + DEFAULT_PREFER_WUHB_OVER_RPX_VALUE, gPreferWUHBOverRPX, + &preferWUHBOverRPXChanged)); - return config; + root.add(WUPSConfigItemBoolean::Create(HIDE_ALL_RPX_STRING, + "Hide all .rpx", + DEFAULT_HIDE_ALL_RPX_VALUE, gHideAllRPX, + &hideAllRPXChanged)); + } catch (std::exception &e) { + OSReport("Exception: %s\n", e.what()); + return WUPSCONFIG_API_CALLBACK_RESULT_ERROR; + } + return WUPSCONFIG_API_CALLBACK_RESULT_SUCCESS; } bool sSDUtilsInitDone = false; bool sSDIsMounted = false; bool sTitleRebooting = false; -WUPS_CONFIG_CLOSED() { +void ConfigMenuClosedCallback() { // Save all changes - WUPSStorageError storageRes; - if ((storageRes = WUPS_CloseStorage()) != WUPS_STORAGE_ERROR_SUCCESS) { - DEBUG_FUNCTION_LINE_ERR("Failed to close storage %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); + auto saveErr = WUPSStorageAPI::SaveStorage(); + if (saveErr != WUPS_STORAGE_ERROR_SUCCESS) { + DEBUG_FUNCTION_LINE_ERR("Failed to save storage: %s", WUPSStorageAPI::GetStatusStr(saveErr).data()); } if (prevHideValue != gHideHomebrew || prevPreferWUHBOverRPXValue != gPreferWUHBOverRPX || prevHideAllRPX != gHideAllRPX) { @@ -314,7 +303,7 @@ ON_APPLICATION_START() { // Ignore all lines that start with '#' gIgnorePatterns.erase(std::remove_if(gIgnorePatterns.begin(), gIgnorePatterns.end(), [](auto &line) { return line.starts_with('#'); }), gIgnorePatterns.end()); } else { - DEBUG_FUNCTION_LINE_ERR("No ignore found"); + DEBUG_FUNCTION_LINE_INFO("No ignore found"); } gInWiiUMenu = true; diff --git a/src/main.h b/src/main.h index d865e67..e430146 100644 --- a/src/main.h +++ b/src/main.h @@ -2,5 +2,5 @@ #include "version.h" -#define VERSION "v0.1.7" +#define VERSION "v0.1.8" #define VERSION_FULL VERSION VERSION_EXTRA