mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-12 11:02:28 +00:00
loader/fs.mitm: Support override config changes at runtime
This commit is contained in:
parent
e61bb00d7a
commit
f96e1d5074
4 changed files with 34 additions and 33 deletions
|
@ -34,6 +34,9 @@ static std::atomic_bool g_has_hid_session = false;
|
|||
static u64 g_override_key_combination = KEY_R;
|
||||
static bool g_override_by_default = true;
|
||||
|
||||
/* Static buffer for loader.ini contents at runtime. */
|
||||
static char g_config_ini_data[0x800];
|
||||
|
||||
static bool IsHexadecimal(const char *str) {
|
||||
while (*str) {
|
||||
if (isxdigit(*str)) {
|
||||
|
@ -93,12 +96,7 @@ void Utils::InitializeSdThreadFunc(void *args) {
|
|||
fsDirClose(&titles_dir);
|
||||
}
|
||||
|
||||
FsFile config_file;
|
||||
if (R_SUCCEEDED(fsFsOpenFile(&g_sd_filesystem, "/atmosphere/loader.ini", FS_OPEN_READ, &config_file))) {
|
||||
Utils::LoadConfiguration(&config_file);
|
||||
fsFileClose(&config_file);
|
||||
}
|
||||
|
||||
Utils::RefreshConfiguration();
|
||||
|
||||
g_has_initialized = true;
|
||||
|
||||
|
@ -251,6 +249,9 @@ bool Utils::HasOverrideButton(u64 tid) {
|
|||
return true;
|
||||
}
|
||||
|
||||
/* Unconditionally refresh loader.ini contents. */
|
||||
RefreshConfiguration();
|
||||
|
||||
u64 kDown = 0;
|
||||
bool keys_triggered = (R_SUCCEEDED(GetKeysDown(&kDown)) && ((kDown & g_override_key_combination) != 0));
|
||||
return IsSdInitialized() && (g_override_by_default ^ keys_triggered);
|
||||
|
@ -314,27 +315,26 @@ static int FsMitMIniHandler(void *user, const char *section, const char *name, c
|
|||
}
|
||||
|
||||
|
||||
void Utils::LoadConfiguration(FsFile *f) {
|
||||
if (f == NULL) {
|
||||
void Utils::RefreshConfiguration() {
|
||||
FsFile config_file;
|
||||
if (R_FAILED(fsFsOpenFile(&g_sd_filesystem, "/atmosphere/loader.ini", FS_OPEN_READ, &config_file))) {
|
||||
return;
|
||||
}
|
||||
|
||||
u64 size;
|
||||
if (R_FAILED(fsFileGetSize(f, &size))) {
|
||||
if (R_FAILED(fsFileGetSize(&config_file, &size))) {
|
||||
return;
|
||||
}
|
||||
|
||||
size = std::min(size, (decltype(size))0x7FF);
|
||||
|
||||
char *config_str = new char[0x800];
|
||||
if (config_str != NULL) {
|
||||
/* Read in string. */
|
||||
std::fill(config_str, config_str + 0x800, 0);
|
||||
size_t r_s;
|
||||
fsFileRead(f, 0, config_str, size, &r_s);
|
||||
/* Read in string. */
|
||||
std::fill(g_config_ini_data, g_config_ini_data + 0x800, 0);
|
||||
size_t r_s;
|
||||
fsFileRead(&config_file, 0, g_config_ini_data, size, &r_s);
|
||||
|
||||
ini_parse_string(g_config_ini_data, FsMitMIniHandler, NULL);
|
||||
|
||||
ini_parse_string(config_str, FsMitMIniHandler, NULL);
|
||||
|
||||
delete[] config_str;
|
||||
}
|
||||
|
||||
fsFileClose(&config_file);
|
||||
}
|
|
@ -45,5 +45,5 @@ class Utils {
|
|||
static Result GetKeysDown(u64 *keys);
|
||||
static bool HasOverrideButton(u64 tid);
|
||||
private:
|
||||
static void LoadConfiguration(FsFile *f);
|
||||
static void RefreshConfiguration();
|
||||
};
|
|
@ -40,6 +40,9 @@ static u64 g_override_key_combination = KEY_R;
|
|||
static bool g_override_by_default = true;
|
||||
static u64 g_override_hbl_tid = 0x010000000000100D;
|
||||
|
||||
/* Static buffer for loader.ini contents at runtime. */
|
||||
static char g_config_ini_data[0x800];
|
||||
|
||||
Result ContentManagement::MountCode(u64 tid, FsStorageId sid) {
|
||||
char path[FS_MAX_PATH] = {0};
|
||||
Result rc;
|
||||
|
@ -49,6 +52,10 @@ Result ContentManagement::MountCode(u64 tid, FsStorageId sid) {
|
|||
TryMountSdCard();
|
||||
}
|
||||
|
||||
if (g_has_initialized_fs_dev) {
|
||||
RefreshConfigurationData();
|
||||
}
|
||||
|
||||
if (ShouldOverrideContents() && R_SUCCEEDED(MountCodeNspOnSd(tid))) {
|
||||
return 0x0;
|
||||
}
|
||||
|
@ -259,23 +266,17 @@ static int LoaderIniHandler(void *user, const char *section, const char *name, c
|
|||
return 1;
|
||||
}
|
||||
|
||||
void ContentManagement::LoadConfiguration(FILE *config) {
|
||||
void ContentManagement::RefreshConfigurationData() {
|
||||
FILE *config = fopen("sdmc:/atmosphere/loader.ini", "r");
|
||||
if (config == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
char *config_str = new char[0x800];
|
||||
if (config_str != NULL) {
|
||||
/* Read in string. */
|
||||
std::fill(config_str, config_str + 0x800, 0);
|
||||
fread(config_str, 1, 0x7FF, config);
|
||||
|
||||
ini_parse_string(config_str, LoaderIniHandler, NULL);
|
||||
|
||||
delete[] config_str;
|
||||
}
|
||||
|
||||
std::fill(g_config_ini_data, g_config_ini_data + 0x800, 0);
|
||||
fread(g_config_ini_data, 1, 0x7FF, config);
|
||||
fclose(config);
|
||||
|
||||
ini_parse_string(g_config_ini_data, LoaderIniHandler, NULL);
|
||||
}
|
||||
|
||||
void ContentManagement::TryMountSdCard() {
|
||||
|
@ -292,7 +293,6 @@ void ContentManagement::TryMountSdCard() {
|
|||
}
|
||||
|
||||
if (R_SUCCEEDED(fsdevMountSdmc())) {
|
||||
ContentManagement::LoadConfiguration(fopen("sdmc:/atmosphere/loader.ini", "r"));
|
||||
g_has_initialized_fs_dev = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ class ContentManagement {
|
|||
|
||||
static bool HasCreatedTitle(u64 tid);
|
||||
static void SetCreatedTitle(u64 tid);
|
||||
static void RefreshConfigurationData();
|
||||
static void LoadConfiguration(FILE *config);
|
||||
static void TryMountSdCard();
|
||||
|
||||
|
|
Loading…
Reference in a new issue