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