]> Chaos Git - corbenik/corbenik.git/commitdiff
Force regenerate cache when NAND CID changes
authorchaoskagami <chaos.kagami@gmail.com>
Fri, 19 Aug 2016 19:43:07 +0000 (15:43 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Fri, 19 Aug 2016 21:47:03 +0000 (17:47 -0400)
source/config-file.c
source/main.c

index cfdaaa16a31ba86bb399f037d3a57c751632a29e..fbaa4970f92991fc17bde6f4edabf71b187cfedf 100644 (file)
@@ -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")))
index cb5185fdc3631b5fac1a5896e4cf7d2ac9103344..43855d813314d6de508a6c7a40b16c8f143948c7 100644 (file)
@@ -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();
 }