Move stuff, fix stuff.

This commit is contained in:
J-D-K 2021-10-12 23:14:04 -04:00
parent bf15660c2d
commit 9ca4c6ff52
7 changed files with 124 additions and 67 deletions

View File

@ -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, ...);
}

View File

@ -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();

View File

@ -11,6 +11,8 @@ static FSFILE *debLog;
static FsFileSystem sv;
static std::vector<std::string> 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";

View File

@ -16,8 +16,6 @@
static std::string wd = "sdmc:/JKSV/";
static std::vector<std::string> 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;

View File

@ -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;

View File

@ -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");

View File

@ -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));