From 4362e63dd54d8d35603d81fd2468cfe710b88f3e Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Wed, 19 Apr 2017 14:43:11 -0700 Subject: Have a common "capture file close alert box" routine. Take the code from cf_read() to pop up an alert box and put it into libui, with the name cfile_read_failure_alert_box(). Use it in a couple of places where we pop up such an error dialog. While we're at it, get rid of the "err" argument to rescan_file(); nobody uses what it returns. Change-Id: Iba7099b95de24309359d94eb96f606020e2ff2c3 Reviewed-on: https://code.wireshark.org/review/21232 Reviewed-by: Guy Harris --- ui/alert_box.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- ui/alert_box.h | 9 +++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/alert_box.c b/ui/alert_box.c index 26d2b49d8c..bdf71e20fa 100644 --- a/ui/alert_box.c +++ b/ui/alert_box.c @@ -25,7 +25,6 @@ #include - #include #include @@ -208,6 +207,69 @@ cfile_open_failure_alert_box(const char *filename, int err, gchar *err_info, } } +/* + * Alert box for a failed attempt to read from a capture file. + * "err" is assumed to be a UNIX-style errno or a WTAP_ERR_ value; + * "err_info" is assumed to be a string giving further information for + * some WTAP_ERR_ values. + */ +void +cfile_read_failure_alert_box(const char *filename, int err, gchar *err_info) +{ + gchar *display_name; + + if (filename == NULL) + display_name = g_strdup("capture file"); + else { + gchar *display_basename; + + display_basename = g_filename_display_basename(filename); + display_name = g_strdup_printf("capture file %s", display_basename); + g_free(display_basename); + } + + switch (err) { + + case WTAP_ERR_UNSUPPORTED: + simple_error_message_box( + "The %s contains record data that Wireshark doesn't support.\n(%s)", + display_name, + err_info != NULL ? err_info : "no information supplied"); + g_free(err_info); + break; + + case WTAP_ERR_SHORT_READ: + simple_error_message_box( + "The %s appears to have been cut short in the middle of a packet.", + display_name); + break; + + case WTAP_ERR_BAD_FILE: + simple_error_message_box( + "The %s appears to be damaged or corrupt.\n(%s)", + display_name, + err_info != NULL ? err_info : "no information supplied"); + g_free(err_info); + break; + + case WTAP_ERR_DECOMPRESS: + simple_error_message_box( + "The compressed %s appears to be damaged or corrupt.\n(%s)", + display_name, + err_info != NULL ? err_info : "no information supplied"); + g_free(err_info); + break; + + default: + simple_error_message_box( + "An error occurred while reading the %s: %s.", + display_name, + wtap_strerror(err)); + break; + } + g_free(display_name); +} + /* * Alert box for a failed attempt to close a capture file. * "err" is assumed to be a UNIX-style errno or a WTAP_ERR_ value. diff --git a/ui/alert_box.h b/ui/alert_box.h index bd19963279..1660749dc7 100644 --- a/ui/alert_box.h +++ b/ui/alert_box.h @@ -52,6 +52,15 @@ extern void cfile_open_failure_alert_box(const char *filename, int err, gchar *err_info, gboolean for_writing, int file_type); +/* + * Alert box for a failed attempt to read from a capture file. + * "err" is assumed to be a UNIX-style errno or a WTAP_ERR_ value; + * "err_info" is assumed to be a string giving further information for + * some WTAP_ERR_ values. + */ +extern void cfile_read_failure_alert_box(const char *filename, int err, + gchar *err_info); + /* * Alert box for a failed attempt to close a capture file. * "err" is assumed to be a UNIX-style errno or a WTAP_ERR_ value. -- cgit v1.2.1