From 998f5a32198f23b78caf8f16d59afb71c78508c0 Mon Sep 17 00:00:00 2001 From: Maschell Date: Mon, 19 Sep 2022 17:48:14 +0200 Subject: [PATCH] Improve the error message on error --- src/modpackSelector.cpp | 52 +++++++++++++++++++++++++++++++++++------ src/modpackSelector.h | 2 +- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/modpackSelector.cpp b/src/modpackSelector.cpp index 3322699..2cefa27 100644 --- a/src/modpackSelector.cpp +++ b/src/modpackSelector.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -76,7 +77,7 @@ void HandleMultiModPacks(uint64_t titleID) { OSScreenFlipBuffersEx(SCREEN_DRC); if (modTitlePath.size() == 1 && gSkipPrepareIfSingleModpack) { - ReplaceContent(modTitlePath.begin()->second); + ReplaceContent(modTitlePath.begin()->second, modTitlePath.begin()->first); } else { @@ -143,7 +144,7 @@ void HandleMultiModPacks(uint64_t titleID) { } if (frameCounter >= durationInFrames) { - ReplaceContent(modTitlePath.begin()->second); + ReplaceContent(modTitlePath.begin()->second, modTitlePath.begin()->first); break; } @@ -214,7 +215,7 @@ void HandleMultiModPacks(uint64_t titleID) { std::string value = it.second; if (wantToExit && cur_ == selected) { - ReplaceContent(value); + ReplaceContent(value, key); break; } @@ -257,20 +258,57 @@ extern CRLayerHandle aocLayerHandle; bool ReplaceContentInternal(const std::string &basePath, const std::string &subdir, CRLayerHandle *layerHandle); -bool ReplaceContent(const std::string &basePath) { +bool ReplaceContent(const std::string &basePath, const std::string &modpack) { bool contentRes = ReplaceContentInternal(basePath, "content", &contentLayerHandle); bool aocRes = ReplaceContentInternal(basePath, "aoc", &aocLayerHandle); if (!contentRes && !aocRes) { - DEBUG_FUNCTION_LINE_ERR("Failed to apply modpack. Starting without mods."); + uint32_t sleepTime = 3000; + DEBUG_FUNCTION_LINE_ERR("Failed to apply the modpack. Starting without mods."); OSScreenClearBufferEx(SCREEN_TV, 0); OSScreenClearBufferEx(SCREEN_DRC, 0); console_print_pos(-2, -1, "SDCafiine plugin " VERSION VERSION_EXTRA); - console_print_pos(-2, 1, "Failed to apply modpack. Starting without mods."); + console_print_pos(-2, 1, "Failed to apply the modpack. Starting without mods..."); + bool folderExists = false; + struct stat st {}; + std::string contentPath = (std::string(modpack) + "/content"); + if (stat(contentPath.c_str(), &st) >= 0) { + folderExists = true; + } else { + console_print_pos(-2, 3, "No /vol/content replacement found (%s)", contentPath.c_str()); + } + + std::string aocPath = (std::string(modpack) + "/aoc"); + if (stat(aocPath.c_str(), &st) >= 0) { + folderExists = true; + } else { + console_print_pos(-2, 4, "No /vol/aoc replacement found (%s)", aocPath.c_str()); + } + if (folderExists) { + console_print_pos(-2, 6, "ContentRedirection_AddFSLayer failed"); + } else { + sleepTime = 5000; + console_print_pos(-2, 6, "You need at least one of the replacements!"); + + DIR *dir = opendir(basePath.c_str()); + if (dir) { + auto res = readdir(dir); + if (res != nullptr) { + sleepTime = 7000; + console_print_pos(-2, 8, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + console_print_pos(-2, 9, "!!! OLD DIRECTORY STRUCTURE DETECTED. !!!"); + console_print_pos(-2, 10, "!!! Please migrate to the new directory structure. !!!"); + console_print_pos(-2, 11, R"(!!! Move the files into the "content" directory of the modpack !!!)"); + console_print_pos(-2, 12, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + } + closedir(dir); + } + } + OSScreenFlipBuffersEx(SCREEN_TV); OSScreenFlipBuffersEx(SCREEN_DRC); - OSSleepTicks(OSMillisecondsToTicks(3000)); + OSSleepTicks(OSMillisecondsToTicks(sleepTime)); return false; } return true; diff --git a/src/modpackSelector.h b/src/modpackSelector.h index 4087e53..4cbffe3 100644 --- a/src/modpackSelector.h +++ b/src/modpackSelector.h @@ -5,4 +5,4 @@ void HandleMultiModPacks(uint64_t titleid /*,bool showMenu = true*/); void console_print_pos(int x, int y, const char *format, ...); -bool ReplaceContent(const std::string &basePath); \ No newline at end of file +bool ReplaceContent(const std::string &basePath, const std::string &modpack); \ No newline at end of file