Chris@35
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@35
|
2 /*
|
Chris@35
|
3 Copyright (c) 2016-2018 Queen Mary, University of London
|
Chris@35
|
4
|
Chris@35
|
5 Permission is hereby granted, free of charge, to any person
|
Chris@35
|
6 obtaining a copy of this software and associated documentation
|
Chris@35
|
7 files (the "Software"), to deal in the Software without
|
Chris@35
|
8 restriction, including without limitation the rights to use, copy,
|
Chris@35
|
9 modify, merge, publish, distribute, sublicense, and/or sell copies
|
Chris@35
|
10 of the Software, and to permit persons to whom the Software is
|
Chris@35
|
11 furnished to do so, subject to the following conditions:
|
Chris@35
|
12
|
Chris@35
|
13 The above copyright notice and this permission notice shall be
|
Chris@35
|
14 included in all copies or substantial portions of the Software.
|
Chris@35
|
15
|
Chris@35
|
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
Chris@35
|
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
Chris@35
|
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
Chris@35
|
19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
Chris@35
|
20 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
Chris@35
|
21 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
Chris@35
|
22 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
Chris@35
|
23
|
Chris@35
|
24 Except as contained in this notice, the names of the Centre for
|
Chris@35
|
25 Digital Music and Queen Mary, University of London shall not be
|
Chris@35
|
26 used in advertising or otherwise to promote the sale, use or other
|
Chris@35
|
27 dealings in this Software without prior written authorization.
|
Chris@35
|
28 */
|
Chris@35
|
29
|
Chris@35
|
30 #include "knownplugincandidates.h"
|
Chris@35
|
31
|
Chris@35
|
32 #include <sstream>
|
Chris@35
|
33
|
Chris@35
|
34 using namespace std;
|
Chris@35
|
35
|
Chris@35
|
36 /** This returns true if the helper has a name ending in "-32". By our
|
Chris@35
|
37 * convention, this means that it is a 32-bit helper found on a
|
Chris@35
|
38 * 64-bit system, so (depending on the OS) we may need to look in
|
Chris@35
|
39 * 32-bit-specific paths. Note that is32bit() is *not* usually true
|
Chris@35
|
40 * on 32-bit systems; it's used specifically to indicate a
|
Chris@35
|
41 * "non-native" 32-bit helper.
|
Chris@35
|
42 */
|
Chris@35
|
43 static
|
Chris@35
|
44 bool
|
Chris@35
|
45 is32bit(string helperExecutableName)
|
Chris@35
|
46 {
|
Chris@35
|
47 return helperExecutableName.find("-32") != string::npos;
|
Chris@35
|
48 }
|
Chris@35
|
49
|
Chris@35
|
50 KnownPluginCandidates::KnownPluginCandidates(string helperExecutableName,
|
Chris@35
|
51 PluginCandidates::LogCallback *cb) :
|
Chris@35
|
52 m_known(is32bit(helperExecutableName) ?
|
Chris@35
|
53 KnownPlugins::FormatNonNative32Bit :
|
Chris@35
|
54 KnownPlugins::FormatNative),
|
Chris@35
|
55 m_candidates(helperExecutableName),
|
Chris@35
|
56 m_helperExecutableName(helperExecutableName)
|
Chris@35
|
57 {
|
Chris@35
|
58 m_candidates.setLogCallback(cb);
|
Chris@35
|
59
|
Chris@35
|
60 auto knownTypes = m_known.getKnownPluginTypes();
|
Chris@35
|
61
|
Chris@35
|
62 for (auto type: knownTypes) {
|
Chris@35
|
63 m_candidates.scan(m_known.getTagFor(type),
|
Chris@35
|
64 m_known.getPathFor(type),
|
Chris@35
|
65 m_known.getDescriptorFor(type));
|
Chris@35
|
66 }
|
Chris@35
|
67 }
|
Chris@35
|
68
|
Chris@40
|
69 vector<PluginCandidates::FailureRec>
|
Chris@40
|
70 KnownPluginCandidates::getFailures() const
|
Chris@35
|
71 {
|
Chris@35
|
72 vector<PluginCandidates::FailureRec> failures;
|
Chris@35
|
73
|
Chris@35
|
74 for (auto t: getKnownPluginTypes()) {
|
Chris@35
|
75 auto ff = m_candidates.getFailedLibrariesFor(m_known.getTagFor(t));
|
Chris@35
|
76 failures.insert(failures.end(), ff.begin(), ff.end());
|
Chris@35
|
77 }
|
Chris@35
|
78
|
Chris@40
|
79 return failures;
|
Chris@40
|
80 }
|
Chris@40
|
81
|
Chris@40
|
82 string
|
Chris@40
|
83 KnownPluginCandidates::getFailureReport() const
|
Chris@40
|
84 {
|
Chris@40
|
85 auto failures = getFailures();
|
Chris@35
|
86 if (failures.empty()) return "";
|
Chris@35
|
87
|
Chris@35
|
88 int n = int(failures.size());
|
Chris@35
|
89 int i = 0;
|
Chris@35
|
90
|
Chris@35
|
91 ostringstream os;
|
Chris@35
|
92
|
Chris@35
|
93 os << "<ul>";
|
Chris@35
|
94 for (auto f: failures) {
|
Chris@35
|
95 os << "<li>" + f.library;
|
Chris@35
|
96 if (f.message != "") {
|
Chris@35
|
97 os << "<br><i>" + f.message + "</i>";
|
Chris@35
|
98 } else {
|
Chris@35
|
99 os << "<br><i>unknown error</i>";
|
Chris@35
|
100 }
|
Chris@35
|
101 os << "</li>";
|
Chris@35
|
102
|
Chris@35
|
103 if (n > 10) {
|
Chris@35
|
104 if (++i == 5) {
|
Chris@35
|
105 os << "<li>(... and " << (n - i) << " further failures)</li>";
|
Chris@35
|
106 break;
|
Chris@35
|
107 }
|
Chris@35
|
108 }
|
Chris@35
|
109 }
|
Chris@35
|
110 os << "</ul>";
|
Chris@35
|
111
|
Chris@35
|
112 return os.str();
|
Chris@35
|
113 }
|