Let checkpoint compile with libnx 3.0.0

This commit is contained in:
BernardoGiordano 2019-12-13 21:51:36 +01:00
parent 0f6ce0d8f7
commit 177ad185e0
13 changed files with 105 additions and 90 deletions

View file

@ -36,8 +36,30 @@
#define USER_ICON_SIZE 64
namespace std {
template <>
struct hash<AccountUid> {
size_t operator()(const AccountUid& a) const { return ((hash<u64>()(a.uid[0]) ^ (hash<u64>()(a.uid[1]) << 1)) >> 1); }
};
}
inline bool operator==(const AccountUid& x, const AccountUid& y)
{
return x.uid[0] == y.uid[0] && x.uid[1] == y.uid[1];
}
inline bool operator==(const AccountUid& x, u64 y)
{
return x.uid[0] == y && x.uid[1] == y;
}
inline bool operator<(const AccountUid& x, const AccountUid& y)
{
return x.uid[0] < y.uid[0] && x.uid[1] == y.uid[1];
}
struct User {
u128 id;
AccountUid id;
std::string name;
std::string shortName;
SDL_Texture* icon;
@ -47,11 +69,11 @@ namespace Account {
Result init(void);
void exit(void);
std::vector<u128> ids(void);
SDL_Texture* icon(u128 id);
u128 selectAccount(void);
std::string username(u128 id);
std::string shortName(u128 id);
std::vector<AccountUid> ids(void);
SDL_Texture* icon(AccountUid id);
AccountUid selectAccount(void);
std::string username(AccountUid id);
std::string shortName(AccountUid id);
}
#endif

View file

@ -27,11 +27,11 @@
#ifndef FILESYSTEM_HPP
#define FILESYSTEM_HPP
#include "account.hpp"
#include <switch.h>
namespace FileSystem {
Result mount(FsFileSystem* fileSystem, u64 titleID, u128 userID);
Result mount(FsFileSystem* fileSystem, u64 saveID);
Result mount(FsFileSystem* fileSystem, u64 titleID, AccountUid userID);
int mount(FsFileSystem fs);
void unmount(void);
}

View file

@ -28,6 +28,7 @@
#define IO_HPP
#include "KeyboardManager.hpp"
#include "account.hpp"
#include "directory.hpp"
#include "multiselection.hpp"
#include "title.hpp"
@ -42,8 +43,8 @@
#define BUFFER_SIZE 0x80000
namespace io {
std::tuple<bool, Result, std::string> backup(size_t index, u128 uid, size_t cellIndex);
std::tuple<bool, Result, std::string> restore(size_t index, u128 uid, size_t cellIndex, const std::string& nameFromCell);
std::tuple<bool, Result, std::string> backup(size_t index, AccountUid uid, size_t cellIndex);
std::tuple<bool, Result, std::string> restore(size_t index, AccountUid uid, size_t cellIndex, const std::string& nameFromCell);
Result copyDirectory(const std::string& srcPath, const std::string& dstPath);
void copyFile(const std::string& srcPath, const std::string& dstPath);

View file

@ -28,13 +28,14 @@
#define MAIN_HPP
#include "Screen.hpp"
#include "account.hpp"
#include "title.hpp"
#include "util.hpp"
#include <memory>
#include <switch.h>
inline float g_currentTime = 0;
inline u128 g_currentUId = 0;
inline float g_currentTime = 0;
inline AccountUid g_currentUId;
inline bool g_backupScrollEnabled = 0;
inline bool g_notificationLedAvailable = false;
inline std::shared_ptr<Screen> g_screen = nullptr;

View file

@ -25,6 +25,7 @@
*/
#include "KeyboardManager.hpp"
#include "account.hpp"
#include "title.hpp"
#include <arpa/inet.h>
#include <errno.h>
@ -41,5 +42,5 @@
#define PKSM_PORT 34567
bool isPKSMBridgeTitle(u64 id);
std::tuple<bool, Result, std::string> sendToPKSMBrigde(size_t index, u128 uid, size_t cellIndex);
std::tuple<bool, Result, std::string> recvFromPKSMBridge(size_t index, u128 uid, size_t cellIndex);
std::tuple<bool, Result, std::string> sendToPKSMBrigde(size_t index, AccountUid uid, size_t cellIndex);
std::tuple<bool, Result, std::string> recvFromPKSMBridge(size_t index, AccountUid uid, size_t cellIndex);

View file

@ -28,6 +28,7 @@
#define TITLE_HPP
#include "SDLHelper.hpp"
#include "account.hpp"
#include "configuration.hpp"
#include "filesystem.hpp"
#include "io.hpp"
@ -41,7 +42,7 @@
class Title {
public:
void init(u8 saveDataType, u64 titleid, u128 userID, const std::string& name, const std::string& author);
void init(u8 saveDataType, u64 titleid, AccountUid userID, const std::string& name, const std::string& author);
~Title(void){};
std::string author(void);
@ -58,14 +59,13 @@ public:
void saveId(u64 id);
std::vector<std::string> saves(void);
u8 saveDataType(void);
bool systemSave(void);
u128 userId(void);
AccountUid userId(void);
std::string userName(void);
private:
u64 mId;
u64 mSaveId;
u128 mUserId;
AccountUid mUserId;
std::string mUserName;
std::string mName;
std::string mSafeName;
@ -78,13 +78,13 @@ private:
std::string mPlayTime;
};
void getTitle(Title& dst, u128 uid, size_t i);
size_t getTitleCount(u128 uid);
void getTitle(Title& dst, AccountUid uid, size_t i);
size_t getTitleCount(AccountUid uid);
void loadTitles(void);
void refreshDirectories(u64 id);
bool favorite(u128 uid, int i);
bool favorite(AccountUid uid, int i);
void freeIcons(void);
SDL_Texture* smallIcon(u128 uid, size_t i);
SDL_Texture* smallIcon(AccountUid uid, size_t i);
std::unordered_map<std::string, std::string> getCompleteTitleList(void);
#endif

View file

@ -26,11 +26,11 @@
#include "account.hpp"
static std::map<u128, User> mUsers;
static std::map<AccountUid, User> mUsers;
Result Account::init(void)
{
return accountInitialize();
return accountInitialize(AccountServiceType_Application);
}
void Account::exit(void)
@ -41,16 +41,16 @@ void Account::exit(void)
accountExit();
}
std::vector<u128> Account::ids(void)
std::vector<AccountUid> Account::ids(void)
{
std::vector<u128> v;
std::vector<AccountUid> v;
for (auto& value : mUsers) {
v.push_back(value.second.id);
}
return v;
}
static User getUser(u128 id)
static User getUser(AccountUid id)
{
User user{id, "", "", NULL};
AccountProfile profile;
@ -58,12 +58,12 @@ static User getUser(u128 id)
memset(&profilebase, 0, sizeof(profilebase));
if (R_SUCCEEDED(accountGetProfile(&profile, id)) && R_SUCCEEDED(accountProfileGet(&profile, NULL, &profilebase))) {
user.name = std::string(profilebase.username, 0x20);
user.name = std::string(profilebase.nickname, 0x20);
user.shortName = trimToFit(user.name, 96 - g_username_dotsize * 2, 13);
// load icon
u8* buffer;
size_t image_size, real_size;
u32 image_size, real_size;
if (R_SUCCEEDED(accountProfileGetImageSize(&profile, &image_size)) && (buffer = (u8*)malloc(image_size)) != NULL &&
R_SUCCEEDED(accountProfileLoadImage(&profile, buffer, image_size, &real_size))) {
SDLH_LoadImage(&user.icon, buffer, image_size);
@ -75,9 +75,9 @@ static User getUser(u128 id)
return user;
}
std::string Account::username(u128 id)
std::string Account::username(AccountUid id)
{
std::map<u128, User>::const_iterator got = mUsers.find(id);
std::map<AccountUid, User>::const_iterator got = mUsers.find(id);
if (got == mUsers.end()) {
User user = getUser(id);
mUsers.insert({id, user});
@ -87,9 +87,9 @@ std::string Account::username(u128 id)
return got->second.name;
}
std::string Account::shortName(u128 id)
std::string Account::shortName(AccountUid id)
{
std::map<u128, User>::const_iterator got = mUsers.find(id);
std::map<AccountUid, User>::const_iterator got = mUsers.find(id);
if (got == mUsers.end()) {
User user = getUser(id);
mUsers.insert({id, user});
@ -99,9 +99,9 @@ std::string Account::shortName(u128 id)
return got->second.shortName;
}
SDL_Texture* Account::icon(u128 id)
SDL_Texture* Account::icon(AccountUid id)
{
std::map<u128, User>::const_iterator got = mUsers.find(id);
std::map<AccountUid, User>::const_iterator got = mUsers.find(id);
if (got == mUsers.end()) {
User user = getUser(id);
mUsers.insert({id, user});
@ -110,9 +110,9 @@ SDL_Texture* Account::icon(u128 id)
return got->second.icon;
}
u128 Account::selectAccount(void)
AccountUid Account::selectAccount(void)
{
u128 out_id = 0;
AccountUid out_id;
LibAppletArgs args;
libappletArgsCreate(&args, 0x10000);
u8 st_in[0xA0] = {0};
@ -121,8 +121,8 @@ u128 Account::selectAccount(void)
Result res = libappletLaunch(AppletId_playerSelect, &args, st_in, 0xA0, st_out, 0x18, &repsz);
if (R_SUCCEEDED(res)) {
u64 lres = *(u64*)st_out;
u128 uid = *(u128*)&st_out[8];
u64 lres = *(u64*)st_out;
AccountUid uid = *(AccountUid*)&st_out[8];
if (lres == 0)
out_id = uid;
}

View file

@ -26,14 +26,9 @@
#include "filesystem.hpp"
Result FileSystem::mount(FsFileSystem* fileSystem, u64 titleID, u128 userID)
Result FileSystem::mount(FsFileSystem* fileSystem, u64 titleID, AccountUid userID)
{
return fsMount_SaveData(fileSystem, titleID, userID);
}
Result FileSystem::mount(FsFileSystem* fileSystem, u64 saveID)
{
return fsMount_SystemSaveData(fileSystem, saveID);
return fsOpen_SaveData(fileSystem, titleID, userID);
}
int FileSystem::mount(FsFileSystem fs)

View file

@ -151,7 +151,7 @@ Result io::deleteFolderRecursively(const std::string& path)
return 0;
}
std::tuple<bool, Result, std::string> io::backup(size_t index, u128 uid, size_t cellIndex)
std::tuple<bool, Result, std::string> io::backup(size_t index, AccountUid uid, size_t cellIndex)
{
const bool isNewFolder = cellIndex == 0;
Result res = 0;
@ -160,7 +160,7 @@ std::tuple<bool, Result, std::string> io::backup(size_t index, u128 uid, size_t
getTitle(title, uid, index);
Logger::getInstance().log(Logger::INFO, "Started backup of %s. Title id: 0x%016lX; User id: 0x%lX%lX.", title.name().c_str(), title.id(),
(u64)(title.userId() >> 8), (u64)(title.userId()));
title.userId().uid[1], title.userId().uid[0]);
FsFileSystem fileSystem;
res = FileSystem::mount(&fileSystem, title.id(), title.userId());
@ -169,14 +169,14 @@ std::tuple<bool, Result, std::string> io::backup(size_t index, u128 uid, size_t
if (rc == -1) {
FileSystem::unmount();
Logger::getInstance().log(Logger::ERROR, "Failed to mount filesystem during backup. Title id: 0x%016lX; User id: 0x%lX%lX.", title.id(),
(u64)(title.userId() >> 8), (u64)(title.userId()));
title.userId().uid[1], title.userId().uid[0]);
return std::make_tuple(false, -2, "Failed to mount save.");
}
}
else {
Logger::getInstance().log(Logger::ERROR,
"Failed to mount filesystem during backup with result 0x%08lX. Title id: 0x%016lX; User id: 0x%lX%lX.", res, title.id(),
(u64)(title.userId() >> 8), (u64)(title.userId()));
title.userId().uid[1], title.userId().uid[0]);
return std::make_tuple(false, res, "Failed to mount save.");
}
@ -257,7 +257,7 @@ std::tuple<bool, Result, std::string> io::backup(size_t index, u128 uid, size_t
return ret;
}
std::tuple<bool, Result, std::string> io::restore(size_t index, u128 uid, size_t cellIndex, const std::string& nameFromCell)
std::tuple<bool, Result, std::string> io::restore(size_t index, AccountUid uid, size_t cellIndex, const std::string& nameFromCell)
{
Result res = 0;
std::tuple<bool, Result, std::string> ret = std::make_tuple(false, -1, "");
@ -265,23 +265,23 @@ std::tuple<bool, Result, std::string> io::restore(size_t index, u128 uid, size_t
getTitle(title, uid, index);
Logger::getInstance().log(Logger::INFO, "Started restore of %s. Title id: 0x%016lX; User id: 0x%lX%lX.", title.name().c_str(), title.id(),
(u64)(title.userId() >> 8), (u64)(title.userId()));
title.userId().uid[1], title.userId().uid[0]);
FsFileSystem fileSystem;
res = title.systemSave() ? FileSystem::mount(&fileSystem, title.id()) : FileSystem::mount(&fileSystem, title.id(), title.userId());
res = FileSystem::mount(&fileSystem, title.id(), title.userId());
if (R_SUCCEEDED(res)) {
int rc = FileSystem::mount(fileSystem);
if (rc == -1) {
FileSystem::unmount();
Logger::getInstance().log(Logger::ERROR, "Failed to mount filesystem during restore. Title id: 0x%016lX; User id: 0x%lX%lX.", title.id(),
(u64)(title.userId() >> 8), (u64)(title.userId()));
title.userId().uid[1], title.userId().uid[0]);
return std::make_tuple(false, -2, "Failed to mount save.");
}
}
else {
Logger::getInstance().log(Logger::ERROR,
"Failed to mount filesystem during restore with result 0x%08lX. Title id: 0x%016lX; User id: 0x%lX%lX.", res, title.id(),
(u64)(title.userId() >> 8), (u64)(title.userId()));
title.userId().uid[1], title.userId().uid[0]);
return std::make_tuple(false, res, "Failed to mount save.");
}

View file

@ -52,13 +52,13 @@ int main(void)
loadTitles();
// get the user IDs
std::vector<u128> userIds = Account::ids();
std::vector<AccountUid> userIds = Account::ids();
// set g_currentUId to a default user in case we loaded at least one user
if (g_currentUId == 0)
g_currentUId = userIds.at(0);
Thread networkThread;
threadCreate(&networkThread, (ThreadFunc)networkLoop, nullptr, 16 * 1000, 0x2C, -2);
threadCreate(&networkThread, (ThreadFunc)networkLoop, nullptr, nullptr, 16 * 1000, 0x2C, -2);
threadStart(&networkThread);
while (appletMainLoop() && !(hidKeysDown(CONTROLLER_P1_AUTO) & KEY_PLUS)) {

View file

@ -40,7 +40,7 @@ bool validateIpAddress(const std::string& ip)
return inet_pton(AF_INET, ip.c_str(), &sa.sin_addr) != 0;
}
std::tuple<bool, Result, std::string> sendToPKSMBrigde(size_t index, u128 uid, size_t cellIndex)
std::tuple<bool, Result, std::string> sendToPKSMBrigde(size_t index, AccountUid uid, size_t cellIndex)
{
auto systemKeyboardAvailable = KeyboardManager::get().isSystemKeyboardAvailable();
if (!systemKeyboardAvailable.first) {
@ -111,7 +111,7 @@ std::tuple<bool, Result, std::string> sendToPKSMBrigde(size_t index, u128 uid, s
}
}
std::tuple<bool, Result, std::string> recvFromPKSMBridge(size_t index, u128 uid, size_t cellIndex)
std::tuple<bool, Result, std::string> recvFromPKSMBridge(size_t index, AccountUid uid, size_t cellIndex)
{
int fd;
struct sockaddr_in servaddr;

View file

@ -26,7 +26,7 @@
#include "title.hpp"
static std::unordered_map<u128, std::vector<Title>> titles;
static std::unordered_map<AccountUid, std::vector<Title>> titles;
static std::unordered_map<u64, SDL_Texture*> icons;
void freeIcons(void)
@ -47,7 +47,7 @@ static void loadIcon(u64 id, NsApplicationControlData* nsacd, size_t iconsize)
}
}
void Title::init(u8 saveDataType, u64 id, u128 userID, const std::string& name, const std::string& author)
void Title::init(u8 saveDataType, u64 id, AccountUid userID, const std::string& name, const std::string& author)
{
mId = id;
mUserId = userID;
@ -90,11 +90,6 @@ void Title::init(u8 saveDataType, u64 id, u128 userID, const std::string& name,
refreshDirectories();
}
bool Title::systemSave(void)
{
return mSaveDataType != FsSaveDataType_SaveData;
}
u8 Title::saveDataType(void)
{
return mSaveDataType;
@ -115,7 +110,7 @@ void Title::saveId(u64 saveId)
mSaveId = saveId;
}
u128 Title::userId(void)
AccountUid Title::userId(void)
{
return mUserId;
}
@ -214,10 +209,10 @@ void loadTitles(void)
{
titles.clear();
FsSaveDataIterator iterator;
FsSaveDataInfoReader reader;
FsSaveDataInfo info;
size_t total_entries = 0;
size_t outsize = 0;
s64 total_entries = 0;
size_t outsize = 0;
NacpLanguageEntry* nle = NULL;
NsApplicationControlData* nsacd = (NsApplicationControlData*)malloc(sizeof(NsApplicationControlData));
@ -226,29 +221,29 @@ void loadTitles(void)
}
memset(nsacd, 0, sizeof(NsApplicationControlData));
Result res = fsOpenSaveDataIterator(&iterator, FsSaveDataSpaceId_NandUser);
Result res = fsOpenSaveDataInfoReader(&reader, FsSaveDataSpaceId_User);
if (R_FAILED(res)) {
free(nsacd);
return;
}
while (1) {
res = fsSaveDataIteratorRead(&iterator, &info, 1, &total_entries);
res = fsSaveDataInfoReaderRead(&reader, &info, 1, &total_entries);
if (R_FAILED(res) || total_entries == 0) {
break;
}
if (info.saveDataType == FsSaveDataType_SaveData) {
u64 tid = info.titleID;
u64 sid = info.saveID;
u128 uid = info.userID;
if (info.save_data_type == FsSaveDataType_Account) {
u64 tid = info.application_id;
u64 sid = info.save_data_id;
AccountUid uid = info.uid;
if (!Configuration::getInstance().filter(tid)) {
res = nsGetApplicationControlData(1, tid, nsacd, sizeof(NsApplicationControlData), &outsize);
res = nsGetApplicationControlData(NsApplicationControlSource_Storage, tid, nsacd, sizeof(NsApplicationControlData), &outsize);
if (R_SUCCEEDED(res) && !(outsize < sizeof(nsacd->nacp))) {
res = nacpGetLanguageEntry(&nsacd->nacp, &nle);
if (R_SUCCEEDED(res) && nle != NULL) {
Title title;
title.init(info.saveDataType, tid, uid, std::string(nle->name), std::string(nle->author));
title.init(info.save_data_type, tid, uid, std::string(nle->name), std::string(nle->author));
title.saveId(sid);
// load play statistics
@ -262,7 +257,7 @@ void loadTitles(void)
loadIcon(tid, nsacd, outsize - sizeof(nsacd->nacp));
// check if the vector is already created
std::unordered_map<u128, std::vector<Title>>::iterator it = titles.find(uid);
std::unordered_map<AccountUid, std::vector<Title>>::iterator it = titles.find(uid);
if (it != titles.end()) {
// found
it->second.push_back(title);
@ -281,7 +276,7 @@ void loadTitles(void)
}
free(nsacd);
fsSaveDataIteratorClose(&iterator);
fsSaveDataInfoReaderClose(&reader);
for (auto& vect : titles) {
std::sort(vect.second.begin(), vect.second.end(), [](Title& l, Title& r) {
@ -295,23 +290,23 @@ void loadTitles(void)
}
}
void getTitle(Title& dst, u128 uid, size_t i)
void getTitle(Title& dst, AccountUid uid, size_t i)
{
std::unordered_map<u128, std::vector<Title>>::iterator it = titles.find(uid);
std::unordered_map<AccountUid, std::vector<Title>>::iterator it = titles.find(uid);
if (it != titles.end() && i < getTitleCount(uid)) {
dst = it->second.at(i);
}
}
size_t getTitleCount(u128 uid)
size_t getTitleCount(AccountUid uid)
{
std::unordered_map<u128, std::vector<Title>>::iterator it = titles.find(uid);
std::unordered_map<AccountUid, std::vector<Title>>::iterator it = titles.find(uid);
return it != titles.end() ? it->second.size() : 0;
}
bool favorite(u128 uid, int i)
bool favorite(AccountUid uid, int i)
{
std::unordered_map<u128, std::vector<Title>>::iterator it = titles.find(uid);
std::unordered_map<AccountUid, std::vector<Title>>::iterator it = titles.find(uid);
return it != titles.end() ? Configuration::getInstance().favorite(it->second.at(i).id()) : false;
}
@ -326,9 +321,9 @@ void refreshDirectories(u64 id)
}
}
SDL_Texture* smallIcon(u128 uid, size_t i)
SDL_Texture* smallIcon(AccountUid uid, size_t i)
{
std::unordered_map<u128, std::vector<Title>>::iterator it = titles.find(uid);
std::unordered_map<AccountUid, std::vector<Title>>::iterator it = titles.find(uid);
return it != titles.end() ? it->second.at(i).icon() : NULL;
}

View file

@ -176,13 +176,13 @@ HidsysNotificationLedPattern blinkLedPattern(u8 times)
void blinkLed(u8 times)
{
if (g_notificationLedAvailable) {
size_t n;
s32 n;
u64 uniquePadIds[2];
HidsysNotificationLedPattern pattern = blinkLedPattern(times);
memset(uniquePadIds, 0, sizeof(uniquePadIds));
Result res = hidsysGetUniquePadsFromNpad(hidGetHandheldMode() ? CONTROLLER_HANDHELD : CONTROLLER_PLAYER_1, uniquePadIds, 2, &n);
if (R_SUCCEEDED(res)) {
for (size_t i = 0; i < n; i++) {
for (s32 i = 0; i < n; i++) {
hidsysSetNotificationLedPattern(&pattern, uniquePadIds[i]);
}
}