SaveRedirection: Fix copy files when swichting accounts

This commit is contained in:
Maschell 2022-04-28 20:24:53 +02:00
parent 622dff63c6
commit 57eee716bc

View File

@ -15,6 +15,7 @@ CRLayerHandle saveLayer __attribute__((section(".data"))) = 0;
void SaveRedirectionCleanUp() { void SaveRedirectionCleanUp() {
if (saveLayer != 0) { if (saveLayer != 0) {
DEBUG_FUNCTION_LINE("Remove save redirection: %s -> %s", "/vol/save", "fs:" SAVE_REPLACEMENT_PATH "/save/");
auto res = ContentRedirection_RemoveFSLayer(saveLayer); auto res = ContentRedirection_RemoveFSLayer(saveLayer);
if (res != CONTENT_REDIRECTION_RESULT_SUCCESS) { if (res != CONTENT_REDIRECTION_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to remove save FSLayer"); DEBUG_FUNCTION_LINE_ERR("Failed to remove save FSLayer");
@ -22,7 +23,8 @@ void SaveRedirectionCleanUp() {
saveLayer = 0; saveLayer = 0;
} }
} }
void initSaveData() {
void CopyExistingFiles() {
nn::act::Initialize(); nn::act::Initialize();
nn::act::PersistentId persistentId = nn::act::GetPersistentId(); nn::act::PersistentId persistentId = nn::act::GetPersistentId();
nn::act::Finalize(); nn::act::Finalize();
@ -61,7 +63,13 @@ void initSaveData() {
DEBUG_FUNCTION_LINE_ERR("Failed to copy file: %s -> %s", BaristaIconDataBaseOriginal.c_str(), BaristaIconDataBase.c_str()); DEBUG_FUNCTION_LINE_ERR("Failed to copy file: %s -> %s", BaristaIconDataBaseOriginal.c_str(), BaristaIconDataBase.c_str());
} }
} }
}
void initSaveData() {
CopyExistingFiles();
SaveRedirectionCleanUp(); SaveRedirectionCleanUp();
DEBUG_FUNCTION_LINE("Setup save redirection: %s -> %s", "/vol/save", "fs:" SAVE_REPLACEMENT_PATH "/save/");
auto res = ContentRedirection_AddFSLayer(&saveLayer, "homp_save_redirection", "fs:" SAVE_REPLACEMENT_PATH "/save/", FS_LAYER_TYPE_SAVE_REPLACE); auto res = ContentRedirection_AddFSLayer(&saveLayer, "homp_save_redirection", "fs:" SAVE_REPLACEMENT_PATH "/save/", FS_LAYER_TYPE_SAVE_REPLACE);
if (res != CONTENT_REDIRECTION_RESULT_SUCCESS) { if (res != CONTENT_REDIRECTION_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to add save FS Layer: %d", res); DEBUG_FUNCTION_LINE_ERR("Failed to add save FS Layer: %d", res);
@ -73,8 +81,7 @@ DECL_FUNCTION(int32_t, LoadConsoleAccount__Q2_2nn3actFUc13ACTLoadOptionPCcb, nn:
if (result >= 0 && gInWiiUMenu) { if (result >= 0 && gInWiiUMenu) {
DEBUG_FUNCTION_LINE("Changed account, we need to init the save data"); DEBUG_FUNCTION_LINE("Changed account, we need to init the save data");
// If the account has changed, we need to init save data for this account // If the account has changed, we need to init save data for this account
// Calls our function replacement. CopyExistingFiles();
SAVEInit();
} }
return result; return result;