yay for splitting to functions. code is now not ugly
authorDana Jansens <danakj@orodu.net>
Tue, 29 May 2007 23:54:36 +0000 (23:54 +0000)
committerDana Jansens <danakj@orodu.net>
Tue, 29 May 2007 23:54:36 +0000 (23:54 +0000)
src/install.c
src/install.h

index 2bce641fa734b2c0cdfcd1ca359ff889ef513d4b..3b6af76e0392e768edbdede2bf9e3b44a45d127c 100644 (file)
@@ -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;
index 3b46b4763d0a75ad5ee9e4d51c1a30e84e2a7225..215bd341bd363c470b59b602d9dfa8e921ceaa4e 100644 (file)
@@ -3,6 +3,6 @@
 
 #include <glib.h>
 
-gboolean install_theme(char *path, char *theme);
+gboolean install_theme(gchar *path, gchar *theme);
 
 #endif