• R/O
  • HTTP
  • SSH
  • HTTPS

MUtilities: 提交

MUtilities development repository


Commit MetaInfo

修订版44add70b7ca0c549f442981501b71439d4372aaf (tree)
时间2015-09-20 21:54:37
作者LoRd_MuldeR <mulder2@gmx....>
CommiterLoRd_MuldeR

Log Message

Expose the crack_command_line() function.

更改概述

差异

--- a/include/MUtils/OSSupport.h
+++ b/include/MUtils/OSSupport.h
@@ -102,6 +102,7 @@ namespace MUtils
102102
103103 //CLI Arguments
104104 typedef QMap<QString,QString> ArgumentMap;
105+ MUTILS_API const QStringList crack_command_line(const QString &command_line = QString());
105106 MUTILS_API const ArgumentMap &arguments(void);
106107
107108 //Copy file
--- a/src/OSSupport_Win32.cpp
+++ b/src/OSSupport_Win32.cpp
@@ -77,6 +77,28 @@ void MUtils::OS::system_message_err(const wchar_t *const title, const wchar_t *c
7777 static QReadWriteLock g_arguments_lock;
7878 static QScopedPointer<MUtils::OS::ArgumentMap> g_arguments_list;
7979
80+const QStringList MUtils::OS::crack_command_line(const QString &command_line)
81+{
82+ int nArgs = 0;
83+ LPWSTR *szArglist = CommandLineToArgvW(command_line.isNull() ? GetCommandLineW() : MUTILS_WCHR(command_line), &nArgs);
84+
85+ QStringList command_line_tokens;
86+ if(NULL != szArglist)
87+ {
88+ for(int i = 0; i < nArgs; i++)
89+ {
90+ const QString argStr = MUTILS_QSTR(szArglist[i]).trimmed();
91+ if(!argStr.isEmpty())
92+ {
93+ command_line_tokens << argStr;
94+ }
95+ }
96+ LocalFree(szArglist);
97+ }
98+
99+ return command_line_tokens;
100+}
101+
80102 const MUtils::OS::ArgumentMap &MUtils::OS::arguments(void)
81103 {
82104 QReadLocker readLock(&g_arguments_lock);
@@ -98,15 +120,16 @@ const MUtils::OS::ArgumentMap &MUtils::OS::arguments(void)
98120
99121 g_arguments_list.reset(new ArgumentMap());
100122 int nArgs = 0;
101- LPWSTR *szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
123+ const QStringList argList = crack_command_line();
102124
103- if(NULL != szArglist)
125+ if(argList.count() > 1)
104126 {
105- const QChar separator = QLatin1Char('=');
106127 const QString argPrefix = QLatin1String("--");
107- for(int i = 0; i < nArgs; i++)
128+ const QChar separator = QLatin1Char('=');
129+
130+ for(int i = 1; i < nArgs; i++)
108131 {
109- const QString argStr = MUTILS_QSTR(szArglist[i]).trimmed();
132+ const QString &argStr = argList[i];
110133 if(argStr.startsWith(argPrefix))
111134 {
112135 const QString argData = argStr.mid(2).trimmed();
@@ -126,9 +149,8 @@ const MUtils::OS::ArgumentMap &MUtils::OS::arguments(void)
126149 }
127150 }
128151 }
129- LocalFree(szArglist);
130152 }
131- else
153+ else if(argList.empty())
132154 {
133155 qWarning("CommandLineToArgvW() has failed !!!");
134156 }
Show on old repository browser