comparison 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
comparison
equal deleted inserted replaced
171:aab308a3b304 172:b6dd1ee0e486
20 20
21 #include <QFileInfo> 21 #include <QFileInfo>
22 #include <QProcessEnvironment> 22 #include <QProcessEnvironment>
23 #include <QStringList> 23 #include <QStringList>
24 #include <QDir> 24 #include <QDir>
25 #include <QRegExp>
25 26
26 #include <sys/types.h> 27 #include <sys/types.h>
27 28
28 #ifdef Q_OS_WIN32 29 #ifdef Q_OS_WIN32
29 #define _WIN32_WINNT 0x0500 30 #define _WIN32_WINNT 0x0500
39 #include <sys/stat.h> 40 #include <sys/stat.h>
40 #include <fcntl.h> 41 #include <fcntl.h>
41 #include <signal.h> 42 #include <signal.h>
42 #endif 43 #endif
43 44
44 QString findExecutable(QString name) 45 QString findInPath(QString name, QString installPath, bool executableRequired)
45 { 46 {
46 bool found = false; 47 bool found = false;
47 if (name != "") { 48 if (name != "") {
48 if (name[0] != '/') { 49 if (name[0] != '/'
50 #ifdef Q_OS_WIN32
51 && (QRegExp("^[a-zA-Z]:").indexIn(name) != 0)
52 #endif
53 ) {
49 #ifdef Q_OS_WIN32 54 #ifdef Q_OS_WIN32
50 QChar pathSep = ';'; 55 QChar pathSep = ';';
51 #else 56 #else
52 QChar pathSep = ':'; 57 QChar pathSep = ':';
53 #endif 58 #endif
54 name = QFileInfo(name).fileName(); 59 name = QFileInfo(name).fileName();
55 QString path = 60 QString path =
56 QProcessEnvironment::systemEnvironment().value("PATH"); 61 QProcessEnvironment::systemEnvironment().value("PATH");
57 DEBUG << "findExecutable: seeking location for binary " << name 62 DEBUG << "findExecutable: seeking location for binary " << name
58 << ": system path is " << path << endl; 63 << ": system path is " << path << endl;
64 if (installPath != "") {
65 DEBUG << "findExecutable: install path is " << installPath
66 << ", adding to system path" << endl;
67 //!!! path = path + pathSep + installPath;
68 path = installPath + pathSep + path;
69 }
59 #ifndef Q_OS_WIN32 70 #ifndef Q_OS_WIN32
71 //!!!
60 path = path + ":/usr/local/bin"; 72 path = path + ":/usr/local/bin";
61 DEBUG << "... adding /usr/local/bin just in case (fix and add settings dlg please)" 73 DEBUG << "... adding /usr/local/bin just in case (fix and add settings dlg please)"
62 << endl; 74 << endl;
63 #endif 75 #endif
64 QStringList elements = path.split(pathSep, QString::SkipEmptyParts); 76 QStringList elements = path.split(pathSep, QString::SkipEmptyParts);
65 foreach (QString element, elements) { 77 foreach (QString element, elements) {
66 QString full = QDir(element).filePath(name); 78 QString full = QDir(element).filePath(name);
67 QFileInfo fi(full); 79 QFileInfo fi(full);
68 if (fi.exists() && fi.isFile() && fi.isExecutable()) { 80 DEBUG << "findExecutable: looking at " << full << endl;
69 name = full; 81 if (fi.exists() && fi.isFile()) {
70 found = true; 82 DEBUG << "findExecutable: it's a file" << endl;
71 break; 83 if (!executableRequired || fi.isExecutable()) {
84 name = full;
85 DEBUG << "findExecutable: found at " << name << endl;
86 found = true;
87 break;
88 }
72 } 89 }
73 } 90 }
74 } 91 }
75 } 92 }
76 #ifdef Q_OS_WIN32 93 #ifdef Q_OS_WIN32
77 if (!found) { 94 if (!found) {
78 if (!name.endsWith(".exe")) { 95 if (!name.endsWith(".exe")) {
79 return findExecutable(name + ".exe"); 96 return findInPath(name + ".exe", installPath, executableRequired);
80 } 97 }
81 } 98 }
82 #endif 99 #endif
83 return name; 100 return name;
84 } 101 }