Don't close Wireshark (GTK) if user cancels Save on Close.

Bug: 9635
Change-Id: I4a6e3ca676f1c1096521c0a8147a1459777c92fa
Reviewed-on: https://code.wireshark.org/review/16075
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
Michael Mann 2016-06-22 01:28:48 -04:00
parent 92ea29128f
commit a9a306f0a1
1 changed files with 18 additions and 13 deletions

View File

@ -74,8 +74,8 @@
#include "ui/win32/file_dlg_win32.h" #include "ui/win32/file_dlg_win32.h"
#endif #endif
static void do_file_save(capture_file *cf, gboolean dont_reopen); static gboolean do_file_save(capture_file *cf, gboolean dont_reopen);
static void file_save_as_cmd(capture_file *cf, static gboolean file_save_as_cmd(capture_file *cf,
gboolean must_support_all_comments, gboolean must_support_all_comments,
gboolean dont_reopen); gboolean dont_reopen);
static void file_select_file_type_cb(GtkWidget *w, gpointer data); static void file_select_file_type_cb(GtkWidget *w, gpointer data);
@ -1238,7 +1238,8 @@ test_file_close(capture_file *cf, gboolean from_quit, const char *before_what)
do_capture_stop(cf); do_capture_stop(cf);
#endif #endif
/* Save the file and close it */ /* Save the file and close it */
do_file_save(cf, TRUE); if (do_file_save(cf, TRUE) == FALSE)
return FALSE;
break; break;
case GTK_RESPONSE_REJECT: case GTK_RESPONSE_REJECT:
@ -1392,7 +1393,7 @@ check_save_with_comments(capture_file *cf)
* Save the capture file in question, prompting the user for a file * Save the capture file in question, prompting the user for a file
* name to save to if necessary. * name to save to if necessary.
*/ */
static void static gboolean
do_file_save(capture_file *cf, gboolean dont_reopen) do_file_save(capture_file *cf, gboolean dont_reopen)
{ {
char *fname; char *fname;
@ -1407,7 +1408,7 @@ do_file_save(capture_file *cf, gboolean dont_reopen)
probably pcap-ng, which supports comments and, if it's probably pcap-ng, which supports comments and, if it's
not pcap-ng, let the user decide what they want to do not pcap-ng, let the user decide what they want to do
if they've added comments. */ if they've added comments. */
file_save_as_cmd(cf, FALSE, dont_reopen); return file_save_as_cmd(cf, FALSE, dont_reopen);
} else { } else {
if (cf->unsaved_changes) { if (cf->unsaved_changes) {
/* This is not a temporary capture file, but it has unsaved /* This is not a temporary capture file, but it has unsaved
@ -1440,18 +1441,17 @@ do_file_save(capture_file *cf, gboolean dont_reopen)
support comments, and the user said not to delete the support comments, and the user said not to delete the
comments. Do a "Save As" so the user can select comments. Do a "Save As" so the user can select
one of those formats and choose a file name. */ one of those formats and choose a file name. */
file_save_as_cmd(cf, TRUE, dont_reopen); return file_save_as_cmd(cf, TRUE, dont_reopen);
return;
case CANCELLED: case CANCELLED:
/* The user said "forget it". Just return. */ /* The user said "forget it". Just return. */
return; return FALSE;
default: default:
/* Squelch warnings that discard_comments is being used /* Squelch warnings that discard_comments is being used
uninitialized. */ uninitialized. */
g_assert_not_reached(); g_assert_not_reached();
return; return TRUE;
} }
/* XXX - cf->filename might get freed out from under us, because /* XXX - cf->filename might get freed out from under us, because
@ -1486,6 +1486,8 @@ do_file_save(capture_file *cf, gboolean dont_reopen)
} }
/* Otherwise just do nothing. */ /* Otherwise just do nothing. */
} }
return TRUE;
} }
void void
@ -1820,7 +1822,7 @@ file_add_extension(GString *file_name, int file_type, gboolean compressed) {
* Close the window. * Close the window.
*/ */
static void static gboolean
file_save_as_cmd(capture_file *cf, gboolean must_support_all_comments, file_save_as_cmd(capture_file *cf, gboolean must_support_all_comments,
gboolean dont_reopen) gboolean dont_reopen)
{ {
@ -1882,7 +1884,7 @@ file_save_as_cmd(capture_file *cf, gboolean must_support_all_comments,
/* The user said "forget it". Just get rid of the dialog box /* The user said "forget it". Just get rid of the dialog box
and return. */ and return. */
g_string_free(file_name, TRUE); g_string_free(file_name, TRUE);
return; return FALSE;
} }
file_add_extension(file_name, file_type, compressed); file_add_extension(file_name, file_type, compressed);
@ -1919,11 +1921,14 @@ file_save_as_cmd(capture_file *cf, gboolean must_support_all_comments,
case CF_WRITE_ABORTED: case CF_WRITE_ABORTED:
/* The user aborted the save; just return. */ /* The user aborted the save; just return. */
g_string_free(file_name, TRUE); g_string_free(file_name, TRUE);
return; return FALSE;
} }
} else {
g_string_free(file_name, TRUE);
return FALSE;
} }
g_string_free(file_name, TRUE); g_string_free(file_name, TRUE);
return; return TRUE;
} }
} }