diff options
author | James Booth <boothj5@gmail.com> | 2016-07-12 23:50:21 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2016-07-12 23:50:21 +0100 |
commit | 0991699ae65387dc67852a3f9d465de25d6067a0 (patch) | |
tree | 93ac5aab454e6d2b7a281deb0441965c5242f47a /src/plugins/plugins.c | |
parent | 5f393a6d9f995a9be86923f24e8b634a7a9d4ed9 (diff) | |
download | profani-tty-0991699ae65387dc67852a3f9d465de25d6067a0.tar.gz |
Add /plugins install command
Diffstat (limited to 'src/plugins/plugins.c')
-rw-r--r-- | src/plugins/plugins.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c index 24eb40d2..5096bdee 100644 --- a/src/plugins/plugins.c +++ b/src/plugins/plugins.c @@ -62,6 +62,8 @@ static GHashTable *plugins; +static gchar* _get_plugins_dir(void); + void plugins_init(void) { @@ -129,6 +131,30 @@ plugins_init(void) } gboolean +plugins_install(const char *const plugin_name, const char *const filename) +{ + char *plugins_dir = _get_plugins_dir(); + GString *target_path = g_string_new(plugins_dir); + free(plugins_dir); + g_string_append(target_path, "/"); + g_string_append(target_path, plugin_name); + + ProfPlugin *plugin = g_hash_table_lookup(plugins, plugin_name); + if (plugin) { + plugins_unload(plugin_name); + } + + gboolean result = copy_file(filename, target_path->str); + g_string_free(target_path, TRUE); + + if (result) { + result = plugins_load(plugin_name); + } + + return result; +} + +gboolean plugins_load(const char *const name) { ProfPlugin *plugin = g_hash_table_lookup(plugins, name); |