diff options
author | Stefano Karapetsas <[email protected]> | 2014-01-15 00:38:40 -0800 |
---|---|---|
committer | Stefano Karapetsas <[email protected]> | 2014-01-15 00:38:40 -0800 |
commit | dbbb0a62cbd8156ece72fde93fd051318df13932 (patch) | |
tree | 286ed098271517f42ec6bd79724b14007ce9ac59 | |
parent | 325e6e485a88efeee316f633ae3dfeed1be45ceb (diff) | |
parent | 45deb61cce3acdf82b466a83013bbd72b30c1df9 (diff) | |
download | engrampa-dbbb0a62cbd8156ece72fde93fd051318df13932.tar.bz2 engrampa-dbbb0a62cbd8156ece72fde93fd051318df13932.tar.xz |
Merge pull request #38 from infirit/1.6
Cherrypick dome more usefull commits from master
-rw-r--r-- | help/C/engrampa.xml | 8 | ||||
-rw-r--r-- | src/dlg-package-installer.c | 51 | ||||
-rw-r--r-- | src/fr-command-rar.c | 168 | ||||
-rw-r--r-- | src/fr-command-rar.h | 3 | ||||
-rw-r--r-- | src/fr-command-zip.c | 8 |
5 files changed, 172 insertions, 66 deletions
diff --git a/help/C/engrampa.xml b/help/C/engrampa.xml index 66dc804..ce55e63 100644 --- a/help/C/engrampa.xml +++ b/help/C/engrampa.xml @@ -142,7 +142,7 @@ <revnumber>Engrampa Manual V2.5</revnumber> <date>March 2004</date> <revdescription> - <para role="author">Sun MATE Documentation Team</para> + <para role="author">Sun GNOME Documentation Team</para> <para role="publisher">MATE Documentation Project</para> </revdescription> </revision> @@ -150,7 +150,7 @@ <revnumber>Engrampa Manual V2.4</revnumber> <date>February 2004</date> <revdescription> - <para role="author">Sun MATE Documentation Team</para> + <para role="author">Sun GNOME Documentation Team</para> <para role="publisher">MATE Documentation Project</para> </revdescription> </revision> @@ -158,7 +158,7 @@ <revnumber>Engrampa Manual V2.3</revnumber> <date>August 2003</date> <revdescription> - <para role="author">Sun MATE Documentation Team</para> + <para role="author">Sun GNOME Documentation Team</para> <para role="publisher">MATE Documentation Project</para> </revdescription> </revision> @@ -166,7 +166,7 @@ <revnumber>Engrampa Manual V2.2</revnumber> <date>June 2003</date> <revdescription> - <para role="author">Sun MATE Documentation Team</para> + <para role="author">Sun GNOME Documentation Team</para> <para role="publisher">MATE Documentation Project</para> </revdescription> </revision> diff --git a/src/dlg-package-installer.c b/src/dlg-package-installer.c index 451a2ca..466aa5f 100644 --- a/src/dlg-package-installer.c +++ b/src/dlg-package-installer.c @@ -48,8 +48,9 @@ installer_data_free (InstallerData *idata) static void -package_installer_terminated (InstallerData *idata, - const char *error) +package_installer_terminated (InstallerData *idata, + FrProcErrorType error_type, + const char *error_message) { GdkWindow *window; @@ -57,11 +58,11 @@ package_installer_terminated (InstallerData *idata, if (window != NULL) gdk_window_set_cursor (window, NULL); - if (error != NULL) { + if (error_type != FR_PROC_ERROR_NONE) { fr_archive_action_completed (idata->archive, FR_ACTION_CREATING_NEW_ARCHIVE, - FR_PROC_ERROR_GENERIC, - error); + error_type, + error_message); } else { update_registered_commands_capabilities (); @@ -83,24 +84,36 @@ packagekit_install_package_names_ready_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { - InstallerData *idata = user_data; - GDBusProxy *proxy; - GVariant *values; - GError *error = NULL; - char *message = NULL; + InstallerData *idata = user_data; + GDBusProxy *proxy; + GVariant *values; + GError *error = NULL; + FrProcErrorType error_type = FR_PROC_ERROR_NONE; + char *error_message = NULL; proxy = G_DBUS_PROXY (source_object); values = g_dbus_proxy_call_finish (proxy, res, &error); if (values == NULL) { - message = g_strdup_printf ("%s\n%s", - _("There was an internal error trying to search for applications:"), - error->message); + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) + || (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR) + && (error->message != NULL) + && (strstr (error->message, "org.freedesktop.Packagekit.Modify.Cancelled") != NULL))) + { + error_type = FR_PROC_ERROR_STOPPED; + error_message = NULL; + } + else { + error_type = FR_PROC_ERROR_GENERIC; + error_message = g_strdup_printf ("%s\n%s", + _("There was an internal error trying to search for applications:"), + error->message); + } g_clear_error (&error); } - package_installer_terminated (idata, message); + package_installer_terminated (idata, error_type, error_message); - g_free (message); + g_free (error_message); if (values != NULL) g_variant_unref (values); g_object_unref (proxy); @@ -204,7 +217,7 @@ install_packages (InstallerData *idata) message = g_strdup_printf ("%s\n%s", _("There was an internal error trying to search for applications:"), error->message); - package_installer_terminated (idata, message); + package_installer_terminated (idata, FR_PROC_ERROR_GENERIC, message); g_clear_error (&error); } @@ -251,7 +264,7 @@ dlg_package_installer (FrWindow *window, if (command_type == 0) command_type = get_preferred_command_for_mime_type (idata->archive->content_type, FR_COMMAND_CAN_READ); if (command_type == 0) { - package_installer_terminated (idata, _("Archive type not supported.")); + package_installer_terminated (idata, FR_PROC_ERROR_GENERIC, _("Archive type not supported.")); return; } @@ -260,7 +273,7 @@ dlg_package_installer (FrWindow *window, g_object_unref (command); if (idata->packages == NULL) { - package_installer_terminated (idata, _("Archive type not supported.")); + package_installer_terminated (idata, FR_PROC_ERROR_GENERIC, _("Archive type not supported.")); return; } @@ -288,7 +301,7 @@ dlg_package_installer (FrWindow *window, #else /* ! ENABLE_PACKAGEKIT */ - package_installer_terminated (idata, _("Archive type not supported.")); + package_installer_terminated (idata, FR_PROC_ERROR_GENERIC, _("Archive type not supported.")); #endif /* ENABLE_PACKAGEKIT */ } diff --git a/src/fr-command-rar.c b/src/fr-command-rar.c index 6ef0859..631d58a 100644 --- a/src/fr-command-rar.c +++ b/src/fr-command-rar.c @@ -56,8 +56,8 @@ have_rar (void) static time_t -mktime_from_string (char *date_s, - char *time_s) +mktime_from_string (const char *date_s, + const char *time_s) { struct tm tm = {0, }; char **fields; @@ -90,6 +90,84 @@ mktime_from_string (char *date_s, return mktime (&tm); } +/* Sample rar-5 listing output: + +RAR 5.00 beta 8 Copyright (c) 1993-2013 Alexander Roshal 22 Aug 2013 +Trial version Type RAR -? for help + +Archive: test.rar +Details: RAR 4 + + Attributes Size Packed Ratio Date Time Checksum Name +----------- --------- -------- ----- -------- ----- -------- ---- + -rw-r--r-- 453 304 67% 05-09-13 09:55 56DA5EF3 loremipsum.txt +----------- --------- -------- ----- -------- ----- -------- ---- + 453 304 67% 1 + + * + * Sample rar-4 listing output: + * + +RAR 4.20 Copyright (c) 1993-2012 Alexander Roshal 9 Jun 2012 +Trial version Type RAR -? for help + +Archive test.rar + +Pathname/Comment + Size Packed Ratio Date Time Attr CRC Meth Ver +------------------------------------------------------------------------------- + loremipsum.txt + 453 304 67% 05-09-13 09:55 -rw-r--r-- 56DA5EF3 m3b 2.9 +------------------------------------------------------------------------------- + 1 453 304 67% + + */ + +static void +parse_name_field (char *line, + FrCommandRar *rar_comm) +{ + char *name_field; + FileData *fdata; + + rar_comm->fdata = fdata = file_data_new (); + + /* read file name. */ + + fdata->encrypted = (line[0] == '*') ? TRUE : FALSE; + + if (rar_comm->rar5) + /* rar-5 output adds trailing spaces to short file names :( */ + name_field = g_strchomp (g_strdup (get_last_field (line, 8))); + else + name_field = g_strdup (line + 1); + + if (*name_field == '/') { + fdata->full_path = g_strdup (name_field); + fdata->original_path = fdata->full_path; + } + else { + fdata->full_path = g_strconcat ("/", name_field, NULL); + fdata->original_path = fdata->full_path + 1; + } + + fdata->link = NULL; + fdata->path = remove_level_from_path (fdata->full_path); + + g_free (name_field); +} + +static gboolean +attr_field_is_dir (const char *attr_field, + FrCommandRar *rar_comm) +{ + if ((attr_field[0] == 'd') || + (rar_comm->rar5 && attr_field[3] == 'D') || + (!rar_comm->rar5 && attr_field[1] == 'D')) + return TRUE; + + return FALSE; +} static void process_line (char *line, @@ -98,14 +176,24 @@ process_line (char *line, FrCommand *comm = FR_COMMAND (data); FrCommandRar *rar_comm = FR_COMMAND_RAR (comm); char **fields; - const char *name_field; g_return_if_fail (line != NULL); if (! rar_comm->list_started) { - if (strncmp (line, "--------", 8) == 0) { + if (strncmp (line, "RAR ", 4) == 0) { + int version; + sscanf (line, "RAR %d.", &version); + rar_comm->rar5 = (version >= 5); + } + else if (strncmp (line, "UNRAR ", 6) == 0) { + int version; + sscanf (line, "UNRAR %d.", &version); + rar_comm->rar5 = (version >= 5); + } + else if (strncmp (line, "--------", 8) == 0) { rar_comm->list_started = TRUE; - rar_comm->odd_line = TRUE; + if (! rar_comm->rar5) + rar_comm->rar4_odd_line = TRUE; } else if (strncmp (line, "Volume ", 7) == 0) comm->multi_volume = TRUE; @@ -117,24 +205,43 @@ process_line (char *line, return; } - if (! rar_comm->odd_line) { - FileData *fdata; + if (rar_comm->rar4_odd_line || rar_comm->rar5) + parse_name_field (line, rar_comm); + + if (! rar_comm->rar4_odd_line) { + FileData *fdata; + const char *size_field, *ratio_field, *date_field, *time_field, *attr_field; fdata = rar_comm->fdata; /* read file info. */ fields = split_line (line, 6); + if (rar_comm->rar5) { + size_field = fields[1]; + ratio_field = fields[3]; + date_field = fields[4]; + time_field = fields[5]; + attr_field = fields[0]; + } + else { + size_field = fields[0]; + ratio_field = fields[2]; + date_field = fields[3]; + time_field = fields[4]; + attr_field = fields[5]; + } if (g_strv_length (fields) < 6) { /* wrong line format, treat this line as a filename line */ g_strfreev (fields); file_data_free (rar_comm->fdata); rar_comm->fdata = NULL; - rar_comm->odd_line = TRUE; + rar_comm->rar4_odd_line = TRUE; + parse_name_field (line, rar_comm); } else { - if ((strcmp (fields[2], "<->") == 0) - || (strcmp (fields[2], "<--") == 0)) + if ((strcmp (ratio_field, "<->") == 0) + || (strcmp (ratio_field, "<--") == 0)) { /* ignore files that span more volumes */ @@ -142,10 +249,10 @@ process_line (char *line, rar_comm->fdata = NULL; } else { - fdata->size = g_ascii_strtoull (fields[0], NULL, 10); - fdata->modified = mktime_from_string (fields[3], fields[4]); + fdata->size = g_ascii_strtoull (size_field, NULL, 10); + fdata->modified = mktime_from_string (date_field, time_field); - if ((fields[5][1] == 'D') || (fields[5][0] == 'd')) { + if (attr_field_is_dir (attr_field, rar_comm)) { char *tmp; tmp = fdata->full_path; @@ -159,8 +266,11 @@ process_line (char *line, fdata->name = dir_name_from_path (fdata->full_path); fdata->dir = TRUE; } - else + else { fdata->name = g_strdup (file_name_from_path (fdata->full_path)); + if (attr_field[0] == 'l') + fdata->link = g_strdup (file_name_from_path (fdata->full_path)); + } fr_command_add_file (comm, fdata); rar_comm->fdata = NULL; @@ -170,34 +280,8 @@ process_line (char *line, } } - if (rar_comm->odd_line) { - FileData *fdata; - - rar_comm->fdata = fdata = file_data_new (); - - /* read file name. */ - - fdata->encrypted = (line[0] == '*') ? TRUE : FALSE; - - name_field = line + 1; - - if (*name_field == '/') { - fdata->full_path = g_strdup (name_field); - fdata->original_path = fdata->full_path; - } - else { - fdata->full_path = g_strconcat ("/", name_field, NULL); - fdata->original_path = fdata->full_path + 1; - } - - fdata->link = NULL; - fdata->path = remove_level_from_path (fdata->full_path); - } - else { - - } - - rar_comm->odd_line = ! rar_comm->odd_line; + if (! rar_comm->rar5) + rar_comm->rar4_odd_line = ! rar_comm->rar4_odd_line; } diff --git a/src/fr-command-rar.h b/src/fr-command-rar.h index e2a5e12..c86fec5 100644 --- a/src/fr-command-rar.h +++ b/src/fr-command-rar.h @@ -43,7 +43,8 @@ struct _FrCommandRar FrCommand __parent; gboolean list_started; - gboolean odd_line; + gboolean rar4_odd_line; + gboolean rar5; FileData *fdata; }; diff --git a/src/fr-command-zip.c b/src/fr-command-zip.c index 8c51bef..2aa332e 100644 --- a/src/fr-command-zip.c +++ b/src/fr-command-zip.c @@ -190,6 +190,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, "--"); fr_process_add_arg (comm->process, comm->filename); fr_process_end_command (comm->process); fr_process_start (comm->process); @@ -253,6 +254,8 @@ fr_command_zip_add (FrCommand *comm, } fr_process_add_arg (comm->process, comm->filename); + fr_process_add_arg (comm->process, "--"); + for (scan = file_list; scan; scan = scan->next) fr_process_add_arg (comm->process, scan->data); @@ -275,6 +278,8 @@ fr_command_zip_delete (FrCommand *comm, fr_process_add_arg (comm->process, "-d"); fr_process_add_arg (comm->process, comm->filename); + fr_process_add_arg (comm->process, "--"); + for (scan = file_list; scan; scan = scan->next) { char *escaped; @@ -319,6 +324,8 @@ fr_command_zip_extract (FrCommand *comm, add_password_arg (comm, comm->password); fr_process_add_arg (comm->process, comm->filename); + fr_process_add_arg (comm->process, "--"); + for (scan = file_list; scan; scan = scan->next) { char *escaped; @@ -337,6 +344,7 @@ fr_command_zip_test (FrCommand *comm) fr_process_begin_command (comm->process, "unzip"); fr_process_add_arg (comm->process, "-t"); add_password_arg (comm, comm->password); + fr_process_add_arg (comm->process, "--"); fr_process_add_arg (comm->process, comm->filename); fr_process_end_command (comm->process); } |