Auto use memdisk/grub2/wimboot mode if the ISO file name has _VTMEMDISK/_VTGRUB2/_VTWIMBOOT suffix. (e.g. ubuntu-22.04-desktop-amd64_VTGRUB2.iso)

This commit is contained in:
longpanda 2022-06-08 10:15:56 +08:00
parent bf2517bb25
commit 1c0b4ee903
2 changed files with 89 additions and 19 deletions

View File

@ -3715,20 +3715,70 @@ static grub_err_t ventoy_cmd_dump_persistence(grub_extcmd_context_t ctxt, int ar
return 0; return 0;
} }
static int ventoy_check_mode_by_name(char *filename, const char *suffix)
{
int i;
int len1;
int len2;
len1 = (int)grub_strlen(filename);
len2 = (int)grub_strlen(suffix);
if (len1 <= len2)
{
return 0;
}
for (i = len1 - 1; i >= 0; i--)
{
if (filename[i] == '.')
{
break;
}
}
if (i < len2 + 1)
{
return 0;
}
if (filename[i - len2 - 1] != '_')
{
return 0;
}
if (grub_strncasecmp(filename + (i - len2), suffix, len2) == 0)
{
return 1;
}
return 0;
}
static grub_err_t ventoy_cmd_check_mode(grub_extcmd_context_t ctxt, int argc, char **args) static grub_err_t ventoy_cmd_check_mode(grub_extcmd_context_t ctxt, int argc, char **args)
{ {
(void)ctxt; (void)ctxt;
(void)argc; (void)argc;
(void)args; (void)args;
if (argc != 1) if (argc != 1 && argc != 2)
{ {
return 1; return 1;
} }
if (args[0][0] == '0') if (args[0][0] == '0')
{ {
return g_ventoy_memdisk_mode ? 0 : 1; if (g_ventoy_memdisk_mode)
{
return 0;
}
if (argc == 2 && ventoy_check_mode_by_name(args[1], "vtmemdisk"))
{
return 0;
}
return 1;
} }
else if (args[0][0] == '1') else if (args[0][0] == '1')
{ {
@ -3740,11 +3790,31 @@ static grub_err_t ventoy_cmd_check_mode(grub_extcmd_context_t ctxt, int argc, ch
} }
else if (args[0][0] == '3') else if (args[0][0] == '3')
{ {
return g_ventoy_grub2_mode ? 0 : 1; if (g_ventoy_grub2_mode)
{
return 0;
}
if (argc == 2 && ventoy_check_mode_by_name(args[1], "vtgrub2"))
{
return 0;
}
return 1;
} }
else if (args[0][0] == '4') else if (args[0][0] == '4')
{ {
return g_ventoy_wimboot_mode ? 0 : 1; if (g_ventoy_wimboot_mode)
{
return 0;
}
if (argc == 2 && ventoy_check_mode_by_name(args[1], "vtwimboot"))
{
return 0;
}
return 1;
} }
return 1; return 1;

View File

@ -621,7 +621,7 @@ function uefi_windows_menu_func {
vt_windows_chain_data "${1}${chosen_path}" vt_windows_chain_data "${1}${chosen_path}"
ventoy_debug_pause ventoy_debug_pause
if vt_check_mode 4; then if vt_check_mode 4 "$vt_chosen_name"; then
vtoy_windows_wimboot_func vtoy_windows_wimboot_func
fi fi
@ -779,7 +779,7 @@ function uefi_linux_menu_func {
ventoy_cli_console ventoy_cli_console
unset vtGrub2Mode unset vtGrub2Mode
if vt_check_mode 3; then if vt_check_mode 3 "$vt_chosen_name"; then
set vtGrub2Mode=1 set vtGrub2Mode=1
elif vt_str_begin "$vt_volume_id" "KRD"; then elif vt_str_begin "$vt_volume_id" "KRD"; then
if [ -f (loop)/boot/grub/grub.cfg.sig ]; then if [ -f (loop)/boot/grub/grub.cfg.sig ]; then
@ -867,7 +867,7 @@ function uefi_iso_menu_func {
if [ -n "$vtisouefi" ]; then if [ -n "$vtisouefi" ]; then
set LoadIsoEfiDriver=on set LoadIsoEfiDriver=on
unset vtisouefi unset vtisouefi
elif vt_check_mode 2; then elif vt_check_mode 2 "$vt_chosen_name"; then
set LoadIsoEfiDriver=on set LoadIsoEfiDriver=on
else else
unset LoadIsoEfiDriver unset LoadIsoEfiDriver
@ -904,7 +904,7 @@ function uefi_iso_menu_func {
if [ -n "$vtcompat" ]; then if [ -n "$vtcompat" ]; then
set ventoy_compatible=YES set ventoy_compatible=YES
unset vtcompat unset vtcompat
elif vt_check_mode 1; then elif vt_check_mode 1 "$vt_chosen_name"; then
set ventoy_compatible=YES set ventoy_compatible=YES
else else
vt_check_compatible (loop) vt_check_compatible (loop)
@ -1050,7 +1050,7 @@ function legacy_windows_menu_func {
vt_windows_chain_data "${1}${chosen_path}" vt_windows_chain_data "${1}${chosen_path}"
ventoy_debug_pause ventoy_debug_pause
if vt_check_mode 4; then if vt_check_mode 4 "$vt_chosen_name"; then
vtoy_windows_wimboot_func vtoy_windows_wimboot_func
fi fi
@ -1133,7 +1133,7 @@ function legacy_linux_menu_func {
ventoy_debug_pause ventoy_debug_pause
if [ -n "$vtoy_chain_mem_addr" ]; then if [ -n "$vtoy_chain_mem_addr" ]; then
if vt_check_mode 3; then if vt_check_mode 3 "$vt_chosen_name"; then
ventoy_acpi_param ${vtoy_chain_mem_addr} 2048 ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
ventoy_cli_console ventoy_cli_console
@ -1212,7 +1212,7 @@ function legacy_iso_menu_func {
if [ -n "$vtcompat" ]; then if [ -n "$vtcompat" ]; then
set ventoy_compatible=YES set ventoy_compatible=YES
unset vtcompat unset vtcompat
elif vt_check_mode 1; then elif vt_check_mode 1 "$vt_chosen_name"; then
set ventoy_compatible=YES set ventoy_compatible=YES
else else
vt_check_compatible (loop) vt_check_compatible (loop)
@ -1343,7 +1343,7 @@ function iso_common_menuentry {
# auto memdisk mode for some special ISO files # auto memdisk mode for some special ISO files
vt_iso_vd_id_parse "${vtoy_iso_part}${vt_chosen_path}" vt_iso_vd_id_parse "${vtoy_iso_part}${vt_chosen_path}"
unset vtMemDiskBoot unset vtMemDiskBoot
if vt_check_mode 0; then if vt_check_mode 0 "$vt_chosen_name"; then
set vtMemDiskBoot=1 set vtMemDiskBoot=1
else else
if [ "$grub_platform" = "pc" ]; then if [ "$grub_platform" = "pc" ]; then
@ -1380,7 +1380,7 @@ function iso_common_menuentry {
} }
function miso_common_menuentry { function miso_common_menuentry {
vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
if vt_check_password "${vt_chosen_path}"; then if vt_check_password "${vt_chosen_path}"; then
return return
@ -1414,7 +1414,7 @@ function iso_unsupport_menuentry {
} }
function wim_common_menuentry { function wim_common_menuentry {
vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
if vt_check_password "${vt_chosen_path}"; then if vt_check_password "${vt_chosen_path}"; then
return return
@ -1453,7 +1453,7 @@ function wim_unsupport_menuentry {
} }
function efi_common_menuentry { function efi_common_menuentry {
vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
if vt_check_password "${vt_chosen_path}"; then if vt_check_password "${vt_chosen_path}"; then
return return
@ -1523,7 +1523,7 @@ function vhdboot_common_func {
} }
function vhd_common_menuentry { function vhd_common_menuentry {
vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
if vt_check_password "${vt_chosen_path}"; then if vt_check_password "${vt_chosen_path}"; then
return return
@ -1620,7 +1620,7 @@ function vtoyboot_common_func {
} }
function vtoy_common_menuentry { function vtoy_common_menuentry {
vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
if vt_check_password "${vt_chosen_path}"; then if vt_check_password "${vt_chosen_path}"; then
return return
@ -2030,7 +2030,7 @@ function img_common_menuentry {
set ventoy_busybox_ver=32 set ventoy_busybox_ver=32
unset LoadIsoEfiDriver unset LoadIsoEfiDriver
vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_img_path vt_chosen_path vt_chosen_size vt_chosen_name
if vt_check_password "${vt_chosen_path}"; then if vt_check_password "${vt_chosen_path}"; then
return return
@ -2041,7 +2041,7 @@ function img_common_menuentry {
fi fi
if [ "$grub_platform" = "pc" ]; then if [ "$grub_platform" = "pc" ]; then
if vt_check_mode 0; then if vt_check_mode 0 "$vt_chosen_name"; then
legacy_img_memdisk $vtoy_iso_part "$vt_chosen_path" legacy_img_memdisk $vtoy_iso_part "$vt_chosen_path"
return return
fi fi