diff --git a/ui/win32/file_dlg_win32.c b/ui/win32/file_dlg_win32.c index 955767f156..ec85cc41c1 100644 --- a/ui/win32/file_dlg_win32.c +++ b/ui/win32/file_dlg_win32.c @@ -1499,29 +1499,78 @@ append_file_type(GArray *sa, int ft) 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); } static TCHAR * build_file_open_type_list(void) { TCHAR *str16; int ft; - GArray* sa = g_array_new(FALSE /*zero_terminated*/, FALSE /*clear_*/,2 /*element_size*/); - guint16 zero = 0; + 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. + */ + + /* + * 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*/); /* Add the "All Files" entry. */ - str16 = utf_8to16("All Files (*.*)"); - sa = g_array_append_vals(sa, str16, (guint) strlen("All Files (*.*)")); + 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("*.*")); sa = g_array_append_val(sa, zero); + /* + * Add an "All Capture Files" entry, with all the 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. + */ + pattern_str = g_string_new(""); + extensions_list = wtap_get_all_file_extensions_list(); + 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_file_extensions_list(extensions_list); + 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); + /* Include all the file types Wireshark supports. */ for (ft = 0; ft < WTAP_NUM_FILE_TYPES; ft++) { if (ft == WTAP_FILE_UNKNOWN) diff --git a/wiretap/file_access.c b/wiretap/file_access.c index 356f8374f3..fc7620137f 100644 --- a/wiretap/file_access.c +++ b/wiretap/file_access.c @@ -1117,37 +1117,12 @@ static GSList *add_extensions(GSList *extensions, const gchar *extension, return extensions; } -/* Return a list of file extensions that are used by the specified file type. - - If include_compressed is TRUE, the list will include compressed - extensions, e.g. not just "pcap" but also "pcap.gz" if we can read - gzipped files. - - All strings in the list are allocated with g_malloc() and must be freed - with g_free(). */ -GSList *wtap_get_file_extensions_list(int filetype, gboolean include_compressed) +static GSList * +add_extensions_for_filetype(int filetype, GSList *extensions, + GSList *compressed_file_extensions) { gchar **extensions_set, **extensionp; gchar *extension; - GSList *compressed_file_extensions; - GSList *extensions; - - if (filetype < 0 || filetype >= wtap_num_file_types) - return NULL; /* not a valid file type */ - - if (dump_open_table[filetype].default_file_extension == NULL) - return NULL; /* valid, but no extensions known */ - - extensions = NULL; /* empty list, to start with */ - - /* - * If include_compressions is true, get the list of compressed-file - * extensions. - */ - if (include_compressed) - compressed_file_extensions = wtap_get_compressed_file_extensions(); - else - compressed_file_extensions = NULL; /* * Add the default extension, and all compressed variants of @@ -1184,12 +1159,87 @@ GSList *wtap_get_file_extensions_list(int filetype, gboolean include_compressed) g_strfreev(extensions_set); } + return extensions; +} + +/* Return a list of all extensions that are used by all file types, + including compressed extensions, e.g. not just "pcap" but also + "pcap.gz" if we can read gzipped files. + + All strings in the list are allocated with g_malloc() and must be freed + with g_free(). */ +GSList *wtap_get_all_file_extensions_list(void) +{ + GSList *compressed_file_extensions; + GSList *extensions; + int filetype; + + extensions = NULL; /* empty list, to start with */ + + /* + * Get the list of compressed-file extensions. + */ + compressed_file_extensions = wtap_get_compressed_file_extensions(); + + for (filetype = 0; filetype < WTAP_NUM_FILE_TYPES; filetype++) { + if (dump_open_table[filetype].default_file_extension != NULL) { + /* + * This file type has at least one extension. + * Add all its extensions, with compressed + * variants. + */ + extensions = add_extensions_for_filetype(filetype, + extensions, compressed_file_extensions); + } + } + + g_slist_free(compressed_file_extensions); + return extensions; +} + +/* Return a list of file extensions that are used by the specified file type. + + If include_compressed is TRUE, the list will include compressed + extensions, e.g. not just "pcap" but also "pcap.gz" if we can read + gzipped files. + + All strings in the list are allocated with g_malloc() and must be freed + with g_free(). */ +GSList *wtap_get_file_extensions_list(int filetype, gboolean include_compressed) +{ + GSList *compressed_file_extensions; + GSList *extensions; + + if (filetype < 0 || filetype >= wtap_num_file_types) + return NULL; /* not a valid file type */ + + if (dump_open_table[filetype].default_file_extension == NULL) + return NULL; /* valid, but no extensions known */ + + extensions = NULL; /* empty list, to start with */ + + /* + * If include_compressions is true, get the list of compressed-file + * extensions. + */ + if (include_compressed) + compressed_file_extensions = wtap_get_compressed_file_extensions(); + else + compressed_file_extensions = NULL; + + /* + * Add all this file type's extensions, with compressed + * variants. + */ + extensions = add_extensions_for_filetype(filetype, extensions, + compressed_file_extensions); + g_slist_free(compressed_file_extensions); return extensions; } /* - * Free a list returned by wtap_file_extensions_list(). + * Free a list returned by wtap_get_file_extensions_list(). */ void wtap_free_file_extensions_list(GSList *extensions) { diff --git a/wiretap/wtap.h b/wiretap/wtap.h index 44001a870b..5d4c26a73e 100644 --- a/wiretap/wtap.h +++ b/wiretap/wtap.h @@ -1331,6 +1331,8 @@ int wtap_short_string_to_file_type(const char *short_name); /*** various file extension functions ***/ WS_DLL_PUBLIC +GSList *wtap_get_all_file_extensions_list(void); +WS_DLL_PUBLIC const char *wtap_default_file_extension(int filetype); WS_DLL_PUBLIC GSList *wtap_get_file_extensions_list(int filetype, gboolean include_compressed);