summaryrefslogtreecommitdiff
path: root/src/libs/utils/environment.cpp
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@nokia.com>2010-10-18 11:10:55 +0200
committerTobias Hunger <tobias.hunger@nokia.com>2010-10-18 11:10:55 +0200
commitac2f0f1ca3cbba9d82c45dbda9dc51e9f949513a (patch)
treef7490cc16cba6bf9bede2d4287293ad951505ba7 /src/libs/utils/environment.cpp
parentb2ba7c706e426ea3946db632366e115a8e81aa58 (diff)
downloadqt-creator-ac2f0f1ca3cbba9d82c45dbda9dc51e9f949513a.tar.gz
Environment: Fix crash searching executables in windows
Diffstat (limited to 'src/libs/utils/environment.cpp')
-rw-r--r--src/libs/utils/environment.cpp78
1 files changed, 43 insertions, 35 deletions
diff --git a/src/libs/utils/environment.cpp b/src/libs/utils/environment.cpp
index 12cb33fa7c..6ac0381b05 100644
--- a/src/libs/utils/environment.cpp
+++ b/src/libs/utils/environment.cpp
@@ -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();
}