Unify the GTK+ and Win32 versions of "Export Specified Packets". Add a

shared "file_add_extension" routine. We no longer support _MSC_VER <
1400 so get rid of some clutter. Add a gzip checkbox to the Win32 export
packets dialog. Windows code hasn't yet been tested (and is likely
broken). I'll fix it shortly.

svn path=/trunk/; revision=45296
This commit is contained in:
Gerald Combs 2012-10-03 19:24:14 +00:00
parent 191dd647a1
commit bcd2cea774
4 changed files with 257 additions and 378 deletions

View File

@ -27,17 +27,17 @@ FONT 8, "MS Shell Dlg"
LTEXT "Elapsed:", EWFD_PT_ELAPSED, 224, 62, 40, 8
LTEXT "-", EWFD_PTX_ELAPSED, 271, 62, 150, 8
// 164/211, 79, 40/150, 8
}
WIRESHARK_SAVEASFILENAME_TEMPLATE DIALOGEX 0, 0, 167, 15
STYLE WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | DS_3DLOOK | DS_CONTROL
FONT 8, "MS Shell Dlg"
{
CHECKBOX "Compress with gzip", EWFD_GZIP_CB, 67, 0, 100, 8, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
CHECKBOX "Compress with gzip", EWFD_GZIP_CB, 67, 0, 100, 8, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
}
WIRESHARK_EXPORT_SPECIFIED_PACKETS_FILENAME_TEMPLATE DIALOGEX 0, 0, 275, 107
WIRESHARK_EXPORT_SPECIFIED_PACKETS_FILENAME_TEMPLATE DIALOGEX 0, 0, 442, 107
STYLE WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | DS_3DLOOK | DS_CONTROL
FONT 8, "MS Shell Dlg"
{
@ -67,6 +67,8 @@ FONT 8, "MS Shell Dlg"
LTEXT "0", EWFD_FIRST_LAST_DISP, 282, 60, 41, 8, SS_RIGHT
LTEXT "0", EWFD_RANGE_DISP, 282, 72, 41, 8, SS_RIGHT
LTEXT "0", EWFD_IGNORED_DISP, 282, 84, 41, 8, SS_RIGHT
CHECKBOX "Compress with gzip", EWFD_GZIP_CB, 342, 0, 100, 8, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP
}
WIRESHARK_MERGEFILENAME_TEMPLATE DIALOGEX 0, 0, 421, 77

View File

@ -82,7 +82,6 @@ static void do_file_save(capture_file *cf, gboolean dont_reopen);
static void file_save_as_cmd(capture_file *cf, gboolean must_support_comments,
gboolean dont_reopen);
static void file_select_file_type_cb(GtkWidget *w, gpointer data);
static cf_write_status_t file_export_specified_packets_cb(GtkWidget *fs, packet_range_t *range);
static int set_file_type_list(GtkWidget *combo_box, capture_file *cf,
gboolean must_support_comments);
static gboolean test_file_close(capture_file *cf, gboolean from_quit,
@ -1698,6 +1697,65 @@ gtk_save_as_file(GtkWidget *w _U_, capture_file *cf, GString *file_name, int *fi
}
#endif /* USE_WIN32_FILE_DIALOGS */
static void
file_add_extension(GString *file_name, int file_type, gboolean compressed) {
gchar *file_name_lower;
GString *file_suffix;
GSList *extensions_list, *extension;
gboolean add_extension;
/*
* Append the default file extension if there's none given by
* the user or if they gave one that's not one of the valid
* extensions for the file type.
*/
file_name_lower = g_utf8_strdown(file_name->str, -1);
file_suffix = g_string_new("");
extensions_list = wtap_get_file_extensions_list(file_type, FALSE);
if (extensions_list != NULL) {
/* We have one or more extensions for this file type.
Start out assuming we need to add the default one. */
add_extension = TRUE;
/* OK, see if the file has one of those extensions. */
for (extension = extensions_list; extension != NULL;
extension = g_slist_next(extension)) {
g_string_printf(file_suffix, ".%s", (char *)extension->data);
if (g_str_has_suffix(file_name_lower, file_suffix->str)) {
/*
* The file name has one of the extensions for
* this file type.
*/
add_extension = FALSE;
break;
}
g_string_append(file_suffix, ".gz");
if (g_str_has_suffix(file_name_lower, file_suffix->str)) {
/*
* The file name has one of the extensions for
* this file type.
*/
add_extension = FALSE;
break;
}
}
} else {
/* We have no extensions for this file type. Don't add one. */
add_extension = FALSE;
}
g_free(file_name_lower);
g_string_free(file_suffix, TRUE);
if (add_extension) {
if (wtap_default_file_extension(file_type) != NULL) {
g_string_append_printf(file_name, ".%s",
wtap_default_file_extension(file_type));
if (compressed) {
g_string_append(file_name, ".gz");
}
}
}
}
/* Save a file with a user-specified name */
/*
@ -1716,10 +1774,6 @@ file_save_as_cmd(capture_file *cf, gboolean must_support_comments,
int file_type;
gboolean compressed;
cf_write_status_t status;
gchar *file_name_lower;
GString *file_suffix;
GSList *extensions_list, *extension;
gboolean add_extension;
gchar *dirname;
gboolean discard_comments = FALSE;
@ -1778,56 +1832,7 @@ file_save_as_cmd(capture_file *cf, gboolean must_support_comments,
return;
}
/*
* Append the default file extension if there's none given by
* the user or if they gave one that's not one of the valid
* extensions for the file type.
*/
file_name_lower = g_utf8_strdown(file_name->str, -1);
file_suffix = g_string_new("");
extensions_list = wtap_get_file_extensions_list(file_type, FALSE);
if (extensions_list != NULL) {
/* We have one or more extensions for this file type.
Start out assuming we need to add the default one. */
add_extension = TRUE;
/* OK, see if the file has one of those extensions. */
for (extension = extensions_list; extension != NULL;
extension = g_slist_next(extension)) {
g_string_printf(file_suffix, ".%s", (char *)extension->data);
if (g_str_has_suffix(file_name_lower, file_suffix->str)) {
/*
* The file name has one of the extensions for
* this file type.
*/
add_extension = FALSE;
break;
}
g_string_append(file_suffix, ".gz");
if (g_str_has_suffix(file_name_lower, file_suffix->str)) {
/*
* The file name has one of the extensions for
* this file type.
*/
add_extension = FALSE;
break;
}
}
} else {
/* We have no extensions for this file type. Don't add one. */
add_extension = FALSE;
}
g_free(file_name_lower);
g_string_free(file_suffix, TRUE);
if (add_extension) {
if (wtap_default_file_extension(file_type) != NULL) {
g_string_append_printf(file_name, ".%s",
wtap_default_file_extension(file_type));
if (compressed) {
g_string_append(file_name, ".gz");
}
}
}
file_add_extension(file_name, file_type, compressed);
#ifndef _WIN32
/* If the file exists and it's user-immutable or not writable,
@ -1846,7 +1851,7 @@ file_save_as_cmd(capture_file *cf, gboolean must_support_comments,
case CF_WRITE_OK:
/* The save succeeded; we're done. */
/* Save the directory name for future file dialogs. */
dirname = get_dirname(file_name->str); /* Overwrites cf_name */
dirname = get_dirname(file_name->str); /* Overwrites file_name->str */
set_last_open_dir(dirname);
/* If we discarded comments, redraw the packet list to reflect
any packets that no longer have comments. */
@ -1875,27 +1880,22 @@ file_save_as_cmd_cb(GtkWidget *w _U_, gpointer data _U_)
file_save_as_cmd(&cfile, FALSE, FALSE);
}
void
file_export_specified_packets_cmd_cb(GtkWidget *widget _U_, gpointer data _U_)
#ifndef USE_WIN32_FILE_DIALOGS
static gboolean
gtk_export_specified_packets_file(GtkWidget *w _U_, GString *file_name, int *file_type,
gboolean *compressed, packet_range_t *range)
{
#ifdef USE_WIN32_FILE_DIALOGS
win32_export_specified_packets_file(GDK_WINDOW_HWND(gtk_widget_get_window(top_level)));
#else /* USE_WIN32_FILE_DIALOGS */
GtkWidget *file_export_specified_packets_w;
GtkWidget *main_vb, *ft_hb, *ft_lb, *ft_combo_box, *range_fr, *range_tb,
*compressed_cb;
packet_range_t range;
char *cf_name;
gchar *display_basename;
GtkWidget *msg_dialog;
gpointer ptr;
if (!file_name || !file_type || !compressed || !range)
return FALSE;
/* Default to writing out all displayed packets, in the file's current format. */
/* init the packet range */
packet_range_init(&range);
range.process_filtered = TRUE;
range.include_dependents = TRUE;
/* build the file selection */
file_export_specified_packets_w = file_selection_new("Wireshark: Export Specified Packets",
FILE_SELECTION_SAVE);
@ -1915,7 +1915,7 @@ file_export_specified_packets_cmd_cb(GtkWidget *widget _U_, gpointer data _U_)
gtk_widget_show(range_fr);
/* range table */
range_tb = range_new(&range, TRUE);
range_tb = range_new(range, TRUE);
gtk_container_add(GTK_CONTAINER(range_fr), range_tb);
gtk_widget_show(range_tb);
@ -1950,142 +1950,138 @@ file_export_specified_packets_cmd_cb(GtkWidget *widget _U_, gpointer data _U_)
g_signal_connect(ft_combo_box, "changed", G_CALLBACK(file_select_file_type_cb), file_export_specified_packets_w);
ws_combo_box_set_active(GTK_COMBO_BOX(ft_combo_box), 0);
/*
* Loop until the user either selects a file or gives up.
*/
for (;;) {
cf_name = file_selection_run(file_export_specified_packets_w);
if (cf_name == NULL) {
/* User cancelled or closed the dialog. */
return;
}
/* Check whether the range is valid. */
if (!range_check_validity_modal(file_export_specified_packets_w, &range)) {
/* The range isn't valid; the user was told that, and dismissed
the dialog telling them that, so let them fix the range
and try again, or cancel. */
g_free(cf_name);
continue;
}
/*
* Check that we're not going to save on top of the current
* capture file.
* We do it here so we catch all cases ...
* Unfortunately, the file requester gives us an absolute file
* name and the read file name may be relative (if supplied on
* the command line). From Joerg Mayer.
*/
if (files_identical(cfile.filename, cf_name)) {
display_basename = g_filename_display_basename(cf_name);
msg_dialog = gtk_message_dialog_new(GTK_WINDOW(file_export_specified_packets_w),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
"The file \"%s\" is the capture file from which you're exporting the packets.",
display_basename);
g_free(display_basename);
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(msg_dialog),
"You cannot export packets on top of the current capture file.");
gtk_dialog_run(GTK_DIALOG(msg_dialog));
gtk_widget_destroy(msg_dialog);
g_free(cf_name);
continue;
}
#ifndef _WIN32
/* If the file exists and it's user-immutable or not writable,
ask the user whether they want to override that. */
if (!file_target_unwritable_ui(file_export_specified_packets_w, cf_name)) {
/* They don't. Let them try another file name or cancel. */
g_free(cf_name);
continue;
}
#endif
/* attempt to export the packets */
g_free(cf_name);
switch (file_export_specified_packets_cb(file_export_specified_packets_w,
&range)) {
case CF_WRITE_OK:
/* The save succeeded; we're done. */
return;
case CF_WRITE_ERROR:
/* The save failed; let the user try again */
continue;
case CF_WRITE_ABORTED:
/* The user aborted the save; just return. */
return;
}
cf_name = file_selection_run(file_export_specified_packets_w);
if (cf_name == NULL) {
/* User cancelled or closed the dialog. */
return FALSE;
}
#endif /* USE_WIN32_FILE_DIALOGS */
}
/* all tests ok, we only have to write out the packets */
/* (and probably continue with a pending operation) */
static cf_write_status_t
file_export_specified_packets_cb(GtkWidget *fs, packet_range_t *range)
{
GtkWidget *ft_combo_box;
GtkWidget *compressed_cb;
gchar *cf_name;
gchar *dirname;
gpointer ptr;
int file_type;
gboolean compressed;
cf_write_status_t status;
/* Hide the file chooser while we're doing the export. */
gtk_widget_hide(fs);
cf_name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs));
compressed_cb = (GtkWidget *)g_object_get_data(G_OBJECT(fs), E_COMPRESSED_CB_KEY);
ft_combo_box = (GtkWidget *)g_object_get_data(G_OBJECT(fs), E_FILE_TYPE_COMBO_BOX_KEY);
if (! ws_combo_box_get_active_pointer(GTK_COMBO_BOX(ft_combo_box), &ptr)) {
g_assert_not_reached(); /* Programming error: somehow nothing is active */
}
file_type = GPOINTER_TO_INT(ptr);
compressed = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compressed_cb));
*file_type = GPOINTER_TO_INT(ptr);
*compressed = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compressed_cb));
/* Write out the specified packets to the file with the specified name. */
status = cf_export_specified_packets(&cfile, cf_name, range, file_type,
compressed);
switch (status) {
/* We've crossed the Rubicon; get rid of the file export box. */
window_destroy(GTK_WIDGET(file_export_specified_packets_w));
case CF_WRITE_OK:
/* The write succeeded; get rid of the file selection box. */
/* cf_export_specified_packets() might already closed our dialog! */
window_destroy(GTK_WIDGET(fs));
/* Save the directory name for future file dialogs.
XXX - should there be separate ones for "Save As" and
"Export Specified Packets"? */
dirname = get_dirname(cf_name); /* Overwrites cf_name */
set_last_open_dir(dirname);
break;
case CF_WRITE_ERROR:
/* The write failed.
just leave the file selection box around so that the user can,
after they dismiss the alert box popped up for the error, try
again. */
break;
case CF_WRITE_ABORTED:
/* The write was aborted; just get rid of the file selection
box and return. */
window_destroy(fs);
break;
}
g_string_printf(file_name, "%s", cf_name);
g_free(cf_name);
return status;
return TRUE;
}
#endif /* USE_WIN32_FILE_DIALOGS */
/*
* <platform/>_export_specified_packets_file routines should upon entry...
* Set the path and fill in the filename if the path+filename is provided.
* ...and upon exit...
* Return TRUE on "OK" and "FALSE" on "Cancel".
* Close the window.
*/
void
file_export_specified_packets_cmd_cb(GtkWidget *w _U_, gpointer data _U_) {
GString *file_name = g_string_new("");
int file_type;
gboolean compressed;
packet_range_t range;
cf_write_status_t status;
gchar *dirname;
gchar *display_basename;
GtkWidget *msg_dialog;
/* init the packet range */
packet_range_init(&range);
range.process_filtered = TRUE;
range.include_dependents = TRUE;
/*
* Loop until the user either selects a file or gives up.
*/
for (;;) {
#ifdef USE_WIN32_FILE_DIALOGS
if (win32_export_specified_packets_file(GDK_WINDOW_HWND(gtk_widget_get_window(top_level)),
file_name, &file_type, &compressed, &range)) {
#else /* USE_WIN32_FILE_DIALOGS */
if (gtk_export_specified_packets_file(w, file_name, &file_type, &compressed, &range)) {
#endif /* USE_WIN32_FILE_DIALOGS */
/* Check whether the range is valid. */
if (!range_check_validity_modal(top_level, &range)) {
/* The range isn't valid; the user was told that, and dismissed
the dialog telling them that, so let them fix the range
and try again, or cancel. */
continue;
}
/* XXX - Check for comments? */
/*
* Check that we're not going to save on top of the current
* capture file.
* We do it here so we catch all cases ...
* Unfortunately, the file requester gives us an absolute file
* name and the read file name may be relative (if supplied on
* the command line). From Joerg Mayer.
*/
if (files_identical(cfile.filename, file_name->str)) {
display_basename = g_filename_display_basename(file_name->str);
msg_dialog = gtk_message_dialog_new(GTK_WINDOW(top_level),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
"The file \"%s\" is the capture file from which you're exporting the packets.",
display_basename);
g_free(display_basename);
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(msg_dialog),
"You cannot export packets on top of the current capture file.");
gtk_dialog_run(GTK_DIALOG(msg_dialog));
gtk_widget_destroy(msg_dialog);
continue;
}
file_add_extension(file_name, file_type, compressed);
#ifndef _WIN32
/* If the file exists and it's user-immutable or not writable,
ask the user whether they want to override that. */
if (!file_target_unwritable_ui(top_level, file_name->str)) {
/* They don't. Let them try another file name or cancel. */
continue;
}
#endif
/* Attempt to export the file */
status = cf_export_specified_packets(&cfile, file_name->str, &range, file_type,
compressed);
switch (status) {
case CF_WRITE_OK:
/* The write succeeded; get rid of the file selection box. */
/* cf_export_specified_packets() might already closed our dialog! */
/* Save the directory name for future file dialogs.
XXX - should there be separate ones for "Save As" and
"Export Specified Packets"? */
dirname = get_dirname(file_name->str); /* Overwrites file_name->str */
set_last_open_dir(dirname);
break;
case CF_WRITE_ERROR:
/* The save failed; let the user try again. */
continue;
case CF_WRITE_ABORTED:
/* The user aborted the save; just return. */
g_string_free(file_name, TRUE);
return;
}
}
g_string_free(file_name, TRUE);
return;
}
}
/* Reload a file using the current read and display filters */
void

View File

@ -106,28 +106,6 @@ typedef enum {
#define FILE_DEFAULT_COLOR 2
/*
* We should probably test the SDK version instead of the compiler version,
* but this should work for our purposes.
*/
#if (_MSC_VER <= 1200)
static UINT CALLBACK open_file_hook_proc(HWND of_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
static UINT CALLBACK save_as_file_hook_proc(HWND of_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
static UINT CALLBACK export_specified_packets_file_hook_proc(HWND of_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
static UINT CALLBACK merge_file_hook_proc(HWND mf_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
static UINT CALLBACK export_file_hook_proc(HWND of_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
static UINT CALLBACK export_raw_file_hook_proc(HWND of_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
static UINT CALLBACK export_sslkeys_file_hook_proc(HWND of_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
#else
static UINT_PTR CALLBACK open_file_hook_proc(HWND of_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
static UINT_PTR CALLBACK save_as_file_hook_proc(HWND of_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
static UINT_PTR CALLBACK export_specified_packets_file_hook_proc(HWND of_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
static UINT_PTR CALLBACK merge_file_hook_proc(HWND mf_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
static UINT_PTR CALLBACK export_file_hook_proc(HWND of_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
static UINT_PTR CALLBACK export_raw_file_hook_proc(HWND of_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
static UINT_PTR CALLBACK export_sslkeys_file_hook_proc(HWND of_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
#endif /* (_MSC_VER <= 1200) */
static void range_update_dynamics(HWND sf_hwnd, packet_range_t *range);
static void range_handle_wm_initdialog(HWND dlg_hwnd, packet_range_t *range);
static void range_handle_wm_command(HWND dlg_hwnd, HWND ctrl, WPARAM w_param, packet_range_t *range);
@ -136,11 +114,11 @@ static TCHAR *build_file_open_type_list(void);
static TCHAR *build_file_save_type_list(GArray *savable_file_types,
gboolean must_support_comments);
static int g_filetype;
static gboolean g_compressed;
static packet_range_t g_range;
static merge_action_e g_merge_action;
static print_args_t print_args;
static int g_filetype;
static gboolean g_compressed;
static packet_range_t *g_range;
static merge_action_e g_merge_action;
static print_args_t print_args;
/* XXX - The reason g_sf_hwnd exists is so that we can call
* range_update_dynamics() from anywhere; it's currently
* static, but if we move to using the native Windows
@ -222,11 +200,7 @@ win32_open_file (HWND h_wnd, GString *file_name, GString *display_filter) {
ofn->lStructSize = ofnsize;
ofn->hwndOwner = h_wnd;
#if (_MSC_VER <= 1200)
ofn->hInstance = (HINSTANCE) GetWindowLong(h_wnd, GWL_HINSTANCE);
#else
ofn->hInstance = (HINSTANCE) GetWindowLongPtr(h_wnd, GWLP_HINSTANCE);
#endif
ofn->lpstrFilter = build_file_open_type_list();
ofn->lpstrCustomFilter = NULL;
ofn->nMaxCustFilter = 0;
@ -403,11 +377,7 @@ win32_save_as_file(HWND h_wnd, capture_file *cf, GString *file_name, int *file_t
ofn->lStructSize = ofnsize;
ofn->hwndOwner = h_wnd;
#if (_MSC_VER <= 1200)
ofn->hInstance = (HINSTANCE) GetWindowLong(h_wnd, GWL_HINSTANCE);
#else
ofn->hInstance = (HINSTANCE) GetWindowLongPtr(h_wnd, GWLP_HINSTANCE);
#endif
ofn->lpstrFilter = build_file_save_type_list(savable_file_types,
must_support_comments);
ofn->lpstrCustomFilter = NULL;
@ -452,25 +422,34 @@ win32_save_as_file(HWND h_wnd, capture_file *cf, GString *file_name, int *file_t
return gsfn_ok;
}
void
win32_export_specified_packets_file(HWND h_wnd) {
gboolean
win32_export_specified_packets_file(HWND h_wnd, GString *file_name,
int *file_type,
gboolean *compressed,
packet_range_t *range) {
GArray *savable_file_types;
OPENFILENAME *ofn;
TCHAR file_name16[MAX_PATH] = _T("");
GString *file_name8;
gchar *file_last_dot;
GSList *extensions_list, *extension;
gboolean add_extension;
gchar *dirname;
int ofnsize;
gboolean gsfn_ok;
#if (_MSC_VER >= 1500)
OSVERSIONINFO osvi;
#endif
if (!file_name || !file_type || !compressed || !range)
return FALSE;
if (file_name->len > 0) {
StringCchCopy(file_name16, MAX_PATH, utf_8to16(file_name->str));
}
savable_file_types = wtap_get_savable_file_types(cfile.cd_t, cfile.linktypes);
if (savable_file_types == NULL)
return; /* shouldn't happen - the "Save As..." item should be disabled if we can't save the file */
g_range = range;
g_compressed = FALSE;
/* see OPENFILENAME comment in win32_open_file */
#if (_MSC_VER >= 1500)
SecureZeroMemory(&osvi, sizeof(OSVERSIONINFO));
@ -488,11 +467,7 @@ win32_export_specified_packets_file(HWND h_wnd) {
ofn->lStructSize = ofnsize;
ofn->hwndOwner = h_wnd;
#if (_MSC_VER <= 1200)
ofn->hInstance = (HINSTANCE) GetWindowLong(h_wnd, GWL_HINSTANCE);
#else
ofn->hInstance = (HINSTANCE) GetWindowLongPtr(h_wnd, GWLP_HINSTANCE);
#endif
ofn->lpstrFilter = build_file_save_type_list(savable_file_types, FALSE);
ofn->lpstrCustomFilter = NULL;
ofn->nMaxCustFilter = 0;
@ -510,82 +485,31 @@ win32_export_specified_packets_file(HWND h_wnd) {
ofn->lpfnHook = export_specified_packets_file_hook_proc;
ofn->lpTemplateName = _T("WIRESHARK_EXPORT_SPECIFIED_PACKETS_FILENAME_TEMPLATE");
if (GetSaveFileName(ofn)) {
g_filetype = g_array_index(savable_file_types, int, ofn->nFilterIndex - 1);
gsfn_ok = GetSaveFileName(ofn);
/*
* Append the default file extension if there's none given by the user
* or if they gave one that's not one of the valid extensions for
* the file type.
*/
file_name8 = g_string_new(utf_16to8(file_name16));
file_last_dot = strrchr(file_name8->str,'.');
extensions_list = wtap_get_file_extensions_list(g_filetype, FALSE);
if (extensions_list != NULL) {
/* We have one or more extensions for this file type.
Start out assuming we need to add the default one. */
add_extension = TRUE;
if (file_last_dot != NULL) {
/* Skip past the dot. */
file_last_dot++;
/* OK, see if the file has one of those extensions. */
for (extension = extensions_list; extension != NULL;
extension = g_slist_next(extension)) {
if (g_ascii_strcasecmp((char *)extension->data, file_last_dot) == 0) {
/* The file name has one of the extensions for this file type */
add_extension = FALSE;
break;
}
}
}
} else {
/* We have no extensions for this file type. Don't add one. */
add_extension = FALSE;
if (gsfn_ok) {
g_string_printf(file_name, "%s", utf_16to8(file_name16));
/* What file format was specified? */
*file_type = g_array_index(savable_file_types, int, ofn->nFilterIndex - 1);
*compressed = g_compressed;
} else {
/* User cancelled or closed the dialog, or an error occurred. */
if (CommDlgExtendedError() != 0) {
/* XXX - pop up some error here. FNERR_INVALIDFILENAME
* might be a user error; if so, they should know about
* it. For now we force a do-over.
*/
g_string_truncate(file_name, 0);
gsfn_ok = TRUE;
}
if (add_extension) {
if (wtap_default_file_extension(g_filetype) != NULL) {
g_string_append_printf(file_name8, ".%s", wtap_default_file_extension(g_filetype));
}
}
g_sf_hwnd = NULL;
/*
* 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, g_filetype, FALSE) != CF_OK) {
/* The write failed. Try again. */
g_array_free(savable_file_types, TRUE);
g_string_free(file_name8, TRUE /* free_segment */);
g_free( (void *) ofn->lpstrFilter);
g_free( (void *) ofn);
win32_export_specified_packets_file(h_wnd);
return;
}
/* Save the directory name for future file dialogs. */
dirname = get_dirname(file_name8->str); /* Overwrites cf_name */
set_last_open_dir(dirname);
g_string_free(file_name8, TRUE /* free_segment */);
}
g_sf_hwnd = NULL;
g_range = NULL;
g_array_free(savable_file_types, TRUE);
g_free( (void *) ofn->lpstrFilter);
g_free( (void *) ofn);
return gsfn_ok;
}
@ -630,11 +554,7 @@ win32_merge_file (HWND h_wnd, GString *file_name, GString *display_filter, int *
ofn->lStructSize = ofnsize;
ofn->hwndOwner = h_wnd;
#if (_MSC_VER <= 1200)
ofn->hInstance = (HINSTANCE) GetWindowLong(h_wnd, GWL_HINSTANCE);
#else
ofn->hInstance = (HINSTANCE) GetWindowLongPtr(h_wnd, GWLP_HINSTANCE);
#endif
ofn->lpstrFilter = build_file_open_type_list();
ofn->lpstrCustomFilter = NULL;
ofn->nMaxCustFilter = 0;
@ -712,11 +632,7 @@ win32_export_file(HWND h_wnd, export_type_e export_type) {
ofn->lStructSize = ofnsize;
ofn->hwndOwner = h_wnd;
#if (_MSC_VER <= 1200)
ofn->hInstance = (HINSTANCE) GetWindowLong(h_wnd, GWL_HINSTANCE);
#else
ofn->hInstance = (HINSTANCE) GetWindowLongPtr(h_wnd, GWLP_HINSTANCE);
#endif
ofn->lpstrFilter = FILE_TYPES_EXPORT;
ofn->lpstrCustomFilter = NULL;
ofn->nMaxCustFilter = 0;
@ -836,11 +752,7 @@ win32_export_raw_file(HWND h_wnd) {
ofn->lStructSize = ofnsize;
ofn->hwndOwner = h_wnd;
#if (_MSC_VER <= 1200)
ofn->hInstance = (HINSTANCE) GetWindowLong(h_wnd, GWL_HINSTANCE);
#else
ofn->hInstance = (HINSTANCE) GetWindowLongPtr(h_wnd, GWLP_HINSTANCE);
#endif
ofn->lpstrFilter = FILE_TYPES_RAW;
ofn->lpstrCustomFilter = NULL;
ofn->nMaxCustFilter = 0;
@ -930,11 +842,7 @@ win32_export_sslkeys_file(HWND h_wnd) {
ofn->lStructSize = ofnsize;
ofn->hwndOwner = h_wnd;
#if (_MSC_VER <= 1200)
ofn->hInstance = (HINSTANCE) GetWindowLong(h_wnd, GWL_HINSTANCE);
#else
ofn->hInstance = (HINSTANCE) GetWindowLongPtr(h_wnd, GWLP_HINSTANCE);
#endif
ofn->lpstrFilter = FILE_TYPES_SSLKEYS;
ofn->lpstrCustomFilter = NULL;
ofn->nMaxCustFilter = 0;
@ -1015,11 +923,7 @@ win32_export_color_file(HWND h_wnd, gpointer filter_list) {
ofn->lStructSize = ofnsize;
ofn->hwndOwner = h_wnd;
#if (_MSC_VER <= 1200)
ofn->hInstance = (HINSTANCE) GetWindowLong(h_wnd, GWL_HINSTANCE);
#else
ofn->hInstance = (HINSTANCE) GetWindowLongPtr(h_wnd, GWLP_HINSTANCE);
#endif
ofn->lpstrFilter = FILE_TYPES_COLOR;
ofn->lpstrCustomFilter = NULL;
ofn->nMaxCustFilter = 0;
@ -1080,11 +984,7 @@ win32_import_color_file(HWND h_wnd, gpointer color_filters) {
ofn->lStructSize = ofnsize;
ofn->hwndOwner = h_wnd;
#if (_MSC_VER <= 1200)
ofn->hInstance = (HINSTANCE) GetWindowLong(h_wnd, GWL_HINSTANCE);
#else
ofn->hInstance = (HINSTANCE) GetWindowLongPtr(h_wnd, GWLP_HINSTANCE);
#endif
ofn->lpstrFilter = FILE_TYPES_COLOR;
ofn->lpstrCustomFilter = NULL;
ofn->nMaxCustFilter = 0;
@ -1443,11 +1343,7 @@ filter_tb_syntax_check(HWND hwnd, TCHAR *filter_text) {
}
#if (_MSC_VER <= 1200)
static UINT CALLBACK
#else
static UINT_PTR CALLBACK
#endif
open_file_hook_proc(HWND of_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
HWND cur_ctrl, parent;
OFNOTIFY *notify = (OFNOTIFY *) l_param;
@ -1673,7 +1569,7 @@ build_file_format_list(HWND sf_hwnd) {
if (ft == WTAP_FILE_UNKNOWN)
continue; /* not a real file type */
if (!packet_range_process_all(&g_range) || ft != cfile.cd_t) {
if (!packet_range_process_all(g_range) || ft != cfile.cd_t) {
/* not all unfiltered packets or a different file type. We have to use Wiretap. */
if (!wtap_can_save_with_wiretap(ft, cfile.linktypes))
continue; /* We can't. */
@ -1699,11 +1595,7 @@ build_file_format_list(HWND sf_hwnd) {
}
#endif
#if (_MSC_VER <= 1200)
static UINT CALLBACK
#else
static UINT_PTR CALLBACK
#endif
save_as_file_hook_proc(HWND sf_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
HWND cur_ctrl;
OFNOTIFY *notify = (OFNOTIFY *) l_param;
@ -1813,11 +1705,7 @@ save_as_file_hook_proc(HWND sf_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
}
#define RANGE_TEXT_MAX 128
#if (_MSC_VER <= 1200)
static UINT CALLBACK
#else
static UINT_PTR CALLBACK
#endif
export_specified_packets_file_hook_proc(HWND sf_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
HWND cur_ctrl;
OFNOTIFY *notify = (OFNOTIFY *) l_param;
@ -1830,16 +1718,14 @@ export_specified_packets_file_hook_proc(HWND sf_hwnd, UINT msg, WPARAM w_param,
/* Default to saving all packets, in the file's current format. */
g_filetype = cfile.cd_t;
/* init the packet range */
packet_range_init(&g_range);
/* default to displayed packets */
g_range.process_filtered = TRUE;
g_range.include_dependents = TRUE;
/* Fill in the file format list */
/*build_file_format_list(sf_hwnd);*/
range_handle_wm_initdialog(sf_hwnd, &g_range);
range_handle_wm_initdialog(sf_hwnd, g_range);
/* Fill in the compression checkbox */
cur_ctrl = GetDlgItem(sf_hwnd, EWFD_GZIP_CB);
SendMessage(cur_ctrl, BM_SETCHECK, g_compressed, 0);
break;
case WM_COMMAND:
@ -1887,6 +1773,13 @@ export_specified_packets_file_hook_proc(HWND sf_hwnd, UINT msg, WPARAM w_param,
char *file_name8_selected;
int selected_size;
/* Fetch our compression value */
cur_ctrl = GetDlgItem(sf_hwnd, EWFD_GZIP_CB);
if (SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
g_compressed = TRUE;
else
g_compressed = FALSE;
/* Check if trying to do 'save as' to the currently open file */
parent = GetParent(sf_hwnd);
selected_size = CommDlg_OpenSave_GetFilePath(parent, file_name16_selected, MAX_PATH);
@ -2182,11 +2075,7 @@ range_handle_wm_command(HWND dlg_hwnd, HWND ctrl, WPARAM w_param, packet_range_t
}
}
#if (_MSC_VER <= 1200)
static UINT CALLBACK
#else
static UINT_PTR CALLBACK
#endif
merge_file_hook_proc(HWND mf_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
HWND cur_ctrl, parent;
OFNOTIFY *notify = (OFNOTIFY *) l_param;
@ -2258,11 +2147,7 @@ merge_file_hook_proc(HWND mf_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
}
#if (_MSC_VER <= 1200)
static UINT CALLBACK
#else
static UINT_PTR CALLBACK
#endif
export_file_hook_proc(HWND ef_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
HWND cur_ctrl;
OFNOTIFY *notify = (OFNOTIFY *) l_param;
@ -2322,11 +2207,7 @@ export_file_hook_proc(HWND ef_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
return 0;
}
#if (_MSC_VER <= 1200)
static UINT CALLBACK
#else
static UINT_PTR CALLBACK
#endif
export_raw_file_hook_proc(HWND ef_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
HWND cur_ctrl;
OPENFILENAME *ofnp = (OPENFILENAME *) l_param;
@ -2354,11 +2235,7 @@ export_raw_file_hook_proc(HWND ef_hwnd, UINT msg, WPARAM w_param, LPARAM l_param
return 0;
}
#if (_MSC_VER <= 1200)
static UINT CALLBACK
#else
static UINT_PTR CALLBACK
#endif
export_sslkeys_file_hook_proc(HWND ef_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
HWND cur_ctrl;
OPENFILENAME *ofnp = (OPENFILENAME *) l_param;

View File

@ -77,7 +77,11 @@ gboolean win32_save_as_file(HWND h_wnd, capture_file *cf,
*
* @param h_wnd HWND of the parent window.
*/
void win32_export_specified_packets_file(HWND h_wnd);
void win32_export_specified_packets_file(HWND h_wnd, GString *file_name,
int *file_type,
gboolean *compressed,
packet_range_t *range);
/** Open the "Merge" dialog box.
*
@ -145,8 +149,8 @@ void file_set_save_marked_sensitive();
#define EWFD_PTX_FIRST_PKT 1014
#define EWFD_PTX_ELAPSED 1015
/* Save as dialog defines */
#define EWFD_GZIP_CB 1000
/* Save as and export dialog defines */
#define EWFD_GZIP_CB 1040
/* Export dialog defines */
#define EWFD_CAPTURED_BTN 1000