From b06041fdfba8e10278059c240418a4408645eb44 Mon Sep 17 00:00:00 2001 From: geek85 Date: Wed, 23 May 2018 10:29:26 +0200 Subject: [PATCH 1/4] Add a delete command (ZL) not tested! code review is mandatory! It should delete in dev the files that are in sd:/inject/ (by name) --- source/main.cpp | 50 +++++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/source/main.cpp b/source/main.cpp index 205dc3a..3ce4b78 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -75,24 +75,27 @@ int isDirectory(const char *path) { return S_ISDIR(statbuf.st_mode); } -int cpFile(const char * filenameI, const char * filenameO) { +int cpFile(const char * filenameI, const char * filenameO, bool isDelete) { remove( filenameO ); - - std::ifstream src(filenameI, std::ios::binary); - std::ofstream dst(filenameO, std::ios::binary); - - dst << src.rdbuf(); - + if(!isDelete) { + std::ifstream src(filenameI, std::ios::binary); + std::ofstream dst(filenameO, std::ios::binary); + dst << src.rdbuf(); + } return 0; } -int copyAllSave(const char * dev, const char * path, bool isInject, +int copyAllSave(const char * dev, const char * path, char action, const char * exportDir) { DIR* dir; struct dirent* ent; char dirPath[0x100]; - if(isInject) { + bool isDelete=False; + if(action=="Delete"){ + isDelete=True; + } + if(action=="Inject") { strcpy(dirPath, INJECT_DIR); strcat(dirPath, path); } else { @@ -119,7 +122,7 @@ int copyAllSave(const char * dev, const char * path, bool isInject, char filenameI[0x100]; char filenameO[0x100]; - if(isInject) { + if(action!=NULL) { strcpy(filenameI, INJECT_DIR); strcat(filenameI, filename); @@ -139,13 +142,13 @@ int copyAllSave(const char * dev, const char * path, bool isInject, if(isDirectory(filenameI)) { mkdir(filenameO, 0700); - int res = copyAllSave(dev, filename, isInject, exportDir); + int res = copyAllSave(dev, filename, action, exportDir); if(res != 0) return res; } else { - printf("Copying %s... ", filenameI); - cpFile(filenameI, filenameO); - if(isInject) { + printf("Processing %s... ", filenameI); + cpFile(filenameI, filenameO, isDelete); + if(action!=NULL) { if (R_SUCCEEDED(fsdevCommitDevice(SAVE_DEV))) { // Thx yellows8 printf("committed.\n"); } else { @@ -164,11 +167,11 @@ int copyAllSave(const char * dev, const char * path, bool isInject, } int dumpAll() { - return copyAllSave("save:/", ".", false, NULL); + return copyAllSave("save:/", ".", NULL, NULL); } int dumpAllTo(char * dir) { - return copyAllSave("save:/", ".", false, dir); + return copyAllSave("save:/", ".", NULL, dir); } void dumpToTitleUserDir(FsSaveDataInfo info) { @@ -182,7 +185,11 @@ void dumpToTitleUserDir(FsSaveDataInfo info) { } int inject() { - return copyAllSave("save:/", ".", true, NULL); + return copyAllSave("save:/", ".", "Inject", NULL); +} + +int delete() { + return copyAllSave("save:/", ".", "Delete", NULL); } Result getTitleName(u64 titleID, char * name) { @@ -419,7 +426,14 @@ int main(int argc, char **argv) printf("Dump over.\n\n"); } } - + if (kDown & KEY_KEY_ZL) { + if (userConfirm("Erase saves? Sure?")) { + mountSaveBySaveDataInfo(info, SAVE_DEV); + if( delete() == 0 ) { + printf("Delete over.\n\n"); + } + fsdevUnmountDevice(SAVE_DEV); + } if (kDown & KEY_X) { if (userConfirm("Inject data from 'inject/'?")) { mountSaveBySaveDataInfo(info, SAVE_DEV); From 9aba27af6134efd807a365bc0c90a824d2dda6a2 Mon Sep 17 00:00:00 2001 From: geek85 Date: Wed, 23 May 2018 11:22:38 +0200 Subject: [PATCH 2/4] correct typos (not familiar with c++) --- source/main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/main.cpp b/source/main.cpp index 3ce4b78..bc7097e 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -91,9 +91,9 @@ int copyAllSave(const char * dev, const char * path, char action, DIR* dir; struct dirent* ent; char dirPath[0x100]; - bool isDelete=False; + bool isDelete=false; if(action=="Delete"){ - isDelete=True; + isDelete=true; } if(action=="Inject") { strcpy(dirPath, INJECT_DIR); @@ -188,7 +188,7 @@ int inject() { return copyAllSave("save:/", ".", "Inject", NULL); } -int delete() { +int del() { return copyAllSave("save:/", ".", "Delete", NULL); } @@ -426,10 +426,10 @@ int main(int argc, char **argv) printf("Dump over.\n\n"); } } - if (kDown & KEY_KEY_ZL) { + if (kDown & KEY_ZL) { if (userConfirm("Erase saves? Sure?")) { mountSaveBySaveDataInfo(info, SAVE_DEV); - if( delete() == 0 ) { + if( del() == 0 ) { printf("Delete over.\n\n"); } fsdevUnmountDevice(SAVE_DEV); From 0f8ba619fb23c116e16e79cf43f1ec84c435b832 Mon Sep 17 00:00:00 2001 From: minikea Date: Wed, 23 May 2018 12:10:24 +0200 Subject: [PATCH 3/4] managed to make a successful build --- source/main.cpp | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/source/main.cpp b/source/main.cpp index bc7097e..8d3a3fe 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -10,6 +10,8 @@ const char * EXPORT_DIR = "save/"; const char * INJECT_DIR = "inject/"; const char * SAVE_DEV = "save"; +const char * DELETE = "Delete"; +const char * INJECT = "Inject"; Result getSaveList(std::vector & saveInfoList) { Result rc=0; @@ -29,7 +31,7 @@ Result getSaveList(std::vector & saveInfoList) { if (total_entries==0) return MAKERESULT(Module_Libnx, LibnxError_NotFound); - for(; R_SUCCEEDED(rc) && total_entries > 0; + for(; R_SUCCEEDED(rc) && total_entries > 0; rc = fsSaveDataIteratorRead(&iterator, &info, 1, &total_entries)) { if (info.SaveDataType == FsSaveDataType_SaveData) { saveInfoList.push_back(info); @@ -47,7 +49,7 @@ Result mountSaveBySaveDataInfo(const FsSaveDataInfo & info, const char * dev) { u64 titleID = info.titleID; u128 userID = info.userID; - + FsFileSystem tmpfs; printf("\n\nUsing titleID=0x%016lx userID: 0x%lx 0x%lx\n", titleID, (u64)(userID>>64), (u64)userID); @@ -86,19 +88,18 @@ int cpFile(const char * filenameI, const char * filenameO, bool isDelete) { } -int copyAllSave(const char * dev, const char * path, char action, - const char * exportDir) { +int copyAllSave(const char * dev, const char * path, const char * action, const char * exportDir) { DIR* dir; struct dirent* ent; char dirPath[0x100]; - bool isDelete=false; - if(action=="Delete"){ + bool isDelete = false; + if(action == DELETE){ isDelete=true; } - if(action=="Inject") { + if(action == INJECT) { strcpy(dirPath, INJECT_DIR); strcat(dirPath, path); - } else { + } else { strcpy(dirPath, dev); strcat(dirPath, path); } @@ -185,11 +186,11 @@ void dumpToTitleUserDir(FsSaveDataInfo info) { } int inject() { - return copyAllSave("save:/", ".", "Inject", NULL); + return copyAllSave("save:/", ".", INJECT, NULL); } int del() { - return copyAllSave("save:/", ".", "Delete", NULL); + return copyAllSave("save:/", ".", DELETE, NULL); } Result getTitleName(u64 titleID, char * name) { @@ -265,7 +266,6 @@ Result getUserNameById(u128 userID, char * username) { if (R_FAILED(rc)) { printf("accountGetProfile() failed: 0x%x\n", rc); } - if (R_SUCCEEDED(rc)) { rc = accountProfileGet(&profile, &userdata, &profilebase);//userdata is otional, see libnx acc.h. @@ -293,8 +293,7 @@ int selectSaveFromList(int & selection, int change, if (selection < 0) { selection = abs(selection) % saveInfoList.size(); selection = saveInfoList.size() - selection; - } else if (selection > 0 - && static_cast(selection) >= saveInfoList.size()) { + } else if (selection > 0 && static_cast(selection) >= saveInfoList.size()) { selection %= saveInfoList.size(); } @@ -320,7 +319,7 @@ int selectSaveFromList(int & selection, int change, bool userConfirm(const char * msg) { printf("\n%s\nPress A to confirm, any other button to cancel\n", msg); - u64 kDownPrevious = hidKeysDown(CONTROLLER_P1_AUTO); + u64 kDownPrevious = hidKeysDown(CONTROLLER_P1_AUTO); while(appletMainLoop()) { hidScanInput(); @@ -351,7 +350,7 @@ int main(int argc, char **argv) std::vector saveInfoList; mkdir(EXPORT_DIR, 0700); - mkdir(INJECT_DIR, 0700); + mkdir(INJECT_DIR, 0700); if (R_FAILED(getSaveList(saveInfoList))) { printf("Failed to get save list 0x%x\n", rc); @@ -400,7 +399,7 @@ int main(int argc, char **argv) printName = !printName; selectSaveFromList(selection, 0, saveInfoList, info, printName); } - + if (kDown & KEY_A) { mountSaveBySaveDataInfo(info, SAVE_DEV); dumpAll(); @@ -426,20 +425,22 @@ int main(int argc, char **argv) printf("Dump over.\n\n"); } } + if (kDown & KEY_ZL) { if (userConfirm("Erase saves? Sure?")) { mountSaveBySaveDataInfo(info, SAVE_DEV); if( del() == 0 ) { - printf("Delete over.\n\n"); + printf("Delete over.\n\n"); } fsdevUnmountDevice(SAVE_DEV); + } } + if (kDown & KEY_X) { if (userConfirm("Inject data from 'inject/'?")) { mountSaveBySaveDataInfo(info, SAVE_DEV); if( inject() == 0 ) { printf("Inject over.\n\n"); - } fsdevUnmountDevice(SAVE_DEV); } From ab13d483bdade9ee688e36124613730651f058c0 Mon Sep 17 00:00:00 2001 From: geek85 Date: Wed, 23 May 2018 12:51:51 +0200 Subject: [PATCH 4/4] add credits and change version --- source/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/main.cpp b/source/main.cpp index 8d3a3fe..9086cea 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -356,7 +356,7 @@ int main(int argc, char **argv) printf("Failed to get save list 0x%x\n", rc); } - printf("Y'allAreNUTs v0.1.1\n" + printf("Y'allAreNUTs v0.2 by 3096 and geek85\n" "Press UP and DOWN to select a save\n" "Press LEFT and RIGHT to skip 5 saves\n" "Press A to dump save to 'save/'\n"