aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/main.cpp
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2018-10-07 10:06:00 -0700
committerGuy Harris <guy@alum.mit.edu>2018-10-07 18:57:54 +0000
commita679ae6f791ac6b02f342d3b73d6b4aecb9ca6e9 (patch)
treed2f21c87ea7422fa56ba8cc2ff6f23d18bea36f2 /ui/qt/main.cpp
parentce53b4c170e0b0b1c7bb521fe677db1eadc7792b (diff)
Use wsetargv.obj, and wmain() rather than main(), on Windows.
Doing so for command-line programs means that the argument list doesn't ever get converted to the local code page; converting to the local code page can mangle file names that *can't* be converted to the local code page. Furthermore, code that uses setargv.obj rather than wsetargv.obj has issues in some versions of Windows 10; see bug 15151. That means that converting the argument list to UTF-8 is a bit simpler - we don't need to call GetCommandLineW() or CommandLineToArgvW(), we just loop over the UTF-16LE argument strings in argv[]. While we're at it, note in Wireshark's main() why we discard argv on Windows (Qt does the same "convert-to-the-local-code-page" stuff); that means we *do* need to call GetCommandLineW() and CommandLineToArgvW() in main() (i.e., we duplicate what Qt's WinMain() does, but converting to UTF-8 rather than to the local code page). Change-Id: I35b57c1b658fb3e9b0c685097afe324e9fe98649 Ping-Bug: 15151 Reviewed-on: https://code.wireshark.org/review/30051 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/main.cpp')
-rw-r--r--ui/qt/main.cpp36
1 files changed, 29 insertions, 7 deletions
diff --git a/ui/qt/main.cpp b/ui/qt/main.cpp
index 9826f64f00..fbd367085a 100644
--- a/ui/qt/main.cpp
+++ b/ui/qt/main.cpp
@@ -13,6 +13,13 @@
#include <locale.h>
+#ifdef _WIN32
+#include <windows.h>
+#include <tchar.h>
+#include <wchar.h>
+#include <shellapi.h>
+#endif
+
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
@@ -92,7 +99,6 @@
#ifdef _WIN32
# include "caputils/capture-wpcap.h"
# include "caputils/capture_wpcap_packet.h"
-# include <tchar.h> /* Needed for Unicode */
# include <wsutil/file_util.h>
#endif /* _WIN32 */
@@ -352,6 +358,8 @@ int main(int argc, char *qt_argv[])
#ifdef _WIN32
int opt;
+ LPWSTR *wc_argv;
+ int wc_argc;
#endif
int ret_val = EXIT_SUCCESS;
char **argv = qt_argv;
@@ -400,12 +408,26 @@ int main(int argc, char *qt_argv[])
setlocale(LC_ALL, "");
#ifdef _WIN32
- // QCoreApplication clobbers argv. Let's have a local copy.
- argv = (char **) g_malloc(sizeof(char *) * argc);
- for (opt = 0; opt < argc; opt++) {
- argv[opt] = qt_argv[opt];
- }
- arg_list_utf_16to8(argc, argv);
+ //
+ // On Windows, QCoreApplication has its own WinMain(), which gets the
+ // command line using GetCommandLineW(), breaks it into individual
+ // arguments using CommandLineToArgvW(), and then "helpfully"
+ // converts those UTF-16LE arguments into strings in the local code
+ // page.
+ //
+ // We don't want that, because not all file names can be represented
+ // in the local code page, so we do the same, but we convert the
+ // strings into UTF-8.
+ //
+ wc_argv = CommandLineToArgvW(GetCommandLineW(), &wc_argc);
+ if (wc_argv && wc_argc == argc) {
+ argv = (char **) g_malloc(sizeof(char *) * argc);
+ for (opt = 0; opt < argc; opt++) {
+ argv[opt] = g_utf16_to_utf8((const gunichar2 *)wc_argv[opt], -1, NULL, NULL, NULL);
+ }
+ } /* XXX else bail because something is horribly, horribly wrong? */
+ LocalFree(wc_argv);
+
create_app_running_mutex();
#endif /* _WIN32 */