mirror of
https://github.com/ventoy/Ventoy.git
synced 2025-08-28 08:21:14 +00:00
1.0.53 release
This commit is contained in:
1603
GRUB2/MOD_SRC/grub-2.04/grub-core/font/font.c
Normal file
1603
GRUB2/MOD_SRC/grub-2.04/grub-core/font/font.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -59,11 +59,15 @@ struct grub_gui_label
|
||||
grub_font_t font;
|
||||
grub_video_rgba_color_t color;
|
||||
int value;
|
||||
int vtoytip;
|
||||
enum align_mode align;
|
||||
};
|
||||
|
||||
typedef struct grub_gui_label *grub_gui_label_t;
|
||||
|
||||
extern const char * g_ventoy_tip_msg1;
|
||||
extern const char * g_ventoy_tip_msg2;
|
||||
|
||||
static void
|
||||
label_destroy (void *vself)
|
||||
{
|
||||
@@ -90,6 +94,7 @@ label_is_instance (void *vself __attribute__((unused)), const char *type)
|
||||
static void
|
||||
label_paint (void *vself, const grub_video_rect_t *region)
|
||||
{
|
||||
const char *text;
|
||||
grub_gui_label_t self = vself;
|
||||
|
||||
if (! self->visible)
|
||||
@@ -98,16 +103,24 @@ label_paint (void *vself, const grub_video_rect_t *region)
|
||||
if (!grub_video_have_common_points (region, &self->bounds))
|
||||
return;
|
||||
|
||||
if (self->vtoytip == 1) {
|
||||
text = g_ventoy_tip_msg1 ? g_ventoy_tip_msg1 : "";
|
||||
} else if (self->vtoytip == 2) {
|
||||
text = g_ventoy_tip_msg2 ? g_ventoy_tip_msg2 : "";
|
||||
} else {
|
||||
text = self->text;
|
||||
}
|
||||
|
||||
/* Calculate the starting x coordinate. */
|
||||
int left_x;
|
||||
if (self->align == align_left)
|
||||
left_x = 0;
|
||||
else if (self->align == align_center)
|
||||
left_x = (self->bounds.width
|
||||
- grub_font_get_string_width (self->font, self->text)) / 2;
|
||||
- grub_font_get_string_width (self->font, text)) / 2;
|
||||
else if (self->align == align_right)
|
||||
left_x = (self->bounds.width
|
||||
- grub_font_get_string_width (self->font, self->text));
|
||||
- grub_font_get_string_width (self->font, text));
|
||||
else
|
||||
return; /* Invalid alignment. */
|
||||
|
||||
@@ -116,7 +129,7 @@ label_paint (void *vself, const grub_video_rect_t *region)
|
||||
|
||||
grub_video_rect_t vpsave;
|
||||
grub_gui_set_viewport (&self->bounds, &vpsave);
|
||||
grub_font_draw_string (self->text,
|
||||
grub_font_draw_string (text,
|
||||
self->font,
|
||||
grub_video_map_rgba_color (self->color),
|
||||
left_x,
|
||||
@@ -156,8 +169,8 @@ static void
|
||||
label_get_minimal_size (void *vself, unsigned *width, unsigned *height)
|
||||
{
|
||||
grub_gui_label_t self = vself;
|
||||
*width = grub_font_get_string_width (self->font, self->text);
|
||||
*height = (grub_font_get_ascent (self->font)
|
||||
*width = grub_font_get_string_width (self->font, self->text);
|
||||
*height = (grub_font_get_ascent (self->font)
|
||||
+ grub_font_get_descent (self->font));
|
||||
}
|
||||
|
||||
@@ -255,8 +268,14 @@ label_set_property (void *vself, const char *name, const char *value)
|
||||
{
|
||||
grub_gfxmenu_timeout_unregister ((grub_gui_component_t) self);
|
||||
grub_free (self->id);
|
||||
if (value)
|
||||
if (value) {
|
||||
self->id = grub_strdup (value);
|
||||
if (grub_strcmp(value, "VTOY_MENU_TIP_1") == 0) {
|
||||
self->vtoytip = 1;
|
||||
} else if (grub_strcmp(value, "VTOY_MENU_TIP_2") == 0) {
|
||||
self->vtoytip = 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
self->id = 0;
|
||||
if (self->id && grub_strcmp (self->id, GRUB_GFXMENU_TIMEOUT_COMPONENT_ID)
|
||||
|
@@ -733,6 +733,8 @@ done:
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
extern int g_menu_update_mode;
|
||||
|
||||
/* Set properties on the view based on settings from the specified
|
||||
theme file. */
|
||||
grub_err_t
|
||||
@@ -752,7 +754,7 @@ grub_gfxmenu_view_load_theme (grub_gfxmenu_view_t view, const char *theme_path)
|
||||
}
|
||||
|
||||
p.len = grub_file_size (file);
|
||||
p.buf = grub_malloc (p.len + 4096);
|
||||
p.buf = grub_malloc (p.len + 8192);
|
||||
p.pos = 0;
|
||||
p.line_num = 1;
|
||||
p.col_num = 1;
|
||||
@@ -781,6 +783,33 @@ grub_gfxmenu_view_load_theme (grub_gfxmenu_view_t view, const char *theme_path)
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const char *tip = grub_env_get("VTOY_MENU_TIP_ENABLE");
|
||||
if (tip && tip[0] == '1')
|
||||
{
|
||||
char tmpmsg[512];
|
||||
|
||||
grub_memset(tmpmsg, 'w', 500);
|
||||
tmpmsg[500] = 0;
|
||||
|
||||
g_menu_update_mode = 1;
|
||||
p.len += grub_snprintf(p.buf + p.len, 4096,
|
||||
"\n+ vbox{\n left = %s\n top = %s\n"
|
||||
"+ label { id=\"VTOY_MENU_TIP_1\" text = \"%s\" color = \"%s\" align = \"%s\"}\n"
|
||||
"+ label { id=\"VTOY_MENU_TIP_2\" text = \"%s\" color = \"%s\" align = \"%s\"}\n"
|
||||
"}\n",
|
||||
grub_env_get("VTOY_TIP_LEFT"),
|
||||
grub_env_get("VTOY_TIP_TOP"),
|
||||
tmpmsg,
|
||||
grub_env_get("VTOY_TIP_COLOR"),
|
||||
grub_env_get("VTOY_TIP_ALIGN"),
|
||||
tmpmsg,
|
||||
grub_env_get("VTOY_TIP_COLOR"),
|
||||
grub_env_get("VTOY_TIP_ALIGN")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (view->canvas)
|
||||
view->canvas->component.ops->destroy (view->canvas);
|
||||
|
||||
|
@@ -386,21 +386,37 @@ redraw_menu_visit (grub_gui_component_t component,
|
||||
}
|
||||
}
|
||||
|
||||
extern int g_menu_update_mode;
|
||||
|
||||
static void grub_gfxmenu_update_all(grub_gfxmenu_view_t view)
|
||||
{
|
||||
grub_video_set_area_status(GRUB_VIDEO_AREA_DISABLED);
|
||||
grub_gfxmenu_view_redraw(view, &view->screen);
|
||||
}
|
||||
|
||||
void
|
||||
grub_gfxmenu_redraw_menu (grub_gfxmenu_view_t view)
|
||||
{
|
||||
update_menu_components (view);
|
||||
|
||||
grub_gui_iterate_recursively ((grub_gui_component_t) view->canvas,
|
||||
redraw_menu_visit, view);
|
||||
if (g_menu_update_mode)
|
||||
grub_gfxmenu_update_all(view);
|
||||
else
|
||||
grub_gui_iterate_recursively ((grub_gui_component_t) view->canvas,
|
||||
redraw_menu_visit, view);
|
||||
|
||||
grub_video_swap_buffers ();
|
||||
if (view->double_repaint)
|
||||
{
|
||||
grub_gui_iterate_recursively ((grub_gui_component_t) view->canvas,
|
||||
redraw_menu_visit, view);
|
||||
if (g_menu_update_mode)
|
||||
grub_gfxmenu_update_all(view);
|
||||
else
|
||||
grub_gui_iterate_recursively ((grub_gui_component_t) view->canvas,
|
||||
redraw_menu_visit, view);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
grub_gfxmenu_set_chosen_entry (int entry, void *data)
|
||||
{
|
||||
@@ -408,6 +424,8 @@ grub_gfxmenu_set_chosen_entry (int entry, void *data)
|
||||
|
||||
view->selected = entry;
|
||||
grub_gfxmenu_redraw_menu (view);
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
|
@@ -33,6 +33,9 @@
|
||||
#include <grub/gfxterm.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/env.h>
|
||||
#include <grub/extcmd.h>
|
||||
#include <grub/ventoy.h>
|
||||
#include "ventoy/ventoy_def.h"
|
||||
|
||||
int g_ventoy_menu_refresh = 0;
|
||||
int g_ventoy_memdisk_mode = 0;
|
||||
@@ -381,10 +384,28 @@ grub_menu_execute_with_fallback (grub_menu_t menu,
|
||||
|
||||
static struct grub_menu_viewer *viewers;
|
||||
|
||||
int g_menu_update_mode = 0;
|
||||
int g_ventoy_tip_label_enable = 0;
|
||||
const char * g_ventoy_tip_msg1 = NULL;
|
||||
const char * g_ventoy_tip_msg2 = NULL;
|
||||
|
||||
static void
|
||||
menu_set_chosen_entry (int entry)
|
||||
menu_set_chosen_entry (grub_menu_t menu, int entry)
|
||||
{
|
||||
struct grub_menu_viewer *cur;
|
||||
img_info *img;
|
||||
grub_menu_entry_t e = grub_menu_get_entry (menu, entry);
|
||||
|
||||
g_ventoy_tip_msg1 = g_ventoy_tip_msg2 = NULL;
|
||||
if (e && e->id && grub_strncmp(e->id, "VID_", 4) == 0) {
|
||||
img = (img_info *)(void *)grub_strtoul(e->id + 4, NULL, 16);
|
||||
if (img)
|
||||
{
|
||||
g_ventoy_tip_msg1 = img->tip1;
|
||||
g_ventoy_tip_msg2 = img->tip2;
|
||||
}
|
||||
}
|
||||
|
||||
for (cur = viewers; cur; cur = cur->next)
|
||||
cur->set_chosen_entry (entry, cur->data);
|
||||
}
|
||||
@@ -732,13 +753,13 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
|
||||
case GRUB_TERM_KEY_HOME:
|
||||
case GRUB_TERM_CTRL | 'a':
|
||||
current_entry = 0;
|
||||
menu_set_chosen_entry (current_entry);
|
||||
menu_set_chosen_entry (menu, current_entry);
|
||||
break;
|
||||
|
||||
case GRUB_TERM_KEY_END:
|
||||
case GRUB_TERM_CTRL | 'e':
|
||||
current_entry = menu->size - 1;
|
||||
menu_set_chosen_entry (current_entry);
|
||||
menu_set_chosen_entry (menu, current_entry);
|
||||
break;
|
||||
|
||||
case GRUB_TERM_KEY_UP:
|
||||
@@ -746,7 +767,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
|
||||
case '^':
|
||||
if (current_entry > 0)
|
||||
current_entry--;
|
||||
menu_set_chosen_entry (current_entry);
|
||||
menu_set_chosen_entry (menu, current_entry);
|
||||
break;
|
||||
|
||||
case GRUB_TERM_CTRL | 'n':
|
||||
@@ -754,7 +775,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
|
||||
case 'v':
|
||||
if (current_entry < menu->size - 1)
|
||||
current_entry++;
|
||||
menu_set_chosen_entry (current_entry);
|
||||
menu_set_chosen_entry (menu, current_entry);
|
||||
break;
|
||||
|
||||
case GRUB_TERM_CTRL | 'g':
|
||||
@@ -763,7 +784,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
|
||||
current_entry = 0;
|
||||
else
|
||||
current_entry -= GRUB_MENU_PAGE_SIZE;
|
||||
menu_set_chosen_entry (current_entry);
|
||||
menu_set_chosen_entry (menu, current_entry);
|
||||
break;
|
||||
|
||||
case GRUB_TERM_CTRL | 'c':
|
||||
@@ -772,7 +793,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
|
||||
current_entry += GRUB_MENU_PAGE_SIZE;
|
||||
else
|
||||
current_entry = menu->size - 1;
|
||||
menu_set_chosen_entry (current_entry);
|
||||
menu_set_chosen_entry (menu, current_entry);
|
||||
break;
|
||||
|
||||
case '\n':
|
||||
|
@@ -1562,6 +1562,7 @@ static int ventoy_collect_img_files(const char *filename, const struct grub_dirh
|
||||
grub_size_t len;
|
||||
img_info *img;
|
||||
img_info *tail;
|
||||
const menu_tip *tip;
|
||||
img_iterator_node *tmp;
|
||||
img_iterator_node *new_node;
|
||||
img_iterator_node *node = (img_iterator_node *)data;
|
||||
@@ -1779,6 +1780,14 @@ static int ventoy_collect_img_files(const char *filename, const struct grub_dirh
|
||||
g_ventoy_img_count++;
|
||||
|
||||
img->alias = ventoy_plugin_get_menu_alias(vtoy_alias_image_file, img->path);
|
||||
|
||||
tip = ventoy_plugin_get_menu_tip(img->path);
|
||||
if (tip)
|
||||
{
|
||||
img->tip1 = tip->tip1;
|
||||
img->tip2 = tip->tip2;
|
||||
}
|
||||
|
||||
img->class = ventoy_plugin_get_menu_class(vtoy_class_image_file, img->name, img->path);
|
||||
if (!img->class)
|
||||
{
|
||||
@@ -2073,23 +2082,23 @@ static int ventoy_dynamic_tree_menu(img_iterator_node *node)
|
||||
if (g_tree_view_menu_style == 0)
|
||||
{
|
||||
vtoy_ssprintf(g_tree_script_buf, g_tree_script_pos,
|
||||
"menuentry \"%-10s %s%s\" --class=\"%s\" --id=\"VID_%d\" {\n"
|
||||
"menuentry \"%-10s %s%s\" --class=\"%s\" --id=\"VID_%p\" {\n"
|
||||
" %s_%s \n"
|
||||
"}\n",
|
||||
grub_get_human_size(img->size, GRUB_HUMAN_SIZE_SHORT),
|
||||
img->unsupport ? "[***********] " : "",
|
||||
img->alias ? img->alias : img->name, img->class, img->id,
|
||||
img->alias ? img->alias : img->name, img->class, img,
|
||||
img->menu_prefix,
|
||||
img->unsupport ? "unsupport_menuentry" : "common_menuentry");
|
||||
}
|
||||
else
|
||||
{
|
||||
vtoy_ssprintf(g_tree_script_buf, g_tree_script_pos,
|
||||
"menuentry \"%s%s\" --class=\"%s\" --id=\"VID_%d\" {\n"
|
||||
"menuentry \"%s%s\" --class=\"%s\" --id=\"VID_%p\" {\n"
|
||||
" %s_%s \n"
|
||||
"}\n",
|
||||
img->unsupport ? "[***********] " : "",
|
||||
img->alias ? img->alias : img->name, img->class, img->id,
|
||||
img->alias ? img->alias : img->name, img->class, img,
|
||||
img->menu_prefix,
|
||||
img->unsupport ? "unsupport_menuentry" : "common_menuentry");
|
||||
}
|
||||
@@ -2136,7 +2145,7 @@ static int ventoy_set_default_menu(void)
|
||||
|
||||
if (0 == g_default_menu_mode)
|
||||
{
|
||||
vtoy_ssprintf(g_list_script_buf, g_list_script_pos, "set default='VID_%d'\n", default_node->id);
|
||||
vtoy_ssprintf(g_list_script_buf, g_list_script_pos, "set default='VID_%p'\n", default_node);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2169,7 +2178,7 @@ static int ventoy_set_default_menu(void)
|
||||
pos = end + 1;
|
||||
}
|
||||
|
||||
vtoy_ssprintf(g_tree_script_buf, g_tree_script_pos, "VID_%d'\n", default_node->id);
|
||||
vtoy_ssprintf(g_tree_script_buf, g_tree_script_pos, "VID_%p'\n", default_node);
|
||||
grub_free(def);
|
||||
}
|
||||
}
|
||||
@@ -2266,7 +2275,7 @@ static grub_err_t ventoy_cmd_ext_select_img_path(grub_extcmd_context_t ctxt, int
|
||||
return grub_error(GRUB_ERR_BAD_ARGUMENT, "No such image");
|
||||
}
|
||||
|
||||
grub_snprintf(id, sizeof(id), "VID_%d", cur->id);
|
||||
grub_snprintf(id, sizeof(id), "VID_%p", cur);
|
||||
grub_env_set("chosen", id);
|
||||
grub_env_export("chosen");
|
||||
|
||||
@@ -2275,11 +2284,10 @@ static grub_err_t ventoy_cmd_ext_select_img_path(grub_extcmd_context_t ctxt, int
|
||||
|
||||
static grub_err_t ventoy_cmd_chosen_img_path(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
int img_id = 0;
|
||||
char value[32];
|
||||
char *pos = NULL;
|
||||
const char *id = NULL;
|
||||
img_info *cur = g_ventoy_img_list;
|
||||
img_info *cur = NULL;
|
||||
|
||||
(void)ctxt;
|
||||
|
||||
@@ -2293,20 +2301,11 @@ static grub_err_t ventoy_cmd_chosen_img_path(grub_extcmd_context_t ctxt, int arg
|
||||
pos = grub_strstr(id, "VID_");
|
||||
if (pos)
|
||||
{
|
||||
img_id = (int)grub_strtoul(pos + 4, NULL, 10);
|
||||
cur = (img_info *)(void *)grub_strtoul(pos + 4, NULL, 16);
|
||||
}
|
||||
else
|
||||
{
|
||||
img_id = (int)grub_strtoul(id, NULL, 10);
|
||||
}
|
||||
|
||||
while (cur)
|
||||
{
|
||||
if (img_id == cur->id)
|
||||
{
|
||||
break;
|
||||
}
|
||||
cur = cur->next;
|
||||
cur = g_ventoy_img_list;
|
||||
}
|
||||
|
||||
if (!cur)
|
||||
@@ -2335,12 +2334,14 @@ static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char
|
||||
grub_device_t dev = NULL;
|
||||
img_info *cur = NULL;
|
||||
img_info *tail = NULL;
|
||||
img_info *min = NULL;
|
||||
img_info *head = NULL;
|
||||
const char *strdata = NULL;
|
||||
char *device_name = NULL;
|
||||
char buf[32];
|
||||
img_iterator_node *node = NULL;
|
||||
img_iterator_node *tmp = NULL;
|
||||
|
||||
|
||||
(void)ctxt;
|
||||
|
||||
if (argc != 2)
|
||||
@@ -2470,17 +2471,49 @@ static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char
|
||||
}
|
||||
|
||||
/* sort image list by image name */
|
||||
for (cur = g_ventoy_img_list; cur; cur = cur->next)
|
||||
while (g_ventoy_img_list)
|
||||
{
|
||||
for (tail = cur->next; tail; tail = tail->next)
|
||||
min = g_ventoy_img_list;
|
||||
for (cur = g_ventoy_img_list->next; cur; cur = cur->next)
|
||||
{
|
||||
if (ventoy_cmp_img(cur, tail) > 0)
|
||||
if (ventoy_cmp_img(min, cur) > 0)
|
||||
{
|
||||
ventoy_swap_img(cur, tail);
|
||||
min = cur;
|
||||
}
|
||||
}
|
||||
|
||||
if (min->prev)
|
||||
{
|
||||
min->prev->next = min->next;
|
||||
}
|
||||
|
||||
if (min->next)
|
||||
{
|
||||
min->next->prev = min->prev;
|
||||
}
|
||||
|
||||
if (min == g_ventoy_img_list)
|
||||
{
|
||||
g_ventoy_img_list = min->next;
|
||||
}
|
||||
|
||||
if (head == NULL)
|
||||
{
|
||||
head = tail = min;
|
||||
min->prev = NULL;
|
||||
min->next = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
tail->next = min;
|
||||
min->prev = tail;
|
||||
min->next = NULL;
|
||||
tail = min;
|
||||
}
|
||||
}
|
||||
|
||||
g_ventoy_img_list = head;
|
||||
|
||||
if (g_default_menu_mode == 1)
|
||||
{
|
||||
vtoy_ssprintf(g_list_script_buf, g_list_script_pos,
|
||||
@@ -2492,11 +2525,11 @@ static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char
|
||||
for (cur = g_ventoy_img_list; cur; cur = cur->next)
|
||||
{
|
||||
vtoy_ssprintf(g_list_script_buf, g_list_script_pos,
|
||||
"menuentry \"%s%s\" --class=\"%s\" --id=\"VID_%d\" {\n"
|
||||
"menuentry \"%s%s\" --class=\"%s\" --id=\"VID_%p\" {\n"
|
||||
" %s_%s \n"
|
||||
"}\n",
|
||||
cur->unsupport ? "[***********] " : "",
|
||||
cur->alias ? cur->alias : cur->name, cur->class, cur->id,
|
||||
cur->alias ? cur->alias : cur->name, cur->class, cur,
|
||||
cur->menu_prefix,
|
||||
cur->unsupport ? "unsupport_menuentry" : "common_menuentry");
|
||||
}
|
||||
@@ -4851,6 +4884,27 @@ static grub_err_t grub_cmd_gptpriority(grub_extcmd_context_t ctxt, int argc, cha
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* <BEGIN>: Deleted by longpanda, 20210916 PN:XX LABEL:XX */
|
||||
#if 0
|
||||
void ventoy_tip_set_menu_label(const char *vid)
|
||||
{
|
||||
img_info *node;
|
||||
|
||||
g_ventoy_tip_msg1 = g_ventoy_tip_msg2 = NULL;
|
||||
if (vid)
|
||||
{
|
||||
node = (img_info *)(void *)grub_strtoul(vid + 4, NULL, 16);
|
||||
if (node)
|
||||
{
|
||||
g_ventoy_tip_msg1 = node->tip1;
|
||||
g_ventoy_tip_msg2 = node->tip2;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* #if 0 */
|
||||
/* <END> : Deleted by longpanda, 20210916 PN:XX LABEL:XX */
|
||||
|
||||
int ventoy_env_init(void)
|
||||
{
|
||||
char buf[64];
|
||||
|
@@ -215,6 +215,8 @@ typedef struct img_info
|
||||
char name[256];
|
||||
|
||||
const char *alias;
|
||||
const char *tip1;
|
||||
const char *tip2;
|
||||
const char *class;
|
||||
const char *menu_prefix;
|
||||
|
||||
@@ -865,6 +867,17 @@ typedef struct menu_alias
|
||||
struct menu_alias *next;
|
||||
}menu_alias;
|
||||
|
||||
typedef struct menu_tip
|
||||
{
|
||||
int pathlen;
|
||||
char isopath[256];
|
||||
char tip1[1024];
|
||||
char tip2[1024];
|
||||
|
||||
struct menu_tip *next;
|
||||
}menu_tip;
|
||||
|
||||
|
||||
#define vtoy_class_image_file 0
|
||||
#define vtoy_class_directory 1
|
||||
|
||||
@@ -1017,6 +1030,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);
|
||||
const char * ventoy_plugin_get_injection(const char *isopath);
|
||||
const char * ventoy_plugin_get_menu_alias(int type, const char *isopath);
|
||||
const menu_tip * ventoy_plugin_get_menu_tip(const char *isopath);
|
||||
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_get_image_list_index(int type, const char *name);
|
||||
|
@@ -48,6 +48,7 @@ static install_template *g_install_template_head = NULL;
|
||||
static dud *g_dud_head = NULL;
|
||||
static menu_password *g_pwd_head = NULL;
|
||||
static persistence_config *g_persistence_head = NULL;
|
||||
static menu_tip *g_menu_tip_head = NULL;
|
||||
static menu_alias *g_menu_alias_head = NULL;
|
||||
static menu_class *g_menu_class_head = NULL;
|
||||
static custom_boot *g_custom_boot_head = NULL;
|
||||
@@ -1417,6 +1418,176 @@ static int ventoy_plugin_menualias_entry(VTOY_JSON *json, const char *isodisk)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ventoy_plugin_menutip_check(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
const char *path = NULL;
|
||||
const char *tip = NULL;
|
||||
VTOY_JSON *pNode = NULL;
|
||||
|
||||
(void)isodisk;
|
||||
|
||||
if (json->enDataType != JSON_TYPE_OBJECT)
|
||||
{
|
||||
grub_printf("Not object %d\n", json->enDataType);
|
||||
return 1;
|
||||
}
|
||||
|
||||
tip = vtoy_json_get_string_ex(json->pstChild, "left");
|
||||
if (tip)
|
||||
{
|
||||
grub_printf("left: <%s>\n", tip);
|
||||
}
|
||||
|
||||
tip = vtoy_json_get_string_ex(json->pstChild, "top");
|
||||
if (tip)
|
||||
{
|
||||
grub_printf("top: <%s>\n", tip);
|
||||
}
|
||||
|
||||
tip = vtoy_json_get_string_ex(json->pstChild, "color");
|
||||
if (tip)
|
||||
{
|
||||
grub_printf("color: <%s>\n", tip);
|
||||
}
|
||||
|
||||
pNode = vtoy_json_find_item(json->pstChild, JSON_TYPE_ARRAY, "tips");
|
||||
for (pNode = pNode->pstChild; pNode; pNode = pNode->pstNext)
|
||||
{
|
||||
path = vtoy_json_get_string_ex(pNode->pstChild, "image");
|
||||
if (path && path[0] == '/')
|
||||
{
|
||||
if (grub_strchr(path, '*'))
|
||||
{
|
||||
grub_printf("image: <%s> [ * ]\n", path);
|
||||
}
|
||||
else if (ventoy_check_file_exist("%s%s", isodisk, path))
|
||||
{
|
||||
grub_printf("image: <%s> [ OK ]\n", path);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf("image: <%s> [ NOT EXIST ]\n", path);
|
||||
}
|
||||
|
||||
tip = vtoy_json_get_string_ex(pNode->pstChild, "tip");
|
||||
if (tip)
|
||||
{
|
||||
grub_printf("tip: <%s>\n", tip);
|
||||
}
|
||||
else
|
||||
{
|
||||
tip = vtoy_json_get_string_ex(pNode->pstChild, "tip1");
|
||||
if (tip)
|
||||
grub_printf("tip1: <%s>\n", tip);
|
||||
else
|
||||
grub_printf("tip1: <NULL>\n");
|
||||
|
||||
tip = vtoy_json_get_string_ex(pNode->pstChild, "tip2");
|
||||
if (tip)
|
||||
grub_printf("tip2: <%s>\n", tip);
|
||||
else
|
||||
grub_printf("tip2: <NULL>\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf("image: <%s> [ INVALID ]\n", path);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ventoy_plugin_menutip_entry(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
const char *path = NULL;
|
||||
const char *tip = NULL;
|
||||
VTOY_JSON *pNode = NULL;
|
||||
menu_tip *node = NULL;
|
||||
menu_tip *next = NULL;
|
||||
|
||||
(void)isodisk;
|
||||
|
||||
if (json->enDataType != JSON_TYPE_OBJECT)
|
||||
{
|
||||
debug("Not object %d\n", json->enDataType);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pNode = vtoy_json_find_item(json->pstChild, JSON_TYPE_ARRAY, "tips");
|
||||
if (pNode == NULL)
|
||||
{
|
||||
debug("Not tips found\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (g_menu_tip_head)
|
||||
{
|
||||
for (node = g_menu_tip_head; node; node = next)
|
||||
{
|
||||
next = node->next;
|
||||
grub_free(node);
|
||||
}
|
||||
|
||||
g_menu_tip_head = NULL;
|
||||
}
|
||||
|
||||
tip = vtoy_json_get_string_ex(json->pstChild, "left");
|
||||
if (tip)
|
||||
{
|
||||
grub_env_set("VTOY_TIP_LEFT", tip);
|
||||
}
|
||||
|
||||
tip = vtoy_json_get_string_ex(json->pstChild, "top");
|
||||
if (tip)
|
||||
{
|
||||
grub_env_set("VTOY_TIP_TOP", tip);
|
||||
}
|
||||
|
||||
tip = vtoy_json_get_string_ex(json->pstChild, "color");
|
||||
if (tip)
|
||||
{
|
||||
grub_env_set("VTOY_TIP_COLOR", tip);
|
||||
}
|
||||
|
||||
for (pNode = pNode->pstChild; pNode; pNode = pNode->pstNext)
|
||||
{
|
||||
path = vtoy_json_get_string_ex(pNode->pstChild, "image");
|
||||
if (path && path[0] == '/')
|
||||
{
|
||||
node = grub_zalloc(sizeof(menu_tip));
|
||||
if (node)
|
||||
{
|
||||
node->pathlen = grub_snprintf(node->isopath, sizeof(node->isopath), "%s", path);
|
||||
|
||||
tip = vtoy_json_get_string_ex(pNode->pstChild, "tip");
|
||||
if (tip)
|
||||
{
|
||||
grub_snprintf(node->tip1, 1000, "%s", tip);
|
||||
}
|
||||
else
|
||||
{
|
||||
tip = vtoy_json_get_string_ex(pNode->pstChild, "tip1");
|
||||
if (tip)
|
||||
grub_snprintf(node->tip1, 1000, "%s", tip);
|
||||
|
||||
tip = vtoy_json_get_string_ex(pNode->pstChild, "tip2");
|
||||
if (tip)
|
||||
grub_snprintf(node->tip2, 1000, "%s", tip);
|
||||
}
|
||||
|
||||
if (g_menu_tip_head)
|
||||
{
|
||||
node->next = g_menu_tip_head;
|
||||
}
|
||||
|
||||
g_menu_tip_head = node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ventoy_plugin_injection_check(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
@@ -2101,6 +2272,7 @@ static plugin_entry g_plugin_entries[] =
|
||||
{ "auto_install", ventoy_plugin_auto_install_entry, ventoy_plugin_auto_install_check },
|
||||
{ "persistence", ventoy_plugin_persistence_entry, ventoy_plugin_persistence_check },
|
||||
{ "menu_alias", ventoy_plugin_menualias_entry, ventoy_plugin_menualias_check },
|
||||
{ "menu_tip", ventoy_plugin_menutip_entry, ventoy_plugin_menutip_check },
|
||||
{ "menu_class", ventoy_plugin_menuclass_entry, ventoy_plugin_menuclass_check },
|
||||
{ "injection", ventoy_plugin_injection_entry, ventoy_plugin_injection_check },
|
||||
{ "auto_memdisk", ventoy_plugin_auto_memdisk_entry, ventoy_plugin_auto_memdisk_check },
|
||||
@@ -2149,6 +2321,11 @@ grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **a
|
||||
(void)ctxt;
|
||||
(void)argc;
|
||||
|
||||
grub_env_set("VTOY_TIP_LEFT", "10%");
|
||||
grub_env_set("VTOY_TIP_TOP", "80%+5");
|
||||
grub_env_set("VTOY_TIP_COLOR", "blue");
|
||||
grub_env_set("VTOY_TIP_ALIGN", "left");
|
||||
|
||||
file = ventoy_grub_file_open(GRUB_FILE_TYPE_LINUX_INITRD, "%s/ventoy/ventoy.json", args[0]);
|
||||
if (!file)
|
||||
{
|
||||
@@ -2205,6 +2382,15 @@ grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **a
|
||||
}
|
||||
}
|
||||
|
||||
if (g_menu_tip_head)
|
||||
{
|
||||
grub_env_set("VTOY_MENU_TIP_ENABLE", "1");
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_env_unset("VTOY_MENU_TIP_ENABLE");
|
||||
}
|
||||
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
@@ -2465,6 +2651,28 @@ const char * ventoy_plugin_get_menu_alias(int type, const char *isopath)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const menu_tip * ventoy_plugin_get_menu_tip(const char *isopath)
|
||||
{
|
||||
int len;
|
||||
menu_tip *node = NULL;
|
||||
|
||||
if (!g_menu_tip_head)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
len = (int)grub_strlen(isopath);
|
||||
for (node = g_menu_tip_head; node; node = node->next)
|
||||
{
|
||||
if (node->pathlen == len && ventoy_strcmp(node->isopath, isopath) == 0)
|
||||
{
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char * ventoy_plugin_get_menu_class(int type, const char *name, const char *path)
|
||||
{
|
||||
int namelen;
|
||||
|
Reference in New Issue
Block a user