From cd212a9314627e64655fb4e6be8bcc2ff12ae41f Mon Sep 17 00:00:00 2001 From: Maschell Date: Thu, 28 Apr 2022 20:26:02 +0200 Subject: [PATCH] Skip Save Redirection if no SD Card is mounted --- src/SaveRedirection.cpp | 5 +++++ src/main.cpp | 13 ++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/SaveRedirection.cpp b/src/SaveRedirection.cpp index 799455b..cb48c93 100644 --- a/src/SaveRedirection.cpp +++ b/src/SaveRedirection.cpp @@ -87,9 +87,14 @@ DECL_FUNCTION(int32_t, LoadConsoleAccount__Q2_2nn3actFUc13ACTLoadOptionPCcb, nn: return result; } +extern bool sSDIsMounted; DECL_FUNCTION(int32_t, SAVEInit) { auto res = real_SAVEInit(); if (res >= 0) { + if (!sSDIsMounted) { + DEBUG_FUNCTION_LINE_VERBOSE("Skip SD redirection, no SD Card is mounted"); + return res; + } if (OSGetTitleID() == 0x0005001010040000L || // Wii U Menu JPN OSGetTitleID() == 0x0005001010040100L || // Wii U Menu USA OSGetTitleID() == 0x0005001010040200L) { // Wii U Menu EUR diff --git a/src/main.cpp b/src/main.cpp index e039d0c..d84fd23 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -88,7 +88,6 @@ bool sSDUtilsInitDone = false; bool sSDIsMounted = false; bool sTitleRebooting = false; - void Cleanup() { { const std::lock_guard lock1(fileReaderListMutex); @@ -110,6 +109,7 @@ void SDAttachedHandler([[maybe_unused]] SDUtilsAttachStatus status) { ON_APPLICATION_START() { Cleanup(); initLogging(); + sSDIsMounted = false; if (OSGetTitleID() == 0x0005001010040000L || // Wii U Menu JPN OSGetTitleID() == 0x0005001010040100L || // Wii U Menu USA @@ -117,9 +117,17 @@ ON_APPLICATION_START() { gInWiiUMenu = true; if (SDUtils_Init() >= 0) { + DEBUG_FUNCTION_LINE("SDUtils_Init done"); sSDUtilsInitDone = true; sTitleRebooting = false; - SDUtils_AddAttachHandler(SDAttachedHandler); + if (SDUtils_AddAttachHandler(SDAttachedHandler) != SDUTILS_RESULT_SUCCESS) { + DEBUG_FUNCTION_LINE_ERR("Failed to add AttachedHandler"); + } + if (SDUtils_IsSdCardMounted(&sSDIsMounted) != SDUTILS_RESULT_SUCCESS) { + DEBUG_FUNCTION_LINE_ERR("IsSdCardMounted failed"); + } + } else { + DEBUG_FUNCTION_LINE_ERR("Failed to init SDUtils. Make sure to have the SDHotSwapModule loaded!"); } } else { gInWiiUMenu = false; @@ -143,7 +151,6 @@ ON_APPLICATION_ENDS() { sSDIsMounted = false; } - std::optional> getIDByLowerTitleID(uint32_t titleid_lower) { std::lock_guard lock(fileInfosMutex); for (auto &cur : fileInfos) {