From e70e0c2825e8cd301552bdc687364b63ffa65516 Mon Sep 17 00:00:00 2001 From: Lekoopapaul Date: Wed, 22 May 2024 21:23:45 +0200 Subject: [PATCH] add save Rediretion --- src/globals.cpp | 3 ++- src/globals.h | 1 + src/main.cpp | 5 +++++ src/modpackSelector.cpp | 26 ++++++++++++++++++++------ 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/globals.cpp b/src/globals.cpp index a1d6564..64abece 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -6,4 +6,5 @@ bool gSDCafiineEnabled = DEFAULT_SDCAFIINE_ENABLED; CRLayerHandle gContentLayerHandle = 0; -CRLayerHandle gAocLayerHandle = 0; \ No newline at end of file +CRLayerHandle gAocLayerHandle = 0; +CRLayerHandle gSaveLayerHandle = 0; \ No newline at end of file diff --git a/src/globals.h b/src/globals.h index 512e88b..1696443 100644 --- a/src/globals.h +++ b/src/globals.h @@ -19,3 +19,4 @@ extern bool gSDCafiineEnabled; extern CRLayerHandle gAocLayerHandle; extern CRLayerHandle gContentLayerHandle; +extern CRLayerHandle gSaveLayerHandle; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 477e1d8..f13063b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,6 +27,7 @@ INITIALIZE_PLUGIN() { gContentLayerHandle = 0; gAocLayerHandle = 0; + gSaveLayerHandle = 0; } /* Entry point */ @@ -48,5 +49,9 @@ ON_APPLICATION_ENDS() { ContentRedirection_RemoveFSLayer(gAocLayerHandle); gAocLayerHandle = 0; } + if (gSaveLayerHandle != 0) { + ContentRedirection_RemoveFSLayer(gSaveLayerHandle); + gSaveLayerHandle = 0; + } deinitLogging(); } \ No newline at end of file diff --git a/src/modpackSelector.cpp b/src/modpackSelector.cpp index 3705711..5c83ac3 100644 --- a/src/modpackSelector.cpp +++ b/src/modpackSelector.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #define TEXT_SEL(x, text1, text2) ((x) ? (text1) : (text2)) @@ -313,11 +314,12 @@ void HandleMultiModPacks(uint64_t titleID) { KPADShutdown(); } -bool ReplaceContentInternal(const std::string &basePath, const std::string &subdir, CRLayerHandle *layerHandle); +bool ReplaceContentInternal(const std::string &basePath, const std::string &subdir, CRLayerHandle *layerHandle,FSLayerType layerType); bool ReplaceContent(const std::string &basePath, const std::string &modpack) { - bool contentRes = ReplaceContentInternal(basePath, "content", &gContentLayerHandle); - bool aocRes = ReplaceContentInternal(basePath, "aoc", &gAocLayerHandle); + bool contentRes = ReplaceContentInternal(basePath, "content", &gContentLayerHandle,FS_LAYER_TYPE_CONTENT_MERGE); + bool aocRes = ReplaceContentInternal(basePath, "aoc", &gAocLayerHandle,FS_LAYER_TYPE_AOC_MERGE); + bool saveRes = ReplaceContentInternal(basePath, "save", &gSaveLayerHandle,FS_LAYER_TYPE_SAVE_REPLACE); if (!contentRes && !aocRes) { auto screenWasAllocated = screenBuffer_0 != nullptr; @@ -379,9 +381,21 @@ bool ReplaceContent(const std::string &basePath, const std::string &modpack) { return true; } -bool ReplaceContentInternal(const std::string &basePath, const std::string &subdir, CRLayerHandle *layerHandle) { - std::string layerName = "SDCafiine /vol/" + subdir; +bool ReplaceContentInternal(const std::string &basePath, const std::string &subdir, CRLayerHandle *layerHandle,FSLayerType layerType) { + std::string layerName = "SDCafiine Plus /vol/" + subdir; std::string fullPath = basePath + "/" + subdir; + if(layerType == FS_LAYER_TYPE_SAVE_REPLACE){ + nn::act::Initialize(); + nn::act::PersistentId id = nn::act::GetPersistentId(); + nn::act::Finalize(); + + char user[9]; + snprintf(user, 9, "%08x", 0x80000000 | id); + + mkdir(fullPath.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + mkdir((fullPath+"/"+"common").c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + mkdir((fullPath+"/"+user).c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + } struct stat st {}; if (stat(fullPath.c_str(), &st) < 0) { DEBUG_FUNCTION_LINE_WARN("Skip /vol/%s to %s redirection. Dir does not exist", subdir.c_str(), fullPath.c_str()); @@ -391,7 +405,7 @@ bool ReplaceContentInternal(const std::string &basePath, const std::string &subd auto res = ContentRedirection_AddFSLayer(layerHandle, layerName.c_str(), fullPath.c_str(), - subdir == "aoc" ? FS_LAYER_TYPE_AOC_MERGE : FS_LAYER_TYPE_CONTENT_MERGE); + layerType); if (res == CONTENT_REDIRECTION_RESULT_SUCCESS) { DEBUG_FUNCTION_LINE("Redirect /vol/%s to %s", subdir.c_str(), fullPath.c_str()); } else {