comparison common.cpp @ 77:b522aaa2c053

* Further minor win32 fix
author Chris Cannam
date Sat, 20 Nov 2010 11:40:19 +0000
parents d575a8f76a53
children 07405f3a428b
comparison
equal deleted inserted replaced
76:d575a8f76a53 77:b522aaa2c053
19 #include "debug.h" 19 #include "debug.h"
20 20
21 #include <QFileInfo> 21 #include <QFileInfo>
22 #include <QProcessEnvironment> 22 #include <QProcessEnvironment>
23 #include <QStringList> 23 #include <QStringList>
24 #include <QDir>
24 25
25 #include <sys/types.h> 26 #include <sys/types.h>
26 27
27 #ifdef Q_OS_WIN32 28 #ifdef Q_OS_WIN32
28 #define _WIN32_WINNT 0x0500 29 #define _WIN32_WINNT 0x0500
32 #include <pwd.h> 33 #include <pwd.h>
33 #endif 34 #endif
34 35
35 QString findExecutable(QString name) 36 QString findExecutable(QString name)
36 { 37 {
38 bool found = false;
37 if (name != "") { 39 if (name != "") {
38 if (name[0] != '/') { 40 if (name[0] != '/') {
41 #ifdef Q_OS_WIN32
42 QChar pathSep = ';';
43 #else
44 QChar pathSep = ':';
45 #endif
39 name = QFileInfo(name).fileName(); 46 name = QFileInfo(name).fileName();
40 QString path = 47 QString path =
41 QProcessEnvironment::systemEnvironment().value("PATH"); 48 QProcessEnvironment::systemEnvironment().value("PATH");
42 DEBUG << "findExecutable: seeking location for binary " << name 49 DEBUG << "findExecutable: seeking location for binary " << name
43 << ": system path is " << path << endl; 50 << ": system path is " << path << endl;
44 #ifndef Q_OS_WIN32 51 #ifndef Q_OS_WIN32
45 path = path + ":/usr/local/bin"; 52 path = path + ":/usr/local/bin";
46 DEBUG << "... adding /usr/local/bin just in case (fix and add settings dlg please)" 53 DEBUG << "... adding /usr/local/bin just in case (fix and add settings dlg please)"
47 << endl; 54 << endl;
48 #endif 55 #endif
49 #ifdef Q_OS_WIN32
50 QChar pathSep = ';';
51 #else
52 QChar pathSep = ':';
53 #endif
54 QStringList elements = path.split(pathSep, QString::SkipEmptyParts); 56 QStringList elements = path.split(pathSep, QString::SkipEmptyParts);
55 foreach (QString element, elements) { 57 foreach (QString element, elements) {
56 QString full = QString("%1/%2").arg(element).arg(name); 58 QString full = QDir(element).filePath(name);
57 QFileInfo fi(full); 59 QFileInfo fi(full);
58 if (fi.exists() && fi.isFile() && fi.isExecutable()) { 60 if (fi.exists() && fi.isFile() && fi.isExecutable()) {
59 name = full; 61 name = full;
62 found = true;
60 break; 63 break;
61 } 64 }
62 } 65 }
63 } 66 }
64 } 67 }
68 #ifdef Q_OS_WIN32
69 if (!found) {
70 if (!name.endsWith(".exe")) {
71 return findExecutable(name + ".exe");
72 }
73 }
74 #endif
65 return name; 75 return name;
66 } 76 }
67 77
68 QString getSystem() 78 QString getSystem()
69 { 79 {