~ubuntu-branches/ubuntu/quantal/xarchiver/quantal

« back to all changes in this revision

Viewing changes to src/gzip.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2008-11-07 14:54:00 UTC
  • mfrom: (1.1.7 upstream) (2.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20081107145400-z0j3jmgads8coae2
Tags: 0.5.1-1
MergingĀ upstreamĀ versionĀ 0.5.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (C) 2006 Giuseppe Torelli - <colossus73@gmail.com>
3
 
 *  Copyright (C) 2006 Benedikt Meurer - <benny@xfce.org>
 
2
 *  Copyright (C) 2008 Giuseppe Torelli - <colossus73@gmail.com>
4
3
 *
5
4
 *  This program is free software; you can redistribute it and/or modify
6
5
 *  it under the terms of the GNU General Public License as published by
21
20
#include "gzip.h"
22
21
#include "bzip2.h"
23
22
 
24
 
FILE *fd;
25
 
extern int output_fd;
26
 
 
27
 
void OpenGzip ( XArchive *archive )
 
23
extern delete_func      delete  [XARCHIVETYPE_COUNT];
 
24
extern add_func         add     [XARCHIVETYPE_COUNT];
 
25
extern extract_func     extract [XARCHIVETYPE_COUNT];
 
26
 
 
27
/* GString here is used only to respect the prototype of the
 
28
 * extract function so to make life easier to the coder :)*/
 
29
 
 
30
void xa_open_gzip (XArchive *archive)
28
31
{
29
32
        gchar *command;
 
33
        unsigned short int i;
30
34
 
31
 
        if ( g_str_has_suffix ( archive->escaped_path , ".tar.gz") || g_str_has_suffix ( archive->escaped_path , ".tgz") )
 
35
        if (g_str_has_suffix (archive->escaped_path,".tar.gz") || g_str_has_suffix (archive->escaped_path,".tgz"))
32
36
        {
33
 
    gchar *tar;
34
 
 
35
 
    tar = g_find_program_in_path ("gtar");
36
 
    if (tar == NULL)
37
 
      tar = g_strdup ("tar");
 
37
                archive->type = XARCHIVETYPE_TAR_GZ;
 
38
                archive->delete =       delete[archive->type];
 
39
                archive->add =          add[archive->type];
 
40
                archive->extract =      extract[archive->type];
38
41
 
39
42
                command = g_strconcat (tar, " tzvf " , archive->escaped_path, NULL );
 
43
                archive->has_properties = archive->can_add = archive->can_extract = TRUE;
 
44
                archive->has_test = archive->has_sfx = FALSE;
40
45
                archive->dummy_size = 0;
41
46
                archive->nr_of_files = 0;
42
 
                archive->nr_of_dirs = 0;
43
47
                archive->format ="TAR.GZIP";
44
 
                archive->parse_output = TarOpen;
45
 
 
46
 
                SpawnAsyncProcess ( archive , command , 0, 0);
47
 
 
48
 
                g_free (command);
49
 
                g_free (tar);
50
 
 
51
 
                if ( archive->child_pid == 0 )
52
 
                        return;
53
 
 
54
 
                char *names[]= {(_("Filename")),(_("Permissions")),(_("Symbolic Link")),(_("Owner/Group")),(_("Size")),(_("Date")),(_("Time"))};
55
 
                GType types[]= {G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_UINT64,G_TYPE_STRING,G_TYPE_STRING};
56
 
                xa_create_liststore ( 7, names , (GType *)types, archive );
57
 
        archive->type = XARCHIVETYPE_TAR_GZ;
58
 
        }
59
 
        else
60
 
        {
61
 
                extract_window = xa_create_extract_dialog ( 0 , archive);
62
 
                command = xa_parse_extract_dialog_options ( archive , extract_window, NULL );
63
 
                gtk_widget_destroy ( extract_window->dialog1 );
64
 
                g_free (extract_window);
65
 
        }
66
 
}
67
 
 
68
 
 
 
48
                archive->nc = 7;
 
49
                archive->parse_output = xa_get_tar_line_content;
 
50
                xa_spawn_async_process (archive,command);
 
51
                g_free (command);
 
52
 
 
53
                if (archive->child_pid == 0)
 
54
                        return;
 
55
 
 
56
                GType types[]= {GDK_TYPE_PIXBUF,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_UINT64,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_POINTER};
 
57
                archive->column_types = g_malloc0(sizeof(types));
 
58
                for (i = 0; i < 9; i++)
 
59
                        archive->column_types[i] = types[i];
 
60
 
 
61
                char *names[]= {(_("Points to")),(_("Permissions")),(_("Owner/Group")),(_("Size")),(_("Date")),(_("Time")),NULL};
 
62
                xa_create_liststore (archive,names);
 
63
        }
 
64
        else
 
65
        {
 
66
                archive->can_add = archive->has_test = archive->has_sfx = FALSE;
 
67
                archive->has_properties = archive->can_extract = TRUE;
 
68
                archive->nc = 4;
 
69
                archive->parse_output = xa_get_gzip_line_content;
 
70
                archive->nr_of_files = 1;
 
71
                archive->format = "GZIP";
 
72
 
 
73
                GType types[]= {GDK_TYPE_PIXBUF,G_TYPE_STRING,G_TYPE_UINT64,G_TYPE_UINT64,G_TYPE_STRING,G_TYPE_POINTER};
 
74
                archive->column_types = g_malloc0(sizeof(types));
 
75
                for (i = 0; i < 6; i++)
 
76
                        archive->column_types[i] = types[i];
 
77
 
 
78
                char *names[]= {(_("Compressed")),(_("Size")),(_("Ratio"))};
 
79
                xa_create_liststore (archive,names);
 
80
                
 
81
                command = g_strconcat ("gzip -l ",archive->escaped_path,NULL);
 
82
                xa_spawn_async_process (archive,command);
 
83
                g_free (command);
 
84
 
 
85
                if (archive->child_pid == 0)
 
86
                        return;
 
87
        }
 
88
}
 
89
 
 
90
void xa_get_gzip_line_content (gchar *line, gpointer data)
 
91
{
 
92
        XArchive *archive = data;
 
93
        XEntry *entry;
 
94
        gchar *filename;
 
95
        gchar *basename;
 
96
        gpointer item[3];
 
97
        gint n = 0, a = 0 ,linesize = 0;
 
98
 
 
99
        linesize = strlen(line);
 
100
        if (line[9] == 'c')
 
101
                return;
 
102
 
 
103
        /* Size */
 
104
        for(n=0; n < linesize && line[n] == ' '; n++);
 
105
        a = n;
 
106
        for(; n < linesize && line[n] != ' '; n++);
 
107
        line[n]='\0';
 
108
        item[0] = line + a;
 
109
        n++;
 
110
 
 
111
        /* Compressed */
 
112
        for(; n < linesize && line[n] == ' '; n++);
 
113
        a = n;
 
114
        for(; n < linesize && line[n] != ' '; n++);
 
115
        line[n]='\0';
 
116
        item[1] = line + a;
 
117
        archive->dummy_size += g_ascii_strtoull(item[1],NULL,0);
 
118
        n++;
 
119
 
 
120
        /* Ratio */
 
121
        for(; n < linesize && line[n] == ' '; n++);
 
122
        a = n;
 
123
        for(; n < linesize && line[n] != ' '; n++);
 
124
        line[n] = '\0';
 
125
        item[2] = line + a;
 
126
        n++;
 
127
        
 
128
        line[linesize-1] = '\0';
 
129
        filename = line+n;
 
130
        
 
131
        basename = g_path_get_basename(filename);
 
132
        if (basename == NULL)
 
133
                basename = g_strdup(filename);
 
134
 
 
135
        entry = xa_set_archive_entries_for_each_row (archive,basename,item);
 
136
        g_free(basename);
 
137
}
 
138
 
 
139
gboolean gzip_extract(XArchive *archive,GSList *dummy)
 
140
{
 
141
        gchar *command = NULL,*filename = NULL,*dot,*filename_noext;
 
142
        GSList *list = NULL;
 
143
 
 
144
        filename = xa_remove_path_from_archive_name(archive->escaped_path);
 
145
        dot = strrchr(filename,'.');
 
146
        if (G_LIKELY(dot))
 
147
        {
 
148
                filename_noext = g_strndup(filename,(dot - filename));
 
149
                g_free(filename);
 
150
        }
 
151
        else
 
152
                filename_noext = filename;
 
153
 
 
154
        command = g_strconcat("sh -c \"gunzip -cd ",archive->escaped_path," > ",archive->extraction_path,"/",filename_noext,"\"",NULL);
 
155
        list = g_slist_append(list,command);
 
156
        return xa_run_command (archive,list);
 
157
}