4
* Copyright (C) 2005 Giuseppe Torelli - Colossus
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
23
extern int output_fd,error_fd,child_pid,child_status;
25
void OpenRar ( gboolean mode , gchar *path)
28
gchar *command = g_strconcat ( "rar vl -c- " , path, NULL );
29
compressor_pid = SpawnAsyncProcess ( command , 1 , 0 );
31
if ( compressor_pid == 0 ) return;
32
char *names[] = {("Filename"),("Original"),("Compressed"),("Ratio"),("Date"),("Time"),("Permissions"),("CRC"),("Method"),("Version")};
33
GType types[]= {G_TYPE_STRING,G_TYPE_UINT,G_TYPE_UINT,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING};
34
PasswordProtectedArchive = FALSE;
35
CreateListStore ( 10, names , (GType *)types );
36
SetIOChannel (output_fd, G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP|G_IO_NVAL,RarOpen, (gpointer) mode );
37
SetIOChannel (error_fd, G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP|G_IO_NVAL,GenError, NULL );
38
WaitExitStatus ( child_pid , NULL );
41
static gboolean RarOpen (GIOChannel *ioc, GIOCondition cond, gpointer data)
43
gchar **fields = NULL;
44
gchar *filename = NULL;
47
if (cond & (G_IO_IN | G_IO_PRI) )
49
//This to avoid inserting in the list RAR's copyright message
50
if (jump_header == FALSE )
52
for ( x = 0; x <= 8; x++)
54
g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL );
55
if (line != NULL && data ) gtk_text_buffer_insert(textbuf, &enditer, line, strlen ( line ) );
56
if (line !=NULL && strncmp (line , " 0 files" , 9) == 0)
58
response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_INFO, GTK_BUTTONS_OK,"This archive doesn't contain any files !" );
59
g_io_channel_shutdown ( ioc,TRUE,NULL );
60
g_io_channel_unref (ioc);
68
else // ( jump_header )
70
//Now read the filename
71
g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL );
72
if ( line == NULL) return TRUE;
73
if ( data ) gtk_text_buffer_insert(textbuf, &enditer, line, strlen( line ) );
74
//This to avoid inserting in the liststore the last line of Rar output
75
if (strncmp (line, "--------", 8) == 0 || strncmp (line, "\x0a",1) == 0)
78
g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL );
79
if ( line != NULL && data )
81
gtk_text_buffer_insert (textbuf, &enditer, line, strlen( line ) );
86
gtk_list_store_append (liststore, &iter);
87
line[ strlen(line) - 1 ] = '\000';
88
if (line[0] == '*') PasswordProtectedArchive = TRUE;
89
//This to avoid the white space or the * before the first char of the filename
91
gtk_list_store_set (liststore, &iter,0,line,-1);
92
//Restore the pointer before freeing it
96
g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL );
97
if ( line == NULL) return TRUE;
98
if (line != NULL && data ) gtk_text_buffer_insert ( textbuf, &enditer, line, strlen( line ) );
99
fields = split_line (line,9);
100
for ( x = 0; x < 9; x++)
102
if (x == 0 | x == 1) gtk_list_store_set (liststore, &iter,x+1,atoi(fields[x]),-1);
103
else gtk_list_store_set (liststore, &iter,x+1,fields[x],-1);
105
gtk_progress_bar_pulse ( GTK_PROGRESS_BAR (progressbar) );
106
while (gtk_events_pending() )
107
gtk_main_iteration();
108
g_strfreev ( fields );
114
else if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL) )
116
g_io_channel_shutdown ( ioc,TRUE,NULL );
117
g_io_channel_unref (ioc);