mirror of
https://github.com/ventoy/Ventoy.git
synced 2025-08-27 16:01:14 +00:00
1.0.45 release
This commit is contained in:
@@ -4573,6 +4573,7 @@ static cmd_para ventoy_cmds[] =
|
||||
{ "vt_is_pe64", ventoy_cmd_is_pe64, 0, NULL, "", "", NULL },
|
||||
{ "vt_sel_wimboot", ventoy_cmd_sel_wimboot, 0, NULL, "", "", NULL },
|
||||
{ "vt_set_wim_load_prompt", ventoy_cmd_set_wim_prompt, 0, NULL, "", "", NULL },
|
||||
{ "vt_set_theme", ventoy_cmd_set_theme, 0, NULL, "", "", NULL },
|
||||
|
||||
};
|
||||
|
||||
|
@@ -778,6 +778,12 @@ typedef struct file_fullpath
|
||||
char path[256];
|
||||
}file_fullpath;
|
||||
|
||||
typedef struct theme_list
|
||||
{
|
||||
file_fullpath theme;
|
||||
struct theme_list *next;
|
||||
}theme_list;
|
||||
|
||||
#define auto_install_type_file 0
|
||||
#define auto_install_type_parent 1
|
||||
typedef struct install_template
|
||||
@@ -999,6 +1005,7 @@ int ventoy_plugin_load_dud(dud *node, const char *isopart);
|
||||
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);
|
||||
void ventoy_plugin_dump_persistence(void);
|
||||
grub_err_t ventoy_cmd_set_theme(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_check_password(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_linux_get_main_initrd_index(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
@@ -1036,5 +1043,9 @@ int ventoy_chain_file_read(const char *path, int offset, int len, void *buf);
|
||||
|
||||
#define VTOY_CMD_CHECK(a) if (33554432 != g_ventoy_disk_part_size[a]) ventoy_syscall0(exit)
|
||||
|
||||
#define vtoy_theme_random_boot_second 0
|
||||
#define vtoy_theme_random_boot_day 1
|
||||
#define vtoy_theme_random_boot_month 2
|
||||
|
||||
#endif /* __VENTOY_DEF_H__ */
|
||||
|
||||
|
@@ -56,6 +56,11 @@ static auto_memdisk *g_auto_memdisk_head = NULL;
|
||||
static image_list *g_image_list_head = NULL;
|
||||
static conf_replace *g_conf_replace_head = NULL;
|
||||
|
||||
static int g_theme_num = 0;
|
||||
static theme_list *g_theme_head = NULL;
|
||||
static int g_theme_random = vtoy_theme_random_boot_second;
|
||||
static char g_theme_single_file[256];
|
||||
|
||||
static int ventoy_plugin_is_parent(const char *pat, int patlen, const char *isopath)
|
||||
{
|
||||
if (patlen > 1)
|
||||
@@ -177,6 +182,38 @@ static int ventoy_plugin_theme_check(VTOY_JSON *json, const char *isodisk)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
node = vtoy_json_find_item(json->pstChild, JSON_TYPE_ARRAY, "file");
|
||||
if (node)
|
||||
{
|
||||
for (node = node->pstChild; node; node = node->pstNext)
|
||||
{
|
||||
value = node->unData.pcStrVal;
|
||||
grub_printf("file: %s\n", value);
|
||||
if (value[0] == '/')
|
||||
{
|
||||
exist = ventoy_is_file_exist("%s%s", isodisk, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
exist = ventoy_is_file_exist("%s/ventoy/%s", isodisk, value);
|
||||
}
|
||||
|
||||
if (exist == 0)
|
||||
{
|
||||
grub_printf("Theme file %s does NOT exist\n", value);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
value = vtoy_json_get_string_ex(json->pstChild, "random");
|
||||
if (value)
|
||||
{
|
||||
grub_printf("random: %s\n", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
value = vtoy_json_get_string_ex(json->pstChild, "gfxmode");
|
||||
if (value)
|
||||
@@ -244,8 +281,10 @@ static int ventoy_plugin_theme_entry(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
const char *value;
|
||||
char filepath[256];
|
||||
VTOY_JSON *node;
|
||||
|
||||
VTOY_JSON *node = NULL;
|
||||
theme_list *tail = NULL;
|
||||
theme_list *themenode = NULL;
|
||||
|
||||
value = vtoy_json_get_string_ex(json->pstChild, "file");
|
||||
if (value)
|
||||
{
|
||||
@@ -258,7 +297,7 @@ static int ventoy_plugin_theme_entry(VTOY_JSON *json, const char *isodisk)
|
||||
grub_snprintf(filepath, sizeof(filepath), "%s/ventoy/%s", isodisk, value);
|
||||
}
|
||||
|
||||
if (ventoy_is_file_exist(filepath) == 0)
|
||||
if (ventoy_check_file_exist(filepath) == 0)
|
||||
{
|
||||
debug("Theme file %s does not exist\n", filepath);
|
||||
return 0;
|
||||
@@ -266,6 +305,65 @@ static int ventoy_plugin_theme_entry(VTOY_JSON *json, const char *isodisk)
|
||||
|
||||
debug("vtoy_theme %s\n", filepath);
|
||||
grub_env_set("vtoy_theme", filepath);
|
||||
grub_snprintf(g_theme_single_file, sizeof(g_theme_single_file), "%s", filepath);
|
||||
}
|
||||
else
|
||||
{
|
||||
node = vtoy_json_find_item(json->pstChild, JSON_TYPE_ARRAY, "file");
|
||||
if (node)
|
||||
{
|
||||
for (node = node->pstChild; node; node = node->pstNext)
|
||||
{
|
||||
value = node->unData.pcStrVal;
|
||||
if (value[0] == '/')
|
||||
{
|
||||
grub_snprintf(filepath, sizeof(filepath), "%s%s", isodisk, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_snprintf(filepath, sizeof(filepath), "%s/ventoy/%s", isodisk, value);
|
||||
}
|
||||
|
||||
if (ventoy_check_file_exist(filepath) == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
themenode = grub_zalloc(sizeof(theme_list));
|
||||
if (themenode)
|
||||
{
|
||||
grub_snprintf(themenode->theme.path, sizeof(themenode->theme.path), "%s", filepath);
|
||||
if (g_theme_head)
|
||||
{
|
||||
tail->next = themenode;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_theme_head = themenode;
|
||||
}
|
||||
tail = themenode;
|
||||
g_theme_num++;
|
||||
}
|
||||
}
|
||||
|
||||
grub_env_set("vtoy_theme", "random");
|
||||
value = vtoy_json_get_string_ex(json->pstChild, "random");
|
||||
if (value)
|
||||
{
|
||||
if (grub_strcmp(value, "boot_second") == 0)
|
||||
{
|
||||
g_theme_random = vtoy_theme_random_boot_second;
|
||||
}
|
||||
else if (grub_strcmp(value, "boot_day") == 0)
|
||||
{
|
||||
g_theme_random = vtoy_theme_random_boot_day;
|
||||
}
|
||||
else if (grub_strcmp(value, "boot_month") == 0)
|
||||
{
|
||||
g_theme_random = vtoy_theme_random_boot_month;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
value = vtoy_json_get_string_ex(json->pstChild, "gfxmode");
|
||||
@@ -2816,3 +2914,62 @@ end:
|
||||
return 0;
|
||||
}
|
||||
|
||||
grub_err_t ventoy_cmd_set_theme(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
grub_uint32_t i = 0;
|
||||
grub_uint32_t mod = 0;
|
||||
theme_list *node = g_theme_head;
|
||||
struct grub_datetime datetime;
|
||||
|
||||
(void)argc;
|
||||
(void)args;
|
||||
(void)ctxt;
|
||||
|
||||
if (g_theme_single_file[0])
|
||||
{
|
||||
debug("single theme %s\n", g_theme_single_file);
|
||||
grub_env_set("theme", g_theme_single_file);
|
||||
goto end;
|
||||
}
|
||||
|
||||
debug("g_theme_num = %d\n", g_theme_num);
|
||||
|
||||
if (g_theme_num == 0)
|
||||
{
|
||||
goto end;
|
||||
}
|
||||
|
||||
grub_memset(&datetime, 0, sizeof(datetime));
|
||||
grub_get_datetime(&datetime);
|
||||
|
||||
if (g_theme_random == vtoy_theme_random_boot_second)
|
||||
{
|
||||
grub_divmod32((grub_uint32_t)datetime.second, (grub_uint32_t)g_theme_num, &mod);
|
||||
}
|
||||
else if (g_theme_random == vtoy_theme_random_boot_day)
|
||||
{
|
||||
grub_divmod32((grub_uint32_t)datetime.day, (grub_uint32_t)g_theme_num, &mod);
|
||||
}
|
||||
else if (g_theme_random == vtoy_theme_random_boot_month)
|
||||
{
|
||||
grub_divmod32((grub_uint32_t)datetime.month, (grub_uint32_t)g_theme_num, &mod);
|
||||
}
|
||||
|
||||
debug("%04d/%02d/%02d %02d:%02d:%02d radom:%d mod:%d\n",
|
||||
datetime.year, datetime.month, datetime.day,
|
||||
datetime.hour, datetime.minute, datetime.second,
|
||||
g_theme_random, mod);
|
||||
|
||||
for (i = 0; i < mod && node; i++)
|
||||
{
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
debug("random theme %s\n", node->theme.path);
|
||||
grub_env_set("theme", node->theme.path);
|
||||
|
||||
end:
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user