Add path filtering(Not tested thoroughly)

This commit is contained in:
J-D-K 2020-11-01 16:31:16 -05:00
parent 11a382794b
commit abfa13fbc1
6 changed files with 62 additions and 3 deletions

View File

@ -38,7 +38,7 @@ INCLUDES := inc
EXEFS_SRC := exefs_src
APP_TITLE := JKSV
APP_AUTHOR := JK
APP_VERSION := 08.27.2020
APP_VERSION := 11.01.2020
ROMFS := romfs
ICON := romfs/icon.jpg

View File

@ -12,8 +12,8 @@
#define curUser users[data::selUser]
#define curData users[data::selUser].titles[data::selData]
#define BLD_MON 8
#define BLD_DAY 27
#define BLD_MON 11
#define BLD_DAY 01
#define BLD_YEAR 2020
namespace data

View File

@ -47,6 +47,11 @@ namespace fs
//Recursively deletes 'path'
void delDir(const std::string& path);
//Loads paths to filter from backup/deletion
void loadPathFilters(const std::string& _file);
bool pathIsFiltered(const std::string& _path);
void freePathFilters();
inline void wipeSave()
{
fs::delDir("sv:/");
@ -74,6 +79,7 @@ namespace fs
public:
dirItem(const std::string& pathTo, const std::string& sItem);
std::string getItm() const { return itm; }
std::string getName() const;
std::string getExt() const;
bool isDir() const { return dir; }

View File

@ -1,6 +1,7 @@
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <switch.h>
#include <dirent.h>
#include <unistd.h>
@ -30,6 +31,8 @@ typedef struct
static std::string wd;
static std::vector<std::string> pathFilter;
static FSFILE *log;
static FsFileSystem sv;
@ -139,6 +142,15 @@ fs::dirItem::dirItem(const std::string& pathTo, const std::string& sItem)
dir = true;
}
std::string fs::dirItem::getName() const
{
size_t extPos = itm.find_last_of('.'), slPos = itm.find_last_of('/');
if(extPos == itm.npos)
return "";
return itm.substr(slPos + 1, extPos);
}
std::string fs::dirItem::getExt() const
{
size_t extPos = itm.find_last_of('.');
@ -330,6 +342,9 @@ void fs::copyDirToDir(const std::string& from, const std::string& to)
for(unsigned i = 0; i < list.getCount(); i++)
{
if(pathIsFiltered(from + list.getItem(i)))
continue;
if(list.isDir(i))
{
std::string newFrom = from + list.getItem(i) + "/";
@ -376,6 +391,9 @@ void fs::copyDirToZip(const std::string& from, zipFile *to)
for(unsigned i = 0; i < list.getCount(); i++)
{
if(pathIsFiltered(from + list.getItem(i)))
continue;
if(list.isDir(i))
{
std::string newFrom = from + list.getItem(i) + "/";
@ -527,6 +545,9 @@ void fs::delDir(const std::string& path)
dirList list(path);
for(unsigned i = 0; i < list.getCount(); i++)
{
if(pathIsFiltered(path + list.getItem(i)))
continue;
if(list.isDir(i))
{
std::string newPath = path + list.getItem(i) + "/";
@ -544,6 +565,35 @@ void fs::delDir(const std::string& path)
rmdir(path.c_str());
}
void fs::loadPathFilters(const std::string& _file)
{
if(fs::fileExists(_file))
{
fs::dataFile filter(_file);
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();
}
bool fs::dumpAllUserSaves(const data::user& u)
{
for(unsigned i = 0; i < u.titles.size(); i++)

View File

@ -17,6 +17,7 @@ void ui::folderMenuPrepare(data::user& usr, data::titledata& dat)
dat.createDir();
fldList.reassign(dat.getPath());
fs::loadPathFilters(dat.getPath() + "pathFilters.txt");
folderMenu.addOpt("New");
for(unsigned i = 0; i < fldList.getCount(); i++)
folderMenu.addOpt(fldList.getItem(i));
@ -195,6 +196,7 @@ void ui::updateFolderMenu(const uint64_t& down, const uint64_t& held)
case KEY_B:
fs::unmountSave();
fs::freePathFilters();
ui::changeState(TTL_SEL);
break;

View File

@ -169,6 +169,7 @@ void ui::textFolderMenuUpdate(const uint64_t& down, const uint64_t& held)
case KEY_B:
fs::unmountSave();
fs::freePathFilters();
ui::changeState(TXT_TTL);
break;