diff common.cpp @ 172:b6dd1ee0e486

* Fix failure to recognise local uncommitted changes when an untracked file was selected * Win32: Look in installed location (currently just the location of the present .exe) for executables as well as in path * Win32: Search for easyhg extension in same way as executables * Win32: Set installed location to path when running hg commands (for dependent DLLs)
author Chris Cannam
date Wed, 15 Dec 2010 22:07:31 +0000
parents 0dfd6567ec0c
children 1a3af8617ea4
line wrap: on
line diff
--- a/common.cpp	Tue Dec 14 21:16:52 2010 +0000
+++ b/common.cpp	Wed Dec 15 22:07:31 2010 +0000
@@ -22,6 +22,7 @@
 #include <QProcessEnvironment>
 #include <QStringList>
 #include <QDir>
+#include <QRegExp>
 
 #include <sys/types.h>
 
@@ -41,11 +42,15 @@
 #include <signal.h>
 #endif
 
-QString findExecutable(QString name)
+QString findInPath(QString name, QString installPath, bool executableRequired)
 {
     bool found = false;
     if (name != "") {
-        if (name[0] != '/') {
+        if (name[0] != '/'
+#ifdef Q_OS_WIN32
+			&& (QRegExp("^[a-zA-Z]:").indexIn(name) != 0)
+#endif
+			) {
 #ifdef Q_OS_WIN32
             QChar pathSep = ';';
 #else
@@ -56,7 +61,14 @@
                 QProcessEnvironment::systemEnvironment().value("PATH");
             DEBUG << "findExecutable: seeking location for binary " << name
                   << ": system path is " << path << endl;
+            if (installPath != "") {   
+                DEBUG << "findExecutable: install path is " << installPath
+                      << ", adding to system path" << endl;
+                //!!! path = path + pathSep + installPath;
+                path = installPath + pathSep + path;
+            }
 #ifndef Q_OS_WIN32
+			//!!!
             path = path + ":/usr/local/bin";
             DEBUG << "... adding /usr/local/bin just in case (fix and add settings dlg please)"
                     << endl;
@@ -65,10 +77,15 @@
             foreach (QString element, elements) {
                 QString full = QDir(element).filePath(name);
                 QFileInfo fi(full);
-                if (fi.exists() && fi.isFile() && fi.isExecutable()) {
-                    name = full;
-                    found = true;
-                    break;
+                DEBUG << "findExecutable: looking at " << full << endl;
+                if (fi.exists() && fi.isFile()) {
+                    DEBUG << "findExecutable: it's a file" << endl;
+                    if (!executableRequired || fi.isExecutable()) {
+                        name = full;
+                        DEBUG << "findExecutable: found at " << name << endl;
+                        found = true;
+                        break;
+                    }
                 }
             }
         }
@@ -76,7 +93,7 @@
 #ifdef Q_OS_WIN32
     if (!found) {
         if (!name.endsWith(".exe")) {
-            return findExecutable(name + ".exe");
+            return findInPath(name + ".exe", installPath, executableRequired);
         }
     }
 #endif