From 4716225ce601ffd2539650dcd6e4cc5a89ae67ee Mon Sep 17 00:00:00 2001 From: J-D-K Date: Fri, 10 Apr 2020 01:50:18 -0400 Subject: [PATCH] Fix up some stuff, use va_list for log --- Makefile | 2 +- inc/data.h | 2 +- inc/file.h | 2 +- src/data.cpp | 21 +++++++++++---------- src/file.cpp | 15 +++++++++++---- src/ui.cpp | 2 +- 6 files changed, 26 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index fc8c03c..d1a1558 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ INCLUDES := inc EXEFS_SRC := exefs_src APP_TITLE := JKSV APP_AUTHOR := JK -APP_VERSION := 04.06.2020 +APP_VERSION := 04.10.2020 ROMFS := romfs #--------------------------------------------------------------------------------- diff --git a/inc/data.h b/inc/data.h index e772316..104fe0f 100644 --- a/inc/data.h +++ b/inc/data.h @@ -54,7 +54,7 @@ namespace data { public: //Attempts to read title's info - void init(const FsSaveDataInfo& inf); + void init(const FsSaveDataInfo& inf, NsApplicationControlData *dat); //Attempts to mount data with uID + id. Returns false if fails. For filtering. bool isMountable(const AccountUid& uID); diff --git a/inc/file.h b/inc/file.h index c86d01a..e3ead30 100644 --- a/inc/file.h +++ b/inc/file.h @@ -75,7 +75,7 @@ namespace fs }; void logOpen(); - void logWrite(const std::string& out); + void logWrite(const char *fmt, ...); void logClose(); } diff --git a/src/data.cpp b/src/data.cpp index be6dfd9..beb8964 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -171,6 +171,8 @@ namespace data users.push_back(sys); //users.push_back(sysBcat); + //Stop allocing and freeing over and over for every title. + NsApplicationControlData *dat = new NsApplicationControlData; while(R_SUCCEEDED(fsSaveDataInfoReaderRead(&saveIt, &info, 1, &total)) && total != 0) { switch(info.save_data_type) @@ -206,7 +208,7 @@ namespace data u = getUserIndex(info.uid); titledata newData; - newData.init(info); + newData.init(info, dat); if(isFavorite(newData.getID())) newData.setFav(true); @@ -217,7 +219,7 @@ namespace data else { titledata newData; - newData.init(info); + newData.init(info, dat); if(isFavorite(newData.getID())) newData.setFav(true); @@ -226,6 +228,7 @@ namespace data } } } + delete dat; fsSaveDataInfoReaderClose(&saveIt); if(data::incDev) @@ -296,10 +299,9 @@ namespace data drawText("♥", iconFav, ui::shared, 0, 0, 48, clrCreateU32(0xFF4444FF)); } - void titledata::init(const FsSaveDataInfo& inf) + void titledata::init(const FsSaveDataInfo& inf, NsApplicationControlData *dat) { size_t outSz = 0; - NsApplicationControlData *dat = new NsApplicationControlData; NacpLanguageEntry *ent = NULL; memset(dat, 0, sizeof(NsApplicationControlData)); @@ -311,7 +313,8 @@ namespace data saveDataType = inf.save_data_type; Result ctrlDataRes = nsGetApplicationControlData(NsApplicationControlSource_Storage, id, dat, sizeof(NsApplicationControlData), &outSz); Result nacpRes = nacpGetLanguageEntry(&dat->nacp, &ent); - if(R_SUCCEEDED(ctrlDataRes) && !(outSz < sizeof(dat->nacp)) && R_SUCCEEDED(nacpRes) && ent != NULL) + size_t icnSize = outSz - sizeof(dat->nacp); + if(R_SUCCEEDED(ctrlDataRes) && !(outSz < sizeof(dat->nacp)) && R_SUCCEEDED(nacpRes) && ent != NULL && icnSize > 0) { title.assign(ent->name); titleSafe.assign(util::safeString(title)); @@ -326,13 +329,13 @@ namespace data int icnInd = findIcnIndex(id); if(icnInd == -1) { - size_t icnSize = outSz - sizeof(dat->nacp); icn newIcn; newIcn.load(id, dat->icon, icnSize); newIcn.createFav(); icons.push_back(newIcn); - icon = icons[findIcnIndex(id)]; + //safe to assume icon is last + icon = data::icons[data::icons.size() - 1]; } else icon = icons[icnInd]; @@ -351,8 +354,6 @@ namespace data } path = fs::getWorkDir() + titleSafe + "/"; - - delete dat; } bool titledata::isMountable(const AccountUid& uID) @@ -394,7 +395,7 @@ namespace data if(userSafe.empty()) { char tmp[32]; - sprintf(tmp, "Acc%016lX", (uint64_t)uID128); + sprintf(tmp, "Acc%08X", (uint32_t)uID128); userSafe = tmp; } diff --git a/src/file.cpp b/src/file.cpp index 63830f9..4776597 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "file.h" @@ -467,15 +468,21 @@ namespace fs fsFsOpenFile(sd, "/JKSV/log.txt", FsOpenMode_Write, &logFile); } - void logWrite(const std::string& out) + void logWrite(const char *fmt, ...) { + char tmp[256]; + va_list args; + va_start(args, fmt); + vsprintf(tmp, fmt, args); + + unsigned tmpLength = strlen(tmp); s64 curSize = 0; fsFileGetSize(&logFile, &curSize); - curSize += out.size(); + curSize += tmpLength; fsFileSetSize(&logFile, curSize); - fsFileWrite(&logFile, offset, out.c_str(), out.length(), 0); - offset += out.length(); + fsFileWrite(&logFile, offset, tmp, tmpLength, 0); + offset += tmpLength; } void logClose() diff --git a/src/ui.cpp b/src/ui.cpp index a3ee65d..1b4a9e2 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -10,7 +10,7 @@ #include "util.h" #include "file.h" -#define VER_STRING "v. 04.06.2020" +#define VER_STRING "v. 04.10.2020" //Nav buttons std::vector usrNav, ttlNav, fldNav;