commandline.cpp
1 //------------------------------------------------------------------------------
2 // commandline.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2012 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "commandline.h"
24 
25 #include "apprunner.h"
26 #include "strings.h"
27 
28 void CommandLine::escapeArgs(QStringList& args)
29 {
30  QStringList::iterator it;
31  for (it = args.begin(); it != args.end(); ++it)
32  {
33  QString& str = *it;
34  escapeArg(str);
35  }
36 }
37 
38 #if defined Q_OS_WIN
39 void CommandLine::escapeArg(QString& arg)
40 {
41  // Note: this may be game specific (oh, dear...)
42  arg.replace('"', "\\\"");
43  arg.prepend('"');
44  arg += '"';
45 }
46 #else
47 // Since most other operating systems are Unix like we might as well make this a default.
48 void CommandLine::escapeArg(QString& arg)
49 {
50  arg.replace('\'', "'\\''"); // This does: ' -> '\''
51  arg.prepend('\'');
52  arg += '\'';
53 }
54 #endif
55 
57 {
58 #ifdef Q_OS_MAC
59  QFileInfo binary = arg;
60  if(binary.isBundle())
61  arg += AppRunner::findBundleBinary(binary);
62 #endif
63  return escapeArg(arg);
64 }
static void escapeArg(QString &arg)
Escapes all characters in the passed string.
Definition: commandline.cpp:48
static void escapeExecutable(QString &arg)
Escapes the executable path and handles OS X bundles.
Definition: commandline.cpp:56
static void escapeArgs(QStringList &args)
Escapes all characters in all strings on the list.
Definition: commandline.cpp:28