aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2018-11-17 15:24:08 -0800
committerGuy Harris <guy@alum.mit.edu>2018-11-18 00:17:44 +0000
commitc22c060d2b60255f688c2aa9b6dcc63bdeea0031 (patch)
tree83d105e1f059d78479fcc821500d460b2007ed27 /ui/qt
parent204dc92717a7b6cc2765dc0563a4d353ea0a21d7 (diff)
Fix addition of extensions to file names.
If the file is to be compressed, then: if the type in which the file is to be written has a set of extensions it uses, leave the file name alone if it ends with one of those extensions followed by the extension for the compression type, otherwise append the default extension for that file type followed by the extension for the compression type; if it doesn't, leave the file name alone if it ends with the extension for the compression type, otherwise append the extension for the compression type; otherwise: if the type in which the file is to be written has a set of extensions it uses, leave the file name alone if it ends with one of those extensions, otherwise append the default extension for that file type followed by the extension for the compression type; if it doesn't, leave the file name alone if it ends with the extension for the compression type, otherwise append the extension for the compression type. Change-Id: I7c4093af28cc30d579a2ae9faa8f4164b4764001 Reviewed-on: https://code.wireshark.org/review/30681 Petri-Dish: Guy Harris <guy@alum.mit.edu> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'ui/qt')
-rw-r--r--ui/qt/main_window.cpp95
1 files changed, 71 insertions, 24 deletions
diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp
index 8b2f7ee5c2..e958c37fb7 100644
--- a/ui/qt/main_window.cpp
+++ b/ui/qt/main_window.cpp
@@ -1630,57 +1630,104 @@ void MainWindow::exportDissections(export_type_e export_type) {
}
#ifdef Q_OS_WIN
+/*
+ * Ensure that:
+ *
+ * If the file is to be compressed:
+ *
+ * if there is a set of extensions used by the file type to be used,
+ * the file name has one of those extensions followed by the extension
+ * for the compression type to be used;
+ *
+ * otherwise, the file name has the extension for the compression type
+ * to be used;
+ *
+ * otherwise:
+ *
+ * if there is a set of extensions used by the file type to be used,
+ * the file name has one of those extensions.
+ */
void MainWindow::fileAddExtension(QString &file_name, int file_type, wtap_compression_type compression_type) {
QString file_name_lower;
GSList *extensions_list;
- gboolean add_extension;
+ const char *compressed_file_extension;
+ gboolean add_extension_for_file_type;
- /*
- * Append the default file extension if there's none given by
- * the user or if they gave one that's not one of the valid
- * extensions for the file type.
- */
+ /* Lower-case the file name, so the extension matching is case-insensitive. */
file_name_lower = file_name.toLower();
+
+ /* Get a list of all extensions used for this file type; don't
+ include the ones with compression type extensions, as we
+ only want to check for the extension for the compression
+ type we'll be using. */
extensions_list = wtap_get_file_extensions_list(file_type, FALSE);
+
+ /* Get the extension for the compression type we'll be using, or
+ NULL if we won't be compressing it. */
+ compressed_file_extension =
+ (compression_type == WTAP_UNCOMPRESSED) ? NULL : ".gz";
+
if (extensions_list != NULL) {
GSList *extension;
- /* We have one or more extensions for this file type.
+ /* This file type has one or more extensions.
Start out assuming we need to add the default one. */
- add_extension = TRUE;
+ add_extension_for_file_type = TRUE;
- /* OK, see if the file has one of those extensions. */
+ /* OK, see if the file has one of those extensions, followed
+ by the appropriate compression type extension if it's to be
+ compressed. */
for (extension = extensions_list; extension != NULL;
extension = g_slist_next(extension)) {
QString file_suffix = QString(".") + (char *)extension->data;
+ if (compressed_file_extension != NULL)
+ file_suffix += QString(".") + compressed_file_extension;
if (file_name_lower.endsWith(file_suffix)) {
/*
- * The file name has one of the extensions for
- * this file type.
+ * The file name has one of the extensions for this file
+ * type, followed by a compression type extension if
+ * appropriate, so we don't need to add an extension for
+ * the file type or the compression type.
*/
- add_extension = FALSE;
+ add_extension_for_file_type = FALSE;
break;
}
- file_suffix += ".gz";
+ }
+ } else {
+ /* We have no extensions for this file type. Just check
+ to see if we need to add an extension for the compressed
+ file type.
+
+ Start out assuming we do. */
+ add_extension_for_file_type = TRUE;
+ if (compressed_file_extension != NULL) {
+ QString file_suffix = QString(".") + compressed_file_extension;
if (file_name_lower.endsWith(file_suffix)) {
/*
- * The file name has one of the extensions for
- * this file type.
+ * The file name has the appropriate compressed file extension,
+ * so we don't need to add an extension for the compression
+ * type.
*/
- add_extension = FALSE;
- break;
+ add_extension_for_file_type = FALSE;
}
}
- } else {
- /* We have no extensions for this file type. Don't add one. */
- add_extension = FALSE;
}
- if (add_extension) {
+
+ /*
+ * If we need to add an extension for the file type or compressed
+ * file type, do so.
+ */
+ if (add_extension_for_file_type) {
if (wtap_default_file_extension(file_type) != NULL) {
+ /* This file type has a default extension; append it. */
file_name += QString(".") + wtap_default_file_extension(file_type);
- if (compression_type == WTAP_GZIP_COMPRESSED) {
- file_name += ".gz";
- }
+ }
+ if (compression_type != WTAP_UNCOMPRESSED) {
+ /*
+ * The file is to be compressed, so append the extension for
+ * its compression type.
+ */
+ file_name += QString(".gz");
}
}
}