diff common.cpp @ 77:b522aaa2c053

* Further minor win32 fix
author Chris Cannam
date Sat, 20 Nov 2010 11:40:19 +0000
parents d575a8f76a53
children 07405f3a428b
line wrap: on
line diff
--- a/common.cpp	Sat Nov 20 10:11:00 2010 +0000
+++ b/common.cpp	Sat Nov 20 11:40:19 2010 +0000
@@ -21,6 +21,7 @@
 #include <QFileInfo>
 #include <QProcessEnvironment>
 #include <QStringList>
+#include <QDir>
 
 #include <sys/types.h>
 
@@ -34,8 +35,14 @@
 
 QString findExecutable(QString name)
 {
+    bool found = false;
     if (name != "") {
         if (name[0] != '/') {
+#ifdef Q_OS_WIN32
+            QChar pathSep = ';';
+#else
+            QChar pathSep = ':';
+#endif
             name = QFileInfo(name).fileName();
             QString path =
                 QProcessEnvironment::systemEnvironment().value("PATH");
@@ -46,22 +53,25 @@
             DEBUG << "... adding /usr/local/bin just in case (fix and add settings dlg please)"
                     << endl;
 #endif
-#ifdef Q_OS_WIN32
-            QChar pathSep = ';';
-#else
-            QChar pathSep = ':';
-#endif
             QStringList elements = path.split(pathSep, QString::SkipEmptyParts);
             foreach (QString element, elements) {
-                QString full = QString("%1/%2").arg(element).arg(name);
+                QString full = QDir(element).filePath(name);
                 QFileInfo fi(full);
                 if (fi.exists() && fi.isFile() && fi.isExecutable()) {
                     name = full;
+                    found = true;
                     break;
                 }
             }
         }
     }
+#ifdef Q_OS_WIN32
+    if (!found) {
+        if (!name.endsWith(".exe")) {
+            return findExecutable(name + ".exe");
+        }
+    }
+#endif
     return name;
 }