Remove const

This commit is contained in:
J-D-K 2018-06-11 11:12:18 -04:00
parent c0360a3293
commit 5a0808ab01
14 changed files with 1229 additions and 1226 deletions

View File

@ -1,2 +1,3 @@
#JKSV
JKSV for Switch. Mostly to get used to libnx.

View File

@ -8,44 +8,44 @@
namespace data
{
bool init();
bool fini();
bool init();
bool fini();
void loadDataInfo();
void loadDataInfo();
class titledata
{
public:
bool init(const uint64_t& _id, const u128& _uID);
class titledata
{
public:
bool init(const uint64_t& _id, const u128& _uID);
const std::string getTitle();
const std::string getTitleSafe();
std::string getTitle();
std::string getTitleSafe();
const uint64_t getID();
uint64_t getID();
private:
std::string title, titleSafe;
uint64_t id;
u128 uID;
};
private:
std::string title, titleSafe;
uint64_t id;
u128 uID;
};
class user
{
public:
bool init(const u128& _id);
const u128 getUID();
const std::string getUsername();
class user
{
public:
bool init(const u128& _id);
u128 getUID();
std::string getUsername();
std::vector<titledata> titles;
std::vector<titledata> titles;
private:
u128 userID;
std::string username;
};
private:
u128 userID;
std::string username;
};
extern std::vector<user> users;
extern titledata curData;
extern user curUser;
extern std::vector<user> users;
extern titledata curData;
extern user curUser;
}
#endif // DATA_H

View File

@ -10,27 +10,27 @@
namespace fs
{
bool mountSave(data::user& usr, data::titledata& open);
void copyDirToDir(const std::string& from, const std::string& to);
void copyDirToDirCommit(const std::string& from, const std::string& to, const std::string& dev);
void delDir(const std::string& path);
bool mountSave(data::user& usr, data::titledata& open);
void copyDirToDir(const std::string& from, const std::string& to);
void copyDirToDirCommit(const std::string& from, const std::string& to, const std::string& dev);
void delDir(const std::string& path);
class dirList
{
public:
dirList(const std::string& _path);
void rescan();
class dirList
{
public:
dirList(const std::string& _path);
void rescan();
const std::string getItem(int index);
bool isDir(int index);
unsigned getCount();
std::string getItem(int index);
bool isDir(int index);
unsigned getCount();
private:
DIR *d;
struct dirent *ent;
std::string path;
std::vector<std::string> item;
};
private:
DIR *d;
struct dirent *ent;
std::string path;
std::vector<std::string> item;
};
}
#endif // FILE_H

View File

@ -5,28 +5,28 @@
namespace gfx
{
bool init(const uint32_t& _fontSize);
bool fini();
bool init(const uint32_t& _fontSize);
bool fini();
void switchMode();
void handleBuffs();
void switchMode();
void handleBuffs();
void clearConsoleColor(const uint32_t& clr);
void drawText(const std::string& str, unsigned x, unsigned y, const uint32_t& sz, const uint32_t& clr);
void drawRectangle(uint32_t x, uint32_t y, const uint32_t& width, const uint32_t& height, const uint32_t& clr);
void clearConsoleColor(const uint32_t& clr);
void drawText(const std::string& str, unsigned x, unsigned y, const uint32_t& sz, const uint32_t& clr);
void drawRectangle(uint32_t x, uint32_t y, const uint32_t& width, const uint32_t& height, const uint32_t& clr);
class tex
{
public:
void loadFromFile(const std::string& path);
~tex();
void draw(uint32_t x, uint32_t y);
class tex
{
public:
void loadFromFile(const std::string& path);
~tex();
void draw(uint32_t x, uint32_t y);
private:
uint32_t sz;
uint16_t width, height;
uint8_t *data = NULL;
};
private:
uint32_t sz;
uint16_t width, height;
uint8_t *data = NULL;
};
}
#endif // GFX_H

View File

@ -3,10 +3,10 @@
namespace sys
{
bool init();
bool fini();
bool init();
bool fini();
void debugWrite(const std::string& out);
void debugWrite(const std::string& out);
}
#endif // SYS_H

130
inc/ui.h
View File

@ -8,85 +8,85 @@
namespace ui
{
class menu
{
public:
void addOpt(const std::string& add);
~menu();
class menu
{
public:
void addOpt(const std::string& add);
~menu();
void handleInput(const uint64_t& down, const uint64_t& held);
int getSelected();
void print(const unsigned& x, const unsigned& y, const uint32_t& rectWidth);
void handleInput(const uint64_t& down, const uint64_t& held);
int getSelected();
void print(const unsigned& x, const unsigned& y, const uint32_t& rectWidth);
void reset();
void reset();
private:
std::vector<std::string> opt;
int selected = 0, fc = 0, start = 0;
uint8_t clrSh = 0;
bool clrAdd = true;
};
private:
std::vector<std::string> opt;
int selected = 0, fc = 0, start = 0;
uint8_t clrSh = 0;
bool clrAdd = true;
};
class progBar
{
public:
progBar(const uint32_t& _max);
void update(const uint32_t& _prog);
void draw(const std::string& text);
class progBar
{
public:
progBar(const uint32_t& _max);
void update(const uint32_t& _prog);
void draw(const std::string& text);
private:
float max, prog, width;
};
private:
float max, prog, width;
};
class key
{
public:
key(const std::string& txt, const char& _let, const unsigned& _txtSz, const unsigned& _x, const unsigned& _y, const unsigned& _w, const unsigned& _h);
void updateText(const std::string& txt);
void draw();
bool isOver(const touchPosition& p);
bool released(const touchPosition& p);
char getLet();
void toCaps();
void toLower();
class key
{
public:
key(const std::string& txt, const char& _let, const unsigned& _txtSz, const unsigned& _x, const unsigned& _y, const unsigned& _w, const unsigned& _h);
void updateText(const std::string& txt);
void draw();
bool isOver(const touchPosition& p);
bool released(const touchPosition& p);
char getLet();
void toCaps();
void toLower();
private:
bool pressed;
char let;
unsigned x, y, w, h;
unsigned tX, tY;
unsigned txtSz;
std::string text;
touchPosition prev;
};
private:
bool pressed;
char let;
unsigned x, y, w, h;
unsigned tX, tY;
unsigned txtSz;
std::string text;
touchPosition prev;
};
class keyboard
{
public:
keyboard();
~keyboard();
class keyboard
{
public:
keyboard();
~keyboard();
void draw();
const std::string getString();
void draw();
std::string getString();
private:
std::vector<key> keys;
std::string str;
};
private:
std::vector<key> keys;
std::string str;
};
void init();
void init();
void userMenuInit();
void titleMenuPrepare(data::user& usr);
void folderMenuPrepare(data::user& usr, data::titledata& dat);
void userMenuInit();
void titleMenuPrepare(data::user& usr);
void folderMenuPrepare(data::user& usr, data::titledata& dat);
void showUserMenu(const uint64_t& down, const uint64_t& held);
void showTitleMenu(const uint64_t& down, const uint64_t& held);
void showFolderMenu(const uint64_t& down, const uint64_t& held);
void runApp(const uint64_t& down, const uint64_t& held);
void showUserMenu(const uint64_t& down, const uint64_t& held);
void showTitleMenu(const uint64_t& down, const uint64_t& held);
void showFolderMenu(const uint64_t& down, const uint64_t& held);
void runApp(const uint64_t& down, const uint64_t& held);
void showMessage(const std::string& mess);
void showError(const std::string& mess, const Result& r);
void showMessage(const std::string& mess);
void showError(const std::string& mess, const Result& r);
}
#endif

View File

@ -5,8 +5,8 @@
namespace util
{
const std::string getDateTime();
void makeTitleDir(data::user& u, data::titledata& t);
const std::string getTitleDir(data::user& u, data::titledata& t);
std::string getDateTime();
void makeTitleDir(data::user& u, data::titledata& t);
std::string getTitleDir(data::user& u, data::titledata& t);
}
#endif // UTIL_H

View File

@ -15,248 +15,248 @@ static const char verboten[] = { '.', ',', '/', '\\', '<', '>', ':', '"', '|', '
bool isVerboten(char t)
{
for(unsigned i = 0; i < 11; i++)
{
if(t == verboten[i])
return true;
}
for(unsigned i = 0; i < 11; i++)
{
if(t == verboten[i])
return true;
}
return false;
return false;
}
const std::string safeString(const std::string& s)
{
std::string ret = "";
for(unsigned i = 0; i < s.length(); i++)
{
if(isVerboten(s[i]))
{
ret += ' ';
}
else
ret += s[i];
}
std::string ret = "";
for(unsigned i = 0; i < s.length(); i++)
{
if(isVerboten(s[i]))
{
ret += ' ';
}
else
ret += s[i];
}
return ret;
return ret;
}
namespace data
{
titledata curData;
user curUser;
std::vector<user> users;
titledata curData;
user curUser;
std::vector<user> users;
bool init()
{
Result res = 0;
bool init()
{
Result res = 0;
res = accountInitialize();
if(res)
{
printf("accountInitialize failed!");
return false;
}
res = accountInitialize();
if(res)
{
printf("accountInitialize failed!");
return false;
}
return true;
}
return true;
}
bool fini()
{
accountExit();
bool fini()
{
accountExit();
return true;
}
return true;
}
struct
{
bool operator()(titledata& a, titledata& b)
{
for(unsigned i = 0; i < a.getTitle().length(); i++)
{
int charA = tolower(a.getTitle().c_str()[i]), charB = tolower(b.getTitle().c_str()[i]);
if(charA != charB)
return charA < charB;
}
struct
{
bool operator()(titledata& a, titledata& b)
{
for(unsigned i = 0; i < a.getTitle().length(); i++)
{
int charA = tolower(a.getTitle().c_str()[i]), charB = tolower(b.getTitle().c_str()[i]);
if(charA != charB)
return charA < charB;
}
return false;
}
} sortTitles;
return false;
}
} sortTitles;
int getUserIndex(const u128& id)
{
for(unsigned i = 0; i < users.size(); i++)
{
if(users[i].getUID() == id)
return i;
}
int getUserIndex(const u128& id)
{
for(unsigned i = 0; i < users.size(); i++)
{
if(users[i].getUID() == id)
return i;
}
return -1;
}
return -1;
}
void waitForA()
{
while(true)
{
hidScanInput();
void waitForA()
{
while(true)
{
hidScanInput();
uint64_t down = hidKeysDown(CONTROLLER_P1_AUTO);
uint64_t down = hidKeysDown(CONTROLLER_P1_AUTO);
if(down & KEY_A)
break;
if(down & KEY_A)
break;
gfxFlushBuffers();
gfxSwapBuffers();
gfxWaitForVsync();
}
}
gfxFlushBuffers();
gfxSwapBuffers();
gfxWaitForVsync();
}
}
void loadDataInfo()
{
Result res = 0;
FsSaveDataIterator saveIt;
size_t total = 0;
FsSaveDataInfo info;
void loadDataInfo()
{
Result res = 0;
FsSaveDataIterator saveIt;
size_t total = 0;
FsSaveDataInfo info;
res = fsOpenSaveDataIterator(&saveIt, FsSaveDataSpaceId_All);
if(R_FAILED(res))
{
printf("SaveDataIterator Failed\n");
return;
}
res = fsOpenSaveDataIterator(&saveIt, FsSaveDataSpaceId_All);
if(R_FAILED(res))
{
printf("SaveDataIterator Failed\n");
return;
}
while(true)
{
res = fsSaveDataIteratorRead(&saveIt, &info, 1, &total);
if(R_FAILED(res) || total == 0)
break;
while(true)
{
res = fsSaveDataIteratorRead(&saveIt, &info, 1, &total);
if(R_FAILED(res) || total == 0)
break;
if(info.SaveDataType == FsSaveDataType_SaveData)
{
int u = getUserIndex(info.userID);
if(u == -1)
{
user newUser;
if(newUser.init(info.userID))
{
users.push_back(newUser);
if(info.SaveDataType == FsSaveDataType_SaveData)
{
int u = getUserIndex(info.userID);
if(u == -1)
{
user newUser;
if(newUser.init(info.userID))
{
users.push_back(newUser);
u = getUserIndex(info.userID);
titledata newData;
if(newData.init(info.titleID, info.userID))
users[u].titles.push_back(newData);
}
}
else
{
titledata newData;
if(newData.init(info.titleID, info.userID))
{
users[u].titles.push_back(newData);
}
}
}
}
u = getUserIndex(info.userID);
titledata newData;
if(newData.init(info.titleID, info.userID))
users[u].titles.push_back(newData);
}
}
else
{
titledata newData;
if(newData.init(info.titleID, info.userID))
{
users[u].titles.push_back(newData);
}
}
}
}
fsSaveDataIteratorClose(&saveIt);
fsSaveDataIteratorClose(&saveIt);
for(unsigned i = 0; i < users.size(); i++)
std::sort(users[i].titles.begin(), users[i].titles.end(), sortTitles);
for(unsigned i = 0; i < users.size(); i++)
std::sort(users[i].titles.begin(), users[i].titles.end(), sortTitles);
}
}
bool titledata::init(const uint64_t& _id, const u128& _uID)
{
Result res = 0;
NsApplicationControlData *dat = new NsApplicationControlData;
std::memset(dat, 0, sizeof(NsApplicationControlData));
NacpLanguageEntry *ent = NULL;
bool titledata::init(const uint64_t& _id, const u128& _uID)
{
Result res = 0;
NsApplicationControlData *dat = new NsApplicationControlData;
std::memset(dat, 0, sizeof(NsApplicationControlData));
NacpLanguageEntry *ent = NULL;
id = _id;
uID = _uID;
size_t outSz = 0;
id = _id;
uID = _uID;
size_t outSz = 0;
res = nsGetApplicationControlData(1, _id, dat, sizeof(NsApplicationControlData), &outSz);
if(R_FAILED(res) && outSz < sizeof(dat->nacp))
{
printf("nsGetAppCtrlData Failed\n");
delete dat;
}
res = nsGetApplicationControlData(1, _id, dat, sizeof(NsApplicationControlData), &outSz);
if(R_FAILED(res) && outSz < sizeof(dat->nacp))
{
printf("nsGetAppCtrlData Failed\n");
delete dat;
}
if(R_SUCCEEDED(res))
{
res = nacpGetLanguageEntry(&dat->nacp, &ent);
if(R_FAILED(res) || ent == NULL)
{
printf("nacpGetLanguageEntry Failed\n");
delete dat;
}
}
if(R_SUCCEEDED(res))
{
res = nacpGetLanguageEntry(&dat->nacp, &ent);
if(R_FAILED(res) || ent == NULL)
{
printf("nacpGetLanguageEntry Failed\n");
delete dat;
}
}
if(R_SUCCEEDED(res))
{
title.assign(ent->name);
titleSafe = safeString(ent->name);
delete dat;
}
else
{
char tmp[32];
sprintf(tmp, "%016lX", id);
title.assign(tmp);
titleSafe = safeString(tmp);
}
if(R_SUCCEEDED(res))
{
title.assign(ent->name);
titleSafe = safeString(ent->name);
delete dat;
}
else
{
char tmp[32];
sprintf(tmp, "%016lX", id);
title.assign(tmp);
titleSafe = safeString(tmp);
}
return true;
}
return true;
}
const std::string titledata::getTitle()
{
return title;
}
std::string titledata::getTitle()
{
return title;
}
const std::string titledata::getTitleSafe()
{
return titleSafe;
}
std::string titledata::getTitleSafe()
{
return titleSafe;
}
const uint64_t titledata::getID()
{
return id;
}
uint64_t titledata::getID()
{
return id;
}
bool user::init(const u128& _id)
{
Result res = 0;
userID = _id;
bool user::init(const u128& _id)
{
Result res = 0;
userID = _id;
AccountProfile prof;
AccountProfileBase base;
AccountProfile prof;
AccountProfileBase base;
res = accountGetProfile(&prof, userID);
if(R_FAILED(res))
return false;
res = accountGetProfile(&prof, userID);
if(R_FAILED(res))
return false;
res = accountProfileGet(&prof, NULL, &base);
if(R_FAILED(res))
return false;
res = accountProfileGet(&prof, NULL, &base);
if(R_FAILED(res))
return false;
username.assign(base.username);
if(username.empty())
username = "???";
username.assign(base.username);
if(username.empty())
username = "???";
accountProfileClose(&prof);
accountProfileClose(&prof);
return true;
}
return true;
}
const u128 user::getUID()
{
return userID;
}
u128 user::getUID()
{
return userID;
}
const std::string user::getUsername()
{
return username;
}
std::string user::getUsername()
{
return username;
}
}

View File

@ -12,223 +12,223 @@
namespace fs
{
bool mountSave(data::user& usr, data::titledata& open)
{
FsFileSystem sv;
Result res = 0;
bool mountSave(data::user& usr, data::titledata& open)
{
FsFileSystem sv;
Result res = 0;
res = fsMount_SaveData(&sv, open.getID(), usr.getUID());
if(R_FAILED(res))
return false;
res = fsMount_SaveData(&sv, open.getID(), usr.getUID());
if(R_FAILED(res))
return false;
int r = fsdevMountDevice("sv", sv);
if(r == -1)
return false;
int r = fsdevMountDevice("sv", sv);
if(r == -1)
return false;
return true;
}
return true;
}
dirList::dirList(const std::string& _path)
{
path = _path;
d = opendir(path.c_str());
dirList::dirList(const std::string& _path)
{
path = _path;
d = opendir(path.c_str());
while((ent = readdir(d)))
{
item.push_back(ent->d_name);
}
while((ent = readdir(d)))
{
item.push_back(ent->d_name);
}
closedir(d);
}
closedir(d);
}
void dirList::rescan()
{
item.clear();
d = opendir(path.c_str());
void dirList::rescan()
{
item.clear();
d = opendir(path.c_str());
while((ent = readdir(d)))
{
item.push_back(ent->d_name);
}
while((ent = readdir(d)))
{
item.push_back(ent->d_name);
}
closedir(d);
}
closedir(d);
}
const std::string dirList::getItem(int index)
{
return item[index];
}
std::string dirList::getItem(int index)
{
return item[index];
}
bool dirList::isDir(int index)
{
std::string fullPath = path + item[index];
struct stat s;
if(stat(fullPath.c_str(), &s) == 0)
{
if(S_ISDIR(s.st_mode))
return true;
}
bool dirList::isDir(int index)
{
std::string fullPath = path + item[index];
struct stat s;
if(stat(fullPath.c_str(), &s) == 0)
{
if(S_ISDIR(s.st_mode))
return true;
}
return false;
}
return false;
}
unsigned dirList::getCount()
{
return item.size();
}
unsigned dirList::getCount()
{
return item.size();
}
void copyFile(const std::string& from, const std::string& to)
{
std::fstream f(from, std::ios::in | std::ios::binary);
std::fstream t(to, std::ios::out | std::ios::binary);
void copyFile(const std::string& from, const std::string& to)
{
std::fstream f(from, std::ios::in | std::ios::binary);
std::fstream t(to, std::ios::out | std::ios::binary);
f.seekg(0, f.end);
uint64_t fileSize = f.tellg();
f.seekg(0, f.beg);
f.seekg(0, f.end);
uint64_t fileSize = f.tellg();
f.seekg(0, f.beg);
uint8_t *buff = new uint8_t[BUFF_SIZE];
ui::progBar prog(fileSize);
uint8_t *buff = new uint8_t[BUFF_SIZE];
ui::progBar prog(fileSize);
std::string copyString = "Copying " + from + "...";
for(unsigned i = 0; i < fileSize; )
{
hidScanInput();
std::string copyString = "Copying " + from + "...";
for(unsigned i = 0; i < fileSize; )
{
hidScanInput();
uint64_t held = hidKeysHeld(CONTROLLER_P1_AUTO);
uint64_t held = hidKeysHeld(CONTROLLER_P1_AUTO);
if(held & KEY_B)
break;
if(held & KEY_B)
break;
f.read((char *)buff, BUFF_SIZE);
t.write((char *)buff, f.gcount());
f.read((char *)buff, BUFF_SIZE);
t.write((char *)buff, f.gcount());
i += f.gcount();
prog.update(i);
i += f.gcount();
prog.update(i);
prog.draw(copyString);
prog.draw(copyString);
gfx::handleBuffs();
}
gfx::handleBuffs();
}
delete[] buff;
delete[] buff;
f.close();
t.close();
}
f.close();
t.close();
}
void copyFileCommit(const std::string& from, const std::string& to, const std::string& dev)
{
std::fstream f(from, std::ios::in | std::ios::binary);
std::fstream t(to, std::ios::out | std::ios::binary);
void copyFileCommit(const std::string& from, const std::string& to, const std::string& dev)
{
std::fstream f(from, std::ios::in | std::ios::binary);
std::fstream t(to, std::ios::out | std::ios::binary);
f.seekg(0, f.end);
uint64_t fileSize = f.tellg();
f.seekg(0, f.beg);
f.seekg(0, f.end);
uint64_t fileSize = f.tellg();
f.seekg(0, f.beg);
uint8_t *buff = new uint8_t[BUFF_SIZE];
ui::progBar prog(fileSize);
uint8_t *buff = new uint8_t[BUFF_SIZE];
ui::progBar prog(fileSize);
std::string copyString = "Copying " + from + "...";
for(unsigned i = 0; i < fileSize; )
{
hidScanInput();
std::string copyString = "Copying " + from + "...";
for(unsigned i = 0; i < fileSize; )
{
hidScanInput();
uint64_t held = hidKeysHeld(CONTROLLER_P1_AUTO);
uint64_t held = hidKeysHeld(CONTROLLER_P1_AUTO);
if(held & KEY_B)
break;
if(held & KEY_B)
break;
f.read((char *)buff, BUFF_SIZE);
t.write((char *)buff, f.gcount());
f.read((char *)buff, BUFF_SIZE);
t.write((char *)buff, f.gcount());
i += f.gcount();
prog.update(i);
i += f.gcount();
prog.update(i);
prog.draw(copyString);
prog.draw(copyString);
gfx::handleBuffs();
}
gfx::handleBuffs();
}
delete[] buff;
delete[] buff;
f.close();
t.close();
f.close();
t.close();
Result res = fsdevCommitDevice(dev.c_str());
if(R_FAILED(res))
ui::showError("Error committing file to device", res);
}
Result res = fsdevCommitDevice(dev.c_str());
if(R_FAILED(res))
ui::showError("Error committing file to device", res);
}
void copyDirToDir(const std::string& from, const std::string& to)
{
dirList list(from);
void copyDirToDir(const std::string& from, const std::string& to)
{
dirList list(from);
for(unsigned i = 0; i < list.getCount(); i++)
{
if(list.isDir(i))
{
std::string newFrom = from + list.getItem(i) + "/";
std::string newTo = to + list.getItem(i);
mkdir(newTo.c_str(), 0777);
newTo += "/";
for(unsigned i = 0; i < list.getCount(); i++)
{
if(list.isDir(i))
{
std::string newFrom = from + list.getItem(i) + "/";
std::string newTo = to + list.getItem(i);
mkdir(newTo.c_str(), 0777);
newTo += "/";
copyDirToDir(newFrom, newTo);
}
else
{
std::string fullFrom = from + list.getItem(i);
std::string fullTo = to + list.getItem(i);
copyDirToDir(newFrom, newTo);
}
else
{
std::string fullFrom = from + list.getItem(i);
std::string fullTo = to + list.getItem(i);
copyFile(fullFrom, fullTo);
}
}
}
copyFile(fullFrom, fullTo);
}
}
}
void copyDirToDirCommit(const std::string& from, const std::string& to, const std::string& dev)
{
dirList list(from);
void copyDirToDirCommit(const std::string& from, const std::string& to, const std::string& dev)
{
dirList list(from);
for(unsigned i = 0; i < list.getCount(); i++)
{
if(list.isDir(i))
{
std::string newFrom = from + list.getItem(i) + "/";
std::string newTo = to + list.getItem(i);
mkdir(newTo.c_str(), 0777);
newTo += "/";
for(unsigned i = 0; i < list.getCount(); i++)
{
if(list.isDir(i))
{
std::string newFrom = from + list.getItem(i) + "/";
std::string newTo = to + list.getItem(i);
mkdir(newTo.c_str(), 0777);
newTo += "/";
copyDirToDirCommit(newFrom, newTo, dev);
}
else
{
std::string fullFrom = from + list.getItem(i);
std::string fullTo = to + list.getItem(i);
copyDirToDirCommit(newFrom, newTo, dev);
}
else
{
std::string fullFrom = from + list.getItem(i);
std::string fullTo = to + list.getItem(i);
copyFileCommit(fullFrom, fullTo, dev);
}
}
}
copyFileCommit(fullFrom, fullTo, dev);
}
}
}
void delDir(const std::string& path)
{
dirList list(path);
for(unsigned i = 0; i < list.getCount(); i++)
{
if(list.isDir(i))
{
std::string newPath = path + "/" + list.getItem(i) + "/";
delDir(newPath);
void delDir(const std::string& path)
{
dirList list(path);
for(unsigned i = 0; i < list.getCount(); i++)
{
if(list.isDir(i))
{
std::string newPath = path + "/" + list.getItem(i) + "/";
delDir(newPath);
std::string delPath = path + list.getItem(i);
rmdir(delPath.c_str());
}
else
{
std::string delPath = path + list.getItem(i);
std::remove(delPath.c_str());
}
}
std::string delPath = path + list.getItem(i);
rmdir(delPath.c_str());
}
else
{
std::string delPath = path + list.getItem(i);
std::remove(delPath.c_str());
}
}
rmdir(path.c_str());
}
rmdir(path.c_str());
}
}

View File

@ -19,230 +19,230 @@ static uint32_t fontSize = 0;
namespace gfx
{
bool init(const uint32_t& _fontSize)
{
Result res = 0;
bool init(const uint32_t& _fontSize)
{
Result res = 0;
gfxInitDefault();
consoleInit(NULL);
gfxInitDefault();
consoleInit(NULL);
PlFontData font;
PlFontData font;
res = plInitialize();
if(R_FAILED(res))
{
printf("plInitialize failed.");
return false;
}
res = plInitialize();
if(R_FAILED(res))
{
printf("plInitialize failed.");
return false;
}
res = plGetSharedFontByType(&font, PlSharedFontType_Standard);
if(R_FAILED(res))
{
printf("plGetSharedFontByTypeFailed!");
return false;
}
res = plGetSharedFontByType(&font, PlSharedFontType_Standard);
if(R_FAILED(res))
{
printf("plGetSharedFontByTypeFailed!");
return false;
}
ret = FT_Init_FreeType(&lib);
libret = ret;
if(ret)
{
printf("FT_Init_FreeType() failed: %d", ret);
return false;
}
ret = FT_Init_FreeType(&lib);
libret = ret;
if(ret)
{
printf("FT_Init_FreeType() failed: %d", ret);
return false;
}
ret = FT_New_Memory_Face(lib, (FT_Byte *)font.address, font.size, 0, &face);
faceret = ret;
if(ret)
{
printf("FT_New_Memory_Face failed: %d", ret);
return false;
}
ret = FT_New_Memory_Face(lib, (FT_Byte *)font.address, font.size, 0, &face);
faceret = ret;
if(ret)
{
printf("FT_New_Memory_Face failed: %d", ret);
return false;
}
ret = FT_Set_Char_Size(face, 0, 8 * _fontSize, 300, 300);
if(ret)
{
printf("FT_Set_Char_Size failed: %d", ret);
return false;
}
ret = FT_Set_Char_Size(face, 0, 8 * _fontSize, 300, 300);
if(ret)
{
printf("FT_Set_Char_Size failed: %d", ret);
return false;
}
fontSize = _fontSize;
fontSize = _fontSize;
return true;
}
return true;
}
bool fini()
{
if(faceret == 0)
FT_Done_Face(face);
if(libret == 0)
FT_Done_FreeType(lib);
bool fini()
{
if(faceret == 0)
FT_Done_Face(face);
if(libret == 0)
FT_Done_FreeType(lib);
plExit();
gfxExit();
plExit();
gfxExit();
return true;
}
return true;
}
void switchMode()
{
gfxSetMode(GfxMode_LinearDouble);
}
void switchMode()
{
gfxSetMode(GfxMode_LinearDouble);
}
void handleBuffs()
{
gfxFlushBuffers();
gfxSwapBuffers();
gfxWaitForVsync();
}
void handleBuffs()
{
gfxFlushBuffers();
gfxSwapBuffers();
gfxWaitForVsync();
}
void drawGlyph(FT_Bitmap& bmp, uint32_t *frameBuf, unsigned x, unsigned y, const uint32_t& clr)
{
uint32_t frameX, frameY, tmpX, tmpY;
uint8_t *imgPtr = bmp.buffer;
void drawGlyph(FT_Bitmap& bmp, uint32_t *frameBuf, unsigned x, unsigned y, const uint32_t& clr)
{
uint32_t frameX, frameY, tmpX, tmpY;
uint8_t *imgPtr = bmp.buffer;
if(bmp.pixel_mode != FT_PIXEL_MODE_GRAY)
return;
uint8_t r, g, b;
r = clr >> 24 & 0xFF;
g = clr >> 16 & 0xFF;
b = clr >> 8 & 0xFF;
if(bmp.pixel_mode != FT_PIXEL_MODE_GRAY)
return;
uint8_t r, g, b;
r = clr >> 24 & 0xFF;
g = clr >> 16 & 0xFF;
b = clr >> 8 & 0xFF;
for(tmpY = 0; tmpY < bmp.rows; tmpY++)
{
for(tmpX = 0; tmpX < bmp.width; tmpX++)
{
frameX = x + tmpX;
frameY = y + tmpY;
for(tmpY = 0; tmpY < bmp.rows; tmpY++)
{
for(tmpX = 0; tmpX < bmp.width; tmpX++)
{
frameX = x + tmpX;
frameY = y + tmpY;
if(imgPtr[tmpX] > 0)
{
frameBuf[frameY * frameBufWidth + frameX] = RGBA8_MAXALPHA(r, g, b);
}
}
if(imgPtr[tmpX] > 0)
{
frameBuf[frameY * frameBufWidth + frameX] = RGBA8_MAXALPHA(r, g, b);
}
}
imgPtr += bmp.pitch;
}
}
imgPtr += bmp.pitch;
}
}
void drawText(const std::string& str, unsigned x, unsigned y, const uint32_t& sz, const uint32_t& clr)
{
y = y + 27;
uint32_t tmpX = x;
FT_Error ret = 0;
FT_UInt glyphIndex;
FT_GlyphSlot slot = face->glyph;
uint32_t tmpChr;
ssize_t unitCount = 0;
void drawText(const std::string& str, unsigned x, unsigned y, const uint32_t& sz, const uint32_t& clr)
{
y = y + 27;
uint32_t tmpX = x;
FT_Error ret = 0;
FT_UInt glyphIndex;
FT_GlyphSlot slot = face->glyph;
uint32_t tmpChr;
ssize_t unitCount = 0;
FT_Set_Char_Size(face, 0, 8 * sz, 300, 300);
FT_Set_Char_Size(face, 0, 8 * sz, 300, 300);
uint32_t *frameBuffer = (uint32_t *)gfxGetFramebuffer(&frameBufWidth, NULL);
uint32_t *frameBuffer = (uint32_t *)gfxGetFramebuffer(&frameBufWidth, NULL);
uint8_t tmpStr[512];
sprintf((char *)tmpStr, "%s", str.c_str());
uint8_t tmpStr[512];
sprintf((char *)tmpStr, "%s", str.c_str());
for(unsigned i = 0; i < str.length(); )
{
unitCount = decode_utf8(&tmpChr, &tmpStr[i]);
if(unitCount <= 0)
break;
for(unsigned i = 0; i < str.length(); )
{
unitCount = decode_utf8(&tmpChr, &tmpStr[i]);
if(unitCount <= 0)
break;
i += unitCount;
if(tmpChr == '\n')
{
tmpX = x;
y += face->size->metrics.height / fontSize;
continue;
}
i += unitCount;
if(tmpChr == '\n')
{
tmpX = x;
y += face->size->metrics.height / fontSize;
continue;
}
glyphIndex = FT_Get_Char_Index(face, tmpChr);
ret = FT_Load_Glyph(face, glyphIndex, FT_LOAD_DEFAULT);
if(ret == 0)
{
ret = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL);
}
glyphIndex = FT_Get_Char_Index(face, tmpChr);
ret = FT_Load_Glyph(face, glyphIndex, FT_LOAD_DEFAULT);
if(ret == 0)
{
ret = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL);
}
if(ret)
return;
if(ret)
return;
drawGlyph(slot->bitmap, frameBuffer, tmpX + slot->bitmap_left, y - slot->bitmap_top, clr);
tmpX += slot->advance.x >> 6;
y += slot->advance.y >> 6;
}
}
drawGlyph(slot->bitmap, frameBuffer, tmpX + slot->bitmap_left, y - slot->bitmap_top, clr);
tmpX += slot->advance.x >> 6;
y += slot->advance.y >> 6;
}
}
void clearConsoleColor(const uint32_t& clr)
{
uint8_t r, g, b;
r = clr >> 24 & 0xFF;
g = clr >> 16 & 0xFF;
b = clr >> 8 & 0xFF;
void clearConsoleColor(const uint32_t& clr)
{
uint8_t r, g, b;
r = clr >> 24 & 0xFF;
g = clr >> 16 & 0xFF;
b = clr >> 8 & 0xFF;
size_t fbSize = gfxGetFramebufferSize() / 4;
uint32_t *fb = (uint32_t *)gfxGetFramebuffer(NULL, NULL);
size_t fbSize = gfxGetFramebufferSize() / 4;
uint32_t *fb = (uint32_t *)gfxGetFramebuffer(NULL, NULL);
for(unsigned i = 0; i < fbSize; i++)
{
fb[i] = RGBA8_MAXALPHA(r, g, b);
}
}
for(unsigned i = 0; i < fbSize; i++)
{
fb[i] = RGBA8_MAXALPHA(r, g, b);
}
}
void drawRectangle(uint32_t x, uint32_t y, const uint32_t& width, const uint32_t& height, const uint32_t& clr)
{
uint32_t w, h, tX, tY;
uint32_t *frameBuffer = (uint32_t *)gfxGetFramebuffer(&w, &h);
void drawRectangle(uint32_t x, uint32_t y, const uint32_t& width, const uint32_t& height, const uint32_t& clr)
{
uint32_t w, h, tX, tY;
uint32_t *frameBuffer = (uint32_t *)gfxGetFramebuffer(&w, &h);
uint8_t r, g, b;
r = clr >> 24 & 0xFF;
g = clr >> 16 & 0xFF;
b = clr >> 8 & 0xFF;
uint8_t r, g, b;
r = clr >> 24 & 0xFF;
g = clr >> 16 & 0xFF;
b = clr >> 8 & 0xFF;
for(tY = y; tY < y + height; tY++)
{
for(tX = x; tX < x + width; tX++)
{
frameBuffer[tY * w + tX] = RGBA8_MAXALPHA(r, g, b);
}
}
}
for(tY = y; tY < y + height; tY++)
{
for(tX = x; tX < x + width; tX++)
{
frameBuffer[tY * w + tX] = RGBA8_MAXALPHA(r, g, b);
}
}
}
void tex::loadFromFile(const std::string& path)
{
std::fstream dataIn(path, std::ios::in | std::ios::binary);
if(dataIn.is_open())
{
dataIn.read((char *)&sz, sizeof(uint32_t));
dataIn.read((char *)&width, sizeof(uint16_t));
dataIn.read((char *)&height, sizeof(uint16_t));
void tex::loadFromFile(const std::string& path)
{
std::fstream dataIn(path, std::ios::in | std::ios::binary);
if(dataIn.is_open())
{
dataIn.read((char *)&sz, sizeof(uint32_t));
dataIn.read((char *)&width, sizeof(uint16_t));
dataIn.read((char *)&height, sizeof(uint16_t));
data = new uint8_t[sz];
if(data != NULL)
dataIn.read((char *)data, sz);
data = new uint8_t[sz];
if(data != NULL)
dataIn.read((char *)data, sz);
dataIn.close();
}
}
dataIn.close();
}
}
tex::~tex()
{
if(data != NULL)
delete[] data;
}
tex::~tex()
{
if(data != NULL)
delete[] data;
}
void tex::draw(uint32_t x, uint32_t y)
{
if(data != NULL)
{
uint32_t tY, tX, i = 0;
uint32_t *frameBuffer = (uint32_t *)gfxGetFramebuffer(NULL, NULL);
void tex::draw(uint32_t x, uint32_t y)
{
if(data != NULL)
{
uint32_t tY, tX, i = 0;
uint32_t *frameBuffer = (uint32_t *)gfxGetFramebuffer(NULL, NULL);
for(tY = y; tY < y + height; tY++)
{
for(tX = x; tX < x + width; tX++, i += 4)
{
frameBuffer[tY * frameBufWidth + tX] = RGBA8_MAXALPHA(data[i], data[i + 1], data[i + 2]);
}
}
}
}
for(tY = y; tY < y + height; tY++)
{
for(tX = x; tX < x + width; tX++, i += 4)
{
frameBuffer[tY * frameBufWidth + tX] = RGBA8_MAXALPHA(data[i], data[i + 1], data[i + 2]);
}
}
}
}
}

View File

@ -17,15 +17,17 @@ int main(int argc, const char *argv[])
bool init = false;
init = gfx::init(64);
if(init) init = sys::init();
if(init) init = data::init();
if(init)
init = sys::init();
if(init)
init = data::init();
if(init)
{
data::loadDataInfo();
gfx::switchMode();
ui::init();
ui::userMenuInit();
ui::userMenuInit();
bool run = true;
while(appletMainLoop() && run)
@ -37,10 +39,10 @@ int main(int argc, const char *argv[])
touchPosition p;
hidTouchRead(&p, 0);
if(down & KEY_PLUS)
break;
if(down & KEY_PLUS)
break;
gfx::clearConsoleColor(0x3B3B3BFF);
gfx::clearConsoleColor(0x3B3B3BFF);
gfx::drawText("JKSV - 6/10/2018", 16, 16, 64, 0xFFFFFFFF);
gfx::drawRectangle(16, 64, 1248, 2, 0xFFFFFFFF);
gfx::drawRectangle(384, 64, 2, 592, 0xFFFFFFFF);
@ -52,21 +54,21 @@ int main(int argc, const char *argv[])
}
}
else
{
while(appletMainLoop())
{
hidScanInput();
{
while(appletMainLoop())
{
hidScanInput();
uint64_t down = hidKeysDown(CONTROLLER_P1_AUTO);
uint64_t down = hidKeysDown(CONTROLLER_P1_AUTO);
if(down & KEY_PLUS)
break;
if(down & KEY_PLUS)
break;
gfx::handleBuffs();
}
}
gfx::handleBuffs();
}
}
gfx::fini();
sys::fini();
data::fini();
gfx::fini();
sys::fini();
data::fini();
}

View File

@ -9,58 +9,58 @@ static std::fstream deb;
namespace sys
{
bool init()
{
Result res = 0;
res = fsdevMountSdmc();
if(R_FAILED(res))
{
printf("MountSdmc failed\n");
return false;
}
bool init()
{
Result res = 0;
res = fsdevMountSdmc();
if(R_FAILED(res))
{
printf("MountSdmc failed\n");
return false;
}
res = romfsInit();
if(R_FAILED(res))
{
printf("romfsInit failed\n");
return false;
}
res = romfsInit();
if(R_FAILED(res))
{
printf("romfsInit failed\n");
return false;
}
res = hidInitialize();
if(R_FAILED(res))
{
printf("hidInit failed\n");
return false;
}
res = hidInitialize();
if(R_FAILED(res))
{
printf("hidInit failed\n");
return false;
}
res = nsInitialize();
if(R_FAILED(res))
{
printf("nsInit failed\n");
return false;
}
res = nsInitialize();
if(R_FAILED(res))
{
printf("nsInit failed\n");
return false;
}
mkdir("sdmc:/JKSV", 0777);
chdir("sdmc:/JKSV");
mkdir("sdmc:/JKSV", 0777);
chdir("sdmc:/JKSV");
deb.open("deb.txt", std::ios::out);
deb.open("deb.txt", std::ios::out);
return true;
}
return true;
}
bool fini()
{
deb.close();
fsdevUnmountAll();
romfsExit();
hidExit();
nsExit();
bool fini()
{
deb.close();
fsdevUnmountAll();
romfsExit();
hidExit();
nsExit();
return true;
}
return true;
}
void debugWrite(const std::string& out)
{
deb.write(out.c_str(), out.length());
}
void debugWrite(const std::string& out)
{
deb.write(out.c_str(), out.length());
}
}

View File

@ -12,10 +12,10 @@
static const char qwerty[] =
{
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p',
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', '_',
'z', 'x', 'c', 'v', 'b', 'n', 'm', '-', '@', '+'
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p',
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', '_',
'z', 'x', 'c', 'v', 'b', 'n', 'm', '-', '@', '+'
};
enum menuState
@ -39,7 +39,7 @@ namespace ui
menu::~menu()
{
opt.clear();
opt.clear();
}
void menu::handleInput(const uint64_t& down, const uint64_t& held)
@ -101,18 +101,18 @@ namespace ui
void menu::print(const unsigned& x, const unsigned& y, const uint32_t& rectWidth)
{
if(clrAdd)
{
clrSh++;
if(clrSh > 63)
clrAdd = false;
}
else
{
clrSh--;
if(clrSh == 0)
clrAdd = true;
}
if(clrAdd)
{
clrSh++;
if(clrSh > 63)
clrAdd = false;
}
else
{
clrSh--;
if(clrSh == 0)
clrAdd = true;
}
int length = 0;
if((opt.size() - 1) < 15)
@ -120,7 +120,7 @@ namespace ui
else
length = start + 15;
uint32_t rectClr = 0x00 << 24 | ((0x88 + clrSh) & 0xFF) << 16 | ((0xbb + clrSh) & 0xFF) << 8 | 0xFF;
uint32_t rectClr = 0x00 << 24 | ((0x88 + clrSh) & 0xFF) << 16 | ((0xbb + clrSh) & 0xFF) << 8 | 0xFF;
for(int i = start; i < length; i++)
{
@ -141,444 +141,444 @@ namespace ui
}
progBar::progBar(const uint32_t& _max)
{
max = (float)_max;
}
void progBar::update(const uint32_t& _prog)
{
prog = (float)_prog;
float percent = (float)(prog / max) * 100;
width = (float)(percent * 1088) / 100;
}
void progBar::draw(const std::string& text)
{
gfx::drawRectangle(64, 240, 1152, 240, 0xC0C0C0FF);
gfx::drawRectangle(96, 400, 1088, 64, 0x000000FF);
gfx::drawRectangle(96, 400, (uint32_t)width, 64, 0x00CC00FF);
char tmp[64];
sprintf(tmp, "%u / %u", (unsigned)prog, (unsigned)max);
gfx::drawText(text, 80, 256, 64, 0x000000FF);
gfx::drawText(tmp, 80, 320, 64, 0x000000FF);
}
key::key(const std::string& txt, const char& _let, const unsigned& _txtSz, const unsigned& _x, const unsigned& _y, const unsigned& _w, const unsigned& _h)
{
x = _x;
y = _y;
w = _w;
h = _h;
txtSz = _txtSz;
let = _let;
text = txt;
tX = x + 16;
tY = y + 16;
pressed = false;
}
void key::updateText(const std::string& txt)
{
text = txt;
}
void key::draw()
{
gfx::drawRectangle(x, y, w, h, 0x3B3B3BFF);
if(pressed)
gfx::drawRectangle(x + 1, y + 1, w - 1, h - 1, 0x2B2B2BFF);
else
gfx::drawRectangle(x + 1, y + 1, w - 1, h - 1, 0xC0C0C0FF);
gfx::drawText(text, tX, tY, txtSz, 0x000000FF);
}
bool key::isOver(const touchPosition& p)
{
return (p.px > x && p.px < x + w) && (p.py > y && p.py < y + h);
}
bool key::released(const touchPosition& p)
{
prev = p;
if(isOver(p))
pressed = true;
else
{
uint32_t touchCount = hidTouchCount();
if(pressed && touchCount == 0)
{
pressed = false;
return true;
}
else
pressed = false;
}
return false;
}
char key::getLet()
{
return let;
}
void key::toCaps()
{
let = toupper(let);
char tmp[8];
sprintf(tmp, "%c", let);
updateText(tmp);
}
void key::toLower()
{
let = tolower(let);
char tmp[2];
sprintf(tmp, "%c", let);
updateText(tmp);
}
keyboard::keyboard()
{
int x = 160, y = 256;
for(unsigned i = 0; i < 40; i++, x += 96)
{
char tmp[2];
sprintf(tmp, "%c", qwerty[i]);
key newKey(tmp, qwerty[i], 64, x, y, 80, 80);
keys.push_back(newKey);
char ch = qwerty[i];
if(ch == '0' || ch == 'p' || ch == '_')
{
x = 64;
y += 96;
}
}
//spc key
key shift("Shift", ' ', 64, 16, 544, 128, 80);
key space("Spc", ' ', 64, 240, 640, 800, 80);
key bckSpc("Back", ' ', 64, 1120, 256, 128, 80);
key enter("Entr", ' ', 64, 1120, 352, 128, 80);
key cancel("Cancel", ' ', 64, 1120, 448, 128, 80);
keys.push_back(space);
keys.push_back(shift);
keys.push_back(bckSpc);
keys.push_back(enter);
keys.push_back(cancel);
}
keyboard::~keyboard()
{
keys.clear();
}
void keyboard::draw()
{
gfx::drawRectangle(0, 176, 1280, 64, 0xFFFFFFFF);
gfx::drawRectangle(0, 240, 1280, 480, 0x3B3B3BFF);
for(unsigned i = 0; i < keys.size(); i++)
keys[i].draw();
gfx::drawText(str, 16, 192, 64, 0x000000FF);
}
const std::string keyboard::getString()
{
while(true)
{
hidScanInput();
uint64_t down = hidKeysDown(CONTROLLER_P1_AUTO);
if(down & KEY_R)
str += util::getDateTime();
touchPosition p;
hidTouchRead(&p, 0);
//Stndrd key
for(unsigned i = 0; i < 41; i++)
{
if(keys[i].released(p))
{
str += keys[i].getLet();
}
}
//shift
if(keys[41].released(p))
{
if(keys[10].getLet() == 'q')
{
for(unsigned i = 10; i < 41; i++)
keys[i].toCaps();
}
else
{
for(unsigned i = 10; i < 41; i++)
keys[i].toLower();
}
}
//bckspace
else if(keys[42].released(p))
{
if(!str.empty())
str.erase(str.end() - 1, str.end());
}
//enter
else if(keys[43].released(p) || down & KEY_PLUS)
break;
//cancel
else if(keys[44].released(p) || down & KEY_B)
{
str.erase(str.begin(), str.end());
break;
}
draw();
gfx::handleBuffs();
}
return str;
}
void init()
{
buttonA.loadFromFile("romfs:/img/buttonA.data");
buttonB.loadFromFile("romfs:/img/buttonB.data");
buttonX.loadFromFile("romfs:/img/buttonX.data");
buttonY.loadFromFile("romfs:/img/buttonY.data");
}
void userMenuInit()
{
for(unsigned i = 0; i < data::users.size(); i++)
userMenu.addOpt(data::users[i].getUsername());
}
void titleMenuPrepare(data::user& usr)
{
titleMenu.reset();
for(unsigned i = 0; i < usr.titles.size(); i++)
titleMenu.addOpt(usr.titles[i].getTitle());
}
void folderMenuPrepare(data::user& usr, data::titledata& dat)
{
folderMenu.reset();
util::makeTitleDir(usr, dat);
std::string scanPath = util::getTitleDir(usr, dat);
fs::dirList list(scanPath);
folderMenu.addOpt("New");
for(unsigned i = 0; i < list.getCount(); i++)
folderMenu.addOpt(list.getItem(i));
}
void showUserMenu(const uint64_t& down, const uint64_t& held)
{
userMenu.handleInput(down, held);
if(down & KEY_A)
{
data::curUser = data::users[userMenu.getSelected()];
mkdir(data::curUser.getUsername().c_str(), 777);
titleMenuPrepare(data::curUser);
mstate = TTL_SEL;
}
userMenu.print(16, 88, 364);
//I'm too lazy to add width calculation right now.
unsigned startX = 1152;
buttonA.draw(startX, 672);
gfx::drawText("Select", startX += 38, 668, 32, 0xFFFFFFFF);
}
void showTitleMenu(const uint64_t& down, const uint64_t& held)
{
titleMenu.handleInput(down, held);
if(down & KEY_A)
{
data::curData = data::curUser.titles[titleMenu.getSelected()];
if(fs::mountSave(data::curUser, data::curData))
{
util::makeTitleDir(data::curUser, data::curData);
folderMenuPrepare(data::curUser, data::curData);
mstate = FLD_SEL;
}
}
else if(down & KEY_B)
mstate = USR_SEL;
titleMenu.print(16, 88, 364);
unsigned startX = 1056;
buttonA.draw(startX, 672);
gfx::drawText("Select", startX += 38, 668, 32, 0xFFFFFFFF);
buttonB.draw(startX += 72, 672);
gfx::drawText("Back", startX += 38, 668, 32, 0xFFFFFFFF);
}
void showFolderMenu(const uint64_t& down, const uint64_t& held)
{
folderMenu.handleInput(down, held);
if(down & KEY_A)
{
if(folderMenu.getSelected() == 0)
{
ui::keyboard key;
std::string folder = key.getString();
if(!folder.empty())
{
std::string path = util::getTitleDir(data::curUser, data::curData) + "/" + folder;
mkdir(path.c_str(), 777);
path += "/";
std::string root = "sv:/";
fs::copyDirToDir(root, path);
folderMenuPrepare(data::curUser, data::curData);
}
}
else
{
std::string scanPath = util::getTitleDir(data::curUser, data::curData);
fs::dirList list(scanPath);
std::string toPath = util::getTitleDir(data::curUser, data::curData) + list.getItem(folderMenu.getSelected() - 1) + "/";
std::string root = "sv:/";
fs::copyDirToDir(root, toPath);
}
}
else if(down & KEY_Y)
{
if(folderMenu.getSelected() > 0)
{
fs::delDir("sv:/");
std::string scanPath = util::getTitleDir(data::curUser, data::curData);
fs::dirList list(scanPath);
std::string fromPath = util::getTitleDir(data::curUser, data::curData) + list.getItem(folderMenu.getSelected() - 1) + "/";
std::string root = "sv:/";
fs::copyDirToDirCommit(fromPath, root, "sv");
}
}
else if(down & KEY_X)
{
if(folderMenu.getSelected() > 0)
{
std::string scanPath = util::getTitleDir(data::curUser, data::curData);
fs::dirList list(scanPath);
std::string delPath = scanPath + list.getItem(folderMenu.getSelected() - 1) + "/";
fs::delDir(delPath);
folderMenuPrepare(data::curUser, data::curData);
}
}
else if(down & KEY_B)
{
fsdevUnmountDevice("sv");
mstate = TTL_SEL;
}
titleMenu.print(16, 88, 364);
folderMenu.print(390, 88, 874);
unsigned startX = 836;
buttonA.draw(startX, 672);
gfx::drawText("Backup", startX += 38, 668, 32, 0xFFFFFFFF);
buttonY.draw(startX += 72, 672);
gfx::drawText("Restore", startX += 38, 668, 32, 0xFFFFFFFF);
buttonX.draw(startX += 72, 672);
gfx::drawText("Delete", startX += 38, 668, 32, 0xFFFFFFFF);
buttonB.draw(startX += 72, 672);
gfx::drawText("Back", startX += 38, 668, 32, 0xFFFFFFFF);
}
void runApp(const uint64_t& down, const uint64_t& held)
{
switch(mstate)
{
case USR_SEL:
showUserMenu(down, held);
break;
case TTL_SEL:
showTitleMenu(down, held);
break;
case FLD_SEL:
showFolderMenu(down, held);
break;
}
}
void showMessage(const std::string& mess)
{
while(true)
{
hidScanInput();
uint64_t down = hidKeysDown(CONTROLLER_P1_AUTO);
if(down & KEY_A || down & KEY_B)
break;
gfx::drawRectangle(128, 128, 1024, 464, 0xC0C0C0FF);
gfx::drawText(mess, 144, 144, 32, 0x000000FF);
gfx::handleBuffs();
}
}
void showError(const std::string& mess, const Result& r)
{
char tmp[512];
sprintf(tmp, "%s\n0x%08X", mess.c_str(), (unsigned)r);
while(true)
{
hidScanInput();
uint64_t down = hidKeysDown(CONTROLLER_P1_AUTO);
if(down & KEY_A || down & KEY_B)
break;
gfx::drawRectangle(128, 128, 1024, 464, 0xC0C0C0FF);
gfx::drawText(tmp, 144, 144, 32, 0x000000FF);
gfx::handleBuffs();
}
}
{
max = (float)_max;
}
void progBar::update(const uint32_t& _prog)
{
prog = (float)_prog;
float percent = (float)(prog / max) * 100;
width = (float)(percent * 1088) / 100;
}
void progBar::draw(const std::string& text)
{
gfx::drawRectangle(64, 240, 1152, 240, 0xC0C0C0FF);
gfx::drawRectangle(96, 400, 1088, 64, 0x000000FF);
gfx::drawRectangle(96, 400, (uint32_t)width, 64, 0x00CC00FF);
char tmp[64];
sprintf(tmp, "%u / %u", (unsigned)prog, (unsigned)max);
gfx::drawText(text, 80, 256, 64, 0x000000FF);
gfx::drawText(tmp, 80, 320, 64, 0x000000FF);
}
key::key(const std::string& txt, const char& _let, const unsigned& _txtSz, const unsigned& _x, const unsigned& _y, const unsigned& _w, const unsigned& _h)
{
x = _x;
y = _y;
w = _w;
h = _h;
txtSz = _txtSz;
let = _let;
text = txt;
tX = x + 16;
tY = y + 16;
pressed = false;
}
void key::updateText(const std::string& txt)
{
text = txt;
}
void key::draw()
{
gfx::drawRectangle(x, y, w, h, 0x3B3B3BFF);
if(pressed)
gfx::drawRectangle(x + 1, y + 1, w - 1, h - 1, 0x2B2B2BFF);
else
gfx::drawRectangle(x + 1, y + 1, w - 1, h - 1, 0xC0C0C0FF);
gfx::drawText(text, tX, tY, txtSz, 0x000000FF);
}
bool key::isOver(const touchPosition& p)
{
return (p.px > x && p.px < x + w) && (p.py > y && p.py < y + h);
}
bool key::released(const touchPosition& p)
{
prev = p;
if(isOver(p))
pressed = true;
else
{
uint32_t touchCount = hidTouchCount();
if(pressed && touchCount == 0)
{
pressed = false;
return true;
}
else
pressed = false;
}
return false;
}
char key::getLet()
{
return let;
}
void key::toCaps()
{
let = toupper(let);
char tmp[8];
sprintf(tmp, "%c", let);
updateText(tmp);
}
void key::toLower()
{
let = tolower(let);
char tmp[2];
sprintf(tmp, "%c", let);
updateText(tmp);
}
keyboard::keyboard()
{
int x = 160, y = 256;
for(unsigned i = 0; i < 40; i++, x += 96)
{
char tmp[2];
sprintf(tmp, "%c", qwerty[i]);
key newKey(tmp, qwerty[i], 64, x, y, 80, 80);
keys.push_back(newKey);
char ch = qwerty[i];
if(ch == '0' || ch == 'p' || ch == '_')
{
x = 64;
y += 96;
}
}
//spc key
key shift("Shift", ' ', 64, 16, 544, 128, 80);
key space("Spc", ' ', 64, 240, 640, 800, 80);
key bckSpc("Back", ' ', 64, 1120, 256, 128, 80);
key enter("Entr", ' ', 64, 1120, 352, 128, 80);
key cancel("Cancel", ' ', 64, 1120, 448, 128, 80);
keys.push_back(space);
keys.push_back(shift);
keys.push_back(bckSpc);
keys.push_back(enter);
keys.push_back(cancel);
}
keyboard::~keyboard()
{
keys.clear();
}
void keyboard::draw()
{
gfx::drawRectangle(0, 176, 1280, 64, 0xFFFFFFFF);
gfx::drawRectangle(0, 240, 1280, 480, 0x3B3B3BFF);
for(unsigned i = 0; i < keys.size(); i++)
keys[i].draw();
gfx::drawText(str, 16, 192, 64, 0x000000FF);
}
std::string keyboard::getString()
{
while(true)
{
hidScanInput();
uint64_t down = hidKeysDown(CONTROLLER_P1_AUTO);
if(down & KEY_R)
str += util::getDateTime();
touchPosition p;
hidTouchRead(&p, 0);
//Stndrd key
for(unsigned i = 0; i < 41; i++)
{
if(keys[i].released(p))
{
str += keys[i].getLet();
}
}
//shift
if(keys[41].released(p))
{
if(keys[10].getLet() == 'q')
{
for(unsigned i = 10; i < 41; i++)
keys[i].toCaps();
}
else
{
for(unsigned i = 10; i < 41; i++)
keys[i].toLower();
}
}
//bckspace
else if(keys[42].released(p))
{
if(!str.empty())
str.erase(str.end() - 1, str.end());
}
//enter
else if(keys[43].released(p) || down & KEY_PLUS)
break;
//cancel
else if(keys[44].released(p) || down & KEY_B)
{
str.erase(str.begin(), str.end());
break;
}
draw();
gfx::handleBuffs();
}
return str;
}
void init()
{
buttonA.loadFromFile("romfs:/img/buttonA.data");
buttonB.loadFromFile("romfs:/img/buttonB.data");
buttonX.loadFromFile("romfs:/img/buttonX.data");
buttonY.loadFromFile("romfs:/img/buttonY.data");
}
void userMenuInit()
{
for(unsigned i = 0; i < data::users.size(); i++)
userMenu.addOpt(data::users[i].getUsername());
}
void titleMenuPrepare(data::user& usr)
{
titleMenu.reset();
for(unsigned i = 0; i < usr.titles.size(); i++)
titleMenu.addOpt(usr.titles[i].getTitle());
}
void folderMenuPrepare(data::user& usr, data::titledata& dat)
{
folderMenu.reset();
util::makeTitleDir(usr, dat);
std::string scanPath = util::getTitleDir(usr, dat);
fs::dirList list(scanPath);
folderMenu.addOpt("New");
for(unsigned i = 0; i < list.getCount(); i++)
folderMenu.addOpt(list.getItem(i));
}
void showUserMenu(const uint64_t& down, const uint64_t& held)
{
userMenu.handleInput(down, held);
if(down & KEY_A)
{
data::curUser = data::users[userMenu.getSelected()];
mkdir(data::curUser.getUsername().c_str(), 777);
titleMenuPrepare(data::curUser);
mstate = TTL_SEL;
}
userMenu.print(16, 88, 364);
//I'm too lazy to add width calculation right now.
unsigned startX = 1152;
buttonA.draw(startX, 672);
gfx::drawText("Select", startX += 38, 668, 32, 0xFFFFFFFF);
}
void showTitleMenu(const uint64_t& down, const uint64_t& held)
{
titleMenu.handleInput(down, held);
if(down & KEY_A)
{
data::curData = data::curUser.titles[titleMenu.getSelected()];
if(fs::mountSave(data::curUser, data::curData))
{
util::makeTitleDir(data::curUser, data::curData);
folderMenuPrepare(data::curUser, data::curData);
mstate = FLD_SEL;
}
}
else if(down & KEY_B)
mstate = USR_SEL;
titleMenu.print(16, 88, 364);
unsigned startX = 1056;
buttonA.draw(startX, 672);
gfx::drawText("Select", startX += 38, 668, 32, 0xFFFFFFFF);
buttonB.draw(startX += 72, 672);
gfx::drawText("Back", startX += 38, 668, 32, 0xFFFFFFFF);
}
void showFolderMenu(const uint64_t& down, const uint64_t& held)
{
folderMenu.handleInput(down, held);
if(down & KEY_A)
{
if(folderMenu.getSelected() == 0)
{
ui::keyboard key;
std::string folder = key.getString();
if(!folder.empty())
{
std::string path = util::getTitleDir(data::curUser, data::curData) + "/" + folder;
mkdir(path.c_str(), 777);
path += "/";
std::string root = "sv:/";
fs::copyDirToDir(root, path);
folderMenuPrepare(data::curUser, data::curData);
}
}
else
{
std::string scanPath = util::getTitleDir(data::curUser, data::curData);
fs::dirList list(scanPath);
std::string toPath = util::getTitleDir(data::curUser, data::curData) + list.getItem(folderMenu.getSelected() - 1) + "/";
std::string root = "sv:/";
fs::copyDirToDir(root, toPath);
}
}
else if(down & KEY_Y)
{
if(folderMenu.getSelected() > 0)
{
fs::delDir("sv:/");
std::string scanPath = util::getTitleDir(data::curUser, data::curData);
fs::dirList list(scanPath);
std::string fromPath = util::getTitleDir(data::curUser, data::curData) + list.getItem(folderMenu.getSelected() - 1) + "/";
std::string root = "sv:/";
fs::copyDirToDirCommit(fromPath, root, "sv");
}
}
else if(down & KEY_X)
{
if(folderMenu.getSelected() > 0)
{
std::string scanPath = util::getTitleDir(data::curUser, data::curData);
fs::dirList list(scanPath);
std::string delPath = scanPath + list.getItem(folderMenu.getSelected() - 1) + "/";
fs::delDir(delPath);
folderMenuPrepare(data::curUser, data::curData);
}
}
else if(down & KEY_B)
{
fsdevUnmountDevice("sv");
mstate = TTL_SEL;
}
titleMenu.print(16, 88, 364);
folderMenu.print(390, 88, 874);
unsigned startX = 836;
buttonA.draw(startX, 672);
gfx::drawText("Backup", startX += 38, 668, 32, 0xFFFFFFFF);
buttonY.draw(startX += 72, 672);
gfx::drawText("Restore", startX += 38, 668, 32, 0xFFFFFFFF);
buttonX.draw(startX += 72, 672);
gfx::drawText("Delete", startX += 38, 668, 32, 0xFFFFFFFF);
buttonB.draw(startX += 72, 672);
gfx::drawText("Back", startX += 38, 668, 32, 0xFFFFFFFF);
}
void runApp(const uint64_t& down, const uint64_t& held)
{
switch(mstate)
{
case USR_SEL:
showUserMenu(down, held);
break;
case TTL_SEL:
showTitleMenu(down, held);
break;
case FLD_SEL:
showFolderMenu(down, held);
break;
}
}
void showMessage(const std::string& mess)
{
while(true)
{
hidScanInput();
uint64_t down = hidKeysDown(CONTROLLER_P1_AUTO);
if(down & KEY_A || down & KEY_B)
break;
gfx::drawRectangle(128, 128, 1024, 464, 0xC0C0C0FF);
gfx::drawText(mess, 144, 144, 32, 0x000000FF);
gfx::handleBuffs();
}
}
void showError(const std::string& mess, const Result& r)
{
char tmp[512];
sprintf(tmp, "%s\n0x%08X", mess.c_str(), (unsigned)r);
while(true)
{
hidScanInput();
uint64_t down = hidKeysDown(CONTROLLER_P1_AUTO);
if(down & KEY_A || down & KEY_B)
break;
gfx::drawRectangle(128, 128, 1024, 464, 0xC0C0C0FF);
gfx::drawText(tmp, 144, 144, 32, 0x000000FF);
gfx::handleBuffs();
}
}
}

View File

@ -7,27 +7,27 @@
namespace util
{
const std::string getDateTime()
{
char ret[48];
const std::string getDateTime()
{
char ret[48];
time_t raw;
time(&raw);
tm *Time = localtime(&raw);
time_t raw;
time(&raw);
tm *Time = localtime(&raw);
sprintf(ret, "%04d-%02d-%02d@%02d-%02d-%02d", Time->tm_year + 1900, Time->tm_mon + 1, Time->tm_mday, Time->tm_hour, Time->tm_min, Time->tm_sec);
sprintf(ret, "%04d-%02d-%02d@%02d-%02d-%02d", Time->tm_year + 1900, Time->tm_mon + 1, Time->tm_mday, Time->tm_hour, Time->tm_min, Time->tm_sec);
return std::string(ret);
}
return std::string(ret);
}
void makeTitleDir(data::user& u, data::titledata& t)
{
std::string path = u.getUsername() + "/" + t.getTitleSafe();
mkdir(path.c_str(), 777);
}
void makeTitleDir(data::user& u, data::titledata& t)
{
std::string path = u.getUsername() + "/" + t.getTitleSafe();
mkdir(path.c_str(), 777);
}
const std::string getTitleDir(data::user& u, data::titledata& t)
{
return std::string(u.getUsername() + "/" + t.getTitleSafe() + "/");
}
const std::string getTitleDir(data::user& u, data::titledata& t)
{
return std::string(u.getUsername() + "/" + t.getTitleSafe() + "/");
}
}