2 * Native Windows file dialog routines
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 2004 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
44 #include "epan/filesystem.h"
45 #include "epan/addr_resolv.h"
46 #include "epan/prefs.h"
47 #include "epan/dissectors/packet-ssl.h"
48 #include "epan/dissectors/packet-ssl-utils.h"
49 #include "wsutil/file_util.h"
50 #include "wsutil/unicode-utils.h"
52 #include "../alert_box.h"
55 #include "../simple_dialog.h"
57 #include "../color_filters.h"
60 #include "gtk/file_dlg.h"
61 #include "gtk/capture_file_dlg.h"
63 #include "gtk/menus.h"
64 #include "gtk/drag_and_drop.h"
65 #include "gtk/capture_dlg.h"
66 #include "win32/file_dlg_win32.h"
67 #include "gtk/help_dlg.h"
68 #include "gtk/export_sslkeys.h"
76 #define FILE_OPEN_DEFAULT 1 /* All Files */
78 #define FILE_MERGE_DEFAULT FILE_OPEN_DEFAULT
80 #define FILE_SAVE_DEFAULT 1 /* Wireshark/tcpdump */
82 #define FILE_TYPES_EXPORT \
83 _T("Plain text (*.txt)\0") _T("*.txt\0") \
84 _T("PostScript (*.ps)\0") _T("*.ps\0") \
85 _T("CSV (Comma Separated Values summary) (*.csv)\0") _T("*.csv\0") \
86 _T("PSML (XML packet summary) (*.psml)\0") _T("*.psml\0") \
87 _T("PDML (XML packet detail) (*.pdml)\0") _T("*.pdml\0") \
88 _T("C Arrays (packet bytes) (*.c)\0") _T("*.c\0")
90 #define FILE_TYPES_RAW \
91 _T("Raw data (*.bin, *.dat, *.raw)\0") _T("*.bin;*.dat;*.raw\0") \
92 _T("All Files (*.*)\0") _T("*.*\0")
94 #define FILE_RAW_DEFAULT 1
96 #define FILE_TYPES_SSLKEYS \
97 _T("SSL Session Keys (*.keys)\0") _T("*.keys\0") \
98 _T("All Files (*.*)\0") _T("*.*\0")
100 #define FILE_SSLKEYS_DEFAULT 1
102 #define FILE_TYPES_COLOR \
103 _T("Text Files (*.txt)\0") _T("*.txt\0") \
104 _T("All Files (*.*)\0") _T("*.*\0")
106 #define FILE_DEFAULT_COLOR 2
109 * We should probably test the SDK version instead of the compiler version,
110 * but this should work for our purposes.
112 #if (_MSC_VER <= 1200)
113 static UINT CALLBACK open_file_hook_proc(HWND of_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
114 static UINT CALLBACK save_as_file_hook_proc(HWND of_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
115 static UINT CALLBACK merge_file_hook_proc(HWND mf_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
116 static UINT CALLBACK export_file_hook_proc(HWND of_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
117 static UINT CALLBACK export_raw_file_hook_proc(HWND of_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
118 static UINT CALLBACK export_sslkeys_file_hook_proc(HWND of_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
120 static UINT_PTR CALLBACK open_file_hook_proc(HWND of_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
121 static UINT_PTR CALLBACK save_as_file_hook_proc(HWND of_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
122 static UINT_PTR CALLBACK merge_file_hook_proc(HWND mf_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
123 static UINT_PTR CALLBACK export_file_hook_proc(HWND of_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
124 static UINT_PTR CALLBACK export_raw_file_hook_proc(HWND of_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
125 static UINT_PTR CALLBACK export_sslkeys_file_hook_proc(HWND of_hwnd, UINT ui_msg, WPARAM w_param, LPARAM l_param);
126 #endif /* (_MSC_VER <= 1200) */
128 static void range_update_dynamics(HWND sf_hwnd, packet_range_t *range);
129 static void range_handle_wm_initdialog(HWND dlg_hwnd, packet_range_t *range);
130 static void range_handle_wm_command(HWND dlg_hwnd, HWND ctrl, WPARAM w_param, packet_range_t *range);
132 static TCHAR *build_file_type_list(gboolean save, int *item_to_select);
133 static int file_type_from_list_index(gboolean save, int index);
136 static packet_range_t g_range;
137 static merge_action_e merge_action;
138 static print_args_t print_args;
139 /* XXX - The reason g_sf_hwnd exists is so that we can call
140 * range_update_dynamics() from anywhere; it's currently
141 * static, but if we move to using the native Windows
142 * print dialog and put range widgets in it as well,
143 * it might be moved to a separate file.
145 * However, the save file dialog hogs the foreground, so
146 * this may not be necessary (and, in fact, the file dialogs
147 * should arguably be modal to the window for the file
148 * being opened/saved/etc.).
150 static HWND g_sf_hwnd = NULL;
151 static char *dfilter_str = NULL;
154 * According to http://msdn.microsoft.com/en-us/library/bb776913.aspx
155 * we should use IFileOpenDialog and IFileSaveDialog on Windows Vista
160 win32_open_file (HWND h_wnd) {
162 TCHAR file_name[MAX_PATH] = _T("");
167 #if (_MSC_VER >= 1500)
171 /* Remarks on OPENFILENAME_SIZE_VERSION_400:
173 * MSDN states that OPENFILENAME_SIZE_VERSION_400 should be used with
174 * WINVER and _WIN32_WINNT >= 0x0500.
175 * Unfortunately all these are compiler constants, while the underlying is a
176 * problem based is a length check of the runtime version used.
178 * Instead of using OPENFILENAME_SIZE_VERSION_400, just malloc
179 * the OPENFILENAME size plus 12 bytes.
180 * These 12 bytes are the difference between the two versions of this struct.
182 * Interestingly this fixes a bug, so the places bar e.g. "My Documents"
183 * is displayed - which wasn't the case with the former implementation.
185 * XXX - It's unclear if this length+12 works on all supported platforms,
186 * NT4 is the question here. However, even if it fails, we must calculate
187 * the length based on the runtime, not the compiler version anyway ...
189 /* This assumption does not work when compiling with MSVC2008EE as
190 * the open dialog window does not appear.
191 * Instead detect Windows version at runtime and choose size accordingly */
192 #if (_MSC_VER >= 1500)
193 SecureZeroMemory(&osvi, sizeof(OSVERSIONINFO));
194 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
196 if (osvi.dwMajorVersion >= 5) {
197 ofnsize = sizeof(OPENFILENAME);
199 ofnsize = OPENFILENAME_SIZE_VERSION_400;
202 ofnsize = sizeof(OPENFILENAME) + 12;
204 ofn = g_malloc0(ofnsize);
206 ofn->lStructSize = ofnsize;
207 ofn->hwndOwner = h_wnd;
208 #if (_MSC_VER <= 1200)
209 ofn->hInstance = (HINSTANCE) GetWindowLong(h_wnd, GWL_HINSTANCE);
211 ofn->hInstance = (HINSTANCE) GetWindowLongPtr(h_wnd, GWLP_HINSTANCE);
213 ofn->lpstrFilter = build_file_type_list(FALSE /*!save*/, NULL);
214 ofn->lpstrCustomFilter = NULL;
215 ofn->nMaxCustFilter = 0;
216 ofn->nFilterIndex = FILE_OPEN_DEFAULT;
217 ofn->lpstrFile = file_name;
218 ofn->nMaxFile = MAX_PATH;
219 ofn->lpstrFileTitle = NULL;
220 ofn->nMaxFileTitle = 0;
221 if (prefs.gui_fileopen_style == FO_STYLE_SPECIFIED && prefs.gui_fileopen_dir[0] != '\0') {
222 ofn->lpstrInitialDir = utf_8to16(prefs.gui_fileopen_dir);
224 ofn->lpstrInitialDir = utf_8to16(get_last_open_dir());
226 ofn->lpstrTitle = _T("Wireshark: Open Capture File");
227 ofn->Flags = OFN_ENABLESIZING | OFN_ENABLETEMPLATE | OFN_EXPLORER |
228 OFN_NOCHANGEDIR | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY |
229 OFN_ENABLEHOOK | OFN_SHOWHELP;
230 ofn->lpstrDefExt = NULL;
231 ofn->lpfnHook = open_file_hook_proc;
232 ofn->lpTemplateName = _T("WIRESHARK_OPENFILENAME_TEMPLATE");
234 if (GetOpenFileName(ofn)) {
235 g_free( (void *) ofn->lpstrFilter);
236 g_free( (void *) ofn);
238 if (cf_open(&cfile, utf_16to8(file_name), FALSE, &err) != CF_OK) {
242 /* apply our filter */
243 if (dfilter_compile(dfilter_str, &dfp)) {
244 cf_set_rfcode(&cfile, dfp);
247 switch (cf_read(&cfile, FALSE)) {
250 dirname = get_dirname(utf_16to8(file_name));
251 set_last_open_dir(dirname);
256 g_free( (void *) ofn->lpstrFilter);
257 g_free( (void *) ofn);
264 win32_save_as_file(HWND h_wnd, action_after_save_e action_after_save, gpointer action_after_save_data) {
266 TCHAR file_name16[MAX_PATH] = _T("");
268 gchar *file_last_dot;
272 #if (_MSC_VER >= 1500)
276 /* see OPENFILENAME comment in win32_open_file */
277 #if (_MSC_VER >= 1500)
278 SecureZeroMemory(&osvi, sizeof(OSVERSIONINFO));
279 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
281 if (osvi.dwMajorVersion >= 5) {
282 ofnsize = sizeof(OPENFILENAME);
284 ofnsize = OPENFILENAME_SIZE_VERSION_400;
287 ofnsize = sizeof(OPENFILENAME) + 12;
289 ofn = g_malloc0(ofnsize);
291 ofn->lStructSize = ofnsize;
292 ofn->hwndOwner = h_wnd;
293 #if (_MSC_VER <= 1200)
294 ofn->hInstance = (HINSTANCE) GetWindowLong(h_wnd, GWL_HINSTANCE);
296 ofn->hInstance = (HINSTANCE) GetWindowLongPtr(h_wnd, GWLP_HINSTANCE);
298 ofn->lpstrFilter = build_file_type_list(TRUE /*save*/, &save_index);
299 ofn->lpstrCustomFilter = NULL;
300 ofn->nMaxCustFilter = 0;
301 ofn->nFilterIndex = save_index;
302 ofn->lpstrFile = file_name16;
303 ofn->nMaxFile = MAX_PATH;
304 ofn->lpstrFileTitle = NULL;
305 ofn->nMaxFileTitle = 0;
306 ofn->lpstrInitialDir = utf_8to16(get_last_open_dir());
307 ofn->lpstrTitle = _T("Wireshark: Save file as");
308 ofn->Flags = OFN_ENABLESIZING | OFN_ENABLETEMPLATE | OFN_EXPLORER |
309 OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY |
310 OFN_PATHMUSTEXIST | OFN_ENABLEHOOK | OFN_SHOWHELP;
311 ofn->lpstrDefExt = NULL;
312 ofn->lpfnHook = save_as_file_hook_proc;
313 ofn->lpTemplateName = _T("WIRESHARK_SAVEFILENAME_TEMPLATE");
315 if (GetSaveFileName(ofn)) {
316 filetype = file_type_from_list_index(TRUE /*save*/, ofn->nFilterIndex);
318 /* append the default file extension if there's none given by the user */
319 /* (we expect a file extension to be at most 5 chars + the dot) */
320 file_name8 = g_string_new(utf_16to8(file_name16));
321 file_last_dot = strrchr(file_name8->str,'.');
322 if(file_last_dot == NULL || strlen(file_name8->str)-(file_last_dot-file_name8->str) > 5+1) {
323 if(wtap_file_extension_default_string(filetype) != NULL) {
324 file_name8 = g_string_append(file_name8, wtap_file_extension_default_string(filetype));
329 /* Write out the packets (all, or only the ones from the current
330 range) to the file with the specified name. */
332 /* GetSaveFileName() already asked the user if he wants to overwrite the old file, */
333 /* so if we are here, user already confirmed to overwrite - just delete the old file now. */
334 /* Note: Windows ws_unlink cannot delete a currently open file; Therefore the */
335 /* GetSaveFileName dialog has been coded to prevent doing a 'save as' to the */
336 /* currently open capture file. */
337 /* XX: Windows Wireshark is built with GLIB >= 2.6 these */
338 /* days so ws_unlink will properly convert the */
339 /* UTF8 filename to UTF16 & then do a _wunlink. */
340 /* XX: if the cf_save fails, it will do a GTK simple_dialog() */
341 /* which is not useful while doing a Windows dialog. */
342 /* (A GTK dialog box will be generated and basically will */
343 /* only appear when the redisplayed Windows 'save_as-file' */
344 /* dialog is dismissed. It will then need to be dismissed. */
345 /* This should be fixed even though the cf_save() */
346 /* presumably should rarely fail in this case. */
347 if ((ws_unlink(file_name8->str) != 0) && (errno == EACCES)) {
348 /* XXX: Is MessageBox the best way to pop up an error ? How to make text bold ? */
349 gchar *str = g_strdup_printf("Unable to delete file: %s\nPlease choose another name !", file_name8->str);
350 MessageBox( NULL, utf_8to16(str), _T("Error"), MB_ICONERROR | MB_APPLMODAL | MB_OK);
354 if (cf_save(&cfile, file_name8->str, &g_range, filetype, FALSE) != CF_OK) {
355 /* The write failed. Try again. */
357 g_string_free(file_name8, TRUE /* free_segment */);
358 g_free( (void *) ofn->lpstrFilter);
359 g_free( (void *) ofn);
360 win32_save_as_file(h_wnd, action_after_save, action_after_save_data);
364 /* Save the directory name for future file dialogs. */
365 dirname = get_dirname(file_name8->str); /* Overwrites cf_name */
366 set_last_open_dir(dirname);
368 g_string_free(file_name8, TRUE /* free_segment */);
370 /* we have finished saving, do we have pending things to do? */
371 switch(action_after_save) {
372 case(after_save_no_action):
374 case(after_save_open_dialog):
375 win32_open_file(h_wnd);
377 case(after_save_open_recent_file):
378 menu_open_recent_file_cmd(action_after_save_data);
380 case(after_save_open_dnd_file):
381 dnd_open_file_cmd(action_after_save_data);
383 case(after_save_merge_dialog):
384 win32_merge_file(h_wnd);
387 case(after_save_capture_dialog):
388 capture_start_confirmed();
391 case(after_save_close_file):
394 case(after_save_exit):
398 g_assert_not_reached();
402 g_free( (void *) ofn->lpstrFilter);
403 g_free( (void *) ofn);
408 win32_merge_file (HWND h_wnd) {
410 TCHAR file_name[MAX_PATH] = _T("");
412 cf_status_t merge_status = CF_ERROR;
413 char *in_filenames[2];
418 #if (_MSC_VER >= 1500)
422 /* see OPENFILENAME comment in win32_open_file */
423 #if (_MSC_VER >= 1500)
424 SecureZeroMemory(&osvi, sizeof(OSVERSIONINFO));
425 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
427 if (osvi.dwMajorVersion >= 5) {
428 ofnsize = sizeof(OPENFILENAME);
430 ofnsize = OPENFILENAME_SIZE_VERSION_400;
433 ofnsize = sizeof(OPENFILENAME) + 12;
435 ofn = g_malloc0(ofnsize);
437 ofn->lStructSize = ofnsize;
438 ofn->hwndOwner = h_wnd;
439 #if (_MSC_VER <= 1200)
440 ofn->hInstance = (HINSTANCE) GetWindowLong(h_wnd, GWL_HINSTANCE);
442 ofn->hInstance = (HINSTANCE) GetWindowLongPtr(h_wnd, GWLP_HINSTANCE);
444 ofn->lpstrFilter = build_file_type_list(FALSE /*!save*/, NULL);
445 ofn->lpstrCustomFilter = NULL;
446 ofn->nMaxCustFilter = 0;
447 ofn->nFilterIndex = FILE_MERGE_DEFAULT;
448 ofn->lpstrFile = file_name;
449 ofn->nMaxFile = MAX_PATH;
450 ofn->lpstrFileTitle = NULL;
451 ofn->nMaxFileTitle = 0;
452 if (prefs.gui_fileopen_style == FO_STYLE_SPECIFIED && prefs.gui_fileopen_dir[0] != '\0') {
453 ofn->lpstrInitialDir = utf_8to16(prefs.gui_fileopen_dir);
455 ofn->lpstrInitialDir = utf_8to16(get_last_open_dir());
457 ofn->lpstrTitle = _T("Wireshark: Merge with capture file");
458 ofn->Flags = OFN_ENABLESIZING | OFN_ENABLETEMPLATE | OFN_EXPLORER |
459 OFN_NOCHANGEDIR | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY |
460 OFN_ENABLEHOOK | OFN_SHOWHELP;
461 ofn->lpstrDefExt = NULL;
462 ofn->lpfnHook = merge_file_hook_proc;
463 ofn->lpTemplateName = _T("WIRESHARK_MERGEFILENAME_TEMPLATE");
465 if (GetOpenFileName(ofn)) {
466 filetype = cfile.cd_t;
467 g_free( (void *) ofn->lpstrFilter);
468 g_free( (void *) ofn);
470 /* merge or append the two files */
473 switch (merge_action) {
476 in_filenames[0] = cfile.filename;
477 in_filenames[1] = utf_16to8(file_name);
478 merge_status = cf_merge_files(&tmpname, 2, in_filenames, filetype, TRUE);
481 /* chonological order */
482 in_filenames[0] = cfile.filename;
483 in_filenames[1] = utf_16to8(file_name);
484 merge_status = cf_merge_files(&tmpname, 2, in_filenames, filetype, FALSE);
488 in_filenames[0] = utf_16to8(file_name);
489 in_filenames[1] = cfile.filename;
490 merge_status = cf_merge_files(&tmpname, 2, in_filenames, filetype, TRUE);
493 g_assert_not_reached();
496 if(merge_status != CF_OK) {
504 /* Try to open the merged capture file. */
505 if (cf_open(&cfile, tmpname, TRUE /* temporary file */, &err) != CF_OK) {
506 /* We couldn't open it; don't dismiss the open dialog box,
507 just leave it around so that the user can, after they
508 dismiss the alert box popped up for the open error,
513 /* apply our filter */
514 if (dfilter_compile(dfilter_str, &dfp)) {
515 cf_set_rfcode(&cfile, dfp);
518 switch (cf_read(&cfile, FALSE)) {
521 dirname = get_dirname(utf_16to8(file_name));
522 set_last_open_dir(dirname);
523 menu_name_resolution_changed();
525 case CF_READ_ABORTED:
529 g_free( (void *) ofn->lpstrFilter);
530 g_free( (void *) ofn);
535 win32_export_file(HWND h_wnd, export_type_e export_type) {
537 TCHAR file_name[MAX_PATH] = _T("");
539 cf_print_status_t status;
541 #if (_MSC_VER >= 1500)
545 /* see OPENFILENAME comment in win32_open_file */
546 #if (_MSC_VER >= 1500)
547 SecureZeroMemory(&osvi, sizeof(OSVERSIONINFO));
548 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
550 if (osvi.dwMajorVersion >= 5) {
551 ofnsize = sizeof(OPENFILENAME);
553 ofnsize = OPENFILENAME_SIZE_VERSION_400;
556 ofnsize = sizeof(OPENFILENAME) + 12;
558 ofn = g_malloc0(ofnsize);
560 ofn->lStructSize = ofnsize;
561 ofn->hwndOwner = h_wnd;
562 #if (_MSC_VER <= 1200)
563 ofn->hInstance = (HINSTANCE) GetWindowLong(h_wnd, GWL_HINSTANCE);
565 ofn->hInstance = (HINSTANCE) GetWindowLongPtr(h_wnd, GWLP_HINSTANCE);
567 ofn->lpstrFilter = FILE_TYPES_EXPORT;
568 ofn->lpstrCustomFilter = NULL;
569 ofn->nMaxCustFilter = 0;
570 ofn->nFilterIndex = export_type;
571 ofn->lpstrFile = file_name;
572 ofn->nMaxFile = MAX_PATH;
573 ofn->lpstrFileTitle = NULL;
574 ofn->nMaxFileTitle = 0;
575 ofn->lpstrInitialDir = utf_8to16(get_last_open_dir());
576 ofn->lpstrTitle = _T("Wireshark: Export File");
577 ofn->Flags = OFN_ENABLESIZING | OFN_ENABLETEMPLATE | OFN_EXPLORER |
578 OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY |
579 OFN_PATHMUSTEXIST | OFN_ENABLEHOOK | OFN_SHOWHELP;
580 ofn->lpstrDefExt = NULL;
581 ofn->lpfnHook = export_file_hook_proc;
582 ofn->lpTemplateName = _T("WIRESHARK_EXPORTFILENAME_TEMPLATE");
584 /* Fill in our print (and export) args */
586 print_args.format = PR_FMT_TEXT;
587 print_args.to_file = TRUE;
588 print_args.cmd = NULL;
589 print_args.print_summary = TRUE;
590 print_args.print_dissections = print_dissections_as_displayed;
591 print_args.print_hex = FALSE;
592 print_args.print_formfeed = FALSE;
594 if (GetSaveFileName(ofn)) {
595 print_args.file = utf_16to8(file_name);
596 switch (ofn->nFilterIndex) {
597 case export_type_text: /* Text */
598 print_args.stream = print_stream_text_new(TRUE, print_args.file);
599 if (print_args.stream == NULL) {
600 open_failure_alert_box(print_args.file, errno, TRUE);
601 g_free( (void *) ofn);
604 status = cf_print_packets(&cfile, &print_args);
606 case export_type_ps: /* PostScript (r) */
607 print_args.stream = print_stream_ps_new(TRUE, print_args.file);
608 if (print_args.stream == NULL) {
609 open_failure_alert_box(print_args.file, errno, TRUE);
610 g_free( (void *) ofn);
613 status = cf_print_packets(&cfile, &print_args);
615 case export_type_csv: /* CSV */
616 status = cf_write_csv_packets(&cfile, &print_args);
618 case export_type_carrays: /* C Arrays */
619 status = cf_write_carrays_packets(&cfile, &print_args);
621 case export_type_psml: /* PSML */
622 status = cf_write_psml_packets(&cfile, &print_args);
624 case export_type_pdml: /* PDML */
625 status = cf_write_pdml_packets(&cfile, &print_args);
628 g_free( (void *) ofn);
635 case CF_PRINT_OPEN_ERROR:
636 open_failure_alert_box(print_args.file, errno, TRUE);
638 case CF_PRINT_WRITE_ERROR:
639 write_failure_alert_box(print_args.file, errno);
642 /* Save the directory name for future file dialogs. */
643 dirname = get_dirname(utf_16to8(file_name)); /* Overwrites cf_name */
644 set_last_open_dir(dirname);
647 g_free( (void *) ofn);
651 win32_export_raw_file(HWND h_wnd) {
653 TCHAR file_name[MAX_PATH] = _T("");
655 const guint8 *data_p;
659 #if (_MSC_VER >= 1500)
663 if (!cfile.finfo_selected) {
664 /* This shouldn't happen */
665 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "No bytes were selected.");
669 /* see OPENFILENAME comment in win32_open_file */
670 #if (_MSC_VER >= 1500)
671 SecureZeroMemory(&osvi, sizeof(OSVERSIONINFO));
672 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
674 if (osvi.dwMajorVersion >= 5) {
675 ofnsize = sizeof(OPENFILENAME);
677 ofnsize = OPENFILENAME_SIZE_VERSION_400;
680 ofnsize = sizeof(OPENFILENAME) + 12;
682 ofn = g_malloc0(ofnsize);
684 ofn->lStructSize = ofnsize;
685 ofn->hwndOwner = h_wnd;
686 #if (_MSC_VER <= 1200)
687 ofn->hInstance = (HINSTANCE) GetWindowLong(h_wnd, GWL_HINSTANCE);
689 ofn->hInstance = (HINSTANCE) GetWindowLongPtr(h_wnd, GWLP_HINSTANCE);
691 ofn->lpstrFilter = FILE_TYPES_RAW;
692 ofn->lpstrCustomFilter = NULL;
693 ofn->nMaxCustFilter = 0;
694 ofn->nFilterIndex = FILE_RAW_DEFAULT;
695 ofn->lpstrFile = file_name;
696 ofn->nMaxFile = MAX_PATH;
697 ofn->lpstrFileTitle = NULL;
698 ofn->nMaxFileTitle = 0;
699 ofn->lpstrInitialDir = utf_8to16(get_last_open_dir());
700 ofn->lpstrTitle = _T("Wireshark: Export Raw Data");
701 ofn->Flags = OFN_ENABLESIZING | OFN_ENABLETEMPLATE | OFN_EXPLORER |
702 OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY |
703 OFN_PATHMUSTEXIST | OFN_ENABLEHOOK | OFN_SHOWHELP;
704 ofn->lpstrDefExt = NULL;
705 ofn->lCustData = cfile.finfo_selected->length;
706 ofn->lpfnHook = export_raw_file_hook_proc;
707 ofn->lpTemplateName = _T("WIRESHARK_EXPORTRAWFILENAME_TEMPLATE");
710 * XXX - The GTK+ code uses get_byte_view_data_and_length(). We just
711 * grab the info from cfile.finfo_selected. Which is more "correct"?
714 if (GetSaveFileName(ofn)) {
715 g_free( (void *) ofn);
716 file_name8 = utf_16to8(file_name);
717 data_p = tvb_get_ptr(cfile.finfo_selected->ds_tvb, 0, -1) +
718 cfile.finfo_selected->start;
719 fd = ws_open(file_name8, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0666);
721 open_failure_alert_box(file_name8, errno, TRUE);
724 if (write(fd, data_p, cfile.finfo_selected->length) < 0) {
725 write_failure_alert_box(file_name8, errno);
730 write_failure_alert_box(file_name8, errno);
734 /* Save the directory name for future file dialogs. */
735 dirname = get_dirname(file_name8); /* Overwrites cf_name */
736 set_last_open_dir(dirname);
738 g_free( (void *) ofn);
743 win32_export_sslkeys_file(HWND h_wnd) {
745 TCHAR file_name[MAX_PATH] = _T("");
752 #if (_MSC_VER >= 1500)
756 keylist_size = g_hash_table_size(ssl_session_hash);
757 if (keylist_size==0) {
758 /* This shouldn't happen */
759 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "No SSL Session Keys to export.");
763 /* see OPENFILENAME comment in win32_open_file */
764 #if (_MSC_VER >= 1500)
765 SecureZeroMemory(&osvi, sizeof(OSVERSIONINFO));
766 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
768 if (osvi.dwMajorVersion >= 5) {
769 ofnsize = sizeof(OPENFILENAME);
771 ofnsize = OPENFILENAME_SIZE_VERSION_400;
774 ofnsize = sizeof(OPENFILENAME) + 12;
776 ofn = g_malloc0(ofnsize);
778 ofn->lStructSize = ofnsize;
779 ofn->hwndOwner = h_wnd;
780 #if (_MSC_VER <= 1200)
781 ofn->hInstance = (HINSTANCE) GetWindowLong(h_wnd, GWL_HINSTANCE);
783 ofn->hInstance = (HINSTANCE) GetWindowLongPtr(h_wnd, GWLP_HINSTANCE);
785 ofn->lpstrFilter = FILE_TYPES_SSLKEYS;
786 ofn->lpstrCustomFilter = NULL;
787 ofn->nMaxCustFilter = 0;
788 ofn->nFilterIndex = FILE_SSLKEYS_DEFAULT;
789 ofn->lpstrFile = file_name;
790 ofn->nMaxFile = MAX_PATH;
791 ofn->lpstrFileTitle = NULL;
792 ofn->nMaxFileTitle = 0;
793 ofn->lpstrInitialDir = utf_8to16(get_last_open_dir());
794 ofn->lpstrTitle = _T("Wireshark: Export SSL Session Keys");
795 ofn->Flags = OFN_ENABLESIZING | OFN_ENABLETEMPLATE | OFN_EXPLORER |
796 OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY |
797 OFN_PATHMUSTEXIST | OFN_ENABLEHOOK | OFN_SHOWHELP;
798 ofn->lpstrDefExt = NULL;
799 ofn->lCustData = keylist_size;
800 ofn->lpfnHook = export_sslkeys_file_hook_proc;
801 ofn->lpTemplateName = _T("WIRESHARK_EXPORTSSLKEYSFILENAME_TEMPLATE");
803 if (GetSaveFileName(ofn)) {
804 g_free( (void *) ofn);
805 file_name8 = utf_16to8(file_name);
806 keylist = ssl_export_sessions(ssl_session_hash);
807 fd = ws_open(file_name8, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0666);
809 open_failure_alert_box(file_name8, errno, TRUE);
814 * Thanks, Microsoft, for not using size_t for the third argument to
815 * _write(). Presumably this string will be <= 4GiB long....
817 if (ws_write(fd, keylist->data, (unsigned int)strlen(keylist->data)) < 0) {
818 write_failure_alert_box(file_name8, errno);
823 if (ws_close(fd) < 0) {
824 write_failure_alert_box(file_name8, errno);
829 /* Save the directory name for future file dialogs. */
830 dirname = get_dirname(file_name8); /* Overwrites cf_name */
831 set_last_open_dir(dirname);
833 g_free( (void *) ofn);
839 win32_export_color_file(HWND h_wnd, gpointer filter_list) {
841 TCHAR file_name[MAX_PATH] = _T("");
844 #if (_MSC_VER >= 1500)
848 /* see OPENFILENAME comment in win32_open_file */
849 #if (_MSC_VER >= 1500)
850 SecureZeroMemory(&osvi, sizeof(OSVERSIONINFO));
851 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
853 if (osvi.dwMajorVersion >= 5) {
854 ofnsize = sizeof(OPENFILENAME);
856 ofnsize = OPENFILENAME_SIZE_VERSION_400;
859 ofnsize = sizeof(OPENFILENAME) + 12;
861 ofn = g_malloc0(ofnsize);
863 ofn->lStructSize = ofnsize;
864 ofn->hwndOwner = h_wnd;
865 #if (_MSC_VER <= 1200)
866 ofn->hInstance = (HINSTANCE) GetWindowLong(h_wnd, GWL_HINSTANCE);
868 ofn->hInstance = (HINSTANCE) GetWindowLongPtr(h_wnd, GWLP_HINSTANCE);
870 ofn->lpstrFilter = FILE_TYPES_COLOR;
871 ofn->lpstrCustomFilter = NULL;
872 ofn->nMaxCustFilter = 0;
873 ofn->nFilterIndex = FILE_DEFAULT_COLOR;
874 ofn->lpstrFile = file_name;
875 ofn->nMaxFile = MAX_PATH;
876 ofn->lpstrFileTitle = NULL;
877 ofn->nMaxFileTitle = 0;
878 ofn->lpstrInitialDir = utf_8to16(get_last_open_dir());
879 ofn->lpstrTitle = _T("Wireshark: Export Color Filters");
880 ofn->Flags = OFN_ENABLESIZING | OFN_EXPLORER |
881 OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY |
882 OFN_PATHMUSTEXIST | OFN_ENABLEHOOK;
883 ofn->lpstrDefExt = NULL;
884 ofn->lpfnHook = NULL;
885 ofn->lpTemplateName = NULL;
887 filetype = cfile.cd_t;
889 /* XXX - Support marked filters */
890 if (GetSaveFileName(ofn)) {
891 g_free( (void *) ofn);
892 if (!color_filters_export(utf_16to8(file_name), filter_list, FALSE /* all filters */))
895 /* Save the directory name for future file dialogs. */
896 dirname = get_dirname(utf_16to8(file_name)); /* Overwrites cf_name */
897 set_last_open_dir(dirname);
899 g_free( (void *) ofn);
904 win32_import_color_file(HWND h_wnd, gpointer color_filters) {
906 TCHAR file_name[MAX_PATH] = _T("");
909 #if (_MSC_VER >= 1500)
913 /* see OPENFILENAME comment in win32_open_file */
914 #if (_MSC_VER >= 1500)
915 SecureZeroMemory(&osvi, sizeof(OSVERSIONINFO));
916 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
918 if (osvi.dwMajorVersion >= 5) {
919 ofnsize = sizeof(OPENFILENAME);
921 ofnsize = OPENFILENAME_SIZE_VERSION_400;
924 ofnsize = sizeof(OPENFILENAME) + 12;
926 ofn = g_malloc0(ofnsize);
928 ofn->lStructSize = ofnsize;
929 ofn->hwndOwner = h_wnd;
930 #if (_MSC_VER <= 1200)
931 ofn->hInstance = (HINSTANCE) GetWindowLong(h_wnd, GWL_HINSTANCE);
933 ofn->hInstance = (HINSTANCE) GetWindowLongPtr(h_wnd, GWLP_HINSTANCE);
935 ofn->lpstrFilter = FILE_TYPES_COLOR;
936 ofn->lpstrCustomFilter = NULL;
937 ofn->nMaxCustFilter = 0;
938 ofn->nFilterIndex = FILE_DEFAULT_COLOR;
939 ofn->lpstrFile = file_name;
940 ofn->nMaxFile = MAX_PATH;
941 ofn->lpstrFileTitle = NULL;
942 ofn->nMaxFileTitle = 0;
943 ofn->lpstrInitialDir = utf_8to16(get_last_open_dir());
944 ofn->lpstrTitle = _T("Wireshark: Import Color Filters");
945 ofn->Flags = OFN_ENABLESIZING | OFN_EXPLORER |
946 OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY |
947 OFN_PATHMUSTEXIST | OFN_ENABLEHOOK;
948 ofn->lpstrDefExt = NULL;
949 ofn->lpfnHook = NULL;
950 ofn->lpTemplateName = NULL;
952 /* XXX - Support export limited to selected filters */
953 if (GetOpenFileName(ofn)) {
954 g_free( (void *) ofn);
955 if (!color_filters_import(utf_16to8(file_name), color_filters))
958 /* Save the directory name for future file dialogs. */
959 dirname = get_dirname(utf_16to8(file_name)); /* Overwrites cf_name */
960 set_last_open_dir(dirname);
962 g_free( (void *) ofn);
971 /** Given a print_args_t struct, update a set of print/export format controls
974 * @param dlg_hwnd HWND of the dialog in question.
975 * @param args Pointer to a print args struct.
978 print_update_dynamic(HWND dlg_hwnd, print_args_t *args) {
981 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_PKT_SUMMARY_CB);
982 if (SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
983 args->print_summary = TRUE;
985 args->print_summary = FALSE;
987 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_PKT_DETAIL_CB);
988 if (SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED) {
989 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_PKT_DETAIL_COMBO);
990 switch (SendMessage(cur_ctrl, CB_GETCURSEL, 0, 0)) {
992 args->print_dissections = print_dissections_collapsed;
995 args->print_dissections = print_dissections_as_displayed;
998 args->print_dissections = print_dissections_expanded;
1001 g_assert_not_reached();
1003 EnableWindow(cur_ctrl, TRUE);
1005 args->print_dissections = print_dissections_none;
1006 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_PKT_DETAIL_COMBO);
1007 EnableWindow(cur_ctrl, FALSE);
1010 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_PKT_BYTES_CB);
1011 if (SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
1012 args->print_hex = TRUE;
1014 args->print_hex = FALSE;
1016 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_PKT_NEW_PAGE_CB);
1017 if (SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
1018 args->print_formfeed = TRUE;
1020 args->print_formfeed = FALSE;
1024 format_handle_wm_initdialog(HWND dlg_hwnd, print_args_t *args) {
1027 /* Set the "Packet summary" box */
1028 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_PKT_SUMMARY_CB);
1029 SendMessage(cur_ctrl, BM_SETCHECK, args->print_summary, 0);
1031 /* Set the "Packet details" box */
1032 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_PKT_DETAIL_CB);
1033 SendMessage(cur_ctrl, BM_SETCHECK, args->print_dissections != print_dissections_none, 0);
1035 /* Set the "Packet details" combo */
1036 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_PKT_DETAIL_COMBO);
1037 SendMessage(cur_ctrl, CB_ADDSTRING, 0, (WPARAM) _T("All collapsed"));
1038 SendMessage(cur_ctrl, CB_ADDSTRING, 0, (WPARAM) _T("As displayed"));
1039 SendMessage(cur_ctrl, CB_ADDSTRING, 0, (WPARAM) _T("All expanded"));
1041 switch (args->print_dissections) {
1042 case print_dissections_none:
1043 case print_dissections_collapsed:
1044 SendMessage(cur_ctrl, CB_SETCURSEL, 0, 0);
1046 case print_dissections_as_displayed:
1047 SendMessage(cur_ctrl, CB_SETCURSEL, 1, 0);
1049 case print_dissections_expanded:
1050 SendMessage(cur_ctrl, CB_SETCURSEL, 2, 0);
1052 g_assert_not_reached();
1055 /* Set the "Packet bytes" box */
1056 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_PKT_BYTES_CB);
1057 SendMessage(cur_ctrl, BM_SETCHECK, args->print_hex, 0);
1059 /* Set the "Each packet on a new page" box */
1060 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_PKT_NEW_PAGE_CB);
1061 SendMessage(cur_ctrl, BM_SETCHECK, args->print_formfeed, 0);
1063 print_update_dynamic(dlg_hwnd, args);
1067 #define PREVIEW_STR_MAX 200
1069 /* If preview_file is NULL, disable the elements. If not, enable and
1070 * show the preview info. */
1072 preview_set_filename(HWND of_hwnd, gchar *preview_file) {
1075 gboolean enable = FALSE;
1077 const struct wtap_pkthdr *phdr;
1080 TCHAR string_buff[PREVIEW_STR_MAX];
1087 time_t time_preview;
1088 time_t time_current;
1089 double start_time = 0;
1090 double stop_time = 0;
1092 gboolean is_breaked = FALSE;
1094 if (preview_file != NULL && strlen(preview_file) > 0) {
1098 for (i = EWFD_PT_FILENAME; i <= EWFD_PTX_ELAPSED; i++) {
1099 cur_ctrl = GetDlgItem(of_hwnd, i);
1101 EnableWindow(cur_ctrl, enable);
1105 for (i = EWFD_PTX_FILENAME; i <= EWFD_PTX_ELAPSED; i++) {
1106 cur_ctrl = GetDlgItem(of_hwnd, i);
1108 SetWindowText(cur_ctrl, _T("-"));
1113 cur_ctrl = GetDlgItem(of_hwnd, EWFD_PTX_FILENAME);
1114 SetWindowText(cur_ctrl, utf_8to16(get_basename(preview_file)));
1116 cur_ctrl = GetDlgItem(of_hwnd, EWFD_PTX_FORMAT);
1117 wth = wtap_open_offline(preview_file, &err, &err_info, TRUE);
1118 if (cur_ctrl && wth == NULL) {
1119 if(err == WTAP_ERR_FILE_UNKNOWN_FORMAT) {
1120 SetWindowText(cur_ctrl, _T("unknown file format"));
1122 SetWindowText(cur_ctrl, _T("error opening file"));
1128 filesize = wtap_file_size(wth, &err);
1129 utf_8to16_snprintf(string_buff, PREVIEW_STR_MAX, "%" G_GINT64_FORMAT " bytes", filesize);
1130 cur_ctrl = GetDlgItem(of_hwnd, EWFD_PTX_SIZE);
1131 SetWindowText(cur_ctrl, string_buff);
1134 cur_ctrl = GetDlgItem(of_hwnd, EWFD_PTX_FORMAT);
1135 SetWindowText(cur_ctrl, utf_8to16(wtap_file_type_string(wtap_file_type(wth))));
1137 time(&time_preview);
1138 while ( (wtap_read(wth, &err, &err_info, &data_offset)) ) {
1139 phdr = wtap_phdr(wth);
1140 cur_time = nstime_to_sec( (const nstime_t *) &phdr->ts );
1142 start_time = cur_time;
1143 stop_time = cur_time;
1145 if (cur_time < start_time) {
1146 start_time = cur_time;
1148 if (cur_time > stop_time){
1149 stop_time = cur_time;
1152 if(packet%100 == 0) {
1153 time(&time_current);
1154 if(time_current-time_preview >= (time_t) prefs.gui_fileopen_preview) {
1162 _snwprintf(string_buff, PREVIEW_STR_MAX, _T("error after reading %u packets"), packet);
1163 cur_ctrl = GetDlgItem(of_hwnd, EWFD_PTX_PACKETS);
1164 SetWindowText(cur_ctrl, string_buff);
1171 _snwprintf(string_buff, PREVIEW_STR_MAX, _T("more than %u packets (preview timeout)"), packet);
1173 _snwprintf(string_buff, PREVIEW_STR_MAX, _T("%u"), packet);
1175 cur_ctrl = GetDlgItem(of_hwnd, EWFD_PTX_PACKETS);
1176 SetWindowText(cur_ctrl, string_buff);
1179 ti_time = (long)start_time;
1180 ti_tm = localtime( &ti_time );
1182 _snwprintf(string_buff, PREVIEW_STR_MAX,
1183 _T("%04d-%02d-%02d %02d:%02d:%02d"),
1184 ti_tm->tm_year + 1900,
1191 _snwprintf(string_buff, PREVIEW_STR_MAX, _T("?"));
1193 cur_ctrl = GetDlgItem(of_hwnd, EWFD_PTX_FIRST_PKT);
1194 SetWindowText(cur_ctrl, string_buff);
1197 elapsed_time = (unsigned int)(stop_time-start_time);
1198 if(elapsed_time/86400) {
1199 _snwprintf(string_buff, PREVIEW_STR_MAX, _T("%02u days %02u:%02u:%02u"),
1200 elapsed_time/86400, elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
1202 _snwprintf(string_buff, PREVIEW_STR_MAX, _T("%02u:%02u:%02u"),
1203 elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
1206 _snwprintf(string_buff, PREVIEW_STR_MAX, _T("unknown"));
1208 cur_ctrl = GetDlgItem(of_hwnd, EWFD_PTX_ELAPSED);
1209 SetWindowText(cur_ctrl, string_buff);
1220 filter_tb_get(HWND hwnd) {
1221 TCHAR *strval = NULL;
1225 /* If filter_text is non-NULL, use it. Otherwise, grab the text from
1227 len = GetWindowTextLength(hwnd);
1230 strval = g_malloc(len*sizeof(TCHAR));
1231 len = GetWindowText(hwnd, strval, len);
1232 ret = g_utf16_to_utf8(strval, -1, NULL, NULL, NULL);
1241 /* XXX - Copied from "filter-util.c" in the wireshark-win32 branch */
1242 /* XXX - The only reason for the "filter_text" parameter is to be able to feed
1243 * in the "real" filter string in the case of a CBN_SELCHANGE notification message.
1246 filter_tb_syntax_check(HWND hwnd, TCHAR *filter_text) {
1247 TCHAR *strval = NULL;
1251 /* If filter_text is non-NULL, use it. Otherwise, grab the text from
1254 len = (lstrlen(filter_text) + 1) * sizeof(TCHAR);
1255 strval = g_malloc(len);
1256 memcpy(strval, filter_text, len);
1258 len = GetWindowTextLength(hwnd);
1261 strval = g_malloc(len*sizeof(TCHAR));
1262 len = GetWindowText(hwnd, strval, len);
1267 /* Default window background */
1268 SendMessage(hwnd, EM_SETBKGNDCOLOR, (WPARAM) 1, COLOR_WINDOW);
1270 } else if (dfilter_compile(utf_16to8(strval), &dfp)) { /* colorize filter string entry */
1273 /* Valid (light green) */
1274 SendMessage(hwnd, EM_SETBKGNDCOLOR, 0, 0x00afffaf);
1276 /* Invalid (light red) */
1277 SendMessage(hwnd, EM_SETBKGNDCOLOR, 0, 0x00afafff);
1280 if (strval) g_free(strval);
1284 #if (_MSC_VER <= 1200)
1285 static UINT CALLBACK
1287 static UINT_PTR CALLBACK
1289 open_file_hook_proc(HWND of_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
1290 HWND cur_ctrl, parent;
1291 OFNOTIFY *notify = (OFNOTIFY *) l_param;
1292 TCHAR sel_name[MAX_PATH];
1296 /* Retain the filter text, and fill it in. */
1297 if(dfilter_str != NULL) {
1298 cur_ctrl = GetDlgItem(of_hwnd, EWFD_FILTER_EDIT);
1299 SetWindowText(cur_ctrl, utf_8to16(dfilter_str));
1302 /* Fill in our resolution values */
1303 cur_ctrl = GetDlgItem(of_hwnd, EWFD_MAC_NR_CB);
1304 SendMessage(cur_ctrl, BM_SETCHECK, gbl_resolv_flags & RESOLV_MAC, 0);
1305 cur_ctrl = GetDlgItem(of_hwnd, EWFD_NET_NR_CB);
1306 SendMessage(cur_ctrl, BM_SETCHECK, gbl_resolv_flags & RESOLV_NETWORK, 0);
1307 cur_ctrl = GetDlgItem(of_hwnd, EWFD_TRANS_NR_CB);
1308 SendMessage(cur_ctrl, BM_SETCHECK, gbl_resolv_flags & RESOLV_TRANSPORT, 0);
1310 preview_set_filename(of_hwnd, NULL);
1313 switch (notify->hdr.code) {
1315 /* Fetch the read filter */
1316 cur_ctrl = GetDlgItem(of_hwnd, EWFD_FILTER_EDIT);
1318 g_free(dfilter_str);
1319 dfilter_str = filter_tb_get(cur_ctrl);
1321 /* Fetch our resolution values */
1322 gbl_resolv_flags = prefs.name_resolve & RESOLV_CONCURRENT;
1323 cur_ctrl = GetDlgItem(of_hwnd, EWFD_MAC_NR_CB);
1324 if (SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
1325 gbl_resolv_flags |= RESOLV_MAC;
1326 cur_ctrl = GetDlgItem(of_hwnd, EWFD_NET_NR_CB);
1327 if (SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
1328 gbl_resolv_flags |= RESOLV_NETWORK;
1329 cur_ctrl = GetDlgItem(of_hwnd, EWFD_TRANS_NR_CB);
1330 if (SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
1331 gbl_resolv_flags |= RESOLV_TRANSPORT;
1334 /* This _almost_ works correctly. We need to handle directory
1336 parent = GetParent(of_hwnd);
1337 CommDlg_OpenSave_GetSpec(parent, sel_name, MAX_PATH);
1338 preview_set_filename(of_hwnd, utf_16to8(sel_name));
1341 topic_cb(NULL, HELP_OPEN_WIN32_DIALOG);
1348 cur_ctrl = (HWND) l_param;
1350 case (EN_UPDATE << 16) | EWFD_FILTER_EDIT:
1351 filter_tb_syntax_check(cur_ctrl, NULL);
1354 * If we ever figure out a way to integrate the Windows
1355 * and GTK+ event loops (or make a native filter dialog),
1356 * we can re-enable the "Filter" button.
1359 case EWFD_FILTER_BTN:
1372 /* XXX - Copied verbatim from gtk/capture_file_dlg.c. Perhaps it
1373 * should be in wiretap instead?
1377 can_save_with_wiretap(int ft)
1379 /* To save a file with Wiretap, Wiretap has to handle that format,
1380 and its code to handle that format must be able to write a file
1381 with this file's encapsulation type. */
1382 return wtap_dump_can_open(ft) && wtap_dump_can_write_encap(ft, cfile.lnk_t);
1385 /* Generate a list of the file types we can save this file as.
1387 "filetype" is the type it has now.
1389 "encap" is the encapsulation for its packets (which could be
1390 "unknown" or "per-packet").
1392 "filtered" is TRUE if we're to save only the packets that passed
1393 the display filter (in which case we have to save it using Wiretap)
1394 and FALSE if we're to save the entire file (in which case, if we're
1395 saving it in the type it has already, we can just copy it).
1397 The same applies for sel_curr, sel_all, sel_m_only, sel_m_range and sel_man_range
1401 file_type_from_list_index(gboolean save, int index) {
1405 /* Check all file types. */
1407 for (ft = 0; ft < WTAP_NUM_FILE_TYPES; ft++) {
1408 if (save && (!packet_range_process_all(&g_range) || ft != cfile.cd_t)) {
1409 /* not all unfiltered packets or a different file type. We have to use Wiretap. */
1410 if (!can_save_with_wiretap(ft))
1411 continue; /* We can't. */
1414 /* OK, we can write it out in this type. */
1415 if(wtap_file_type_string(ft) == NULL) {
1420 if(curr_index == index) {
1430 build_file_type_list(gboolean save, int *item_to_select) {
1433 GString* str = g_string_new("");
1435 GArray* sa = g_array_new(FALSE /*zero_terminated*/, FALSE /*clear_*/,2 /*element_size*/);
1439 /* Default to the first supported file type, if the file's current
1440 type isn't supported. */
1441 if(item_to_select) {
1443 *item_to_select = FILE_SAVE_DEFAULT;
1445 *item_to_select = FILE_OPEN_DEFAULT;
1449 /* append the "All Files" entry */
1451 str16 = utf_8to16("All Files (*.*)");
1452 sa = g_array_append_vals(sa, str16, (guint) strlen("All Files (*.*)"));
1453 sa = g_array_append_val(sa, zero);
1454 str16 = utf_8to16("*.*");
1455 sa = g_array_append_vals(sa, str16, (guint) strlen("*.*"));
1456 sa = g_array_append_val(sa, zero);
1459 /* Check all file types. */
1460 index = 1; /* the index is one based! */
1461 for (ft = 0; ft < WTAP_NUM_FILE_TYPES; ft++) {
1462 if (save && (!packet_range_process_all(&g_range) || ft != cfile.cd_t)) {
1463 /* not all unfiltered packets or a different file type. We have to use Wiretap. */
1464 if (!can_save_with_wiretap(ft))
1465 continue; /* We can't. */
1468 /* OK, we can write it out in this type. */
1469 if(wtap_file_type_string(ft) != NULL) {
1470 g_string_printf(str, "%s (%s)", wtap_file_type_string(ft), wtap_file_extensions_string(ft));
1474 str16 = utf_8to16(str->str);
1475 sa = g_array_append_vals(sa, str16, (guint) strlen(str->str));
1476 sa = g_array_append_val(sa, zero);
1478 g_string_printf(str, "%s", wtap_file_extensions_string(ft));
1479 str16 = utf_8to16(str->str);
1480 sa = g_array_append_vals(sa, str16, (guint) strlen(str->str));
1481 sa = g_array_append_val(sa, zero);
1483 if (ft == cfile.cd_t && item_to_select != NULL) {
1484 /* Default to the same format as the file, if it's supported. */
1485 *item_to_select = index;
1490 /* terminate the array */
1491 sa = g_array_append_val(sa, zero);
1493 return (TCHAR *) g_array_free(sa, FALSE /*free_segment*/);
1499 build_file_format_list(HWND sf_hwnd) {
1503 guint item_to_select;
1506 /* Default to the first supported file type, if the file's current
1507 type isn't supported. */
1510 format_cb = GetDlgItem(sf_hwnd, EWFD_FILE_TYPE_COMBO);
1511 SendMessage(format_cb, CB_RESETCONTENT, 0, 0);
1513 /* Check all file types. */
1515 for (ft = 0; ft < WTAP_NUM_FILE_TYPES; ft++) {
1516 if (!packet_range_process_all(&g_range) || ft != cfile.cd_t) {
1517 /* not all unfiltered packets or a different file type. We have to use Wiretap. */
1518 if (!can_save_with_wiretap(ft))
1519 continue; /* We can't. */
1522 /* OK, we can write it out in this type. */
1523 if(wtap_file_extensions_string(ft) != NULL) {
1524 s = g_strdup_printf("%s (%s)", wtap_file_type_string(ft), wtap_file_extensions_string(ft));
1526 s = g_strdup_printf("%s (*.*)", wtap_file_type_string(ft));
1528 SendMessage(format_cb, CB_ADDSTRING, 0, (LPARAM) utf_8to16(s));
1530 SendMessage(format_cb, CB_SETITEMDATA, (LPARAM) index, (WPARAM) ft);
1531 if (ft == filetype) {
1532 /* Default to the same format as the file, if it's supported. */
1533 item_to_select = index;
1538 SendMessage(format_cb, CB_SETCURSEL, (WPARAM) item_to_select, 0);
1542 #define RANGE_TEXT_MAX 128
1543 #if (_MSC_VER <= 1200)
1544 static UINT CALLBACK
1546 static UINT_PTR CALLBACK
1548 save_as_file_hook_proc(HWND sf_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
1550 OFNOTIFY *notify = (OFNOTIFY *) l_param;
1551 /*int new_filetype, index;*/
1555 g_sf_hwnd = sf_hwnd;
1557 /* Default to saving all packets, in the file's current format. */
1558 filetype = cfile.cd_t;
1560 /* init the packet range */
1561 packet_range_init(&g_range);
1563 /* Fill in the file format list */
1564 /*build_file_format_list(sf_hwnd);*/
1566 range_handle_wm_initdialog(sf_hwnd, &g_range);
1570 cur_ctrl = (HWND) l_param;
1574 case (CBN_SELCHANGE << 16) | EWFD_FILE_TYPE_COMBO:
1575 index = SendMessage(cur_ctrl, CB_GETCURSEL, 0, 0);
1576 if (index != CB_ERR) {
1577 new_filetype = SendMessage(cur_ctrl, CB_GETITEMDATA, (WPARAM) index, 0);
1578 if (new_filetype != CB_ERR) {
1579 if (filetype != new_filetype) {
1580 if (can_save_with_wiretap(new_filetype)) {
1581 cur_ctrl = GetDlgItem(sf_hwnd, EWFD_CAPTURED_BTN);
1582 EnableWindow(cur_ctrl, TRUE);
1583 cur_ctrl = GetDlgItem(sf_hwnd, EWFD_DISPLAYED_BTN);
1584 EnableWindow(cur_ctrl, TRUE);
1586 cur_ctrl = GetDlgItem(sf_hwnd, EWFD_CAPTURED_BTN);
1587 SendMessage(cur_ctrl, BM_SETCHECK, 0, 0);
1588 EnableWindow(cur_ctrl, FALSE);
1589 cur_ctrl = GetDlgItem(sf_hwnd, EWFD_DISPLAYED_BTN);
1590 EnableWindow(cur_ctrl, FALSE);
1592 filetype = new_filetype;
1599 range_handle_wm_command(sf_hwnd, cur_ctrl, w_param, &g_range);
1604 switch (notify->hdr.code) {
1606 topic_cb(NULL, HELP_SAVE_WIN32_DIALOG);
1610 TCHAR file_name16_selected[MAX_PATH];
1611 char *file_name8_selected;
1614 /* Check if trying to do 'save as' to the currently open file */
1615 parent = GetParent(sf_hwnd);
1616 selected_size = CommDlg_OpenSave_GetSpec(parent, file_name16_selected, MAX_PATH);
1617 if (selected_size > 0) {
1618 file_name8_selected = utf_16to8(file_name16_selected);
1619 if (files_identical(cfile.filename, file_name8_selected)) {
1620 /* XXX: Is MessageBox the best way to pop up an error ? How to make text bold ? */
1621 gchar *str = g_strdup_printf(
1622 "Capture File \"%s\" identical to loaded file !!\n\n"
1623 "Please choose a different filename.",
1624 file_name8_selected);
1625 MessageBox( parent, utf_8to16(str), _T("Error"), MB_ICONERROR | MB_APPLMODAL | MB_OK);
1627 SetWindowLongPtr(sf_hwnd, DWLP_MSGRESULT, 1L); /* Don't allow ! */
1644 #define STATIC_LABEL_CHARS 100
1645 /* For each range static control, fill in its value and enable/disable it. */
1647 range_update_dynamics(HWND dlg_hwnd, packet_range_t *range) {
1649 gboolean filtered_active = FALSE;
1650 TCHAR static_val[STATIC_LABEL_CHARS];
1652 guint32 ignored_cnt = 0, displayed_ignored_cnt = 0;
1654 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_DISPLAYED_BTN);
1655 if (SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
1656 filtered_active = TRUE;
1658 /* RANGE_SELECT_ALL */
1659 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_ALL_PKTS_CAP);
1660 EnableWindow(cur_ctrl, !filtered_active);
1661 if (range->remove_ignored) {
1662 _snwprintf(static_val, STATIC_LABEL_CHARS, _T("%u"), cfile.count - range->ignored_cnt);
1664 _snwprintf(static_val, STATIC_LABEL_CHARS, _T("%u"), cfile.count);
1666 SetWindowText(cur_ctrl, static_val);
1668 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_ALL_PKTS_DISP);
1669 EnableWindow(cur_ctrl, filtered_active);
1670 if (range->remove_ignored) {
1671 _snwprintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->displayed_cnt - range->displayed_ignored_cnt);
1673 _snwprintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->displayed_cnt);
1675 SetWindowText(cur_ctrl, static_val);
1677 /* RANGE_SELECT_CURR */
1678 selected_num = (cfile.current_frame) ? cfile.current_frame->num : 0;
1679 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_SEL_PKT_CAP);
1680 EnableWindow(cur_ctrl, selected_num && !filtered_active);
1681 if (range->remove_ignored && cfile.current_frame && cfile.current_frame->flags.ignored) {
1682 _snwprintf(static_val, STATIC_LABEL_CHARS, _T("0"));
1684 _snwprintf(static_val, STATIC_LABEL_CHARS, _T("%u"), selected_num ? 1 : 0);
1686 SetWindowText(cur_ctrl, static_val);
1688 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_SEL_PKT_DISP);
1689 EnableWindow(cur_ctrl, selected_num && filtered_active);
1690 if (range->remove_ignored && cfile.current_frame && cfile.current_frame->flags.ignored) {
1691 _snwprintf(static_val, STATIC_LABEL_CHARS, _T("0"));
1693 _snwprintf(static_val, STATIC_LABEL_CHARS, _T("%u"), selected_num ? 1 : 0);
1695 SetWindowText(cur_ctrl, static_val);
1697 /* RANGE_SELECT_MARKED */
1698 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_MARKED_BTN);
1699 EnableWindow(cur_ctrl, cfile.marked_count);
1701 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_MARKED_CAP);
1702 EnableWindow(cur_ctrl, cfile.marked_count && !filtered_active);
1703 if (range->remove_ignored) {
1704 _snwprintf(static_val, STATIC_LABEL_CHARS, _T("%u"), cfile.marked_count - range->ignored_marked_cnt);
1706 _snwprintf(static_val, STATIC_LABEL_CHARS, _T("%u"), cfile.marked_count);
1708 SetWindowText(cur_ctrl, static_val);
1710 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_MARKED_DISP);
1711 EnableWindow(cur_ctrl, cfile.marked_count && filtered_active);
1712 if (range->remove_ignored) {
1713 _snwprintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->displayed_marked_cnt - range->displayed_ignored_marked_cnt);
1715 _snwprintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->displayed_marked_cnt);
1717 SetWindowText(cur_ctrl, static_val);
1719 /* RANGE_SELECT_MARKED_RANGE */
1720 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_FIRST_LAST_BTN);
1721 EnableWindow(cur_ctrl, range->mark_range_cnt);
1723 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_FIRST_LAST_CAP);
1724 EnableWindow(cur_ctrl, range->mark_range_cnt && !filtered_active);
1725 if (range->remove_ignored) {
1726 _snwprintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->mark_range_cnt - range->ignored_mark_range_cnt);
1728 _snwprintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->mark_range_cnt);
1730 SetWindowText(cur_ctrl, static_val);
1732 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_FIRST_LAST_DISP);
1733 EnableWindow(cur_ctrl, range->displayed_mark_range_cnt && filtered_active);
1734 if (range->remove_ignored) {
1735 _snwprintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->displayed_mark_range_cnt - range->displayed_ignored_mark_range_cnt);
1737 _snwprintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->displayed_mark_range_cnt);
1739 SetWindowText(cur_ctrl, static_val);
1741 /* RANGE_SELECT_USER */
1742 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_CAP);
1743 EnableWindow(cur_ctrl, !filtered_active);
1744 if (range->remove_ignored) {
1745 _snwprintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->user_range_cnt - range->ignored_user_range_cnt);
1747 _snwprintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->user_range_cnt);
1749 SetWindowText(cur_ctrl, static_val);
1751 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_DISP);
1752 EnableWindow(cur_ctrl, filtered_active);
1753 if (range->remove_ignored) {
1754 _snwprintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->displayed_user_range_cnt - range->displayed_ignored_user_range_cnt);
1756 _snwprintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->displayed_user_range_cnt);
1758 SetWindowText(cur_ctrl, static_val);
1760 /* RANGE_REMOVE_IGNORED_PACKETS */
1761 switch(range->process) {
1762 case(range_process_all):
1763 ignored_cnt = range->ignored_cnt;
1764 displayed_ignored_cnt = range->displayed_ignored_cnt;
1766 case(range_process_selected):
1767 ignored_cnt = (cfile.current_frame && cfile.current_frame->flags.ignored) ? 1 : 0;
1768 displayed_ignored_cnt = ignored_cnt;
1770 case(range_process_marked):
1771 ignored_cnt = range->ignored_marked_cnt;
1772 displayed_ignored_cnt = range->displayed_ignored_marked_cnt;
1774 case(range_process_marked_range):
1775 ignored_cnt = range->ignored_mark_range_cnt;
1776 displayed_ignored_cnt = range->displayed_ignored_mark_range_cnt;
1778 case(range_process_user_range):
1779 ignored_cnt = range->ignored_user_range_cnt;
1780 displayed_ignored_cnt = range->displayed_ignored_user_range_cnt;
1783 g_assert_not_reached();
1786 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_REMOVE_IGN_CB);
1787 EnableWindow(cur_ctrl, ignored_cnt);
1789 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_IGNORED_CAP);
1790 EnableWindow(cur_ctrl, ignored_cnt && !filtered_active);
1791 _snwprintf(static_val, STATIC_LABEL_CHARS, _T("%u"), ignored_cnt);
1792 SetWindowText(cur_ctrl, static_val);
1794 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_IGNORED_DISP);
1795 EnableWindow(cur_ctrl, displayed_ignored_cnt && filtered_active);
1796 _snwprintf(static_val, STATIC_LABEL_CHARS, _T("%u"), displayed_ignored_cnt);
1797 SetWindowText(cur_ctrl, static_val);
1801 range_handle_wm_initdialog(HWND dlg_hwnd, packet_range_t *range) {
1804 /* Set the appropriate captured/displayed radio */
1805 if (range->process_filtered)
1806 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_DISPLAYED_BTN);
1808 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_CAPTURED_BTN);
1809 SendMessage(cur_ctrl, BM_SETCHECK, TRUE, 0);
1811 /* dynamic values in the range frame */
1812 range_update_dynamics(dlg_hwnd, range);
1814 /* Set the appropriate range radio */
1815 switch(range->process) {
1816 case(range_process_all):
1817 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_ALL_PKTS_BTN);
1819 case(range_process_selected):
1820 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_SEL_PKT_BTN);
1822 case(range_process_marked):
1823 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_MARKED_BTN);
1825 case(range_process_marked_range):
1826 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_FIRST_LAST_BTN);
1828 case(range_process_user_range):
1829 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_BTN);
1832 g_assert_not_reached();
1834 SendMessage(cur_ctrl, BM_SETCHECK, TRUE, 0);
1838 range_handle_wm_command(HWND dlg_hwnd, HWND ctrl, WPARAM w_param, packet_range_t *range) {
1840 TCHAR range_text[RANGE_TEXT_MAX];
1843 case (BN_CLICKED << 16) | EWFD_CAPTURED_BTN:
1844 case (BN_CLICKED << 16) | EWFD_DISPLAYED_BTN:
1845 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_CAPTURED_BTN);
1846 if (SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
1847 range->process_filtered = FALSE;
1849 range->process_filtered = TRUE;
1850 range_update_dynamics(dlg_hwnd, range);
1852 case (BN_CLICKED << 16) | EWFD_ALL_PKTS_BTN:
1853 if (SendMessage(ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED) {
1854 range->process = range_process_all;
1855 range_update_dynamics(dlg_hwnd, range);
1858 case (BN_CLICKED << 16) | EWFD_SEL_PKT_BTN:
1859 if (SendMessage(ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED) {
1860 range->process = range_process_selected;
1861 range_update_dynamics(dlg_hwnd, range);
1864 case (BN_CLICKED << 16) | EWFD_MARKED_BTN:
1865 if (SendMessage(ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED) {
1866 range->process = range_process_marked;
1867 range_update_dynamics(dlg_hwnd, range);
1870 case (BN_CLICKED << 16) | EWFD_FIRST_LAST_BTN:
1871 if (SendMessage(ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED) {
1872 range->process = range_process_marked_range;
1873 range_update_dynamics(dlg_hwnd, range);
1876 case (BN_CLICKED << 16) | EWFD_RANGE_BTN:
1877 if (SendMessage(ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED) {
1878 range->process = range_process_user_range;
1879 range_update_dynamics(dlg_hwnd, range);
1880 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_EDIT);
1884 case (EN_SETFOCUS << 16) | EWFD_RANGE_EDIT:
1885 cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_BTN);
1886 SendMessage(cur_ctrl, BM_CLICK, 0, 0);
1888 case (EN_CHANGE << 16) | EWFD_RANGE_EDIT:
1889 SendMessage(ctrl, WM_GETTEXT, (WPARAM) RANGE_TEXT_MAX, (LPARAM) range_text);
1890 packet_range_convert_str(range, utf_16to8(range_text));
1891 range_update_dynamics(dlg_hwnd, range);
1893 case (BN_CLICKED << 16) | EWFD_REMOVE_IGN_CB:
1894 if (SendMessage(ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED) {
1895 range->remove_ignored = TRUE;
1897 range->remove_ignored = FALSE;
1899 range_update_dynamics(dlg_hwnd, range);
1904 #if (_MSC_VER <= 1200)
1905 static UINT CALLBACK
1907 static UINT_PTR CALLBACK
1909 merge_file_hook_proc(HWND mf_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
1910 HWND cur_ctrl, parent;
1911 OFNOTIFY *notify = (OFNOTIFY *) l_param;
1912 TCHAR sel_name[MAX_PATH];
1916 /* Retain the filter text, and fill it in. */
1917 if(dfilter_str != NULL) {
1918 cur_ctrl = GetDlgItem(mf_hwnd, EWFD_FILTER_EDIT);
1919 SetWindowText(cur_ctrl, utf_8to16(dfilter_str));
1922 /* Append by default */
1923 cur_ctrl = GetDlgItem(mf_hwnd, EWFD_MERGE_PREPEND_BTN);
1924 SendMessage(cur_ctrl, BM_SETCHECK, TRUE, 0);
1925 merge_action = merge_append;
1927 preview_set_filename(mf_hwnd, NULL);
1930 switch (notify->hdr.code) {
1932 /* Fetch the read filter */
1933 cur_ctrl = GetDlgItem(mf_hwnd, EWFD_FILTER_EDIT);
1935 g_free(dfilter_str);
1936 dfilter_str = filter_tb_get(cur_ctrl);
1938 cur_ctrl = GetDlgItem(mf_hwnd, EWFD_MERGE_CHRONO_BTN);
1939 if(SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED) {
1940 merge_action = merge_chrono;
1942 cur_ctrl = GetDlgItem(mf_hwnd, EWFD_MERGE_PREPEND_BTN);
1943 if(SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED) {
1944 merge_action = merge_prepend;
1950 /* This _almost_ works correctly. We need to handle directory
1952 parent = GetParent(mf_hwnd);
1953 CommDlg_OpenSave_GetSpec(parent, sel_name, MAX_PATH);
1954 preview_set_filename(mf_hwnd, utf_16to8(sel_name));
1957 topic_cb(NULL, HELP_MERGE_WIN32_DIALOG);
1964 cur_ctrl = (HWND) l_param;
1966 case (EN_UPDATE << 16) | EWFD_FILTER_EDIT:
1967 filter_tb_syntax_check(cur_ctrl, NULL);
1980 #if (_MSC_VER <= 1200)
1981 static UINT CALLBACK
1983 static UINT_PTR CALLBACK
1985 export_file_hook_proc(HWND ef_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
1987 OFNOTIFY *notify = (OFNOTIFY *) l_param;
1988 gboolean pkt_fmt_enable;
1993 /* init the printing range */
1994 packet_range_init(&print_args.range);
1995 range_handle_wm_initdialog(ef_hwnd, &print_args.range);
1996 format_handle_wm_initdialog(ef_hwnd, &print_args);
2000 cur_ctrl = (HWND) l_param;
2002 case (CBN_SELCHANGE << 16) | EWFD_PKT_DETAIL_COMBO:
2004 range_handle_wm_command(ef_hwnd, cur_ctrl, w_param, &print_args.range);
2005 print_update_dynamic(ef_hwnd, &print_args);
2010 switch (notify->hdr.code) {
2013 case CDN_TYPECHANGE:
2014 index = notify->lpOFN->nFilterIndex;
2016 if (index == 2) /* PostScript */
2017 print_args.format = PR_FMT_TEXT;
2019 print_args.format = PR_FMT_PS;
2020 if (index == 3 || index == 4 || index == 5 || index == 6)
2021 pkt_fmt_enable = FALSE;
2023 pkt_fmt_enable = TRUE;
2024 for (i = EWFD_PKT_FORMAT_GB; i <= EWFD_PKT_NEW_PAGE_CB; i++) {
2025 cur_ctrl = GetDlgItem(ef_hwnd, i);
2026 EnableWindow(cur_ctrl, pkt_fmt_enable);
2030 topic_cb(NULL, HELP_EXPORT_FILE_WIN32_DIALOG);
2042 #if (_MSC_VER <= 1200)
2043 static UINT CALLBACK
2045 static UINT_PTR CALLBACK
2047 export_raw_file_hook_proc(HWND ef_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
2049 OPENFILENAME *ofnp = (OPENFILENAME *) l_param;
2050 TCHAR raw_msg[STATIC_LABEL_CHARS];
2051 OFNOTIFY *notify = (OFNOTIFY *) l_param;
2055 _snwprintf(raw_msg, STATIC_LABEL_CHARS, _T("%d byte%s of raw binary data will be written"),
2056 ofnp->lCustData, utf_8to16(plurality(ofnp->lCustData, "", "s")));
2057 cur_ctrl = GetDlgItem(ef_hwnd, EWFD_EXPORTRAW_ST);
2058 SetWindowText(cur_ctrl, raw_msg);
2061 switch (notify->hdr.code) {
2063 topic_cb(NULL, HELP_EXPORT_BYTES_WIN32_DIALOG);
2074 #if (_MSC_VER <= 1200)
2075 static UINT CALLBACK
2077 static UINT_PTR CALLBACK
2079 export_sslkeys_file_hook_proc(HWND ef_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
2081 OPENFILENAME *ofnp = (OPENFILENAME *) l_param;
2082 TCHAR sslkeys_msg[STATIC_LABEL_CHARS];
2083 OFNOTIFY *notify = (OFNOTIFY *) l_param;
2087 _snwprintf(sslkeys_msg, STATIC_LABEL_CHARS, _T("%d SSL Session Key%s will be written"),
2088 ofnp->lCustData, utf_8to16(plurality(ofnp->lCustData, "", "s")));
2089 cur_ctrl = GetDlgItem(ef_hwnd, EWFD_EXPORTSSLKEYS_ST);
2090 SetWindowText(cur_ctrl, sslkeys_msg);
2093 switch (notify->hdr.code) {
2095 topic_cb(NULL, HELP_EXPORT_BYTES_WIN32_DIALOG);
2112 * indent-tabs-mode: nil
2115 * ex: set shiftwidth=4 tabstop=8 expandtab
2116 * :indentSize=4:tabSize=8:noTabs=true: