Awful (and not tested) Multi-User LFS support

This commit is contained in:
Pika 2018-08-21 11:53:46 -04:00 committed by GitHub
parent c40bb9b317
commit e42ca20734
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include <atomic> #include <atomic>
#include <algorithm> #include <algorithm>
#include <dirent.h>
#include "sm_mitm.h" #include "sm_mitm.h"
#include "debug.hpp" #include "debug.hpp"
@ -83,12 +84,36 @@ Result Utils::OpenSdFileForAtmosphere(u64 title_id, const char *fn, int flags, F
return 0xFA202; return 0xFA202;
} }
// multi-user stuff
// todo: add error handling (should i use fatalSimple?)
accountInitialize();
u128 user_id;
bool acc_selected;
accountGetActiveUser(&user_id, &acc_selected);
AccountProfile profile;
accountGetProfile(&profile, user_id);
AccountUserData user_data;
AccountProfileBase profile_base;
accountProfileGet(&profile, &user_data, &profile_base);
char path[FS_MAX_PATH]; char path[FS_MAX_PATH];
if (*fn == '/') { if (*fn == '/') {
snprintf(path, sizeof(path), "sdmc:/atmosphere/titles/%016lx_%s", title_id, profile_base.username);
DIR* dir = opendir(path);
if (dir) {
snprintf(path, sizeof(path), "/atmosphere/titles/%016lx_$s%s", title_id, profile_base.username, fn);
} else {
snprintf(path, sizeof(path), "/atmosphere/titles/%016lx%s", title_id, fn); snprintf(path, sizeof(path), "/atmosphere/titles/%016lx%s", title_id, fn);
}
} else {
snprintf(path, sizeof(path), "sdmc:/atmosphere/titles/%016lx_%s", title_id, profile_base.username);
DIR* dir = opendir(path);
if (dir) {
snprintf(path, sizeof(path), "/atmosphere/titles/%016lx_$s/%s", title_id, profile_base.username, fn);
} else { } else {
snprintf(path, sizeof(path), "/atmosphere/titles/%016lx/%s", title_id, fn); snprintf(path, sizeof(path), "/atmosphere/titles/%016lx/%s", title_id, fn);
} }
}
return fsFsOpenFile(&g_sd_filesystem, path, flags, out); return fsFsOpenFile(&g_sd_filesystem, path, flags, out);
} }