Move all filepath handling to files.c

This commit is contained in:
James Booth
2016-07-24 21:35:12 +01:00
parent 29452f8f1b
commit a3a73cf003
19 changed files with 174 additions and 262 deletions

View File

@@ -41,6 +41,7 @@
#include "log.h"
#include "config/preferences.h"
#include "config/files.h"
#include "plugins/api.h"
#include "plugins/callbacks.h"
#include "plugins/plugins.h"
@@ -60,9 +61,9 @@ c_plugin_create(const char *const filename)
ProfPlugin *plugin;
void *handle = NULL;
gchar *plugins_dir = plugins_get_dir();
char *plugins_dir = files_get_data_path(DIR_PLUGINS);
GString *path = g_string_new(plugins_dir);
g_free(plugins_dir);
free(plugins_dir);
g_string_append(path, "/");
g_string_append(path, filename);

View File

@@ -131,7 +131,7 @@ plugins_init(void)
gboolean
plugins_install(const char *const plugin_name, const char *const filename)
{
char *plugins_dir = plugins_get_dir();
char *plugins_dir = files_get_data_path(DIR_PLUGINS);
GString *target_path = g_string_new(plugins_dir);
free(plugins_dir);
g_string_append(target_path, "/");
@@ -266,7 +266,7 @@ GSList*
plugins_unloaded_list(void)
{
GSList *result = NULL;
char *plugins_dir = plugins_get_dir();
char *plugins_dir = files_get_data_path(DIR_PLUGINS);
_plugins_unloaded_list_dir(plugins_dir, &result);
free(plugins_dir);
@@ -830,16 +830,3 @@ plugins_shutdown(void)
callbacks_close();
disco_close();
}
char*
plugins_get_dir(void)
{
gchar *xdg_data = files_get_xdg_data_home();
GString *plugins_dir = g_string_new(xdg_data);
g_string_append(plugins_dir, "/profanity/plugins");
char *result = strdup(plugins_dir->str);
g_free(xdg_data);
g_string_free(plugins_dir, TRUE);
return result;
}

View File

@@ -36,6 +36,7 @@
#include "config.h"
#include "config/preferences.h"
#include "config/files.h"
#include "plugins/api.h"
#include "plugins/callbacks.h"
#include "plugins/plugins.h"
@@ -77,7 +78,7 @@ python_env_init(void)
python_init_prof();
gchar *plugins_dir = plugins_get_dir();
char *plugins_dir = files_get_data_path(DIR_PLUGINS);
GString *path = g_string_new("import sys\n");
g_string_append(path, "sys.path.append(\"");
g_string_append(path, plugins_dir);

View File

@@ -49,24 +49,21 @@ static void _save_settings(void);
void
plugin_settings_init(void)
{
gchar *xdg_data = files_get_xdg_data_home();
GString *fileloc = g_string_new(xdg_data);
g_string_append(fileloc, "/profanity/plugin_settings");
g_free(xdg_data);
char *settings_file = files_get_data_path(FILE_PLUGIN_SETTINGS);
if (g_file_test(fileloc->str, G_FILE_TEST_EXISTS)) {
g_chmod(fileloc->str, S_IRUSR | S_IWUSR);
if (g_file_test(settings_file, G_FILE_TEST_EXISTS)) {
g_chmod(settings_file, S_IRUSR | S_IWUSR);
}
settings = g_key_file_new();
g_key_file_load_from_file(settings, fileloc->str, G_KEY_FILE_KEEP_COMMENTS, NULL);
g_key_file_load_from_file(settings, settings_file, G_KEY_FILE_KEEP_COMMENTS, NULL);
gsize g_data_size;
gchar *g_data = g_key_file_to_data(settings, &g_data_size, NULL);
g_file_set_contents(fileloc->str, g_data, g_data_size, NULL);
g_chmod(fileloc->str, S_IRUSR | S_IWUSR);
g_file_set_contents(settings_file, g_data, g_data_size, NULL);
g_chmod(settings_file, S_IRUSR | S_IWUSR);
g_free(g_data);
g_string_free(fileloc, TRUE);
free(settings_file);
}
void
@@ -135,19 +132,13 @@ _save_settings(void)
gsize g_data_size;
gchar *g_data = g_key_file_to_data(settings, &g_data_size, NULL);
gchar *xdg_data = files_get_xdg_data_home();
GString *fileloc = g_string_new(xdg_data);
g_free(xdg_data);
g_string_append(fileloc, "/profanity/");
char *base = strdup(fileloc->str);
g_string_append(fileloc, "plugin_settings");
gchar *true_loc = get_file_or_linked(fileloc->str, base);
free(base);
char *fileloc = files_get_data_path(FILE_PLUGIN_SETTINGS);
gchar *base = g_path_get_basename(fileloc);
gchar *true_loc = get_file_or_linked(fileloc, base);
g_free(base);
g_file_set_contents(true_loc, g_data, g_data_size, NULL);
free(true_loc);
g_free(g_data);
g_chmod(fileloc->str, S_IRUSR | S_IWUSR);
g_string_free(fileloc, TRUE);
g_chmod(fileloc, S_IRUSR | S_IWUSR);
free(fileloc);
}

View File

@@ -32,6 +32,8 @@
*
*/
#include <stdlib.h>
#include <glib.h>
#include <glib/gstdio.h>
@@ -44,24 +46,21 @@ static GKeyFile *themes;
void
plugin_themes_init(void)
{
gchar *xdg_data = files_get_xdg_data_home();
GString *fileloc = g_string_new(xdg_data);
g_string_append(fileloc, "/profanity/plugin_themes");
g_free(xdg_data);
char *themes_file = files_get_data_path(FILE_PLUGIN_THEMES);
if (g_file_test(fileloc->str, G_FILE_TEST_EXISTS)) {
g_chmod(fileloc->str, S_IRUSR | S_IWUSR);
if (g_file_test(themes_file, G_FILE_TEST_EXISTS)) {
g_chmod(themes_file, S_IRUSR | S_IWUSR);
}
themes = g_key_file_new();
g_key_file_load_from_file(themes, fileloc->str, G_KEY_FILE_KEEP_COMMENTS, NULL);
g_key_file_load_from_file(themes, themes_file, G_KEY_FILE_KEEP_COMMENTS, NULL);
gsize g_data_size;
gchar *g_data = g_key_file_to_data(themes, &g_data_size, NULL);
g_file_set_contents(fileloc->str, g_data, g_data_size, NULL);
g_chmod(fileloc->str, S_IRUSR | S_IWUSR);
g_file_set_contents(themes_file, g_data, g_data_size, NULL);
g_chmod(themes_file, S_IRUSR | S_IWUSR);
g_free(g_data);
g_string_free(fileloc, TRUE);
free(themes_file);
}
void