Commit ac2f0f1c authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Environment: Fix crash searching executables in windows

parent b2ba7c70
......@@ -182,48 +182,56 @@ void Environment::clear()
}
QString Environment::searchInPath(const QString &executable,
const QStringList & additionalDirs) const
const QStringList &additionalDirs) const
{
QString exec = expandVariables(executable);
QStringList execs;
execs << executable;
#ifdef Q_OS_WIN
// Check all the executable extensions on windows:
QStringList extensions = value(QLatin1String("PATHEXT")).split(QLatin1Char(';'));
if (exec.isEmpty() || QFileInfo(exec).isAbsolute())
return QDir::toNativeSeparators(exec);
// .exe.bat is legal (and run when starting new.exe), so always go through the complete list once:
foreach (const QString &ext, extensions)
execs << executable + ext.toLower();
#endif
return searchInPath(execs, additionalDirs);
}
// Check in directories:
foreach (const QString &dir, additionalDirs) {
if (dir.isEmpty())
continue;
QFileInfo fi(dir + QLatin1Char('/') + exec);
if (fi.isFile() && fi.isExecutable())
return fi.absoluteFilePath();
}
QString Environment::searchInPath(const QStringList &executables,
const QStringList &additionalDirs) const
{
foreach (const QString &executable, executables) {
QString exec = expandVariables(executable);
// Check in path:
if (exec.indexOf(QChar('/')) != -1)
return QString();
const QChar slash = QLatin1Char('/');
foreach (const QString &p, path()) {
QString fp = p;
fp += slash;
fp += exec;
const QFileInfo fi(fp);
if (fi.exists())
return fi.absoluteFilePath();
}
if (exec.isEmpty())
continue;
#ifdef Q_OS_WIN
// Check all the executable extensions on windows:
QStringList extensions = value(QLatin1String("PATHEXT")).split(QLatin1Char(';'));
if (extensions.isEmpty())
extensions.append(QLatin1String(".exe"));
QFileInfo baseFi(exec);
if (baseFi.isAbsolute() && baseFi.exists())
return QDir::toNativeSeparators(exec);
// Check in directories:
foreach (const QString &dir, additionalDirs) {
if (dir.isEmpty())
continue;
QFileInfo fi(dir + QLatin1Char('/') + exec);
if (fi.isFile() && fi.isExecutable())
return fi.absoluteFilePath();
}
// .exe.bat is legal (and run when starting new.exe), so always go through the complete list:
foreach (const QString &ext, extensions) {
QString result = searchInPath(exec + ext.toLower(), additionalDirs);
if (!result.isEmpty())
return result;
// Check in path:
const QChar slash = QLatin1Char('/');
if (exec.indexOf(slash) != -1)
continue;
foreach (const QString &p, path()) {
QString fp = p;
fp += slash;
fp += exec;
const QFileInfo fi(fp);
if (fi.exists())
return fi.absoluteFilePath();
}
}
#endif
return QString();
}
......
......@@ -103,6 +103,8 @@ public:
bool operator!=(const Environment &other) const;
bool operator==(const Environment &other) const;
private:
QString searchInPath(const QStringList &executables,
const QStringList & additionalDirs = QStringList()) const;
QMap<QString, QString> m_values;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment