For the Windows Open dialog for capture files, get rid of the "(*.*)" in

the "All Files" entry (the current UI guidelines from Microsoft say to
do so, and that's what Paint does, at least), and add an "All Capture
Files" entry with all the file extensions for the file types we support
(it'll pick up all text files, but there's not much we can do about
that, and it won't pick up files with *no* extension or weird
extensions, such as you might get from UN*X systems or from WinDump
commands, but at least it'll filter out some other crud).

Fix what appear to be memory leaks; that should be backported unless
I've missed something and they aren't leaks.

Fix an out-of-date comment, and add an additional comment.

svn path=/trunk/; revision=51481
This commit is contained in:
Guy Harris 2013-08-23 00:06:26 +00:00
parent 713012163c
commit 32e1523bb2
3 changed files with 135 additions and 34 deletions

View File

@ -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)

View File

@ -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)
{

View File

@ -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);