From e708f02b6f7f094f00a3cc4fe939de0ad10390fe Mon Sep 17 00:00:00 2001 From: J-D-K Date: Mon, 6 Jan 2020 03:27:10 -0500 Subject: [PATCH] Working on it --- Makefile | 4 +-- inc/data.h | 23 +++++++-------- inc/util.h | 13 +++++++++ src/data.cpp | 73 +++++++++++++++++++++++----------------------- src/ex.c | 4 +-- src/file.cpp | 34 ++++++++++----------- src/main.cpp | 2 +- src/ui.cpp | 2 +- src/ui/clsui.cpp | 22 +++++++------- src/ui/fldrsel.cpp | 2 +- src/util.cpp | 10 +++---- 11 files changed, 99 insertions(+), 90 deletions(-) diff --git a/Makefile b/Makefile index cd7a579..51ebd06 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ INCLUDES := inc EXEFS_SRC := exefs_src APP_TITLE := JKSV APP_AUTHOR := JK -APP_VERSION := 12.07.2019 +APP_VERSION := 01.06.2020 ROMFS := romfs #--------------------------------------------------------------------------------- @@ -51,7 +51,7 @@ override CFLAGS += -g -Wall -O2 -ffunction-sections \ override CFLAGS += $(INCLUDE) -D__SWITCH__ `freetype-config --cflags` -CXXFLAGS:= $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++14 +CXXFLAGS:= $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11 ASFLAGS := -g $(ARCH) LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) diff --git a/inc/data.h b/inc/data.h index dad7d06..b4516a9 100644 --- a/inc/data.h +++ b/inc/data.h @@ -48,28 +48,25 @@ namespace data void init(const FsSaveDataInfo& inf); //Attempts to mount data with uID + id. Returns false if fails. For filtering. - bool isMountable(const u128& uID); + bool isMountable(const AccountUid& uID); //Returns title + title without forbidden chars std::string getTitle() { return title;} std::string getTitleSafe() { return titleSafe; } - //for disabling certain things - void setType(FsSaveDataType _type){ type = _type; } - - //Returns ID uint64_t getID() { return id; } + FsSaveDataType getType(){ return (FsSaveDataType)info.save_data_type; } + void setType(FsSaveDataType type){ info.save_data_type = type; } //Game icon icn icon; - FsSaveDataType getType() { return type; } + //FUCK IT + FsSaveDataInfo info; private: - FsSaveDataType type; std::string title, titleSafe; uint64_t id; - u128 uID; }; //Class to store user info + titles @@ -77,16 +74,16 @@ namespace data { public: //Attempts to read user data using _id - bool init(const u128& _id); + bool init(const AccountUid& _id); //Allows user to init without reading data. For fun. - bool initNoChk(const u128& _id, const std::string& _backupName); + bool initNoChk(const AccountUid& _id, const std::string& _backupName); //Sets ID - void setUID(const u128& _id){ userID = _id; } + void setUID(const AccountUid& _id){ userID = _id; } //Returns user ID - u128 getUID() { return userID; } + AccountUid getUID() { return userID; } //Returns username std::string getUsername() { return username; } @@ -100,7 +97,7 @@ namespace data void delIcon(){ texDestroy(userIcon); } private: - u128 userID; + AccountUid userID; std::string username, userSafe; //User icon tex* userIcon; diff --git a/inc/util.h b/inc/util.h index ae79a93..170d09d 100644 --- a/inc/util.h +++ b/inc/util.h @@ -43,5 +43,18 @@ namespace util //Creates a basic generic icon for stuff without one tex *createIconGeneric(const char *txt); + + static inline u128 accountUIDToU128(AccountUid uid) + { + return ((u128)uid.uid[0] << 64 | uid.uid[1]); + } + + static inline AccountUid u128ToAccountUID(u128 id) + { + AccountUid ret; + ret.uid[0] = id >> 64; + ret.uid[1] = id; + return ret; + } } #endif // UTIL_H diff --git a/src/data.cpp b/src/data.cpp index abf95bc..5baaa41 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -33,11 +33,14 @@ static struct } sortTitles; //Returns -1 for new -static int getUserIndex(const u128& id) +static int getUserIndex(const AccountUid& id) { + u128 nId = 0, oId = 0; + nId = util::accountUIDToU128(id); for(unsigned i = 0; i < data::users.size(); i++) { - if(data::users[i].getUID() == id) + oId = util::accountUIDToU128(data::users[i].getUID()); + if(oId == nId) return i; } @@ -75,11 +78,11 @@ namespace data loadBlacklist(); - FsSaveDataIterator saveIt; - size_t total = 0; + FsSaveDataInfoReader saveIt; + s64 total = 0; FsSaveDataInfo info; - if(R_FAILED(fsOpenSaveDataIterator(&saveIt, FsSaveDataSpaceId_All))) + if(R_FAILED(fsOpenSaveDataInfoReader(&saveIt, FsSaveDataSpaceId_All))) { printf("SaveDataIterator Failed\n"); return; @@ -87,9 +90,9 @@ namespace data //Push System and BCAT user user sys, bcat, dev; - sys.initNoChk(1, "System"); - bcat.initNoChk(2, "BCAT"); - dev.initNoChk(3, "Dev. Sv"); + sys.initNoChk(util::u128ToAccountUID(1), "System"); + bcat.initNoChk(util::u128ToAccountUID(2), "BCAT"); + dev.initNoChk(util::u128ToAccountUID(3), "Dev. Sv"); users.push_back(sys); users.push_back(bcat); @@ -97,37 +100,37 @@ namespace data while(true) { - if(R_FAILED(fsSaveDataIteratorRead(&saveIt, &info, 1, &total)) || total == 0) + if(R_FAILED(fsSaveDataInfoReaderRead(&saveIt, &info, 1, &total)) || total == 0) break; - switch(info.saveDataType) + switch(info.save_data_type) { - case FsSaveDataType_SystemBcat: - info.userID = 1; + case FsSaveDataType_System: + info.uid = util::u128ToAccountUID(1); + break; + + case FsSaveDataType_Bcat: + info.uid = util::u128ToAccountUID(2); break; case FsSaveDataType_Device: - info.userID = 2; - break; - - case FsSaveDataType_DeviceSaveData: - info.userID = 3; + info.uid = util::u128ToAccountUID(3); break; } //If save data, not black listed or just ignore - if(!blacklisted(info.titleID)) + if(!blacklisted(info.application_id)) { - int u = getUserIndex(info.userID); + int u = getUserIndex(info.uid); if(u == -1) { user newUser; - if(newUser.init(info.userID)) + if(newUser.init(info.uid)) { //Always insert new users to beginning users.insert(users.begin(), newUser); - u = getUserIndex(info.userID); + u = getUserIndex(info.uid); titledata newData; newData.init(info); if(newData.isMountable(newUser.getUID()) || !forceMount) @@ -144,7 +147,7 @@ namespace data } } - fsSaveDataIteratorClose(&saveIt); + fsSaveDataInfoReaderClose(&saveIt); for(unsigned i = 0; i < users.size(); i++) std::sort(users[i].titles.begin(), users[i].titles.end(), sortTitles); @@ -204,17 +207,15 @@ namespace data NsApplicationControlData *dat = new NsApplicationControlData; std::memset(dat, 0, sizeof(NsApplicationControlData)); NacpLanguageEntry *ent = NULL; - - if(inf.saveDataType== FsSaveDataType_Bcat) - id = inf.titleID; - else if(inf.saveDataType== FsSaveDataType_SystemBcat) - id = inf.saveID; - - uID = inf.userID; - type = (FsSaveDataType)inf.saveDataType; size_t outSz = 0; - if(R_SUCCEEDED(nsGetApplicationControlData(1, id, dat, sizeof(NsApplicationControlData), &outSz)) && outSz >= sizeof(dat->nacp) \ + info = inf; + if(inf.save_data_type == FsSaveDataType_Account) + id = inf.application_id; + else + id = inf.save_data_id; + + if(R_SUCCEEDED(nsGetApplicationControlData(NsApplicationControlSource_Storage, id, dat, sizeof(NsApplicationControlData), &outSz)) && outSz >= sizeof(dat->nacp) \ && R_SUCCEEDED(nacpGetLanguageEntry(&dat->nacp, &ent)) && ent != NULL) { title.assign(ent->name); @@ -250,7 +251,7 @@ namespace data delete dat; } - bool titledata::isMountable(const u128& uID) + bool titledata::isMountable(const AccountUid& uID) { data::user tmpUser; tmpUser.setUID(uID); @@ -262,7 +263,7 @@ namespace data return false; } - bool user::init(const u128& _id) + bool user::init(const AccountUid& _id) { userID = _id; @@ -275,12 +276,12 @@ namespace data if(R_FAILED(accountProfileGet(&prof, NULL, &base))) return false; - username.assign(base.username); + username.assign(base.nickname); if(username.empty()) username = "Unknown"; userSafe = util::safeString(username); - size_t sz = 0; + uint32_t sz = 0; accountProfileGetImageSize(&prof, &sz); uint8_t *profJpeg = new uint8_t[sz]; @@ -294,7 +295,7 @@ namespace data return true; } - bool user::initNoChk(const u128& _id, const std::string& _backupName) + bool user::initNoChk(const AccountUid& _id, const std::string& _backupName) { userID = _id; diff --git a/src/ex.c b/src/ex.c index fa8eaf3..2b4e5cc 100644 --- a/src/ex.c +++ b/src/ex.c @@ -4,7 +4,7 @@ Result fsOpenDataFileSystemByCurrentProcess(FsFileSystem *out) { - Result ret = 0; + /*Result ret = 0; IpcCommand c; ipcInitialize(&c); @@ -34,5 +34,5 @@ Result fsOpenDataFileSystemByCurrentProcess(FsFileSystem *out) serviceCreateSubservice(&out->s, fsGetServiceSession(), &p, 0); } - return ret; + return ret;*/ } diff --git a/src/file.cpp b/src/file.cpp index 2c3c24b..8a00b01 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -18,26 +18,24 @@ static std::string wd; -Result fsMountBCAT(FsFileSystem *out, uint64_t id) +static Result fsMountBCAT(FsFileSystem *out, data::titledata& open) { - FsSave sv; - std::memset(&sv, 0, sizeof(FsSave)); + FsSaveDataAttribute attr; + std::memset(&attr, 0, sizeof(FsSaveDataAttribute)); + attr.application_id = open.info.application_id; + attr.save_data_type = FsSaveDataType_Bcat; - sv.titleID = id; - sv.saveDataType = FsSaveDataType_BcatDeliveryCacheStorage; - - return fsMountSaveData(out, FsSaveDataSpaceId_NandUser, &sv); + return fsOpenSaveDataFileSystem(out, FsSaveDataSpaceId_User, &attr); } -Result fsMountDeviceSave(FsFileSystem *out, uint64_t id) +static Result fsMountDeviceSave(FsFileSystem *out, data::titledata& open) { - FsSave sv; - std::memset(&sv, 0, sizeof(FsSave)); + FsSaveDataAttribute attr; + std::memset(&attr, 0, sizeof(FsSaveDataAttribute)); + attr.application_id = open.info.application_id; + attr.save_data_type = FsSaveDataType_Device; - sv.titleID = id; - sv.saveDataType = FsSaveDataType_Device; - - return fsdevMountSaveData(out, FsSaveDataSpaceId_User, &sv); + return fsOpenSaveDataFileSystem(out, FsSaveDataSpaceId_User, &attr); } static struct @@ -69,13 +67,13 @@ namespace fs { FsFileSystem sv; - if(open.getType() == FsSaveDataType_Bcat && R_FAILED(fsMount_SaveData(&sv, open.getID(), usr.getUID()))) + if(open.info.save_data_type == FsSaveDataType_Account && R_FAILED(fsOpen_SaveData(&sv, open.info.application_id, usr.getUID()))) return false; - else if(open.getType() == FsSaveDataType_SystemBcat && R_FAILED(fsMount_SystemSaveData(&sv, open.getID()))) + else if(open.info.save_data_type == FsSaveDataType_System && R_FAILED(fsOpen_SystemSaveData(&sv, FsSaveDataSpaceId_System, open.info.save_data_id, (AccountUid){0}))) return false; - else if(open.getType() == FsSaveDataType_BcatDeliveryCacheStorage && R_FAILED(fsMountBCAT(&sv, open.getID()))) + else if(open.info.save_data_type == FsSaveDataType_Bcat && R_FAILED(fsMountBCAT(&sv, open))) return false; - else if(open.getType() == FsSaveDataType_Device && R_FAILED(fsMountDeviceSave(&sv, open.getID()))) + else if(open.info.save_data_type == FsSaveDataType_Device && R_FAILED(fsMountDeviceSave(&sv, open))) return false; if(fsdevMountDevice("sv", sv) == -1) diff --git a/src/main.cpp b/src/main.cpp index 995845c..b1fd2cc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,7 +18,7 @@ extern "C" hidInitialize(); nsInitialize(); setsysInitialize(); - accountInitialize(); + accountInitialize(AccountServiceType_Application); } void userAppExit(void) diff --git a/src/ui.cpp b/src/ui.cpp index b592f97..7232301 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -11,7 +11,7 @@ #include "util.h" #include "file.h" -#define VER_STRING "v. 12.07.2019" +#define VER_STRING "v. 01.06.2020" //Nav buttons std::vector usrNav, ttlNav, fldNav; diff --git a/src/ui/clsui.cpp b/src/ui/clsui.cpp index fcaca5a..8adbcd8 100644 --- a/src/ui/clsui.cpp +++ b/src/ui/clsui.cpp @@ -277,7 +277,7 @@ namespace ui case 1: fsdevUnmountDevice("sv"); - fsOpenBisFileSystem(&sv, FsBisStorageId_CalibrationFile, ""); + fsOpenBisFileSystem(&sv, FsBisPartitionId_CalibrationFile, ""); fsdevMountDevice("prodInfo-f", sv); advModePrep("profInfo-f:/", false); @@ -287,7 +287,7 @@ namespace ui case 2: fsdevUnmountDevice("sv"); - fsOpenBisFileSystem(&sv, FsBisStorageId_SafeMode, ""); + fsOpenBisFileSystem(&sv, FsBisPartitionId_SafeMode, ""); fsdevMountDevice("safe", sv); advModePrep("safe:/", false); @@ -297,7 +297,7 @@ namespace ui case 3: fsdevUnmountDevice("sv"); - fsOpenBisFileSystem(&sv, FsBisStorageId_System, ""); + fsOpenBisFileSystem(&sv, FsBisPartitionId_System, ""); fsdevMountDevice("sys", sv); advModePrep("sys:/", false); @@ -307,7 +307,7 @@ namespace ui case 4: fsdevUnmountDevice("sv"); - fsOpenBisFileSystem(&sv, FsBisStorageId_User, ""); + fsOpenBisFileSystem(&sv, FsBisPartitionId_User, ""); fsdevMountDevice("user", sv); advModePrep("user:/", false); @@ -320,8 +320,8 @@ namespace ui fsdevUnmountDevice("sv"); FsStorage nand; - fsOpenBisStorage(&nand, FsBisStorageId_UserDataRoot); - uint64_t nandSize = 0, offset = 0; + fsOpenBisStorage(&nand, FsBisPartitionId_UserDataRoot); + s64 nandSize = 0, offset = 0; fsStorageGetSize(&nand, &nandSize); std::fstream nandOut("sdmc:/JKSV/nand.bin", std::ios::out | std::ios::binary); @@ -367,8 +367,8 @@ namespace ui fsdevUnmountDevice("sv"); FsStorage nand; - fsOpenBisStorage(&nand, FsBisStorageId_UserDataRoot); - uint64_t nandSize = 0, offset = 0; + fsOpenBisStorage(&nand, FsBisPartitionId_UserDataRoot); + s64 nandSize = 0, offset = 0; fsStorageGetSize(&nand, &nandSize); std::fstream nandOut("sdmc:/JKSV/nand.bin.00", std::ios::out | std::ios::binary); @@ -419,7 +419,7 @@ namespace ui case 7: { fsdevUnmountDevice("sv"); - fsOpenBisFileSystem(&sv, FsBisStorageId_System, ""); + fsOpenBisFileSystem(&sv, FsBisPartitionId_System, ""); fsdevMountDevice("sv", sv); std::string delPath = "sv:/Contents/placehld/"; @@ -447,7 +447,7 @@ namespace ui { uint64_t termID = std::strtoull(idStr.c_str(), NULL, 16); pmshellInitialize(); - if(R_SUCCEEDED(pmshellTerminateProcessByTitleId(termID))) + if(R_SUCCEEDED(pmshellTerminateProcess(termID))) ui::showMessage("Process " + idStr + " successfully shutdown.", "Success!"); pmshellExit(); } @@ -459,7 +459,7 @@ namespace ui fsdevUnmountDevice("sv"); std::string idStr = util::getStringInput("8000000000000000", "Enter Sys Save ID", 18, 0, NULL); uint64_t mountID = std::strtoull(idStr.c_str(), NULL, 16); - if(R_SUCCEEDED(fsMount_SystemSaveData(&sv, mountID))) + if(R_SUCCEEDED(fsOpen_SystemSaveData(&sv, FsSaveDataSpaceId_System, mountID, (AccountUid){0}))) { fsdevMountDevice("sv", sv); advModePrep("sv:/", true); diff --git a/src/ui/fldrsel.cpp b/src/ui/fldrsel.cpp index 9701c2f..fa583a2 100644 --- a/src/ui/fldrsel.cpp +++ b/src/ui/fldrsel.cpp @@ -99,7 +99,7 @@ namespace ui } else if(down & KEY_Y || fldNav[1].getEvent() == BUTTON_RELEASED) { - if(data::curData.getType() != FsSaveDataType_SystemBcat && folderMenu.getSelected() > 0) + if(data::curData.info.save_data_type != FsSaveDataType_SystemBcat && folderMenu.getSelected() > 0) { std::string scanPath = util::getTitleDir(data::curUser, data::curData); fs::dirList list(scanPath); diff --git a/src/util.cpp b/src/util.cpp index c6db06b..44b2654 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -158,20 +158,20 @@ namespace util std::string ret = d.getTitle() + "\n"; char id[18]; - sprintf(id, " %016lX", d.getID()); + sprintf(id, " %016lX", d.info.application_id); ret += std::string(id) + "\n\n"; - switch(d.getType()) + switch(d.info.save_data_type) { - case FsSaveDataType_SystemBcat: + case FsSaveDataType_System: ret += "System Save\n\n"; break; - case FsSaveDataType_Bcat: + case FsSaveDataType_Account: ret += "Save Data\n\n"; break; - case FsSaveDataType_BcatDeliveryCacheStorage: + case FsSaveDataType_Bcat: ret += "Bcat Delivery Cache\n\n"; break;