mirror of https://github.com/ventoy/Ventoy.git
Show a warning message if ventoy.json is in UCS-2 encoding. (#1125)
ventoy.json must in UTF-8 encoding. The BOM is auto skipped if exist.
This commit is contained in:
parent
32602a79ab
commit
a9c539572b
|
@ -2399,7 +2399,9 @@ static int ventoy_parse_plugin_config(VTOY_JSON *json, const char *isodisk)
|
|||
grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
int ret = 0;
|
||||
int offset = 0;
|
||||
char *buf = NULL;
|
||||
grub_uint8_t *code = NULL;
|
||||
grub_file_t file;
|
||||
VTOY_JSON *json = NULL;
|
||||
|
||||
|
@ -2436,9 +2438,25 @@ grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **a
|
|||
return 1;
|
||||
}
|
||||
|
||||
code = (grub_uint8_t *)buf;
|
||||
if (code[0] == 0xef && code[1] == 0xbb && code[2] == 0xbf)
|
||||
{
|
||||
offset = 3; /* Skip UTF-8 BOM */
|
||||
}
|
||||
else if ((code[0] == 0xff && code[1] == 0xfe) || (code[0] == 0xfe && code[1] == 0xff))
|
||||
{
|
||||
grub_env_set("VTOY_PLUGIN_SYNTAX_ERROR", "1");
|
||||
grub_env_export("VTOY_PLUGIN_SYNTAX_ERROR");
|
||||
|
||||
grub_env_set("VTOY_PLUGIN_ENCODE_ERROR", "1");
|
||||
grub_env_export("VTOY_PLUGIN_ENCODE_ERROR");
|
||||
|
||||
ret = vtoy_json_parse(json, buf);
|
||||
debug("Failed to parse json string %d\n", ret);
|
||||
grub_free(buf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = vtoy_json_parse(json, buf + offset);
|
||||
if (ret)
|
||||
{
|
||||
grub_env_set("VTOY_PLUGIN_SYNTAX_ERROR", "1");
|
||||
|
|
|
@ -2178,12 +2178,19 @@ fi
|
|||
|
||||
if [ -n "$VTOY_PLUGIN_SYNTAX_ERROR" ]; then
|
||||
clear
|
||||
if [ -n "$VTOY_PLUGIN_ENCODE_ERROR" ]; then
|
||||
echo -e "\n Encoding type for ventoy.json is not supported, please convert to UTF-8.\n"
|
||||
echo -e " ventoy.json 文件编码格式不支持,请转换为 UTF-8 编码格式!\n"
|
||||
else
|
||||
echo -e "\n Syntax error detected in ventoy.json, please check! \n"
|
||||
echo -e " ventoy.json 文件中有语法错误,所有配置都不会生效,请检查!\n"
|
||||
fi
|
||||
|
||||
echo -e "\n press ENTER to continue (请按 回车 键继续) ..."
|
||||
read vtInputKey
|
||||
fi
|
||||
|
||||
|
||||
for vtTFile in ventoy.json ventoy_grub.cfg; do
|
||||
if [ -f $vtoy_efi_part/ventoy/$vtTFile ]; then
|
||||
clear
|
||||
|
|
Loading…
Reference in New Issue