mirror of
https://github.com/J-D-K/JKSV.git
synced 2026-04-26 10:15:22 -05:00
Move stuff, fix stuff.
This commit is contained in:
parent
bf15660c2d
commit
9ca4c6ff52
8
inc/fs.h
8
inc/fs.h
|
|
@ -24,6 +24,11 @@ namespace fs
|
||||||
std::string getWorkDir();
|
std::string getWorkDir();
|
||||||
void setWorkDir(const std::string& _w);
|
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 createSaveData(FsSaveDataType _type, uint64_t _tid, AccountUid _uid, threadInfo *t);
|
||||||
void createSaveDataThreaded(FsSaveDataType _type, uint64_t _tid, AccountUid _uid);
|
void createSaveDataThreaded(FsSaveDataType _type, uint64_t _tid, AccountUid _uid);
|
||||||
bool extendSaveData(const data::userTitleInfo *tinfo, uint64_t extSize, threadInfo *t);
|
bool extendSaveData(const data::userTitleInfo *tinfo, uint64_t extSize, threadInfo *t);
|
||||||
|
|
@ -39,6 +44,9 @@ namespace fs
|
||||||
void restoreBackup(void *a);
|
void restoreBackup(void *a);
|
||||||
void deleteBackup(void *a);
|
void deleteBackup(void *a);
|
||||||
|
|
||||||
|
void dumpAllUserSaves(void *a);
|
||||||
|
void dumpAllUsersAllSaves(void *a);
|
||||||
|
|
||||||
void logOpen();
|
void logOpen();
|
||||||
void logWrite(const char *fmt, ...);
|
void logWrite(const char *fmt, ...);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,13 +24,6 @@ namespace fs
|
||||||
//deletes file
|
//deletes file
|
||||||
void delfile(const std::string& _p);
|
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
|
//Dumps all titles for current user
|
||||||
void dumpAllUserSaves();
|
void dumpAllUserSaves();
|
||||||
|
|
||||||
|
|
@ -66,12 +59,6 @@ namespace fs
|
||||||
bool opened = false;
|
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 logOpen();
|
||||||
void logWrite(const char *fmt, ...);
|
void logWrite(const char *fmt, ...);
|
||||||
void logClose();
|
void logClose();
|
||||||
|
|
|
||||||
105
src/fs.cpp
105
src/fs.cpp
|
|
@ -11,6 +11,8 @@ static FSFILE *debLog;
|
||||||
|
|
||||||
static FsFileSystem sv;
|
static FsFileSystem sv;
|
||||||
|
|
||||||
|
static std::vector<std::string> pathFilter;
|
||||||
|
|
||||||
void fs::init()
|
void fs::init()
|
||||||
{
|
{
|
||||||
mkDirRec("sdmc:/config/JKSV/");
|
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::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)
|
void fs::createSaveData(FsSaveDataType _type, uint64_t _tid, AccountUid _uid, threadInfo *t)
|
||||||
{
|
{
|
||||||
data::titleInfo *tinfo = data::getTitleInfoByTID(_tid);
|
data::titleInfo *tinfo = data::getTitleInfoByTID(_tid);
|
||||||
|
|
@ -543,6 +577,77 @@ void fs::deleteBackup(void *a)
|
||||||
t->finished = true;
|
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()
|
void fs::logOpen()
|
||||||
{
|
{
|
||||||
std::string logPath = wd + "log.txt";
|
std::string logPath = wd + "log.txt";
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,6 @@
|
||||||
|
|
||||||
static std::string wd = "sdmc:/JKSV/";
|
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)
|
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;
|
copyArgs *ret = new copyArgs;
|
||||||
|
|
@ -313,7 +311,7 @@ void fs::copyFileCommitThreaded(const std::string& src, const std::string& dst,
|
||||||
void fs::fileDrawFunc(void *a)
|
void fs::fileDrawFunc(void *a)
|
||||||
{
|
{
|
||||||
threadInfo *t = (threadInfo *)a;
|
threadInfo *t = (threadInfo *)a;
|
||||||
if(!t->finished)
|
if(!t->finished && t->argPtr)
|
||||||
{
|
{
|
||||||
copyArgs *c = (copyArgs *)t->argPtr;
|
copyArgs *c = (copyArgs *)t->argPtr;
|
||||||
std::string tmp;
|
std::string tmp;
|
||||||
|
|
@ -333,58 +331,12 @@ void fs::delfile(const std::string& path)
|
||||||
remove(path.c_str());
|
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)
|
void fs::getShowFileProps(const std::string& _path)
|
||||||
{
|
{
|
||||||
size_t size = fs::fsize(_path);
|
size_t size = fs::fsize(_path);
|
||||||
ui::showMessage(ui::getUICString("fileModeFileProperties", 0), _path.c_str(), util::getSizeString(size).c_str());
|
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 fs::fileExists(const std::string& path)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
|
||||||
|
|
@ -392,7 +392,10 @@ static void _copyMenuGetProps(void *a)
|
||||||
|
|
||||||
int sel = m->getSelected();
|
int sel = m->getSelected();
|
||||||
if(sel == 0)
|
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))
|
else if(sel > 1 && d->isDir(sel - 2))
|
||||||
{
|
{
|
||||||
std::string *folderPath = new std::string;
|
std::string *folderPath = new std::string;
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ static std::string getFilename(int lang)
|
||||||
void ui::initStrings()
|
void ui::initStrings()
|
||||||
{
|
{
|
||||||
addUIString("author", 0, "NULL");
|
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("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("helpFolder", 0, "[A] Select [Y] Restore [X] Delete [B] Close");
|
||||||
addUIString("helpSettings", 0, "[A] Toggle [X] Defaults [B] Back");
|
addUIString("helpSettings", 0, "[A] Toggle [X] Defaults [B] Back");
|
||||||
|
|
|
||||||
|
|
@ -218,9 +218,7 @@ static void cacheSavePanelDraw(void *a)
|
||||||
|
|
||||||
static void usrOptDumpAllUserSaves(void *a)
|
static void usrOptDumpAllUserSaves(void *a)
|
||||||
{
|
{
|
||||||
data::user *u = data::getCurrentUser();
|
ui::newThread(fs::dumpAllUserSaves, NULL, fs::fileDrawFunc);
|
||||||
if(u->titleInfo.size() > 0)
|
|
||||||
fs::dumpAllUserSaves();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void createSaveData(void *a)
|
static void createSaveData(void *a)
|
||||||
|
|
@ -462,6 +460,10 @@ void ui::usrUpdate()
|
||||||
{
|
{
|
||||||
switch(ui::padKeysDown())
|
switch(ui::padKeysDown())
|
||||||
{
|
{
|
||||||
|
case HidNpadButton_Y:
|
||||||
|
ui::newThread(fs::dumpAllUsersAllSaves, NULL, fs::fileDrawFunc);
|
||||||
|
break;
|
||||||
|
|
||||||
case HidNpadButton_X:
|
case HidNpadButton_X:
|
||||||
{
|
{
|
||||||
int cachePos = usrMenu->getOptPos(ui::getUIString("saveTypeMainMenu", 2));
|
int cachePos = usrMenu->getOptPos(ui::getUIString("saveTypeMainMenu", 2));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user