20
20
#include "config.h"
23
static gboolean LhaOpen (GIOChannel *ioc, GIOCondition cond, gpointer data);
24
void OpenLha ( XArchive *archive )
24
extern void xa_reload_archive_content(XArchive *archive);
25
extern void xa_create_liststore ( XArchive *archive, gchar *columns_names[]);
27
void xa_open_lha (XArchive *archive)
30
jump_header = last_line = FALSE;
28
32
command = g_strconcat ("lha l " , archive->escaped_path, NULL);
33
archive->has_properties = archive->can_extract = archive->can_add = archive->has_test = TRUE;
34
archive->has_sfx = FALSE;
29
35
archive->dummy_size = 0;
30
36
archive->nr_of_files = 0;
31
archive->nr_of_dirs = 0;
32
37
archive->format ="LHA";
33
archive->parse_output = LhaOpen;
34
SpawnAsyncProcess ( archive , command , 0, 0);
39
archive->parse_output = xa_get_lha_line_content;
40
xa_spawn_async_process (archive,command);
37
43
if (archive->child_pid == 0)
40
char *names[]= {(_("Filename")),(_("Permissions")),(_("UID/GID")),(_("Size")),(_("Ratio")),(_("Timestamp"))};
41
GType types[]= {G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_UINT64,G_TYPE_STRING,G_TYPE_STRING};
42
xa_create_liststore(6, names, (GType *)types, archive);
46
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_POINTER};
47
archive->column_types = g_malloc0(sizeof(types));
48
for (i = 0; i < 8; i++)
49
archive->column_types[i] = types[i];
51
char *names[]= {(_("Points to")),(_("Permissions")),(_("UID/GID")),(_("Size")),(_("Ratio")),(_("Timestamp"))};
52
xa_create_liststore (archive,names);
45
static gboolean LhaOpen (GIOChannel *ioc, GIOCondition cond, gpointer data)
55
void xa_get_lha_line_content (gchar *line, gpointer data)
47
57
XArchive *archive = data;
49
gchar *permissions = NULL;
52
gchar *timestamp = NULL;
55
gchar *filename = NULL;
56
GIOStatus status = G_IO_STATUS_NORMAL;
57
unsigned short int a = 0, n = 0, num;
60
unsigned int linesize,n,a;
59
if (cond & (G_IO_IN | G_IO_PRI) )
66
if (jump_header == FALSE)
61
// We don't need the first two lines. No actual data there.
62
g_io_channel_read_line(ioc, &line, NULL, NULL, NULL);
66
g_io_channel_read_line(ioc, &line, NULL, NULL, NULL);
71
status = g_io_channel_read_line(ioc, &line, NULL, NULL, NULL);
72
if (line == NULL || (strncmp(line, "---------- -", 12) == 0))
74
gtk_list_store_append (archive->liststore, &iter);
76
permissions = g_strndup(line, 10);
77
gtk_list_store_set (archive->liststore, &iter,1,permissions,-1);
78
if (strstr(permissions, "d") == NULL)
79
archive->nr_of_files++;
81
archive->nr_of_dirs++;
84
owner = g_strndup(&line[11], 11);
85
gtk_list_store_set (archive->liststore, &iter,2,owner,-1);
89
for(n = 23;n < num;n++)
98
size = g_strndup(&line[a], n - a);
99
gtk_list_store_set (archive->liststore, &iter,3,strtoll(size,NULL,0),-1);
100
archive->dummy_size += strtoll(size,NULL,0);
103
ratio = g_strndup(&line[31], 7);
104
gtk_list_store_set (archive->liststore, &iter,4,ratio,-1);
107
timestamp = g_strndup(&line[38], 13);
108
gtk_list_store_set (archive->liststore, &iter,5,timestamp,-1);
111
filename = g_strndup(&line[51], num - 51 - 1);
112
gtk_list_store_set (archive->liststore, &iter,0,filename,-1);
117
while (status == G_IO_STATUS_NORMAL);
119
if (status == G_IO_STATUS_ERROR || status == G_IO_STATUS_EOF)
122
else if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL) )
125
g_io_channel_shutdown(ioc, TRUE, NULL);
126
g_io_channel_unref(ioc);
127
gtk_tree_view_set_model (GTK_TREE_VIEW(archive->treeview), archive->model);
128
g_object_unref (archive->model);
75
if (strncmp(line,"----",4) == 0)
80
linesize = strlen(line);
81
archive->nr_of_files++;
93
//TODO verify the len of the size column with a big archive
95
for(n = 23;n < linesize;n++)
100
for(;n < linesize;n++)
104
line[a+(n-a)] = '\0';
106
archive->dummy_size += g_ascii_strtoull(item[3],NULL,0);
116
line[(linesize- 1)] = '\0';
117
filename = line + 51;
120
gchar *temp = g_strrstr (filename,"->");
123
gint len = strlen(filename) - strlen(temp);
124
item[0] = (filename +=3) + len;
126
filename[strlen(filename) - strlen(temp)-1] = '\0';
131
entry = xa_set_archive_entries_for_each_row (archive,filename,item);
134
gboolean isLha ( FILE *ptr )
136
unsigned char magic[2];
137
fseek(ptr, 0, SEEK_SET);
138
if(fseek(ptr, 19, SEEK_CUR) < 0)
140
if(fread(magic, 1, 2, ptr) == 0)
143
if(magic[0] == 0x20 && magic[1] <= 0x03)
149
void xa_lha_delete (XArchive *archive,GSList *names)
151
gchar *command,*e_filename = NULL;
152
GSList *list = NULL,*_names;
153
GString *files = g_string_new("");
158
e_filename = xa_escape_filename((gchar*)_names->data,"$'`\"\\!?* ()[]&|:;<>#");
159
g_string_prepend (files,e_filename);
160
g_string_prepend_c (files,' ');
161
_names = _names->next;
163
g_slist_foreach(names,(GFunc)g_free,NULL);
166
command = g_strconcat ("lha d " , archive->escaped_path," ",files->str,NULL);
167
g_string_free(files,TRUE);
168
list = g_slist_append(list,command);
170
xa_run_command (archive,list);
171
if (archive->status == XA_ARCHIVESTATUS_DELETE)
172
xa_reload_archive_content(archive);
175
void xa_lha_add (XArchive *archive,GString *files,gchar *compression_string)
178
gchar *command = NULL;
180
if (archive->location_entry_path != NULL)
181
archive->working_dir = g_strdup(archive->tmp);
183
if (compression_string == NULL)
184
compression_string = "5";
185
command = g_strconcat( "lha ",
186
archive->remove_files ? "m" : "a",
187
archive->update ? "u" : "",
188
"o",compression_string,
190
archive->escaped_path,
192
g_string_free(files,TRUE);
193
list = g_slist_append(list,command);
195
xa_run_command (archive,list);
196
xa_reload_archive_content(archive);
199
gboolean xa_lha_extract(XArchive *archive,GSList *files)
201
gchar *command,*e_filename = NULL;
202
GSList *list = NULL,*_files = NULL;
203
GString *names = g_string_new("");
204
gboolean result = FALSE;
209
e_filename = xa_escape_filename((gchar*)_files->data,"$'`\"\\!?* ()[]&|:;<>#");
210
g_string_prepend (names,e_filename);
211
g_string_prepend_c (names,' ');
212
_files = _files->next;
214
g_slist_foreach(_files,(GFunc)g_free,NULL);
215
g_slist_free(_files);
217
command = g_strconcat ("lha ", archive->full_path ? "x" : "xi",
218
archive->overwrite ? "f" : "", "w=",
219
archive->extraction_path," ",archive->escaped_path,names->str,NULL);
220
g_string_free(names,TRUE);
221
list = g_slist_append(list,command);
223
result = xa_run_command (archive,list);
227
void xa_lha_test (XArchive *archive)
229
gchar *command = NULL;
232
archive->status = XA_ARCHIVESTATUS_TEST;
233
command = g_strconcat ("lha t ",archive->escaped_path,NULL);
235
list = g_slist_append(list,command);
236
xa_run_command (archive,list);