]> Chaos Git - corbenik/corbenik.git/commitdiff
[2/2] Merge PATCHENABLE file into the config file
authorchaoskagami <chaos.kagami@gmail.com>
Fri, 19 Aug 2016 18:44:12 +0000 (14:44 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Fri, 19 Aug 2016 21:47:03 +0000 (17:47 -0400)
include/option.h
source/config-file.c
source/menu.c
source/patcher.c

index e1a2f4fb5bec04352aa0252e151b19497268623d..04fc71bfde0d03ba855e031a400df3a12dd6617e 100644 (file)
@@ -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
index f40ee34dd3c32bcf40d04b26bec676f9e5f41e3d..cfdaaa16a31ba86bb399f037d3a57c751632a29e 100644 (file)
@@ -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);
 }
index eefe679dd1c7e2d9a509e0080db97b0c542cd875..2fc7a21d4e06d1a93b63545a50838c4b4a861609 100644 (file)
@@ -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
index c0de558b2f64fd32e2d09eb1fe76ff42968528f3..8cdcfc5905362ee1e7e7a7b9cdb6c29806e0c7a0 100644 (file)
@@ -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;
 }