From 2ab16b9e04dbb5f2a4655b1bc324cc849cbff531 Mon Sep 17 00:00:00 2001 From: J-D-K Date: Thu, 23 Aug 2018 23:15:53 -0400 Subject: [PATCH] Minor stuff --- Makefile | 2 +- inc/data.h | 4 ++-- src/data.cpp | 12 ++++++++---- src/file.cpp | 13 ++----------- src/gfx.c | 49 +++++++++++++++++++++++++++++++---------------- src/main.cpp | 2 +- src/ui.cpp | 2 +- src/ui/clsui.cpp | 2 +- src/ui/menu.cpp | 2 ++ src/ui/miscui.cpp | 10 ++++++---- src/ui/ttlsel.cpp | 2 +- src/util.cpp | 18 ++++++++--------- 12 files changed, 66 insertions(+), 52 deletions(-) diff --git a/Makefile b/Makefile index 2d1a974..b03890c 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ INCLUDES := inc EXEFS_SRC := exefs_src APP_TITLE := JKSV APP_AUTHOR := JK_ -APP_VERSION := 08/15/2018 +APP_VERSION := 08/23/2018 ROMFS := romfs #--------------------------------------------------------------------------------- diff --git a/inc/data.h b/inc/data.h index 24ea6d4..286aa31 100644 --- a/inc/data.h +++ b/inc/data.h @@ -10,7 +10,7 @@ namespace data { - extern bool sysSave; + extern bool sysSave, forceMount; //Loads user + title info void loadDataInfo(); @@ -97,7 +97,7 @@ namespace data std::string username, userSafe; }; //Adds title to blacklist - void blacklistAdd(titledata& t); + void blacklistAdd(user& u, titledata& t); //User vector extern std::vector users; diff --git a/src/data.cpp b/src/data.cpp index b940853..11a195e 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -63,7 +63,7 @@ namespace data user curUser; std::vector icons; std::vector users; - bool sysSave = false; + bool sysSave = false, forceMount = true; void loadDataInfo() { @@ -109,7 +109,7 @@ namespace data u = getUserIndex(info.userID); titledata newData; - if(newData.init(info) && newData.isMountable(newUser.getUID())) + if(newData.init(info) && (newData.isMountable(newUser.getUID()) || !forceMount)) { users[u].titles.push_back(newData); } @@ -118,7 +118,7 @@ namespace data else { titledata newData; - if(newData.init(info) && newData.isMountable(users[u].getUID())) + if(newData.init(info) && (newData.isMountable(users[u].getUID()) || !forceMount)) { users[u].titles.push_back(newData); } @@ -347,10 +347,11 @@ namespace data blacklist.push_back(pushID); } + bl.close(); } } - void blacklistAdd(titledata& t) + void blacklistAdd(user& u, titledata& t) { std::fstream bl(fs::getWorkDir() + "blacklist.txt", std::ios::app); @@ -371,5 +372,8 @@ namespace data users[i].titles.erase(users[i].titles.begin() + j); } } + + int uInd = getUserIndex(u.getUID()); + u = users[uInd]; } } diff --git a/src/file.cpp b/src/file.cpp index 5db69d1..58a869a 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -60,9 +60,7 @@ namespace fs d = opendir(path.c_str()); while((ent = readdir(d))) - { item.push_back(ent->d_name); - } closedir(d); } @@ -76,9 +74,7 @@ namespace fs item.clear(); while((ent = readdir(d))) - { item.push_back(ent->d_name); - } closedir(d); } @@ -89,9 +85,7 @@ namespace fs d = opendir(path.c_str()); while((ent = readdir(d))) - { item.push_back(ent->d_name); - } closedir(d); } @@ -105,11 +99,8 @@ namespace fs { std::string fullPath = path + item[index]; struct stat s; - if(stat(fullPath.c_str(), &s) == 0) - { - if(S_ISDIR(s.st_mode)) - return true; - } + if(stat(fullPath.c_str(), &s) == 0 && S_ISDIR(s.st_mode)) + return true; return false; } diff --git a/src/gfx.c b/src/gfx.c index dfb6ce6..3c288f5 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -110,18 +110,18 @@ static inline void resizeFont(const font *f, int sz) } } -static inline FT_GlyphSlot loadGlyph(const uint32_t c, const font *f) +static inline FT_GlyphSlot loadGlyph(const uint32_t c, const font *f, FT_Int32 flags) { if(f->external) { - FT_Load_Glyph(f->face[0], FT_Get_Char_Index(f->face[0], c), FT_LOAD_RENDER); + FT_Load_Glyph(f->face[0], FT_Get_Char_Index(f->face[0], c), flags); return f->face[0]->glyph; } for(int i = 0; i < 6; i++) { FT_UInt cInd = 0; if( (cInd = FT_Get_Char_Index(f->face[i], c)) != 0 && \ - FT_Load_Glyph(f->face[i], cInd, FT_LOAD_RENDER) == 0) + FT_Load_Glyph(f->face[i], cInd, flags) == 0) { return f->face[i]->glyph; } @@ -153,7 +153,7 @@ void drawText(const char *str, tex *target, const font *f, int x, int y, int sz, continue; } - FT_GlyphSlot slot = loadGlyph(tmpChr, f); + FT_GlyphSlot slot = loadGlyph(tmpChr, f, FT_LOAD_RENDER); if(slot != NULL) { int drawY = y + (sz - slot->bitmap_top); @@ -174,29 +174,44 @@ void drawTextWrap(const char *str, tex *target, const font *f, int x, int y, int { nextbreak = strcspn(&str[i], " /"); - if(nextbreak == strLength) + memset(wordBuf, 0, 128); + memcpy(wordBuf, &str[i], nextbreak + 1); + + size_t width = textGetWidth(wordBuf, f, sz); + + if(tmpX + width >= x + maxWidth) { - drawText(&str[i], target, f, tmpX, y, sz, c); - break; + tmpX = x; + y += sz + 8; } - else + + size_t wLength = strlen(wordBuf); + uint32_t tmpChr = 0; + for(unsigned j = 0; j < wLength; ) { - memset(wordBuf, 0, 128); - memcpy(wordBuf, &str[i], nextbreak + 1); + ssize_t unitCnt = decode_utf8(&tmpChr, (const uint8_t *)&wordBuf[j]); + if(unitCnt <= 0) + break; - size_t width = textGetWidth(wordBuf, f, sz); - - if(tmpX + width >= x + maxWidth) + j += unitCnt; + if(tmpChr == '\n') { tmpX = x; y += sz + 8; + continue; } - drawText(wordBuf, target, f, tmpX, y, sz, c); - tmpX += width; + FT_GlyphSlot slot = loadGlyph(tmpChr, f, FT_LOAD_RENDER); + if(slot != NULL) + { + int drawY = y + (sz - slot->bitmap_top); + drawGlyph(&slot->bitmap, target, tmpX + slot->bitmap_left, drawY, c); - i += strlen(wordBuf); + tmpX += slot->advance.x >> 6; + } } + + i += strlen(wordBuf); } } @@ -217,7 +232,7 @@ size_t textGetWidth(const char *str, const font *f, int sz) break; i += untCnt; - FT_GlyphSlot slot = loadGlyph(tmpChr, f); + FT_GlyphSlot slot = loadGlyph(tmpChr, f, FT_LOAD_DEFAULT); if(ret) return 0; diff --git a/src/main.cpp b/src/main.cpp index 32a5489..7e9f967 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -61,7 +61,7 @@ int main(int argc, const char *argv[]) //Just to be sure fsdevUnmountDevice("sv"); - data::sysSave = true; + data::sysSave = true, data::forceMount = false; data::loadDataInfo(); //Kick back to user diff --git a/src/ui.cpp b/src/ui.cpp index 93c4818..009aa25 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -11,7 +11,7 @@ #include "util.h" #include "file.h" -#define TITLE_TEXT "JKSV - 08/18/2018" +#define TITLE_TEXT "JKSV - 08/23/2018" //background that can be drawn from "/JKSV/back.jpg" static tex *background = NULL; diff --git a/src/ui/clsui.cpp b/src/ui/clsui.cpp index 13d8934..473cbc7 100644 --- a/src/ui/clsui.cpp +++ b/src/ui/clsui.cpp @@ -107,7 +107,7 @@ namespace ui std::string confStr = "Are you 100% sure you want to add \"" + data::curUser.titles[titleMenu.getSelected()].getTitle() + \ "\" to your blacklist?"; if(ui::confirm(confStr)) - data::blacklistAdd(data::curUser.titles[titleMenu.getSelected()]); + data::blacklistAdd(data::curUser, data::curUser.titles[titleMenu.getSelected()]); } else if(down & KEY_B || ttlNav[3].getEvent() == BUTTON_RELEASED) mstate = CLS_USR; diff --git a/src/ui/menu.cpp b/src/ui/menu.cpp index dde64dd..6801665 100644 --- a/src/ui/menu.cpp +++ b/src/ui/menu.cpp @@ -15,6 +15,8 @@ namespace ui rW = _rW; rY = _y; + optButtons.clear(); + for(unsigned i = 0; i < 15; i++) { //Init + push invisible options buttons diff --git a/src/ui/miscui.cpp b/src/ui/miscui.cpp index 05ac982..8d0ac44 100644 --- a/src/ui/miscui.cpp +++ b/src/ui/miscui.cpp @@ -27,10 +27,12 @@ namespace ui drawRect(frameBuffer, 96, 400, 1088, 64, clrCreateU32(0xFF000000)); drawRect(frameBuffer, 96, 400, (unsigned)width, 64, clrCreateU32(0xFF00CC00)); - //char tmp[64]; - //sprintf(tmp, "%u / %u", (unsigned)prog, (unsigned)max); - drawTextWrap(text.c_str(), frameBuffer, ui::shared, 80, 256, 24, txtClr, 752); - //gfx::drawText(tmp, 80, 320, 64, 0x000000FF); + char tmp[128]; + sprintf(tmp, "%u KB/%u KB", (unsigned)prog / 1024, (unsigned)max / 1024); + int szX = 640 - (textGetWidth(tmp, shared, 24) / 2); + + drawTextWrap(text.c_str(), frameBuffer, ui::shared, 80, 256, 18, txtClr, 752); + drawText(tmp, frameBuffer, shared, szX, 416, 24, clrCreateU32(0xFFFFFFFF)); } button::button(const std::string& _txt, unsigned _x, unsigned _y, unsigned _w, unsigned _h) diff --git a/src/ui/ttlsel.cpp b/src/ui/ttlsel.cpp index 3424021..9755ec7 100644 --- a/src/ui/ttlsel.cpp +++ b/src/ui/ttlsel.cpp @@ -214,7 +214,7 @@ namespace ui std::string confStr = "Are you 100% sure you want to add \"" + data::curUser.titles[selected].getTitle() + \ "\" to your blacklist?"; if(ui::confirm(confStr)) - data::blacklistAdd(data::curUser.titles[selected]); + data::blacklistAdd(data::curUser, data::curUser.titles[selected]); } else if(down & KEY_B || ttlNav[3].getEvent() == BUTTON_RELEASED) { diff --git a/src/util.cpp b/src/util.cpp index 79606a0..773dec3 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -99,40 +99,40 @@ namespace util std::string getInfoString(data::user& u, data::titledata& d) { - std::string ret = d.getTitle(); + std::string ret = d.getTitle() + "\n"; char id[18]; sprintf(id, " %016lX", d.getID()); - ret += id; + ret += std::string(id) + "\n\n"; switch(d.getType()) { case FsSaveDataType_SystemSaveData: - ret += " System Save"; + ret += "System Save\n\n"; break; case FsSaveDataType_SaveData: - ret += " Save Data"; + ret += "Save Data\n\n"; break; case FsSaveDataType_BcatDeliveryCacheStorage: - ret += " Bcat Delivery Cache"; + ret += "Bcat Delivery Cache\n\n"; break; case FsSaveDataType_DeviceSaveData: - ret += " Device Save"; + ret += "Device Save\n\n"; break; case FsSaveDataType_TemporaryStorage: - ret = " Temp Storage"; + ret = "Temp Storage\n\n"; break; case FsSaveDataType_CacheStorage: - ret+= " Cache Storage"; + ret+= "Cache Storage\n\n"; break; } - ret += "\n" + u.getUsername(); + ret += u.getUsername(); return ret; }