2016-07-17 02:29:35 +00:00
|
|
|
/* file_dlg_win32.c
|
2006-02-13 21:25:43 +00:00
|
|
|
* Native Windows file dialog routines
|
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2006-02-13 21:25:43 +00:00
|
|
|
* Copyright 2004 Gerald Combs
|
|
|
|
*
|
2018-02-07 11:26:45 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2006-02-13 21:25:43 +00:00
|
|
|
*/
|
|
|
|
|
2020-12-11 21:38:14 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
2012-09-20 01:48:30 +00:00
|
|
|
#include "config.h"
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2006-03-08 20:55:32 +00:00
|
|
|
#include <tchar.h>
|
2006-02-13 21:25:43 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2021-07-05 17:16:52 +00:00
|
|
|
#include <string>
|
|
|
|
|
2008-10-24 00:42:09 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <commdlg.h>
|
|
|
|
#include <richedit.h>
|
2012-07-16 20:46:13 +00:00
|
|
|
#include <strsafe.h>
|
2008-10-24 00:42:09 +00:00
|
|
|
|
2019-12-09 18:19:01 +00:00
|
|
|
#include "file.h"
|
2008-04-13 03:32:24 +00:00
|
|
|
|
2013-07-16 02:35:33 +00:00
|
|
|
#include "wsutil/file_util.h"
|
2015-11-04 09:17:18 +00:00
|
|
|
#include "wsutil/str_util.h"
|
2013-07-16 02:35:33 +00:00
|
|
|
#include "wsutil/unicode-utils.h"
|
2021-06-18 18:21:42 +00:00
|
|
|
#include <wsutil/ws_assert.h>
|
2013-07-16 02:35:33 +00:00
|
|
|
|
2013-11-17 02:55:14 +00:00
|
|
|
#include "wsutil/filesystem.h"
|
2006-02-13 21:25:43 +00:00
|
|
|
#include "epan/prefs.h"
|
|
|
|
|
2012-10-09 23:51:30 +00:00
|
|
|
#include "ui/alert_box.h"
|
2012-10-16 19:47:43 +00:00
|
|
|
#include "ui/help_url.h"
|
2012-01-18 20:55:55 +00:00
|
|
|
#include "ui/last_open_dir.h"
|
2012-10-09 23:51:30 +00:00
|
|
|
#include "ui/simple_dialog.h"
|
|
|
|
#include "ui/util.h"
|
2017-10-14 20:14:14 +00:00
|
|
|
#include "ui/ws_ui_util.h"
|
2016-02-29 21:29:19 +00:00
|
|
|
#include "ui/all_files_wildcard.h"
|
2012-01-18 20:55:55 +00:00
|
|
|
|
2012-01-16 02:17:03 +00:00
|
|
|
#include "file_dlg_win32.h"
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2018-02-09 20:42:32 +00:00
|
|
|
typedef enum {
|
|
|
|
merge_append,
|
|
|
|
merge_chrono,
|
|
|
|
merge_prepend
|
|
|
|
} merge_action_e;
|
|
|
|
|
2006-06-23 18:29:48 +00:00
|
|
|
#define FILE_OPEN_DEFAULT 1 /* All Files */
|
2006-03-08 20:55:32 +00:00
|
|
|
|
|
|
|
#define FILE_MERGE_DEFAULT FILE_OPEN_DEFAULT
|
|
|
|
|
|
|
|
#define FILE_TYPES_EXPORT \
|
2009-01-19 22:37:14 +00:00
|
|
|
_T("Plain text (*.txt)\0") _T("*.txt\0") \
|
|
|
|
_T("PostScript (*.ps)\0") _T("*.ps\0") \
|
|
|
|
_T("CSV (Comma Separated Values summary) (*.csv)\0") _T("*.csv\0") \
|
|
|
|
_T("PSML (XML packet summary) (*.psml)\0") _T("*.psml\0") \
|
|
|
|
_T("PDML (XML packet detail) (*.pdml)\0") _T("*.pdml\0") \
|
2016-06-19 14:52:50 +00:00
|
|
|
_T("C Arrays (packet bytes) (*.c)\0") _T("*.c\0") \
|
|
|
|
_T("JSON (*.json)\0") _T("*.json\0")
|
2006-03-08 20:55:32 +00:00
|
|
|
|
2021-11-28 11:43:27 +00:00
|
|
|
static const TCHAR *FILE_EXT_EXPORT[] =
|
2018-06-27 18:28:49 +00:00
|
|
|
{
|
|
|
|
_T(""), /* export type starts at 1 */
|
|
|
|
_T("txt"),
|
|
|
|
_T("ps"),
|
|
|
|
_T("csv"),
|
|
|
|
_T("psml"),
|
|
|
|
_T("pdml"),
|
|
|
|
_T("c"),
|
|
|
|
_T("json")
|
|
|
|
};
|
|
|
|
|
2012-10-05 18:52:42 +00:00
|
|
|
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);
|
2006-02-13 21:25:43 +00:00
|
|
|
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);
|
|
|
|
|
2012-01-24 05:55:00 +00:00
|
|
|
static TCHAR *build_file_open_type_list(void);
|
2013-04-01 20:36:42 +00:00
|
|
|
static TCHAR *build_file_save_type_list(GArray *savable_file_types);
|
2006-06-23 18:29:48 +00:00
|
|
|
|
2018-05-09 18:46:56 +00:00
|
|
|
#ifdef DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
|
|
|
|
typedef DPI_AWARENESS_CONTEXT (WINAPI *GetThreadDpiAwarenessContextProc)(void);
|
|
|
|
typedef DPI_AWARENESS_CONTEXT (WINAPI *SetThreadDpiAwarenessContextProc)(DPI_AWARENESS_CONTEXT);
|
|
|
|
|
|
|
|
static GetThreadDpiAwarenessContextProc GetThreadDpiAwarenessContextP;
|
|
|
|
static SetThreadDpiAwarenessContextProc SetThreadDpiAwarenessContextP;
|
|
|
|
static gboolean got_proc_addresses = FALSE;
|
|
|
|
|
|
|
|
static gboolean get_proc_addresses(void) {
|
|
|
|
if (got_proc_addresses) return TRUE;
|
|
|
|
|
|
|
|
HMODULE u32_module = LoadLibrary(_T("User32.dll"));
|
|
|
|
if (!u32_module) {
|
|
|
|
got_proc_addresses = FALSE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
gboolean got_all = TRUE;
|
|
|
|
GetThreadDpiAwarenessContextP = (GetThreadDpiAwarenessContextProc) GetProcAddress(u32_module, "GetThreadDpiAwarenessContext");
|
|
|
|
if (!GetThreadDpiAwarenessContextP) got_all = FALSE;
|
|
|
|
SetThreadDpiAwarenessContextP = (SetThreadDpiAwarenessContextProc) GetProcAddress(u32_module, "SetThreadDpiAwarenessContext");
|
|
|
|
if (!SetThreadDpiAwarenessContextP) got_all = FALSE;
|
|
|
|
|
|
|
|
got_proc_addresses = got_all;
|
|
|
|
return got_all;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enabling DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 causes issues
|
|
|
|
// when dragging our open file dialog between differently-DPIed
|
|
|
|
// displays. It might be time to break down and switch to common
|
|
|
|
// item dialogs.
|
|
|
|
HANDLE set_thread_per_monitor_v2_awareness(void) {
|
|
|
|
if (! get_proc_addresses()) return 0;
|
|
|
|
#if 0
|
|
|
|
WCHAR info[100];
|
|
|
|
StringCchPrintf(info, 100,
|
|
|
|
L"GetThrDpiAwarenessCtx: %d",
|
|
|
|
GetThreadDpiAwarenessContextP());
|
|
|
|
MessageBox(NULL, info, _T("DPI info"), MB_OK);
|
|
|
|
#endif
|
|
|
|
return (HANDLE) SetThreadDpiAwarenessContextP(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void revert_thread_per_monitor_v2_awareness(HANDLE context) {
|
2018-05-17 21:21:54 +00:00
|
|
|
if (! get_proc_addresses()) return;
|
2018-05-09 18:46:56 +00:00
|
|
|
SetThreadDpiAwarenessContextP((DPI_AWARENESS_CONTEXT) context);
|
|
|
|
}
|
|
|
|
#else // DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
|
|
|
|
HANDLE set_thread_per_monitor_v2_awareness(void) { return 0; }
|
|
|
|
void revert_thread_per_monitor_v2_awareness(HANDLE context _U_) { }
|
|
|
|
#endif // DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
|
|
|
|
|
2012-10-03 19:24:14 +00:00
|
|
|
static int g_filetype;
|
|
|
|
static gboolean g_compressed;
|
|
|
|
static packet_range_t *g_range;
|
2013-10-11 17:20:50 +00:00
|
|
|
static capture_file *g_cf;
|
2012-10-03 19:24:14 +00:00
|
|
|
static merge_action_e g_merge_action;
|
|
|
|
static print_args_t print_args;
|
2006-02-13 21:25:43 +00:00
|
|
|
/* XXX - The reason g_sf_hwnd exists is so that we can call
|
2006-02-15 22:29:15 +00:00
|
|
|
* range_update_dynamics() from anywhere; it's currently
|
|
|
|
* static, but if we move to using the native Windows
|
|
|
|
* print dialog and put range widgets in it as well,
|
|
|
|
* it might be moved to a separate file.
|
|
|
|
*
|
|
|
|
* However, the save file dialog hogs the foreground, so
|
|
|
|
* this may not be necessary (and, in fact, the file dialogs
|
|
|
|
* should arguably be modal to the window for the file
|
2008-06-03 23:57:26 +00:00
|
|
|
* being opened/saved/etc.).
|
2006-02-13 21:25:43 +00:00
|
|
|
*/
|
2012-07-16 20:46:13 +00:00
|
|
|
static HWND g_sf_hwnd = NULL;
|
2012-09-10 21:27:49 +00:00
|
|
|
static char *g_dfilter_str = NULL;
|
2014-02-26 15:27:20 +00:00
|
|
|
static unsigned int g_format_type = WTAP_TYPE_AUTO;
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2011-08-29 16:45:48 +00:00
|
|
|
/*
|
2019-07-27 22:53:22 +00:00
|
|
|
* According to https://docs.microsoft.com/en-us/windows/win32/shell/common-file-dialog
|
2011-08-29 16:45:48 +00:00
|
|
|
* we should use IFileOpenDialog and IFileSaveDialog on Windows Vista
|
|
|
|
* and later.
|
|
|
|
*/
|
|
|
|
|
2006-02-13 21:25:43 +00:00
|
|
|
gboolean
|
2019-12-09 23:18:06 +00:00
|
|
|
win32_open_file (HWND h_wnd, const wchar_t *title, GString *file_name, unsigned int *type, GString *display_filter) {
|
2007-01-14 05:18:07 +00:00
|
|
|
OPENFILENAME *ofn;
|
2012-09-24 17:04:50 +00:00
|
|
|
TCHAR file_name16[MAX_PATH] = _T("");
|
2018-06-15 17:52:53 +00:00
|
|
|
int ofnsize = sizeof(OPENFILENAME);
|
2018-05-09 18:46:56 +00:00
|
|
|
BOOL gofn_ok;
|
2007-01-14 05:18:07 +00:00
|
|
|
|
2012-07-16 20:46:13 +00:00
|
|
|
if (!file_name || !display_filter)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (file_name->len > 0) {
|
2012-09-24 17:04:50 +00:00
|
|
|
StringCchCopy(file_name16, MAX_PATH, utf_8to16(file_name->str));
|
2012-07-16 20:46:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (display_filter->len > 0) {
|
2012-09-10 21:27:49 +00:00
|
|
|
g_dfilter_str = g_strdup(display_filter->str);
|
|
|
|
} else if (g_dfilter_str) {
|
|
|
|
g_free(g_dfilter_str);
|
|
|
|
g_dfilter_str = NULL;
|
2012-07-16 20:46:13 +00:00
|
|
|
}
|
2018-06-15 17:52:53 +00:00
|
|
|
|
2021-07-01 17:06:02 +00:00
|
|
|
ofn = new OPENFILENAME();
|
2007-01-14 05:18:07 +00:00
|
|
|
|
|
|
|
ofn->lStructSize = ofnsize;
|
|
|
|
ofn->hwndOwner = h_wnd;
|
2009-04-15 23:23:21 +00:00
|
|
|
ofn->hInstance = (HINSTANCE) GetWindowLongPtr(h_wnd, GWLP_HINSTANCE);
|
2012-01-24 05:55:00 +00:00
|
|
|
ofn->lpstrFilter = build_file_open_type_list();
|
2007-01-14 05:18:07 +00:00
|
|
|
ofn->lpstrCustomFilter = NULL;
|
|
|
|
ofn->nMaxCustFilter = 0;
|
|
|
|
ofn->nFilterIndex = FILE_OPEN_DEFAULT;
|
2012-09-24 17:04:50 +00:00
|
|
|
ofn->lpstrFile = file_name16;
|
2007-01-14 05:18:07 +00:00
|
|
|
ofn->nMaxFile = MAX_PATH;
|
|
|
|
ofn->lpstrFileTitle = NULL;
|
|
|
|
ofn->nMaxFileTitle = 0;
|
2006-02-13 21:25:43 +00:00
|
|
|
if (prefs.gui_fileopen_style == FO_STYLE_SPECIFIED && prefs.gui_fileopen_dir[0] != '\0') {
|
2009-01-19 22:37:14 +00:00
|
|
|
ofn->lpstrInitialDir = utf_8to16(prefs.gui_fileopen_dir);
|
2006-02-13 21:25:43 +00:00
|
|
|
} else {
|
2009-01-19 22:37:14 +00:00
|
|
|
ofn->lpstrInitialDir = utf_8to16(get_last_open_dir());
|
2006-02-13 21:25:43 +00:00
|
|
|
}
|
2019-12-09 23:18:06 +00:00
|
|
|
ofn->lpstrTitle = title;
|
2009-01-19 22:37:14 +00:00
|
|
|
ofn->Flags = OFN_ENABLESIZING | OFN_ENABLETEMPLATE | OFN_EXPLORER |
|
|
|
|
OFN_NOCHANGEDIR | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY |
|
|
|
|
OFN_ENABLEHOOK | OFN_SHOWHELP;
|
2007-01-14 05:18:07 +00:00
|
|
|
ofn->lpstrDefExt = NULL;
|
|
|
|
ofn->lpfnHook = open_file_hook_proc;
|
|
|
|
ofn->lpTemplateName = _T("WIRESHARK_OPENFILENAME_TEMPLATE");
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2018-05-09 18:46:56 +00:00
|
|
|
HANDLE save_da_ctx = set_thread_per_monitor_v2_awareness();
|
2012-07-16 20:46:13 +00:00
|
|
|
gofn_ok = GetOpenFileName(ofn);
|
2018-05-09 18:46:56 +00:00
|
|
|
revert_thread_per_monitor_v2_awareness(save_da_ctx);
|
2006-08-30 20:45:13 +00:00
|
|
|
|
2012-07-16 20:46:13 +00:00
|
|
|
if (gofn_ok) {
|
2012-09-24 17:04:50 +00:00
|
|
|
g_string_printf(file_name, "%s", utf_16to8(file_name16));
|
2012-09-10 21:27:49 +00:00
|
|
|
g_string_printf(display_filter, "%s", g_dfilter_str ? g_dfilter_str : "");
|
2014-02-26 15:27:20 +00:00
|
|
|
*type = g_format_type;
|
2009-01-19 22:37:14 +00:00
|
|
|
}
|
2012-07-16 20:46:13 +00:00
|
|
|
|
|
|
|
g_free( (void *) ofn->lpstrFilter);
|
2021-07-01 17:06:02 +00:00
|
|
|
delete ofn;
|
2012-09-10 21:27:49 +00:00
|
|
|
g_free(g_dfilter_str);
|
|
|
|
g_dfilter_str = NULL;
|
2012-07-16 20:46:13 +00:00
|
|
|
return gofn_ok;
|
2006-02-13 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2012-06-23 08:18:14 +00:00
|
|
|
gboolean
|
2019-12-09 23:18:06 +00:00
|
|
|
win32_save_as_file(HWND h_wnd, const wchar_t *title, capture_file *cf, GString *file_name, int *file_type,
|
2018-11-16 04:06:36 +00:00
|
|
|
wtap_compression_type *compression_type,
|
|
|
|
gboolean must_support_all_comments)
|
2012-05-25 21:25:55 +00:00
|
|
|
{
|
2013-04-01 20:36:42 +00:00
|
|
|
guint32 required_comment_types;
|
2012-01-24 05:55:00 +00:00
|
|
|
GArray *savable_file_types;
|
2007-01-14 05:18:07 +00:00
|
|
|
OPENFILENAME *ofn;
|
2006-06-23 18:29:48 +00:00
|
|
|
TCHAR file_name16[MAX_PATH] = _T("");
|
2018-06-15 17:52:53 +00:00
|
|
|
int ofnsize = sizeof(OPENFILENAME);
|
2018-05-09 18:46:56 +00:00
|
|
|
BOOL gsfn_ok;
|
2007-01-14 05:18:07 +00:00
|
|
|
|
2018-11-16 04:06:36 +00:00
|
|
|
if (!file_name || !file_type || !compression_type)
|
2012-09-24 17:04:50 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (file_name->len > 0) {
|
|
|
|
StringCchCopy(file_name16, MAX_PATH, utf_8to16(file_name->str));
|
|
|
|
}
|
|
|
|
|
2013-04-01 20:36:42 +00:00
|
|
|
/* What types of comments do we have to support? */
|
|
|
|
if (must_support_all_comments)
|
|
|
|
required_comment_types = cf_comment_types(cf); /* all the ones the file has */
|
|
|
|
else
|
|
|
|
required_comment_types = 0; /* none of them */
|
|
|
|
|
wiretap: more work on file type/subtypes.
Provide a wiretap routine to get an array of all savable file
type/subtypes, sorted with pcap and pcapng at the top, followed by the
other types, sorted either by the name or the description.
Use that routine to list options for the -F flag for various commands
Rename wtap_get_savable_file_types_subtypes() to
wtap_get_savable_file_types_subtypes_for_file(), to indicate that it
provides an array of all file type/subtypes in which a given file can be
saved. Have it sort all types, other than the default type/subtype and,
if there is one, the "other" type (both of which are put at the top), by
the name or the description.
Don't allow wtap_register_file_type_subtypes() to override any existing
registrations; have them always register a new type. In that routine,
if there are any emply slots in the table, due to an entry being
unregistered, use it rather than allocating a new slot.
Don't allow unregistration of built-in types.
Rename the "dump open table" to the "file type/subtype table", as it has
entries for all types/subtypes, even if we can't write them.
Initialize that table in a routine that pre-allocates the GArray before
filling it with built-in types/subtypes, so it doesn't keep getting
reallocated.
Get rid of wtap_num_file_types_subtypes - it's just a copy of the size
of the GArray.
Don't have wtap_file_type_subtype_description() crash if handed an
file type/subtype that isn't a valid array index - just return NULL, as
we do with wtap_file_type_subtype_name().
In wtap_name_to_file_type_subtype(), don't use WTAP_FILE_TYPE_SUBTYPE_
names for the backwards-compatibility names - map those names to the
current names, and then look them up. This reduces the number of
uses of hardwired WTAP_FILE_TYPE_SUBTYPE_ values.
Clean up the type of wtap_module_count - it has no need to be a gulong.
Have built-in wiretap file handlers register names to be used for their
file type/subtypes, rather than building the table in init.lua.
Add a new Lua C function get_wtap_filetypes() to construct the
wtap_filetypes table, based on the registered names, and use it in
init.lua.
Add a #define WSLUA_INTERNAL_FUNCTION to register functions intended
only for internal use in init.lua, so they can be made available from
Lua without being documented.
Get rid of WTAP_NUM_FILE_TYPES_SUBTYPES - most code has no need to use
it, as it can just request arrays of types, and the space of
type/subtype codes can be sparse due to registration in any case, so
code has to be careful using it.
wtap_get_num_file_types_subtypes() is no longer used, so remove it. It
returns the number of elements in the file type/subtype array, which is
not necessarily the name of known file type/subtypes, as there may have
been some deregistered types, and those types do *not* get removed from
the array, they just get cleared so that they're available for future
allocation (we don't want the indices of any registered types to changes
if another type is deregistered, as those indicates are the type/subtype
values, so we can't shrink the array).
Clean up white space and remove some comments that shouldn't have been
added.
2021-02-17 06:24:47 +00:00
|
|
|
savable_file_types = wtap_get_savable_file_types_subtypes_for_file(cf->cd_t,
|
2013-11-08 19:38:28 +00:00
|
|
|
cf->linktypes,
|
wiretap: more work on file type/subtypes.
Provide a wiretap routine to get an array of all savable file
type/subtypes, sorted with pcap and pcapng at the top, followed by the
other types, sorted either by the name or the description.
Use that routine to list options for the -F flag for various commands
Rename wtap_get_savable_file_types_subtypes() to
wtap_get_savable_file_types_subtypes_for_file(), to indicate that it
provides an array of all file type/subtypes in which a given file can be
saved. Have it sort all types, other than the default type/subtype and,
if there is one, the "other" type (both of which are put at the top), by
the name or the description.
Don't allow wtap_register_file_type_subtypes() to override any existing
registrations; have them always register a new type. In that routine,
if there are any emply slots in the table, due to an entry being
unregistered, use it rather than allocating a new slot.
Don't allow unregistration of built-in types.
Rename the "dump open table" to the "file type/subtype table", as it has
entries for all types/subtypes, even if we can't write them.
Initialize that table in a routine that pre-allocates the GArray before
filling it with built-in types/subtypes, so it doesn't keep getting
reallocated.
Get rid of wtap_num_file_types_subtypes - it's just a copy of the size
of the GArray.
Don't have wtap_file_type_subtype_description() crash if handed an
file type/subtype that isn't a valid array index - just return NULL, as
we do with wtap_file_type_subtype_name().
In wtap_name_to_file_type_subtype(), don't use WTAP_FILE_TYPE_SUBTYPE_
names for the backwards-compatibility names - map those names to the
current names, and then look them up. This reduces the number of
uses of hardwired WTAP_FILE_TYPE_SUBTYPE_ values.
Clean up the type of wtap_module_count - it has no need to be a gulong.
Have built-in wiretap file handlers register names to be used for their
file type/subtypes, rather than building the table in init.lua.
Add a new Lua C function get_wtap_filetypes() to construct the
wtap_filetypes table, based on the registered names, and use it in
init.lua.
Add a #define WSLUA_INTERNAL_FUNCTION to register functions intended
only for internal use in init.lua, so they can be made available from
Lua without being documented.
Get rid of WTAP_NUM_FILE_TYPES_SUBTYPES - most code has no need to use
it, as it can just request arrays of types, and the space of
type/subtype codes can be sparse due to registration in any case, so
code has to be careful using it.
wtap_get_num_file_types_subtypes() is no longer used, so remove it. It
returns the number of elements in the file type/subtype array, which is
not necessarily the name of known file type/subtypes, as there may have
been some deregistered types, and those types do *not* get removed from
the array, they just get cleared so that they're available for future
allocation (we don't want the indices of any registered types to changes
if another type is deregistered, as those indicates are the type/subtype
values, so we can't shrink the array).
Clean up white space and remove some comments that shouldn't have been
added.
2021-02-17 06:24:47 +00:00
|
|
|
required_comment_types,
|
|
|
|
FT_SORT_BY_DESCRIPTION);
|
2012-01-24 05:55:00 +00:00
|
|
|
if (savable_file_types == NULL)
|
2012-06-23 08:18:14 +00:00
|
|
|
return FALSE; /* shouldn't happen - the "Save As..." item should be disabled if we can't save the file */
|
2012-09-24 17:04:50 +00:00
|
|
|
g_compressed = FALSE;
|
2012-01-24 05:55:00 +00:00
|
|
|
|
2021-07-01 17:06:02 +00:00
|
|
|
ofn = new OPENFILENAME();
|
2007-01-14 05:18:07 +00:00
|
|
|
|
2012-09-24 17:04:50 +00:00
|
|
|
ofn->lStructSize = ofnsize;
|
|
|
|
ofn->hwndOwner = h_wnd;
|
|
|
|
ofn->hInstance = (HINSTANCE) GetWindowLongPtr(h_wnd, GWLP_HINSTANCE);
|
2013-04-01 20:36:42 +00:00
|
|
|
ofn->lpstrFilter = build_file_save_type_list(savable_file_types);
|
2012-09-24 17:04:50 +00:00
|
|
|
ofn->lpstrCustomFilter = NULL;
|
|
|
|
ofn->nMaxCustFilter = 0;
|
|
|
|
ofn->nFilterIndex = 1; /* the first entry is the best match; 1-origin indexing */
|
|
|
|
ofn->lpstrFile = file_name16;
|
|
|
|
ofn->nMaxFile = MAX_PATH;
|
|
|
|
ofn->lpstrFileTitle = NULL;
|
|
|
|
ofn->nMaxFileTitle = 0;
|
|
|
|
ofn->lpstrInitialDir = utf_8to16(get_last_open_dir());
|
2019-12-09 23:18:06 +00:00
|
|
|
ofn->lpstrTitle = title;
|
2013-07-14 09:17:31 +00:00
|
|
|
ofn->Flags = OFN_ENABLESIZING | OFN_ENABLETEMPLATE | OFN_EXPLORER |
|
2012-09-24 17:04:50 +00:00
|
|
|
OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY |
|
|
|
|
OFN_PATHMUSTEXIST | OFN_ENABLEHOOK | OFN_SHOWHELP;
|
|
|
|
ofn->lpstrDefExt = NULL;
|
2013-10-11 17:20:50 +00:00
|
|
|
ofn->lCustData = (LPARAM) cf;
|
2012-09-24 17:04:50 +00:00
|
|
|
ofn->lpfnHook = save_as_file_hook_proc;
|
|
|
|
ofn->lpTemplateName = _T("WIRESHARK_SAVEASFILENAME_TEMPLATE");
|
2006-06-23 18:29:48 +00:00
|
|
|
|
2018-05-09 18:46:56 +00:00
|
|
|
HANDLE save_da_ctx = set_thread_per_monitor_v2_awareness();
|
2012-09-24 17:04:50 +00:00
|
|
|
gsfn_ok = GetSaveFileName(ofn);
|
2018-05-09 18:46:56 +00:00
|
|
|
revert_thread_per_monitor_v2_awareness(save_da_ctx);
|
2012-05-24 02:16:53 +00:00
|
|
|
|
2012-09-24 17:04:50 +00:00
|
|
|
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);
|
2018-11-16 04:06:36 +00:00
|
|
|
*compression_type = g_compressed ? WTAP_GZIP_COMPRESSED : WTAP_UNCOMPRESSED;
|
2012-09-24 17:04:50 +00:00
|
|
|
} else {
|
|
|
|
/* User cancelled or closed the dialog, or an error occurred. */
|
2012-09-25 23:29:47 +00:00
|
|
|
if (CommDlgExtendedError() != 0) {
|
2012-09-24 17:44:11 +00:00
|
|
|
/* 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;
|
|
|
|
}
|
2006-02-13 21:25:43 +00:00
|
|
|
}
|
2012-09-24 17:04:50 +00:00
|
|
|
|
2006-02-13 21:25:43 +00:00
|
|
|
g_sf_hwnd = NULL;
|
2012-01-24 05:55:00 +00:00
|
|
|
g_array_free(savable_file_types, TRUE);
|
2007-01-14 05:18:07 +00:00
|
|
|
g_free( (void *) ofn->lpstrFilter);
|
2021-07-01 17:06:02 +00:00
|
|
|
delete ofn;
|
2012-09-24 17:04:50 +00:00
|
|
|
return gsfn_ok;
|
2006-02-13 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2012-10-03 19:24:14 +00:00
|
|
|
gboolean
|
2019-12-09 23:18:06 +00:00
|
|
|
win32_export_specified_packets_file(HWND h_wnd, const wchar_t *title,
|
|
|
|
capture_file *cf,
|
2013-10-11 17:20:50 +00:00
|
|
|
GString *file_name,
|
2012-10-03 19:24:14 +00:00
|
|
|
int *file_type,
|
2018-11-16 04:06:36 +00:00
|
|
|
wtap_compression_type *compression_type,
|
2012-10-03 19:24:14 +00:00
|
|
|
packet_range_t *range) {
|
2012-05-22 22:39:30 +00:00
|
|
|
GArray *savable_file_types;
|
|
|
|
OPENFILENAME *ofn;
|
|
|
|
TCHAR file_name16[MAX_PATH] = _T("");
|
2018-06-15 17:52:53 +00:00
|
|
|
int ofnsize = sizeof(OPENFILENAME);
|
2018-05-09 18:46:56 +00:00
|
|
|
BOOL gsfn_ok;
|
2012-05-22 22:39:30 +00:00
|
|
|
|
2018-11-16 04:06:36 +00:00
|
|
|
if (!file_name || !file_type || !compression_type || !range)
|
2012-10-03 19:24:14 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (file_name->len > 0) {
|
|
|
|
StringCchCopy(file_name16, MAX_PATH, utf_8to16(file_name->str));
|
|
|
|
}
|
|
|
|
|
wiretap: more work on file type/subtypes.
Provide a wiretap routine to get an array of all savable file
type/subtypes, sorted with pcap and pcapng at the top, followed by the
other types, sorted either by the name or the description.
Use that routine to list options for the -F flag for various commands
Rename wtap_get_savable_file_types_subtypes() to
wtap_get_savable_file_types_subtypes_for_file(), to indicate that it
provides an array of all file type/subtypes in which a given file can be
saved. Have it sort all types, other than the default type/subtype and,
if there is one, the "other" type (both of which are put at the top), by
the name or the description.
Don't allow wtap_register_file_type_subtypes() to override any existing
registrations; have them always register a new type. In that routine,
if there are any emply slots in the table, due to an entry being
unregistered, use it rather than allocating a new slot.
Don't allow unregistration of built-in types.
Rename the "dump open table" to the "file type/subtype table", as it has
entries for all types/subtypes, even if we can't write them.
Initialize that table in a routine that pre-allocates the GArray before
filling it with built-in types/subtypes, so it doesn't keep getting
reallocated.
Get rid of wtap_num_file_types_subtypes - it's just a copy of the size
of the GArray.
Don't have wtap_file_type_subtype_description() crash if handed an
file type/subtype that isn't a valid array index - just return NULL, as
we do with wtap_file_type_subtype_name().
In wtap_name_to_file_type_subtype(), don't use WTAP_FILE_TYPE_SUBTYPE_
names for the backwards-compatibility names - map those names to the
current names, and then look them up. This reduces the number of
uses of hardwired WTAP_FILE_TYPE_SUBTYPE_ values.
Clean up the type of wtap_module_count - it has no need to be a gulong.
Have built-in wiretap file handlers register names to be used for their
file type/subtypes, rather than building the table in init.lua.
Add a new Lua C function get_wtap_filetypes() to construct the
wtap_filetypes table, based on the registered names, and use it in
init.lua.
Add a #define WSLUA_INTERNAL_FUNCTION to register functions intended
only for internal use in init.lua, so they can be made available from
Lua without being documented.
Get rid of WTAP_NUM_FILE_TYPES_SUBTYPES - most code has no need to use
it, as it can just request arrays of types, and the space of
type/subtype codes can be sparse due to registration in any case, so
code has to be careful using it.
wtap_get_num_file_types_subtypes() is no longer used, so remove it. It
returns the number of elements in the file type/subtype array, which is
not necessarily the name of known file type/subtypes, as there may have
been some deregistered types, and those types do *not* get removed from
the array, they just get cleared so that they're available for future
allocation (we don't want the indices of any registered types to changes
if another type is deregistered, as those indicates are the type/subtype
values, so we can't shrink the array).
Clean up white space and remove some comments that shouldn't have been
added.
2021-02-17 06:24:47 +00:00
|
|
|
savable_file_types = wtap_get_savable_file_types_subtypes_for_file(cf->cd_t,
|
|
|
|
cf->linktypes, 0,
|
|
|
|
FT_SORT_BY_DESCRIPTION);
|
2012-05-22 22:39:30 +00:00
|
|
|
if (savable_file_types == NULL)
|
2012-10-03 19:45:05 +00:00
|
|
|
return FALSE; /* shouldn't happen - the "Save As..." item should be disabled if we can't save the file */
|
2012-05-22 22:39:30 +00:00
|
|
|
|
2012-10-03 19:24:14 +00:00
|
|
|
g_range = range;
|
2013-10-11 17:20:50 +00:00
|
|
|
g_cf = cf;
|
2012-10-03 19:24:14 +00:00
|
|
|
g_compressed = FALSE;
|
|
|
|
|
2021-07-01 17:06:02 +00:00
|
|
|
ofn = new OPENFILENAME();
|
2012-05-22 22:39:30 +00:00
|
|
|
|
|
|
|
ofn->lStructSize = ofnsize;
|
|
|
|
ofn->hwndOwner = h_wnd;
|
|
|
|
ofn->hInstance = (HINSTANCE) GetWindowLongPtr(h_wnd, GWLP_HINSTANCE);
|
2013-04-01 20:36:42 +00:00
|
|
|
ofn->lpstrFilter = build_file_save_type_list(savable_file_types);
|
2012-05-22 22:39:30 +00:00
|
|
|
ofn->lpstrCustomFilter = NULL;
|
|
|
|
ofn->nMaxCustFilter = 0;
|
|
|
|
ofn->nFilterIndex = 1; /* the first entry is the best match; 1-origin indexing */
|
|
|
|
ofn->lpstrFile = file_name16;
|
|
|
|
ofn->nMaxFile = MAX_PATH;
|
|
|
|
ofn->lpstrFileTitle = NULL;
|
|
|
|
ofn->nMaxFileTitle = 0;
|
|
|
|
ofn->lpstrInitialDir = utf_8to16(get_last_open_dir());
|
2019-12-09 23:18:06 +00:00
|
|
|
ofn->lpstrTitle = title;
|
2012-05-22 22:39:30 +00:00
|
|
|
ofn->Flags = OFN_ENABLESIZING | OFN_ENABLETEMPLATE | OFN_EXPLORER |
|
|
|
|
OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY |
|
|
|
|
OFN_PATHMUSTEXIST | OFN_ENABLEHOOK | OFN_SHOWHELP;
|
|
|
|
ofn->lpstrDefExt = NULL;
|
2013-10-21 18:03:37 +00:00
|
|
|
ofn->lCustData = (LPARAM) cf;
|
2012-05-22 22:39:30 +00:00
|
|
|
ofn->lpfnHook = export_specified_packets_file_hook_proc;
|
2012-05-23 01:06:51 +00:00
|
|
|
ofn->lpTemplateName = _T("WIRESHARK_EXPORT_SPECIFIED_PACKETS_FILENAME_TEMPLATE");
|
2012-05-22 22:39:30 +00:00
|
|
|
|
2018-05-09 18:46:56 +00:00
|
|
|
HANDLE save_da_ctx = set_thread_per_monitor_v2_awareness();
|
2012-10-03 19:24:14 +00:00
|
|
|
gsfn_ok = GetSaveFileName(ofn);
|
2018-05-09 18:46:56 +00:00
|
|
|
revert_thread_per_monitor_v2_awareness(save_da_ctx);
|
2012-05-24 02:16:53 +00:00
|
|
|
|
2012-10-03 19:24:14 +00:00
|
|
|
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);
|
2018-11-16 04:06:36 +00:00
|
|
|
*compression_type = g_compressed ? WTAP_GZIP_COMPRESSED : WTAP_UNCOMPRESSED;
|
2012-10-03 19:24:14 +00:00
|
|
|
} 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;
|
2012-05-22 22:39:30 +00:00
|
|
|
}
|
|
|
|
}
|
2012-10-03 19:24:14 +00:00
|
|
|
|
2012-05-22 22:39:30 +00:00
|
|
|
g_sf_hwnd = NULL;
|
2012-10-03 19:24:14 +00:00
|
|
|
g_range = NULL;
|
2013-10-11 17:20:50 +00:00
|
|
|
g_cf = NULL;
|
2012-05-22 22:39:30 +00:00
|
|
|
g_array_free(savable_file_types, TRUE);
|
|
|
|
g_free( (void *) ofn->lpstrFilter);
|
2021-07-01 17:06:02 +00:00
|
|
|
delete ofn;
|
2012-10-03 19:24:14 +00:00
|
|
|
return gsfn_ok;
|
2012-05-22 22:39:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
gboolean
|
2019-12-09 23:18:06 +00:00
|
|
|
win32_merge_file (HWND h_wnd, const wchar_t *title, GString *file_name, GString *display_filter, int *merge_type) {
|
2007-01-14 05:18:07 +00:00
|
|
|
OPENFILENAME *ofn;
|
2012-09-24 17:04:50 +00:00
|
|
|
TCHAR file_name16[MAX_PATH] = _T("");
|
2018-06-15 17:52:53 +00:00
|
|
|
int ofnsize = sizeof(OPENFILENAME);
|
2018-05-09 18:46:56 +00:00
|
|
|
BOOL gofn_ok;
|
2007-01-14 05:18:07 +00:00
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
if (!file_name || !display_filter || !merge_type)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (file_name->len > 0) {
|
2012-09-24 17:04:50 +00:00
|
|
|
StringCchCopy(file_name16, MAX_PATH, utf_8to16(file_name->str));
|
2012-09-10 21:27:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (display_filter->len > 0) {
|
|
|
|
g_dfilter_str = g_strdup(display_filter->str);
|
|
|
|
} else if (g_dfilter_str) {
|
|
|
|
g_free(g_dfilter_str);
|
|
|
|
g_dfilter_str = NULL;
|
|
|
|
}
|
|
|
|
|
2021-07-01 17:06:02 +00:00
|
|
|
ofn = new OPENFILENAME();
|
2007-01-14 05:18:07 +00:00
|
|
|
|
|
|
|
ofn->lStructSize = ofnsize;
|
|
|
|
ofn->hwndOwner = h_wnd;
|
2009-04-15 23:23:21 +00:00
|
|
|
ofn->hInstance = (HINSTANCE) GetWindowLongPtr(h_wnd, GWLP_HINSTANCE);
|
2012-01-24 05:55:00 +00:00
|
|
|
ofn->lpstrFilter = build_file_open_type_list();
|
2007-01-14 05:18:07 +00:00
|
|
|
ofn->lpstrCustomFilter = NULL;
|
|
|
|
ofn->nMaxCustFilter = 0;
|
|
|
|
ofn->nFilterIndex = FILE_MERGE_DEFAULT;
|
2012-09-24 17:04:50 +00:00
|
|
|
ofn->lpstrFile = file_name16;
|
2007-01-14 05:18:07 +00:00
|
|
|
ofn->nMaxFile = MAX_PATH;
|
|
|
|
ofn->lpstrFileTitle = NULL;
|
|
|
|
ofn->nMaxFileTitle = 0;
|
2006-02-13 21:25:43 +00:00
|
|
|
if (prefs.gui_fileopen_style == FO_STYLE_SPECIFIED && prefs.gui_fileopen_dir[0] != '\0') {
|
2009-01-19 22:37:14 +00:00
|
|
|
ofn->lpstrInitialDir = utf_8to16(prefs.gui_fileopen_dir);
|
2006-02-13 21:25:43 +00:00
|
|
|
} else {
|
2009-01-19 22:37:14 +00:00
|
|
|
ofn->lpstrInitialDir = utf_8to16(get_last_open_dir());
|
2006-02-13 21:25:43 +00:00
|
|
|
}
|
2019-12-09 23:18:06 +00:00
|
|
|
ofn->lpstrTitle = title;
|
2009-01-19 22:37:14 +00:00
|
|
|
ofn->Flags = OFN_ENABLESIZING | OFN_ENABLETEMPLATE | OFN_EXPLORER |
|
|
|
|
OFN_NOCHANGEDIR | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY |
|
|
|
|
OFN_ENABLEHOOK | OFN_SHOWHELP;
|
2007-01-14 05:18:07 +00:00
|
|
|
ofn->lpstrDefExt = NULL;
|
|
|
|
ofn->lpfnHook = merge_file_hook_proc;
|
|
|
|
ofn->lpTemplateName = _T("WIRESHARK_MERGEFILENAME_TEMPLATE");
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2018-05-09 18:46:56 +00:00
|
|
|
HANDLE save_da_ctx = set_thread_per_monitor_v2_awareness();
|
2012-09-10 21:27:49 +00:00
|
|
|
gofn_ok = GetOpenFileName(ofn);
|
2018-05-09 18:46:56 +00:00
|
|
|
revert_thread_per_monitor_v2_awareness(save_da_ctx);
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
if (gofn_ok) {
|
2012-09-24 17:04:50 +00:00
|
|
|
g_string_printf(file_name, "%s", utf_16to8(file_name16));
|
2012-09-10 21:27:49 +00:00
|
|
|
g_string_printf(display_filter, "%s", g_dfilter_str ? g_dfilter_str : "");
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
switch (g_merge_action) {
|
2008-05-30 07:13:28 +00:00
|
|
|
case merge_append:
|
2012-09-10 21:27:49 +00:00
|
|
|
*merge_type = 1;
|
2008-05-30 07:13:28 +00:00
|
|
|
break;
|
|
|
|
case merge_chrono:
|
2012-09-10 21:27:49 +00:00
|
|
|
*merge_type = 0;
|
2008-05-30 07:13:28 +00:00
|
|
|
break;
|
|
|
|
case merge_prepend:
|
2012-09-10 21:27:49 +00:00
|
|
|
*merge_type = -1;
|
2008-05-30 07:13:28 +00:00
|
|
|
break;
|
|
|
|
default:
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert_not_reached();
|
2008-05-30 07:13:28 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-10 21:27:49 +00:00
|
|
|
|
|
|
|
g_free( (void *) ofn->lpstrFilter);
|
2021-07-01 17:06:02 +00:00
|
|
|
delete ofn;
|
2012-09-10 21:27:49 +00:00
|
|
|
g_free(g_dfilter_str);
|
|
|
|
g_dfilter_str = NULL;
|
|
|
|
return gofn_ok;
|
2006-02-13 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-04-27 15:24:05 +00:00
|
|
|
win32_export_file(HWND h_wnd, const wchar_t *title, capture_file *cf, export_type_e export_type, const gchar *range_) {
|
2007-01-14 05:18:07 +00:00
|
|
|
OPENFILENAME *ofn;
|
2006-03-08 20:55:32 +00:00
|
|
|
TCHAR file_name[MAX_PATH] = _T("");
|
2006-02-13 21:25:43 +00:00
|
|
|
char *dirname;
|
|
|
|
cf_print_status_t status;
|
2018-06-15 17:52:53 +00:00
|
|
|
int ofnsize = sizeof(OPENFILENAME);
|
2007-01-14 05:18:07 +00:00
|
|
|
|
2013-10-15 01:10:52 +00:00
|
|
|
g_cf = cf;
|
|
|
|
|
2021-07-01 17:06:02 +00:00
|
|
|
ofn = new OPENFILENAME();
|
2007-01-14 05:18:07 +00:00
|
|
|
|
|
|
|
ofn->lStructSize = ofnsize;
|
|
|
|
ofn->hwndOwner = h_wnd;
|
2009-04-15 23:23:21 +00:00
|
|
|
ofn->hInstance = (HINSTANCE) GetWindowLongPtr(h_wnd, GWLP_HINSTANCE);
|
2007-01-14 05:18:07 +00:00
|
|
|
ofn->lpstrFilter = FILE_TYPES_EXPORT;
|
|
|
|
ofn->lpstrCustomFilter = NULL;
|
|
|
|
ofn->nMaxCustFilter = 0;
|
|
|
|
ofn->nFilterIndex = export_type;
|
|
|
|
ofn->lpstrFile = file_name;
|
|
|
|
ofn->nMaxFile = MAX_PATH;
|
|
|
|
ofn->lpstrFileTitle = NULL;
|
|
|
|
ofn->nMaxFileTitle = 0;
|
2008-05-30 07:13:28 +00:00
|
|
|
ofn->lpstrInitialDir = utf_8to16(get_last_open_dir());
|
2019-12-09 23:18:06 +00:00
|
|
|
ofn->lpstrTitle = title;
|
2009-01-19 22:37:14 +00:00
|
|
|
ofn->Flags = OFN_ENABLESIZING | OFN_ENABLETEMPLATE | OFN_EXPLORER |
|
|
|
|
OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY |
|
|
|
|
OFN_PATHMUSTEXIST | OFN_ENABLEHOOK | OFN_SHOWHELP;
|
2018-06-27 18:28:49 +00:00
|
|
|
ofn->lpstrDefExt = FILE_EXT_EXPORT[export_type];
|
2013-10-11 17:20:50 +00:00
|
|
|
ofn->lCustData = (LPARAM) cf;
|
2007-01-14 05:18:07 +00:00
|
|
|
ofn->lpfnHook = export_file_hook_proc;
|
|
|
|
ofn->lpTemplateName = _T("WIRESHARK_EXPORTFILENAME_TEMPLATE");
|
2006-02-13 21:25:43 +00:00
|
|
|
|
|
|
|
/* Fill in our print (and export) args */
|
|
|
|
|
2020-04-27 15:24:05 +00:00
|
|
|
/* init the printing range */
|
|
|
|
packet_range_init(&print_args.range, cf);
|
|
|
|
|
|
|
|
if (strlen(range_) > 0)
|
|
|
|
packet_range_convert_selection_str(&print_args.range, range_);
|
|
|
|
|
2006-02-13 21:25:43 +00:00
|
|
|
print_args.format = PR_FMT_TEXT;
|
|
|
|
print_args.to_file = TRUE;
|
|
|
|
print_args.cmd = NULL;
|
|
|
|
print_args.print_summary = TRUE;
|
2013-06-19 15:22:56 +00:00
|
|
|
print_args.print_col_headings = TRUE;
|
2006-02-13 21:25:43 +00:00
|
|
|
print_args.print_dissections = print_dissections_as_displayed;
|
|
|
|
print_args.print_hex = FALSE;
|
|
|
|
print_args.print_formfeed = FALSE;
|
2017-02-09 17:06:45 +00:00
|
|
|
print_args.stream = NULL;
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2018-05-09 18:46:56 +00:00
|
|
|
HANDLE save_da_ctx = set_thread_per_monitor_v2_awareness();
|
|
|
|
BOOL gsfn_ok = GetSaveFileName(ofn);
|
|
|
|
revert_thread_per_monitor_v2_awareness(save_da_ctx);
|
|
|
|
|
|
|
|
if (gsfn_ok) {
|
2009-01-19 22:37:14 +00:00
|
|
|
print_args.file = utf_16to8(file_name);
|
|
|
|
switch (ofn->nFilterIndex) {
|
|
|
|
case export_type_text: /* Text */
|
|
|
|
print_args.stream = print_stream_text_new(TRUE, print_args.file);
|
|
|
|
if (print_args.stream == NULL) {
|
|
|
|
open_failure_alert_box(print_args.file, errno, TRUE);
|
2021-07-01 17:06:02 +00:00
|
|
|
delete ofn;
|
2009-01-19 22:37:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-03-01 02:52:52 +00:00
|
|
|
status = cf_print_packets(cf, &print_args, TRUE);
|
2009-01-19 22:37:14 +00:00
|
|
|
break;
|
|
|
|
case export_type_ps: /* PostScript (r) */
|
|
|
|
print_args.stream = print_stream_ps_new(TRUE, print_args.file);
|
|
|
|
if (print_args.stream == NULL) {
|
|
|
|
open_failure_alert_box(print_args.file, errno, TRUE);
|
2021-07-01 17:06:02 +00:00
|
|
|
delete ofn;
|
2009-01-19 22:37:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-03-01 02:52:52 +00:00
|
|
|
status = cf_print_packets(cf, &print_args, TRUE);
|
2009-01-19 22:37:14 +00:00
|
|
|
break;
|
2008-03-11 18:23:16 +00:00
|
|
|
case export_type_csv: /* CSV */
|
2012-10-13 00:18:46 +00:00
|
|
|
status = cf_write_csv_packets(cf, &print_args);
|
2006-02-13 21:25:43 +00:00
|
|
|
break;
|
2008-03-11 18:23:16 +00:00
|
|
|
case export_type_carrays: /* C Arrays */
|
2012-10-13 00:18:46 +00:00
|
|
|
status = cf_write_carrays_packets(cf, &print_args);
|
2008-03-11 18:23:16 +00:00
|
|
|
break;
|
2009-01-19 22:37:14 +00:00
|
|
|
case export_type_psml: /* PSML */
|
2012-10-13 00:18:46 +00:00
|
|
|
status = cf_write_psml_packets(cf, &print_args);
|
2009-01-19 22:37:14 +00:00
|
|
|
break;
|
|
|
|
case export_type_pdml: /* PDML */
|
2012-10-13 00:18:46 +00:00
|
|
|
status = cf_write_pdml_packets(cf, &print_args);
|
2009-01-19 22:37:14 +00:00
|
|
|
break;
|
2016-06-19 14:52:50 +00:00
|
|
|
case export_type_json: /* JSON */
|
|
|
|
status = cf_write_json_packets(cf, &print_args);
|
|
|
|
break;
|
2009-01-19 22:37:14 +00:00
|
|
|
default:
|
2021-07-01 17:06:02 +00:00
|
|
|
delete ofn;
|
2009-01-19 22:37:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
case CF_PRINT_OK:
|
|
|
|
break;
|
2006-02-13 21:25:43 +00:00
|
|
|
case CF_PRINT_OPEN_ERROR:
|
2009-01-19 22:37:14 +00:00
|
|
|
open_failure_alert_box(print_args.file, errno, TRUE);
|
|
|
|
break;
|
2006-02-13 21:25:43 +00:00
|
|
|
case CF_PRINT_WRITE_ERROR:
|
2009-01-19 22:37:14 +00:00
|
|
|
write_failure_alert_box(print_args.file, errno);
|
|
|
|
break;
|
|
|
|
}
|
2008-05-30 07:13:28 +00:00
|
|
|
/* Save the directory name for future file dialogs. */
|
2009-01-19 22:37:14 +00:00
|
|
|
dirname = get_dirname(utf_16to8(file_name)); /* Overwrites cf_name */
|
|
|
|
set_last_open_dir(dirname);
|
2008-05-30 07:13:28 +00:00
|
|
|
}
|
2007-02-07 02:50:33 +00:00
|
|
|
|
2013-10-15 01:10:52 +00:00
|
|
|
g_cf = NULL;
|
2021-07-01 17:06:02 +00:00
|
|
|
delete ofn;
|
2006-02-13 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Private routines
|
|
|
|
*/
|
|
|
|
|
2010-11-22 19:45:03 +00:00
|
|
|
/** Given a print_args_t struct, update a set of print/export format controls
|
|
|
|
* accordingly.
|
|
|
|
*
|
|
|
|
* @param dlg_hwnd HWND of the dialog in question.
|
|
|
|
* @param args Pointer to a print args struct.
|
|
|
|
*/
|
2006-02-13 21:25:43 +00:00
|
|
|
static void
|
|
|
|
print_update_dynamic(HWND dlg_hwnd, print_args_t *args) {
|
|
|
|
HWND cur_ctrl;
|
|
|
|
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_PKT_SUMMARY_CB);
|
2013-06-19 15:22:56 +00:00
|
|
|
if (SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED) {
|
2009-01-19 22:37:14 +00:00
|
|
|
args->print_summary = TRUE;
|
2013-06-19 15:22:56 +00:00
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_COL_HEADINGS_CB);
|
|
|
|
EnableWindow(cur_ctrl, TRUE);
|
|
|
|
if (SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
|
|
|
|
args->print_col_headings = TRUE;
|
|
|
|
else
|
|
|
|
args->print_col_headings = FALSE;
|
|
|
|
} else {
|
2009-01-19 22:37:14 +00:00
|
|
|
args->print_summary = FALSE;
|
2013-06-19 15:22:56 +00:00
|
|
|
args->print_col_headings = FALSE;
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_COL_HEADINGS_CB);
|
|
|
|
EnableWindow(cur_ctrl, FALSE);
|
|
|
|
}
|
2006-02-13 21:25:43 +00:00
|
|
|
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_PKT_DETAIL_CB);
|
|
|
|
if (SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED) {
|
2009-01-19 22:37:14 +00:00
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_PKT_DETAIL_COMBO);
|
|
|
|
switch (SendMessage(cur_ctrl, CB_GETCURSEL, 0, 0)) {
|
|
|
|
case 0:
|
|
|
|
args->print_dissections = print_dissections_collapsed;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
args->print_dissections = print_dissections_as_displayed;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
args->print_dissections = print_dissections_expanded;
|
|
|
|
break;
|
|
|
|
default:
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert_not_reached();
|
2009-01-19 22:37:14 +00:00
|
|
|
}
|
|
|
|
EnableWindow(cur_ctrl, TRUE);
|
2006-02-13 21:25:43 +00:00
|
|
|
} else {
|
2009-01-19 22:37:14 +00:00
|
|
|
args->print_dissections = print_dissections_none;
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_PKT_DETAIL_COMBO);
|
|
|
|
EnableWindow(cur_ctrl, FALSE);
|
2006-02-13 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_PKT_BYTES_CB);
|
|
|
|
if (SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
|
2009-01-19 22:37:14 +00:00
|
|
|
args->print_hex = TRUE;
|
2006-02-13 21:25:43 +00:00
|
|
|
else
|
2009-01-19 22:37:14 +00:00
|
|
|
args->print_hex = FALSE;
|
2006-02-13 21:25:43 +00:00
|
|
|
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_PKT_NEW_PAGE_CB);
|
|
|
|
if (SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
|
2009-01-19 22:37:14 +00:00
|
|
|
args->print_formfeed = TRUE;
|
2006-02-13 21:25:43 +00:00
|
|
|
else
|
2009-01-19 22:37:14 +00:00
|
|
|
args->print_formfeed = FALSE;
|
2006-02-13 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2010-11-22 19:45:03 +00:00
|
|
|
static void
|
|
|
|
format_handle_wm_initdialog(HWND dlg_hwnd, print_args_t *args) {
|
|
|
|
HWND cur_ctrl;
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2013-06-19 15:22:56 +00:00
|
|
|
/* Set the "Packet summary" and "Include column headings" boxes */
|
2010-11-22 19:45:03 +00:00
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_PKT_SUMMARY_CB);
|
|
|
|
SendMessage(cur_ctrl, BM_SETCHECK, args->print_summary, 0);
|
2013-06-19 15:22:56 +00:00
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_COL_HEADINGS_CB);
|
|
|
|
SendMessage(cur_ctrl, BM_SETCHECK, args->print_col_headings, 0);
|
2010-11-22 19:45:03 +00:00
|
|
|
|
|
|
|
/* Set the "Packet details" box */
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_PKT_DETAIL_CB);
|
|
|
|
SendMessage(cur_ctrl, BM_SETCHECK, args->print_dissections != print_dissections_none, 0);
|
|
|
|
|
|
|
|
/* Set the "Packet details" combo */
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_PKT_DETAIL_COMBO);
|
|
|
|
SendMessage(cur_ctrl, CB_ADDSTRING, 0, (WPARAM) _T("All collapsed"));
|
|
|
|
SendMessage(cur_ctrl, CB_ADDSTRING, 0, (WPARAM) _T("As displayed"));
|
|
|
|
SendMessage(cur_ctrl, CB_ADDSTRING, 0, (WPARAM) _T("All expanded"));
|
|
|
|
|
|
|
|
switch (args->print_dissections) {
|
|
|
|
case print_dissections_none:
|
|
|
|
case print_dissections_collapsed:
|
|
|
|
SendMessage(cur_ctrl, CB_SETCURSEL, 0, 0);
|
|
|
|
break;
|
|
|
|
case print_dissections_as_displayed:
|
|
|
|
SendMessage(cur_ctrl, CB_SETCURSEL, 1, 0);
|
|
|
|
break;
|
|
|
|
case print_dissections_expanded:
|
|
|
|
SendMessage(cur_ctrl, CB_SETCURSEL, 2, 0);
|
2020-12-11 10:05:29 +00:00
|
|
|
break;
|
2010-11-22 19:45:03 +00:00
|
|
|
default:
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert_not_reached();
|
2010-11-22 19:45:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the "Packet bytes" box */
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_PKT_BYTES_CB);
|
|
|
|
SendMessage(cur_ctrl, BM_SETCHECK, args->print_hex, 0);
|
|
|
|
|
|
|
|
/* Set the "Each packet on a new page" box */
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_PKT_NEW_PAGE_CB);
|
|
|
|
SendMessage(cur_ctrl, BM_SETCHECK, args->print_formfeed, 0);
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2010-11-22 19:45:03 +00:00
|
|
|
print_update_dynamic(dlg_hwnd, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define PREVIEW_STR_MAX 200
|
2006-02-13 21:25:43 +00:00
|
|
|
|
|
|
|
/* If preview_file is NULL, disable the elements. If not, enable and
|
|
|
|
* show the preview info. */
|
|
|
|
static gboolean
|
2012-07-21 01:14:08 +00:00
|
|
|
preview_set_file_info(HWND of_hwnd, gchar *preview_file) {
|
2006-02-13 21:25:43 +00:00
|
|
|
HWND cur_ctrl;
|
|
|
|
int i;
|
2014-05-09 05:18:49 +00:00
|
|
|
wtap *wth;
|
2018-02-09 19:18:22 +00:00
|
|
|
int err;
|
2006-02-13 21:25:43 +00:00
|
|
|
gchar *err_info;
|
2018-02-10 02:45:14 +00:00
|
|
|
ws_file_preview_stats stats;
|
|
|
|
ws_file_preview_stats_status status;
|
2006-03-08 20:55:32 +00:00
|
|
|
TCHAR string_buff[PREVIEW_STR_MAX];
|
2016-09-08 21:31:03 +00:00
|
|
|
TCHAR first_buff[PREVIEW_STR_MAX];
|
2009-08-31 18:16:16 +00:00
|
|
|
gint64 filesize;
|
2016-09-08 21:31:03 +00:00
|
|
|
gchar *size_str;
|
2006-02-13 21:25:43 +00:00
|
|
|
time_t ti_time;
|
|
|
|
struct tm *ti_tm;
|
|
|
|
guint elapsed_time;
|
|
|
|
|
2016-09-08 21:31:03 +00:00
|
|
|
for (i = EWFD_PTX_FORMAT; i <= EWFD_PTX_START_ELAPSED; i++) {
|
2008-05-30 07:13:28 +00:00
|
|
|
cur_ctrl = GetDlgItem(of_hwnd, i);
|
|
|
|
if (cur_ctrl) {
|
2012-07-21 01:14:08 +00:00
|
|
|
EnableWindow(cur_ctrl, FALSE);
|
2012-07-31 22:12:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-08 21:31:03 +00:00
|
|
|
for (i = EWFD_PTX_FORMAT; i <= EWFD_PTX_START_ELAPSED; i++) {
|
2012-07-31 22:12:41 +00:00
|
|
|
cur_ctrl = GetDlgItem(of_hwnd, i);
|
|
|
|
if (cur_ctrl) {
|
2008-05-30 07:13:28 +00:00
|
|
|
SetWindowText(cur_ctrl, _T("-"));
|
|
|
|
}
|
2006-02-13 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2012-07-21 01:14:08 +00:00
|
|
|
if (preview_file == NULL || strlen(preview_file) < 1) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2012-07-27 21:43:02 +00:00
|
|
|
/* Format: directory */
|
2012-07-21 01:14:08 +00:00
|
|
|
cur_ctrl = GetDlgItem(of_hwnd, EWFD_PTX_FORMAT);
|
|
|
|
if (test_for_directory(preview_file) == EISDIR) {
|
|
|
|
SetWindowText(cur_ctrl, _T("directory"));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2014-01-18 14:20:02 +00:00
|
|
|
wth = wtap_open_offline(preview_file, WTAP_TYPE_AUTO, &err, &err_info, TRUE);
|
2012-07-21 01:14:08 +00:00
|
|
|
if (cur_ctrl && wth == NULL) {
|
|
|
|
if(err == WTAP_ERR_FILE_UNKNOWN_FORMAT) {
|
|
|
|
SetWindowText(cur_ctrl, _T("unknown file format"));
|
|
|
|
} else {
|
|
|
|
SetWindowText(cur_ctrl, _T("error opening file"));
|
2008-05-30 07:13:28 +00:00
|
|
|
}
|
2012-07-21 01:14:08 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2012-07-21 01:14:08 +00:00
|
|
|
/* Success! */
|
2016-09-08 21:31:03 +00:00
|
|
|
for (i = EWFD_PT_FORMAT; i <= EWFD_PTX_START_ELAPSED; i++) {
|
2012-07-21 01:14:08 +00:00
|
|
|
cur_ctrl = GetDlgItem(of_hwnd, i);
|
|
|
|
if (cur_ctrl) {
|
|
|
|
EnableWindow(cur_ctrl, TRUE);
|
2008-05-30 07:13:28 +00:00
|
|
|
}
|
2012-07-21 01:14:08 +00:00
|
|
|
}
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2012-07-27 21:43:02 +00:00
|
|
|
/* Format */
|
|
|
|
cur_ctrl = GetDlgItem(of_hwnd, EWFD_PTX_FORMAT);
|
2021-02-13 08:03:51 +00:00
|
|
|
SetWindowText(cur_ctrl, utf_8to16(wtap_file_type_subtype_description(wtap_file_type_subtype(wth))));
|
2012-07-27 21:43:02 +00:00
|
|
|
|
2012-07-21 01:14:08 +00:00
|
|
|
/* Size */
|
2014-05-09 05:18:49 +00:00
|
|
|
filesize = wtap_file_size(wth, &err);
|
2016-09-08 21:31:03 +00:00
|
|
|
// Windows Explorer uses IEC.
|
|
|
|
size_str = format_size(filesize, format_size_unit_bytes|format_size_prefix_iec);
|
2012-07-21 01:14:08 +00:00
|
|
|
|
2018-02-10 02:45:14 +00:00
|
|
|
status = get_stats_for_preview(wth, &stats, &err, &err_info);
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2018-02-09 19:18:22 +00:00
|
|
|
if(status == PREVIEW_READ_ERROR) {
|
|
|
|
/* XXX - give error details? */
|
|
|
|
g_free(err_info);
|
2018-02-10 02:45:14 +00:00
|
|
|
utf_8to16_snprintf(string_buff, PREVIEW_STR_MAX, "%s, error after %u records",
|
|
|
|
size_str, stats.records);
|
2016-09-08 21:31:03 +00:00
|
|
|
g_free(size_str);
|
|
|
|
cur_ctrl = GetDlgItem(of_hwnd, EWFD_PTX_SIZE);
|
2012-07-21 01:14:08 +00:00
|
|
|
SetWindowText(cur_ctrl, string_buff);
|
2008-05-30 07:13:28 +00:00
|
|
|
wtap_close(wth);
|
2012-07-21 01:14:08 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-02-09 19:18:22 +00:00
|
|
|
/* Packet count */
|
|
|
|
if(status == PREVIEW_TIMED_OUT) {
|
2018-02-10 02:45:14 +00:00
|
|
|
utf_8to16_snprintf(string_buff, PREVIEW_STR_MAX, "%s, timed out at %u data records",
|
|
|
|
size_str, stats.data_records);
|
2012-07-21 01:14:08 +00:00
|
|
|
} else {
|
2018-02-10 02:45:14 +00:00
|
|
|
utf_8to16_snprintf(string_buff, PREVIEW_STR_MAX, "%s, %u data records",
|
|
|
|
size_str, stats.data_records);
|
2006-02-13 21:25:43 +00:00
|
|
|
}
|
2016-09-08 21:31:03 +00:00
|
|
|
g_free(size_str);
|
|
|
|
cur_ctrl = GetDlgItem(of_hwnd, EWFD_PTX_SIZE);
|
2012-07-21 01:14:08 +00:00
|
|
|
SetWindowText(cur_ctrl, string_buff);
|
|
|
|
|
2016-09-08 21:31:03 +00:00
|
|
|
/* First packet / elapsed time */
|
2018-02-10 02:45:14 +00:00
|
|
|
if(stats.have_times) {
|
|
|
|
/*
|
|
|
|
* We saw at least one record with a time stamp, so we can give
|
|
|
|
* a start time (if we have a mix of records with and without
|
|
|
|
* time stamps, and there were records without time stamps
|
|
|
|
* before the one with a time stamp, this may be inaccurate).
|
|
|
|
*/
|
|
|
|
ti_time = (long)stats.start_time;
|
2018-02-09 19:18:22 +00:00
|
|
|
ti_tm = localtime( &ti_time );
|
|
|
|
if(ti_tm) {
|
|
|
|
StringCchPrintf(first_buff, PREVIEW_STR_MAX,
|
|
|
|
_T("%04d-%02d-%02d %02d:%02d:%02d"),
|
|
|
|
ti_tm->tm_year + 1900,
|
|
|
|
ti_tm->tm_mon + 1,
|
|
|
|
ti_tm->tm_mday,
|
|
|
|
ti_tm->tm_hour,
|
|
|
|
ti_tm->tm_min,
|
|
|
|
ti_tm->tm_sec);
|
|
|
|
} else {
|
|
|
|
StringCchPrintf(first_buff, PREVIEW_STR_MAX, _T("?"));
|
|
|
|
}
|
2018-02-10 02:45:14 +00:00
|
|
|
} else {
|
|
|
|
StringCchPrintf(first_buff, PREVIEW_STR_MAX, _T("unknown"));
|
2012-07-21 01:14:08 +00:00
|
|
|
}
|
|
|
|
|
2018-02-09 19:18:22 +00:00
|
|
|
/* Elapsed time */
|
2018-02-10 02:45:14 +00:00
|
|
|
if(status == PREVIEW_SUCCEEDED && stats.have_times) {
|
|
|
|
/*
|
|
|
|
* We didn't time out, so we looked at all packets, and we got
|
|
|
|
* at least one packet with a time stamp, so we can calculate
|
|
|
|
* an elapsed time from the time stamp of the last packet with
|
|
|
|
* with a time stamp (if we have a mix of records with and without
|
|
|
|
* time stamps, and there were records without time stamps after
|
|
|
|
* the last one with a time stamp, this may be inaccurate).
|
|
|
|
*/
|
|
|
|
elapsed_time = (unsigned int)(stats.stop_time-stats.start_time);
|
2021-07-05 17:16:52 +00:00
|
|
|
if (elapsed_time/86400) {
|
2018-02-09 19:18:22 +00:00
|
|
|
StringCchPrintf(string_buff, PREVIEW_STR_MAX, _T("%s / %02u days %02u:%02u:%02u"),
|
|
|
|
first_buff, elapsed_time/86400, elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
|
|
|
|
} else {
|
|
|
|
StringCchPrintf(string_buff, PREVIEW_STR_MAX, _T("%s / %02u:%02u:%02u"),
|
|
|
|
first_buff, elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
|
|
|
|
}
|
2018-02-10 02:45:14 +00:00
|
|
|
} else {
|
2018-02-28 20:23:57 +00:00
|
|
|
StringCchPrintf(string_buff, PREVIEW_STR_MAX, _T("%s / unknown"),
|
|
|
|
first_buff);
|
2012-07-21 01:14:08 +00:00
|
|
|
}
|
2016-09-08 21:31:03 +00:00
|
|
|
cur_ctrl = GetDlgItem(of_hwnd, EWFD_PTX_START_ELAPSED);
|
2012-07-21 01:14:08 +00:00
|
|
|
SetWindowText(cur_ctrl, string_buff);
|
|
|
|
|
|
|
|
wtap_close(wth);
|
2006-02-13 21:25:43 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-10-14 08:59:35 +00:00
|
|
|
static char *
|
2006-08-30 20:45:13 +00:00
|
|
|
filter_tb_get(HWND hwnd) {
|
|
|
|
TCHAR *strval = NULL;
|
|
|
|
gint len;
|
|
|
|
char *ret;
|
|
|
|
|
|
|
|
/* If filter_text is non-NULL, use it. Otherwise, grab the text from
|
|
|
|
* the window */
|
|
|
|
len = GetWindowTextLength(hwnd);
|
|
|
|
if (len > 0) {
|
|
|
|
len++;
|
2021-07-01 17:06:02 +00:00
|
|
|
strval = g_new(TCHAR, len);
|
2006-08-30 20:45:13 +00:00
|
|
|
len = GetWindowText(hwnd, strval, len);
|
2021-07-01 17:06:02 +00:00
|
|
|
ret = g_utf16_to_utf8((gunichar2 *) strval, -1, NULL, NULL, NULL);
|
2006-08-30 20:45:13 +00:00
|
|
|
g_free(strval);
|
|
|
|
return ret;
|
|
|
|
} else {
|
2010-11-03 14:45:17 +00:00
|
|
|
return NULL;
|
2006-08-30 20:45:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* XXX - Copied from "filter-util.c" in the wireshark-win32 branch */
|
2006-02-13 21:25:43 +00:00
|
|
|
/* XXX - The only reason for the "filter_text" parameter is to be able to feed
|
|
|
|
* in the "real" filter string in the case of a CBN_SELCHANGE notification message.
|
|
|
|
*/
|
2010-10-14 08:59:35 +00:00
|
|
|
static void
|
2021-07-05 17:16:52 +00:00
|
|
|
filter_tb_syntax_check(HWND hwnd, const TCHAR *filter_text) {
|
|
|
|
std::wstring strval;
|
2006-02-13 21:25:43 +00:00
|
|
|
dfilter_t *dfp;
|
|
|
|
|
|
|
|
/* If filter_text is non-NULL, use it. Otherwise, grab the text from
|
|
|
|
* the window */
|
|
|
|
if (filter_text) {
|
2021-07-05 17:16:52 +00:00
|
|
|
strval = filter_text;
|
2006-02-13 21:25:43 +00:00
|
|
|
} else {
|
2021-07-07 15:28:40 +00:00
|
|
|
int len = GetWindowTextLength(hwnd);
|
2006-02-13 21:25:43 +00:00
|
|
|
if (len > 0) {
|
|
|
|
len++;
|
2021-07-05 17:16:52 +00:00
|
|
|
strval.resize(len);
|
|
|
|
len = GetWindowText(hwnd, &strval[0], len);
|
|
|
|
strval.resize(len);
|
2006-02-13 21:25:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-07 15:28:40 +00:00
|
|
|
if (strval.empty()) {
|
2006-02-13 21:25:43 +00:00
|
|
|
/* Default window background */
|
|
|
|
SendMessage(hwnd, EM_SETBKGNDCOLOR, (WPARAM) 1, COLOR_WINDOW);
|
|
|
|
return;
|
2021-07-05 17:16:52 +00:00
|
|
|
} else if (dfilter_compile(utf_16to8(strval.c_str()), &dfp, NULL)) { /* colorize filter string entry */
|
2017-08-26 08:30:47 +00:00
|
|
|
dfilter_free(dfp);
|
2006-02-13 21:25:43 +00:00
|
|
|
/* Valid (light green) */
|
2012-10-09 15:34:40 +00:00
|
|
|
SendMessage(hwnd, EM_SETBKGNDCOLOR, 0, RGB(0xe4, 0xff, 0xc7)); /* tango_chameleon_1 */
|
2006-02-13 21:25:43 +00:00
|
|
|
} else {
|
|
|
|
/* Invalid (light red) */
|
2012-10-09 15:34:40 +00:00
|
|
|
SendMessage(hwnd, EM_SETBKGNDCOLOR, 0, RGB(0xff, 0xcc, 0xcc)); /* tango_scarlet_red_1 */
|
2006-02-13 21:25:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-06 20:41:07 +00:00
|
|
|
static gint alpha_sort(gconstpointer a, gconstpointer b)
|
|
|
|
{
|
|
|
|
return g_ascii_strcasecmp(*(const char **)a, *(const char **)b);
|
|
|
|
}
|
|
|
|
|
2009-04-16 03:18:10 +00:00
|
|
|
static UINT_PTR CALLBACK
|
2006-02-13 21:25:43 +00:00
|
|
|
open_file_hook_proc(HWND of_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
|
|
|
|
HWND cur_ctrl, parent;
|
|
|
|
OFNOTIFY *notify = (OFNOTIFY *) l_param;
|
2006-03-08 20:55:32 +00:00
|
|
|
TCHAR sel_name[MAX_PATH];
|
2014-02-26 15:27:20 +00:00
|
|
|
gint i;
|
2006-02-13 21:25:43 +00:00
|
|
|
|
|
|
|
switch(msg) {
|
2009-01-19 22:37:14 +00:00
|
|
|
case WM_INITDIALOG:
|
2021-07-01 17:06:02 +00:00
|
|
|
{
|
2009-01-19 22:37:14 +00:00
|
|
|
/* Retain the filter text, and fill it in. */
|
2012-09-10 21:27:49 +00:00
|
|
|
if(g_dfilter_str != NULL) {
|
2006-08-30 20:45:13 +00:00
|
|
|
cur_ctrl = GetDlgItem(of_hwnd, EWFD_FILTER_EDIT);
|
2012-09-10 21:27:49 +00:00
|
|
|
SetWindowText(cur_ctrl, utf_8to16(g_dfilter_str));
|
2006-08-30 20:45:13 +00:00
|
|
|
}
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2020-07-06 20:41:07 +00:00
|
|
|
/* Put Auto, as well as pcap and pcapng (which are the first two entries in
|
|
|
|
open_routines), at the top of the file type list. */
|
2014-02-26 15:27:20 +00:00
|
|
|
cur_ctrl = GetDlgItem(of_hwnd, EWFD_FORMAT_TYPE);
|
2016-09-08 21:31:03 +00:00
|
|
|
SendMessage(cur_ctrl, CB_ADDSTRING, 0, (WPARAM) _T("Automatically detect file type"));
|
2020-07-06 20:41:07 +00:00
|
|
|
for (i = 0; i < 2; i += 1) {
|
2014-02-26 15:27:20 +00:00
|
|
|
SendMessage(cur_ctrl, CB_ADDSTRING, 0, (WPARAM) utf_8to16(open_routines[i].name));
|
|
|
|
}
|
2020-07-06 20:41:07 +00:00
|
|
|
/* Generate a sorted list of the remaining file types.
|
|
|
|
The magic number 60 is a rough starting point for how big the
|
|
|
|
GPtrArray should start. It'll automatically grow if needed, so
|
|
|
|
the exact number isn't critical. (This is good, because we don't have
|
|
|
|
an easy way to get the exact number.) */
|
|
|
|
GPtrArray *routine_names = g_ptr_array_sized_new(60);
|
|
|
|
for ( /* keep using i */ ; open_routines[i].name != NULL; i += 1) {
|
|
|
|
g_ptr_array_add(routine_names, (gpointer)open_routines[i].name);
|
|
|
|
}
|
|
|
|
g_ptr_array_sort(routine_names, alpha_sort);
|
|
|
|
for (guint i = 0; i < routine_names->len; i += 1) {
|
|
|
|
SendMessage(cur_ctrl, CB_ADDSTRING, 0, (WPARAM) utf_8to16((const char *)g_ptr_array_index(routine_names, i)));
|
|
|
|
}
|
|
|
|
g_ptr_array_free(routine_names, TRUE);
|
2014-02-26 15:27:20 +00:00
|
|
|
SendMessage(cur_ctrl, CB_SETCURSEL, 0, 0);
|
|
|
|
|
2012-07-21 01:14:08 +00:00
|
|
|
preview_set_file_info(of_hwnd, NULL);
|
2021-07-01 17:06:02 +00:00
|
|
|
}
|
2009-01-19 22:37:14 +00:00
|
|
|
break;
|
|
|
|
case WM_NOTIFY:
|
|
|
|
switch (notify->hdr.code) {
|
|
|
|
case CDN_FILEOK:
|
|
|
|
/* Fetch the read filter */
|
2006-08-30 20:45:13 +00:00
|
|
|
cur_ctrl = GetDlgItem(of_hwnd, EWFD_FILTER_EDIT);
|
2017-08-26 08:30:47 +00:00
|
|
|
g_free(g_dfilter_str);
|
2012-09-10 21:27:49 +00:00
|
|
|
g_dfilter_str = filter_tb_get(cur_ctrl);
|
2006-08-30 20:45:13 +00:00
|
|
|
|
2014-02-26 15:27:20 +00:00
|
|
|
cur_ctrl = GetDlgItem(of_hwnd, EWFD_FORMAT_TYPE);
|
2014-03-04 19:15:46 +00:00
|
|
|
g_format_type = (unsigned int) SendMessage(cur_ctrl, CB_GETCURSEL, 0, 0);
|
2014-02-26 15:27:20 +00:00
|
|
|
|
2020-07-06 20:41:07 +00:00
|
|
|
/* The list of file formats is sorted. Get the format by name. */
|
|
|
|
guint label_len;
|
|
|
|
label_len = (guint) SendMessage(cur_ctrl, CB_GETLBTEXTLEN, (WPARAM) g_format_type, 0);
|
|
|
|
if (label_len != CB_ERR) {
|
2021-07-01 17:06:02 +00:00
|
|
|
TCHAR *label = g_new(TCHAR, label_len+1);
|
2020-07-06 20:41:07 +00:00
|
|
|
SendMessage(cur_ctrl, CB_GETLBTEXT, (WPARAM) g_format_type, (LPARAM) label);
|
|
|
|
g_format_type = open_info_name_to_type(utf_16to8(label));
|
|
|
|
g_free(label);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Problem, fall back on automatic */
|
|
|
|
g_format_type = WTAP_TYPE_AUTO;
|
|
|
|
}
|
|
|
|
|
2009-01-19 22:37:14 +00:00
|
|
|
break;
|
|
|
|
case CDN_SELCHANGE:
|
|
|
|
/* This _almost_ works correctly. We need to handle directory
|
|
|
|
selections, etc. */
|
|
|
|
parent = GetParent(of_hwnd);
|
2012-07-21 01:14:08 +00:00
|
|
|
CommDlg_OpenSave_GetFilePath(parent, sel_name, MAX_PATH);
|
|
|
|
preview_set_file_info(of_hwnd, utf_16to8(sel_name));
|
2009-01-19 22:37:14 +00:00
|
|
|
break;
|
2006-08-30 20:45:13 +00:00
|
|
|
case CDN_HELP:
|
2012-10-16 19:47:43 +00:00
|
|
|
topic_action(HELP_OPEN_WIN32_DIALOG);
|
2006-08-30 20:45:13 +00:00
|
|
|
break;
|
2009-01-19 22:37:14 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_COMMAND:
|
|
|
|
cur_ctrl = (HWND) l_param;
|
|
|
|
switch(w_param) {
|
2008-03-27 17:21:48 +00:00
|
|
|
case (EN_UPDATE << 16) | EWFD_FILTER_EDIT:
|
|
|
|
filter_tb_syntax_check(cur_ctrl, NULL);
|
|
|
|
break;
|
|
|
|
/*
|
|
|
|
* If we ever figure out a way to integrate the Windows
|
|
|
|
* and GTK+ event loops (or make a native filter dialog),
|
|
|
|
* we can re-enable the "Filter" button.
|
|
|
|
*/
|
|
|
|
/*
|
2006-02-13 21:54:05 +00:00
|
|
|
case EWFD_FILTER_BTN:
|
|
|
|
break;
|
2008-03-27 17:21:48 +00:00
|
|
|
*/
|
2009-01-19 22:37:14 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2006-02-13 21:25:43 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-08 01:08:42 +00:00
|
|
|
/* Generate a list of the file types we can filter for in the open dialog. */
|
2012-01-24 05:55:00 +00:00
|
|
|
static void
|
2013-11-08 01:08:42 +00:00
|
|
|
append_file_extension_type(GArray *sa, int et)
|
2012-01-24 05:55:00 +00:00
|
|
|
{
|
|
|
|
GString* pattern_str = g_string_new("");
|
|
|
|
GString* description_str = g_string_new("");
|
|
|
|
gchar sep;
|
|
|
|
GSList *extensions_list, *extension;
|
2016-04-28 22:15:32 +00:00
|
|
|
const TCHAR *str16;
|
2012-01-24 08:09:33 +00:00
|
|
|
guint16 zero = 0;
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2013-11-08 01:08:42 +00:00
|
|
|
/* Construct the list of patterns. */
|
|
|
|
extensions_list = wtap_get_file_extension_type_extensions(et);
|
|
|
|
g_string_printf(pattern_str, "");
|
|
|
|
sep = '\0';
|
|
|
|
for (extension = extensions_list; extension != NULL;
|
|
|
|
extension = g_slist_next(extension)) {
|
|
|
|
if (sep != '\0')
|
|
|
|
g_string_append_c(pattern_str, sep);
|
|
|
|
g_string_append_printf(pattern_str, "*.%s", (char *)extension->data);
|
|
|
|
sep = ';';
|
2012-01-24 05:55:00 +00:00
|
|
|
}
|
2013-11-08 01:08:42 +00:00
|
|
|
wtap_free_extensions_list(extensions_list);
|
2006-06-23 18:29:48 +00:00
|
|
|
|
2012-01-24 05:55:00 +00:00
|
|
|
/* Construct the description. */
|
2013-11-08 01:08:42 +00:00
|
|
|
g_string_printf(description_str, "%s (%s)",
|
|
|
|
wtap_get_file_extension_type_name(et),
|
2012-01-24 05:55:00 +00:00
|
|
|
pattern_str->str);
|
|
|
|
str16 = utf_8to16(description_str->str);
|
|
|
|
sa = g_array_append_vals(sa, str16, (guint) strlen(description_str->str));
|
|
|
|
sa = g_array_append_val(sa, zero);
|
2013-08-23 00:06:26 +00:00
|
|
|
g_string_free(description_str, TRUE);
|
2006-06-23 18:29:48 +00:00
|
|
|
|
2012-01-24 05:55:00 +00:00
|
|
|
str16 = utf_8to16(pattern_str->str);
|
|
|
|
sa = g_array_append_vals(sa, str16, (guint) strlen(pattern_str->str));
|
|
|
|
sa = g_array_append_val(sa, zero);
|
2013-08-23 00:06:26 +00:00
|
|
|
g_string_free(pattern_str, TRUE);
|
2006-06-23 18:29:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static TCHAR *
|
2012-01-24 05:55:00 +00:00
|
|
|
build_file_open_type_list(void) {
|
2016-04-28 22:15:32 +00:00
|
|
|
const TCHAR *str16;
|
2013-11-08 01:25:48 +00:00
|
|
|
int et;
|
2013-08-23 00:06:26 +00:00
|
|
|
GArray* sa;
|
|
|
|
static const guint16 zero = 0;
|
|
|
|
GString* pattern_str;
|
|
|
|
gchar sep;
|
|
|
|
GSList *extensions_list, *extension;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Microsoft's UI guidelines say, of the file filters in open and
|
|
|
|
* save dialogs:
|
|
|
|
*
|
|
|
|
* For meta-filters, remove the file extension list to eliminate
|
|
|
|
* clutter. Examples: "All files," "All pictures," "All music,"
|
|
|
|
* and "All videos."
|
|
|
|
*
|
|
|
|
* so we omit them (for "All Capture Files", the filter would be
|
|
|
|
* *really* long). On both Windows XP and Windows 7, Wordpad doesn't
|
|
|
|
* do that, but Paint does.
|
|
|
|
*/
|
2006-06-23 18:29:48 +00:00
|
|
|
|
2013-08-23 00:06:26 +00:00
|
|
|
/*
|
|
|
|
* Array of hexadectets used as a sequence of null-terminated
|
|
|
|
* UTF-16 strings.
|
|
|
|
*/
|
|
|
|
sa = g_array_new(FALSE /*zero_terminated*/, FALSE /*clear_*/,2 /*element_size*/);
|
2006-06-23 18:29:48 +00:00
|
|
|
|
2012-01-24 05:55:00 +00:00
|
|
|
/* Add the "All Files" entry. */
|
2013-08-23 00:06:26 +00:00
|
|
|
str16 = utf_8to16("All Files");
|
|
|
|
sa = g_array_append_vals(sa, str16, (guint) strlen("All Files"));
|
2012-01-24 05:55:00 +00:00
|
|
|
sa = g_array_append_val(sa, zero);
|
2016-02-29 21:29:19 +00:00
|
|
|
str16 = utf_8to16(ALL_FILES_WILDCARD);
|
|
|
|
sa = g_array_append_vals(sa, str16, (guint) strlen(ALL_FILES_WILDCARD));
|
2012-01-24 05:55:00 +00:00
|
|
|
sa = g_array_append_val(sa, zero);
|
2006-06-23 18:29:48 +00:00
|
|
|
|
2013-08-23 00:06:26 +00:00
|
|
|
/*
|
2016-09-10 06:44:25 +00:00
|
|
|
* Add an "All Capture Files" entry, with all the capture file
|
|
|
|
* extensions we know about.
|
2013-08-23 00:06:26 +00:00
|
|
|
*/
|
|
|
|
str16 = utf_8to16("All Capture Files");
|
|
|
|
sa = g_array_append_vals(sa, str16, (guint) strlen("All Capture Files"));
|
|
|
|
sa = g_array_append_val(sa, zero);
|
|
|
|
|
|
|
|
/*
|
2016-09-10 06:44:25 +00:00
|
|
|
* Construct its list of patterns.
|
2013-08-23 00:06:26 +00:00
|
|
|
*/
|
|
|
|
pattern_str = g_string_new("");
|
2016-09-10 06:44:25 +00:00
|
|
|
extensions_list = wtap_get_all_capture_file_extensions_list();
|
2013-08-23 00:06:26 +00:00
|
|
|
sep = '\0';
|
|
|
|
for (extension = extensions_list; extension != NULL;
|
|
|
|
extension = g_slist_next(extension)) {
|
|
|
|
if (sep != '\0')
|
|
|
|
g_string_append_c(pattern_str, sep);
|
|
|
|
g_string_append_printf(pattern_str, "*.%s", (char *)extension->data);
|
|
|
|
sep = ';';
|
|
|
|
}
|
2013-11-08 01:08:42 +00:00
|
|
|
wtap_free_extensions_list(extensions_list);
|
2013-08-23 00:06:26 +00:00
|
|
|
str16 = utf_8to16(pattern_str->str);
|
|
|
|
sa = g_array_append_vals(sa, str16, (guint) strlen(pattern_str->str));
|
|
|
|
sa = g_array_append_val(sa, zero);
|
|
|
|
|
2013-11-08 01:08:42 +00:00
|
|
|
/* Include all the file type extensions Wireshark supports. */
|
2013-11-08 01:25:48 +00:00
|
|
|
for (et = 0; et < wtap_get_num_file_type_extensions(); et++) {
|
2013-11-08 01:08:42 +00:00
|
|
|
append_file_extension_type(sa, et);
|
2012-01-24 05:55:00 +00:00
|
|
|
}
|
2012-01-21 23:44:19 +00:00
|
|
|
|
2012-01-24 05:55:00 +00:00
|
|
|
/* terminate the array */
|
|
|
|
sa = g_array_append_val(sa, zero);
|
2012-01-21 23:44:19 +00:00
|
|
|
|
2012-01-24 05:55:00 +00:00
|
|
|
return (TCHAR *) g_array_free(sa, FALSE /*free_segment*/);
|
|
|
|
}
|
2006-06-23 18:29:48 +00:00
|
|
|
|
2013-11-08 01:08:42 +00:00
|
|
|
/* Generate a list of the file types we can save this file as.
|
|
|
|
|
|
|
|
"g_filetype" is the type it has now.
|
|
|
|
|
|
|
|
"encap" is the encapsulation for its packets (which could be
|
|
|
|
"unknown" or "per-packet").
|
|
|
|
|
|
|
|
"filtered" is TRUE if we're to save only the packets that passed
|
|
|
|
the display filter (in which case we have to save it using Wiretap)
|
|
|
|
and FALSE if we're to save the entire file (in which case, if we're
|
|
|
|
saving it in the type it has already, we can just copy it).
|
|
|
|
|
|
|
|
The same applies for sel_curr, sel_all, sel_m_only, sel_m_range and sel_man_range
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
append_file_type(GArray *sa, int ft)
|
|
|
|
{
|
|
|
|
GString* pattern_str = g_string_new("");
|
|
|
|
GString* description_str = g_string_new("");
|
|
|
|
gchar sep;
|
|
|
|
GSList *extensions_list, *extension;
|
2016-04-28 22:15:32 +00:00
|
|
|
const TCHAR *str16;
|
2013-11-08 01:08:42 +00:00
|
|
|
guint16 zero = 0;
|
|
|
|
|
|
|
|
extensions_list = wtap_get_file_extensions_list(ft, TRUE);
|
|
|
|
if (extensions_list == NULL) {
|
|
|
|
/* This file type doesn't have any particular extension
|
2016-02-29 21:29:19 +00:00
|
|
|
conventionally used for it, so we'll just use a
|
|
|
|
wildcard that matches all file names - even those with
|
|
|
|
no extension, so we don't need to worry about compressed
|
|
|
|
file extensions. */
|
|
|
|
g_string_printf(pattern_str, ALL_FILES_WILDCARD);
|
2013-11-08 01:08:42 +00:00
|
|
|
} else {
|
|
|
|
/* Construct the list of patterns. */
|
|
|
|
g_string_printf(pattern_str, "");
|
|
|
|
sep = '\0';
|
|
|
|
for (extension = extensions_list; extension != NULL;
|
|
|
|
extension = g_slist_next(extension)) {
|
|
|
|
if (sep != '\0')
|
|
|
|
g_string_append_c(pattern_str, sep);
|
|
|
|
g_string_append_printf(pattern_str, "*.%s", (char *)extension->data);
|
|
|
|
sep = ';';
|
|
|
|
}
|
|
|
|
wtap_free_extensions_list(extensions_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Construct the description. */
|
2021-02-13 08:03:51 +00:00
|
|
|
g_string_printf(description_str, "%s (%s)", wtap_file_type_subtype_description(ft),
|
2013-11-08 01:08:42 +00:00
|
|
|
pattern_str->str);
|
|
|
|
str16 = utf_8to16(description_str->str);
|
|
|
|
sa = g_array_append_vals(sa, str16, (guint) strlen(description_str->str));
|
|
|
|
sa = g_array_append_val(sa, zero);
|
|
|
|
g_string_free(description_str, TRUE);
|
|
|
|
|
|
|
|
str16 = utf_8to16(pattern_str->str);
|
|
|
|
sa = g_array_append_vals(sa, str16, (guint) strlen(pattern_str->str));
|
|
|
|
sa = g_array_append_val(sa, zero);
|
|
|
|
g_string_free(pattern_str, TRUE);
|
|
|
|
}
|
|
|
|
|
2012-01-24 05:55:00 +00:00
|
|
|
static TCHAR *
|
2013-04-01 20:36:42 +00:00
|
|
|
build_file_save_type_list(GArray *savable_file_types) {
|
2012-01-24 05:55:00 +00:00
|
|
|
guint i;
|
|
|
|
int ft;
|
|
|
|
GArray* sa = g_array_new(FALSE /*zero_terminated*/, FALSE /*clear_*/,2 /*element_size*/);
|
|
|
|
guint16 zero = 0;
|
2012-01-21 08:59:21 +00:00
|
|
|
|
2012-01-24 05:55:00 +00:00
|
|
|
/* Get only the file types as which we can save this file. */
|
2012-01-24 09:29:02 +00:00
|
|
|
for (i = 0; i < savable_file_types->len; i++) {
|
|
|
|
ft = g_array_index(savable_file_types, int, i);
|
|
|
|
append_file_type(sa, ft);
|
2006-06-23 18:29:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* terminate the array */
|
|
|
|
sa = g_array_append_val(sa, zero);
|
|
|
|
|
|
|
|
return (TCHAR *) g_array_free(sa, FALSE /*free_segment*/);
|
|
|
|
}
|
|
|
|
|
2009-04-16 03:18:10 +00:00
|
|
|
static UINT_PTR CALLBACK
|
2019-12-09 18:19:01 +00:00
|
|
|
save_as_file_hook_proc(HWND sf_hwnd, UINT msg, WPARAM w_param _U_, LPARAM l_param) {
|
2006-02-13 21:25:43 +00:00
|
|
|
HWND cur_ctrl;
|
|
|
|
OFNOTIFY *notify = (OFNOTIFY *) l_param;
|
2015-09-26 14:46:52 +00:00
|
|
|
/*int new_filetype, file_index;*/
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2012-05-22 22:39:30 +00:00
|
|
|
switch(msg) {
|
2013-10-11 17:20:50 +00:00
|
|
|
case WM_INITDIALOG: {
|
|
|
|
OPENFILENAME *ofnp = (OPENFILENAME *) l_param;
|
|
|
|
capture_file *cf = (capture_file *) ofnp->lCustData;
|
2012-05-22 22:39:30 +00:00
|
|
|
g_sf_hwnd = sf_hwnd;
|
|
|
|
|
|
|
|
/* Default to saving in the file's current format. */
|
2013-10-11 17:20:50 +00:00
|
|
|
g_filetype = cf->cd_t;
|
2012-05-22 22:39:30 +00:00
|
|
|
|
|
|
|
/* Fill in the file format list */
|
|
|
|
/*build_file_format_list(sf_hwnd);*/
|
2012-09-19 23:06:39 +00:00
|
|
|
/* Fill in the compression checkbox */
|
|
|
|
cur_ctrl = GetDlgItem(sf_hwnd, EWFD_GZIP_CB);
|
2012-09-24 17:04:50 +00:00
|
|
|
SendMessage(cur_ctrl, BM_SETCHECK, g_compressed, 0);
|
2012-05-22 22:39:30 +00:00
|
|
|
|
|
|
|
break;
|
2013-10-11 17:20:50 +00:00
|
|
|
}
|
2012-05-22 22:39:30 +00:00
|
|
|
case WM_COMMAND:
|
|
|
|
break;
|
|
|
|
case WM_NOTIFY:
|
|
|
|
switch (notify->hdr.code) {
|
|
|
|
case CDN_HELP:
|
2012-10-16 19:47:43 +00:00
|
|
|
topic_action(HELP_SAVE_WIN32_DIALOG);
|
2012-05-22 22:39:30 +00:00
|
|
|
break;
|
|
|
|
case CDN_FILEOK: {
|
|
|
|
HWND parent;
|
2013-06-04 18:07:59 +00:00
|
|
|
char *file_name8;
|
2013-10-11 17:20:50 +00:00
|
|
|
OPENFILENAME *ofnp = (OPENFILENAME *) notify->lpOFN;
|
|
|
|
capture_file *cf = (capture_file *) ofnp->lCustData;
|
2012-05-22 22:39:30 +00:00
|
|
|
|
2012-09-19 23:06:39 +00:00
|
|
|
/* Fetch our compression value */
|
|
|
|
cur_ctrl = GetDlgItem(sf_hwnd, EWFD_GZIP_CB);
|
|
|
|
if (SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
|
2012-09-24 17:04:50 +00:00
|
|
|
g_compressed = TRUE;
|
2012-09-19 23:06:39 +00:00
|
|
|
else
|
2012-09-24 17:04:50 +00:00
|
|
|
g_compressed = FALSE;
|
2012-09-19 23:06:39 +00:00
|
|
|
|
2013-06-04 18:07:59 +00:00
|
|
|
/* Check if we're trying to overwrite the currently open file */
|
2012-05-22 22:39:30 +00:00
|
|
|
parent = GetParent(sf_hwnd);
|
2013-06-04 18:07:59 +00:00
|
|
|
file_name8 = utf_16to8(notify->lpOFN->lpstrFile);
|
2013-10-11 17:20:50 +00:00
|
|
|
if (files_identical(cf->filename, file_name8)) {
|
2013-06-04 18:07:59 +00:00
|
|
|
/* XXX: Is MessageBox the best way to pop up an error ? How to make text bold ? */
|
|
|
|
gchar *str = g_strdup_printf(
|
|
|
|
"Capture File \"%s\" identical to loaded file.\n\n"
|
|
|
|
"Please choose a different filename.",
|
|
|
|
file_name8);
|
|
|
|
MessageBox( parent, utf_8to16(str), _T("Error"), MB_ICONERROR | MB_APPLMODAL | MB_OK);
|
|
|
|
g_free(str);
|
|
|
|
SetWindowLongPtr(sf_hwnd, DWLP_MSGRESULT, 1L); /* Don't allow ! */
|
|
|
|
return 1;
|
2012-05-22 22:39:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define RANGE_TEXT_MAX 128
|
|
|
|
static UINT_PTR CALLBACK
|
|
|
|
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;
|
2015-09-26 14:46:52 +00:00
|
|
|
/*int new_filetype, file_index;*/
|
2012-05-22 22:39:30 +00:00
|
|
|
|
2006-02-13 21:25:43 +00:00
|
|
|
switch(msg) {
|
2013-10-11 17:20:50 +00:00
|
|
|
case WM_INITDIALOG: {
|
2009-01-19 22:37:14 +00:00
|
|
|
g_sf_hwnd = sf_hwnd;
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2011-06-30 01:05:49 +00:00
|
|
|
/* Default to saving all packets, in the file's current format. */
|
2013-10-11 17:20:50 +00:00
|
|
|
g_filetype = g_cf->cd_t;
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2009-01-19 22:37:14 +00:00
|
|
|
/* Fill in the file format list */
|
|
|
|
/*build_file_format_list(sf_hwnd);*/
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2012-10-03 19:24:14 +00:00
|
|
|
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);
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2009-01-19 22:37:14 +00:00
|
|
|
break;
|
2013-10-11 17:20:50 +00:00
|
|
|
}
|
2009-01-19 22:37:14 +00:00
|
|
|
case WM_COMMAND:
|
|
|
|
cur_ctrl = (HWND) l_param;
|
2019-12-09 18:19:01 +00:00
|
|
|
range_handle_wm_command(sf_hwnd, cur_ctrl, w_param, g_range);
|
2009-01-19 22:37:14 +00:00
|
|
|
break;
|
|
|
|
case WM_NOTIFY:
|
|
|
|
switch (notify->hdr.code) {
|
2006-08-30 20:45:13 +00:00
|
|
|
case CDN_HELP:
|
2012-10-16 19:47:43 +00:00
|
|
|
topic_action(HELP_SAVE_WIN32_DIALOG);
|
2006-08-30 20:45:13 +00:00
|
|
|
break;
|
2010-12-02 01:38:50 +00:00
|
|
|
case CDN_FILEOK: {
|
|
|
|
HWND parent;
|
2013-06-04 18:07:59 +00:00
|
|
|
char *file_name8;
|
2013-10-11 17:20:50 +00:00
|
|
|
OPENFILENAME *ofnp = (OPENFILENAME *) notify->lpOFN;
|
|
|
|
capture_file *cf = (capture_file *) ofnp->lCustData;
|
2010-12-02 01:38:50 +00:00
|
|
|
|
2012-10-03 19:24:14 +00:00
|
|
|
/* 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;
|
|
|
|
|
2013-06-04 18:07:59 +00:00
|
|
|
/* Check if we're trying to overwrite the currently open file */
|
2010-12-02 01:38:50 +00:00
|
|
|
parent = GetParent(sf_hwnd);
|
2013-06-04 18:07:59 +00:00
|
|
|
file_name8 = utf_16to8(notify->lpOFN->lpstrFile);
|
2013-10-11 17:20:50 +00:00
|
|
|
if (files_identical(cf->filename, file_name8)) {
|
2013-06-04 18:07:59 +00:00
|
|
|
/* XXX: Is MessageBox the best way to pop up an error ? How to make text bold ? */
|
|
|
|
gchar *str = g_strdup_printf(
|
|
|
|
"Capture File \"%s\" identical to loaded file.\n\n"
|
|
|
|
"Please choose a different filename.",
|
|
|
|
file_name8);
|
|
|
|
MessageBox( parent, utf_8to16(str), _T("Error"), MB_ICONERROR | MB_APPLMODAL | MB_OK);
|
|
|
|
g_free(str);
|
|
|
|
SetWindowLongPtr(sf_hwnd, DWLP_MSGRESULT, 1L); /* Don't allow ! */
|
|
|
|
return 1;
|
2010-12-02 01:38:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-01-19 22:37:14 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2006-02-13 21:25:43 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-17 01:11:05 +00:00
|
|
|
#define STATIC_LABEL_CHARS 100
|
2006-02-13 21:25:43 +00:00
|
|
|
/* For each range static control, fill in its value and enable/disable it. */
|
|
|
|
static void
|
|
|
|
range_update_dynamics(HWND dlg_hwnd, packet_range_t *range) {
|
|
|
|
HWND cur_ctrl;
|
|
|
|
gboolean filtered_active = FALSE;
|
2011-02-17 01:11:05 +00:00
|
|
|
TCHAR static_val[STATIC_LABEL_CHARS];
|
2010-01-27 11:45:16 +00:00
|
|
|
guint32 ignored_cnt = 0, displayed_ignored_cnt = 0;
|
2012-10-09 15:34:40 +00:00
|
|
|
guint32 displayed_cnt;
|
|
|
|
gboolean range_valid = TRUE;
|
2006-02-13 21:25:43 +00:00
|
|
|
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_DISPLAYED_BTN);
|
|
|
|
if (SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
|
2009-01-19 22:37:14 +00:00
|
|
|
filtered_active = TRUE;
|
2006-02-13 21:25:43 +00:00
|
|
|
|
|
|
|
/* RANGE_SELECT_ALL */
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_ALL_PKTS_CAP);
|
|
|
|
EnableWindow(cur_ctrl, !filtered_active);
|
2010-01-27 11:45:16 +00:00
|
|
|
if (range->remove_ignored) {
|
2013-10-11 17:20:50 +00:00
|
|
|
StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), g_cf->count - range->ignored_cnt);
|
2010-01-27 11:45:16 +00:00
|
|
|
} else {
|
2013-10-11 17:20:50 +00:00
|
|
|
StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), g_cf->count);
|
2010-01-27 11:45:16 +00:00
|
|
|
}
|
2006-02-13 21:25:43 +00:00
|
|
|
SetWindowText(cur_ctrl, static_val);
|
|
|
|
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_ALL_PKTS_DISP);
|
|
|
|
EnableWindow(cur_ctrl, filtered_active);
|
2012-02-28 03:19:49 +00:00
|
|
|
if (range->include_dependents)
|
|
|
|
displayed_cnt = range->displayed_plus_dependents_cnt;
|
|
|
|
else
|
|
|
|
displayed_cnt = range->displayed_cnt;
|
2010-01-27 11:45:16 +00:00
|
|
|
if (range->remove_ignored) {
|
2012-07-16 20:46:13 +00:00
|
|
|
StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), displayed_cnt - range->displayed_ignored_cnt);
|
2010-01-27 11:45:16 +00:00
|
|
|
} else {
|
2012-07-16 20:46:13 +00:00
|
|
|
StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), displayed_cnt);
|
2010-01-27 11:45:16 +00:00
|
|
|
}
|
2006-02-13 21:25:43 +00:00
|
|
|
SetWindowText(cur_ctrl, static_val);
|
|
|
|
|
|
|
|
/* RANGE_SELECT_CURR */
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_SEL_PKT_CAP);
|
2019-11-12 15:39:19 +00:00
|
|
|
EnableWindow(cur_ctrl, range->selection_range_cnt > 0 && !filtered_active);
|
|
|
|
if (range->remove_ignored) {
|
|
|
|
StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%d"), range->selection_range_cnt - range->ignored_selection_range_cnt);
|
2010-01-27 11:45:16 +00:00
|
|
|
} else {
|
2019-11-12 15:39:19 +00:00
|
|
|
StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%d"), range->selection_range_cnt);
|
2010-01-27 11:45:16 +00:00
|
|
|
}
|
2006-02-13 21:25:43 +00:00
|
|
|
SetWindowText(cur_ctrl, static_val);
|
|
|
|
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_SEL_PKT_DISP);
|
2019-11-12 15:39:19 +00:00
|
|
|
EnableWindow(cur_ctrl, range->displayed_selection_range_cnt > 0 && filtered_active);
|
|
|
|
if (range->remove_ignored) {
|
|
|
|
StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%d"), range->displayed_selection_range_cnt - range->displayed_ignored_selection_range_cnt);
|
2010-01-27 11:45:16 +00:00
|
|
|
} else {
|
2019-11-12 15:39:19 +00:00
|
|
|
StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%d"), range->displayed_selection_range_cnt);
|
2010-01-27 11:45:16 +00:00
|
|
|
}
|
2006-02-13 21:25:43 +00:00
|
|
|
SetWindowText(cur_ctrl, static_val);
|
|
|
|
|
|
|
|
/* RANGE_SELECT_MARKED */
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_MARKED_BTN);
|
2013-10-11 17:20:50 +00:00
|
|
|
EnableWindow(cur_ctrl, g_cf->marked_count);
|
2006-02-13 21:25:43 +00:00
|
|
|
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_MARKED_CAP);
|
2013-10-11 17:20:50 +00:00
|
|
|
EnableWindow(cur_ctrl, g_cf->marked_count && !filtered_active);
|
2010-01-27 11:45:16 +00:00
|
|
|
if (range->remove_ignored) {
|
2013-10-11 17:20:50 +00:00
|
|
|
StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), g_cf->marked_count - range->ignored_marked_cnt);
|
2010-01-27 11:45:16 +00:00
|
|
|
} else {
|
2013-10-11 17:20:50 +00:00
|
|
|
StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), g_cf->marked_count);
|
2010-01-27 11:45:16 +00:00
|
|
|
}
|
2006-02-13 21:25:43 +00:00
|
|
|
SetWindowText(cur_ctrl, static_val);
|
|
|
|
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_MARKED_DISP);
|
2013-10-11 17:20:50 +00:00
|
|
|
EnableWindow(cur_ctrl, g_cf->marked_count && filtered_active);
|
2010-01-27 11:45:16 +00:00
|
|
|
if (range->remove_ignored) {
|
2012-07-16 20:46:13 +00:00
|
|
|
StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->displayed_marked_cnt - range->displayed_ignored_marked_cnt);
|
2010-01-27 11:45:16 +00:00
|
|
|
} else {
|
2012-07-16 20:46:13 +00:00
|
|
|
StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->displayed_marked_cnt);
|
2010-01-27 11:45:16 +00:00
|
|
|
}
|
2006-02-13 21:25:43 +00:00
|
|
|
SetWindowText(cur_ctrl, static_val);
|
|
|
|
|
|
|
|
/* RANGE_SELECT_MARKED_RANGE */
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_FIRST_LAST_BTN);
|
|
|
|
EnableWindow(cur_ctrl, range->mark_range_cnt);
|
|
|
|
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_FIRST_LAST_CAP);
|
|
|
|
EnableWindow(cur_ctrl, range->mark_range_cnt && !filtered_active);
|
2010-01-27 11:45:16 +00:00
|
|
|
if (range->remove_ignored) {
|
2012-07-16 20:46:13 +00:00
|
|
|
StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->mark_range_cnt - range->ignored_mark_range_cnt);
|
2010-01-27 11:45:16 +00:00
|
|
|
} else {
|
2012-07-16 20:46:13 +00:00
|
|
|
StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->mark_range_cnt);
|
2010-01-27 11:45:16 +00:00
|
|
|
}
|
2006-02-13 21:25:43 +00:00
|
|
|
SetWindowText(cur_ctrl, static_val);
|
|
|
|
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_FIRST_LAST_DISP);
|
|
|
|
EnableWindow(cur_ctrl, range->displayed_mark_range_cnt && filtered_active);
|
2010-01-27 11:45:16 +00:00
|
|
|
if (range->remove_ignored) {
|
2012-07-16 20:46:13 +00:00
|
|
|
StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->displayed_mark_range_cnt - range->displayed_ignored_mark_range_cnt);
|
2010-01-27 11:45:16 +00:00
|
|
|
} else {
|
2012-07-16 20:46:13 +00:00
|
|
|
StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->displayed_mark_range_cnt);
|
2010-01-27 11:45:16 +00:00
|
|
|
}
|
2006-02-13 21:25:43 +00:00
|
|
|
SetWindowText(cur_ctrl, static_val);
|
|
|
|
|
|
|
|
/* RANGE_SELECT_USER */
|
2012-10-09 15:34:40 +00:00
|
|
|
switch (packet_range_check(range)) {
|
|
|
|
case CVT_NO_ERROR:
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_EDIT);
|
|
|
|
SendMessage(cur_ctrl, EM_SETBKGNDCOLOR, (WPARAM) 1, COLOR_WINDOW);
|
|
|
|
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_CAP);
|
|
|
|
EnableWindow(cur_ctrl, !filtered_active);
|
|
|
|
if (range->remove_ignored) {
|
|
|
|
StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->user_range_cnt - range->ignored_user_range_cnt);
|
|
|
|
} else {
|
|
|
|
StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->user_range_cnt);
|
|
|
|
}
|
|
|
|
SetWindowText(cur_ctrl, static_val);
|
2012-10-16 18:14:16 +00:00
|
|
|
|
2012-10-09 15:34:40 +00:00
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_DISP);
|
|
|
|
EnableWindow(cur_ctrl, filtered_active);
|
|
|
|
if (range->remove_ignored) {
|
|
|
|
StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->displayed_user_range_cnt - range->displayed_ignored_user_range_cnt);
|
|
|
|
} else {
|
|
|
|
StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->displayed_user_range_cnt);
|
|
|
|
}
|
|
|
|
SetWindowText(cur_ctrl, static_val);
|
|
|
|
break;
|
|
|
|
case CVT_SYNTAX_ERROR:
|
|
|
|
if (range->process == range_process_user_range) range_valid = FALSE;
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_EDIT);
|
|
|
|
SendMessage(cur_ctrl, EM_SETBKGNDCOLOR, 0, RGB(0xff, 0xcc, 0xcc));
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_CAP);
|
|
|
|
SetWindowText(cur_ctrl, _T("Bad range"));
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_DISP);
|
|
|
|
SetWindowText(cur_ctrl, _T("-"));
|
|
|
|
break;
|
|
|
|
case CVT_NUMBER_TOO_BIG:
|
|
|
|
if (range->process == range_process_user_range) range_valid = FALSE;
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_EDIT);
|
|
|
|
SendMessage(cur_ctrl, EM_SETBKGNDCOLOR, 0, RGB(0xff, 0xcc, 0xcc));
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_CAP);
|
|
|
|
SetWindowText(cur_ctrl, _T("Too large"));
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_DISP);
|
|
|
|
SetWindowText(cur_ctrl, _T("-"));
|
|
|
|
break;
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2012-10-09 15:34:40 +00:00
|
|
|
default:
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert_not_reached();
|
2010-01-27 11:45:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* RANGE_REMOVE_IGNORED_PACKETS */
|
|
|
|
switch(range->process) {
|
|
|
|
case(range_process_all):
|
|
|
|
ignored_cnt = range->ignored_cnt;
|
|
|
|
displayed_ignored_cnt = range->displayed_ignored_cnt;
|
|
|
|
break;
|
|
|
|
case(range_process_selected):
|
2019-11-12 15:39:19 +00:00
|
|
|
ignored_cnt = range->ignored_selection_range_cnt;
|
|
|
|
displayed_ignored_cnt = range->displayed_ignored_selection_range_cnt;
|
2010-01-27 11:45:16 +00:00
|
|
|
break;
|
|
|
|
case(range_process_marked):
|
|
|
|
ignored_cnt = range->ignored_marked_cnt;
|
|
|
|
displayed_ignored_cnt = range->displayed_ignored_marked_cnt;
|
|
|
|
break;
|
|
|
|
case(range_process_marked_range):
|
|
|
|
ignored_cnt = range->ignored_mark_range_cnt;
|
|
|
|
displayed_ignored_cnt = range->displayed_ignored_mark_range_cnt;
|
|
|
|
break;
|
|
|
|
case(range_process_user_range):
|
|
|
|
ignored_cnt = range->ignored_user_range_cnt;
|
|
|
|
displayed_ignored_cnt = range->displayed_ignored_user_range_cnt;
|
|
|
|
break;
|
|
|
|
default:
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert_not_reached();
|
2010-01-27 11:45:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_REMOVE_IGN_CB);
|
|
|
|
EnableWindow(cur_ctrl, ignored_cnt);
|
|
|
|
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_IGNORED_CAP);
|
2010-01-27 11:55:57 +00:00
|
|
|
EnableWindow(cur_ctrl, ignored_cnt && !filtered_active);
|
2012-07-16 20:46:13 +00:00
|
|
|
StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), ignored_cnt);
|
2010-01-27 11:45:16 +00:00
|
|
|
SetWindowText(cur_ctrl, static_val);
|
|
|
|
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_IGNORED_DISP);
|
2010-01-27 11:55:57 +00:00
|
|
|
EnableWindow(cur_ctrl, displayed_ignored_cnt && filtered_active);
|
2012-07-16 20:46:13 +00:00
|
|
|
StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), displayed_ignored_cnt);
|
2006-02-13 21:25:43 +00:00
|
|
|
SetWindowText(cur_ctrl, static_val);
|
2012-10-09 15:34:40 +00:00
|
|
|
|
|
|
|
cur_ctrl = GetDlgItem(GetParent(dlg_hwnd), IDOK);
|
|
|
|
EnableWindow(cur_ctrl, range_valid);
|
2006-02-13 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
range_handle_wm_initdialog(HWND dlg_hwnd, packet_range_t *range) {
|
|
|
|
HWND cur_ctrl;
|
|
|
|
|
|
|
|
/* Set the appropriate captured/displayed radio */
|
|
|
|
if (range->process_filtered)
|
2009-01-19 22:37:14 +00:00
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_DISPLAYED_BTN);
|
2006-02-13 21:25:43 +00:00
|
|
|
else
|
2009-01-19 22:37:14 +00:00
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_CAPTURED_BTN);
|
2006-02-13 21:25:43 +00:00
|
|
|
SendMessage(cur_ctrl, BM_SETCHECK, TRUE, 0);
|
|
|
|
|
2012-10-09 15:34:40 +00:00
|
|
|
/* Retain the filter text, and fill it in. */
|
|
|
|
if(range->user_range != NULL) {
|
2015-01-10 00:50:09 +00:00
|
|
|
char* tmp_str;
|
2012-10-09 15:34:40 +00:00
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_EDIT);
|
2015-01-10 00:50:09 +00:00
|
|
|
tmp_str = range_convert_range(NULL, range->user_range);
|
|
|
|
SetWindowText(cur_ctrl, utf_8to16(tmp_str));
|
|
|
|
wmem_free(NULL, tmp_str);
|
2012-10-09 15:34:40 +00:00
|
|
|
}
|
|
|
|
|
2006-02-13 21:25:43 +00:00
|
|
|
/* dynamic values in the range frame */
|
|
|
|
range_update_dynamics(dlg_hwnd, range);
|
|
|
|
|
|
|
|
/* Set the appropriate range radio */
|
|
|
|
switch(range->process) {
|
2009-01-19 22:37:14 +00:00
|
|
|
case(range_process_all):
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_ALL_PKTS_BTN);
|
|
|
|
break;
|
|
|
|
case(range_process_selected):
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_SEL_PKT_BTN);
|
|
|
|
break;
|
|
|
|
case(range_process_marked):
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_MARKED_BTN);
|
|
|
|
break;
|
|
|
|
case(range_process_marked_range):
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_FIRST_LAST_BTN);
|
|
|
|
break;
|
|
|
|
case(range_process_user_range):
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_BTN);
|
|
|
|
break;
|
|
|
|
default:
|
2021-06-18 18:21:42 +00:00
|
|
|
ws_assert_not_reached();
|
2006-02-13 21:25:43 +00:00
|
|
|
}
|
|
|
|
SendMessage(cur_ctrl, BM_SETCHECK, TRUE, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
range_handle_wm_command(HWND dlg_hwnd, HWND ctrl, WPARAM w_param, packet_range_t *range) {
|
|
|
|
HWND cur_ctrl;
|
2009-01-20 23:33:38 +00:00
|
|
|
TCHAR range_text[RANGE_TEXT_MAX];
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2012-10-03 19:45:05 +00:00
|
|
|
if (!range) return;
|
2012-10-05 18:52:42 +00:00
|
|
|
|
2006-02-13 21:25:43 +00:00
|
|
|
switch(w_param) {
|
2009-01-19 22:37:14 +00:00
|
|
|
case (BN_CLICKED << 16) | EWFD_CAPTURED_BTN:
|
|
|
|
case (BN_CLICKED << 16) | EWFD_DISPLAYED_BTN:
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_CAPTURED_BTN);
|
|
|
|
if (SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
|
|
|
|
range->process_filtered = FALSE;
|
|
|
|
else
|
|
|
|
range->process_filtered = TRUE;
|
|
|
|
range_update_dynamics(dlg_hwnd, range);
|
|
|
|
break;
|
|
|
|
case (BN_CLICKED << 16) | EWFD_ALL_PKTS_BTN:
|
|
|
|
if (SendMessage(ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED) {
|
|
|
|
range->process = range_process_all;
|
|
|
|
range_update_dynamics(dlg_hwnd, range);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case (BN_CLICKED << 16) | EWFD_SEL_PKT_BTN:
|
|
|
|
if (SendMessage(ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED) {
|
|
|
|
range->process = range_process_selected;
|
|
|
|
range_update_dynamics(dlg_hwnd, range);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case (BN_CLICKED << 16) | EWFD_MARKED_BTN:
|
|
|
|
if (SendMessage(ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED) {
|
|
|
|
range->process = range_process_marked;
|
|
|
|
range_update_dynamics(dlg_hwnd, range);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case (BN_CLICKED << 16) | EWFD_FIRST_LAST_BTN:
|
|
|
|
if (SendMessage(ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED) {
|
|
|
|
range->process = range_process_marked_range;
|
|
|
|
range_update_dynamics(dlg_hwnd, range);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case (BN_CLICKED << 16) | EWFD_RANGE_BTN:
|
|
|
|
if (SendMessage(ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED) {
|
|
|
|
range->process = range_process_user_range;
|
|
|
|
range_update_dynamics(dlg_hwnd, range);
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_EDIT);
|
|
|
|
SetFocus(cur_ctrl);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case (EN_SETFOCUS << 16) | EWFD_RANGE_EDIT:
|
|
|
|
cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_BTN);
|
|
|
|
SendMessage(cur_ctrl, BM_CLICK, 0, 0);
|
|
|
|
break;
|
2012-10-09 15:34:40 +00:00
|
|
|
case (EN_UPDATE << 16) | EWFD_RANGE_EDIT:
|
2009-01-19 22:37:14 +00:00
|
|
|
SendMessage(ctrl, WM_GETTEXT, (WPARAM) RANGE_TEXT_MAX, (LPARAM) range_text);
|
2009-01-20 23:33:38 +00:00
|
|
|
packet_range_convert_str(range, utf_16to8(range_text));
|
2009-01-19 22:37:14 +00:00
|
|
|
range_update_dynamics(dlg_hwnd, range);
|
|
|
|
break;
|
2010-01-27 11:45:16 +00:00
|
|
|
case (BN_CLICKED << 16) | EWFD_REMOVE_IGN_CB:
|
|
|
|
if (SendMessage(ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED) {
|
|
|
|
range->remove_ignored = TRUE;
|
|
|
|
} else {
|
|
|
|
range->remove_ignored = FALSE;
|
|
|
|
}
|
|
|
|
range_update_dynamics(dlg_hwnd, range);
|
|
|
|
break;
|
2006-02-13 21:25:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-16 03:18:10 +00:00
|
|
|
static UINT_PTR CALLBACK
|
2006-02-13 21:25:43 +00:00
|
|
|
merge_file_hook_proc(HWND mf_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
|
|
|
|
HWND cur_ctrl, parent;
|
|
|
|
OFNOTIFY *notify = (OFNOTIFY *) l_param;
|
2006-03-08 20:55:32 +00:00
|
|
|
TCHAR sel_name[MAX_PATH];
|
2006-02-13 21:25:43 +00:00
|
|
|
|
|
|
|
switch(msg) {
|
2009-01-19 22:37:14 +00:00
|
|
|
case WM_INITDIALOG:
|
|
|
|
/* Retain the filter text, and fill it in. */
|
2012-09-10 21:27:49 +00:00
|
|
|
if(g_dfilter_str != NULL) {
|
2006-08-30 20:45:13 +00:00
|
|
|
cur_ctrl = GetDlgItem(mf_hwnd, EWFD_FILTER_EDIT);
|
2012-09-10 21:27:49 +00:00
|
|
|
SetWindowText(cur_ctrl, utf_8to16(g_dfilter_str));
|
2006-08-30 20:45:13 +00:00
|
|
|
}
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
/* Chrono by default */
|
|
|
|
cur_ctrl = GetDlgItem(mf_hwnd, EWFD_MERGE_CHRONO_BTN);
|
2009-01-19 22:37:14 +00:00
|
|
|
SendMessage(cur_ctrl, BM_SETCHECK, TRUE, 0);
|
2012-09-10 21:27:49 +00:00
|
|
|
g_merge_action = merge_append;
|
2009-01-19 22:37:14 +00:00
|
|
|
|
2012-07-21 01:14:08 +00:00
|
|
|
preview_set_file_info(mf_hwnd, NULL);
|
2009-01-19 22:37:14 +00:00
|
|
|
break;
|
|
|
|
case WM_NOTIFY:
|
|
|
|
switch (notify->hdr.code) {
|
|
|
|
case CDN_FILEOK:
|
|
|
|
/* Fetch the read filter */
|
2006-08-30 20:45:13 +00:00
|
|
|
cur_ctrl = GetDlgItem(mf_hwnd, EWFD_FILTER_EDIT);
|
2017-08-26 08:30:47 +00:00
|
|
|
g_free(g_dfilter_str);
|
2012-09-10 21:27:49 +00:00
|
|
|
g_dfilter_str = filter_tb_get(cur_ctrl);
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2009-01-19 22:37:14 +00:00
|
|
|
cur_ctrl = GetDlgItem(mf_hwnd, EWFD_MERGE_CHRONO_BTN);
|
|
|
|
if(SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED) {
|
2012-09-10 21:27:49 +00:00
|
|
|
g_merge_action = merge_chrono;
|
2009-01-19 22:37:14 +00:00
|
|
|
} else {
|
|
|
|
cur_ctrl = GetDlgItem(mf_hwnd, EWFD_MERGE_PREPEND_BTN);
|
|
|
|
if(SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED) {
|
2012-09-10 21:27:49 +00:00
|
|
|
g_merge_action = merge_prepend;
|
2009-01-19 22:37:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case CDN_SELCHANGE:
|
|
|
|
/* This _almost_ works correctly. We need to handle directory
|
|
|
|
selections, etc. */
|
|
|
|
parent = GetParent(mf_hwnd);
|
2012-07-21 01:14:08 +00:00
|
|
|
CommDlg_OpenSave_GetFilePath(parent, sel_name, MAX_PATH);
|
|
|
|
preview_set_file_info(mf_hwnd, utf_16to8(sel_name));
|
2009-01-19 22:37:14 +00:00
|
|
|
break;
|
2006-08-30 20:45:13 +00:00
|
|
|
case CDN_HELP:
|
2012-10-16 19:47:43 +00:00
|
|
|
topic_action(HELP_MERGE_WIN32_DIALOG);
|
2006-08-30 20:45:13 +00:00
|
|
|
break;
|
2009-01-19 22:37:14 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_COMMAND:
|
|
|
|
cur_ctrl = (HWND) l_param;
|
|
|
|
switch(w_param) {
|
|
|
|
case (EN_UPDATE << 16) | EWFD_FILTER_EDIT:
|
|
|
|
filter_tb_syntax_check(cur_ctrl, NULL);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2006-02-13 21:25:43 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-16 03:18:10 +00:00
|
|
|
static UINT_PTR CALLBACK
|
2006-02-13 21:25:43 +00:00
|
|
|
export_file_hook_proc(HWND ef_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
|
|
|
|
HWND cur_ctrl;
|
|
|
|
OFNOTIFY *notify = (OFNOTIFY *) l_param;
|
|
|
|
gboolean pkt_fmt_enable;
|
2015-09-26 14:46:52 +00:00
|
|
|
int i, filter_index;
|
2006-02-13 21:25:43 +00:00
|
|
|
|
|
|
|
switch(msg) {
|
2013-10-11 17:20:50 +00:00
|
|
|
case WM_INITDIALOG: {
|
2011-10-05 05:40:34 +00:00
|
|
|
/* default to displayed packets */
|
|
|
|
print_args.range.process_filtered = TRUE;
|
2009-01-19 22:37:14 +00:00
|
|
|
range_handle_wm_initdialog(ef_hwnd, &print_args.range);
|
|
|
|
format_handle_wm_initdialog(ef_hwnd, &print_args);
|
|
|
|
|
|
|
|
break;
|
2013-10-11 17:20:50 +00:00
|
|
|
}
|
2009-01-19 22:37:14 +00:00
|
|
|
case WM_COMMAND:
|
|
|
|
cur_ctrl = (HWND) l_param;
|
|
|
|
switch (w_param) {
|
|
|
|
case (CBN_SELCHANGE << 16) | EWFD_PKT_DETAIL_COMBO:
|
|
|
|
default:
|
|
|
|
range_handle_wm_command(ef_hwnd, cur_ctrl, w_param, &print_args.range);
|
|
|
|
print_update_dynamic(ef_hwnd, &print_args);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_NOTIFY:
|
|
|
|
switch (notify->hdr.code) {
|
|
|
|
case CDN_FILEOK:
|
|
|
|
break;
|
|
|
|
case CDN_TYPECHANGE:
|
2015-09-26 14:46:52 +00:00
|
|
|
filter_index = notify->lpOFN->nFilterIndex;
|
2009-01-19 22:37:14 +00:00
|
|
|
|
2015-09-26 14:46:52 +00:00
|
|
|
if (filter_index == 2) /* PostScript */
|
2009-01-19 22:37:14 +00:00
|
|
|
print_args.format = PR_FMT_TEXT;
|
|
|
|
else
|
|
|
|
print_args.format = PR_FMT_PS;
|
2015-09-26 14:46:52 +00:00
|
|
|
if (filter_index == 3 || filter_index == 4 || filter_index == 5 || filter_index == 6)
|
2009-01-19 22:37:14 +00:00
|
|
|
pkt_fmt_enable = FALSE;
|
|
|
|
else
|
|
|
|
pkt_fmt_enable = TRUE;
|
|
|
|
for (i = EWFD_PKT_FORMAT_GB; i <= EWFD_PKT_NEW_PAGE_CB; i++) {
|
|
|
|
cur_ctrl = GetDlgItem(ef_hwnd, i);
|
|
|
|
EnableWindow(cur_ctrl, pkt_fmt_enable);
|
|
|
|
}
|
|
|
|
break;
|
2006-08-30 20:45:13 +00:00
|
|
|
case CDN_HELP:
|
2012-10-16 19:47:43 +00:00
|
|
|
topic_action(HELP_EXPORT_FILE_WIN32_DIALOG);
|
2006-08-30 20:45:13 +00:00
|
|
|
break;
|
2009-01-19 22:37:14 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2006-02-13 21:25:43 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-11 21:38:14 +00:00
|
|
|
#endif // _WIN32
|