diff options
author | Guy Harris <guy@alum.mit.edu> | 2012-05-24 02:16:53 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2012-05-24 02:16:53 +0000 |
commit | b655197a9dbfc5ea973ffa37b9642de0c1baeec1 (patch) | |
tree | e326402cc6f277500eb2b23fed4fa9269376c5ed /ui/win32 | |
parent | 25e70c04d7a4ed27472948d5e0c7dd2e403adc97 (diff) | |
download | wireshark-b655197a9dbfc5ea973ffa37b9642de0c1baeec1.tar.gz |
In the "Save As" and "Export Specified Packets" code path, do a "safe
save" if the destination file exists.
Don't forbid overwriting an existing file in either of those cases (we
still forbid overwriting the current capture file) - the GUI asks the
user whether they want to do the overwrite, and allows them to cancel
out of it - and don't remove the file before writing to it (doing so
makes the save *un*safe).
Attempt to do a save of an unedited temporary file by just moving the
file on Windows as well as on UN*X - ws_rename() will remove the target
if necessary on Windows (and won't do it as a separate operation before
attempting the rename), so it behaves like ws_rename() on UN*X (which is
just a wrapper around rename()).
svn path=/trunk/; revision=42816
Diffstat (limited to 'ui/win32')
-rw-r--r-- | ui/win32/file_dlg_win32.c | 85 |
1 files changed, 32 insertions, 53 deletions
diff --git a/ui/win32/file_dlg_win32.c b/ui/win32/file_dlg_win32.c index 5e142ca1cb..eaf88f904a 100644 --- a/ui/win32/file_dlg_win32.c +++ b/ui/win32/file_dlg_win32.c @@ -362,33 +362,23 @@ win32_save_as_file(HWND h_wnd, action_after_save_e action_after_save, gpointer a } g_sf_hwnd = NULL; - /* Write out all the packets to the file with the specified name. */ - - /* GetSaveFileName() already asked the user if he wants to overwrite the old file, */ - /* so if we are here, user already confirmed to overwrite - just delete the old file now. */ - /* Note: Windows ws_unlink cannot delete a currently open file; Therefore the */ - /* GetSaveFileName dialog has been coded to prevent doing a 'save as' to the */ - /* currently open capture file. */ - /* XX: Windows Wireshark is built with GLIB >= 2.6 these */ - /* days so ws_unlink will properly convert the */ - /* UTF8 filename to UTF16 & then do a _wunlink. */ - /* XX: if the cf_save_as fails, it will do a GTK simple_dialog() */ - /* which is not useful while doing a Windows dialog. */ - /* (A GTK dialog box will be generated and basically will */ - /* only appear when the redisplayed Windows 'save_as-file' */ - /* dialog is dismissed. It will then need to be dismissed. */ - /* This should be fixed even though the cf_save_as() */ - /* presumably should rarely fail in this case. */ - if ((ws_unlink(file_name8->str) != 0) && (errno == EACCES)) { - /* XXX: Is MessageBox the best way to pop up an error ? How to make text bold ? */ - gchar *str = g_strdup_printf("Unable to delete file: %s\nPlease choose another name !", file_name8->str); - MessageBox( NULL, utf_8to16(str), _T("Error"), MB_ICONERROR | MB_APPLMODAL | MB_OK); - g_free(str); - goto AGAIN; - } - if (cf_save_as(&cfile, file_name8->str, filetype, FALSE) != CF_OK) { + + /* + * GetSaveFileName() already asked the user if he wants to overwrite + * the old file, so if we are here, the user already said "yes". + * Write out all the packets to the file with the specified name. + * + * XXX: if the cf_save_packets() fails, it will do a GTK+ + * simple_dialog(), which is not useful while runing a Windows + * dialog. + * (A GTK dialog box will be generated and basically will + * only appear when the redisplayed Windows 'save_as-file' + * dialog is dismissed. It will then need to be dismissed. + * This should be fixed even though the cf_save_packets() + * presumably should rarely fail in this case. + */ + if (cf_save_packets(&cfile, file_name8->str, filetype) != CF_OK) { /* The write failed. Try again. */ - AGAIN: g_array_free(savable_file_types, TRUE); g_string_free(file_name8, TRUE /* free_segment */); g_free( (void *) ofn->lpstrFilter); @@ -539,35 +529,24 @@ win32_export_specified_packets_file(HWND h_wnd) { } g_sf_hwnd = NULL; - /* Write out the specified packets to the file with the specified name. */ - - /* GetSaveFileName() already asked the user if he wants to overwrite the old file, */ - /* so if we are here, user already confirmed to overwrite - just delete the old file now. */ - /* Note: Windows ws_unlink cannot delete a currently open file; Therefore the */ - /* GetSaveFileName dialog has been coded to prevent doing a 'save as' to the */ - /* currently open capture file. */ - /* XX: Windows Wireshark is built with GLIB >= 2.6 these */ - /* days so ws_unlink will properly convert the */ - /* UTF8 filename to UTF16 & then do a _wunlink. */ - /* XX: if the cf_export_specified_packets fails, it will do a */ - /* GTK simple_dialog() which is not useful while doing a */ - /* Windows dialog. */ - /* (A GTK dialog box will be generated and basically will */ - /* only appear when the redisplayed Windows 'save_as-file' */ - /* dialog is dismissed. It will then need to be dismissed. */ - /* This should be fixed even though the */ - /* cf_export_specified_packets() presumably should rarely */ - /* fail in this case. */ - if ((ws_unlink(file_name8->str) != 0) && (errno == EACCES)) { - /* XXX: Is MessageBox the best way to pop up an error ? How to make text bold ? */ - gchar *str = g_strdup_printf("Unable to delete file: %s\nPlease choose another name !", file_name8->str); - MessageBox( NULL, utf_8to16(str), _T("Error"), MB_ICONERROR | MB_APPLMODAL | MB_OK); - g_free(str); - goto AGAIN; - } + + /* + * GetSaveFileName() already asked the user if he wants to overwrite + * the old file, so if we are here, the user already said "yes". + * Write out the specified packets to the file with the specified + * name. + * + * XXX: if the cf_export_specified_packets() fails, it will do a + * GTK+ simple_dialog(), which is not useful while runing a Windows + * dialog. + * (A GTK dialog box will be generated and basically will + * only appear when the redisplayed Windows 'save_as-file' + * dialog is dismissed. It will then need to be dismissed. + * This should be fixed even though the cf_save_packets() + * presumably should rarely fail in this case. + */ if (cf_export_specified_packets(&cfile, file_name8->str, &g_range, filetype, FALSE) != CF_OK) { /* The write failed. Try again. */ - AGAIN: g_array_free(savable_file_types, TRUE); g_string_free(file_name8, TRUE /* free_segment */); g_free( (void *) ofn->lpstrFilter); |