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
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
#---------------------------------------------------------------------------------

View File

@ -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

View File

@ -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<std::string> item;
std::vector<dirItem> item;
};
}

View File

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

View File

@ -1,5 +1,7 @@
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <switch.h>
#include <dirent.h>
#include <unistd.h>
@ -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<dirItem> 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<dirItem> 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<dirItem> 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()

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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

View File

@ -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:

View File

@ -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)
{

View File

@ -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;
}
}
}