From f115bcbedc1cf5fb5aa1f53227e4711fe1e88df4 Mon Sep 17 00:00:00 2001 From: Steven Smith Date: Sun, 12 Apr 2015 10:47:34 -0700 Subject: [PATCH] Allow deleting CIA files and installing/deleting all CIA files in a directory at once. --- source/main.cpp | 163 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 136 insertions(+), 27 deletions(-) diff --git a/source/main.cpp b/source/main.cpp index b70a931..b16bada 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -2,13 +2,17 @@ #include #include -#include -#include #include +#include +#include + +#include + typedef enum { - INSTALL, - DELETE + INSTALL_CIA, + DELETE_CIA, + DELETE_TITLE } Mode; int main(int argc, char **argv) { @@ -17,12 +21,34 @@ int main(int argc, char **argv) { } bool ninjhax = platformIsNinjhax(); + /* if(ninjhax) { + consoleInit(GFX_BOTTOM, NULL); + consoleClear(); + + AcquireResult result = platformAcquireServices(); + if(result != ACQUIRE_SUCCESS) { + //std::stringstream errorStream; + //errorStream << "Failed to acquire services." << "\n"; + //errorStream << platformGetAcquireResultString(result) << "\n"; + //uiPrompt(TOP_SCREEN, errorStream.str(), false); + + while(true) { + inputPoll(); + if(inputIsPressed(BUTTON_START)) { + break; + } + } + + platformCleanup(); + return 0; + } + } */ std::vector extensions; extensions.push_back("cia"); MediaType destination = SD; - Mode mode = INSTALL; + Mode mode = INSTALL_CIA; bool exit = false; bool netInstall = false; u64 freeSpace = fsGetFreeSpace(destination); @@ -42,16 +68,18 @@ int main(int argc, char **argv) { } freeSpace = fsGetFreeSpace(destination); - if(mode == DELETE) { + if(mode == DELETE_TITLE) { breakLoop = true; } } if(inputIsPressed(BUTTON_R)) { - if(mode == INSTALL) { - mode = DELETE; + if(mode == INSTALL_CIA) { + mode = DELETE_CIA; + } else if(mode == DELETE_CIA) { + mode = DELETE_TITLE; } else { - mode = INSTALL; + mode = INSTALL_CIA; } breakLoop = true; @@ -64,8 +92,14 @@ int main(int argc, char **argv) { std::stringstream stream; stream << "Free Space: " << freeSpace << " bytes (" << std::fixed << std::setprecision(2) << freeSpace / 1024.0f / 1024.0f << "MB)" << "\n"; - stream << "Destination: " << (destination == NAND ? "NAND" : "SD") << ", Mode: " << (mode == INSTALL ? "Install" : "Delete") << "\n"; + stream << "Destination: " << (destination == NAND ? "NAND" : "SD") << ", Mode: " << (mode == INSTALL_CIA ? "Install CIA" : mode == DELETE_CIA ? "Delete CIA" : "Delete Title") << "\n"; stream << "L - Switch Destination, R - Switch Mode" << "\n"; + if(mode == INSTALL_CIA) { + stream << "X - Install all CIAs in the current directory" << "\n"; + } else if(mode == DELETE_CIA) { + stream << "X - Delete all CIAs in the current directory" << "\n"; + } + stream << "Y - Receive an app over the network" << "\n"; if(ninjhax) { stream << "SELECT - Exit to launcher" << "\n"; @@ -84,16 +118,45 @@ int main(int argc, char **argv) { }; while(platformIsRunning()) { - std::string targetInstall; - App targetDelete; - if(mode == INSTALL) { - uiSelectFile(&targetInstall, "sdmc:", extensions, [&](bool inRoot) { - return onLoop(); - }, [&](std::string path, bool &updateList) { - if(uiPrompt(TOP_SCREEN, "Install the selected title?", true)) { - AppResult ret = appInstallFile(destination, path, onProgress); - std::stringstream resultMsg; + std::string fileTarget; + App appTarget; + if(mode == INSTALL_CIA) { + uiSelectFile(&fileTarget, "/", extensions, [&](const std::string currDirectory, bool inRoot, bool &updateList) { + if(inputIsPressed(BUTTON_X)) { + if(uiPrompt(TOP_SCREEN, "Install all CIAs in the current directory?", true)) { + bool failed = false; + std::vector contents = fsGetDirectoryContents(currDirectory); + for(std::vector::iterator it = contents.begin(); it != contents.end(); it++) { + std::string path = (*it).path; + std::string fileName = (*it).name; + if(!fsIsDirectory(path) && fsHasExtensions(path, extensions)) { + AppResult ret = appInstallFile(destination, path, onProgress); + if(ret != APP_SUCCESS) { + std::stringstream resultMsg; + resultMsg << "Install failed!" << "\n"; + resultMsg << fileName << "\n"; + resultMsg << appGetResultString(ret) << "\n"; + uiPrompt(TOP_SCREEN, resultMsg.str(), false); + failed = true; + break; + } + } + } + if(!failed) { + uiPrompt(TOP_SCREEN, "Install succeeded!\n", false); + } + + freeSpace = fsGetFreeSpace(destination); + } + } + + return onLoop(); + }, [&](const std::string path, bool &updateList) { + if(uiPrompt(TOP_SCREEN, "Install the selected CIA?", true)) { + AppResult ret = appInstallFile(destination, path, onProgress); + + std::stringstream resultMsg; resultMsg << "Install "; if(ret == APP_SUCCESS) { resultMsg << "succeeded!"; @@ -109,8 +172,59 @@ int main(int argc, char **argv) { return false; }); - } else if(mode == DELETE) { - uiSelectApp(&targetDelete, destination, onLoop, [&](App app, bool &updateList) { + } 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 contents = fsGetDirectoryContents(currDirectory); + for(std::vector::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; + resultMsg << "Delete "; + if(fsDelete(path)) { + resultMsg << "succeeded!"; + } else { + resultMsg << "failed!" << "\n"; + } + + uiPrompt(TOP_SCREEN, resultMsg.str(), false); + + freeSpace = fsGetFreeSpace(destination); + } + + return false; + }); + } else if(mode == DELETE_TITLE) { + uiSelectApp(&appTarget, destination, [&](bool &updateList) { + return onLoop(); + }, [&](App app, bool &updateList) { if(uiPrompt(TOP_SCREEN, "Delete the selected title?", true)) { updateList = true; uiDisplayMessage(TOP_SCREEN, "Deleting title..."); @@ -150,12 +264,7 @@ int main(int argc, char **argv) { if(uiPrompt(TOP_SCREEN, confirmStream.str(), true)) { AppResult ret = appInstall(destination, file.fd, file.fileSize, onProgress); std::stringstream resultMsg; - if(mode == INSTALL) { - resultMsg << "Install "; - } else if(mode == DELETE) { - resultMsg << "Delete "; - } - + resultMsg << "Install "; if(ret == APP_SUCCESS) { resultMsg << "succeeded!"; } else {