Allow unloading all plugins
This commit is contained in:
@@ -6212,120 +6212,140 @@ cmd_xa(ProfWin *window, const char *const command, gchar **args)
|
||||
}
|
||||
|
||||
gboolean
|
||||
cmd_plugins(ProfWin *window, const char *const command, gchar **args)
|
||||
cmd_plugins_install(ProfWin *window, const char *const command, gchar **args)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
gchar *plugin_name = g_path_get_basename(filename);
|
||||
gboolean result = plugins_install(plugin_name, filename);
|
||||
if (result) {
|
||||
cons_show("Plugin installed: %s", plugin_name);
|
||||
} else {
|
||||
cons_show("Failed to install plugin: %s", plugin_name);
|
||||
}
|
||||
g_free(plugin_name);
|
||||
|
||||
free(filename);
|
||||
return TRUE;
|
||||
} else if (g_strcmp0(args[0], "load") == 0) {
|
||||
if (args[1] == NULL) {
|
||||
cons_bad_cmd_usage(command);
|
||||
return TRUE;
|
||||
}
|
||||
gboolean res = plugins_load(args[1]);
|
||||
if (res) {
|
||||
cons_show("Loaded plugin: %s", args[1]);
|
||||
} else {
|
||||
cons_show("Failed to load plugin: %s", args[1]);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
} else if (g_strcmp0(args[0], "unload") == 0) {
|
||||
if (args[1] == NULL) {
|
||||
cons_bad_cmd_usage(command);
|
||||
return TRUE;
|
||||
}
|
||||
gboolean res = plugins_unload(args[1]);
|
||||
if (res) {
|
||||
cons_show("Unloaded plugin: %s", args[1]);
|
||||
} else {
|
||||
cons_show("Failed to unload plugin: %s", args[1]);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
} else if (g_strcmp0(args[0], "reload") == 0) {
|
||||
if (args[1] == NULL) {
|
||||
plugins_reload_all();
|
||||
cons_show("Reloaded all plugins");
|
||||
} else {
|
||||
gboolean res = plugins_reload(args[1]);
|
||||
if (res) {
|
||||
cons_show("Reloaded plugin: %s", args[1]);
|
||||
} else {
|
||||
cons_show("Failed to reload plugin: %s", args[1]);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
} else if (g_strcmp0(args[0], "python_version") == 0) {
|
||||
#ifdef HAVE_PYTHON
|
||||
const char *version = python_get_version();
|
||||
cons_show("Python version:");
|
||||
cons_show("%s", version);
|
||||
#else
|
||||
cons_show("This build does not support pytyon plugins.");
|
||||
#endif
|
||||
return TRUE;
|
||||
|
||||
} else {
|
||||
GList *plugins = plugins_loaded_list();
|
||||
if (plugins == NULL) {
|
||||
cons_show("No plugins installed.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GList *curr = plugins;
|
||||
cons_show("Installed plugins:");
|
||||
while (curr) {
|
||||
cons_show(" %s", curr->data);
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
g_list_free(plugins);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
gchar *plugin_name = g_path_get_basename(filename);
|
||||
gboolean result = plugins_install(plugin_name, filename);
|
||||
if (result) {
|
||||
cons_show("Plugin installed: %s", plugin_name);
|
||||
} else {
|
||||
cons_show("Failed to install plugin: %s", plugin_name);
|
||||
}
|
||||
g_free(plugin_name);
|
||||
|
||||
free(filename);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
cmd_plugins_load(ProfWin *window, const char *const command, gchar **args)
|
||||
{
|
||||
if (args[1] == NULL) {
|
||||
cons_bad_cmd_usage(command);
|
||||
return TRUE;
|
||||
}
|
||||
gboolean res = plugins_load(args[1]);
|
||||
if (res) {
|
||||
cons_show("Loaded plugin: %s", args[1]);
|
||||
} else {
|
||||
cons_show("Failed to load plugin: %s", args[1]);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
cmd_plugins_unload(ProfWin *window, const char *const command, gchar **args)
|
||||
{
|
||||
if (args[1] == NULL) {
|
||||
plugins_unload_all();
|
||||
cons_show("Unloaded all plugins");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean res = plugins_unload(args[1]);
|
||||
if (res) {
|
||||
cons_show("Unloaded plugin: %s", args[1]);
|
||||
} else {
|
||||
cons_show("Failed to unload plugin: %s", args[1]);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
cmd_plugins_reload(ProfWin *window, const char *const command, gchar **args)
|
||||
{
|
||||
if (args[1] == NULL) {
|
||||
plugins_reload_all();
|
||||
cons_show("Reloaded all plugins");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean res = plugins_reload(args[1]);
|
||||
if (res) {
|
||||
cons_show("Reloaded plugin: %s", args[1]);
|
||||
} else {
|
||||
cons_show("Failed to reload plugin: %s", args[1]);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
cmd_plugins_python_version(ProfWin *window, const char *const command, gchar **args)
|
||||
{
|
||||
#ifdef HAVE_PYTHON
|
||||
const char *version = python_get_version();
|
||||
cons_show("Python version:");
|
||||
cons_show("%s", version);
|
||||
#else
|
||||
cons_show("This build does not support pytyon plugins.");
|
||||
#endif
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
cmd_plugins(ProfWin *window, const char *const command, gchar **args)
|
||||
{
|
||||
GList *plugins = plugins_loaded_list();
|
||||
if (plugins == NULL) {
|
||||
cons_show("No plugins installed.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GList *curr = plugins;
|
||||
cons_show("Installed plugins:");
|
||||
while (curr) {
|
||||
cons_show(" %s", curr->data);
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
g_list_free(plugins);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
||||
Reference in New Issue
Block a user