55 #include <QCoreApplication>
62 QCoreApplication app(argc,argv);
67 QString myAppName =
"kwrapper4:";
71 if (QCoreApplication::arguments().size() == 1)
73 qDebug() << myAppName <<
"no application given";
77 if (QCoreApplication::arguments().at(1) ==
"--verbose")
83 exeToStart = QCoreApplication::arguments().at(firstParam);
85 for(
int i=firstParam+1; i < QCoreApplication::arguments().size(); i++)
86 exeParams << QCoreApplication::arguments().at(i);
88 QString path = QString::fromLocal8Bit(qgetenv(
"PATH")).toLower().replace(
'\\',
'/');
94 foreach(
const QString &a, path.split(
';'))
96 if (!envPath.contains(a))
98 if (!a.endsWith(QLatin1String(
"/lib")) && !a.endsWith(QLatin1String(
"/lib/")) && !searchPath.contains(a))
103 path = QCoreApplication::applicationDirPath().toLower().replace(
'\\',
'/');
104 if (!envPath.contains(path))
109 QFileInfo fi(path +
"/../..");
110 QString rootPath = fi.canonicalPath();
113 qDebug() <<
"try to find kdedirs.cache in" << rootPath;
116 path = path.replace(
"bin",
"lib");
117 if (!envPath.contains(path))
125 path = QString::fromLocal8Bit(qgetenv(
"KDEDIRS")).toLower().replace(
'\\',
'/');
129 kdedirs = path.split(
';');
131 bool changedKDEDIRS = 0;
133 if (kdedirs.size() == 0)
137 kdedirsCacheList << rootPath +
"/kdedirs.cache.msvc";
139 kdedirsCacheList << rootPath +
"/kdedirs.cache";
142 foreach(
const QString &kdedirsCachePath,kdedirsCacheList)
144 QFile f(kdedirsCachePath);
147 f.open(QIODevice::ReadOnly);
148 QByteArray data = f.readAll();
150 kdedirs =
QString(data).split(
';');
152 qDebug() <<
"load kdedirs cache from " << kdedirsCachePath <<
"values=" << kdedirs;
170 qDebug() <<
"found KDEDIRS\n\t" << kdedirs.join(
"\n\t");
172 foreach(
const QString &a, kdedirs)
174 if (!envPath.contains(a+
"/bin"))
175 envPath << a +
"/bin";
176 if (!envPath.contains(a+
"/lib"))
177 envPath << a +
"/lib";
178 if (!searchPath.contains(a+
"/bin"))
179 searchPath << a +
"/bin";
183 WCHAR _appName[MAX_PATH+1];
186 qDebug() <<
"search " << exeToStart <<
"in";
189 foreach(
const QString &a, searchPath)
192 qDebug() <<
"\t" << a;
194 if (SearchPathW((LPCWSTR)a.utf16(),(LPCWSTR)exeToStart.utf16(),
195 L
".exe",MAX_PATH+1,(LPWSTR)_appName,NULL))
201 if (QFile::exists(a+
"/"+exeToStart+
".exe"))
208 QString appName = QString::fromUtf16((
unsigned short*)_appName);
212 qWarning() << myAppName <<
"application not found";
217 qDebug() <<
"run" << exeToStart <<
"with params" << exeParams <<
"and PATH environment\n\t" << envPath.join(
"\n\t");
221 env.replaceInStrings(QRegExp(
"^PATH=(.*)", Qt::CaseInsensitive), QLatin1String(
"PATH=") + envPath.join(
";"));
223 env << QLatin1String(
"KDEDIRS=") + kdedirs.join(
";");
226 process->setEnvironment(env);
227 process->start(appName,exeParams);
228 if (process->state() == QProcess::NotRunning)
230 qWarning() << myAppName <<
"process not running";
233 process->waitForStarted();
int main(int argc, char **argv)