summaryrefslogtreecommitdiffstats
path: root/installerbuilder/common/utils.cpp
diff options
context:
space:
mode:
authorkh1 <qt-info@nokia.com>2011-05-18 13:24:28 +0200
committerkh1 <qt-info@nokia.com>2011-05-18 13:24:28 +0200
commit5f52ee825d6143c492c039019161c083d1e4f0ef (patch)
treef1f8afa768a6e09aaef9a2a9b7ef9fea6c256817 /installerbuilder/common/utils.cpp
parent08628a66d34a0df81deb08729464b577f50eb480 (diff)
Use our own parser for arguments.
This fixes a; an crash seen on Linux and Mac caused by two instances of Q{Core}Application and b; should hide the icon and suppress message boxes in case we check for updates. Seen on Mac mostly... Review-by: tjenssen, Niels Weber
Diffstat (limited to 'installerbuilder/common/utils.cpp')
-rw-r--r--installerbuilder/common/utils.cpp101
1 files changed, 93 insertions, 8 deletions
diff --git a/installerbuilder/common/utils.cpp b/installerbuilder/common/utils.cpp
index e4460bd4c..39b53a470 100644
--- a/installerbuilder/common/utils.cpp
+++ b/installerbuilder/common/utils.cpp
@@ -32,15 +32,14 @@
**************************************************************************/
#include "utils.h"
-#include <QByteArray>
-#include <QHash>
-#include <QIODevice>
-#include <QProcessEnvironment>
#include <QtCore/QDateTime>
-#include <QString>
-#include <QUrl>
-#include <QFileInfo>
-#include <QDir>
+#include <QtCore/QDir>
+#include <QtCore/QProcessEnvironment>
+#include <QtCore/QVector>
+
+#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
+# include "qt_windows.h"
+#endif
#include <fstream>
#include <iostream>
@@ -220,3 +219,89 @@ QInstaller::VerboseWriter& QInstaller::verbose()
{
return *verboseWriter();
}
+
+#ifdef Q_OS_WIN
+template<typename Char>
+static QVector<Char*> qWinCmdLine(Char *cmdParam, int length, int &argc)
+{
+ QVector<Char*> argv(8);
+ Char *p = cmdParam;
+ Char *p_end = p + length;
+
+ argc = 0;
+
+ while (*p && p < p_end) { // parse cmd line arguments
+ while (QChar((short)(*p)).isSpace()) // skip white space
+ p++;
+ if (*p && p < p_end) { // arg starts
+ int quote;
+ Char *start, *r;
+ if (*p == Char('\"') || *p == Char('\'')) { // " or ' quote
+ quote = *p;
+ start = ++p;
+ } else {
+ quote = 0;
+ start = p;
+ }
+ r = start;
+ while (*p && p < p_end) {
+ if (quote) {
+ if (*p == quote) {
+ p++;
+ if (QChar((short)(*p)).isSpace())
+ break;
+ quote = 0;
+ }
+ }
+ if (*p == '\\') { // escape char?
+ p++;
+ if (*p == Char('\"') || *p == Char('\''))
+ ; // yes
+ else
+ p--; // treat \ literally
+ } else {
+ if (!quote && (*p == Char('\"') || *p == Char('\''))) { // " or ' quote
+ quote = *p++;
+ continue;
+ } else if (QChar((short)(*p)).isSpace() && !quote)
+ break;
+ }
+ if (*p)
+ *r++ = *p++;
+ }
+ if (*p && p < p_end)
+ p++;
+ *r = Char('\0');
+
+ if (argc >= (int)argv.size()-1) // expand array
+ argv.resize(argv.size()*2);
+ argv[argc++] = start;
+ }
+ }
+ argv[argc] = 0;
+
+ return argv;
+}
+
+QStringList QInstaller::parseCommandLineArgs(int argc, char **argv)
+{
+ Q_UNUSED(argc)
+ Q_UNUSED(argv)
+
+ QStringList arguments;
+ QString cmdLine = QString::fromWCharArray(GetCommandLine());
+
+ QVector<wchar_t*> args = qWinCmdLine<wchar_t>((wchar_t *)cmdLine.utf16(), cmdLine.length(), argc);
+ for (int a = 0; a < argc; ++a)
+ arguments << QString::fromWCharArray(args[a]);
+ return arguments;
+}
+#else
+QStringList QInstaller::parseCommandLineArgs(int argc, char **argv)
+{
+ QStringList arguments;
+ for (int a = 0; a < argc; ++a)
+ arguments << QString::fromLocal8Bit(argv[a]);
+ return arguments;
+}
+#endif