1 /******************************************************************************
4 * Copyright (c) 2020, longpanda <admin@ventoy.net>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include <grub/types.h>
21 #include <grub/misc.h>
25 #include <grub/disk.h>
26 #include <grub/device.h>
27 #include <grub/term.h>
28 #include <grub/partition.h>
29 #include <grub/file.h>
30 #include <grub/normal.h>
31 #include <grub/extcmd.h>
32 #include <grub/datetime.h>
33 #include <grub/i18n.h>
35 #include <grub/time.h>
36 #include <grub/ventoy.h>
37 #include "ventoy_def.h"
39 GRUB_MOD_LICENSE ("GPLv3+");
41 static int ventoy_plugin_theme_entry(VTOY_JSON
*json
, const char *isodisk
)
46 value
= vtoy_json_get_string_ex(json
->pstChild
, "file");
49 grub_snprintf(filepath
, sizeof(filepath
), "%s/ventoy/%s", isodisk
, value
);
50 if (ventoy_is_file_exist(filepath
) == 0)
52 debug("Theme file %s does not exist\n", filepath
);
56 debug("vtoy_theme %s\n", filepath
);
57 grub_env_set("vtoy_theme", filepath
);
60 value
= vtoy_json_get_string_ex(json
->pstChild
, "gfxmode");
63 debug("vtoy_gfxmode %s\n", value
);
64 grub_env_set("vtoy_gfxmode", value
);
70 static plugin_entry g_plugin_entries
[] =
72 { "theme", ventoy_plugin_theme_entry
},
75 static int ventoy_parse_plugin_config(VTOY_JSON
*json
, const char *isodisk
)
78 VTOY_JSON
*cur
= json
;
82 for (i
= 0; i
< (int)ARRAY_SIZE(g_plugin_entries
); i
++)
84 if (grub_strcmp(g_plugin_entries
[i
].key
, cur
->pcName
) == 0)
86 debug("Plugin entry for %s\n", g_plugin_entries
[i
].key
);
87 g_plugin_entries
[i
].entryfunc(cur
, isodisk
);
98 grub_err_t
ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt
, int argc
, char **args
)
103 VTOY_JSON
*json
= NULL
;
108 file
= ventoy_grub_file_open(VENTOY_FILE_TYPE
, "%s/ventoy/ventoy.json", args
[0]);
111 return GRUB_ERR_NONE
;
114 debug("json configuration file size %d\n", (int)file
->size
);
116 buf
= grub_malloc(file
->size
+ 1);
119 grub_file_close(file
);
124 grub_file_read(file
, buf
, file
->size
);
125 grub_file_close(file
);
127 json
= vtoy_json_create();
135 ret
= vtoy_json_parse(json
, buf
);
138 debug("Failed to parse json string %d\n", ret
);
143 ventoy_parse_plugin_config(json
->pstChild
, args
[0]);
145 vtoy_json_destroy(json
);
149 VENTOY_CMD_RETURN(GRUB_ERR_NONE
);