Merge installing and deleting CIAs into one selector, preventing the file selector from being reset on mode change.

This commit is contained in:
Steven Smith 2015-04-12 11:07:03 -07:00
parent f115bcbedc
commit bedc96c647

View File

@ -78,11 +78,11 @@ int main(int argc, char **argv) {
mode = DELETE_CIA; mode = DELETE_CIA;
} else if(mode == DELETE_CIA) { } else if(mode == DELETE_CIA) {
mode = DELETE_TITLE; mode = DELETE_TITLE;
breakLoop = true;
} else { } else {
mode = INSTALL_CIA; mode = INSTALL_CIA;
breakLoop = true;
} }
breakLoop = true;
} }
if(inputIsPressed(BUTTON_Y)) { if(inputIsPressed(BUTTON_Y)) {
@ -120,25 +120,44 @@ int main(int argc, char **argv) {
while(platformIsRunning()) { while(platformIsRunning()) {
std::string fileTarget; std::string fileTarget;
App appTarget; App appTarget;
if(mode == INSTALL_CIA) { if(mode == INSTALL_CIA || mode == DELETE_CIA) {
uiSelectFile(&fileTarget, "/", extensions, [&](const std::string currDirectory, bool inRoot, bool &updateList) { uiSelectFile(&fileTarget, "/", extensions, [&](const std::string currDirectory, bool inRoot, bool &updateList) {
if(inputIsPressed(BUTTON_X)) { if(inputIsPressed(BUTTON_X)) {
if(uiPrompt(TOP_SCREEN, "Install all CIAs in the current directory?", true)) { std::stringstream confirmMsg;
if(mode == INSTALL_CIA) {
confirmMsg << "Install ";
} else {
confirmMsg << "Delete ";
}
confirmMsg << "all CIAs in the current directory?";
if(uiPrompt(TOP_SCREEN, confirmMsg.str(), true)) {
bool failed = false; bool failed = false;
std::vector<FileInfo> contents = fsGetDirectoryContents(currDirectory); std::vector<FileInfo> contents = fsGetDirectoryContents(currDirectory);
for(std::vector<FileInfo>::iterator it = contents.begin(); it != contents.end(); it++) { for(std::vector<FileInfo>::iterator it = contents.begin(); it != contents.end(); it++) {
std::string path = (*it).path; std::string path = (*it).path;
std::string fileName = (*it).name; std::string fileName = (*it).name;
if(!fsIsDirectory(path) && fsHasExtensions(path, extensions)) { if(!fsIsDirectory(path) && fsHasExtensions(path, extensions)) {
AppResult ret = appInstallFile(destination, path, onProgress); if(mode == INSTALL_CIA) {
if(ret != APP_SUCCESS) { AppResult ret = appInstallFile(destination, path, onProgress);
std::stringstream resultMsg; if(ret != APP_SUCCESS) {
resultMsg << "Install failed!" << "\n"; std::stringstream resultMsg;
resultMsg << fileName << "\n"; resultMsg << "Install failed!" << "\n";
resultMsg << appGetResultString(ret) << "\n"; resultMsg << fileName << "\n";
uiPrompt(TOP_SCREEN, resultMsg.str(), false); resultMsg << appGetResultString(ret) << "\n";
failed = true; uiPrompt(TOP_SCREEN, resultMsg.str(), false);
break; failed = true;
break;
}
} else {
if(!fsDelete(path)) {
std::stringstream resultMsg;
resultMsg << "Delete failed!" << "\n";
resultMsg << fileName << "\n";
uiPrompt(TOP_SCREEN, resultMsg.str(), false);
failed = true;
break;
}
} }
} }
} }
@ -153,65 +172,36 @@ int main(int argc, char **argv) {
return onLoop(); return onLoop();
}, [&](const std::string path, bool &updateList) { }, [&](const std::string path, bool &updateList) {
if(uiPrompt(TOP_SCREEN, "Install the selected CIA?", true)) { std::stringstream confirmMsg;
AppResult ret = appInstallFile(destination, path, onProgress); if(mode == INSTALL_CIA) {
confirmMsg << "Install ";
std::stringstream resultMsg; } else {
resultMsg << "Install "; confirmMsg << "Delete ";
if(ret == APP_SUCCESS) {
resultMsg << "succeeded!";
} else {
resultMsg << "failed!" << "\n";
resultMsg << appGetResultString(ret) << "\n";
}
uiPrompt(TOP_SCREEN, resultMsg.str(), false);
freeSpace = fsGetFreeSpace(destination);
} }
return false; confirmMsg << "the selected CIA?";
}); if(uiPrompt(TOP_SCREEN, confirmMsg.str(), true)) {
} else if(mode == DELETE_CIA) {
uiSelectFile(&fileTarget, "/", extensions, [&](const std::string currDirectory, bool inRoot, bool &updateList) {
if(inputIsPressed(BUTTON_X)) {
if(uiPrompt(TOP_SCREEN, "Delete all CIAs in the current directory?", true)) {
updateList = true;
bool failed = false;
std::vector<FileInfo> contents = fsGetDirectoryContents(currDirectory);
for(std::vector<FileInfo>::iterator it = contents.begin(); it != contents.end(); it++) {
std::string path = (*it).path;
std::string fileName = (*it).name;
if(!fsIsDirectory(path) && fsHasExtensions(path, extensions)) {
if(!fsDelete(path)) {
std::stringstream resultMsg;
resultMsg << "Delete failed!" << "\n";
resultMsg << fileName << "\n";
uiPrompt(TOP_SCREEN, resultMsg.str(), false);
failed = true;
break;
}
}
}
if(!failed) {
uiPrompt(TOP_SCREEN, "Delete succeeded!\n", false);
}
freeSpace = fsGetFreeSpace(destination);
}
}
return onLoop();
}, [&](const std::string path, bool &updateList) {
if(uiPrompt(TOP_SCREEN, "Delete the selected CIA?", true)) {
updateList = true;
std::stringstream resultMsg; std::stringstream resultMsg;
resultMsg << "Delete "; if(mode == INSTALL_CIA) {
if(fsDelete(path)) { resultMsg << "Install ";
resultMsg << "succeeded!";
} else { } else {
resultMsg << "failed!" << "\n"; resultMsg << "Delete ";
}
if(mode == INSTALL_CIA) {
AppResult ret = appInstallFile(destination, path, onProgress);
if(ret == APP_SUCCESS) {
resultMsg << "succeeded!";
} else {
resultMsg << "failed!" << "\n";
resultMsg << appGetResultString(ret) << "\n";
}
} else {
if(fsDelete(path)) {
resultMsg << "succeeded!";
} else {
resultMsg << "failed!" << "\n";
}
} }
uiPrompt(TOP_SCREEN, resultMsg.str(), false); uiPrompt(TOP_SCREEN, resultMsg.str(), false);