From: chaoskagami Date: Fri, 19 Aug 2016 19:43:07 +0000 (-0400) Subject: Force regenerate cache when NAND CID changes X-Git-Tag: v0.3.0~48 X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=999b7952b4d35842b8623c22abf6c35af780310c;p=corbenik%2Fcorbenik.git Force regenerate cache when NAND CID changes --- diff --git a/source/config-file.c b/source/config-file.c index cfdaaa1..fbaa497 100644 --- a/source/config-file.c +++ b/source/config-file.c @@ -5,6 +5,8 @@ FILE *conf_handle; struct config_file *config; extern uint8_t *enable_list; char *config_file_path; +int changed_consoles = 0; +uint32_t cid[4]; void list_patches_build(char *name, int desc_is_fname); @@ -79,9 +81,24 @@ load_config() config_file_path = malloc(256); // MAX_PATH memset(config_file_path, 0, 256); - uint32_t cid[4]; sdmmc_get_cid(1, cid); + FILE* f = fopen(SYSCONFDIR "/current-nand-cid", "r"); + if (!f) { + // Nonexistent. Write it. + f = fopen(SYSCONFDIR "/current-nand-cid", "w"); + fwrite(cid, 1, 4, f); + fclose(f); + f = fopen(SYSCONFDIR "/current-nand-cid", "r"); + } + + fread(&cid[1], 1, 4, f); + + // If our console's CID doesn't match what was read, we need to regenerate caches immediately when we can. + if (cid[0] != cid[1]) { + changed_consoles = 1; + } + strcpy(config_file_path, SYSCONFDIR "/config-"); size_t len = strlen(config_file_path) + 7; @@ -123,6 +140,12 @@ load_config() void save_config() { + if (changed_consoles) { + FILE* f = fopen(SYSCONFDIR "/current-nand-cid", "w"); + fwrite(cid, 1, 4, f); + fclose(f); + } + f_unlink(config_file_path); if (!(conf_handle = fopen(config_file_path, "w"))) diff --git a/source/main.c b/source/main.c index cb5185f..43855d8 100644 --- a/source/main.c +++ b/source/main.c @@ -11,6 +11,8 @@ int doing_autoboot = 0; int menu_handler(); void shut_up(); +extern int changed_consoles; + int main(int argc, char** argv) { @@ -55,5 +57,11 @@ main(int argc, char** argv) menu_handler(); } + if (changed_consoles) { + fprintf(stderr, "Console changed, regenerating caches\n"); + save_config(); + generate_patch_cache(); + } + boot_cfw(); }