add save Rediretion

This commit is contained in:
Lekoopapaul 2024-05-22 21:23:45 +02:00
parent 482a529b0f
commit e70e0c2825
4 changed files with 28 additions and 7 deletions

View File

@ -7,3 +7,4 @@ bool gSDCafiineEnabled = DEFAULT_SDCAFIINE_ENABLED;
CRLayerHandle gContentLayerHandle = 0; CRLayerHandle gContentLayerHandle = 0;
CRLayerHandle gAocLayerHandle = 0; CRLayerHandle gAocLayerHandle = 0;
CRLayerHandle gSaveLayerHandle = 0;

View File

@ -19,3 +19,4 @@ extern bool gSDCafiineEnabled;
extern CRLayerHandle gAocLayerHandle; extern CRLayerHandle gAocLayerHandle;
extern CRLayerHandle gContentLayerHandle; extern CRLayerHandle gContentLayerHandle;
extern CRLayerHandle gSaveLayerHandle;

View File

@ -27,6 +27,7 @@ INITIALIZE_PLUGIN() {
gContentLayerHandle = 0; gContentLayerHandle = 0;
gAocLayerHandle = 0; gAocLayerHandle = 0;
gSaveLayerHandle = 0;
} }
/* Entry point */ /* Entry point */
@ -48,5 +49,9 @@ ON_APPLICATION_ENDS() {
ContentRedirection_RemoveFSLayer(gAocLayerHandle); ContentRedirection_RemoveFSLayer(gAocLayerHandle);
gAocLayerHandle = 0; gAocLayerHandle = 0;
} }
if (gSaveLayerHandle != 0) {
ContentRedirection_RemoveFSLayer(gSaveLayerHandle);
gSaveLayerHandle = 0;
}
deinitLogging(); deinitLogging();
} }

View File

@ -16,6 +16,7 @@
#include <string> #include <string>
#include <utils/logger.h> #include <utils/logger.h>
#include <wups/storage.h> #include <wups/storage.h>
#include <nn/act.h>
#define TEXT_SEL(x, text1, text2) ((x) ? (text1) : (text2)) #define TEXT_SEL(x, text1, text2) ((x) ? (text1) : (text2))
@ -313,11 +314,12 @@ void HandleMultiModPacks(uint64_t titleID) {
KPADShutdown(); 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 ReplaceContent(const std::string &basePath, const std::string &modpack) {
bool contentRes = ReplaceContentInternal(basePath, "content", &gContentLayerHandle); bool contentRes = ReplaceContentInternal(basePath, "content", &gContentLayerHandle,FS_LAYER_TYPE_CONTENT_MERGE);
bool aocRes = ReplaceContentInternal(basePath, "aoc", &gAocLayerHandle); 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) { if (!contentRes && !aocRes) {
auto screenWasAllocated = screenBuffer_0 != nullptr; auto screenWasAllocated = screenBuffer_0 != nullptr;
@ -379,9 +381,21 @@ bool ReplaceContent(const std::string &basePath, const std::string &modpack) {
return true; return true;
} }
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) {
std::string layerName = "SDCafiine /vol/" + subdir; std::string layerName = "SDCafiine Plus /vol/" + subdir;
std::string fullPath = basePath + "/" + 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 {}; struct stat st {};
if (stat(fullPath.c_str(), &st) < 0) { 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()); 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, auto res = ContentRedirection_AddFSLayer(layerHandle,
layerName.c_str(), layerName.c_str(),
fullPath.c_str(), fullPath.c_str(),
subdir == "aoc" ? FS_LAYER_TYPE_AOC_MERGE : FS_LAYER_TYPE_CONTENT_MERGE); layerType);
if (res == CONTENT_REDIRECTION_RESULT_SUCCESS) { if (res == CONTENT_REDIRECTION_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE("Redirect /vol/%s to %s", subdir.c_str(), fullPath.c_str()); DEBUG_FUNCTION_LINE("Redirect /vol/%s to %s", subdir.c_str(), fullPath.c_str());
} else { } else {