The configuration must be the first line in theme.txt and must be in the following format.
ventoy_left_top_color: "@5%@95%@#0000ff@"
The format is very strict:
1. ventoy_left_top_color must start with no space in front of.
2. left/top/color options must be around with 4 @
if (! view->title_text)
return grub_errno;
}
+ else if (! grub_strcmp ("ventoy_left_top_color", name))
+ return grub_errno;
else
{
return grub_error (GRUB_ERR_BAD_ARGUMENT,
return 0;
}
+static global_var_cfg g_global_vars[] =
+{
+ { "gfxmode", "1024x768", NULL },
+ { ventoy_left_key, "5%", NULL },
+ { ventoy_top_key, "95%", NULL },
+ { ventoy_color_key, "#0000ff", NULL },
+ { NULL, NULL, NULL }
+};
+
+static const char * ventoy_global_var_read_hook(struct grub_env_var *var, const char *val)
+{
+ int i;
+
+ for (i = 0; g_global_vars[i].name; i++)
+ {
+ if (grub_strcmp(g_global_vars[i].name, var->name) == 0)
+ {
+ return g_global_vars[i].value;
+ }
+ }
+
+ return val;
+}
+
+static char * ventoy_global_var_write_hook(struct grub_env_var *var, const char *val)
+{
+ int i;
+
+ for (i = 0; g_global_vars[i].name; i++)
+ {
+ if (grub_strcmp(g_global_vars[i].name, var->name) == 0)
+ {
+ grub_check_free(g_global_vars[i].value);
+ g_global_vars[i].value = grub_strdup(val);
+ break;
+ }
+ }
+
+ return grub_strdup(val);
+}
+
+int ventoy_global_var_init(void)
+{
+ int i;
+
+ for (i = 0; g_global_vars[i].name; i++)
+ {
+ g_global_vars[i].value = grub_strdup(g_global_vars[i].defval);
+ ventoy_env_export(g_global_vars[i].name, g_global_vars[i].defval);
+ grub_register_variable_hook(g_global_vars[i].name, ventoy_global_var_read_hook, ventoy_global_var_write_hook);
+ }
+
+ return 0;
+}
+
+static ctrl_var_cfg g_ctrl_vars[] =
+{
+ { "VTOY_WIN11_BYPASS_CHECK", 0 },
+ { "VTOY_LINUX_REMOUNT", 0 },
+ { "VTOY_SECONDARY_BOOT_MENU", 1 },
+ { NULL, 0 }
+};
+
+static const char * ventoy_ctrl_var_read_hook(struct grub_env_var *var, const char *val)
+{
+ int i;
+
+ for (i = 0; g_ctrl_vars[i].name; i++)
+ {
+ if (grub_strcmp(g_ctrl_vars[i].name, var->name) == 0)
+ {
+ return g_ctrl_vars[i].value ? "1" : "0";
+ }
+ }
+
+ return val;
+}
+
+static char * ventoy_ctrl_var_write_hook(struct grub_env_var *var, const char *val)
+{
+ int i;
+
+ for (i = 0; g_ctrl_vars[i].name; i++)
+ {
+ if (grub_strcmp(g_ctrl_vars[i].name, var->name) == 0)
+ {
+ if (val && val[0] == '1' && val[1] == 0)
+ {
+ g_ctrl_vars[i].value = 1;
+ return grub_strdup("1");
+ }
+ else
+ {
+ g_ctrl_vars[i].value = 0;
+ return grub_strdup("0");
+ }
+ }
+ }
+
+ return grub_strdup(val);
+}
+
+int ventoy_ctrl_var_init(void)
+{
+ int i;
+
+ for (i = 0; g_ctrl_vars[i].name; i++)
+ {
+ ventoy_env_export(g_ctrl_vars[i].name, g_ctrl_vars[i].value ? "1" : "0");
+ grub_register_variable_hook(g_ctrl_vars[i].name, ventoy_ctrl_var_read_hook, ventoy_ctrl_var_write_hook);
+ }
+
+ return 0;
+}
+
GRUB_MOD_INIT(ventoy)
{
ventoy_hwinfo_init();
static int g_pager_flag = 0;
static char g_old_pager[32];
-static char g_vtoy_gfxmode[64];
-
const char *g_menu_class[img_type_max] =
{
"vtoyiso", "vtoywim", "vtoyefi", "vtoyimg", "vtoyvhd", "vtoyvtoy"
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
+static int ventoy_pre_parse_data(char *src, int size)
+{
+ char c;
+ char *pos = NULL;
+ char buf[256];
+
+ if (size < 20 || grub_strncmp(src, "ventoy_left_top_color", 21))
+ {
+ return 0;
+ }
+
+ pos = src + 21;
+ while (*pos && *pos != '\r' && *pos != '\n')
+ {
+ pos++;
+ }
+
+ c = *pos;
+ *pos = 0;
+
+ if (grub_strlen(src) > 200)
+ {
+ goto end;
+ }
+
+ grub_snprintf(buf, sizeof(buf),
+ "regexp -s 1:%s -s 2:%s -s 3:%s \"@([^@]*)@([^@]*)@([^@]*)@\" \"%s\"",
+ ventoy_left_key, ventoy_top_key, ventoy_color_key, src);
+
+ grub_script_execute_sourcecode(buf);
+
+end:
+ *pos = c;
+ return 0;
+}
+
static grub_file_t ventoy_wrapper_open(grub_file_t rawFile, enum grub_file_type type)
{
int len;
}
grub_file_read(rawFile, file->data, rawFile->size);
+ ventoy_pre_parse_data((char *)file->data, (int)rawFile->size);
len = ventoy_fill_data(4096, (char *)file->data + rawFile->size);
g_old_file = rawFile;
return ventoy_get_vmenu_title(val);
}
-static const char * ventoy_gfxmode_read_hook(struct grub_env_var *var, const char *val)
-{
- (void)var;
- (void)val;
-
- return g_vtoy_gfxmode;
-}
-
-static char * ventoy_gfxmode_write_hook(struct grub_env_var *var, const char *val)
-{
- (void)var;
-
- grub_strncpy(g_vtoy_gfxmode, val, sizeof(g_vtoy_gfxmode) - 1);
- return grub_strdup(val);
-}
-
-static ctrl_var_cfg g_ctrl_vars[] =
-{
- { "VTOY_WIN11_BYPASS_CHECK", 0 },
- { "VTOY_LINUX_REMOUNT", 0 },
- { "VTOY_SECONDARY_BOOT_MENU", 1 },
- { NULL, 0 }
-};
-
-static const char * ventoy_ctrl_var_read_hook(struct grub_env_var *var, const char *val)
-{
- int i;
-
- for (i = 0; g_ctrl_vars[i].name; i++)
- {
- if (grub_strcmp(g_ctrl_vars[i].name, var->name) == 0)
- {
- return g_ctrl_vars[i].value ? "1" : "0";
- }
- }
-
- return val;
-}
-
-static char * ventoy_ctrl_var_write_hook(struct grub_env_var *var, const char *val)
-{
- int i;
-
- for (i = 0; g_ctrl_vars[i].name; i++)
- {
- if (grub_strcmp(g_ctrl_vars[i].name, var->name) == 0)
- {
- if (val && val[0] == '1' && val[1] == 0)
- {
- g_ctrl_vars[i].value = 1;
- return grub_strdup("1");
- }
- else
- {
- g_ctrl_vars[i].value = 0;
- return grub_strdup("0");
- }
- }
- }
-
- return grub_strdup(val);
-}
-
-static int ventoy_ctrl_var_init(void)
-{
- int i;
-
- for (i = 0; g_ctrl_vars[i].name; i++)
- {
- ventoy_env_export(g_ctrl_vars[i].name, g_ctrl_vars[i].value ? "1" : "0");
- grub_register_variable_hook(g_ctrl_vars[i].name, ventoy_ctrl_var_read_hook, ventoy_ctrl_var_write_hook);
- }
-
- return 0;
-}
-
int ventoy_env_init(void)
{
int i;
grub_env_set("vtdebug_flag", "");
- grub_register_variable_hook("gfxmode", ventoy_gfxmode_read_hook, ventoy_gfxmode_write_hook);
grub_register_vtoy_menu_lang_hook(ventoy_menu_lang_read_hook);
-
ventoy_ctrl_var_init();
+ ventoy_global_var_init();
g_part_list_buf = grub_malloc(VTOY_PART_BUF_LEN);
g_tree_script_buf = grub_malloc(VTOY_MAX_SCRIPT_BUF);
#define VTOY_ARCH_CPIO "ventoy_x86.cpio"
#endif
+#define ventoy_left_key "VTLE_LFT"
+#define ventoy_top_key "VTLE_TOP"
+#define ventoy_color_key "VTLE_CLR"
+
#define ventoy_varg_4(arg) arg[0], arg[1], arg[2], arg[3]
#define ventoy_varg_8(arg) arg[0], arg[1], arg[2], arg[3], arg[4], arg[5], arg[6], arg[7]
int len;
}systemd_menu_ctx;
+typedef struct global_var_cfg
+{
+ const char *name;
+ const char *defval;
+ char *value;
+}global_var_cfg;
+
typedef struct ctrl_var_cfg
{
const char *name;
const char *ventoy_get_vmenu_title(const char *vMenu);
grub_err_t ventoy_cmd_cur_menu_lang(grub_extcmd_context_t ctxt, int argc, char **args);
extern int ventoy_menu_push_key(int code);
+int ventoy_ctrl_var_init(void);
+int ventoy_global_var_init(void);
#endif /* __VENTOY_DEF_H__ */
value = vtoy_json_get_string_ex(json->pstChild, "ventoy_left");
if (value)
{
- ventoy_env_export("VTLE_LFT", value);
+ ventoy_env_export(ventoy_left_key, value);
}
value = vtoy_json_get_string_ex(json->pstChild, "ventoy_top");
if (value)
{
- ventoy_env_export("VTLE_TOP", value);
+ ventoy_env_export(ventoy_top_key, value);
}
value = vtoy_json_get_string_ex(json->pstChild, "ventoy_color");
if (value)
{
- ventoy_env_export("VTLE_CLR", value);
+ ventoy_env_export(ventoy_color_key, value);
}
node = vtoy_json_find_item(json->pstChild, JSON_TYPE_ARRAY, "fonts");