Skip to content

Instantly share code, notes, and snippets.

@mahiuchun
Created November 12, 2012 07:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahiuchun/4057999 to your computer and use it in GitHub Desktop.
Save mahiuchun/4057999 to your computer and use it in GitHub Desktop.
Support Unicode Enabled ZIP Archives in File Roller
diff --git a/src/fr-command-zip.c b/src/fr-command-zip.c
index 32baf78..953a560 100644
--- a/src/fr-command-zip.c
+++ b/src/fr-command-zip.c
@@ -20,6 +20,7 @@
*/
#include <config.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
@@ -83,6 +84,63 @@ mktime_from_string (char *datetime_s)
return mktime (&tm);
}
+static char *
+convert_escaped_unicode (const char *name_field)
+{
+ GString *string;
+ char buf[7];
+ char c;
+ gint i;
+ gunichar wc;
+
+ g_return_val_if_fail (name_field != NULL, NULL);
+
+ string = g_string_new ("");
+ for (i = 0; i < strlen (name_field); i++) {
+ c = name_field[i];
+ if (c != '#') {
+ g_string_append_c (string, c);
+ } else {
+ c = name_field[++i];
+ if (c == 'U') {
+ strcpy (buf, "");
+ sscanf (name_field+i,
+ "U%4[0-9a-f]",
+ buf);
+ if (strlen(buf) == 4) {
+ sscanf (buf,
+ "%04X",
+ &wc);
+ g_string_append_unichar (string, wc);
+ i += 4;
+ } else {
+ g_string_append_c (string, '#');
+ g_string_append_c (string, c);
+ }
+ } else if (c == 'L') {
+ strcpy (buf, "");
+ sscanf (name_field+i,
+ "L%6[0-9a-f]",
+ buf);
+ if (strlen(buf) == 6) {
+ sscanf (buf,
+ "%06X",
+ &wc);
+ g_string_append_unichar (string, wc);
+ i += 6;
+ } else {
+ g_string_append_c (string, '#');
+ g_string_append_c (string, c);
+ }
+ } else {
+ g_string_append_c (string, '#');
+ g_string_append_c (string, c);
+ }
+ }
+ }
+
+ return g_string_free (string, FALSE);
+}
static void
list__process_line (char *line,
@@ -91,6 +149,7 @@ list__process_line (char *line,
FileData *fdata;
FrCommand *comm = FR_COMMAND (data);
char **fields;
+ char *name;
const char *name_field;
gint line_l;
@@ -129,15 +188,18 @@ list__process_line (char *line,
/* Full path */
name_field = _g_str_get_last_field (line, 8);
+ name = convert_escaped_unicode (name_field);
- if (*name_field == '/') {
- fdata->full_path = g_strdup (name_field);
+ if (*name == '/') {
+ fdata->full_path = g_strdup (name);
fdata->original_path = fdata->full_path;
} else {
- fdata->full_path = g_strconcat ("/", name_field, NULL);
+ fdata->full_path = g_strconcat ("/", name, NULL);
fdata->original_path = fdata->full_path + 1;
}
+ g_free(name);
+
fdata->link = NULL;
fdata->dir = line[0] == 'd';
@@ -181,7 +243,7 @@ fr_command_zip_list (FrCommand *comm)
fr_process_begin_command (comm->process, "unzip");
fr_process_set_begin_func (comm->process, list__begin, comm);
- fr_process_add_arg (comm->process, "-ZTs");
+ fr_process_add_arg (comm->process, "-ZUTs");
fr_process_add_arg (comm->process, "--");
fr_process_add_arg (comm->process, comm->filename);
fr_process_end_command (comm->process);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment