]> glassweightruler.freedombox.rocks Git - Ventoy.git/commitdiff
Add timeout option for auto_install/persistence plugin (#1161)
authorlongpanda <admin@ventoy.net>
Wed, 20 Oct 2021 09:00:20 +0000 (17:00 +0800)
committerlongpanda <admin@ventoy.net>
Wed, 20 Oct 2021 09:00:20 +0000 (17:00 +0800)
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
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_plugin.c
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_windows.c

index 9b1d3140b10018ad1ae5293de38673d8713a0d93..c83c911b5f74c7719a8cd47c45631a4a219d56de 100644 (file)
@@ -45,6 +45,7 @@ int g_ventoy_wimboot_mode = 0;
 int g_ventoy_iso_uefi_drv = 0;
 int g_ventoy_last_entry = -1;
 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_terminal_output = 0;
@@ -639,7 +640,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
   default_entry = get_entry_number (menu, "default");
 
   if (g_ventoy_suppress_esc)
-      default_entry = 1;
+      default_entry = g_ventoy_suppress_esc_default;
   else if (g_ventoy_last_entry >= 0 && g_ventoy_last_entry < menu->size) {
       default_entry = g_ventoy_last_entry;
   } 
@@ -1036,6 +1037,11 @@ show_menu (grub_menu_t menu, int nested, int autobooted)
               break;          
       }
 
+      if (autobooted == 0 && g_ventoy_menu_esc && auto_boot) {
+          g_ventoy_last_entry = boot_entry;
+          break;
+      }
+
       e = grub_menu_get_entry (menu, boot_entry);
       if (! e)
        continue; /* Menu is empty.  */
index b7e7ce0a00ceb15bae7d969fd11b4b72987bbdcb..3a6f5c9b1291d96cfbdc08d6efcd8c3d8f1273f4 100644 (file)
@@ -2969,6 +2969,7 @@ static grub_err_t ventoy_cmd_sel_auto_install(grub_extcmd_context_t ctxt, int ar
 {
     int i = 0;
     int pos = 0;
+    int defidx = 1;
     char *buf = NULL;
     char configfile[128];
     install_template *node = NULL;
@@ -2993,9 +2994,13 @@ static grub_err_t ventoy_cmd_sel_auto_install(grub_extcmd_context_t ctxt, int ar
 
     if (node->autosel >= 0 && node->autosel <= node->templatenum)
     {
-        node->cursel = node->autosel - 1;
-        debug("Auto install template auto select %d\n", node->autosel);
-        return 0;
+        defidx = node->autosel;
+        if (node->timeout < 0)
+        {
+            node->cursel = node->autosel - 1;
+            debug("Auto install template auto select %d\n", node->autosel);
+            return 0;
+        }
     }
 
     buf = (char *)grub_malloc(VTOY_MAX_SCRIPT_BUF);
@@ -3004,24 +3009,31 @@ static grub_err_t ventoy_cmd_sel_auto_install(grub_extcmd_context_t ctxt, int ar
         return 0;
     }
 
+    if (node->timeout > 0)
+    {
+        vtoy_ssprintf(buf, pos, "set timeout=%d\n", node->timeout);        
+    }
+    
     vtoy_ssprintf(buf, pos, "menuentry \"Boot without auto installation template\" {\n"
-                  "  echo %s\n}\n", "123");
+                  "  echo %s\n}\n", "");
 
     for (i = 0; i < node->templatenum; i++)
     {
-        vtoy_ssprintf(buf, pos, "menuentry \"Boot with %s\" {\n"
-                  "  echo 123\n}\n",
+        vtoy_ssprintf(buf, pos, "menuentry \"Boot with %s\"{\n"
+                  "  echo \"\"\n}\n",
                   node->templatepath[i].path);
     }
 
     g_ventoy_menu_esc = 1;
     g_ventoy_suppress_esc = 1;
+    g_ventoy_suppress_esc_default = defidx;
 
     grub_snprintf(configfile, sizeof(configfile), "configfile mem:0x%llx:size:%d", (ulonglong)(ulong)buf, pos);
     grub_script_execute_sourcecode(configfile);
     
     g_ventoy_menu_esc = 0;
     g_ventoy_suppress_esc = 0;
+    g_ventoy_suppress_esc_default = 1;
 
     grub_free(buf);
 
@@ -3034,6 +3046,7 @@ static grub_err_t ventoy_cmd_sel_persistence(grub_extcmd_context_t ctxt, int arg
 {
     int i = 0;
     int pos = 0;
+    int defidx = 1;
     char *buf = NULL;
     char configfile[128];
     persistence_config *node;
@@ -3058,9 +3071,13 @@ static grub_err_t ventoy_cmd_sel_persistence(grub_extcmd_context_t ctxt, int arg
 
     if (node->autosel >= 0 && node->autosel <= node->backendnum)
     {
-        node->cursel = node->autosel - 1;
-        debug("Persistence image auto select %d\n", node->autosel);
-        return 0;
+        defidx = node->autosel;
+        if (node->timeout < 0)
+        {
+            node->cursel = node->autosel - 1;
+            debug("Persistence image auto select %d\n", node->autosel);
+            return 0;            
+        }
     }
 
     buf = (char *)grub_malloc(VTOY_MAX_SCRIPT_BUF);
@@ -3069,25 +3086,32 @@ static grub_err_t ventoy_cmd_sel_persistence(grub_extcmd_context_t ctxt, int arg
         return 0;
     }
 
+    if (node->timeout > 0)
+    {
+        vtoy_ssprintf(buf, pos, "set timeout=%d\n", node->timeout);        
+    }
+
     vtoy_ssprintf(buf, pos, "menuentry \"Boot without persistence\" {\n"
-                  "  echo %s\n}\n", "123");
+                  "  echo %s\n}\n", "");
     
     for (i = 0; i < node->backendnum; i++)
     {
         vtoy_ssprintf(buf, pos, "menuentry \"Boot with %s\" {\n"
-                      "  echo 123\n}\n",
+                      "  echo \"\"\n}\n",
                       node->backendpath[i].path);
         
     }
 
     g_ventoy_menu_esc = 1;
     g_ventoy_suppress_esc = 1;
-
+    g_ventoy_suppress_esc_default = defidx;
+    
     grub_snprintf(configfile, sizeof(configfile), "configfile mem:0x%llx:size:%d", (ulonglong)(ulong)buf, pos);
     grub_script_execute_sourcecode(configfile);
     
     g_ventoy_menu_esc = 0;
     g_ventoy_suppress_esc = 0;
+    g_ventoy_suppress_esc_default = 1;
 
     grub_free(buf);
 
index 1099cefb7087b6404f86f05cabcab4cc2cb60648..3c51aa61296cad3110d044f52b77ad42b19b9233 100644 (file)
@@ -829,6 +829,7 @@ typedef struct install_template
     int pathlen;
     char isopath[256];
 
+    int timeout;
     int autosel;
     int cursel;
     int templatenum;
@@ -860,6 +861,7 @@ typedef struct persistence_config
     int pathlen;
     char isopath[256];
 
+    int timeout;
     int autosel;
     int cursel;
     int backendnum;
@@ -987,6 +989,7 @@ typedef struct menu_password
 
 extern int g_ventoy_menu_esc;
 extern int g_ventoy_suppress_esc;
+extern int g_ventoy_suppress_esc_default;
 extern int g_ventoy_last_entry;
 extern int g_ventoy_memdisk_mode;
 extern int g_ventoy_iso_raw;
index 591ed2651d3d55a063929a746a5731a06804ddc3..53c1142baadaf8bb5e0ffabedcfb7b321038a323 100644 (file)
@@ -602,6 +602,7 @@ static int ventoy_plugin_auto_install_check(VTOY_JSON *json, const char *isodisk
 {
     int pathnum = 0;
     int autosel = 0;
+    int timeout = 0;
     char *pos = NULL;
     const char *iso = NULL;
     VTOY_JSON *pNode = NULL;
@@ -638,6 +639,18 @@ static int ventoy_plugin_auto_install_check(VTOY_JSON *json, const char *isodisk
                         grub_printf("autosel: %d [FAIL]\n", autosel);
                     }
                 }
+                
+                if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "timeout", &timeout))
+                {
+                    if (timeout >= 0)
+                    {
+                        grub_printf("timeout: %d [OK]\n", timeout);
+                    }
+                    else
+                    {
+                        grub_printf("timeout: %d [FAIL]\n", timeout);
+                    }
+                }
             }
             else
             {
@@ -662,6 +675,18 @@ static int ventoy_plugin_auto_install_check(VTOY_JSON *json, const char *isodisk
                         grub_printf("autosel: %d [FAIL]\n", autosel);
                     }
                 }
+                
+                if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "timeout", &timeout))
+                {
+                    if (timeout >= 0)
+                    {
+                        grub_printf("timeout: %d [OK]\n", timeout);
+                    }
+                    else
+                    {
+                        grub_printf("timeout: %d [FAIL]\n", timeout);
+                    }
+                }
             }
             else
             {
@@ -682,6 +707,7 @@ static int ventoy_plugin_auto_install_entry(VTOY_JSON *json, const char *isodisk
     int type = 0;
     int pathnum = 0;
     int autosel = 0;
+    int timeout = 0;
     const char *iso = NULL;
     VTOY_JSON *pNode = NULL;
     install_template *node = NULL;
@@ -729,6 +755,7 @@ static int ventoy_plugin_auto_install_entry(VTOY_JSON *json, const char *isodisk
                     node->templatenum = pathnum;
 
                     node->autosel = -1;
+                    node->timeout = -1;
                     if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "autosel", &autosel))
                     {
                         if (autosel >= 0 && autosel <= pathnum)
@@ -736,6 +763,14 @@ static int ventoy_plugin_auto_install_entry(VTOY_JSON *json, const char *isodisk
                             node->autosel = autosel;
                         }
                     }
+                    
+                    if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "timeout", &timeout))
+                    {
+                        if (timeout >= 0)
+                        {
+                            node->timeout = timeout;
+                        }
+                    }
 
                     if (g_install_template_head)
                     {
@@ -1175,6 +1210,7 @@ static int ventoy_plugin_pwd_check(VTOY_JSON *json, const char *isodisk)
 static int ventoy_plugin_persistence_check(VTOY_JSON *json, const char *isodisk)
 {
     int autosel = 0;
+    int timeout = 0;
     int pathnum = 0;
     char *pos = NULL;
     const char *iso = NULL;
@@ -1213,6 +1249,18 @@ static int ventoy_plugin_persistence_check(VTOY_JSON *json, const char *isodisk)
                         grub_printf("autosel: %d [FAIL]\n", autosel);
                     }
                 }
+                
+                if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "timeout", &timeout))
+                {
+                    if (timeout >= 0)
+                    {
+                        grub_printf("timeout: %d [OK]\n", timeout);
+                    }
+                    else
+                    {
+                        grub_printf("timeout: %d [FAIL]\n", timeout);
+                    }
+                }
             } 
             else
             {
@@ -1231,6 +1279,7 @@ static int ventoy_plugin_persistence_check(VTOY_JSON *json, const char *isodisk)
 static int ventoy_plugin_persistence_entry(VTOY_JSON *json, const char *isodisk)
 {
     int autosel = 0;
+    int timeout = 0;
     int pathnum = 0;
     const char *iso = NULL;
     VTOY_JSON *pNode = NULL;
@@ -1273,6 +1322,7 @@ static int ventoy_plugin_persistence_entry(VTOY_JSON *json, const char *isodisk)
                     node->backendnum = pathnum;
 
                     node->autosel = -1;
+                    node->timeout = -1;
                     if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "autosel", &autosel))
                     {
                         if (autosel >= 0 && autosel <= pathnum)
@@ -1280,6 +1330,14 @@ static int ventoy_plugin_persistence_entry(VTOY_JSON *json, const char *isodisk)
                             node->autosel = autosel;
                         }
                     }
+                    
+                    if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "timeout", &timeout))
+                    {
+                        if (timeout >= 0)
+                        {
+                            node->timeout = timeout;
+                        }
+                    }
 
                     if (g_persistence_head)
                     {
index b2e986bcd2afc925b49cc97c29e2f1230fb626d2..4e605093c052cb4f133c41a8aaec970e0fd95022 100644 (file)
@@ -375,6 +375,7 @@ grub_err_t ventoy_cmd_sel_wimboot(grub_extcmd_context_t ctxt, int argc, char **a
 
     g_ventoy_menu_esc = 1;
     g_ventoy_suppress_esc = 1;
+    g_ventoy_suppress_esc_default = 1;
 
     grub_snprintf(configfile, sizeof(configfile), "configfile mem:0x%llx:size:%d", (ulonglong)(ulong)buf, size);
     grub_script_execute_sourcecode(configfile);