From 099a334c2febd2e265c79daa1dc8aa71722b7efc Mon Sep 17 00:00:00 2001 From: J-D-K Date: Wed, 8 Apr 2020 00:29:17 -0400 Subject: [PATCH] Clean some stuff up --- inc/data.h | 7 ++++++- inc/miscui.h | 3 ++- inc/util.h | 6 ------ src/data.cpp | 8 ++++++++ src/file.cpp | 4 ++-- src/ui.cpp | 2 +- src/ui/fldrsel.cpp | 26 +++++++++++--------------- src/ui/miscui.cpp | 5 ----- src/ui/ttlsel.cpp | 6 ------ src/ui/txtui.cpp | 28 ++++++++++------------------ src/util.cpp | 11 ----------- 11 files changed, 40 insertions(+), 66 deletions(-) diff --git a/inc/data.h b/inc/data.h index 815f263..e772316 100644 --- a/inc/data.h +++ b/inc/data.h @@ -64,6 +64,11 @@ namespace data std::string getTitleSafe() { return titleSafe; } std::string getAuthor() { return author; } + //Creates title folder + void createDir(); + //Returns folder path + std::string getPath() { return path; } + uint64_t getID() { return id; } FsSaveDataType getType() { return (FsSaveDataType)saveDataType; } void setType(FsSaveDataType type) { saveDataType = type; } @@ -75,7 +80,7 @@ namespace data private: uint8_t saveDataType; - std::string title, titleSafe, author; + std::string title, titleSafe, author, path; uint64_t id; bool favorite = false; }; diff --git a/inc/miscui.h b/inc/miscui.h index eee7f90..6da309f 100644 --- a/inc/miscui.h +++ b/inc/miscui.h @@ -29,7 +29,7 @@ namespace ui { public: //Constructor. _max is the maximum value - progBar(const uint64_t& _max); + progBar(const uint64_t& _max) { max = _max; } //Updates progress void update(const uint64_t& _prog); @@ -40,6 +40,7 @@ namespace ui private: uint64_t max, prog; float width; + tex *bg; }; class button diff --git a/inc/util.h b/inc/util.h index abbe9de..46aa04d 100644 --- a/inc/util.h +++ b/inc/util.h @@ -19,12 +19,6 @@ namespace util //Returns string with date S+ time std::string getDateTime(int fmt); - //Creates Dir 'JKSV/[title] - void makeTitleDir(data::user& u, data::titledata& t); - - //Returns 'JKSV/[title]/' - std::string getTitleDir(data::user& u, data::titledata& t); - //Copys dir list to a menu with 'D: ' + 'F: ' void copyDirListToMenu(fs::dirList& d, ui::menu& m); diff --git a/src/data.cpp b/src/data.cpp index 544f0e9..be6dfd9 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -349,6 +349,9 @@ namespace data icons.push_back(newIcn); icon = icons[findIcnIndex(id)]; } + + path = fs::getWorkDir() + titleSafe + "/"; + delete dat; } @@ -364,6 +367,11 @@ namespace data return false; } + void titledata::createDir() + { + mkdir(std::string(fs::getWorkDir() + titleSafe).c_str(), 777); + } + bool user::init(const AccountUid& _id) { userID = _id; diff --git a/src/file.cpp b/src/file.cpp index ec47473..63830f9 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -363,10 +363,10 @@ namespace fs { if(fs::mountSave(u, u.titles[i])) { - util::makeTitleDir(u, u.titles[i]); + u.titles[i].createDir(); //sdmc:/JKSV/[title]/[user] - [date]/ - std::string outPath = util::getTitleDir(u, u.titles[i]) + u.getUsernameSafe() + " - " + util::getDateTime(util::DATE_FMT_YMD); + std::string outPath = u.titles[i].getPath() + u.getUsernameSafe() + " - " + util::getDateTime(util::DATE_FMT_YMD); mkdir(outPath.c_str(), 777); outPath += "/"; diff --git a/src/ui.cpp b/src/ui.cpp index 04ec5e1..9010587 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -295,7 +295,7 @@ namespace ui default: case ColorSetId_Dark: - drawRect(frameBuffer, x + 4, y + 4, w - 8, h - 8, clrCreateU32(0xFF272221)); + drawRect(frameBuffer, x + 4, y + 4, w - 8, h - 8, clrCreateU32(0xFF212221)); break; } diff --git a/src/ui/fldrsel.cpp b/src/ui/fldrsel.cpp index 6c9a92e..d1d7600 100644 --- a/src/ui/fldrsel.cpp +++ b/src/ui/fldrsel.cpp @@ -17,10 +17,9 @@ namespace ui folderMenu.setParams(466, 98, 730); folderMenu.reset(); - util::makeTitleDir(usr, dat); - std::string scanPath = util::getTitleDir(usr, dat); + dat.createDir(); - fs::dirList list(scanPath); + fs::dirList list(dat.getPath()); folderMenu.addOpt("New"); for(unsigned i = 0; i < list.getCount(); i++) folderMenu.addOpt(list.getItem(i)); @@ -70,7 +69,7 @@ namespace ui } if(!folder.empty()) { - std::string path = util::getTitleDir(data::curUser, data::curData) + "/" + folder; + std::string path = data::curData.getPath() + "/" + folder; mkdir(path.c_str(), 777); path += "/"; @@ -82,13 +81,12 @@ namespace ui } else { - std::string scanPath = util::getTitleDir(data::curUser, data::curData); - fs::dirList list(scanPath); + fs::dirList list(data::curData.getPath()); std::string folderName = list.getItem(folderMenu.getSelected() - 1); if(confirm("Are you sure you want to overwrite \"" + folderName + "\"?", true)) { - std::string toPath = util::getTitleDir(data::curUser, data::curData) + folderName + "/"; + std::string toPath = data::curData.getPath() + folderName + "/"; //Delete and recreate fs::delDir(toPath); mkdir(toPath.c_str(), 777); @@ -102,16 +100,15 @@ namespace ui else if(down & KEY_Y || fldNav[1].getEvent() == BUTTON_RELEASED) { if(data::curData.getType() != FsSaveDataType_System && folderMenu.getSelected() > 0) - { - std::string scanPath = util::getTitleDir(data::curUser, data::curData); - fs::dirList list(scanPath); + {; + fs::dirList list(data::curData.getPath()); std::string folderName = list.getItem(folderMenu.getSelected() - 1); if(confirm("Are you sure you want to restore \"" + folderName + "\"?", true)) { if(data::autoBack) { - std::string autoFolder = util::getTitleDir(data::curUser, data::curData) + "/AUTO - " + data::curUser.getUsernameSafe() + " - " + util::getDateTime(util::DATE_FMT_YMD); + std::string autoFolder = data::curData.getPath() + "/AUTO - " + data::curUser.getUsernameSafe() + " - " + util::getDateTime(util::DATE_FMT_YMD); mkdir(autoFolder.c_str(), 777); autoFolder += "/"; @@ -119,7 +116,7 @@ namespace ui fs::copyDirToDir(root, autoFolder); } - std::string fromPath = util::getTitleDir(data::curUser, data::curData) + folderName + "/"; + std::string fromPath = data::curData.getPath() + folderName + "/"; std::string root = "sv:/"; fs::delDir(root); @@ -137,13 +134,12 @@ namespace ui { if(folderMenu.getSelected() > 0) { - std::string scanPath = util::getTitleDir(data::curUser, data::curData); - fs::dirList list(scanPath); + fs::dirList list(data::curData.getPath()); std::string folderName = list.getItem(folderMenu.getSelected() - 1); if(confirm("Are you sure you want to delete \"" + folderName + "\"?", true)) { - std::string delPath = scanPath + folderName + "/"; + std::string delPath = data::curData.getPath() + folderName + "/"; fs::delDir(delPath); } diff --git a/src/ui/miscui.cpp b/src/ui/miscui.cpp index 05d5612..f2b9b2c 100644 --- a/src/ui/miscui.cpp +++ b/src/ui/miscui.cpp @@ -26,11 +26,6 @@ static const std::string loadGlyphArray[] = namespace ui { - progBar::progBar(const uint64_t& _max) - { - max = _max; - } - void progBar::update(const uint64_t& _prog) { prog = _prog; diff --git a/src/ui/ttlsel.cpp b/src/ui/ttlsel.cpp index 3d2ab4a..a763e12 100644 --- a/src/ui/ttlsel.cpp +++ b/src/ui/ttlsel.cpp @@ -91,9 +91,7 @@ namespace ui data::curData = data::curUser.titles[data::selData]; if(fs::mountSave(data::curUser, data::curData)) { - util::makeTitleDir(data::curUser, data::curData); folderMenuPrepare(data::curUser, data::curData); - mstate = FLD_SEL; } } @@ -175,9 +173,7 @@ namespace ui data::curData = data::curUser.titles[data::selData]; if(fs::mountSave(data::curUser, data::curData)) { - util::makeTitleDir(data::curUser, data::curData); folderMenuPrepare(data::curUser, data::curData); - //Wanna change this sometime ui::folderMenuInfo = util::getInfoString(data::curUser, data::curData); @@ -185,9 +181,7 @@ namespace ui } } else if(down & KEY_Y || ttlNav[1].getEvent() == BUTTON_RELEASED) - { fs::dumpAllUserSaves(data::curUser); - } else if(down & KEY_X || ttlNav[2].getEvent() == BUTTON_RELEASED) { std::string confStr = "Are you 100% sure you want to add \"" + data::curUser.titles[data::selData].getTitle() + \ diff --git a/src/ui/txtui.cpp b/src/ui/txtui.cpp index 542b438..e88fa0b 100644 --- a/src/ui/txtui.cpp +++ b/src/ui/txtui.cpp @@ -63,10 +63,9 @@ namespace ui folderMenu.setParams(466, 98, 730); folderMenu.reset(); - util::makeTitleDir(usr, dat); - std::string scanPath = util::getTitleDir(usr, dat); + dat.createDir(); - fs::dirList list(scanPath); + fs::dirList list(dat.getPath()); folderMenu.addOpt("New"); for(unsigned i = 0; i < list.getCount(); i++) folderMenu.addOpt(list.getItem(i)); @@ -111,9 +110,7 @@ namespace ui ui::mstate = EX_MNU; } else if(down & KEY_ZR) - { ui::mstate = OPT_MNU; - } } void textTitleMenuUpdate(const uint64_t& down, const uint64_t& held, const touchPosition& p) @@ -130,9 +127,7 @@ namespace ui if(fs::mountSave(data::curUser, data::curData)) { - util::makeTitleDir(data::curUser, data::curData); textFolderPrep(data::curUser, data::curData); - mstate = TXT_FLD; } } @@ -221,7 +216,7 @@ namespace ui } if(!folder.empty()) { - std::string path = util::getTitleDir(data::curUser, data::curData) + "/" + folder; + std::string path = data::curData.getPath() + folder; mkdir(path.c_str(), 777); path += "/"; @@ -233,13 +228,12 @@ namespace ui } else { - std::string scanPath = util::getTitleDir(data::curUser, data::curData); - fs::dirList list(scanPath); + fs::dirList list(data::curData.getPath()); std::string folderName = list.getItem(folderMenu.getSelected() - 1); if(confirm("Are you sure you want to overwrite \"" + folderName + "\"?", true)) { - std::string toPath = util::getTitleDir(data::curUser, data::curData) + folderName + "/"; + std::string toPath = data::curData.getPath() + folderName + "/"; //Delete and recreate fs::delDir(toPath); mkdir(toPath.c_str(), 777); @@ -254,15 +248,14 @@ namespace ui { if(data::curData.getType() != FsSaveDataType_System && folderMenu.getSelected() > 0) { - std::string scanPath = util::getTitleDir(data::curUser, data::curData); - fs::dirList list(scanPath); + fs::dirList list(data::curData.getPath()); std::string folderName = list.getItem(folderMenu.getSelected() - 1); if(confirm("Are you sure you want to restore \"" + folderName + "\"?", true)) { if(data::autoBack) { - std::string autoFolder = util::getTitleDir(data::curUser, data::curData) + "/AUTO - " + data::curUser.getUsernameSafe() + " - " + util::getDateTime(util::DATE_FMT_YMD); + std::string autoFolder = data::curData.getPath() + "/AUTO - " + data::curUser.getUsernameSafe() + " - " + util::getDateTime(util::DATE_FMT_YMD); mkdir(autoFolder.c_str(), 777); autoFolder += "/"; @@ -270,7 +263,7 @@ namespace ui fs::copyDirToDir(root, autoFolder); } - std::string fromPath = util::getTitleDir(data::curUser, data::curData) + folderName + "/"; + std::string fromPath = data::curData.getPath() + folderName + "/"; std::string root = "sv:/"; fs::delDir(root); @@ -287,13 +280,12 @@ namespace ui { if(folderMenu.getSelected() > 0) { - std::string scanPath = util::getTitleDir(data::curUser, data::curData); - fs::dirList list(scanPath); + fs::dirList list(data::curData.getPath()); std::string folderName = list.getItem(folderMenu.getSelected() - 1); if(confirm("Are you sure you want to delete \"" + folderName + "\"?", true)) { - std::string delPath = scanPath + folderName + "/"; + std::string delPath = data::curData.getPath() + folderName + "/"; fs::delDir(delPath); } diff --git a/src/util.cpp b/src/util.cpp index 21786e7..c35d1c9 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -94,17 +94,6 @@ namespace util return std::string(ret); } - void makeTitleDir(data::user& u, data::titledata& t) - { - std::string path = fs::getWorkDir() + t.getTitleSafe(); - mkdir(path.c_str(), 777); - } - - std::string getTitleDir(data::user& u, data::titledata& t) - { - return std::string(fs::getWorkDir() + t.getTitleSafe() + "/"); - } - void copyDirListToMenu(fs::dirList& d, ui::menu& m) { m.reset();