Only display the write lock error when a sd card is mounted

This commit is contained in:
Maschell 2023-03-26 17:28:27 +02:00
parent f8261378ee
commit 2f0c88f157
4 changed files with 33 additions and 12 deletions

View File

@ -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/wiiupluginsystem:20230215 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/libnotifications:20230126 /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/librpxloader:20220903 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/libcurlwrapper:20230121 /artifacts $DEVKITPRO COPY --from=ghcr.io/wiiu-env/libcurlwrapper:20230121 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/libsdutils:20220903 /artifacts $DEVKITPRO
WORKDIR project WORKDIR project

View File

@ -48,7 +48,7 @@ CXXFLAGS += -DDEBUG -DVERBOSE_DEBUG -g
CFLAGS += -DDEBUG -DVERBOSE_DEBUG -g CFLAGS += -DDEBUG -DVERBOSE_DEBUG -g
endif 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 # list of directories containing libraries, this must be the top level

View File

@ -4,6 +4,7 @@
#include <coreinit/thread.h> #include <coreinit/thread.h>
#include <notifications/notification_defines.h> #include <notifications/notification_defines.h>
#include <notifications/notifications.h> #include <notifications/notifications.h>
#include <sdutils/sdutils.h>
#include <thread> #include <thread>
std::unique_ptr<std::thread> sShowHintThread; std::unique_ptr<std::thread> sShowHintThread;
@ -19,18 +20,30 @@ void ShowHints() {
return; return;
} }
const char *tmp_file = "fs:/vol/external01/wiiu/write_lock"; bool isMounted = false;
int fd = -1; if (SDUtils_IsSdCardMounted(&isMounted) != SDUTILS_RESULT_SUCCESS) {
if ((fd = open(tmp_file, O_CREAT | O_TRUNC | O_RDWR)) < 0) { DEBUG_FUNCTION_LINE_ERR("SDUtils_IsSdCardMounted failed");
NotificationModuleStatus err; }
NMColor red = {237, 28, 36, 255};
NotificationModuleHandle outHandle; if (isMounted) {
if ((err = NotificationModule_SetDefaultValue(NOTIFICATION_MODULE_NOTIFICATION_TYPE_DYNAMIC, NOTIFICATION_MODULE_DEFAULT_OPTION_BACKGROUND_COLOR, red)) == NOTIFICATION_MODULE_RESULT_SUCCESS && const char *tmp_file = "fs:/vol/external01/wiiu/write_lock";
(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) { 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 { } else {
close(fd); DEBUG_FUNCTION_LINE_VERBOSE("SD Card is not mounted");
remove(tmp_file);
} }
if (!gConfigMenuHintShown) { if (!gConfigMenuHintShown) {

View File

@ -9,6 +9,7 @@
#include <nn/spm.h> #include <nn/spm.h>
#include <notifications/notifications.h> #include <notifications/notifications.h>
#include <rpxloader/rpxloader.h> #include <rpxloader/rpxloader.h>
#include <sdutils/sdutils.h>
#include <utils/logger.h> #include <utils/logger.h>
#include <wups.h> #include <wups.h>
@ -21,6 +22,8 @@ WUPS_PLUGIN_LICENSE("GPL");
WUPS_USE_WUT_DEVOPTAB(); WUPS_USE_WUT_DEVOPTAB();
WUPS_USE_STORAGE("aroma_base_plugin"); // Unique id for the storage api WUPS_USE_STORAGE("aroma_base_plugin"); // Unique id for the storage api
static bool sSDUtilsInitDone = false;
INITIALIZE_PLUGIN() { INITIALIZE_PLUGIN() {
initLogging(); initLogging();
if (NotificationModule_InitLibrary() != NOTIFICATION_MODULE_RESULT_SUCCESS) { if (NotificationModule_InitLibrary() != NOTIFICATION_MODULE_RESULT_SUCCESS) {
@ -29,6 +32,9 @@ INITIALIZE_PLUGIN() {
if (RPXLoader_InitLibrary() != RPX_LOADER_RESULT_SUCCESS) { if (RPXLoader_InitLibrary() != RPX_LOADER_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("RPXLoader_InitLibrary failed"); 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 // Open storage to read values
WUPSStorageError storageRes = WUPS_OpenStorage(); WUPSStorageError storageRes = WUPS_OpenStorage();
@ -92,6 +98,7 @@ ON_APPLICATION_ENDS() {
DEINITIALIZE_PLUGIN() { DEINITIALIZE_PLUGIN() {
NotificationModule_DeInitLibrary(); NotificationModule_DeInitLibrary();
RPXLoader_DeInitLibrary(); RPXLoader_DeInitLibrary();
SDUtils_DeInitLibrary();
} }
DECL_FUNCTION(uint32_t, SuspendDaemonsAndDisconnectIfWireless__Q2_2nn3ndmFv) { DECL_FUNCTION(uint32_t, SuspendDaemonsAndDisconnectIfWireless__Q2_2nn3ndmFv) {