From 28bd63aa48a0f78a3e5c224e23fb0f6bdb068623 Mon Sep 17 00:00:00 2001 From: w3irDv <170813473+w3irDv@users.noreply.github.com> Date: Sat, 24 Aug 2024 16:42:02 +0200 Subject: [PATCH] change in batch backup don't overwrite logic - always use slot 0, slot 1 only for duplicate NAND savedata --- include/savemng.h | 1 + src/menu/BatchBackupState.cpp | 5 ---- src/savemng.cpp | 55 +++++++++++++++++++++++------------ 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/include/savemng.h b/include/savemng.h index 7d48037..ffb1392 100644 --- a/include/savemng.h +++ b/include/savemng.h @@ -116,6 +116,7 @@ bool hasAccountSave(Title *title, bool inSD, bool iine, uint32_t user, uint8_t s bool getLoadiineGameSaveDir(char *out, const char *productCode, const char *longName, const uint32_t highID, const uint32_t lowID); bool getLoadiineSaveVersionList(int *out, const char *gamePath); bool isSlotEmpty(uint32_t highID, uint32_t lowID, uint8_t slot); +bool isSlotEmpty(uint32_t highID, uint32_t lowID, uint8_t slot, const std::string &batchDatetime); bool hasCommonSave(Title *title, bool inSD, bool iine, uint8_t slot, int version); void copySavedata(Title *title, Title *titled, int8_t wiiuuser, int8_t wiiuuser_d, bool common) __attribute__((hot)); std::string getNowDateForFolder() __attribute__((hot)); diff --git a/src/menu/BatchBackupState.cpp b/src/menu/BatchBackupState.cpp index 4a7b82c..840a312 100644 --- a/src/menu/BatchBackupState.cpp +++ b/src/menu/BatchBackupState.cpp @@ -19,11 +19,6 @@ void BatchBackupState::render() { (this->wiiuTitlesCount > 1) ? "s" : ""); consolePrintPos(M_OFF, 4, LanguageUtils::gettext(" Backup vWii (%u Title%s)"), this->vWiiTitlesCount, (this->vWiiTitlesCount > 1) ? "s" : ""); - DrawUtils::setFontColor(COLOR_INFO); - consolePrintPosAligned(10,4,2,LanguageUtils::gettext("WiiU USB Savedata >> slot 0")); - consolePrintPosAligned(11,4,2,LanguageUtils::gettext("WiiU NAND Savedata >> slot 1")); - consolePrintPosAligned(12,4,2,LanguageUtils::gettext("vWii Savedata >> slot 0")); - DrawUtils::setFontColor(COLOR_TEXT); consolePrintPos(M_OFF, 2 + cursorPos, "\u2192"); consolePrintPosAligned(17, 4, 2, LanguageUtils::gettext("\ue000: Backup \ue001: Back")); } diff --git a/src/savemng.cpp b/src/savemng.cpp index c1beb0c..186e30b 100644 --- a/src/savemng.cpp +++ b/src/savemng.cpp @@ -729,6 +729,13 @@ bool isSlotEmpty(uint32_t highID, uint32_t lowID, uint8_t slot) { return ret <= 0; } +bool isSlotEmpty(uint32_t highID, uint32_t lowID, uint8_t slot, const std::string &batchDatetime) { + std::string path; + path = getBatchBackupPath(highID,lowID,slot,batchDatetime); + int ret = checkEntry(path.c_str()); + return ret <= 0; +} + static int getEmptySlot(uint32_t highID, uint32_t lowID) { for (int i = 0; i < 256; i++) if (isSlotEmpty(highID, lowID, i)) @@ -736,6 +743,14 @@ static int getEmptySlot(uint32_t highID, uint32_t lowID) { return -1; } +static int getEmptySlot(uint32_t highID, uint32_t lowID, const std::string &batchDatetime) { + for (int i = 0; i < 256; i++) + if (isSlotEmpty(highID, lowID, i, batchDatetime)) + return i; + return -1; +} + + bool hasAccountSave(Title *title, bool inSD, bool iine, uint32_t user, uint8_t slot, int version) { uint32_t highID = title->highID; uint32_t lowID = title->lowID; @@ -948,26 +963,28 @@ void writeMetadata(uint32_t highID,uint32_t lowID,uint8_t slot,bool isUSB, const } void backupAllSave(Title *titles, int count, const std::string &batchDatetime) { - for (int i = 0; i < count; i++) { - if (titles[i].highID == 0 || titles[i].lowID == 0 || !titles[i].saveInit) - continue; - uint32_t highID = titles[i].highID; - uint32_t lowID = titles[i].lowID; - bool isUSB = titles[i].isTitleOnUSB; - bool isWii = ((highID & 0xFFFFFFF0) == 0x00010000); - uint8_t slot = ( isWii ? 0 : (isUSB ? 0 : 1)); - const std::string path = (isWii ? "storage_slccmpt01:/title" : (isUSB ? (getUSB() + "/usr/save").c_str() : "storage_mlc01:/usr/save")); - std::string srcPath = StringUtils::stringFormat("%s/%08x/%08x/%s", path.c_str(), highID, lowID, isWii ? "data" : "user"); - //std::string dstPath = StringUtils::stringFormat("%s/%s/%08x%08x/%u", batchBackupPath, batchDatetime.c_str(), highID, lowID,slot); - std::string dstPath = getBatchBackupPath(highID,lowID,slot, batchDatetime); - - createFolder(dstPath.c_str()); - if (!copyDir(srcPath, dstPath)) - promptError(LanguageUtils::gettext("Backup failed.")); - else - writeMetadata(highID,lowID,slot,isUSB,batchDatetime); + for ( int sourceStorage = 0; sourceStorage < 2 ; sourceStorage++ ) { + for (int i = 0; i < count; i++) { + if (titles[i].highID == 0 || titles[i].lowID == 0 || !titles[i].saveInit) + continue; + uint32_t highID = titles[i].highID; + uint32_t lowID = titles[i].lowID; + bool isUSB = titles[i].isTitleOnUSB; + bool isWii = ((highID & 0xFFFFFFF0) == 0x00010000); + if ((sourceStorage == 0 && !isUSB) || (sourceStorage == 1 && isUSB)) // backup first WiiU USB savedata to slot 0 + continue; + uint8_t slot = getEmptySlot(highID,lowID,batchDatetime); + const std::string path = (isWii ? "storage_slccmpt01:/title" : (isUSB ? (getUSB() + "/usr/save").c_str() : "storage_mlc01:/usr/save")); + std::string srcPath = StringUtils::stringFormat("%s/%08x/%08x/%s", path.c_str(), highID, lowID, isWii ? "data" : "user"); + std::string dstPath = getBatchBackupPath(highID,lowID,slot,batchDatetime); + + createFolder(dstPath.c_str()); + if (!copyDir(srcPath, dstPath)) + promptError(LanguageUtils::gettext("Backup failed.")); + else + writeMetadata(highID,lowID,slot,isUSB,batchDatetime); + } } - } void backupSavedata(Title *title, uint8_t slot, int8_t wiiuuser, bool common) {