]> glassweightruler.freedombox.rocks Git - Ventoy.git/commitdiff
1. Disable Fn hotkey during secondary boot menu.
authorlongpanda <admin@ventoy.net>
Sat, 24 Sep 2022 13:06:29 +0000 (21:06 +0800)
committerlongpanda <admin@ventoy.net>
Sat, 24 Sep 2022 13:06:29 +0000 (21:06 +0800)
2. Recover boot mode after boot fail from secondary boot menu.

GRUB2/MOD_SRC/grub-2.04/grub-core/normal/menu.c
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_cmd.c
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h
INSTALL/grub/grub.cfg

index 5f6bef00df6eb14306e20c08cebe13b60624ea57..aa23be3b05d83183614c807cc624f36a062db19d 100644 (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;
-
-        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 ();
+                g_ventoy_iso_uefi_drv = 1 - g_ventoy_iso_uefi_drv;
+                g_ventoy_menu_refresh = 1;
                 goto refresh;
             }
             break;
-        }
-        case (GRUB_TERM_CTRL | 'm'):
-        case 'm':
+        case (GRUB_TERM_CTRL | 'h'):
+        case 'h':
         {
-            if (g_ventoy_cur_img_path)
+            if (0 == g_ventoy_secondary_menu_on)
             {
-                grub_env_set("VTOY_CHKSUM_FILE_PATH", g_ventoy_cur_img_path);
-                cmdstr = grub_env_get("VTOY_CHKSUM_CMD");
+                cmdstr = grub_env_get("VTOY_HELP_CMD");
                 if (cmdstr)
                 {
-                    menu_fini();
                     grub_script_execute_sourcecode(cmdstr);
+                    while (grub_getkey() != GRUB_TERM_ESC)
+                        ;
+                    menu_fini ();
                     goto refresh;
-                }
+                }                
             }
-            else
-            {
-                grub_env_set("VTOY_CHKSUM_FILE_PATH", "X");
+            break;
+        }
+        case (GRUB_TERM_CTRL | 'm'):
+        case 'm':
+        {
+            if (0 == g_ventoy_secondary_menu_on)
+            {                
+                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)
+                    {
+                        menu_fini();
+                        grub_script_execute_sourcecode(cmdstr);
+                        goto refresh;
+                    }
+                }
+                else
+                {
+                    grub_env_set("VTOY_CHKSUM_FILE_PATH", "X");
+                }
             }
             break;
         }
index 2c4e0e063558574a2bcaac02776ba68d58bfe2a6..113050c656f7f60f37bcc774ad3a64319b90ff0d 100644 (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)
index 42235c67cb484e6a6ce795fcd1596b8eb7cf08e0..705f965a433988d11deea1ed29cae3513309dfdb 100644 (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;
index 8b5396fad14f9dde03757c2892a4fef7027a16c0..3e000d9a391031f07e6a0dc278bb9ce82e6f2380 100644 (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 {