This commit is contained in:
J-D-K 2018-12-03 23:26:13 -05:00
parent 1a33cd9ddc
commit 581db1ea59
11 changed files with 150 additions and 60 deletions

View File

@ -37,8 +37,8 @@ DATA := data
INCLUDES := inc INCLUDES := inc
EXEFS_SRC := exefs_src EXEFS_SRC := exefs_src
APP_TITLE := JKSV APP_TITLE := JKSV
APP_AUTHOR := JK_ APP_AUTHOR := JK
APP_VERSION := 11/7/2018 APP_VERSION := 12/03/2018
ROMFS := romfs ROMFS := romfs
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------

View File

@ -13,8 +13,8 @@ namespace ui
//I don't think this matched very well //I don't think this matched very well
void classicFolderMenuUpdate(const uint64_t& down, const uint64_t& held, const touchPosition& p); 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 updateExMenu(const uint64_t& down, const uint64_t& held, const touchPosition& p);
void devMenuPrep(); void exMenuPrep();
} }
#endif // CLSUI_H #endif // CLSUI_H

View File

@ -38,6 +38,18 @@ namespace fs
//Retrieves working dir string //Retrieves working dir string
std::string getWorkDir(); 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 //Just retrieves a listing for _path and stores it in item vector
class dirList class dirList
{ {
@ -54,7 +66,7 @@ namespace fs
DIR *d; DIR *d;
struct dirent *ent; struct dirent *ent;
std::string path; std::string path;
std::vector<std::string> item; std::vector<dirItem> item;
}; };
} }

View File

@ -23,7 +23,7 @@ enum menuState
CLS_USR, CLS_USR,
CLS_TTL, CLS_TTL,
CLS_FLD, CLS_FLD,
DEV_MNU EX_MNU
}; };

View File

@ -1,5 +1,7 @@
#include <fstream> #include <fstream>
#include <cstdio> #include <cstdio>
#include <algorithm>
#include <cstring>
#include <switch.h> #include <switch.h>
#include <dirent.h> #include <dirent.h>
#include <unistd.h> #include <unistd.h>
@ -15,6 +17,21 @@
static std::string wd; 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 namespace fs
{ {
void init() void init()
@ -49,15 +66,49 @@ namespace fs
return true; 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) dirList::dirList(const std::string& _path)
{ {
path = _path; path = _path;
d = opendir(path.c_str()); d = opendir(path.c_str());
std::vector<dirItem> dirVect, filVect;
while((ent = readdir(d))) 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); 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) void dirList::reassign(const std::string& _path)
@ -68,10 +119,24 @@ namespace fs
item.clear(); item.clear();
std::vector<dirItem> dirVect, filVect;
while((ent = readdir(d))) 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); 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() void dirList::rescan()
@ -79,22 +144,34 @@ namespace fs
item.clear(); item.clear();
d = opendir(path.c_str()); d = opendir(path.c_str());
std::vector<dirItem> dirVect, filVect;
while((ent = readdir(d))) 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); 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) std::string dirList::getItem(int index)
{ {
return item[index]; return item[index].getItm();
} }
bool dirList::isDir(int index) bool dirList::isDir(int index)
{ {
std::string fullPath = path + item[index]; return item[index].isDir();
struct stat s;
return stat(fullPath.c_str(), &s) == 0 && S_ISDIR(s.st_mode);
} }
unsigned dirList::getCount() unsigned dirList::getCount()

View File

@ -67,13 +67,6 @@ int main(int argc, const char *argv[])
ui::mstate = ui::clsMode ? CLS_USR : USR_SEL; 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) else if(down & KEY_PLUS)
break; break;

View File

@ -11,7 +11,7 @@
#include "util.h" #include "util.h"
#include "file.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" //background that can be drawn from "/JKSV/back.jpg"
//txtSide and fldSide are to fake alpha blending so the framerate doesn't suffer //txtSide and fldSide are to fake alpha blending so the framerate doesn't suffer
@ -183,13 +183,15 @@ namespace ui
void setupNavButtons() void setupNavButtons()
{ {
//User Select //User Select
int startX = 848; int startX = 878;
ui::button sel("", startX, 656, 110, 64); ui::button sel("", startX, 656, 110, 64);
ui::button dmp("", startX += 110, 656, 134, 64); ui::button dmp("", startX += 110, 656, 134, 64);
ui::button cls("", startX += 134, 656, 110, 64); ui::button cls("", startX += 134, 656, 110, 64);
ui::button ex("", startX += 110, 656, 110, 64);
usrNav.push_back(sel); usrNav.push_back(sel);
usrNav.push_back(dmp); usrNav.push_back(dmp);
usrNav.push_back(cls); usrNav.push_back(cls);
usrNav.push_back(ex);
//Title //Title
startX = 804; startX = 804;
@ -243,7 +245,7 @@ namespace ui
case CLS_TTL: case CLS_TTL:
case CLS_USR: case CLS_USR:
case CLS_FLD: case CLS_FLD:
case DEV_MNU: case EX_MNU:
if(txtSide == NULL) if(txtSide == NULL)
drawRect(frameBuffer, 30, 88, 448, 560, sideRect); drawRect(frameBuffer, 30, 88, 448, 560, sideRect);
else else
@ -257,7 +259,7 @@ namespace ui
case CLS_USR: case CLS_USR:
{ {
//Input guide //Input guide
unsigned startX = 848; unsigned startX = 754;
texDraw(buttonA, frameBuffer, startX, 672); texDraw(buttonA, frameBuffer, startX, 672);
drawText("Select", frameBuffer, shared, startX += 38, 680, 14, mnuTxt); drawText("Select", frameBuffer, shared, startX += 38, 680, 14, mnuTxt);
texDraw(buttonY, frameBuffer, startX += 72, 672); texDraw(buttonY, frameBuffer, startX += 72, 672);
@ -267,6 +269,8 @@ namespace ui
drawText("GUI Mode", frameBuffer, shared, startX += 38, 680, 14, mnuTxt); drawText("GUI Mode", frameBuffer, shared, startX += 38, 680, 14, mnuTxt);
else else
drawText("Text Mode", frameBuffer, shared, startX += 38, 680, 14, mnuTxt); 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; break;
@ -340,8 +344,8 @@ namespace ui
classicFolderMenuUpdate(down, held, p); classicFolderMenuUpdate(down, held, p);
break; break;
case DEV_MNU: case EX_MNU:
updateDevMenu(down, held, p); updateExMenu(down, held, p);
break; break;
} }
} }

View File

@ -103,8 +103,8 @@ void performCopyMenuOps()
fs::copyFileCommit(fromPath, toPath, "sv"); fs::copyFileCommit(fromPath, toPath, "sv");
} }
} }
break;
} }
break;
} }
} }
break; break;
@ -181,18 +181,21 @@ void performCopyMenuOps()
//save //save
case 0: case 0:
{ {
if(saveMenu.getSelected() > 1 && data::curData.getType() != FsSaveDataType_SystemSaveData) if(data::curData.getType() != FsSaveDataType_SystemSaveData)
{ {
int selSave = saveMenu.getSelected() - 2; if(saveMenu.getSelected() > 1)
ui::keyboard getName;
std::string newName = getName.getString(saveList.getItem(selSave));
if(!newName.empty())
{ {
std::string b4Path = savePath + saveList.getItem(selSave); int selSave = saveMenu.getSelected() - 2;
std::string newPath = savePath + newName; 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()); std::rename(b4Path.c_str(), newPath.c_str());
fsdevCommitDevice("sv"); fsdevCommitDevice("sv");
}
} }
} }
} }
@ -458,8 +461,8 @@ namespace ui
} }
else if(down & KEY_MINUS) else if(down & KEY_MINUS)
{ {
if(prevState == DEV_MNU) if(prevState == EX_MNU)
mstate = DEV_MNU; mstate = EX_MNU;
else if(ui::clsMode) else if(ui::clsMode)
mstate = CLS_FLD; mstate = CLS_FLD;
else else

View File

@ -225,7 +225,7 @@ namespace ui
} }
} }
void devMenuPrep() void exMenuPrep()
{ {
devMenu.reset(); devMenu.reset();
devMenu.setParams(42, 98, 424); devMenu.setParams(42, 98, 424);
@ -238,7 +238,7 @@ namespace ui
devMenu.addOpt("Remove Downloaded Update"); 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); devMenu.handleInput(down, held, p);
@ -255,7 +255,7 @@ namespace ui
advModePrep(); advModePrep();
mstate = ADV_MDE; mstate = ADV_MDE;
prevState = DEV_MNU; prevState = EX_MNU;
break; break;
case 1: case 1:
@ -265,7 +265,7 @@ namespace ui
advModePrep(); advModePrep();
mstate = ADV_MDE; mstate = ADV_MDE;
prevState = DEV_MNU; prevState = EX_MNU;
break; break;
case 2: case 2:
@ -275,7 +275,7 @@ namespace ui
advModePrep(); advModePrep();
mstate = ADV_MDE; mstate = ADV_MDE;
prevState = DEV_MNU; prevState = EX_MNU;
break; break;
case 3: case 3:
@ -285,7 +285,7 @@ namespace ui
advModePrep(); advModePrep();
mstate = ADV_MDE; mstate = ADV_MDE;
prevState = DEV_MNU; prevState = EX_MNU;
break; break;
case 4: case 4:

View File

@ -92,28 +92,23 @@ namespace ui
} }
else if(down & KEY_Y || fldNav[1].getEvent() == BUTTON_RELEASED) 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); std::string fromPath = util::getTitleDir(data::curUser, data::curData) + folderName + "/";
fs::dirList list(scanPath); std::string root = "sv:/";
std::string folderName = list.getItem(folderMenu.getSelected() - 1); fs::delDir(root);
if(confirm("Are you sure you want to restore \"" + folderName + "\"?")) fsdevCommitDevice("sv");
{
std::string fromPath = util::getTitleDir(data::curUser, data::curData) + folderName + "/";
std::string root = "sv:/";
fs::delDir(root); fs::copyDirToDirCommit(fromPath, root, "sv");
fsdevCommitDevice("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) else if(down & KEY_X || fldNav[2].getEvent() == BUTTON_RELEASED)
{ {

View File

@ -163,5 +163,11 @@ namespace ui
mstate = CLS_USR; mstate = CLS_USR;
clsMode = true; clsMode = true;
} }
else if(down & KEY_MINUS || usrNav[3].getEvent() == BUTTON_RELEASED)
{
fsdevUnmountDevice("sv");
ui::exMenuPrep();
ui::mstate = EX_MNU;
}
} }
} }