Skip to content

Commit

Permalink
change in batch backup don't overwrite logic - always use slot 0, slo…
Browse files Browse the repository at this point in the history
…t 1 only for duplicate NAND savedata
  • Loading branch information
w3irDv committed Aug 24, 2024
1 parent 112e616 commit 28bd63a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
1 change: 1 addition & 0 deletions include/savemng.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
5 changes: 0 additions & 5 deletions src/menu/BatchBackupState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand Down
55 changes: 36 additions & 19 deletions src/savemng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,13 +729,28 @@ 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))
return i;
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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 28bd63a

Please sign in to comment.