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

@ -6,4 +6,5 @@ bool gSDCafiineEnabled = DEFAULT_SDCAFIINE_ENABLED;
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 gContentLayerHandle;
extern CRLayerHandle gSaveLayerHandle;

View File

@ -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();
}

View File

@ -16,6 +16,7 @@
#include <string>
#include <utils/logger.h>
#include <wups/storage.h>
#include <nn/act.h>
#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 {