From 4521a410bfb883ed996583b70ad7d39fdfcfc823 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Tue, 29 May 2007 23:54:36 +0000 Subject: [PATCH] yay for splitting to functions. code is now not ugly --- src/install.c | 56 +++++++++++++++++++++++++-------------------------- src/install.h | 2 +- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/install.c b/src/install.c index 2bce641..3b6af76 100644 --- a/src/install.c +++ b/src/install.c @@ -30,6 +30,7 @@ static ssize_t gzread_frontend(int nothing, void *buf, size_t s); static ssize_t gzwrite_frontend(int nothing, const void *buf, size_t s); static gchar *get_theme_dir(); static gboolean change_dir(const gchar *dir); +static gboolean install_theme_to(gchar *theme, gchar *file, gchar *to); tartype_t funcs = { (openfunc_t) gzopen_frontend, @@ -58,62 +59,61 @@ static gchar *get_theme_dir() static gboolean change_dir(const gchar *dir) { - if (chdir(dest) == -1) { - gtk_msg(GTK_MESSAGE_ERROR, - _("Unable to move to directory \"%s\": %s"), - dest, strerror(errno)); + if (chdir(dir) == -1) { + gtk_msg(GTK_MESSAGE_ERROR, _("Unable to move to directory \"%s\": %s"), + dir, strerror(errno)); return FALSE; } return TRUE; } -gboolean install_theme(char *path, char *theme) +static gboolean install_theme_to(gchar *theme, gchar *file, gchar *to) { TAR *t; - gchar *dest; - gint r; gchar *glob; - gchar *curdir; - - if (!(dest = get_theme_dir())) - return FALSE; - - curdir = g_get_current_dir(); - if (!change_dir(dest)) { - g_free(curdir); - return FALSE; - } + gint r; - if (tar_open(&t, path, &funcs, 0, O_RDONLY, TAR_GNU) == -1) { + if (tar_open(&t, file, &funcs, 0, O_RDONLY, TAR_GNU) == -1) { gtk_msg(GTK_MESSAGE_ERROR, _("Unable to open the file \"%s\": %s"), - path, strerror(errno)); - chdir(curdir); - g_free(curdir); + file, strerror(errno)); return FALSE; } glob = g_strdup_printf("%s/openbox-3/*", theme); - r = tar_extract_glob(t, glob, dest); + r = tar_extract_glob(t, glob, to); g_free(glob); + tar_close(t); - if (r != 0) { + if (r != 0) gtk_msg(GTK_MESSAGE_ERROR, _("Unable to extract the file \"%s\".\nIt does not appear to be a valid Openbox theme archive (in tar.gz format)."), - path, strerror(errno)); + file, strerror(errno)); + + return r == 0; +} + +gboolean install_theme(gchar *path, gchar *theme) +{ + gchar *dest; + gchar *curdir; - g_free(dest); - chdir(curdir); + if (!(dest = get_theme_dir())) + return FALSE; + + curdir = g_get_current_dir(); + if (!change_dir(dest)) { g_free(curdir); return FALSE; } - gtk_msg(GTK_MESSAGE_INFO, _("%s was installed to %s"), theme, dest); + if (install_theme_to(theme, path, dest)) + gtk_msg(GTK_MESSAGE_INFO, _("%s was installed to %s"), theme, dest); g_free(dest); - chdir(curdir); + change_dir(curdir); g_free(curdir); return TRUE; diff --git a/src/install.h b/src/install.h index 3b46b47..215bd34 100644 --- a/src/install.h +++ b/src/install.h @@ -3,6 +3,6 @@ #include -gboolean install_theme(char *path, char *theme); +gboolean install_theme(gchar *path, gchar *theme); #endif -- 2.39.2