19
19
#include "config.h"
22
23
extern gboolean unrar;
23
static gboolean RarOpen (GIOChannel *ioc, GIOCondition cond, gpointer data);
24
extern void xa_reload_archive_content(XArchive *archive);
25
extern void xa_create_liststore ( XArchive *archive, gchar *columns_names[]);
26
void OpenRar ( XArchive *archive )
27
void xa_open_rar (XArchive *archive)
29
30
gchar *command = NULL;
32
jump_header = read_filename = last_line = encrypted = FALSE;
37
archive->can_add = archive->has_sfx = FALSE;
42
archive->can_add = archive->has_sfx = TRUE;
37
command = g_strconcat ( rar," vl -c- " , archive->escaped_path, NULL );
45
command = g_strconcat ( rar," v " , archive->escaped_path, NULL );
46
archive->can_extract = archive->has_test = archive->has_properties = TRUE;
38
47
archive->dummy_size = 0;
39
48
archive->nr_of_files = 0;
40
archive->nr_of_dirs = 0;
41
archive->parse_output = RarOpen;
42
archive->format ="RAR";
43
SpawnAsyncProcess ( archive , command , 0, 0);
50
archive->parse_output = xa_get_rar_line_content;
51
archive->format = "RAR";
52
xa_spawn_async_process (archive,command);
44
53
g_free ( command );
45
55
if ( archive->child_pid == 0 )
48
char *names[] = {(_("Filename")),(_("Original")),(_("Compressed")),(_("Ratio")),(_("Date")),(_("Time")),(_("Permissions")),(_("Checksum")),(_("Method")),(_("Version"))};
49
GType types[]= {G_TYPE_STRING,G_TYPE_UINT64,G_TYPE_UINT64,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING};
50
archive->has_passwd = FALSE;
51
xa_create_liststore ( 10, names , (GType *)types, archive );
58
GType types[]= {GDK_TYPE_PIXBUF,G_TYPE_STRING,G_TYPE_UINT64,G_TYPE_UINT64,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_POINTER};
59
archive->column_types = g_malloc0(sizeof(types));
60
for (i = 0; i < 12; i++)
61
archive->column_types[i] = types[i];
63
char *names[]= {(_("Original")),(_("Compressed")),(_("Ratio")),(_("Date")),(_("Time")),(_("Permissions")),(_("CRC")),(_("Method")),(_("Version")),NULL};
64
xa_create_liststore (archive,names);
54
static gboolean RarOpen (GIOChannel *ioc, GIOCondition cond, gpointer data)
67
void xa_get_rar_line_content (gchar *line, gpointer data)
56
69
XArchive *archive = data;
57
gchar **fields = NULL;
59
GIOStatus status = G_IO_STATUS_NORMAL;
61
if (cond & (G_IO_IN | G_IO_PRI) )
65
/* This to avoid inserting in the list RAR's copyright message */
66
if (jump_header == FALSE )
68
status = g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL );
71
if (strncmp (line , "--------" , 8) == 0)
79
if ( jump_header && odd_line )
81
/* Now read the filename */
82
status = g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL );
85
/* This to avoid inserting in the liststore the last line of Rar output */
86
if (strncmp (line, "--------", 8) == 0 || strncmp (line, "\x0a",1) == 0)
89
status = g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL );
93
gtk_list_store_append (archive->liststore, &iter);
94
line[ strlen(line) - 1 ] = '\000';
96
archive->has_passwd = TRUE;
97
/* This to avoid the white space or the * before the first char of the filename */
99
gtk_list_store_set (archive->liststore, &iter,0,line,-1);
100
/* Restore the pointer before freeing it */
103
odd_line = ! odd_line;
108
/* Now read the rest of the data */
109
status = g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL );
112
fields = split_line (line,9);
113
if (fields[5] == NULL)
115
if ( strstr (fields[5] , "d") == NULL && strstr (fields[5] , "D") == NULL )
116
archive->nr_of_files++;
118
archive->nr_of_dirs++;
119
for (x = 0; x < 9; x++)
121
if (x == 0 || x == 1)
122
gtk_list_store_set (archive->liststore, &iter,x+1,strtoll(fields[x],NULL,0),-1);
124
gtk_list_store_set (archive->liststore, &iter,x+1,fields[x],-1);
126
while ( gtk_events_pending() )
127
gtk_main_iteration();
128
archive->dummy_size += strtoll(fields[0],NULL,0);
129
g_strfreev ( fields );
131
odd_line = ! odd_line;
134
while (status == G_IO_STATUS_NORMAL);
136
if (status == G_IO_STATUS_ERROR || status == G_IO_STATUS_EOF)
139
else if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL) )
141
done: g_io_channel_shutdown ( ioc,TRUE,NULL );
142
g_io_channel_unref (ioc);
143
gtk_tree_view_set_model (GTK_TREE_VIEW(archive->treeview), archive->model);
144
g_object_unref (archive->model);
72
unsigned short int i = 0;
73
unsigned int linesize,n,a;
75
static gchar *filename;
80
if (jump_header == FALSE)
82
if (strncmp(line,"Comment:",8) == 0)
84
jump_comment = archive->has_comment = TRUE;
85
archive->comment = g_string_new("");
86
archive->comment = g_string_append(archive->comment,&line[9]);
89
if (jump_comment == TRUE)
91
if (strncmp(line,"Pathname/Comment",16) != 0)
92
{ archive->comment = g_string_append(archive->comment,line);
105
if (read_filename == FALSE)
107
linesize = strlen(line);
110
archive->has_passwd = TRUE;
113
else if (line[0] == '-')
118
line[linesize - 1] = '\0';
119
filename = g_strdup(line+1);
120
read_filename = TRUE;
124
linesize = strlen(line);
125
archive->nr_of_files++;
127
for(n=0; n < linesize && line[n] == ' '; n++);
129
for(; n < linesize && line[n] != ' '; n++);
132
archive->dummy_size += g_ascii_strtoull(item[i],NULL,0);
137
for(; n < linesize && line[n] == ' '; n++);
139
for(; n < linesize && line[n] != ' '; n++);
146
for(; n < linesize && line[n] == ' '; n++);
148
for(; n < linesize && line[n] != ' '; n++);
155
for(; n < linesize && line[n] == ' '; n++);
157
for(; n < linesize && line[n] != ' '; n++);
164
for(; n < linesize && line[n] == ' '; n++);
166
for(; n < linesize && line[n] != ' '; n++);
173
for(; n < linesize && line[n] == ' '; n++);
175
for(; n < linesize && line[n] != ' '; n++);
177
if ((line+a)[0] == 'd')
184
for(; n < linesize && line[n] == ' '; n++);
186
for(; n < linesize && line[n] != ' '; n++);
193
for(; n < linesize && line[n] == ' '; n++);
195
for(; n < linesize && line[n] != ' '; n++);
202
for(; n < linesize && line[n] == ' '; n++);
204
for(; n < linesize && line[n] != ' ' && line[n] != '\n'; n++);
208
/* Work around for rar which doesn't
209
* output / with directories */
212
gchar *filename_with_slash = g_strconcat (filename,"/",NULL);
214
filename = filename_with_slash;
216
entry = xa_set_archive_entries_for_each_row (archive,filename,item);
218
entry->is_encrypted = encrypted;
220
read_filename = FALSE;
225
void xa_rar_delete (XArchive *archive,GSList *names)
227
gchar *command,*e_filename = NULL;
228
GSList *list = NULL,*_names;
229
GString *files = g_string_new("");
234
e_filename = xa_escape_filename((gchar*)_names->data,"$'`\"\\!?* ()[]&|:;<>#");
235
g_string_prepend (files,e_filename);
236
g_string_prepend_c (files,' ');
237
_names = _names->next;
239
g_slist_foreach(names,(GFunc)g_free,NULL);
242
command = g_strconcat ("rar d ",archive->escaped_path," ",files->str,NULL);
243
g_string_free(files,TRUE);
244
list = g_slist_append(list,command);
246
xa_run_command (archive,list);
247
if (archive->status == XA_ARCHIVESTATUS_DELETE)
248
xa_reload_archive_content(archive);
251
void xa_rar_add (XArchive *archive,GString *files,gchar *compression_string)
254
gchar *command = NULL;
256
if (archive->location_entry_path != NULL)
257
archive->working_dir = g_strdup(archive->tmp);
259
if (compression_string == NULL)
260
compression_string = "3";
261
if (archive->passwd != NULL)
262
command = g_strconcat ( "rar a ",
263
archive->update ? "-u " : "",
264
archive->freshen ? "-f " : "",
265
archive->solid_archive ? "-s " : "",
266
archive->remove_files ? "-df " : "",
267
"-p" , archive->passwd,
269
"-m",compression_string," ",
270
archive->escaped_path,
273
command = g_strconcat ( "rar a ",
274
archive->update ? "-u " : "",
275
archive->freshen ? "-f " : "",
276
archive->solid_archive ? "-s " : "",
277
archive->remove_files ? "-df " : "",
279
"-m",compression_string," ",
280
archive->escaped_path,
283
g_string_free(files,TRUE);
284
list = g_slist_append(list,command);
286
xa_run_command (archive,list);
287
xa_reload_archive_content(archive);
290
gboolean xa_rar_extract(XArchive *archive,GSList *files)
292
gchar *rar, *command, *e_filename = NULL;
293
GSList *list = NULL,*_files = NULL;
294
GString *names = g_string_new("");
295
gboolean result = FALSE;
305
e_filename = xa_escape_filename((gchar*)_files->data,"$'`\"\\!?* ()[]&|:;<>#");
306
g_string_prepend (names,e_filename);
307
g_string_prepend_c (names,' ');
308
_files = _files->next;
310
g_slist_foreach(_files,(GFunc)g_free,NULL);
311
g_slist_free(_files);
313
if (archive->passwd != NULL)
314
command = g_strconcat (rar," ",archive->full_path ? "x " : "e ",
315
archive->freshen ? "-f " : "" , archive->update ? "-u " : "",
316
" -p",archive->passwd,
317
archive->overwrite ? " -o+" : " -o-",
319
archive->escaped_path,names->str," ",archive->extraction_path , NULL );
321
command = g_strconcat (rar," ",archive->full_path ? "x " : "e ",
322
archive->freshen ? "-f " : "" , archive->update ? "-u " : "",
323
archive->overwrite ? "-o+" : "-o-",
325
archive->escaped_path,names->str," ",archive->extraction_path , NULL );
326
g_string_free(names,TRUE);
327
list = g_slist_append(list,command);
329
result = xa_run_command (archive,list);
333
void xa_rar_test (XArchive *archive)
336
gchar *command = NULL;
344
archive->status = XA_ARCHIVESTATUS_TEST;
345
if (archive->passwd != NULL)
346
command = g_strconcat (rar," t -idp -p" , archive->passwd ," " , archive->escaped_path, NULL);
348
command = g_strconcat (rar," t -idp " , archive->escaped_path, NULL);
350
list = g_slist_append(list,command);
351
xa_run_command (archive,list);