diff --git a/Dockerfile b/Dockerfile index e4eb6d3..526ab36 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,9 @@ -FROM ghcr.io/wiiu-env/devkitppc:20230218 +FROM ghcr.io/wiiu-env/devkitppc:20230326 COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:20230215 /artifacts $DEVKITPRO COPY --from=ghcr.io/wiiu-env/libnotifications:20230126 /artifacts $DEVKITPRO COPY --from=ghcr.io/wiiu-env/librpxloader:20220903 /artifacts $DEVKITPRO COPY --from=ghcr.io/wiiu-env/libcurlwrapper:20230121 /artifacts $DEVKITPRO +COPY --from=ghcr.io/wiiu-env/libsdutils:20220903 /artifacts $DEVKITPRO WORKDIR project \ No newline at end of file diff --git a/Makefile b/Makefile index e6dd524..4ad9008 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ CXXFLAGS += -DDEBUG -DVERBOSE_DEBUG -g CFLAGS += -DDEBUG -DVERBOSE_DEBUG -g endif -LIBS := -lcurlwrapper -lnotifications -lrpxloader -lwups -lwut +LIBS := -lcurlwrapper -lnotifications -lrpxloader -lsdutils -lwups -lwut #------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level diff --git a/src/Hints.cpp b/src/Hints.cpp index a28340e..137baa3 100644 --- a/src/Hints.cpp +++ b/src/Hints.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include std::unique_ptr sShowHintThread; @@ -19,18 +20,30 @@ void ShowHints() { return; } - const char *tmp_file = "fs:/vol/external01/wiiu/write_lock"; - int fd = -1; - if ((fd = open(tmp_file, O_CREAT | O_TRUNC | O_RDWR)) < 0) { - NotificationModuleStatus err; - NMColor red = {237, 28, 36, 255}; - NotificationModuleHandle outHandle; - if ((err = NotificationModule_SetDefaultValue(NOTIFICATION_MODULE_NOTIFICATION_TYPE_DYNAMIC, NOTIFICATION_MODULE_DEFAULT_OPTION_BACKGROUND_COLOR, red)) == NOTIFICATION_MODULE_RESULT_SUCCESS && - (err = NotificationModule_AddDynamicNotification("Failed to write to the sd card. Please restart the console and make sure the sd card is not write locked.", &outHandle)) == NOTIFICATION_MODULE_RESULT_SUCCESS) { + bool isMounted = false; + if (SDUtils_IsSdCardMounted(&isMounted) != SDUTILS_RESULT_SUCCESS) { + DEBUG_FUNCTION_LINE_ERR("SDUtils_IsSdCardMounted failed"); + } + + if (isMounted) { + const char *tmp_file = "fs:/vol/external01/wiiu/write_lock"; + int fd = -1; + if ((fd = open(tmp_file, O_CREAT | O_TRUNC | O_RDWR)) < 0) { + DEBUG_FUNCTION_LINE_VERBOSE("SD Card mounted but not writable"); + NotificationModuleStatus err; + NMColor red = {237, 28, 36, 255}; + NotificationModuleHandle outHandle; + if ((err = NotificationModule_SetDefaultValue(NOTIFICATION_MODULE_NOTIFICATION_TYPE_DYNAMIC, NOTIFICATION_MODULE_DEFAULT_OPTION_BACKGROUND_COLOR, red)) != NOTIFICATION_MODULE_RESULT_SUCCESS || + (err = NotificationModule_AddDynamicNotification("Failed to write to the sd card. Please restart the console and make sure the sd card is not write locked.", &outHandle)) != NOTIFICATION_MODULE_RESULT_SUCCESS) { + DEBUG_FUNCTION_LINE_ERR("Failed to display notification: %s", NotificationModule_GetStatusStr(err)); + } + } else { + DEBUG_FUNCTION_LINE_VERBOSE("SD Card is mounted and writeable"); + close(fd); + remove(tmp_file); } } else { - close(fd); - remove(tmp_file); + DEBUG_FUNCTION_LINE_VERBOSE("SD Card is not mounted"); } if (!gConfigMenuHintShown) { diff --git a/src/main.cpp b/src/main.cpp index 15c63da..0dc9a9e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -21,6 +22,8 @@ WUPS_PLUGIN_LICENSE("GPL"); WUPS_USE_WUT_DEVOPTAB(); WUPS_USE_STORAGE("aroma_base_plugin"); // Unique id for the storage api +static bool sSDUtilsInitDone = false; + INITIALIZE_PLUGIN() { initLogging(); if (NotificationModule_InitLibrary() != NOTIFICATION_MODULE_RESULT_SUCCESS) { @@ -29,6 +32,9 @@ INITIALIZE_PLUGIN() { if (RPXLoader_InitLibrary() != RPX_LOADER_RESULT_SUCCESS) { DEBUG_FUNCTION_LINE_ERR("RPXLoader_InitLibrary failed"); } + if (SDUtils_InitLibrary() != SDUTILS_RESULT_SUCCESS) { + DEBUG_FUNCTION_LINE_ERR("SDUtils_InitLibrary failed"); + } // Open storage to read values WUPSStorageError storageRes = WUPS_OpenStorage(); @@ -92,6 +98,7 @@ ON_APPLICATION_ENDS() { DEINITIALIZE_PLUGIN() { NotificationModule_DeInitLibrary(); RPXLoader_DeInitLibrary(); + SDUtils_DeInitLibrary(); } DECL_FUNCTION(uint32_t, SuspendDaemonsAndDisconnectIfWireless__Q2_2nn3ndmFv) {