mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-20 22:16:21 +00:00
Add /plugins install command
This commit is contained in:
@@ -6025,7 +6025,50 @@ cmd_xa(ProfWin *window, const char *const command, gchar **args)
|
||||
gboolean
|
||||
cmd_plugins(ProfWin *window, const char *const command, gchar **args)
|
||||
{
|
||||
if (g_strcmp0(args[0], "load") == 0) {
|
||||
if (g_strcmp0(args[0], "install") == 0) {
|
||||
char *filename = args[1];
|
||||
if (filename == NULL) {
|
||||
cons_bad_cmd_usage(command);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// expand ~ to $HOME
|
||||
if (filename[0] == '~' && filename[1] == '/') {
|
||||
if (asprintf(&filename, "%s/%s", getenv("HOME"), filename+2) == -1) {
|
||||
return TRUE;
|
||||
}
|
||||
} else {
|
||||
filename = strdup(filename);
|
||||
}
|
||||
|
||||
if (access(filename, R_OK) != 0) {
|
||||
cons_show("File not found: %s", filename);
|
||||
free(filename);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (!is_regular_file(filename)) {
|
||||
cons_show("Not a file: %s", filename);
|
||||
free(filename);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (!g_str_has_suffix(filename, ".py") && !g_str_has_suffix(filename, ".so")) {
|
||||
cons_show("Plugins must have one of the following extensions: '.py' '.so'");
|
||||
free(filename);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char *plugin_name = basename(filename);
|
||||
gboolean result = plugins_install(plugin_name, filename);
|
||||
if (result) {
|
||||
cons_show("Plugin installed, use '/plugin load %s' to enable the plugin.", plugin_name);
|
||||
} else {
|
||||
cons_show("Failed to install plugin: %s", plugin_name);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
} else if (g_strcmp0(args[0], "load") == 0) {
|
||||
if (args[1] == NULL) {
|
||||
cons_bad_cmd_usage(command);
|
||||
return TRUE;
|
||||
|
||||
Reference in New Issue
Block a user