~ubuntu-branches/ubuntu/feisty/xarchiver/feisty

« back to all changes in this revision

Viewing changes to src/rar.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2006-03-12 09:45:00 UTC
  • Revision ID: james.westby@ubuntu.com-20060312094500-e1m5oxiyro0xfj3a
Tags: upstream-0.3.1
ImportĀ upstreamĀ versionĀ 0.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Xarchiver
 
3
 *
 
4
 *  Copyright (C) 2005 Giuseppe Torelli - Colossus
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
19
 */
 
20
 
 
21
#include "rar.h"
 
22
 
 
23
extern int output_fd,error_fd,child_pid,child_status;
 
24
 
 
25
void OpenRar ( gboolean mode , gchar *path)
 
26
{
 
27
        jump_header = FALSE;
 
28
    gchar *command = g_strconcat ( "rar vl -c- " , path, NULL );
 
29
        compressor_pid = SpawnAsyncProcess ( command , 1 , 0 );
 
30
    g_free ( command );
 
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 );
 
39
}
 
40
 
 
41
static gboolean RarOpen (GIOChannel *ioc, GIOCondition cond, gpointer data)
 
42
{
 
43
        gchar **fields = NULL;
 
44
        gchar *filename = NULL;
 
45
    gchar *line = NULL;
 
46
 
 
47
        if (cond & (G_IO_IN | G_IO_PRI) )
 
48
        {
 
49
        //This to avoid inserting in the list RAR's copyright message
 
50
                if (jump_header == FALSE )
 
51
        {
 
52
                        for ( x = 0; x <= 8; x++)
 
53
                        {
 
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)
 
57
                            {
 
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);
 
61
                    g_free (line);
 
62
                    return FALSE;
 
63
                            }
 
64
                g_free (line);
 
65
                        }
 
66
                        jump_header = TRUE;
 
67
        }
 
68
        else // ( jump_header )
 
69
                {
 
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)
 
76
                        {
 
77
                g_free (line);
 
78
                                g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL );
 
79
                if ( line != NULL && data )
 
80
                {
 
81
                    gtk_text_buffer_insert (textbuf, &enditer, line, strlen( line ) );
 
82
                    g_free (line);
 
83
                }
 
84
                return TRUE;
 
85
                        }
 
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
 
90
            line++;
 
91
                        gtk_list_store_set (liststore, &iter,0,line,-1);
 
92
            //Restore the pointer before freeing it
 
93
            line--;
 
94
            g_free (line);            
 
95
                        //Now read the rest
 
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++)
 
101
            {
 
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);
 
104
            }
 
105
            gtk_progress_bar_pulse ( GTK_PROGRESS_BAR (progressbar) );
 
106
            while (gtk_events_pending() )
 
107
                            gtk_main_iteration();
 
108
                        g_strfreev ( fields );
 
109
                        g_free (line);
 
110
                        return TRUE;
 
111
                }
 
112
                return TRUE;
 
113
        }
 
114
        else if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL) )
 
115
        {
 
116
                g_io_channel_shutdown ( ioc,TRUE,NULL );
 
117
                g_io_channel_unref (ioc);
 
118
        return FALSE;
 
119
        }
 
120
}
 
121