From eda930975649ac83b6fafe9cba4988e852b79131 Mon Sep 17 00:00:00 2001 From: chaoskagami Date: Fri, 19 Aug 2016 14:44:12 -0400 Subject: [PATCH] [2/2] Merge PATCHENABLE file into the config file --- include/option.h | 14 +------------- source/config-file.c | 17 +++++++++-------- source/menu.c | 35 +++++++++++------------------------ source/patcher.c | 34 ++++++++++++++++++++++++---------- 4 files changed, 45 insertions(+), 55 deletions(-) diff --git a/include/option.h b/include/option.h index e1a2f4f..04fc71b 100644 --- a/include/option.h +++ b/include/option.h @@ -1,7 +1,7 @@ #ifndef __CONFIG_H #define __CONFIG_H -#define config_version 1 ///< Static version of the config. Updated when the config has changed in an +#define config_version 2 ///< Static version of the config. Updated when the config has changed in an ///< incompatible way. #define CONFIG_MAGIC "OVAN" ///< Magic to identify config files. @@ -16,18 +16,6 @@ struct config_file uint8_t options[256]; ///< Options in the menu - deliberately large to avoid ///< config version bumps. - - uint64_t patch_ids[256]; ///< What patches are enabled by UUID. 256 is an - ///< arbitrary limit - contact me if you hit it. -} __attribute__((packed)); - -/* State of a patch file - */ -struct patch_state -{ - char filename[256]; ///< Patch filename. - - uint8_t state; ///< Status of patch. } __attribute__((packed)); #ifdef LOADER diff --git a/source/config-file.c b/source/config-file.c index f40ee34..cfdaaa1 100644 --- a/source/config-file.c +++ b/source/config-file.c @@ -21,7 +21,7 @@ regenerate_config() if (!(conf_handle = fopen(config_file_path, "w"))) poweroff(); - fwrite(config, 1, sizeof(struct config_file), conf_handle); + fwrite(config, 1, sizeof(struct config_file) + FCRAM_SPACING / 2, conf_handle); fclose(conf_handle); } @@ -91,15 +91,17 @@ load_config() cid[0] >>= 4; } - config = (struct config_file*)malloc(sizeof(struct config_file)); - memset(config, 0, sizeof(struct config_file)); + config = (struct config_file*)malloc(sizeof(struct config_file) + FCRAM_SPACING / 2); + memset(config, 0, sizeof(struct config_file) + FCRAM_SPACING / 2); + enable_list = (uint8_t*)config + sizeof(struct config_file); } // Zero on success. if (!(conf_handle = fopen(config_file_path, "r"))) { regenerate_config(); } else { - fread(config, 1, sizeof(struct config_file), conf_handle); + fread(config, 1, sizeof(struct config_file) + FCRAM_SPACING / 2, conf_handle); + fclose(conf_handle); if (memcmp(&(config->magic), CONFIG_MAGIC, 4)) { @@ -107,7 +109,7 @@ load_config() regenerate_config(); } - if (config->config_ver < config_version) { + if (config->config_ver != config_version) { f_unlink(config_file_path); regenerate_config(); } @@ -121,13 +123,12 @@ load_config() void save_config() { - write_file(enable_list, PATH_TEMP "/PATCHENABLE", FCRAM_SPACING / 2); - f_unlink(config_file_path); if (!(conf_handle = fopen(config_file_path, "w"))) while(1); - fwrite(config, 1, sizeof(struct config_file), conf_handle); + fwrite(config, 1, sizeof(struct config_file) + FCRAM_SPACING / 2, conf_handle); + fclose(conf_handle); } diff --git a/source/menu.c b/source/menu.c index eefe679..2fc7a21 100644 --- a/source/menu.c +++ b/source/menu.c @@ -4,7 +4,7 @@ // FIXME - Remove limit #define MAX_PATCHES 256 struct options_s *patches = NULL; -uint8_t *enable_list = NULL; +uint8_t *enable_list; static struct options_s options[] = { // Patches. @@ -105,35 +105,22 @@ list_patches_build(char *name, int desc_is_fname) current_menu_index_patches = 0; - if (!enable_list) - enable_list = malloc(FCRAM_SPACING / 2); // FIXME - the PATCHENABLE file has to go. Badly. + if (!patches) + patches = malloc(sizeof(struct options_s) * 258); // FIXME - hard limit. Implement realloc. - if (!patches) - patches = malloc(sizeof(struct options_s) * 258); // FIXME - hard limit. Implement realloc. + strncpy(patches[0].name, "Patches", 64); + strncpy(patches[0].desc, "", 255); + patches[0].index = 0; + patches[0].allowed = not_option; + patches[0].a = 1; + patches[0].b = 0; + patches[0].indent = 0; - memset(enable_list, 0, FCRAM_SPACING / 2); - - if (!desc_is_fname) { - strncpy(patches[0].name, "Patches", 64); - strncpy(patches[0].desc, "", 255); - patches[0].index = 0; - patches[0].allowed = not_option; - patches[0].a = 1; - patches[0].b = 0; - patches[0].indent = 0; - - current_menu_index_patches += 1; - } + current_menu_index_patches += 1; recurse_call(name, patch_func); patches[current_menu_index_patches].index = -1; - - FILE *f; - if ((f = fopen(PATH_TEMP "/PATCHENABLE", "r"))) { - fread(enable_list, 1, FCRAM_SPACING / 2, f); - fclose(f); - } } void diff --git a/source/patcher.c b/source/patcher.c index c0de558..8cdcfc5 100644 --- a/source/patcher.c +++ b/source/patcher.c @@ -25,25 +25,39 @@ wait() void list_patches_build(char *name, int desc_is_fname); -int -generate_patch_cache() +void +patch_cache_func(char* fpath) { - // Remove cache - rrmdir(PATH_LOADER_CACHE); - f_mkdir(PATH_LOADER_CACHE); + FILINFO f2; + if (f_stat(fpath, &f2) != FR_OK) + return; - list_patches_build(PATH_PATCHES, 1); + if (!(f2.fattrib & AM_DIR)) { + struct system_patch p; + read_file(&p, fpath, sizeof(struct system_patch)); - for (int i = 0; patches[i].index != -1; i++) { - if (enable_list[patches[i].index]) { + if (memcmp(p.magic, "AIDA", 4)) + return; + + if (enable_list[p.uuid]) { // Patch is enabled. Cache it. - if (execb(patches[i].desc, 1)) { - abort("Failed to apply:\n %s\n", patches[i].name); + if (execb(fpath, 1)) { + abort("Failed to cache:\n %s\n", fpath); } wait(); } } +} + +int +generate_patch_cache() +{ + // Remove cache + rrmdir(PATH_LOADER_CACHE); + f_mkdir(PATH_LOADER_CACHE); + + recurse_call(PATH_PATCHES, patch_cache_func); return 0; } -- 2.39.5