--- capplets/theme-switcher/gnome-theme-installer.c 2005-12-04 17:23:35.000000000 -0600 +++ capplets/theme-switcher/gnome-theme-installer.c 2005-12-04 17:37:58.000000000 -0600 @@ -139,19 +139,32 @@ transfer_done_targz_idle_cb (gpointer data) { int status; - gchar *command, *filename; + gchar *command, *filename, *gzip, *tar; theme_properties *theme_props = data; - + + if (!(gzip = g_find_program_in_path("gzip"))) { + return FALSE; + } + + if (!(tar = g_find_program_in_path("tar"))) { + g_free (gzip); + return FALSE; + } + /* this should be something more clever and nonblocking */ filename = g_shell_quote(theme_props->filename); - command = g_strdup_printf ("sh -c 'cd \"%s\"; /bin/gzip -d -c < \"%s\" | /bin/tar xf - '", - theme_props->target_tmp_dir, filename); + command = g_strdup_printf ("sh -c 'cd \"%s\"; %s -d -c < \"%s\" | %s xf - '", + theme_props->target_tmp_dir, gzip, filename, tar); g_free(filename); if (g_spawn_command_line_sync (command, NULL, NULL, &status, NULL) && status == 0) { g_free (command); + g_free (gzip); + g_free (tar); return TRUE; } else { g_free (command); + g_free (gzip); + g_free (tar); return FALSE; } } @@ -171,19 +184,32 @@ transfer_done_tarbz2_idle_cb (gpointer data) { int status; - gchar *command, *filename; + gchar *command, *filename, *bzip2, *tar; theme_properties *theme_props = data; + + if (!(bzip2 = g_find_program_in_path("bzip2"))) { + return FALSE; + } + + if (!(tar = g_find_program_in_path("tar"))) { + g_free (bzip2); + return FALSE; + } filename = g_shell_quote(theme_props->filename); /* this should be something more clever and nonblocking */ - command = g_strdup_printf ("sh -c 'cd \"%s\"; /usr/bin/bzip2 -d -c < \"%s\" | /bin/tar xf - '", - theme_props->target_tmp_dir, filename); + command = g_strdup_printf ("sh -c 'cd \"%s\"; %s -d -c < \"%s\" | %s xf - '", + theme_props->target_tmp_dir, bzip2, filename, tar); g_free (filename); if (g_spawn_command_line_sync (command, NULL, NULL, &status, NULL) && status == 0) { g_free (command); + g_free (bzip2); + g_free (tar); return TRUE; } else { g_free (command); + g_free (bzip2); + g_free (tar); return FALSE; } } @@ -193,7 +219,7 @@ { GtkWidget *dialog; int len = strlen (path); - gchar *command,**dir, *first_line, *filename; + gchar *command,**dir, *first_line, *filename, *gzip, *bzip2, *tar; int status,theme_type; theme_properties *theme_props; GnomeVFSURI *theme_source_dir, *theme_dest_dir; @@ -206,17 +232,31 @@ g_get_home_dir(), g_random_int()); + if (!(gzip = g_find_program_in_path("gzip"))) { + return FALSE; + } + + if (!(bzip2 = g_find_program_in_path("bzip2"))) { + g_free (gzip); + return FALSE; + } + + if (!(tar = g_find_program_in_path("tar"))) { + g_free (gzip); + g_free (bzip2); + return FALSE; + } - if (path && len > 7 && ( (!strcmp (path + len - 7, ".tar.gz")) || (!strcmp (path + len - 4, ".tgz")) )) { + if (tar && gzip && path && len > 7 && ( (!strcmp (path + len - 7, ".tar.gz")) || (!strcmp (path + len - 4, ".tgz")) )) { filename = g_shell_quote (path); - command = g_strdup_printf ("sh -c '/bin/gzip -d -c < \"%s\" | /bin/tar ft - | head -1'", - filename); + command = g_strdup_printf ("sh -c '%s -d -c < \"%s\" | %s ft - | head -n1'", + gzip, filename, tar); theme_props->filetype=TARGZ; g_free (filename); - } else if (path && len > 8 && !strcmp (path + len - 8, ".tar.bz2")) { + } else if (tar && bzip2 && path && len > 8 && !strcmp (path + len - 8, ".tar.bz2")) { filename = g_shell_quote (path); - command = g_strdup_printf ("sh -c '/usr/bin/bzip2 -d -c < \"%s\" | /bin/tar ft - | head -1'", - filename); + command = g_strdup_printf ("sh -c '%s -d -c < \"%s\" | %s ft - | head -n1'", + bzip2, filename, tar); theme_props->filetype=TARBZ; g_free (filename); } else { @@ -230,6 +270,9 @@ gnome_vfs_unlink(path); g_free (theme_props->target_tmp_dir); g_free (theme_props); + g_free (tar); + g_free (gzip); + g_free (bzip2); return; } @@ -245,6 +288,9 @@ g_free (command); g_free (theme_props->target_tmp_dir); g_free (theme_props); + g_free (tar); + g_free (gzip); + g_free (bzip2); return; } @@ -252,7 +298,7 @@ theme_props->filename=g_strdup(path); if (theme_props->filetype == TARBZ ) { - if (!g_file_test ("/usr/bin/bzip2", G_FILE_TEST_EXISTS)) { + if (!bzip2) { dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, @@ -265,6 +311,9 @@ g_free (theme_props->target_tmp_dir); g_free (theme_props->filename); g_free (theme_props); + g_free (tar); + g_free (gzip); + g_free (bzip2); return; } @@ -281,12 +330,15 @@ g_free (theme_props->filename); g_free (theme_props); g_free (command); + g_free (tar); + g_free (gzip); + g_free (bzip2); return; } } if (theme_props->filetype == TARGZ ) { - if (!g_file_test ("/bin/gzip", G_FILE_TEST_EXISTS)) { + if (!gzip) { dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, @@ -299,6 +351,9 @@ g_free (theme_props->target_tmp_dir); g_free (theme_props->filename); g_free (theme_props); + g_free (tar); + g_free (gzip); + g_free (bzip2); return; } if (!transfer_done_targz_idle_cb(theme_props)) { @@ -314,6 +369,9 @@ g_free (theme_props->filename); g_free (theme_props); g_free (command); + g_free (tar); + g_free (gzip); + g_free (bzip2); return; } } @@ -351,6 +409,9 @@ g_free (theme_props->theme_tmp_dir); g_free (theme_props); g_free (command); + g_free (tar); + g_free (gzip); + g_free (bzip2); return; } else { dialog = gtk_message_dialog_new (NULL, @@ -365,6 +426,9 @@ g_free (theme_props->theme_tmp_dir); g_free (theme_props); g_free (command); + g_free (tar); + g_free (gzip); + g_free (bzip2); return; } /* Move the Dir to the target dir */ @@ -391,6 +455,9 @@ g_free (theme_props->user_message); g_free (theme_props); g_free (command); + g_free (tar); + g_free (gzip); + g_free (bzip2); return; } else { dialog = gtk_message_dialog_new (NULL, @@ -408,6 +475,9 @@ g_free (theme_props->user_message); g_free (theme_props); g_free (command); + g_free (tar); + g_free (gzip); + g_free (bzip2); return; } @@ -416,6 +486,9 @@ g_free (theme_props->target_tmp_dir); g_free (theme_props->filename); g_free (theme_props); + g_free (tar); + g_free (gzip); + g_free (bzip2); } static void