changeset 77:b522aaa2c053

* Further minor win32 fix
author Chris Cannam
date Sat, 20 Nov 2010 11:40:19 +0000
parents d575a8f76a53
children 07405f3a428b
files common.cpp hgrunner.cpp
diffstat 2 files changed, 23 insertions(+), 10 deletions(-) [+]
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;
 }
     
--- a/hgrunner.cpp	Sat Nov 20 10:11:00 2010 +0000
+++ b/hgrunner.cpp	Sat Nov 20 11:40:19 2010 +0000
@@ -90,10 +90,13 @@
 QString HgRunner::getHgBinaryName()
 {
     QSettings settings;
-    QString hg = settings.value("hgbinary", "hg").toString();
-    if (hg == "") hg = "hg";
-    hg = findExecutable(hg);
-    settings.setValue("hgbinary", hg);
+    QString hg = settings.value("hgbinary", "").toString();
+    if (hg == "") {
+        hg = findExecutable("hg");
+    }
+    if (hg != "hg") {
+        settings.setValue("hgbinary", hg);
+    }
     return hg;
 }