1. Disable Fn hotkey during secondary boot menu.

2. Recover boot mode after boot fail from secondary boot menu.
This commit is contained in:
longpanda 2022-09-24 21:06:29 +08:00
parent d58bd8c3f7
commit ebc5e2e993
4 changed files with 105 additions and 45 deletions

View File

@ -48,10 +48,11 @@ int g_ventoy_suppress_esc = 0;
int g_ventoy_suppress_esc_default = 1;
int g_ventoy_menu_esc = 0;
int g_ventoy_fn_mutex = 0;
int g_ventoy_secondary_menu_on = 0;
int g_ventoy_terminal_output = 0;
#define VTOY_COMM_HOTKEY(cmdkey) \
if (0 == g_ventoy_fn_mutex) { \
if (0 == g_ventoy_fn_mutex && 0 == g_ventoy_secondary_menu_on) { \
cmdstr = grub_env_get(cmdkey); \
if (cmdstr) \
{ \
@ -933,70 +934,91 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
goto refresh;
case GRUB_TERM_KEY_F1:
case '1':
menu_fini ();
g_ventoy_memdisk_mode = 1 - g_ventoy_memdisk_mode;
g_ventoy_menu_refresh = 1;
goto refresh;
if (0 == g_ventoy_secondary_menu_on)
{
menu_fini ();
g_ventoy_memdisk_mode = 1 - g_ventoy_memdisk_mode;
g_ventoy_menu_refresh = 1;
goto refresh;
}
break;
case (GRUB_TERM_CTRL | 'i'):
case 'i':
menu_fini ();
g_ventoy_iso_raw = 1 - g_ventoy_iso_raw;
g_ventoy_menu_refresh = 1;
goto refresh;
if (0 == g_ventoy_secondary_menu_on)
{
menu_fini ();
g_ventoy_iso_raw = 1 - g_ventoy_iso_raw;
g_ventoy_menu_refresh = 1;
goto refresh;
}
break;
case (GRUB_TERM_CTRL | 'r'):
case 'r':
menu_fini ();
g_ventoy_grub2_mode = 1 - g_ventoy_grub2_mode;
g_ventoy_menu_refresh = 1;
goto refresh;
if (0 == g_ventoy_secondary_menu_on)
{
menu_fini ();
g_ventoy_grub2_mode = 1 - g_ventoy_grub2_mode;
g_ventoy_menu_refresh = 1;
goto refresh;
}
break;
case (GRUB_TERM_CTRL | 'w'):
case 'w':
menu_fini ();
g_ventoy_wimboot_mode = 1 - g_ventoy_wimboot_mode;
g_ventoy_menu_refresh = 1;
goto refresh;
if (0 == g_ventoy_secondary_menu_on)
{
menu_fini ();
g_ventoy_wimboot_mode = 1 - g_ventoy_wimboot_mode;
g_ventoy_menu_refresh = 1;
goto refresh;
}
break;
case (GRUB_TERM_CTRL | 'u'):
case 'u':
menu_fini ();
g_ventoy_iso_uefi_drv = 1 - g_ventoy_iso_uefi_drv;
g_ventoy_menu_refresh = 1;
goto refresh;
if (0 == g_ventoy_secondary_menu_on)
{
menu_fini ();
g_ventoy_iso_uefi_drv = 1 - g_ventoy_iso_uefi_drv;
g_ventoy_menu_refresh = 1;
goto refresh;
}
break;
case (GRUB_TERM_CTRL | 'h'):
case 'h':
{
cmdstr = grub_env_get("VTOY_HELP_CMD");
if (cmdstr)
if (0 == g_ventoy_secondary_menu_on)
{
grub_script_execute_sourcecode(cmdstr);
while (grub_getkey() != GRUB_TERM_ESC)
;
menu_fini ();
goto refresh;
cmdstr = grub_env_get("VTOY_HELP_CMD");
if (cmdstr)
{
grub_script_execute_sourcecode(cmdstr);
while (grub_getkey() != GRUB_TERM_ESC)
;
menu_fini ();
goto refresh;
}
}
break;
}
case (GRUB_TERM_CTRL | 'm'):
case 'm':
{
if (g_ventoy_cur_img_path)
{
grub_env_set("VTOY_CHKSUM_FILE_PATH", g_ventoy_cur_img_path);
cmdstr = grub_env_get("VTOY_CHKSUM_CMD");
if (cmdstr)
if (0 == g_ventoy_secondary_menu_on)
{
if (g_ventoy_cur_img_path)
{
menu_fini();
grub_script_execute_sourcecode(cmdstr);
goto refresh;
grub_env_set("VTOY_CHKSUM_FILE_PATH", g_ventoy_cur_img_path);
cmdstr = grub_env_get("VTOY_CHKSUM_CMD");
if (cmdstr)
{
menu_fini();
grub_script_execute_sourcecode(cmdstr);
goto refresh;
}
}
else
{
grub_env_set("VTOY_CHKSUM_FILE_PATH", "X");
}
}
else
{
grub_env_set("VTOY_CHKSUM_FILE_PATH", "X");
}
break;
}

View File

@ -158,6 +158,8 @@ const char *g_menu_prefix[img_type_max] =
"iso", "wim", "efi", "img", "vhd", "vtoy"
};
static int g_vtoy_secondary_need_recover = 0;
static int g_vtoy_load_prompt = 0;
static char g_vtoy_prompt_msg[64];
@ -6009,6 +6011,7 @@ static grub_err_t ventoy_cmd_show_secondary_menu(grub_extcmd_context_t ctxt, int
return 1;
}
g_vtoy_secondary_need_recover = 0;
grub_env_unset("VTOY_CHKSUM_FILE_PATH");
env = grub_env_get("VTOY_SECONDARY_TIMEOUT");
@ -6049,25 +6052,30 @@ static grub_err_t ventoy_cmd_show_secondary_menu(grub_extcmd_context_t ctxt, int
g_ventoy_menu_esc = 1;
g_ventoy_suppress_esc = 1;
g_ventoy_suppress_esc_default = 0;
g_ventoy_secondary_menu_on = 1;
grub_snprintf(cfgfile, sizeof(cfgfile), "configfile mem:0x%llx:size:%d", (ulonglong)(ulong)cmd, pos);
grub_script_execute_sourcecode(cfgfile);
g_ventoy_menu_esc = 0;
g_ventoy_suppress_esc = 0;
g_ventoy_suppress_esc_default = 1;
g_ventoy_secondary_menu_on = 0;
select = seldata[g_ventoy_last_entry];
if (select == 2)
{
g_ventoy_wimboot_mode = 1;
g_vtoy_secondary_need_recover = 1;
}
else if (select == 3)
{
g_ventoy_grub2_mode = 1;
g_vtoy_secondary_need_recover = 2;
}
else if (select == 4)
{
g_ventoy_memdisk_mode = 1;
g_vtoy_secondary_need_recover = 3;
}
else if (select == 5)
{
@ -6080,6 +6088,30 @@ static grub_err_t ventoy_cmd_show_secondary_menu(grub_extcmd_context_t ctxt, int
return 0;
}
static grub_err_t ventoy_cmd_secondary_recover_mode(grub_extcmd_context_t ctxt, int argc, char **args)
{
(void)ctxt;
(void)argc;
(void)args;
if (g_vtoy_secondary_need_recover == 1)
{
g_ventoy_wimboot_mode = 0;
}
else if (g_vtoy_secondary_need_recover == 2)
{
g_ventoy_grub2_mode = 0;
}
else if (g_vtoy_secondary_need_recover == 3)
{
g_ventoy_memdisk_mode = 0;
}
g_vtoy_secondary_need_recover = 0;
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
static grub_err_t ventoy_cmd_fs_ignore_case(grub_extcmd_context_t ctxt, int argc, char **args)
{
(void)ctxt;
@ -6303,6 +6335,7 @@ static cmd_para ventoy_cmds[] =
{ "vt_show_secondary_menu", ventoy_cmd_show_secondary_menu, 0, NULL, "", "", NULL },
{ "vt_fs_ignore_case", ventoy_cmd_fs_ignore_case, 0, NULL, "", "", NULL },
{ "vt_systemd_menu", ventoy_cmd_linux_systemd_menu, 0, NULL, "", "", NULL },
{ "vt_secondary_recover_mode", ventoy_cmd_secondary_recover_mode, 0, NULL, "", "", NULL },
};
int ventoy_register_all_cmd(void)

View File

@ -1039,6 +1039,7 @@ typedef struct menu_password
}menu_password;
extern int g_ventoy_menu_esc;
extern int g_ventoy_secondary_menu_on;
extern int g_ventoy_suppress_esc;
extern int g_ventoy_suppress_esc_default;
extern int g_ventoy_last_entry;

View File

@ -936,6 +936,7 @@ function uefi_iso_menu_func {
vt_show_secondary_menu "$vt_chosen_path" "$vtoy_os" $vt_chosen_size
if vt_check_mode 0 "$vt_chosen_name"; then
uefi_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
vt_secondary_recover_mode
return
fi
fi
@ -957,6 +958,7 @@ function uefi_iso_menu_func {
fi
ventoy_gui_console
vt_secondary_recover_mode
}
function uefi_iso_memdisk {
@ -1368,6 +1370,7 @@ function legacy_iso_menu_func {
vt_show_secondary_menu "$vt_chosen_path" "$vtoy_os" $vt_chosen_size
if vt_check_mode 0 "$vt_chosen_name"; then
legacy_iso_memdisk $vtoy_iso_part "$vt_chosen_path"
vt_secondary_recover_mode
return
fi
fi
@ -1387,6 +1390,7 @@ function legacy_iso_menu_func {
vt_check_compatible_linux (loop)
legacy_linux_menu_func "$1" "${chosen_path}"
fi
vt_secondary_recover_mode
}
function legacy_iso_memdisk {