Have the frame_tvbuff.c routines not use the global cfile.
[metze/wireshark/wip.git] / ui / win32 / file_dlg_win32.c
index 57a8aa04197a978edd91a31f60fd12ec72569d7f..ebfc57590043305a5026409a8391bc4ff9534f5a 100644 (file)
@@ -1,23 +1,11 @@
-/* win32-file-dlg.c
+/* file_dlg_win32.c
  * Native Windows file dialog routines
  *
  * Wireshark - Network traffic analyzer
  * By Gerald Combs <gerald@wireshark.org>
  * Copyright 2004 Gerald Combs
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: GPL-2.0+
  */
 
 #include "config.h"
 #include <richedit.h>
 #include <strsafe.h>
 
-#include "file.h"
+#include "globals.h"
 
 #include "wsutil/file_util.h"
+#include "wsutil/str_util.h"
 #include "wsutil/unicode-utils.h"
 
-
 #include "wsutil/filesystem.h"
-#include "epan/addr_resolv.h"
 #include "epan/prefs.h"
 
-#include "color_filters.h"
+#include "epan/color_filters.h"
 
 #include "ui/alert_box.h"
 #include "ui/help_url.h"
@@ -49,6 +36,8 @@
 #include "ui/simple_dialog.h"
 #include "ui/ssl_key_export.h"
 #include "ui/util.h"
+#include "ui/ws_ui_util.h"
+#include "ui/all_files_wildcard.h"
 
 #include "file_dlg_win32.h"
 
     _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")  \
-    _T("C Arrays (packet bytes) (*.c)\0")                _T("*.c\0")
+    _T("C Arrays (packet bytes) (*.c)\0")                _T("*.c\0")     \
+    _T("JSON (*.json)\0")                                _T("*.json\0")
 
 #define FILE_TYPES_RAW \
     _T("Raw data (*.bin, *.dat, *.raw)\0")               _T("*.bin;*.dat;*.raw\0") \
-    _T("All Files (*.*)\0")                              _T("*.*\0")
+    _T("All Files (") _T(ALL_FILES_WILDCARD) _T(")\0")   _T(ALL_FILES_WILDCARD) _T("\0")
 
 #define FILE_RAW_DEFAULT 1
 
 #define FILE_TYPES_SSLKEYS \
     _T("SSL Session Keys (*.keys)\0")                    _T("*.keys\0") \
-    _T("All Files (*.*)\0")                              _T("*.*\0")
+    _T("All Files (") _T(ALL_FILES_WILDCARD) _T(")\0")   _T(ALL_FILES_WILDCARD) _T("\0")
 
 #define FILE_SSLKEYS_DEFAULT 1
 
 #define FILE_TYPES_COLOR \
     _T("Text Files (*.txt)\0")                           _T("*.txt\0")   \
-    _T("All Files (*.*)\0")                              _T("*.*\0")
+    _T("All Files (") _T(ALL_FILES_WILDCARD) _T(")\0")   _T(ALL_FILES_WILDCARD) _T("\0")
 
 #define FILE_DEFAULT_COLOR 2
 
@@ -269,24 +259,22 @@ win32_check_save_as_with_comments(HWND parent, capture_file *cf, int file_type)
            format you selected", or "Cancel", meaning "don't bother
            saving the file at all".
 
-           XXX - sadly, customizing buttons in a MessageBox() is
-           Really Painful; there are tricks out there to do it
-           with a "computer-based training" hook that gets called
-           before the window is activated and sets the text of the
-           buttons, but if you change the text of the buttons you
-           also have to make the buttons bigger.  There *has* to
-           be a better way of doing that, given that Microsoft's
-           own UI guidelines have examples of dialog boxes with
-           action buttons that have custom labels, but maybe we'd
-           have to go with Windows Forms or XAML or whatever the
-           heck the technology of the week is.
-
-           Therefore, we ask a yes-or-no question - "do you want
-           to discard the comments and save in the format you
-           chose?" - and have "no" mean "I want to save the
-           file but I don't want to discard the comments, meaning
-           we should reopen the dialog and not offer the user any
-           choices that would involve discarding the comments. */
+           XXX - given that we no longer support releases prior to
+           Windows Vista, we should use a task dialog:
+
+               https://msdn.microsoft.com/en-us/library/windows/desktop/ff486057(v=vs.85).aspx
+
+           created with TaskDialogIndirect():
+
+               https://msdn.microsoft.com/en-us/library/windows/desktop/bb760544(v=vs.85).aspx
+
+           because the TASKDIALOGCONFIG structure
+
+               https://msdn.microsoft.com/en-us/library/windows/desktop/bb787473(v=vs.85).aspx
+
+           supports adding custom buttons, with custom labels, unlike
+           a MessageBox(), which doesn't appear to offer a clean way to
+           do that. */
         response = MessageBox(parent,
   _T("The capture has comments, but the file format you chose ")
   _T("doesn't support comments.  Do you want to discard the comments ")
@@ -684,6 +672,7 @@ win32_export_file(HWND h_wnd, capture_file *cf, export_type_e export_type) {
     print_args.print_dissections   = print_dissections_as_displayed;
     print_args.print_hex           = FALSE;
     print_args.print_formfeed      = FALSE;
+    print_args.stream              = NULL;
 
     if (GetSaveFileName(ofn)) {
         print_args.file = utf_16to8(file_name);
@@ -695,7 +684,7 @@ win32_export_file(HWND h_wnd, capture_file *cf, export_type_e export_type) {
                     g_free( (void *) ofn);
                     return;
                 }
-                status = cf_print_packets(cf, &print_args);
+                status = cf_print_packets(cf, &print_args, TRUE);
                 break;
             case export_type_ps:        /* PostScript (r) */
                 print_args.stream = print_stream_ps_new(TRUE, print_args.file);
@@ -704,7 +693,7 @@ win32_export_file(HWND h_wnd, capture_file *cf, export_type_e export_type) {
                     g_free( (void *) ofn);
                     return;
                 }
-                status = cf_print_packets(cf, &print_args);
+                status = cf_print_packets(cf, &print_args, TRUE);
                 break;
             case export_type_csv:       /* CSV */
                 status = cf_write_csv_packets(cf, &print_args);
@@ -718,6 +707,9 @@ win32_export_file(HWND h_wnd, capture_file *cf, export_type_e export_type) {
             case export_type_pdml:      /* PDML */
                 status = cf_write_pdml_packets(cf, &print_args);
                 break;
+            case export_type_json:      /* JSON */
+                status = cf_write_json_packets(cf, &print_args);
+                break;
             default:
                 g_free( (void *) ofn);
                 return;
@@ -797,12 +789,12 @@ win32_export_raw_file(HWND h_wnd, capture_file *cf) {
             open_failure_alert_box(file_name8, errno, TRUE);
             return;
         }
-        if (write(fd, data_p, cf->finfo_selected->length) < 0) {
+        if (ws_write(fd, data_p, cf->finfo_selected->length) < 0) {
             write_failure_alert_box(file_name8, errno);
-            close(fd);
+            ws_close(fd);
             return;
         }
-        if (close(fd) < 0) {
+        if (ws_close(fd) < 0) {
             write_failure_alert_box(file_name8, errno);
             return;
         }
@@ -898,6 +890,7 @@ win32_export_color_file(HWND h_wnd, capture_file *cf, gpointer filter_list) {
     TCHAR  file_name[MAX_PATH] = _T("");
     gchar *dirname;
     int    ofnsize;
+    gchar *err_msg = NULL;
 
     ofnsize = win32_get_ofnsize();
     ofn = g_malloc0(ofnsize);
@@ -927,8 +920,12 @@ win32_export_color_file(HWND h_wnd, capture_file *cf, gpointer filter_list) {
     /* XXX - Support marked filters */
     if (GetSaveFileName(ofn)) {
         g_free( (void *) ofn);
-        if (!color_filters_export(utf_16to8(file_name), filter_list, FALSE /* all filters */))
+        if (!color_filters_export(utf_16to8(file_name), filter_list, FALSE /* all filters */, &err_msg))
+        {
+            simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg);
+            g_free(err_msg);
             return;
+        }
 
         /* Save the directory name for future file dialogs. */
         dirname = get_dirname(utf_16to8(file_name));  /* Overwrites cf_name */
@@ -944,6 +941,7 @@ win32_import_color_file(HWND h_wnd, gpointer color_filters) {
     TCHAR  file_name[MAX_PATH] = _T("");
     gchar *dirname;
     int    ofnsize;
+    gchar *err_msg = NULL;
 
     ofnsize = win32_get_ofnsize();
     ofn = g_malloc0(ofnsize);
@@ -971,8 +969,11 @@ win32_import_color_file(HWND h_wnd, gpointer color_filters) {
     /* XXX - Support export limited to selected filters */
     if (GetOpenFileName(ofn)) {
         g_free( (void *) ofn);
-        if (!color_filters_import(utf_16to8(file_name), color_filters))
+        if (!color_filters_import(utf_16to8(file_name), color_filters, &err_msg, color_filter_add_cb)) {
+            simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg);
+            g_free(err_msg);
             return;
+        }
 
         /* Save the directory name for future file dialogs. */
         dirname = get_dirname(utf_16to8(file_name));  /* Overwrites cf_name */
@@ -1108,9 +1109,11 @@ preview_set_file_info(HWND of_hwnd, gchar *preview_file) {
     int         err = 0;
     gchar      *err_info;
     TCHAR       string_buff[PREVIEW_STR_MAX];
+    TCHAR       first_buff[PREVIEW_STR_MAX];
     gint64      data_offset;
     guint       packet = 0;
     gint64      filesize;
+    gchar      *size_str;
     time_t      ti_time;
     struct tm  *ti_tm;
     guint       elapsed_time;
@@ -1121,14 +1124,14 @@ preview_set_file_info(HWND of_hwnd, gchar *preview_file) {
     double      cur_time;
     gboolean    is_breaked = FALSE;
 
-    for (i = EWFD_PTX_FORMAT; i <= EWFD_PTX_ELAPSED; i++) {
+    for (i = EWFD_PTX_FORMAT; i <= EWFD_PTX_START_ELAPSED; i++) {
         cur_ctrl = GetDlgItem(of_hwnd, i);
         if (cur_ctrl) {
             EnableWindow(cur_ctrl, FALSE);
         }
     }
 
-    for (i = EWFD_PTX_FORMAT; i <= EWFD_PTX_ELAPSED; i++) {
+    for (i = EWFD_PTX_FORMAT; i <= EWFD_PTX_START_ELAPSED; i++) {
         cur_ctrl = GetDlgItem(of_hwnd, i);
         if (cur_ctrl) {
             SetWindowText(cur_ctrl, _T("-"));
@@ -1157,7 +1160,7 @@ preview_set_file_info(HWND of_hwnd, gchar *preview_file) {
     }
 
     /* Success! */
-    for (i = EWFD_PT_FORMAT; i <= EWFD_PTX_ELAPSED; i++) {
+    for (i = EWFD_PT_FORMAT; i <= EWFD_PTX_START_ELAPSED; i++) {
         cur_ctrl = GetDlgItem(of_hwnd, i);
         if (cur_ctrl) {
             EnableWindow(cur_ctrl, TRUE);
@@ -1170,9 +1173,8 @@ preview_set_file_info(HWND of_hwnd, gchar *preview_file) {
 
     /* Size */
     filesize = wtap_file_size(wth, &err);
-    utf_8to16_snprintf(string_buff, PREVIEW_STR_MAX, "%" G_GINT64_FORMAT " bytes", filesize);
-    cur_ctrl = GetDlgItem(of_hwnd, EWFD_PTX_SIZE);
-    SetWindowText(cur_ctrl, string_buff);
+    // Windows Explorer uses IEC.
+    size_str = format_size(filesize, format_size_unit_bytes|format_size_prefix_iec);
 
     time(&time_preview);
     while ( (wtap_read(wth, &err, &err_info, &data_offset)) ) {
@@ -1199,8 +1201,10 @@ preview_set_file_info(HWND of_hwnd, gchar *preview_file) {
     }
 
     if(err != 0) {
-        StringCchPrintf(string_buff, PREVIEW_STR_MAX, _T("error after reading %u packets"), packet);
-        cur_ctrl = GetDlgItem(of_hwnd, EWFD_PTX_PACKETS);
+        utf_8to16_snprintf(string_buff, PREVIEW_STR_MAX, "%s, error after %u packets",
+            size_str, packet);
+        g_free(size_str);
+        cur_ctrl = GetDlgItem(of_hwnd, EWFD_PTX_SIZE);
         SetWindowText(cur_ctrl, string_buff);
         wtap_close(wth);
         return TRUE;
@@ -1208,18 +1212,21 @@ preview_set_file_info(HWND of_hwnd, gchar *preview_file) {
 
     /* Packets */
     if(is_breaked) {
-        StringCchPrintf(string_buff, PREVIEW_STR_MAX, _T("more than %u packets (preview timeout)"), packet);
+        utf_8to16_snprintf(string_buff, PREVIEW_STR_MAX, "%s, timed out at %u packets",
+            size_str, packet);
     } else {
-        StringCchPrintf(string_buff, PREVIEW_STR_MAX, _T("%u"), packet);
+        utf_8to16_snprintf(string_buff, PREVIEW_STR_MAX, "%s, %u packets",
+            size_str, packet);
     }
-    cur_ctrl = GetDlgItem(of_hwnd, EWFD_PTX_PACKETS);
+    g_free(size_str);
+    cur_ctrl = GetDlgItem(of_hwnd, EWFD_PTX_SIZE);
     SetWindowText(cur_ctrl, string_buff);
 
-    /* First packet */
+    /* First packet / elapsed time */
     ti_time = (long)start_time;
     ti_tm = localtime( &ti_time );
     if(ti_tm) {
-        StringCchPrintf(string_buff, PREVIEW_STR_MAX,
+        StringCchPrintf(first_buff, PREVIEW_STR_MAX,
                  _T("%04d-%02d-%02d %02d:%02d:%02d"),
                  ti_tm->tm_year + 1900,
                  ti_tm->tm_mon + 1,
@@ -1228,24 +1235,21 @@ preview_set_file_info(HWND of_hwnd, gchar *preview_file) {
                  ti_tm->tm_min,
                  ti_tm->tm_sec);
     } else {
-        StringCchPrintf(string_buff, PREVIEW_STR_MAX, _T("?"));
+        StringCchPrintf(first_buff, PREVIEW_STR_MAX, _T("?"));
     }
-    cur_ctrl = GetDlgItem(of_hwnd, EWFD_PTX_FIRST_PKT);
-    SetWindowText(cur_ctrl, string_buff);
 
-    /* Elapsed time */
     elapsed_time = (unsigned int)(stop_time-start_time);
     if(elapsed_time/86400) {
-        StringCchPrintf(string_buff, PREVIEW_STR_MAX, _T("%02u days %02u:%02u:%02u"),
-        elapsed_time/86400, elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
+        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("%02u:%02u:%02u"),
-        elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
+        StringCchPrintf(string_buff, PREVIEW_STR_MAX, _T("%s / %02u:%02u:%02u"),
+        first_buff, elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
     }
     if(is_breaked) {
-        StringCchPrintf(string_buff, PREVIEW_STR_MAX, _T("unknown"));
+        StringCchPrintf(string_buff, PREVIEW_STR_MAX, _T("%s / unknown"), first_buff);
     }
-    cur_ctrl = GetDlgItem(of_hwnd, EWFD_PTX_ELAPSED);
+    cur_ctrl = GetDlgItem(of_hwnd, EWFD_PTX_START_ELAPSED);
     SetWindowText(cur_ctrl, string_buff);
 
     wtap_close(wth);
@@ -1307,8 +1311,7 @@ filter_tb_syntax_check(HWND hwnd, TCHAR *filter_text) {
         SendMessage(hwnd, EM_SETBKGNDCOLOR, (WPARAM) 1, COLOR_WINDOW);
         return;
     } else if (dfilter_compile(utf_16to8(strval), &dfp, NULL)) { /* colorize filter string entry */
-        if (dfp != NULL)
-            dfilter_free(dfp);
+        dfilter_free(dfp);
         /* Valid (light green) */
         SendMessage(hwnd, EM_SETBKGNDCOLOR, 0, RGB(0xe4, 0xff, 0xc7)); /* tango_chameleon_1 */
     } else {
@@ -1316,7 +1319,7 @@ filter_tb_syntax_check(HWND hwnd, TCHAR *filter_text) {
         SendMessage(hwnd, EM_SETBKGNDCOLOR, 0, RGB(0xff, 0xcc, 0xcc)); /* tango_scarlet_red_1 */
     }
 
-    if (strval) g_free(strval);
+    g_free(strval);
 }
 
 
@@ -1336,22 +1339,12 @@ open_file_hook_proc(HWND of_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
             }
 
             cur_ctrl = GetDlgItem(of_hwnd, EWFD_FORMAT_TYPE);
-            SendMessage(cur_ctrl, CB_ADDSTRING, 0, (WPARAM) _T("Automatic"));
+            SendMessage(cur_ctrl, CB_ADDSTRING, 0, (WPARAM) _T("Automatically detect file type"));
             for (i = 0; open_routines[i].name != NULL; i += 1) {
                 SendMessage(cur_ctrl, CB_ADDSTRING, 0, (WPARAM) utf_8to16(open_routines[i].name));
             }
             SendMessage(cur_ctrl, CB_SETCURSEL, 0, 0);
 
-            /* Fill in our resolution values */
-            cur_ctrl = GetDlgItem(of_hwnd, EWFD_MAC_NR_CB);
-            SendMessage(cur_ctrl, BM_SETCHECK, gbl_resolv_flags.mac_name, 0);
-            cur_ctrl = GetDlgItem(of_hwnd, EWFD_NET_NR_CB);
-            SendMessage(cur_ctrl, BM_SETCHECK, gbl_resolv_flags.network_name, 0);
-            cur_ctrl = GetDlgItem(of_hwnd, EWFD_TRANS_NR_CB);
-            SendMessage(cur_ctrl, BM_SETCHECK, gbl_resolv_flags.transport_name, 0);
-            cur_ctrl = GetDlgItem(of_hwnd, EWFD_EXTERNAL_NR_CB);
-            SendMessage(cur_ctrl, BM_SETCHECK, gbl_resolv_flags.use_external_net_name_resolver, 0);
-
             preview_set_file_info(of_hwnd, NULL);
             break;
         case WM_NOTIFY:
@@ -1359,26 +1352,12 @@ open_file_hook_proc(HWND of_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
                 case CDN_FILEOK:
                     /* Fetch the read filter */
                     cur_ctrl = GetDlgItem(of_hwnd, EWFD_FILTER_EDIT);
-                    if (g_dfilter_str)
-                        g_free(g_dfilter_str);
+                    g_free(g_dfilter_str);
                     g_dfilter_str = filter_tb_get(cur_ctrl);
 
                     cur_ctrl = GetDlgItem(of_hwnd, EWFD_FORMAT_TYPE);
                     g_format_type = (unsigned int) SendMessage(cur_ctrl, CB_GETCURSEL, 0, 0);
 
-                    /* Fetch our resolution values */
-                    cur_ctrl = GetDlgItem(of_hwnd, EWFD_MAC_NR_CB);
-                    if (SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
-                        gbl_resolv_flags.mac_name = TRUE;
-                    cur_ctrl = GetDlgItem(of_hwnd, EWFD_NET_NR_CB);
-                    if (SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
-                        gbl_resolv_flags.network_name = TRUE;
-                    cur_ctrl = GetDlgItem(of_hwnd, EWFD_TRANS_NR_CB);
-                    if (SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
-                        gbl_resolv_flags.transport_name = TRUE;
-                    cur_ctrl = GetDlgItem(of_hwnd, EWFD_EXTERNAL_NR_CB);
-                    if (SendMessage(cur_ctrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
-                        gbl_resolv_flags.use_external_net_name_resolver = TRUE;
                     break;
                 case CDN_SELCHANGE:
                     /* This _almost_ works correctly. We need to handle directory
@@ -1427,7 +1406,7 @@ append_file_extension_type(GArray *sa, int et)
     GString* description_str = g_string_new("");
     gchar sep;
     GSList *extensions_list, *extension;
-    TCHAR *str16;
+    const TCHAR *str16;
     guint16 zero = 0;
 
     /* Construct the list of patterns. */
@@ -1460,7 +1439,7 @@ append_file_extension_type(GArray *sa, int et)
 
 static TCHAR *
 build_file_open_type_list(void) {
-    TCHAR *str16;
+    const TCHAR *str16;
     int et;
     GArray* sa;
     static const guint16 zero = 0;
@@ -1491,24 +1470,23 @@ build_file_open_type_list(void) {
     str16 = utf_8to16("All Files");
     sa = g_array_append_vals(sa, str16, (guint) strlen("All Files"));
     sa = g_array_append_val(sa, zero);
-    str16 = utf_8to16("*.*");
-    sa = g_array_append_vals(sa, str16, (guint) strlen("*.*"));
+    str16 = utf_8to16(ALL_FILES_WILDCARD);
+    sa = g_array_append_vals(sa, str16, (guint) strlen(ALL_FILES_WILDCARD));
     sa = g_array_append_val(sa, zero);
 
     /*
-     * Add an "All Capture Files" entry, with all the extensions we
-     * know about.
+     * Add an "All Capture Files" entry, with all the capture file
+     * extensions we know about.
      */
     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);
 
     /*
-     * Construct its list of patterns from a list of all extensions
-     * we support.
+     * Construct its list of patterns.
      */
     pattern_str = g_string_new("");
-    extensions_list = wtap_get_all_file_extensions_list();
+    extensions_list = wtap_get_all_capture_file_extensions_list();
     sep = '\0';
     for (extension = extensions_list; extension != NULL;
          extension = g_slist_next(extension)) {
@@ -1554,19 +1532,17 @@ append_file_type(GArray *sa, int ft)
     GString* description_str = g_string_new("");
     gchar sep;
     GSList *extensions_list, *extension;
-    TCHAR *str16;
+    const TCHAR *str16;
     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
-           conventionally used for it, so we'll just use "*.*"
-           as the pattern; on Windows, that matches all file names
-           - even those with no extension -  so we don't need to
-           worry about compressed file extensions.  (It does not
-           do so on UN*X; the right pattern on UN*X would just
-           be "*".) */
-           g_string_printf(pattern_str, "*.*");
+           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);
     } else {
         /* Construct the list of patterns. */
         g_string_printf(pattern_str, "");
@@ -1620,7 +1596,7 @@ static void
 build_file_format_list(HWND sf_hwnd) {
     HWND  format_cb;
     int   ft;
-    guint index;
+    guint file_index;
     guint item_to_select;
     gchar *s;
 
@@ -1632,7 +1608,7 @@ build_file_format_list(HWND sf_hwnd) {
     SendMessage(format_cb, CB_RESETCONTENT, 0, 0);
 
     /* Check all file types. */
-    index = 0;
+    file_index = 0;
     for (ft = 0; ft < WTAP_NUM_FILE_TYPES; ft++) {
         if (ft == WTAP_FILE_UNKNOWN)
             continue;  /* not a real file type */
@@ -1647,16 +1623,16 @@ build_file_format_list(HWND sf_hwnd) {
         if(wtap_file_extensions_string(ft) != NULL) {
             s = g_strdup_printf("%s (%s)", wtap_file_type_string(ft), wtap_file_extensions_string(ft));
         } else {
-            s = g_strdup_printf("%s (*.*)", wtap_file_type_string(ft));
+            s = g_strdup_printf("%s (" ALL_FILES_WILDCARD ")", wtap_file_type_string(ft));
         }
         SendMessage(format_cb, CB_ADDSTRING, 0, (LPARAM) utf_8to16(s));
         g_free(s);
-        SendMessage(format_cb, CB_SETITEMDATA, (LPARAM) index, (WPARAM) ft);
+        SendMessage(format_cb, CB_SETITEMDATA, (LPARAM) file_index, (WPARAM) ft);
         if (ft == g_filetype) {
             /* Default to the same format as the file, if it's supported. */
-            item_to_select = index;
+            item_to_select = file_index;
         }
-        index++;
+        file_index++;
     }
 
     SendMessage(format_cb, CB_SETCURSEL, (WPARAM) item_to_select, 0);
@@ -1667,7 +1643,7 @@ static UINT_PTR CALLBACK
 save_as_file_hook_proc(HWND sf_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
     HWND           cur_ctrl;
     OFNOTIFY      *notify = (OFNOTIFY *) l_param;
-    /*int            new_filetype, index;*/
+    /*int            new_filetype, file_index;*/
 
     switch(msg) {
         case WM_INITDIALOG: {
@@ -1692,9 +1668,9 @@ save_as_file_hook_proc(HWND sf_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
             switch (w_param) {
 #if 0
                 case (CBN_SELCHANGE << 16) | EWFD_FILE_TYPE_COMBO:
-                    index = SendMessage(cur_ctrl, CB_GETCURSEL, 0, 0);
-                    if (index != CB_ERR) {
-                        new_filetype = SendMessage(cur_ctrl, CB_GETITEMDATA, (WPARAM) index, 0);
+                    file_index = SendMessage(cur_ctrl, CB_GETCURSEL, 0, 0);
+                    if (file_index != CB_ERR) {
+                        new_filetype = SendMessage(cur_ctrl, CB_GETITEMDATA, (WPARAM) file_index, 0);
                         if (new_filetype != CB_ERR) {
                             if (g_filetype != new_filetype) {
                                 if (wtap_can_save_with_wiretap(new_filetype, cfile.linktypes)) {
@@ -1797,7 +1773,7 @@ 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;
-    /*int            new_filetype, index;*/
+    /*int            new_filetype, file_index;*/
 
     switch(msg) {
         case WM_INITDIALOG: {
@@ -1823,9 +1799,9 @@ export_specified_packets_file_hook_proc(HWND sf_hwnd, UINT msg, WPARAM w_param,
             switch (w_param) {
 #if 0
                 case (CBN_SELCHANGE << 16) | EWFD_FILE_TYPE_COMBO:
-                    index = SendMessage(cur_ctrl, CB_GETCURSEL, 0, 0);
-                    if (index != CB_ERR) {
-                        new_filetype = SendMessage(cur_ctrl, CB_GETITEMDATA, (WPARAM) index, 0);
+                    file_index = SendMessage(cur_ctrl, CB_GETCURSEL, 0, 0);
+                    if (file_index != CB_ERR) {
+                        new_filetype = SendMessage(cur_ctrl, CB_GETITEMDATA, (WPARAM) file_index, 0);
                         if (new_filetype != CB_ERR) {
                             if (g_filetype != new_filetype) {
                                 if (wtap_can_save_with_wiretap(new_filetype, cfile.linktypes)) {
@@ -1942,7 +1918,7 @@ range_update_dynamics(HWND dlg_hwnd, packet_range_t *range) {
     if (range->remove_ignored && g_cf->current_frame && g_cf->current_frame->flags.ignored) {
         StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("0"));
     } else {
-        StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), selected_num ? 1 : 0);
+        StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%d"), selected_num ? 1 : 0);
     }
     SetWindowText(cur_ctrl, static_val);
 
@@ -1951,7 +1927,7 @@ range_update_dynamics(HWND dlg_hwnd, packet_range_t *range) {
     if (range->remove_ignored && g_cf->current_frame && g_cf->current_frame->flags.ignored) {
         StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("0"));
     } else {
-        StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), selected_num ? 1 : 0);
+        StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%d"), selected_num ? 1 : 0);
     }
     SetWindowText(cur_ctrl, static_val);
 
@@ -2230,8 +2206,7 @@ merge_file_hook_proc(HWND mf_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
                 case CDN_FILEOK:
                     /* Fetch the read filter */
                     cur_ctrl = GetDlgItem(mf_hwnd, EWFD_FILTER_EDIT);
-                    if (g_dfilter_str)
-                        g_free(g_dfilter_str);
+                    g_free(g_dfilter_str);
                     g_dfilter_str = filter_tb_get(cur_ctrl);
 
                     cur_ctrl = GetDlgItem(mf_hwnd, EWFD_MERGE_CHRONO_BTN);
@@ -2281,7 +2256,7 @@ 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;
-    int            i, index;
+    int            i, filter_index;
 
     switch(msg) {
         case WM_INITDIALOG: {
@@ -2312,13 +2287,13 @@ export_file_hook_proc(HWND ef_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) {
                 case CDN_FILEOK:
                     break;
                 case CDN_TYPECHANGE:
-                    index = notify->lpOFN->nFilterIndex;
+                    filter_index = notify->lpOFN->nFilterIndex;
 
-                    if (index == 2)     /* PostScript */
+                    if (filter_index == 2)     /* PostScript */
                         print_args.format = PR_FMT_TEXT;
                     else
                         print_args.format = PR_FMT_PS;
-                    if (index == 3 || index == 4 || index == 5 || index == 6)
+                    if (filter_index == 3 || filter_index == 4 || filter_index == 5 || filter_index == 6)
                         pkt_fmt_enable = FALSE;
                     else
                         pkt_fmt_enable = TRUE;