From 62dc0033ad5c986de9f6ef6661bc52fa8560e1e7 Mon Sep 17 00:00:00 2001 From: longpanda Date: Tue, 15 Feb 2022 11:51:32 +0800 Subject: [PATCH] Make VTOY_TREE_VIEW_MENU_STYLE also control the browser menu style. (#1439) --- .../grub-core/ventoy/ventoy_browser.c | 98 ++++++++++++++----- .../grub-2.04/grub-core/ventoy/ventoy_def.h | 1 + 2 files changed, 77 insertions(+), 22 deletions(-) diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_browser.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_browser.c index c083f192..1395541e 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_browser.c +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_browser.c @@ -171,10 +171,20 @@ static int ventoy_browser_iterate_partition(struct grub_disk *disk, const grub_p fs->fs_label(dev, &Label); - grub_snprintf(title, sizeof(title), "%-10s (%s,%s%d) [%s] %s %s", - "DISK", disk->name, partition->msdostype == 0xee ? "gpt" : "msdos", - partition->number + 1, (Label ? Label : ""), fs->name, - grub_get_human_size(partition->len << disk->log_sector_size, GRUB_HUMAN_SIZE_SHORT)); + if (g_tree_view_menu_style == 0) + { + grub_snprintf(title, sizeof(title), "%-10s (%s,%s%d) [%s] %s %s", + "DISK", disk->name, partition->msdostype == 0xee ? "gpt" : "msdos", + partition->number + 1, (Label ? Label : ""), fs->name, + grub_get_human_size(partition->len << disk->log_sector_size, GRUB_HUMAN_SIZE_SHORT)); + } + else + { + grub_snprintf(title, sizeof(title), "(%s,%s%d) [%s] %s %s", + disk->name, partition->msdostype == 0xee ? "gpt" : "msdos", + partition->number + 1, (Label ? Label : ""), fs->name, + grub_get_human_size(partition->len << disk->log_sector_size, GRUB_HUMAN_SIZE_SHORT)); + } if (ventoy_get_fs_type(fs->name) >= ventoy_fs_max) { @@ -326,11 +336,23 @@ static int ventoy_browser_iterate_dir(const char *filename, const struct grub_di node->dir = 1; grub_strncpy(node->filename, filename, sizeof(node->filename)); - grub_snprintf(node->menuentry, sizeof(node->menuentry), - "menuentry \"%-10s [%s]\" --class=vtoydir {\n" - " vt_browser_dir %s 0x%lx \"%s/%s\"\n" - "}\n", - "DIR", filename, g_menu_device, (ulong)g_menu_fs, g_menu_path_buf, filename); + + if (g_tree_view_menu_style == 0) + { + grub_snprintf(node->menuentry, sizeof(node->menuentry), + "menuentry \"%-10s [%s]\" --class=vtoydir {\n" + " vt_browser_dir %s 0x%lx \"%s/%s\"\n" + "}\n", + "DIR", filename, g_menu_device, (ulong)g_menu_fs, g_menu_path_buf, filename); + } + else + { + grub_snprintf(node->menuentry, sizeof(node->menuentry), + "menuentry \"[%s]\" --class=vtoydir {\n" + " vt_browser_dir %s 0x%lx \"%s/%s\"\n" + "}\n", + filename, g_menu_device, (ulong)g_menu_fs, g_menu_path_buf, filename); + } } else { @@ -363,15 +385,31 @@ static int ventoy_browser_iterate_dir(const char *filename, const struct grub_di node->dir = 0; grub_strncpy(node->filename, filename, sizeof(node->filename)); - grub_snprintf(node->menuentry, sizeof(node->menuentry), - "menuentry \"%-10s %s\" --class=%s {\n" - " vt_set_fake_vlnk \"(%s)%s/%s\" %s %llu\n" - " %s_common_menuentry\n" - " vt_reset_fake_vlnk\n" - "}\n", - grub_get_human_size(fsize, GRUB_HUMAN_SIZE_SHORT), filename, g_menu_class[type], - g_menu_device, g_menu_path_buf, filename, g_menu_prefix[type], (ulonglong)fsize, - g_menu_prefix[type]); + + if (g_tree_view_menu_style == 0) + { + grub_snprintf(node->menuentry, sizeof(node->menuentry), + "menuentry \"%-10s %s\" --class=%s {\n" + " vt_set_fake_vlnk \"(%s)%s/%s\" %s %llu\n" + " %s_common_menuentry\n" + " vt_reset_fake_vlnk\n" + "}\n", + grub_get_human_size(fsize, GRUB_HUMAN_SIZE_SHORT), filename, g_menu_class[type], + g_menu_device, g_menu_path_buf, filename, g_menu_prefix[type], (ulonglong)fsize, + g_menu_prefix[type]); + } + else + { + grub_snprintf(node->menuentry, sizeof(node->menuentry), + "menuentry \"%s\" --class=%s {\n" + " vt_set_fake_vlnk \"(%s)%s/%s\" %s %llu\n" + " %s_common_menuentry\n" + " vt_reset_fake_vlnk\n" + "}\n", + filename, g_menu_class[type], + g_menu_device, g_menu_path_buf, filename, g_menu_prefix[type], (ulonglong)fsize, + g_menu_prefix[type]); + } } node->prev = NULL; @@ -434,8 +472,16 @@ grub_err_t ventoy_cmd_browser_dir(grub_extcmd_context_t ctxt, int argc, char **a } grub_device_close(dev); - browser_ssprintf(&mbuf, "menuentry \"%-10s [../]\" --class=\"vtoyret\" VTOY_RET {\n " - " echo 'return ...' \n}\n", "<--"); + if (g_tree_view_menu_style == 0) + { + browser_ssprintf(&mbuf, "menuentry \"%-10s [../]\" --class=\"vtoyret\" VTOY_RET {\n " + " echo 'return ...' \n}\n", "<--"); + } + else + { + browser_ssprintf(&mbuf, "menuentry \"[../]\" --class=\"vtoyret\" VTOY_RET {\n " + " echo 'return ...' \n}\n"); + } for (i = 1; i >= 0; i--) { @@ -493,8 +539,16 @@ grub_err_t ventoy_cmd_browser_disk(grub_extcmd_context_t ctxt, int argc, char ** g_vtoy_dev = grub_env_get("vtoydev"); - browser_ssprintf(&mbuf, "menuentry \"%-10s [Return]\" --class=\"vtoyret\" VTOY_RET {\n " - " echo 'return ...' \n}\n", "<--"); + if (g_tree_view_menu_style == 0) + { + browser_ssprintf(&mbuf, "menuentry \"%-10s [Return]\" --class=\"vtoyret\" VTOY_RET {\n " + " echo 'return ...' \n}\n", "<--"); + } + else + { + browser_ssprintf(&mbuf, "menuentry \"[Return]\" --class=\"vtoyret\" VTOY_RET {\n " + " echo 'return ...' \n}\n"); + } grub_disk_dev_iterate(ventoy_browser_iterate_disk, &mbuf); diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h index f00ce37e..5dde8ddf 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h @@ -1187,6 +1187,7 @@ typedef struct browser_node struct browser_node *next; }browser_node; +extern int g_tree_view_menu_style; extern int g_sort_case_sensitive; extern int g_wimboot_enable; extern int g_filt_dot_underscore_file;