From 9ca4c6ff52d4f6b2020dc9f33d2afbd8321b04fd Mon Sep 17 00:00:00 2001 From: J-D-K Date: Tue, 12 Oct 2021 23:14:04 -0400 Subject: [PATCH] Move stuff, fix stuff. --- inc/fs.h | 8 ++++ inc/fs/file.h | 13 ------ src/fs.cpp | 105 +++++++++++++++++++++++++++++++++++++++++++++++ src/fs/file.cpp | 50 +--------------------- src/ui/fm.cpp | 5 ++- src/ui/uistr.cpp | 2 +- src/ui/usr.cpp | 8 ++-- 7 files changed, 124 insertions(+), 67 deletions(-) diff --git a/inc/fs.h b/inc/fs.h index d757e98..fe1147b 100644 --- a/inc/fs.h +++ b/inc/fs.h @@ -24,6 +24,11 @@ namespace fs std::string getWorkDir(); void setWorkDir(const std::string& _w); + //Loads paths to filter from backup/deletion + void loadPathFilters(const uint64_t& tid); + bool pathIsFiltered(const std::string& _path); + void freePathFilters(); + void createSaveData(FsSaveDataType _type, uint64_t _tid, AccountUid _uid, threadInfo *t); void createSaveDataThreaded(FsSaveDataType _type, uint64_t _tid, AccountUid _uid); bool extendSaveData(const data::userTitleInfo *tinfo, uint64_t extSize, threadInfo *t); @@ -39,6 +44,9 @@ namespace fs void restoreBackup(void *a); void deleteBackup(void *a); + void dumpAllUserSaves(void *a); + void dumpAllUsersAllSaves(void *a); + void logOpen(); void logWrite(const char *fmt, ...); } diff --git a/inc/fs/file.h b/inc/fs/file.h index 26acce1..49b064e 100644 --- a/inc/fs/file.h +++ b/inc/fs/file.h @@ -24,13 +24,6 @@ namespace fs //deletes file void delfile(const std::string& _p); - //Loads paths to filter from backup/deletion - void loadPathFilters(const uint64_t& tid); - bool pathIsFiltered(const std::string& _path); - void freePathFilters(); - - void wipeSave(); - //Dumps all titles for current user void dumpAllUserSaves(); @@ -66,12 +59,6 @@ namespace fs bool opened = false; }; - //Take a pointer to backupArgs^ - void createNewBackup(void *a); - void overwriteBackup(void *a); - void restoreBackup(void *a); - void deleteBackup(void *a); - void logOpen(); void logWrite(const char *fmt, ...); void logClose(); diff --git a/src/fs.cpp b/src/fs.cpp index 4da11e7..63a6d35 100644 --- a/src/fs.cpp +++ b/src/fs.cpp @@ -11,6 +11,8 @@ static FSFILE *debLog; static FsFileSystem sv; +static std::vector pathFilter; + void fs::init() { mkDirRec("sdmc:/config/JKSV/"); @@ -105,6 +107,38 @@ std::string fs::getWorkDir() { return wd; } void fs::setWorkDir(const std::string& _w) { wd = _w; } + +void fs::loadPathFilters(const uint64_t& tid) +{ + char path[256]; + sprintf(path, "sdmc:/config/JKSV/0x%016lX_filter.txt", tid); + if(fs::fileExists(path)) + { + fs::dataFile filter(path); + while(filter.readNextLine(false)) + pathFilter.push_back(filter.getLine()); + } +} + +bool fs::pathIsFiltered(const std::string& _path) +{ + if(pathFilter.empty()) + return false; + + for(std::string& _p : pathFilter) + { + if(_path == _p) + return true; + } + + return false; +} + +void fs::freePathFilters() +{ + pathFilter.clear(); +} + void fs::createSaveData(FsSaveDataType _type, uint64_t _tid, AccountUid _uid, threadInfo *t) { data::titleInfo *tinfo = data::getTitleInfoByTID(_tid); @@ -543,6 +577,77 @@ void fs::deleteBackup(void *a) t->finished = true; } +void fs::dumpAllUserSaves(void *a) +{ + threadInfo *t = (threadInfo *)a; + fs::copyArgs *c = fs::copyArgsCreate("", "", "", NULL, NULL, false, false, 0); + t->argPtr = c; + data::user *u = data::getCurrentUser(); + + for(unsigned i = 0; i < u->titleInfo.size(); i++) + { + bool saveMounted = fs::mountSave(u->titleInfo[i].saveInfo); + util::createTitleDirectoryByTID(u->titleInfo[i].tid); + if(saveMounted && fs::dirNotEmpty("sv:/") && cfg::config["zip"]) + { + fs::loadPathFilters(u->titleInfo[i].tid); + std::string dst = util::generatePathByTID(u->titleInfo[i].tid) + u->getUsernameSafe() + " - " + util::getDateTime(util::DATE_FMT_YMD) + ".zip"; + zipFile zip = zipOpen64(dst.c_str(), 0); + fs::copyDirToZip("sv:/", zip, false, 0, t); + zipClose(zip, NULL); + fs::freePathFilters(); + } + else if(saveMounted && fs::dirNotEmpty("sv:/")) + { + fs::loadPathFilters(u->titleInfo[i].tid); + std::string dst = util::generatePathByTID(u->titleInfo[i].tid) + u->getUsernameSafe() + " - " + util::getDateTime(util::DATE_FMT_YMD) + "/"; + fs::mkDir(dst.substr(0, dst.length() - 1)); + fs::copyDirToDir("sv:/", dst, t); + fs::freePathFilters(); + } + fs::unmountSave(); + } + delete c; + t->finished = true; +} + +void fs::dumpAllUsersAllSaves(void *a) +{ + threadInfo *t = (threadInfo *)a; + fs::copyArgs *c = fs::copyArgsCreate("", "", "", NULL, NULL, false, false, 0); + t->argPtr = c; + unsigned curUser = 0; + while(data::users[curUser].getUID128() != 2) + { + data::user *u = &data::users[curUser++]; + for(unsigned i = 0; i < u->titleInfo.size(); i++) + { + bool saveMounted = fs::mountSave(u->titleInfo[i].saveInfo); + util::createTitleDirectoryByTID(u->titleInfo[i].tid); + if(saveMounted && fs::dirNotEmpty("sv:/") && cfg::config["zip"]) + { + fs::loadPathFilters(u->titleInfo[i].tid); + std::string dst = util::generatePathByTID(u->titleInfo[i].tid) + u->getUsernameSafe() + " - " + util::getDateTime(util::DATE_FMT_YMD) + ".zip"; + zipFile zip = zipOpen64(dst.c_str(), 0); + fs::copyDirToZip("sv:/", zip, false, 0, t); + zipClose(zip, NULL); + fs::freePathFilters(); + } + else if(saveMounted && fs::dirNotEmpty("sv:/")) + { + fs::loadPathFilters(u->titleInfo[i].tid); + std::string dst = util::generatePathByTID(u->titleInfo[i].tid) + u->getUsernameSafe() + " - " + util::getDateTime(util::DATE_FMT_YMD) + "/"; + fs::mkDir(dst.substr(0, dst.length() - 1)); + fs::copyDirToDir("sv:/", dst, t); + fs::freePathFilters(); + } + fs::unmountSave(); + } + } + delete c; + t->finished = true; +} + void fs::logOpen() { std::string logPath = wd + "log.txt"; diff --git a/src/fs/file.cpp b/src/fs/file.cpp index 50887c6..b6f9dc5 100644 --- a/src/fs/file.cpp +++ b/src/fs/file.cpp @@ -16,8 +16,6 @@ static std::string wd = "sdmc:/JKSV/"; -static std::vector pathFilter; - fs::copyArgs *fs::copyArgsCreate(const std::string& src, const std::string& dst, const std::string& dev, zipFile z, unzFile unz, bool _cleanup, bool _trimZipPath, uint8_t _trimPlaces) { copyArgs *ret = new copyArgs; @@ -313,7 +311,7 @@ void fs::copyFileCommitThreaded(const std::string& src, const std::string& dst, void fs::fileDrawFunc(void *a) { threadInfo *t = (threadInfo *)a; - if(!t->finished) + if(!t->finished && t->argPtr) { copyArgs *c = (copyArgs *)t->argPtr; std::string tmp; @@ -333,58 +331,12 @@ void fs::delfile(const std::string& path) remove(path.c_str()); } -void fs::loadPathFilters(const uint64_t& tid) -{ - char path[256]; - sprintf(path, "sdmc:/config/JKSV/0x%016lX_filter.txt", tid); - if(fs::fileExists(path)) - { - fs::dataFile filter(path); - while(filter.readNextLine(false)) - pathFilter.push_back(filter.getLine()); - } -} - -bool fs::pathIsFiltered(const std::string& _path) -{ - if(pathFilter.empty()) - return false; - - for(std::string& _p : pathFilter) - { - if(_path == _p) - return true; - } - - return false; -} - -void fs::freePathFilters() -{ - pathFilter.clear(); -} - -void fs::dumpAllUserSaves() -{ - //This is only really used for the progress bar - /*fs::copyArgs *send = fs::copyArgsCreate("", "", "", NULL, NULL, true, false, 0); - ui::newThread(fs::backupUserSaves_t, send, _fileDrawFunc);*/ -} - void fs::getShowFileProps(const std::string& _path) { size_t size = fs::fsize(_path); ui::showMessage(ui::getUICString("fileModeFileProperties", 0), _path.c_str(), util::getSizeString(size).c_str()); } -void fs::getShowDirProps(const std::string& _path) -{ - fs::dirCountArgs *send = new fs::dirCountArgs; - send->path = _path; - send->origin = true; -// ui::newThread(fs::getShowDirProps_t, send, NULL); -} - bool fs::fileExists(const std::string& path) { bool ret = false; diff --git a/src/ui/fm.cpp b/src/ui/fm.cpp index e0a4d4b..357487e 100644 --- a/src/ui/fm.cpp +++ b/src/ui/fm.cpp @@ -392,7 +392,10 @@ static void _copyMenuGetProps(void *a) int sel = m->getSelected(); if(sel == 0) - fs::getShowDirProps(*ma->path); + { + std::string *folderPath = new std::string(*ma->path); + ui::newThread(_copyMenuGetShowDirProps_t, folderPath, NULL); + } else if(sel > 1 && d->isDir(sel - 2)) { std::string *folderPath = new std::string; diff --git a/src/ui/uistr.cpp b/src/ui/uistr.cpp index 22b1c7c..660f217 100644 --- a/src/ui/uistr.cpp +++ b/src/ui/uistr.cpp @@ -106,7 +106,7 @@ static std::string getFilename(int lang) void ui::initStrings() { addUIString("author", 0, "NULL"); - addUIString("helpUser", 0, "[A] Select [X] User Options"); + addUIString("helpUser", 0, "[A] Select [Y] Dump All Saves [X] User Options"); addUIString("helpTitle", 0, "[A] Select [L][R] Jump [Y] Favorite [X] Title Options [B] Back"); addUIString("helpFolder", 0, "[A] Select [Y] Restore [X] Delete [B] Close"); addUIString("helpSettings", 0, "[A] Toggle [X] Defaults [B] Back"); diff --git a/src/ui/usr.cpp b/src/ui/usr.cpp index eed17c7..cdd923b 100644 --- a/src/ui/usr.cpp +++ b/src/ui/usr.cpp @@ -218,9 +218,7 @@ static void cacheSavePanelDraw(void *a) static void usrOptDumpAllUserSaves(void *a) { - data::user *u = data::getCurrentUser(); - if(u->titleInfo.size() > 0) - fs::dumpAllUserSaves(); + ui::newThread(fs::dumpAllUserSaves, NULL, fs::fileDrawFunc); } static void createSaveData(void *a) @@ -462,6 +460,10 @@ void ui::usrUpdate() { switch(ui::padKeysDown()) { + case HidNpadButton_Y: + ui::newThread(fs::dumpAllUsersAllSaves, NULL, fs::fileDrawFunc); + break; + case HidNpadButton_X: { int cachePos = usrMenu->getOptPos(ui::getUIString("saveTypeMainMenu", 2));