22
21
#include "extract_dialog.h"
23
22
#include "string_utils.h"
25
extern gboolean TarOpen (GIOChannel *ioc, GIOCondition cond, gpointer data);
24
extern delete_func delete [XARCHIVETYPE_COUNT];
25
extern add_func add [XARCHIVETYPE_COUNT];
26
extern extract_func extract [XARCHIVETYPE_COUNT];
31
void OpenBzip2 ( XArchive *archive )
29
void xa_open_bzip2_lzma (XArchive *archive)
34
if ( g_str_has_suffix ( archive->escaped_path , ".tar.bz2") || g_str_has_suffix ( archive->escaped_path , ".tar.bz") || g_str_has_suffix ( archive->escaped_path , ".tbz") || g_str_has_suffix ( archive->escaped_path , ".tbz2" ) )
32
gchar *filename = NULL;;
38
if (g_str_has_suffix(archive->escaped_path,".tar.bz2") || g_str_has_suffix (archive->escaped_path,".tar.bz")
39
|| g_str_has_suffix ( archive->escaped_path , ".tbz") || g_str_has_suffix (archive->escaped_path,".tbz2") )
38
tar = g_find_program_in_path ("gtar");
40
tar = g_strdup ("tar");
42
command = g_strconcat (tar, " tfjv " , archive->escaped_path, NULL );
43
archive->dummy_size = 0;
44
archive->nr_of_files = 0;
45
archive->nr_of_dirs = 0;
41
archive->type = XARCHIVETYPE_TAR_BZ2;
46
42
archive->format = "TAR.BZIP2";
47
archive->parse_output = TarOpen;
48
SpawnAsyncProcess ( archive , command , 0, 0);
53
if ( archive->child_pid == 0 )
43
archive->delete = delete[archive->type];
44
archive->add = add[archive->type];
45
archive->extract = extract[archive->type];
46
xa_open_tar_compressed_file(archive);
48
else if (g_str_has_suffix(archive->escaped_path,".tar.lzma") || g_str_has_suffix (archive->escaped_path,".tlz"))
50
archive->type = XARCHIVETYPE_TAR_LZMA;
51
archive->format = "TAR.LZMA";
52
archive->delete = delete[archive->type];
53
archive->add = add[archive->type];
54
archive->extract = extract[archive->type];
55
xa_open_tar_compressed_file(archive);
57
else if (g_str_has_suffix(archive->escaped_path,".tar.lzop") || g_str_has_suffix (archive->escaped_path,".tzo"))
59
archive->type = XARCHIVETYPE_TAR_LZOP;
60
archive->format = "TAR.LZOP";
61
archive->delete = delete[archive->type];
62
archive->add = add[archive->type];
63
archive->extract = extract[archive->type];
64
xa_open_tar_compressed_file(archive);
69
gchar *compressed = NULL;
70
gchar *size = NULL,*command = NULL,*executable = NULL,*dot = NULL;
74
if (archive->type == XARCHIVETYPE_BZIP2)
76
archive->format = "BZIP2";
77
executable = "bzip2 ";
80
else if (archive->type == XARCHIVETYPE_LZMA)
82
archive->format = "LZMA";
86
else if (archive->type == XARCHIVETYPE_LZOP)
88
archive->format = "LZOP";
92
archive->can_add = archive->has_test = archive->has_sfx = FALSE;
93
archive->has_properties = archive->can_extract = TRUE;
95
archive->nr_of_files = 1;
97
GType types[]= {GDK_TYPE_PIXBUF,G_TYPE_STRING,G_TYPE_UINT64,G_TYPE_UINT64,G_TYPE_POINTER};
98
archive->column_types = g_malloc0(sizeof(types));
99
for (i = 0; i < 5; i++)
100
archive->column_types[i] = types[i];
102
char *names[]= {(_("Original")),(_("Compressed"))};
103
xa_create_liststore (archive,names);
104
result = xa_create_temp_directory (archive);
56
char *names[]= {(_("Filename")),(_("Permissions")),(_("Symbolic Link")),(_("Owner/Group")),(_("Size")),(_("Date")),(_("Time"))};
57
GType types[]= {G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_UINT64,G_TYPE_STRING,G_TYPE_STRING};
58
xa_create_liststore ( 7, names , (GType *)types, archive);
59
archive->type = XARCHIVETYPE_TAR_BZ2;
63
extract_window = xa_create_extract_dialog ( 0 , archive);
64
command = xa_parse_extract_dialog_options ( archive , extract_window, NULL );
65
gtk_widget_destroy ( extract_window->dialog1 );
66
g_free (extract_window);
108
/* Let's copy the bzip2 file in the tmp dir */
109
command = g_strconcat("cp -f ",archive->escaped_path," ",archive->tmp,NULL);
110
list = g_slist_append(list,command);
111
/* Let's get its compressed file size */
112
stat (archive->escaped_path,&my_stat);
113
compressed = g_strdup_printf("%lld",(unsigned long long int)my_stat.st_size);
114
item[1] = compressed;
116
/* Let's extract it */
117
_filename = g_path_get_basename(archive->escaped_path);
118
if (_filename[0] == '.')
119
command = g_strconcat(executable,"-f -d ",archive->tmp,"/",archive->escaped_path,NULL);
121
command = g_strconcat(executable,"-f -d ",archive->tmp,"/",_filename,NULL);
123
list = g_slist_append(list,command);
124
xa_run_command (archive,list);
126
/* and let's get its uncompressed file size */
127
dot = strrchr(_filename,'.');
128
if (_filename || G_LIKELY(dot))
130
filename = g_strndup(_filename,strlen(_filename) - len);
131
command = g_strconcat(archive->tmp,"/",filename,NULL);
135
command = g_strconcat(archive->tmp,"/",archive->escaped_path,NULL);
136
filename = g_strdup(archive->escaped_path);
138
stat (command,&my_stat);
140
size = g_strdup_printf("%lld",(unsigned long long int)my_stat.st_size);
141
archive->dummy_size = my_stat.st_size;
144
entry = xa_set_archive_entries_for_each_row (archive,filename,item);
149
xa_update_window_with_archive_entries (archive,NULL);
150
gtk_tree_view_set_model (GTK_TREE_VIEW(archive->treeview), archive->model);
151
g_object_unref (archive->model);
70
void gzip_bzip2_extract ( XArchive *archive , gboolean flag )
155
void xa_open_tar_compressed_file(XArchive *archive)
73
gchar *filename_only = NULL;
74
157
gchar *command = NULL;
158
unsigned short int i;
160
if (archive->type == XARCHIVETYPE_TAR_BZ2)
161
command = g_strconcat(tar," tfjv ",archive->escaped_path,NULL);
162
else if (archive->type == XARCHIVETYPE_TAR_LZMA)
163
command = g_strconcat(tar," tv --use-compress-program=lzma -f ",archive->escaped_path,NULL);
164
else if (archive->type == XARCHIVETYPE_TAR_LZOP)
165
command = g_strconcat(tar," tv --use-compress-program=lzop -f ",archive->escaped_path,NULL);
168
archive->has_properties = archive->can_add = archive->can_extract = TRUE;
169
archive->has_test = archive->has_sfx = FALSE;
170
archive->dummy_size = 0;
171
archive->nr_of_files = 0;
173
archive->parse_output = xa_get_tar_line_content;
174
xa_spawn_async_process (archive,command);
177
if (archive->child_pid == 0)
180
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};
181
archive->column_types = g_malloc0(sizeof(types));
182
for (i = 0; i < 9; i++)
183
archive->column_types[i] = types[i];
185
char *names[]= {(_("Points to")),(_("Permissions")),(_("Owner/Group")),(_("Size")),(_("Date")),(_("Time")),NULL};
186
xa_create_liststore (archive,names);
189
gboolean lzma_bzip2_extract (XArchive *archive,GSList *dummy)
192
gchar *command = NULL,*executable = NULL,*filename = NULL, *dot = NULL, *filename_noext = NULL;
75
193
gboolean result = FALSE;
79
archive->extraction_path = g_strdup (gtk_entry_get_text ( GTK_ENTRY (extract_window->destination_path_entry) ));
81
if ( strlen ( archive->extraction_path ) > 0 )
86
text = g_strdup_printf(_("Extracting gzip file to %s"), archive->extraction_path);
88
text = g_strdup_printf(_("Extracting bzip2 file to %s"), archive->extraction_path);
89
Update_StatusBar ( text );
93
filename_only = g_strrstr (archive->escaped_path , "/");
94
if (file_extension_is (filename_only,".gz") || file_extension_is (filename_only,".bz2") )
100
command = g_strconcat ("cp -f ", archive->escaped_path, " /tmp", NULL);
102
command = g_strconcat ("cp -f ", archive->escaped_path, " /tmp" , filename_only, flag ? ".gz" : ".bz2", NULL);
104
result = xa_run_command (command , 0);
109
command = g_strconcat (flag ? "gzip -f -d -n " : "bzip2 -f -d ", "/tmp",filename_only, NULL);
111
command = g_strconcat (flag ? "gzip -f -d -n " : "bzip2 -f -d ","/tmp",filename_only, flag ? ".gz" : ".bz2", NULL);
113
result = xa_run_command (command , 0);
121
filename_only[strlen(filename_only) - 3] = '\0';
123
filename_only[strlen(filename_only) - 4] = '\0';
124
command = g_strconcat ("mv -f /tmp",filename_only, " ", archive->extraction_path,NULL);
128
if ( g_file_test (archive->extraction_path, G_FILE_TEST_IS_DIR) )
129
command = g_strconcat ("mv -f /tmp",filename_only, " ", archive->extraction_path,filename_only,NULL);
131
command = g_strconcat ("mv -f /tmp",filename_only, " ", archive->extraction_path,NULL);
134
result = xa_run_command (command , 0);
141
xa_set_button_state (1,1,0,0,0,0);
142
archive->status = XA_ARCHIVESTATUS_IDLE;
143
gtk_widget_set_sensitive (Stop_button, FALSE);
144
gtk_widget_hide ( viewport2 );
145
Update_StatusBar ( _("Operation canceled."));
148
xa_watch_child (archive->child_pid, 0, archive);
151
void xa_add_delete_tar_bzip2_gzip ( GString *list , XArchive *archive , gboolean dummy , gboolean add )
153
gchar *command, *msg, *tar,*temp_name,*file_ext;
158
gtk_widget_show (viewport2);
159
msg = g_strdup_printf(_("Decompressing tar file with %s, please wait...") , dummy ? "gzip" : "bzip2");
160
Update_StatusBar ( msg );
164
/* Let's copy the archive to /tmp first */
165
temp_name = g_strconcat ( " /tmp", g_strrstr (archive->escaped_path , "/"), NULL);
166
command = g_strconcat ("cp -ar " ,archive->escaped_path,temp_name,NULL);
168
result = xa_run_command (command , 0);
170
result = SpawnSyncCommand ( command );
177
command = g_strconcat (dummy ? "gzip -f " : "bzip2 ", "-f -d ",temp_name,NULL);
179
result = xa_run_command (command , 0);
181
result = SpawnSyncCommand ( command );
189
tar = g_find_program_in_path ("gtar");
191
tar = g_strdup ("tar");
192
l = strlen (temp_name);
194
if (file_extension_is (archive->escaped_path,".tar.bz2") )
195
temp_name[l - 4] = 0;
196
else if (file_extension_is (archive->escaped_path,".tbz2") )
198
temp_name[l - 3] = 'a';
199
temp_name[l - 2] = 'r';
200
temp_name[l - 1] = 0;
202
else if (file_extension_is (archive->escaped_path,".tar.gz") )
203
temp_name[l - 3] = 0;
205
else if (file_extension_is (archive->escaped_path,".tgz") || file_extension_is (archive->escaped_path, ".tbz") )
207
temp_name[l - 2] = 'a';
208
temp_name[l - 1] = 'r';
212
command = g_strconcat (tar, " ",
213
archive->add_recurse ? "" : "--no-recursion ",
214
archive->remove_files ? "--remove-files " : "",
215
archive->update ? "-uvvf " : "-rvvf ",
219
command = g_strconcat (tar, " --delete -f " , temp_name , list->str , NULL );
221
result = xa_run_command (command , 0);
223
result = SpawnSyncCommand ( command );
234
msg = g_strdup_printf(_("Recompressing tar file with %s, please wait...") , dummy ? "gzip" : "bzip2");
235
Update_StatusBar ( msg );
239
command = g_strconcat ( dummy ? "gzip -f " : "bzip2 ", "-f " , temp_name , NULL );
241
result = xa_run_command (command , 0);
243
result = SpawnSyncCommand ( command );
255
/* Let's move the modified archive from /tmp to the original archive location */
256
command = g_strconcat ( "mv " , temp_name , file_ext, " " ,archive->escaped_path, NULL );
258
result = xa_run_command (command , 1);
260
result = SpawnSyncCommand ( command );
196
if (archive->type == XARCHIVETYPE_BZIP2)
198
executable = "bzip2 ";
201
else if (archive->type == XARCHIVETYPE_LZMA)
203
executable = "lzma ";
206
else if (archive->type == XARCHIVETYPE_LZOP)
208
executable = "lzop ";
212
filename = xa_remove_path_from_archive_name(archive->escaped_path);
213
dot = strrchr(filename,'.');
216
filename_noext = g_strndup(filename,(dot - filename));
220
filename_noext = filename;
222
command = g_strconcat("sh -c \"",executable, " ",archive->escaped_path," -dc > ",archive->extraction_path,"/",filename_noext,"\"",NULL);
223
g_free(filename_noext);
224
list = g_slist_append(list,command);
225
result = xa_run_command (archive,list);