Skip to content

Commit

Permalink
batch restore - RC1
Browse files Browse the repository at this point in the history
  • Loading branch information
w3irDv committed Dec 26, 2024
1 parent 10fd4b5 commit d9ef89e
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 183 deletions.
1 change: 0 additions & 1 deletion include/menu/MainMenuState.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class MainMenuState : public ApplicationState {

void render() override;
ApplicationState::eSubState update(Input *input) override;
std::string tag;

private:
std::unique_ptr<ApplicationState> subState{};
Expand Down
3 changes: 2 additions & 1 deletion include/savemng.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ struct backupInfo {
bool selected;
bool hasUserSavedata;
bool hasCommonSavedata;
eBatchRestoreState batchRestoreState;
eBatchRestoreState batchRestoreState;
int lastErrCode;
};

struct Title {
Expand Down
23 changes: 23 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,35 @@ int main() {

DrawUtils::setFont();

DrawUtils::beginDraw();
DrawUtils::clear(COLOR_BLACK);
consolePrintPosAligned(10, 0, 1, LanguageUtils::gettext("Initializing WPAD and KAPD"));
DrawUtils::endDraw();

WPADInit();
KPADInit();
WPADEnableURCC(1);

DrawUtils::beginDraw();
DrawUtils::clear(COLOR_BLACK);
consolePrintPosAligned(10, 0, 1, LanguageUtils::gettext("Getting Serial ID"));
DrawUtils::endDraw();

getWiiUSerialId();

DrawUtils::beginDraw();
DrawUtils::clear(COLOR_BLACK);
consolePrintPosAligned(10, 0, 1, LanguageUtils::gettext("Initializing loadWiiU Titles"));
DrawUtils::endDraw();

loadWiiUTitles(0);


DrawUtils::beginDraw();
DrawUtils::clear(COLOR_BLACK);
consolePrintPosAligned(10, 0, 1, LanguageUtils::gettext("Initializing ROMFS"));
DrawUtils::endDraw();

int res = romfsInit();
if (res) {
promptError("Failed to init romfs: %d", res);
Expand All @@ -464,6 +485,7 @@ int main() {
Swkbd_LanguageType systemLanguage = LanguageUtils::getSystemLanguage();
LanguageUtils::loadLanguage(systemLanguage);

// notUsed
if (!DrawUtils::initKFont()) {
promptError("Failed to init keyboardFont");
DrawUtils::endDraw();
Expand All @@ -482,6 +504,7 @@ int main() {
DrawUtils::clear(COLOR_BLACK);
DrawUtils::endDraw();


Title *wiiutitles = loadWiiUTitles(1);
Title *wiititles = loadWiiTitles();
getAccountsWiiU();
Expand Down
112 changes: 68 additions & 44 deletions src/menu/BRTitleSelectState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ BRTitleSelectState::BRTitleSelectState(int sduser, int wiiuuser, bool common, bo
titlesCount(titlesCount),
isWiiUBatchRestore(isWiiUBatchRestore)
{
WHBLogPrintf("IN BRTitleSelectState. Inputs:");
WHBLogPrintf("sduser %d",sduser);
WHBLogPrintf("wiiuuser %d",wiiuuser);
WHBLogPrintf("common %c",common ? '0':'1');
Expand All @@ -45,21 +46,21 @@ BRTitleSelectState::BRTitleSelectState(int sduser, int wiiuuser, bool common, bo
if ( this->titles[i].currentBackup.hasBatchBackup == false )
continue;

WHBLogPrintf("get id %u",i);
WHBLogPrintf("shortname %s",this->titles[i].shortName);
//WHBLogPrintf("get id %u",i);
//WHBLogPrintf("shortname %s",this->titles[i].shortName);

uint32_t highID = this->titles[i].highID;
uint32_t lowID = this->titles[i].lowID;
bool isWii = titles[i].is_Wii;
WHBLogPrintf("is wii %s",isWii ? "si" : "no");
//WHBLogPrintf("is wii %s",isWii ? "si" : "no");

std::string srcPath = getDynamicBackupPath(highID, lowID, 0);

if (! isWii) {
std::string usersavePath = srcPath+"/"+getSDacc()[sduser].persistentID;

WHBLogPrintf("check user - %u",i);
WHBLogPrintf("check empty path - %s",usersavePath.c_str());
//WHBLogPrintf("check user - %u",i);
//WHBLogPrintf("check empty path - %s",usersavePath.c_str());

if (! folderEmpty(usersavePath.c_str()))
this->titles[i].currentBackup.hasUserSavedata = true;
Expand All @@ -75,8 +76,8 @@ BRTitleSelectState::BRTitleSelectState(int sduser, int wiiuuser, bool common, bo
if ( sduser != -1 && ! this->titles[i].currentBackup.hasCommonSavedata && ! this->titles[i].currentBackup.hasUserSavedata )
continue;

WHBLogPrintf("candiadte/select set to true - %u", i);
WHBLogPrintf("init select wiiU - is wii %s",isWii ? "si" : "no");
//WHBLogPrintf("candiadte/select set to true - %u", i);
//WHBLogPrintf("init select wiiU - is wii %s",isWii ? "si" : "no");
this->titles[i].currentBackup.candidateToBeRestored = true; // backup has enough data to try restore
this->titles[i].currentBackup.selected = true; // from candidates list, user can select/deselest at wish
if (! test) {
Expand All @@ -88,14 +89,16 @@ BRTitleSelectState::BRTitleSelectState(int sduser, int wiiuuser, bool common, bo
}
else
{
WHBLogPrintf("init select wii - is wii %s",isWii ? "si" : "no");
//WHBLogPrintf("init select wii - is wii %s",isWii ? "si" : "no");
this->titles[i].currentBackup.candidateToBeRestored = true;
this->titles[i].currentBackup.selected = true;
}
// to recover title from "candidate title" index
this->c2t.push_back(i);
this->titles[i].currentBackup.lastErrCode = 0;

}
WHBLogPrintf("out of loop");
//WHBLogPrintf("out of loop");
candidatesCount = (int) this->c2t.size();
WHBLogPrintf("init done. size: %u",candidatesCount);

Expand Down Expand Up @@ -138,14 +141,14 @@ void BRTitleSelectState::render() {
std::string nxtAction;
std::string lastState;
for (int i = 0; i < MAX_TITLE_SHOW; i++) {
WHBLogPrintf("iteracio %d",i);
//WHBLogPrintf("iteracio %d",i);
if (i + this->scroll < 0 || i + this->scroll >= (int) this->candidatesCount)
break;
bool isWii = this->titles[c2t[i + this->scroll]].is_Wii;
DrawUtils::setFontColor(static_cast<Color>(0x00FF00FF));
WHBLogPrintf("candidates %d",candidatesCount);
WHBLogPrintf("scroll %d ",scroll);
WHBLogPrintf("c2t %d",c2t[i + this->scroll]);
//WHBLogPrintf("candidates %d",candidatesCount);
//WHBLogPrintf("scroll %d ",scroll);
//WHBLogPrintf("c2t %d",c2t[i + this->scroll]);

if ( ! this->titles[c2t[i + this->scroll]].currentBackup.selected)
DrawUtils::setFontColor(static_cast<Color>(0x888800FF));
Expand All @@ -157,45 +160,51 @@ void BRTitleSelectState::render() {
DrawUtils::setFontColor(static_cast<Color>(0xFF0000FF));
if (this->titles[c2t[i + this->scroll]].currentBackup.batchRestoreState == OK)
DrawUtils::setFontColor(static_cast<Color>(0xFFFFFFFF));
WHBLogPrintf("nom");
//WHBLogPrintf("nom");

switch (this->titles[c2t[i + this->scroll]].currentBackup.batchRestoreState) {
case NOT_TRIED :
lastState = "[]";
nxtAction = this->titles[c2t[i + this->scroll]].currentBackup.selected ? LanguageUtils::gettext("[Restore]") : LanguageUtils::gettext("[Skip]");
nxtAction = this->titles[c2t[i + this->scroll]].currentBackup.selected ? LanguageUtils::gettext(">> Restore") : LanguageUtils::gettext(">> Skip");
break;
case OK :
lastState = LanguageUtils::gettext("[Ok]");
nxtAction = LanguageUtils::gettext("[Restored]");
lastState = LanguageUtils::gettext("[OK]");
nxtAction = LanguageUtils::gettext("|Restored|");
break;
case ABORTED :
lastState = LanguageUtils::gettext("[AbortedByUser]");
nxtAction = this->titles[c2t[i + this->scroll]].currentBackup.selected ? LanguageUtils::gettext("[Retry]") : LanguageUtils::gettext("[Skip]");
lastState = LanguageUtils::gettext("[AB]");
nxtAction = this->titles[c2t[i + this->scroll]].currentBackup.selected ? LanguageUtils::gettext(">> Retry") : LanguageUtils::gettext(">> Skip");
break;
case WR :
lastState = LanguageUtils::gettext("[Warning-CheckSave]");
nxtAction = this->titles[c2t[i + this->scroll]].currentBackup.selected ? LanguageUtils::gettext("[Retry]") : LanguageUtils::gettext("[Skip]");
lastState = LanguageUtils::gettext("[WR]");
nxtAction = this->titles[c2t[i + this->scroll]].currentBackup.selected ? LanguageUtils::gettext(">> Retry") : LanguageUtils::gettext(">> Skip");
break;
case KO:
nxtAction = this->titles[c2t[i + this->scroll]].currentBackup.selected ? LanguageUtils::gettext("[Retry]") : LanguageUtils::gettext("[Skip]");
lastState = LanguageUtils::gettext("[Failed]");
lastState = LanguageUtils::gettext("[KO]");
nxtAction = this->titles[c2t[i + this->scroll]].currentBackup.selected ? LanguageUtils::gettext(">> Retry") : LanguageUtils::gettext(">> Skip");
break;
default:
nxtAction = "";
lastState = "";
nxtAction = "";
break;
}


//int lastErrCode = this->titles[c2t[i + this->scroll]].currentBackup.lastErrCode;
//std::string lastErrCodeString = "(Err: "+std::to_string(lastErrCode)+")";
char shortName[32];
for (int p=0;p<32;p++)
shortName[p] = this->titles[c2t[i + this->scroll]].shortName[p];
shortName[31] = '\0';
consolePrintPos(M_OFF, i + 2, " %s %s %s %s %s %s",
this->titles[c2t[i + this->scroll]].shortName,
shortName,
this->titles[c2t[i + this->scroll]].isTitleOnUSB ? "(USB)" : "(NAND)",
this->titles[c2t[i + this->scroll]].isTitleDupe ? " [D]" : "",
this->titles[c2t[i + this->scroll]].saveInit ? "" : " [No Init]",
nxtAction.c_str(),lastState.c_str());
//WHBLogPrintf("shortname %s",this->titles[c2t[i + this->scroll]].shortName);
this->titles[c2t[i + this->scroll]].isTitleDupe ? "[D]" : "",
this->titles[c2t[i + this->scroll]].saveInit ? "" : "[No Init]",
lastState.c_str(),
nxtAction.c_str());
WHBLogPrintf("shortname %s nextAction: %s",this->titles[c2t[i + this->scroll]].shortName,
nxtAction.c_str());
DrawUtils::setFontColor(COLOR_TEXT);
//WHBLogPrintf("icona");
if (this->titles[c2t[i + this->scroll]].iconBuf != nullptr) {
if (isWii)
DrawUtils::drawRGB5A3((M_OFF + 2) * 12 - 2, (i + 3) * 24 + 3, 0.25,
Expand Down Expand Up @@ -256,15 +265,19 @@ ApplicationState::eSubState BRTitleSelectState::update(Input *input) {
fullBackup ? LanguageUtils::gettext("- Perform full backup: Y") : LanguageUtils::gettext("- Perform full backup: N"));
}

if (!promptConfirm(ST_WARNING,summary))
return SUBSTATE_RUNNING;
if (!promptConfirm(ST_WARNING,summary)) {
DrawUtils::setRedraw(true);
return SUBSTATE_RUNNING;
}

for (int i = 0; i < titlesCount ; i++) {
if (! this->titles[i].currentBackup.selected )
continue;
if (! this->titles[i].saveInit) {
if (!promptConfirm(ST_ERROR, LanguageUtils::gettext("You have selected uniniilized titles (not recommended). Are you 100% sure?")))
if (!promptConfirm(ST_ERROR, LanguageUtils::gettext("You have selected uninitialized titles (not recommended). Are you 100%% sure?"))) {
DrawUtils::setRedraw(true);
return SUBSTATE_RUNNING;
}
break;
}
}
Expand All @@ -275,7 +288,7 @@ ApplicationState::eSubState BRTitleSelectState::update(Input *input) {
WHBLogPrintf("perform all backup");
}

int retCode;
int retCode = 0;

for (int i = 0; i < titlesCount ; i++) {
if (! this->titles[i].currentBackup.selected )
Expand All @@ -301,11 +314,15 @@ ApplicationState::eSubState BRTitleSelectState::update(Input *input) {
}

retCode = wipeSavedata(&this->titles[i], wiiuuser, effectiveCommon, false);
WHBLogPrintf("wipe retcode: %d",retCode);
if (retCode > 0)
this->titles[i].currentBackup.batchRestoreState = WR;
WHBLogPrintf("%u - wipe user: %d common: %s",i,wiiuuser,effectiveCommon ? "si":"no");
}

wipeDone:
int globalRetCode = retCode<<8;
WHBLogPrintf("wipe ret code %d",retCode);
WHBLogPrintf("restoring");
if (sduser != -1) {
if ( ! this->titles[i].currentBackup.hasUserSavedata && effectiveCommon) {
Expand All @@ -314,30 +331,34 @@ ApplicationState::eSubState BRTitleSelectState::update(Input *input) {
if (retCode > 0)
this->titles[i].currentBackup.batchRestoreState = KO;
WHBLogPrintf("%u - restore user: %d common: %s",i,-2,effectiveCommon ? "si":"no");
continue;
goto restoreDone;
}
}
retCode = restoreSavedata(&this->titles[i], 0, sduser, wiiuuser, effectiveCommon, false); //always from slot 0
if (retCode > 0)
this->titles[i].currentBackup.batchRestoreState = KO;
WHBLogPrintf("%u - restore user: %d common: %s",i,wiiuuser,effectiveCommon ? "si":"no");

restoreDone:
if (this->titles[i].currentBackup.batchRestoreState == OK || this->titles[i].currentBackup.batchRestoreState == WR )
this->titles[i].currentBackup.selected = false;

globalRetCode = globalRetCode + retCode;
this->titles[i].currentBackup.lastErrCode = globalRetCode;
WHBLogPrintf("restore ret code %d",retCode);
}


WHBLogPrintf("restore done");

WHBLogPrintf("restore process done");
int titlesOK = 0;
int titlesAborted = 0;
int titlesWarning = 0;
int titlesKO = 0;
int titlesSkipped = 0;
for (int i = 0; i < titlesCount ; i++) {
if (this->titles[i].currentBackup.candidateToBeRestored && ! this->titles[i].currentBackup.selected) {
titlesSkipped++;
continue;
}
switch (this->titles[i].currentBackup.batchRestoreState) {
for (int i = 0; i < this->candidatesCount ; i++) {
WHBLogPrintf("%s restoreState %d",this->titles[c2t[i]].shortName,this->titles[c2t[i]].currentBackup.batchRestoreState);
switch (this->titles[c2t[i]].currentBackup.batchRestoreState) {
case OK :
titlesOK++;
break;
Expand All @@ -350,9 +371,12 @@ ApplicationState::eSubState BRTitleSelectState::update(Input *input) {
case ABORTED :
titlesAborted++;
break;
default:
titlesSkipped++;
break;
}
}
summaryTemplate = LanguageUtils::gettext("Restore done\n OK: %d\n Warning: %d\n KO: %d\n Aborted: %d\n Skipped: %d\n");
summaryTemplate = LanguageUtils::gettext("Restore completed. Results:\n- OK: %d\n- Warning: %d\n- KO: %d\n- Aborted: %d\n- Skipped: %d\n");
snprintf(summary,512,summaryTemplate,titlesOK,titlesWarning,titlesKO,titlesAborted,titlesSkipped);
promptMessage(COLOR_BG_SUCCESS,summary);
DrawUtils::setRedraw(true);
Expand Down
5 changes: 1 addition & 4 deletions src/menu/BackupSetListState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,13 @@ void BackupSetListState::render() {
}
if (this->state == STATE_BACKUPSET_MENU) {
std::string backupSetItem;
DrawUtils::setFontColor(COLOR_INFO);
if (BackupSetList::currentBackupSetList->entriesView == BackupSetList::currentBackupSetList->entries) {
consolePrintPosAligned(0, 4, 1, LanguageUtils::gettext("BackupSets"));
} else {
DrawUtils::setFontColor(COLOR_INFO);
consolePrintPosAligned(0, 4, 1, LanguageUtils::gettext("BackupSets (filter applied)"));
}
DrawUtils::setFontColor(COLOR_TEXT);
//consolePrintPos(47, 0, LanguageUtils::gettext("\ue083 Sort: %s \ue084"),
// this->sortAscending ? "\u2191" : "\u2193");
consolePrintPosAligned(0,4,2, LanguageUtils::gettext("\ue083 Sort: %s \ue084"),
this->sortAscending ? "\u2191" : "\u2193");
for (int i = 0; i < MAX_ROWS_SHOW; i++) {
Expand All @@ -84,7 +82,6 @@ void BackupSetListState::render() {
consolePrintPosAligned(17, 4, 2, LanguageUtils::gettext("\ue000: Select BS \ue045: Tag BS \ue046: Wipe BS \ue003: Filter List \ue001: Back"));
else
consolePrintPosAligned(17, 4, 2, LanguageUtils::gettext("\ue000: Select BackupSet \ue003: Filter List \ue001: Back"));
consolePrintPos (40,2,"tag %s, newtag %s",tag.c_str(),newTag.c_str());
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/menu/BatchBackupState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ ApplicationState::eSubState BatchBackupState::update(Input *input) {
case 0:
backupAllSave(this->wiiutitles, this->wiiuTitlesCount, batchDatetime);
backupAllSave(this->wiititles, this->vWiiTitlesCount, batchDatetime);
writeBackupAllMetadata(batchDatetime,"WiiU and vWii titles");
break;
case 1:
backupAllSave(this->wiiutitles, this->wiiuTitlesCount, batchDatetime);
writeBackupAllMetadata(batchDatetime,"WiiU titles");
break;
case 2:
backupAllSave(this->wiititles, this->vWiiTitlesCount, batchDatetime);
writeBackupAllMetadata(batchDatetime,"vWii titles");
break;
default:
return SUBSTATE_RETURN;
Expand Down
4 changes: 3 additions & 1 deletion src/menu/BatchRestoreOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ BatchRestoreOptions::BatchRestoreOptions(Title *titles,
WHBLogPrintf("restore type %s",isWiiUBatchRestore ? "wiiU" : "vWii");
minCursorPos = isWiiUBatchRestore ? 0 : 3;
cursorPos = minCursorPos;
WHBLogPrintf("cursorPos %d minCursospos %d",cursorPos,minCursorPos);
//WHBLogPrintf("cursorPos %d minCursospos %d",cursorPos,minCursorPos);
for (int i = 0; i<this->titlesCount; i++) {
this->titles[i].currentBackup= {
.hasBatchBackup = false,
Expand Down Expand Up @@ -127,10 +127,12 @@ ApplicationState::eSubState BatchRestoreOptions::update(Input *input) {
if (this->state == STATE_BATCH_RESTORE_OPTIONS_MENU) {
if (input->get(TRIGGER, PAD_BUTTON_A)) {
this->state = STATE_DO_SUBSTATE;
/*
WHBLogPrintf("to title select");
WHBLogPrintf("sduser %d",sduser);
WHBLogPrintf("wiiuuser %d",wiiuuser);
WHBLogPrintf("titles %u",titles);
*/
this->subState = std::make_unique<BRTitleSelectState>(sduser, wiiuuser, common, wipeBeforeRestore, fullBackup, this->titles, this->titlesCount, isWiiUBatchRestore);
}
if (input->get(TRIGGER, PAD_BUTTON_B))
Expand Down
Loading

0 comments on commit d9ef89e

Please sign in to comment.