From 581db1ea59b638fa9ec641de307ecd40d8240f46 Mon Sep 17 00:00:00 2001 From: J-D-K Date: Mon, 3 Dec 2018 23:26:13 -0500 Subject: [PATCH] Update --- Makefile | 4 +- inc/clsui.h | 4 +- inc/file.h | 14 ++++++- inc/ui.h | 2 +- src/file.cpp | 91 ++++++++++++++++++++++++++++++++++++++++++---- src/main.cpp | 7 ---- src/ui.cpp | 16 +++++--- src/ui/advmode.cpp | 27 ++++++++------ src/ui/clsui.cpp | 12 +++--- src/ui/fldrsel.cpp | 27 ++++++-------- src/ui/usrsel.cpp | 6 +++ 11 files changed, 150 insertions(+), 60 deletions(-) diff --git a/Makefile b/Makefile index 143416e..e654088 100644 --- a/Makefile +++ b/Makefile @@ -37,8 +37,8 @@ DATA := data INCLUDES := inc EXEFS_SRC := exefs_src APP_TITLE := JKSV -APP_AUTHOR := JK_ -APP_VERSION := 11/7/2018 +APP_AUTHOR := JK +APP_VERSION := 12/03/2018 ROMFS := romfs #--------------------------------------------------------------------------------- diff --git a/inc/clsui.h b/inc/clsui.h index 471d84f..d06a2a1 100644 --- a/inc/clsui.h +++ b/inc/clsui.h @@ -13,8 +13,8 @@ namespace ui //I don't think this matched very well void classicFolderMenuUpdate(const uint64_t& down, const uint64_t& held, const touchPosition& p); - void updateDevMenu(const uint64_t& down, const uint64_t& held, const touchPosition& p); - void devMenuPrep(); + void updateExMenu(const uint64_t& down, const uint64_t& held, const touchPosition& p); + void exMenuPrep(); } #endif // CLSUI_H diff --git a/inc/file.h b/inc/file.h index a310dbe..7652971 100644 --- a/inc/file.h +++ b/inc/file.h @@ -38,6 +38,18 @@ namespace fs //Retrieves working dir string std::string getWorkDir(); + class dirItem + { + public: + dirItem(const std::string& pathTo, const std::string& sItem); + std::string getItm(); + bool isDir(); + + private: + std::string itm; + bool dir = false; + }; + //Just retrieves a listing for _path and stores it in item vector class dirList { @@ -54,7 +66,7 @@ namespace fs DIR *d; struct dirent *ent; std::string path; - std::vector item; + std::vector item; }; } diff --git a/inc/ui.h b/inc/ui.h index 6c86eaf..4e165e9 100644 --- a/inc/ui.h +++ b/inc/ui.h @@ -23,7 +23,7 @@ enum menuState CLS_USR, CLS_TTL, CLS_FLD, - DEV_MNU + EX_MNU }; diff --git a/src/file.cpp b/src/file.cpp index 513feff..32cb271 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include #include #include #include @@ -15,6 +17,21 @@ static std::string wd; +static struct +{ + bool operator()(fs::dirItem& a, fs::dirItem& b) + { + for(unsigned i = 0; i < a.getItm().length(); i++) + { + char charA = tolower(a.getItm()[i]); + char charB = tolower(b.getItm()[i]); + if(charA != charB) + return charA < charB; + } + return false; + } +} sortListAlpha; + namespace fs { void init() @@ -49,15 +66,49 @@ namespace fs return true; } + dirItem::dirItem(const std::string& pathTo, const std::string& sItem) + { + itm = sItem; + + std::string fullPath = pathTo + sItem; + struct stat s; + if(stat(fullPath.c_str(), &s) == 0 && S_ISDIR(s.st_mode)) + dir = true; + } + + std::string dirItem::getItm() + { + return itm; + } + + bool dirItem::isDir() + { + return dir; + } + dirList::dirList(const std::string& _path) { path = _path; d = opendir(path.c_str()); + std::vector dirVect, filVect; + while((ent = readdir(d))) - item.push_back(ent->d_name); + { + dirItem add(path, ent->d_name); + if(add.isDir()) + dirVect.push_back(add); + else + filVect.push_back(add); + } closedir(d); + + std::sort(dirVect.begin(), dirVect.end(), sortListAlpha); + std::sort(filVect.begin(), filVect.end(), sortListAlpha); + + item.assign(dirVect.begin(), dirVect.end()); + item.insert(item.end(), filVect.begin(), filVect.end()); } void dirList::reassign(const std::string& _path) @@ -68,10 +119,24 @@ namespace fs item.clear(); + std::vector dirVect, filVect; + while((ent = readdir(d))) - item.push_back(ent->d_name); + { + dirItem add(path, ent->d_name); + if(add.isDir()) + dirVect.push_back(add); + else + filVect.push_back(add); + } closedir(d); + + std::sort(dirVect.begin(), dirVect.end(), sortListAlpha); + std::sort(filVect.begin(), filVect.end(), sortListAlpha); + + item.assign(dirVect.begin(), dirVect.end()); + item.insert(item.end(), filVect.begin(), filVect.end()); } void dirList::rescan() @@ -79,22 +144,34 @@ namespace fs item.clear(); d = opendir(path.c_str()); + std::vector dirVect, filVect; + while((ent = readdir(d))) - item.push_back(ent->d_name); + { + dirItem add(path, ent->d_name); + if(add.isDir()) + dirVect.push_back(add); + else + filVect.push_back(add); + } closedir(d); + + std::sort(dirVect.begin(), dirVect.end(), sortListAlpha); + std::sort(filVect.begin(), filVect.end(), sortListAlpha); + + item.assign(dirVect.begin(), dirVect.end()); + item.insert(item.end(), filVect.begin(), filVect.end()); } std::string dirList::getItem(int index) { - return item[index]; + return item[index].getItm(); } bool dirList::isDir(int index) { - std::string fullPath = path + item[index]; - struct stat s; - return stat(fullPath.c_str(), &s) == 0 && S_ISDIR(s.st_mode); + return item[index].isDir(); } unsigned dirList::getCount() diff --git a/src/main.cpp b/src/main.cpp index 5e492f0..b075193 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -67,13 +67,6 @@ int main(int argc, const char *argv[]) ui::mstate = ui::clsMode ? CLS_USR : USR_SEL; } } - else if((held & KEY_ZL) && (held & KEY_ZR) && (held & KEY_MINUS) && ui::confirm("You are using this mode at your own risk.")) - { - fsdevUnmountDevice("sv"); - data::curData.setType(FsSaveDataType_SystemSaveData); - ui::devMenuPrep(); - ui::mstate = DEV_MNU; - } else if(down & KEY_PLUS) break; diff --git a/src/ui.cpp b/src/ui.cpp index 92bf8b4..d8352ce 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -11,7 +11,7 @@ #include "util.h" #include "file.h" -#define VER_STRING "v. 11/7/2018" +#define VER_STRING "v. 12/03/2018" //background that can be drawn from "/JKSV/back.jpg" //txtSide and fldSide are to fake alpha blending so the framerate doesn't suffer @@ -183,13 +183,15 @@ namespace ui void setupNavButtons() { //User Select - int startX = 848; + int startX = 878; ui::button sel("", startX, 656, 110, 64); ui::button dmp("", startX += 110, 656, 134, 64); ui::button cls("", startX += 134, 656, 110, 64); + ui::button ex("", startX += 110, 656, 110, 64); usrNav.push_back(sel); usrNav.push_back(dmp); usrNav.push_back(cls); + usrNav.push_back(ex); //Title startX = 804; @@ -243,7 +245,7 @@ namespace ui case CLS_TTL: case CLS_USR: case CLS_FLD: - case DEV_MNU: + case EX_MNU: if(txtSide == NULL) drawRect(frameBuffer, 30, 88, 448, 560, sideRect); else @@ -257,7 +259,7 @@ namespace ui case CLS_USR: { //Input guide - unsigned startX = 848; + unsigned startX = 754; texDraw(buttonA, frameBuffer, startX, 672); drawText("Select", frameBuffer, shared, startX += 38, 680, 14, mnuTxt); texDraw(buttonY, frameBuffer, startX += 72, 672); @@ -267,6 +269,8 @@ namespace ui drawText("GUI Mode", frameBuffer, shared, startX += 38, 680, 14, mnuTxt); else drawText("Text Mode", frameBuffer, shared, startX += 38, 680, 14, mnuTxt); + texDraw(buttonMin, frameBuffer, startX += 110, 672); + drawText("Extras", frameBuffer, shared, startX += 38, 680, 14, mnuTxt); } break; @@ -340,8 +344,8 @@ namespace ui classicFolderMenuUpdate(down, held, p); break; - case DEV_MNU: - updateDevMenu(down, held, p); + case EX_MNU: + updateExMenu(down, held, p); break; } } diff --git a/src/ui/advmode.cpp b/src/ui/advmode.cpp index 99512b2..dc77d04 100644 --- a/src/ui/advmode.cpp +++ b/src/ui/advmode.cpp @@ -103,8 +103,8 @@ void performCopyMenuOps() fs::copyFileCommit(fromPath, toPath, "sv"); } } + break; } - break; } } break; @@ -181,18 +181,21 @@ void performCopyMenuOps() //save case 0: { - if(saveMenu.getSelected() > 1 && data::curData.getType() != FsSaveDataType_SystemSaveData) + if(data::curData.getType() != FsSaveDataType_SystemSaveData) { - int selSave = saveMenu.getSelected() - 2; - ui::keyboard getName; - std::string newName = getName.getString(saveList.getItem(selSave)); - if(!newName.empty()) + if(saveMenu.getSelected() > 1) { - std::string b4Path = savePath + saveList.getItem(selSave); - std::string newPath = savePath + newName; + int selSave = saveMenu.getSelected() - 2; + ui::keyboard getName; + std::string newName = getName.getString(saveList.getItem(selSave)); + if(!newName.empty()) + { + std::string b4Path = savePath + saveList.getItem(selSave); + std::string newPath = savePath + newName; - std::rename(b4Path.c_str(), newPath.c_str()); - fsdevCommitDevice("sv"); + std::rename(b4Path.c_str(), newPath.c_str()); + fsdevCommitDevice("sv"); + } } } } @@ -458,8 +461,8 @@ namespace ui } else if(down & KEY_MINUS) { - if(prevState == DEV_MNU) - mstate = DEV_MNU; + if(prevState == EX_MNU) + mstate = EX_MNU; else if(ui::clsMode) mstate = CLS_FLD; else diff --git a/src/ui/clsui.cpp b/src/ui/clsui.cpp index c5c60f4..cfc8eee 100644 --- a/src/ui/clsui.cpp +++ b/src/ui/clsui.cpp @@ -225,7 +225,7 @@ namespace ui } } - void devMenuPrep() + void exMenuPrep() { devMenu.reset(); devMenu.setParams(42, 98, 424); @@ -238,7 +238,7 @@ namespace ui devMenu.addOpt("Remove Downloaded Update"); } - void updateDevMenu(const uint64_t& down, const uint64_t& held, const touchPosition& p) + void updateExMenu(const uint64_t& down, const uint64_t& held, const touchPosition& p) { devMenu.handleInput(down, held, p); @@ -255,7 +255,7 @@ namespace ui advModePrep(); mstate = ADV_MDE; - prevState = DEV_MNU; + prevState = EX_MNU; break; case 1: @@ -265,7 +265,7 @@ namespace ui advModePrep(); mstate = ADV_MDE; - prevState = DEV_MNU; + prevState = EX_MNU; break; case 2: @@ -275,7 +275,7 @@ namespace ui advModePrep(); mstate = ADV_MDE; - prevState = DEV_MNU; + prevState = EX_MNU; break; case 3: @@ -285,7 +285,7 @@ namespace ui advModePrep(); mstate = ADV_MDE; - prevState = DEV_MNU; + prevState = EX_MNU; break; case 4: diff --git a/src/ui/fldrsel.cpp b/src/ui/fldrsel.cpp index a28ea05..ba869c0 100644 --- a/src/ui/fldrsel.cpp +++ b/src/ui/fldrsel.cpp @@ -92,28 +92,23 @@ namespace ui } else if(down & KEY_Y || fldNav[1].getEvent() == BUTTON_RELEASED) { - if(data::curData.getType() != FsSaveDataType_SystemSaveData) + if(folderMenu.getSelected() > 0) { - if(folderMenu.getSelected() > 0) + std::string scanPath = util::getTitleDir(data::curUser, data::curData); + fs::dirList list(scanPath); + + std::string folderName = list.getItem(folderMenu.getSelected() - 1); + if(confirm("Are you sure you want to restore \"" + folderName + "\"?")) { - std::string scanPath = util::getTitleDir(data::curUser, data::curData); - fs::dirList list(scanPath); + std::string fromPath = util::getTitleDir(data::curUser, data::curData) + folderName + "/"; + std::string root = "sv:/"; - std::string folderName = list.getItem(folderMenu.getSelected() - 1); - if(confirm("Are you sure you want to restore \"" + folderName + "\"?")) - { - std::string fromPath = util::getTitleDir(data::curUser, data::curData) + folderName + "/"; - std::string root = "sv:/"; + fs::delDir(root); + fsdevCommitDevice("sv"); - fs::delDir(root); - fsdevCommitDevice("sv"); - - fs::copyDirToDirCommit(fromPath, root, "sv"); - } + fs::copyDirToDirCommit(fromPath, root, "sv"); } } - else - ui::showMessage("Writing data to system save data is not allowed currently. It CAN brick your system."); } else if(down & KEY_X || fldNav[2].getEvent() == BUTTON_RELEASED) { diff --git a/src/ui/usrsel.cpp b/src/ui/usrsel.cpp index 03841ac..46d0e86 100644 --- a/src/ui/usrsel.cpp +++ b/src/ui/usrsel.cpp @@ -163,5 +163,11 @@ namespace ui mstate = CLS_USR; clsMode = true; } + else if(down & KEY_MINUS || usrNav[3].getEvent() == BUTTON_RELEASED) + { + fsdevUnmountDevice("sv"); + ui::exMenuPrep(); + ui::mstate = EX_MNU; + } } }