+static int ventoy_plugin_custom_boot_entry(VTOY_JSON *json, const char *isodisk)
+{
+ int type;
+ int len;
+ const char *key = NULL;
+ const char *cfg = NULL;
+ VTOY_JSON *pNode = NULL;
+ custom_boot *tail = NULL;
+ custom_boot *node = NULL;
+ custom_boot *next = NULL;
+
+ (void)isodisk;
+
+ if (json->enDataType != JSON_TYPE_ARRAY)
+ {
+ debug("Not array %d\n", json->enDataType);
+ return 0;
+ }
+
+ if (g_custom_boot_head)
+ {
+ for (node = g_custom_boot_head; node; node = next)
+ {
+ next = node->next;
+ grub_free(node);
+ }
+
+ g_custom_boot_head = NULL;
+ }
+
+ for (pNode = json->pstChild; pNode; pNode = pNode->pstNext)
+ {
+ type = vtoy_custom_boot_image_file;
+ key = vtoy_json_get_string_ex(pNode->pstChild, "file");
+ if (!key)
+ {
+ key = vtoy_json_get_string_ex(pNode->pstChild, "dir");
+ type = vtoy_custom_boot_directory;
+ }
+
+ cfg = vtoy_json_get_string_ex(pNode->pstChild, "vcfg");
+ if (key && cfg)
+ {
+ node = grub_zalloc(sizeof(custom_boot));
+ if (node)
+ {
+ node->type = type;
+ node->pathlen = grub_snprintf(node->path, sizeof(node->path), "%s", key);
+ len = (int)grub_snprintf(node->cfg, sizeof(node->cfg), "%s", cfg);
+
+ if (len >= 5 && grub_strncmp(node->cfg + len - 5, ".vcfg", 5) == 0)
+ {
+ if (g_custom_boot_head)
+ {
+ tail->next = node;
+ }
+ else
+ {
+ g_custom_boot_head = node;
+ }
+ tail = node;
+ }
+ else
+ {
+ grub_free(node);
+ }
+ }
+ }
+ }
+
+ return 0;
+}
+
+static int ventoy_plugin_custom_boot_check(VTOY_JSON *json, const char *isodisk)
+{
+ int type;
+ int len;
+ const char *key = NULL;
+ const char *cfg = NULL;
+ VTOY_JSON *pNode = NULL;
+
+ (void)isodisk;
+
+ if (json->enDataType != JSON_TYPE_ARRAY)
+ {
+ grub_printf("Not array %d\n", json->enDataType);
+ return 1;
+ }
+
+ for (pNode = json->pstChild; pNode; pNode = pNode->pstNext)
+ {
+ type = vtoy_custom_boot_image_file;
+ key = vtoy_json_get_string_ex(pNode->pstChild, "file");
+ if (!key)
+ {
+ key = vtoy_json_get_string_ex(pNode->pstChild, "dir");
+ type = vtoy_custom_boot_directory;
+ }
+
+ cfg = vtoy_json_get_string_ex(pNode->pstChild, "vcfg");
+ len = (int)grub_strlen(cfg);
+ if (key && cfg)
+ {
+ if (len < 5 || grub_strncmp(cfg + len - 5, ".vcfg", 5))
+ {
+ grub_printf("<%s> does not have \".vcfg\" suffix\n\n", cfg);
+ }
+ else
+ {
+ grub_printf("%s: <%s>\n", (type == vtoy_custom_boot_directory) ? "dir" : "file", key);
+ grub_printf("vcfg: <%s>\n\n", cfg);
+ }
+ }
+ }
+
+ return 0;
+}
+