mirror of
https://github.com/ventoy/Ventoy.git
synced 2025-01-27 14:43:25 -05:00
Add parent option in menu_class plugin.
This commit is contained in:
parent
c6be35f2c0
commit
e1099e1e5b
@ -1436,7 +1436,7 @@ static int ventoy_collect_img_files(const char *filename, const struct grub_dirh
|
|||||||
g_ventoy_img_count++;
|
g_ventoy_img_count++;
|
||||||
|
|
||||||
img->alias = ventoy_plugin_get_menu_alias(vtoy_alias_image_file, img->path);
|
img->alias = ventoy_plugin_get_menu_alias(vtoy_alias_image_file, img->path);
|
||||||
img->class = ventoy_plugin_get_menu_class(vtoy_class_image_file, img->name);
|
img->class = ventoy_plugin_get_menu_class(vtoy_class_image_file, img->name, img->path);
|
||||||
if (!img->class)
|
if (!img->class)
|
||||||
{
|
{
|
||||||
img->class = g_menu_class[type];
|
img->class = g_menu_class[type];
|
||||||
@ -1695,7 +1695,7 @@ static int ventoy_dynamic_tree_menu(img_iterator_node *node)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
node->dir[node->dirlen - 1] = 0;
|
node->dir[node->dirlen - 1] = 0;
|
||||||
dir_class = ventoy_plugin_get_menu_class(vtoy_class_directory, node->dir);
|
dir_class = ventoy_plugin_get_menu_class(vtoy_class_directory, node->dir, node->dir);
|
||||||
if (!dir_class)
|
if (!dir_class)
|
||||||
{
|
{
|
||||||
dir_class = "vtoydir";
|
dir_class = "vtoydir";
|
||||||
|
@ -830,6 +830,7 @@ typedef struct menu_class
|
|||||||
{
|
{
|
||||||
int type;
|
int type;
|
||||||
int patlen;
|
int patlen;
|
||||||
|
int parent;
|
||||||
char pattern[256];
|
char pattern[256];
|
||||||
char class[64];
|
char class[64];
|
||||||
|
|
||||||
@ -960,7 +961,7 @@ int ventoy_fill_windows_rtdata(void *buf, char *isopath);
|
|||||||
int ventoy_plugin_get_persistent_chunklist(const char *isopath, int index, ventoy_img_chunk_list *chunk_list);
|
int ventoy_plugin_get_persistent_chunklist(const char *isopath, int index, ventoy_img_chunk_list *chunk_list);
|
||||||
const char * ventoy_plugin_get_injection(const char *isopath);
|
const char * ventoy_plugin_get_injection(const char *isopath);
|
||||||
const char * ventoy_plugin_get_menu_alias(int type, const char *isopath);
|
const char * ventoy_plugin_get_menu_alias(int type, const char *isopath);
|
||||||
const char * ventoy_plugin_get_menu_class(int type, const char *name);
|
const char * ventoy_plugin_get_menu_class(int type, const char *name, const char *path);
|
||||||
int ventoy_plugin_check_memdisk(const char *isopath);
|
int ventoy_plugin_check_memdisk(const char *isopath);
|
||||||
int ventoy_plugin_get_image_list_index(int type, const char *name);
|
int ventoy_plugin_get_image_list_index(int type, const char *name);
|
||||||
conf_replace * ventoy_plugin_find_conf_replace(const char *iso);
|
conf_replace * ventoy_plugin_find_conf_replace(const char *iso);
|
||||||
|
@ -1305,6 +1305,7 @@ static int ventoy_plugin_injection_entry(VTOY_JSON *json, const char *isodisk)
|
|||||||
static int ventoy_plugin_menuclass_entry(VTOY_JSON *json, const char *isodisk)
|
static int ventoy_plugin_menuclass_entry(VTOY_JSON *json, const char *isodisk)
|
||||||
{
|
{
|
||||||
int type;
|
int type;
|
||||||
|
int parent = 0;
|
||||||
const char *key = NULL;
|
const char *key = NULL;
|
||||||
const char *class = NULL;
|
const char *class = NULL;
|
||||||
VTOY_JSON *pNode = NULL;
|
VTOY_JSON *pNode = NULL;
|
||||||
@ -1333,12 +1334,21 @@ static int ventoy_plugin_menuclass_entry(VTOY_JSON *json, const char *isodisk)
|
|||||||
|
|
||||||
for (pNode = json->pstChild; pNode; pNode = pNode->pstNext)
|
for (pNode = json->pstChild; pNode; pNode = pNode->pstNext)
|
||||||
{
|
{
|
||||||
|
parent = 0;
|
||||||
type = vtoy_class_image_file;
|
type = vtoy_class_image_file;
|
||||||
key = vtoy_json_get_string_ex(pNode->pstChild, "key");
|
key = vtoy_json_get_string_ex(pNode->pstChild, "key");
|
||||||
if (!key)
|
if (!key)
|
||||||
{
|
{
|
||||||
key = vtoy_json_get_string_ex(pNode->pstChild, "dir");
|
key = vtoy_json_get_string_ex(pNode->pstChild, "parent");
|
||||||
type = vtoy_class_directory;
|
if (key)
|
||||||
|
{
|
||||||
|
parent = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
key = vtoy_json_get_string_ex(pNode->pstChild, "dir");
|
||||||
|
type = vtoy_class_directory;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class = vtoy_json_get_string_ex(pNode->pstChild, "class");
|
class = vtoy_json_get_string_ex(pNode->pstChild, "class");
|
||||||
@ -1348,6 +1358,7 @@ static int ventoy_plugin_menuclass_entry(VTOY_JSON *json, const char *isodisk)
|
|||||||
if (node)
|
if (node)
|
||||||
{
|
{
|
||||||
node->type = type;
|
node->type = type;
|
||||||
|
node->parent = parent;
|
||||||
node->patlen = grub_snprintf(node->pattern, sizeof(node->pattern), "%s", key);
|
node->patlen = grub_snprintf(node->pattern, sizeof(node->pattern), "%s", key);
|
||||||
grub_snprintf(node->class, sizeof(node->class), "%s", class);
|
grub_snprintf(node->class, sizeof(node->class), "%s", class);
|
||||||
|
|
||||||
@ -1369,7 +1380,7 @@ static int ventoy_plugin_menuclass_entry(VTOY_JSON *json, const char *isodisk)
|
|||||||
|
|
||||||
static int ventoy_plugin_menuclass_check(VTOY_JSON *json, const char *isodisk)
|
static int ventoy_plugin_menuclass_check(VTOY_JSON *json, const char *isodisk)
|
||||||
{
|
{
|
||||||
int type;
|
const char *name = NULL;
|
||||||
const char *key = NULL;
|
const char *key = NULL;
|
||||||
const char *class = NULL;
|
const char *class = NULL;
|
||||||
VTOY_JSON *pNode = NULL;
|
VTOY_JSON *pNode = NULL;
|
||||||
@ -1384,18 +1395,23 @@ static int ventoy_plugin_menuclass_check(VTOY_JSON *json, const char *isodisk)
|
|||||||
|
|
||||||
for (pNode = json->pstChild; pNode; pNode = pNode->pstNext)
|
for (pNode = json->pstChild; pNode; pNode = pNode->pstNext)
|
||||||
{
|
{
|
||||||
type = vtoy_class_image_file;
|
name = "key";
|
||||||
key = vtoy_json_get_string_ex(pNode->pstChild, "key");
|
key = vtoy_json_get_string_ex(pNode->pstChild, "key");
|
||||||
if (!key)
|
if (!key)
|
||||||
{
|
{
|
||||||
key = vtoy_json_get_string_ex(pNode->pstChild, "dir");
|
name = "parent";
|
||||||
type = vtoy_class_directory;
|
key = vtoy_json_get_string_ex(pNode->pstChild, "parent");
|
||||||
|
if (!key)
|
||||||
|
{
|
||||||
|
name = "dir";
|
||||||
|
key = vtoy_json_get_string_ex(pNode->pstChild, "dir");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class = vtoy_json_get_string_ex(pNode->pstChild, "class");
|
class = vtoy_json_get_string_ex(pNode->pstChild, "class");
|
||||||
if (key && class)
|
if (key && class)
|
||||||
{
|
{
|
||||||
grub_printf("%s: <%s>\n", (type == vtoy_class_directory) ? "dir" : "key", key);
|
grub_printf("%s: <%s>\n", name, key);
|
||||||
grub_printf("class: <%s>\n\n", class);
|
grub_printf("class: <%s>\n\n", class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2182,7 +2198,7 @@ const char * ventoy_plugin_get_menu_alias(int type, const char *isopath)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * ventoy_plugin_get_menu_class(int type, const char *name)
|
const char * ventoy_plugin_get_menu_class(int type, const char *name, const char *path)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
menu_class *node = NULL;
|
menu_class *node = NULL;
|
||||||
@ -2191,21 +2207,38 @@ const char * ventoy_plugin_get_menu_class(int type, const char *name)
|
|||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = (int)grub_strlen(name);
|
|
||||||
|
|
||||||
if (vtoy_class_image_file == type)
|
if (vtoy_class_image_file == type)
|
||||||
{
|
{
|
||||||
for (node = g_menu_class_head; node; node = node->next)
|
for (node = g_menu_class_head; node; node = node->next)
|
||||||
{
|
{
|
||||||
if (node->type == type && node->patlen <= len && grub_strstr(name, node->pattern))
|
if (node->type != type)
|
||||||
{
|
{
|
||||||
return node->class;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node->parent)
|
||||||
|
{
|
||||||
|
len = (int)grub_strlen(path);
|
||||||
|
if ((node->patlen < len) && (path[node->patlen] == '/') &&
|
||||||
|
(grub_strncmp(path, node->pattern, node->patlen) == 0))
|
||||||
|
{
|
||||||
|
return node->class;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
len = (int)grub_strlen(name);
|
||||||
|
if ((node->patlen < len) && grub_strstr(name, node->pattern))
|
||||||
|
{
|
||||||
|
return node->class;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
len = (int)grub_strlen(name);
|
||||||
for (node = g_menu_class_head; node; node = node->next)
|
for (node = g_menu_class_head; node; node = node->next)
|
||||||
{
|
{
|
||||||
if (node->type == type && node->patlen == len && grub_strncmp(name, node->pattern, len) == 0)
|
if (node->type == type && node->patlen == len && grub_strncmp(name, node->pattern, len) == 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user