Mercurial > hg > svcore
comparison base/HelperExecPath.cpp @ 1243:c7a710f806a1 piper
Add omitted files, again!
author | Chris Cannam |
---|---|
date | Tue, 01 Nov 2016 14:43:51 +0000 |
parents | |
children | 75aefcc9f07d |
comparison
equal
deleted
inserted
replaced
1242:c401e738793f | 1243:c7a710f806a1 |
---|---|
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 static QStringList | |
24 getSuffixes() | |
25 { | |
26 if (sizeof(void *) == 8) { | |
27 return { "-64", "", "-32" }; | |
28 } else { | |
29 return { "", "-32" }; | |
30 } | |
31 } | |
32 | |
33 static bool | |
34 isGood(QString path) | |
35 { | |
36 return QFile(path).exists() && QFileInfo(path).isExecutable(); | |
37 } | |
38 | |
39 QStringList | |
40 HelperExecPath::getHelperExecutables(QString basename) | |
41 { | |
42 QStringList dummy; | |
43 return search(basename, dummy); | |
44 } | |
45 | |
46 QString | |
47 HelperExecPath::getHelperExecutable(QString basename) | |
48 { | |
49 QStringList execs = getHelperExecutables(basename); | |
50 if (execs.empty()) return ""; | |
51 else return execs[0]; | |
52 } | |
53 | |
54 QStringList | |
55 HelperExecPath::getHelperDirPaths() | |
56 { | |
57 QStringList dirs; | |
58 QString myDir = QCoreApplication::applicationDirPath(); | |
59 dirs.push_back(myDir + "/helpers"); | |
60 dirs.push_back(myDir); | |
61 return dirs; | |
62 } | |
63 | |
64 QStringList | |
65 HelperExecPath::getHelperCandidatePaths(QString basename) | |
66 { | |
67 QStringList candidates; | |
68 (void)search(basename, candidates); | |
69 return candidates; | |
70 } | |
71 | |
72 QStringList | |
73 HelperExecPath::search(QString basename, QStringList &candidates) | |
74 { | |
75 // Helpers are expected to exist either in the same directory as | |
76 // this executable was found, or in a subdirectory called helpers. | |
77 | |
78 QString extension = ""; | |
79 #ifdef _WIN32 | |
80 extension = ".exe"; | |
81 #endif | |
82 | |
83 QStringList executables; | |
84 QStringList dirs = getHelperDirPaths(); | |
85 | |
86 for (QString s: getSuffixes()) { | |
87 for (QString d: dirs) { | |
88 QString path = d + QDir::separator() + basename + s + extension; | |
89 candidates.push_back(path); | |
90 if (isGood(path)) { | |
91 executables.push_back(path); | |
92 break; | |
93 } | |
94 } | |
95 } | |
96 | |
97 return executables; | |
98 } | |
99 |