Compare commits

...

2 Commits

Author SHA1 Message Date
longpanda
78ab7a0759 1.0.26 release 2020-10-24 06:26:57 +08:00
longpanda
3ebd58c9df support original order in image_list plugin 2020-10-22 09:34:46 +08:00
11 changed files with 105 additions and 93 deletions

View File

@@ -1020,6 +1020,11 @@ int ventoy_cmp_img(img_info *img1, img_info *img2)
int c1 = 0; int c1 = 0;
int c2 = 0; int c2 = 0;
if (g_plugin_image_list)
{
return (img1->plugin_list_index - img2->plugin_list_index);
}
for (s1 = img1->name, s2 = img2->name; *s1 && *s2; s1++, s2++) for (s1 = img1->name, s2 = img2->name; *s1 && *s2; s1++, s2++)
{ {
c1 = *s1; c1 = *s1;
@@ -1047,13 +1052,18 @@ int ventoy_cmp_img(img_info *img1, img_info *img2)
return (c1 - c2); return (c1 - c2);
} }
static int ventoy_cmp_subdir(char *name1, char *name2) static int ventoy_cmp_subdir(img_iterator_node *node1, img_iterator_node *node2)
{ {
char *s1, *s2; char *s1, *s2;
int c1 = 0; int c1 = 0;
int c2 = 0; int c2 = 0;
for (s1 = name1, s2 = name2; *s1 && *s2; s1++, s2++) if (g_plugin_image_list)
{
return (node1->plugin_list_index - node2->plugin_list_index);
}
for (s1 = node1->dir, s2 = node2->dir; *s1 && *s2; s1++, s2++)
{ {
c1 = *s1; c1 = *s1;
c2 = *s2; c2 = *s2;
@@ -1137,6 +1147,7 @@ static int ventoy_colect_img_files(const char *filename, const struct grub_dirho
int i = 0; int i = 0;
int type = 0; int type = 0;
int ignore = 0; int ignore = 0;
int index = 0;
grub_size_t len; grub_size_t len;
img_info *img; img_info *img;
img_info *tail; img_info *tail;
@@ -1164,9 +1175,21 @@ static int ventoy_colect_img_files(const char *filename, const struct grub_dirho
return 0; return 0;
} }
if (g_plugin_image_list)
{
grub_snprintf(g_img_swap_tmp_buf, sizeof(g_img_swap_tmp_buf), "%s%s/", node->dir, filename);
index = ventoy_plugin_get_image_list_index(vtoy_class_directory, g_img_swap_tmp_buf);
if (index == 0)
{
debug("Directory %s not found in image_list plugin config...\n", g_img_swap_tmp_buf);
return 0;
}
}
new_node = grub_zalloc(sizeof(img_iterator_node)); new_node = grub_zalloc(sizeof(img_iterator_node));
if (new_node) if (new_node)
{ {
new_node->plugin_list_index = index;
new_node->dirlen = grub_snprintf(new_node->dir, sizeof(new_node->dir), "%s%s/", node->dir, filename); new_node->dirlen = grub_snprintf(new_node->dir, sizeof(new_node->dir), "%s%s/", node->dir, filename);
g_enum_fs->fs_dir(g_enum_dev, new_node->dir, ventoy_check_ignore_flag, &ignore); g_enum_fs->fs_dir(g_enum_dev, new_node->dir, ventoy_check_ignore_flag, &ignore);
@@ -1253,9 +1276,11 @@ static int ventoy_colect_img_files(const char *filename, const struct grub_dirho
if (g_plugin_image_list) if (g_plugin_image_list)
{ {
grub_snprintf(g_img_swap_tmp_buf, sizeof(g_img_swap_tmp_buf), "%s%s", node->dir, filename); grub_snprintf(g_img_swap_tmp_buf, sizeof(g_img_swap_tmp_buf), "%s%s", node->dir, filename);
if (ventoy_plugin_check_image_list(g_img_swap_tmp_buf) == 0) index = ventoy_plugin_get_image_list_index(vtoy_class_image_file, g_img_swap_tmp_buf);
if (index == 0)
{ {
return 0; debug("File %s not found in image_list plugin config...\n", g_img_swap_tmp_buf);
return 0;
} }
} }
@@ -1263,6 +1288,7 @@ static int ventoy_colect_img_files(const char *filename, const struct grub_dirho
if (img) if (img)
{ {
img->type = type; img->type = type;
img->plugin_list_index = index;
grub_snprintf(img->name, sizeof(img->name), "%s", filename); grub_snprintf(img->name, sizeof(img->name), "%s", filename);
for (i = 0; i < (int)len; i++) for (i = 0; i < (int)len; i++)
@@ -1422,28 +1448,13 @@ static img_info * ventoy_get_min_iso(img_iterator_node *node)
img_info *minimg = NULL; img_info *minimg = NULL;
img_info *img = (img_info *)(node->firstiso); img_info *img = (img_info *)(node->firstiso);
if (g_plugin_image_list) while (img && (img_iterator_node *)(img->parent) == node)
{ {
while (img && (img_iterator_node *)(img->parent) == node) if (img->select == 0 && (NULL == minimg || ventoy_cmp_img(img, minimg) < 0))
{ {
if (img->select == 0) minimg = img;
{
minimg = img;
break;
}
img = img->next;
}
}
else
{
while (img && (img_iterator_node *)(img->parent) == node)
{
if (img->select == 0 && (NULL == minimg || ventoy_cmp_img(img, minimg) < 0))
{
minimg = img;
}
img = img->next;
} }
img = img->next;
} }
if (minimg) if (minimg)
@@ -1459,28 +1470,13 @@ static img_iterator_node * ventoy_get_min_child(img_iterator_node *node)
img_iterator_node *Minchild = NULL; img_iterator_node *Minchild = NULL;
img_iterator_node *child = node->firstchild; img_iterator_node *child = node->firstchild;
if (g_plugin_image_list) while (child && child->parent == node)
{ {
while (child && child->parent == node) if (child->select == 0 && (NULL == Minchild || ventoy_cmp_subdir(child, Minchild) < 0))
{ {
if (child->select == 0) Minchild = child;
{
Minchild = child;
break;
}
child = child->next;
}
}
else
{
while (child && child->parent == node)
{
if (child->select == 0 && (NULL == Minchild || ventoy_cmp_subdir(child->dir, Minchild->dir) < 0))
{
Minchild = child;
}
child = child->next;
} }
child = child->next;
} }
if (Minchild) if (Minchild)
@@ -1880,7 +1876,7 @@ static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char
grub_snprintf(g_iso_path, sizeof(g_iso_path), "%s", args[0]); grub_snprintf(g_iso_path, sizeof(g_iso_path), "%s", args[0]);
strdata = ventoy_get_env("VTOY_DEFAULT_SEARCH_ROOT"); strdata = ventoy_get_env("VTOY_DEFAULT_SEARCH_ROOT");
if (0 == g_plugin_image_list && strdata && strdata[0] == '/') if (strdata && strdata[0] == '/')
{ {
len = grub_snprintf(g_img_iterator_head.dir, sizeof(g_img_iterator_head.dir) - 1, "%s", strdata); len = grub_snprintf(g_img_iterator_head.dir, sizeof(g_img_iterator_head.dir) - 1, "%s", strdata);
if (g_img_iterator_head.dir[len - 1] != '/') if (g_img_iterator_head.dir[len - 1] != '/')
@@ -1924,17 +1920,14 @@ static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char
node = tmp; node = tmp;
} }
/* sort image list by image name if image_list is not set in ventoy.json */ /* sort image list by image name */
if (0 == g_plugin_image_list) for (cur = g_ventoy_img_list; cur; cur = cur->next)
{ {
for (cur = g_ventoy_img_list; cur; cur = cur->next) for (tail = cur->next; tail; tail = tail->next)
{ {
for (tail = cur->next; tail; tail = tail->next) if (ventoy_cmp_img(cur, tail) > 0)
{ {
if (ventoy_cmp_img(cur, tail) > 0) ventoy_swap_img(cur, tail);
{
ventoy_swap_img(cur, tail);
}
} }
} }
} }
@@ -2738,7 +2731,7 @@ static grub_err_t ventoy_cmd_dump_img_list(grub_extcmd_context_t ctxt, int argc,
while (cur) while (cur)
{ {
grub_printf("path:<%s> id=%d\n", cur->path, cur->id); grub_printf("path:<%s> id=%d list_index=%d\n", cur->path, cur->id, cur->plugin_list_index);
grub_printf("name:<%s>\n\n", cur->name); grub_printf("name:<%s>\n\n", cur->name);
cur = cur->next; cur = cur->next;
} }

View File

@@ -52,6 +52,12 @@
#define VTOY_WARNING "!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!" #define VTOY_WARNING "!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!"
#ifdef GRUB_MACHINE_EFI
#define VTOY_DUAL_MODE_SUFFIX "uefi"
#else
#define VTOY_DUAL_MODE_SUFFIX "legacy"
#endif
typedef struct ventoy_initrd_ctx typedef struct ventoy_initrd_ctx
{ {
const char *path_prefix; const char *path_prefix;
@@ -172,6 +178,7 @@ typedef struct img_info
int id; int id;
int type; int type;
int plugin_list_index;
grub_uint64_t size; grub_uint64_t size;
int select; int select;
int unsupport; int unsupport;
@@ -192,6 +199,8 @@ typedef struct img_iterator_node
int done; int done;
int select; int select;
int plugin_list_index;
struct img_iterator_node *parent; struct img_iterator_node *parent;
struct img_iterator_node *firstchild; struct img_iterator_node *firstchild;
@@ -828,7 +837,7 @@ const char * ventoy_plugin_get_injection(const char *isopath);
const char * ventoy_plugin_get_menu_alias(int type, const char *isopath); const char * ventoy_plugin_get_menu_alias(int type, const char *isopath);
const char * ventoy_plugin_get_menu_class(int type, const char *name); const char * ventoy_plugin_get_menu_class(int type, const char *name);
int ventoy_plugin_check_memdisk(const char *isopath); int ventoy_plugin_check_memdisk(const char *isopath);
int ventoy_plugin_check_image_list(const char *isopath); int ventoy_plugin_get_image_list_index(int type, const char *name);
int ventoy_get_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start); int ventoy_get_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start);
int ventoy_check_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start); int ventoy_check_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start);
void ventoy_plugin_dump_persistence(void); void ventoy_plugin_dump_persistence(void);

View File

@@ -1102,6 +1102,7 @@ static int ventoy_plugin_image_list_entry(VTOY_JSON *json, const char *isodisk)
VTOY_JSON *pNode = NULL; VTOY_JSON *pNode = NULL;
image_list *node = NULL; image_list *node = NULL;
image_list *next = NULL; image_list *next = NULL;
image_list *tail = NULL;
(void)isodisk; (void)isodisk;
@@ -1135,10 +1136,13 @@ static int ventoy_plugin_image_list_entry(VTOY_JSON *json, const char *isodisk)
if (g_image_list_head) if (g_image_list_head)
{ {
node->next = g_image_list_head; tail->next = node;
} }
else
g_image_list_head = node; {
g_image_list_head = node;
}
tail = node;
} }
} }
} }
@@ -1180,11 +1184,6 @@ static plugin_entry g_plugin_entries[] =
{ {
{ "control", ventoy_plugin_control_entry, ventoy_plugin_control_check }, { "control", ventoy_plugin_control_entry, ventoy_plugin_control_check },
{ "theme", ventoy_plugin_theme_entry, ventoy_plugin_theme_check }, { "theme", ventoy_plugin_theme_entry, ventoy_plugin_theme_check },
#ifdef GRUB_MACHINE_EFI
{ "theme_uefi", ventoy_plugin_theme_entry, ventoy_plugin_theme_check },
#else
{ "theme_legacy", ventoy_plugin_theme_entry, ventoy_plugin_theme_check },
#endif
{ "auto_install", ventoy_plugin_auto_install_entry, ventoy_plugin_auto_install_check }, { "auto_install", ventoy_plugin_auto_install_entry, ventoy_plugin_auto_install_check },
{ "persistence", ventoy_plugin_persistence_entry, ventoy_plugin_persistence_check }, { "persistence", ventoy_plugin_persistence_entry, ventoy_plugin_persistence_check },
{ "menu_alias", ventoy_plugin_menualias_entry, ventoy_plugin_menualias_check }, { "menu_alias", ventoy_plugin_menualias_entry, ventoy_plugin_menualias_check },
@@ -1197,6 +1196,7 @@ static plugin_entry g_plugin_entries[] =
static int ventoy_parse_plugin_config(VTOY_JSON *json, const char *isodisk) static int ventoy_parse_plugin_config(VTOY_JSON *json, const char *isodisk)
{ {
int i; int i;
char key[128];
VTOY_JSON *cur = json; VTOY_JSON *cur = json;
grub_snprintf(g_iso_disk_name, sizeof(g_iso_disk_name), "%s", isodisk); grub_snprintf(g_iso_disk_name, sizeof(g_iso_disk_name), "%s", isodisk);
@@ -1205,7 +1205,8 @@ static int ventoy_parse_plugin_config(VTOY_JSON *json, const char *isodisk)
{ {
for (i = 0; i < (int)ARRAY_SIZE(g_plugin_entries); i++) for (i = 0; i < (int)ARRAY_SIZE(g_plugin_entries); i++)
{ {
if (grub_strcmp(g_plugin_entries[i].key, cur->pcName) == 0) grub_snprintf(key, sizeof(key), "%s_%s", g_plugin_entries[i].key, VTOY_DUAL_MODE_SUFFIX);
if (grub_strcmp(g_plugin_entries[i].key, cur->pcName) == 0 || grub_strcmp(key, cur->pcName) == 0)
{ {
debug("Plugin entry for %s\n", g_plugin_entries[i].key); debug("Plugin entry for %s\n", g_plugin_entries[i].key);
g_plugin_entries[i].entryfunc(cur, isodisk); g_plugin_entries[i].entryfunc(cur, isodisk);
@@ -1236,7 +1237,7 @@ grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **a
} }
debug("json configuration file size %d\n", (int)file->size); debug("json configuration file size %d\n", (int)file->size);
buf = grub_malloc(file->size + 1); buf = grub_malloc(file->size + 1);
if (!buf) if (!buf)
{ {
@@ -1259,6 +1260,9 @@ grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **a
ret = vtoy_json_parse(json, buf); ret = vtoy_json_parse(json, buf);
if (ret) if (ret)
{ {
grub_env_set("VTOY_PLUGIN_SYNTAX_ERROR", "1");
grub_env_export("VTOY_PLUGIN_SYNTAX_ERROR");
debug("Failed to parse json string %d\n", ret); debug("Failed to parse json string %d\n", ret);
grub_free(buf); grub_free(buf);
return 1; return 1;
@@ -1558,9 +1562,10 @@ int ventoy_plugin_check_memdisk(const char *isopath)
return 0; return 0;
} }
int ventoy_plugin_check_image_list(const char *isopath) int ventoy_plugin_get_image_list_index(int type, const char *name)
{ {
int len; int len;
int index = 1;
image_list *node = NULL; image_list *node = NULL;
if (!g_image_list_head) if (!g_image_list_head)
@@ -1568,12 +1573,23 @@ int ventoy_plugin_check_image_list(const char *isopath)
return 0; return 0;
} }
len = (int)grub_strlen(isopath); len = (int)grub_strlen(name);
for (node = g_image_list_head; node; node = node->next)
for (node = g_image_list_head; node; node = node->next, index++)
{ {
if (node->pathlen == len && grub_strncmp(isopath, node->isopath, len) == 0) if (vtoy_class_directory == type)
{ {
return 1; if (len < node->pathlen && grub_strncmp(name, node->isopath, len) == 0)
{
return index;
}
}
else
{
if (len == node->pathlen && grub_strncmp(name, node->isopath, len) == 0)
{
return index;
}
} }
} }
@@ -1585,6 +1601,7 @@ grub_err_t ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, ch
int i = 0; int i = 0;
int ret = 0; int ret = 0;
char *buf = NULL; char *buf = NULL;
char key[128];
grub_file_t file; grub_file_t file;
VTOY_JSON *node = NULL; VTOY_JSON *node = NULL;
VTOY_JSON *json = NULL; VTOY_JSON *json = NULL;
@@ -1627,9 +1644,10 @@ grub_err_t ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, ch
goto end; goto end;
} }
grub_snprintf(key, sizeof(key), "%s_%s", args[1], VTOY_DUAL_MODE_SUFFIX);
for (node = json->pstChild; node; node = node->pstNext) for (node = json->pstChild; node; node = node->pstNext)
{ {
if (grub_strcmp(node->pcName, args[1]) == 0) if (grub_strcmp(node->pcName, args[1]) == 0 || grub_strcmp(node->pcName, key) == 0)
{ {
break; break;
} }

Binary file not shown.

View File

@@ -19,27 +19,6 @@ submenu 'Check plugin json configuration (ventoy.json)' --class=debug_json {
unset pager unset pager
} }
if [ "$grub_platform" = "pc" ]; then
menuentry 'Check legacy theme plugin configuration' --class=debug_theme_legacy {
set pager=1
vt_check_plugin_json $vt_plugin_path theme_legacy $vtoy_iso_part
echo -e "\npress ENTER to exit ..."
read vtInputKey
unset pager
}
else
menuentry 'Check uefi theme plugin configuration' --class=debug_theme_uefi {
set pager=1
vt_check_plugin_json $vt_plugin_path theme_uefi $vtoy_iso_part
echo -e "\npress ENTER to exit ..."
read vtInputKey
unset pager
}
fi
menuentry 'Check auto install plugin configuration' --class=debug_autoinstall { menuentry 'Check auto install plugin configuration' --class=debug_autoinstall {
set pager=1 set pager=1
vt_check_plugin_json $vt_plugin_path auto_install $vtoy_iso_part vt_check_plugin_json $vt_plugin_path auto_install $vtoy_iso_part

View File

@@ -1344,7 +1344,7 @@ function img_unsupport_menuentry {
############################################################# #############################################################
############################################################# #############################################################
set VENTOY_VERSION="1.0.25" set VENTOY_VERSION="1.0.26"
#ACPI not compatible with Window7/8, so disable by default #ACPI not compatible with Window7/8, so disable by default
set VTOY_PARAM_NO_ACPI=1 set VTOY_PARAM_NO_ACPI=1
@@ -1384,7 +1384,7 @@ if [ "$vtoy_dev" = "tftp" ]; then
loadfont ascii loadfont ascii
if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
set vt_plugin_path=$vtoy_iso_part set vt_plugin_path=$vtoy_iso_part
else else
set vt_plugin_path=$prefix set vt_plugin_path=$prefix
vt_load_plugin $vt_plugin_path vt_load_plugin $vt_plugin_path
@@ -1471,6 +1471,15 @@ else
terminal_output gfxterm terminal_output gfxterm
fi fi
if [ -n "$VTOY_PLUGIN_SYNTAX_ERROR" ]; then
clear
echo -e "\n Syntax error detected in ventoy.json, please check! \n"
echo -e " ventoy.json 文件中有语法错误,所有配置都不会生效,请检查!\n"
echo -e "\n press ENTER to continue (请按 回车 键继续) ..."
read vtInputKey
fi
#export necessary variable #export necessary variable
export theme export theme
export gfxmode export gfxmode

Binary file not shown.

View File

@@ -63,7 +63,11 @@ if ! [ -b "$DISK" ]; then
fi fi
if [ -e /sys/class/block/${DISK#/dev/}/start ]; then if [ -e /sys/class/block/${DISK#/dev/}/start ]; then
vterr "$DISK is a partition, please use the whole disk" vterr "$DISK is a partition, please use the whole disk."
echo "For example:"
vterr " sudo sh Ventoy2Disk.sh -i /dev/sdX1 <=== This is wrong"
vtinfo " sudo sh Ventoy2Disk.sh -i /dev/sdX <=== This is right"
echo ""
exit 1 exit 1
fi fi

Binary file not shown.

Binary file not shown.

Binary file not shown.