Mercurial > hg > svcore
comparison base/HelperExecPath.cpp @ 1251:67aee57e32c8 3.0-integration
Merge from branch piper
author | Chris Cannam |
---|---|
date | Fri, 04 Nov 2016 14:57:03 +0000 |
parents | 75aefcc9f07d |
children | a9d0b5a2c242 |
comparison
equal
deleted
inserted
replaced
1241:c6bdf247016a | 1251:67aee57e32c8 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2006-2016 Chris Cannam and QMUL. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #include "HelperExecPath.h" | |
17 | |
18 #include <QCoreApplication> | |
19 #include <QFile> | |
20 #include <QDir> | |
21 #include <QFileInfo> | |
22 | |
23 QStringList | |
24 HelperExecPath::getTags() | |
25 { | |
26 if (sizeof(void *) == 8) { | |
27 if (m_type == NativeArchitectureOnly) { | |
28 return { "64", "" }; | |
29 } else { | |
30 return { "64", "", "32" }; | |
31 } | |
32 } else { | |
33 return { "", "32" }; | |
34 } | |
35 } | |
36 | |
37 static bool | |
38 isGood(QString path) | |
39 { | |
40 return QFile(path).exists() && QFileInfo(path).isExecutable(); | |
41 } | |
42 | |
43 QList<HelperExecPath::HelperExec> | |
44 HelperExecPath::getHelperExecutables(QString basename) | |
45 { | |
46 QStringList dummy; | |
47 return search(basename, dummy); | |
48 } | |
49 | |
50 QString | |
51 HelperExecPath::getHelperExecutable(QString basename) | |
52 { | |
53 auto execs = getHelperExecutables(basename); | |
54 if (execs.empty()) return ""; | |
55 else return execs[0].executable; | |
56 } | |
57 | |
58 QStringList | |
59 HelperExecPath::getHelperDirPaths() | |
60 { | |
61 QStringList dirs; | |
62 QString myDir = QCoreApplication::applicationDirPath(); | |
63 dirs.push_back(myDir + "/helpers"); | |
64 dirs.push_back(myDir); | |
65 return dirs; | |
66 } | |
67 | |
68 QStringList | |
69 HelperExecPath::getHelperCandidatePaths(QString basename) | |
70 { | |
71 QStringList candidates; | |
72 (void)search(basename, candidates); | |
73 return candidates; | |
74 } | |
75 | |
76 QList<HelperExecPath::HelperExec> | |
77 HelperExecPath::search(QString basename, QStringList &candidates) | |
78 { | |
79 // Helpers are expected to exist either in the same directory as | |
80 // this executable was found, or in a subdirectory called helpers. | |
81 | |
82 QString extension = ""; | |
83 #ifdef _WIN32 | |
84 extension = ".exe"; | |
85 #endif | |
86 | |
87 QList<HelperExec> executables; | |
88 QStringList dirs = getHelperDirPaths(); | |
89 | |
90 for (QString t: getTags()) { | |
91 for (QString d: dirs) { | |
92 QString path = d + QDir::separator() + basename; | |
93 if (t != QString()) path += "-" + t; | |
94 path += extension; | |
95 candidates.push_back(path); | |
96 if (isGood(path)) { | |
97 executables.push_back({ path, t }); | |
98 break; | |
99 } | |
100 } | |
101 } | |
102 | |
103 return executables; | |
104 } | |
105 |