Chris@66
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@66
|
2 /*
|
Chris@66
|
3 Copyright (c) 2020 Queen Mary, University of London
|
Chris@66
|
4
|
Chris@66
|
5 Permission is hereby granted, free of charge, to any person
|
Chris@66
|
6 obtaining a copy of this software and associated documentation
|
Chris@66
|
7 files (the "Software"), to deal in the Software without
|
Chris@66
|
8 restriction, including without limitation the rights to use, copy,
|
Chris@66
|
9 modify, merge, publish, distribute, sublicense, and/or sell copies
|
Chris@66
|
10 of the Software, and to permit persons to whom the Software is
|
Chris@66
|
11 furnished to do so, subject to the following conditions:
|
Chris@66
|
12
|
Chris@66
|
13 The above copyright notice and this permission notice shall be
|
Chris@66
|
14 included in all copies or substantial portions of the Software.
|
Chris@66
|
15
|
Chris@66
|
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
Chris@66
|
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
Chris@66
|
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
Chris@66
|
19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
Chris@66
|
20 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
Chris@66
|
21 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
Chris@66
|
22 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
Chris@66
|
23
|
Chris@66
|
24 Except as contained in this notice, the names of the Centre for
|
Chris@66
|
25 Digital Music and Queen Mary, University of London shall not be
|
Chris@66
|
26 used in advertising or otherwise to promote the sale, use or other
|
Chris@66
|
27 dealings in this Software without prior written authorization.
|
Chris@66
|
28 */
|
Chris@33
|
29
|
Chris@33
|
30 #include <QApplication>
|
Chris@33
|
31 #include <QString>
|
Chris@33
|
32 #include <QFile>
|
Chris@33
|
33 #include <QDir>
|
Chris@33
|
34
|
Chris@42
|
35 #include <QDialog>
|
Chris@42
|
36 #include <QFrame>
|
Chris@42
|
37 #include <QVBoxLayout>
|
Chris@42
|
38 #include <QCheckBox>
|
Chris@42
|
39 #include <QDialogButtonBox>
|
Chris@46
|
40 #include <QLabel>
|
Chris@51
|
41 #include <QFont>
|
Chris@51
|
42 #include <QFontInfo>
|
Chris@67
|
43 #include <QTemporaryFile>
|
Chris@67
|
44 #include <QMutex>
|
Chris@67
|
45 #include <QMutexLocker>
|
Chris@67
|
46 #include <QProcess>
|
Chris@72
|
47 #include <QToolButton>
|
Chris@79
|
48 #include <QPushButton>
|
Chris@72
|
49 #include <QMessageBox>
|
Chris@74
|
50 #include <QSvgRenderer>
|
Chris@74
|
51 #include <QPainter>
|
Chris@74
|
52 #include <QFontMetrics>
|
Chris@79
|
53 #include <QSpacerItem>
|
Chris@81
|
54 #include <QProgressDialog>
|
Chris@81
|
55 #include <QThread>
|
Chris@42
|
56
|
Chris@41
|
57 #include <vamp-hostsdk/PluginHostAdapter.h>
|
Chris@41
|
58
|
Chris@43
|
59 #include <dataquay/BasicStore.h>
|
Chris@43
|
60 #include <dataquay/RDFException.h>
|
Chris@43
|
61
|
Chris@33
|
62 #include <iostream>
|
Chris@58
|
63 #include <memory>
|
Chris@43
|
64 #include <set>
|
Chris@43
|
65
|
Chris@51
|
66 #include "base/Debug.h"
|
Chris@51
|
67
|
Chris@79
|
68 #include "version.h"
|
Chris@79
|
69
|
Chris@33
|
70 using namespace std;
|
Chris@43
|
71 using namespace Dataquay;
|
Chris@32
|
72
|
Chris@42
|
73 QString
|
Chris@42
|
74 getDefaultInstallDirectory()
|
Chris@32
|
75 {
|
Chris@41
|
76 auto pathList = Vamp::PluginHostAdapter::getPluginPath();
|
Chris@41
|
77 if (pathList.empty()) {
|
Chris@51
|
78 SVCERR << "Failed to look up Vamp plugin path" << endl;
|
Chris@42
|
79 return QString();
|
Chris@41
|
80 }
|
Chris@41
|
81
|
Chris@42
|
82 auto firstPath = *pathList.begin();
|
Chris@42
|
83 QString target = QString::fromUtf8(firstPath.c_str(), firstPath.size());
|
Chris@42
|
84 return target;
|
Chris@42
|
85 }
|
Chris@42
|
86
|
Chris@42
|
87 QStringList
|
Chris@42
|
88 getPluginLibraryList()
|
Chris@42
|
89 {
|
Chris@33
|
90 QDir dir(":out/");
|
Chris@33
|
91 auto entries = dir.entryList({ "*.so", "*.dll", "*.dylib" });
|
Chris@33
|
92
|
Chris@33
|
93 for (auto e: entries) {
|
Chris@51
|
94 SVCERR << e.toStdString() << endl;
|
Chris@33
|
95 }
|
Chris@33
|
96
|
Chris@42
|
97 return entries;
|
Chris@42
|
98 }
|
Chris@33
|
99
|
Chris@50
|
100 void
|
Chris@50
|
101 loadLibraryRdf(BasicStore &store, QString filename)
|
Chris@50
|
102 {
|
Chris@50
|
103 QFile f(filename);
|
Chris@50
|
104 if (!f.open(QFile::ReadOnly | QFile::Text)) {
|
Chris@51
|
105 SVCERR << "Failed to open RDF resource file "
|
Chris@51
|
106 << filename.toStdString() << endl;
|
Chris@50
|
107 return;
|
Chris@50
|
108 }
|
Chris@50
|
109
|
Chris@50
|
110 QByteArray content = f.readAll();
|
Chris@50
|
111 f.close();
|
Chris@50
|
112
|
Chris@50
|
113 try {
|
Chris@50
|
114 store.importString(QString::fromUtf8(content),
|
Chris@50
|
115 Uri("file:" + filename),
|
Chris@50
|
116 BasicStore::ImportIgnoreDuplicates);
|
Chris@50
|
117 } catch (const RDFException &ex) {
|
Chris@51
|
118 SVCERR << "Failed to import RDF resource file "
|
Chris@51
|
119 << filename.toStdString() << ": " << ex.what() << endl;
|
Chris@50
|
120 }
|
Chris@50
|
121 }
|
Chris@50
|
122
|
Chris@43
|
123 unique_ptr<BasicStore>
|
Chris@43
|
124 loadLibrariesRdf()
|
Chris@43
|
125 {
|
Chris@43
|
126 unique_ptr<BasicStore> store(new BasicStore);
|
Chris@43
|
127
|
Chris@50
|
128 vector<QString> dirs { ":rdf/plugins", ":out" };
|
Chris@43
|
129
|
Chris@50
|
130 for (auto d: dirs) {
|
Chris@50
|
131 for (auto e: QDir(d).entryList({ "*.ttl", "*.n3" })) {
|
Chris@50
|
132 loadLibraryRdf(*store, d + "/" + e);
|
Chris@43
|
133 }
|
Chris@43
|
134 }
|
Chris@43
|
135
|
Chris@43
|
136 return store;
|
Chris@43
|
137 }
|
Chris@43
|
138
|
Chris@43
|
139 struct LibraryInfo {
|
Chris@43
|
140 QString id;
|
Chris@43
|
141 QString fileName;
|
Chris@43
|
142 QString title;
|
Chris@43
|
143 QString maker;
|
Chris@43
|
144 QString description;
|
Chris@78
|
145 QString page;
|
Chris@47
|
146 QStringList pluginTitles;
|
Chris@67
|
147 map<QString, int> pluginVersions; // id -> version
|
Chris@74
|
148 QString licence;
|
Chris@43
|
149 };
|
Chris@43
|
150
|
Chris@74
|
151 QString
|
Chris@74
|
152 identifyLicence(QString libraryBasename)
|
Chris@74
|
153 {
|
Chris@74
|
154 QString licenceFile = QString(":out/%1_COPYING.txt").arg(libraryBasename);
|
Chris@74
|
155
|
Chris@74
|
156 QFile f(licenceFile);
|
Chris@74
|
157 if (!f.open(QFile::ReadOnly | QFile::Text)) {
|
Chris@74
|
158 SVCERR << "Failed to open licence file "
|
Chris@74
|
159 << licenceFile.toStdString() << endl;
|
Chris@74
|
160 return {};
|
Chris@74
|
161 }
|
Chris@74
|
162
|
Chris@74
|
163 QByteArray content = f.readAll();
|
Chris@74
|
164 f.close();
|
Chris@74
|
165
|
Chris@74
|
166 QString licenceText = QString::fromUtf8(content);
|
Chris@74
|
167
|
Chris@74
|
168 QString gpl = "GNU General Public License";
|
Chris@74
|
169 QString agpl = "GNU Affero General Public License";
|
Chris@74
|
170 QString apache = "Apache License";
|
Chris@74
|
171 QString mit = "MIT License";
|
Chris@74
|
172
|
Chris@82
|
173 // NB these are not expected to identify an arbitrary licence! We
|
Chris@74
|
174 // know we have only a limited set here. But we do want to
|
Chris@74
|
175 // determine this from the actual licence text included with the
|
Chris@74
|
176 // plugin distribution, not just from e.g. RDF metadata
|
Chris@74
|
177
|
Chris@74
|
178 if (licenceText.contains(gpl.toUpper(), Qt::CaseSensitive)) {
|
Chris@74
|
179 if (licenceText.contains("Version 3, 29 June 2007")) {
|
Chris@74
|
180 return QString("%1, version 3").arg(gpl);
|
Chris@74
|
181 } else if (licenceText.contains("Version 2, June 1991")) {
|
Chris@74
|
182 return QString("%1, version 2").arg(gpl);
|
Chris@74
|
183 } else {
|
Chris@74
|
184 return gpl;
|
Chris@74
|
185 }
|
Chris@74
|
186 }
|
Chris@74
|
187 if (licenceText.contains(agpl.toUpper(), Qt::CaseSensitive)) {
|
Chris@74
|
188 return agpl;
|
Chris@74
|
189 }
|
Chris@74
|
190 if (licenceText.contains(apache)) {
|
Chris@74
|
191 return apache;
|
Chris@74
|
192 }
|
Chris@74
|
193 if (licenceText.contains("Permission is hereby granted, free of charge, to any person")) {
|
Chris@74
|
194 return mit;
|
Chris@74
|
195 }
|
Chris@74
|
196
|
Chris@74
|
197 SVCERR << "Didn't recognise licence for " << libraryBasename << endl;
|
Chris@74
|
198
|
Chris@74
|
199 return {};
|
Chris@74
|
200 }
|
Chris@74
|
201
|
Chris@43
|
202 vector<LibraryInfo>
|
Chris@43
|
203 getLibraryInfo(const Store &store, QStringList libraries)
|
Chris@43
|
204 {
|
Chris@43
|
205 /* e.g.
|
Chris@43
|
206
|
Chris@43
|
207 plugbase:library a vamp:PluginLibrary ;
|
Chris@43
|
208 vamp:identifier "qm-vamp-plugins" ;
|
Chris@43
|
209 dc:title "Queen Mary plugin set"
|
Chris@43
|
210 */
|
Chris@43
|
211
|
Chris@43
|
212 Triples tt = store.match(Triple(Node(),
|
Chris@43
|
213 Uri("a"),
|
Chris@43
|
214 store.expand("vamp:PluginLibrary")));
|
Chris@43
|
215
|
Chris@67
|
216 map<QString, QString> wanted; // basename -> full lib name
|
Chris@43
|
217 for (auto lib: libraries) {
|
Chris@43
|
218 wanted[QFileInfo(lib).baseName()] = lib;
|
Chris@43
|
219 }
|
Chris@43
|
220
|
Chris@43
|
221 vector<LibraryInfo> results;
|
Chris@43
|
222
|
Chris@43
|
223 for (auto t: tt) {
|
Chris@43
|
224
|
Chris@43
|
225 Node libId = store.complete(Triple(t.subject(),
|
Chris@43
|
226 store.expand("vamp:identifier"),
|
Chris@43
|
227 Node()));
|
Chris@43
|
228 if (libId.type != Node::Literal) {
|
Chris@43
|
229 continue;
|
Chris@43
|
230 }
|
Chris@43
|
231 auto wi = wanted.find(libId.value);
|
Chris@43
|
232 if (wi == wanted.end()) {
|
Chris@43
|
233 continue;
|
Chris@43
|
234 }
|
Chris@74
|
235
|
Chris@50
|
236 Node title = store.complete(Triple(t.subject(),
|
Chris@50
|
237 store.expand("dc:title"),
|
Chris@50
|
238 Node()));
|
Chris@50
|
239 if (title.type != Node::Literal) {
|
Chris@50
|
240 continue;
|
Chris@50
|
241 }
|
Chris@50
|
242
|
Chris@43
|
243 LibraryInfo info;
|
Chris@43
|
244 info.id = wi->first;
|
Chris@43
|
245 info.fileName = wi->second;
|
Chris@50
|
246 info.title = title.value;
|
Chris@43
|
247
|
Chris@43
|
248 Node maker = store.complete(Triple(t.subject(),
|
Chris@43
|
249 store.expand("foaf:maker"),
|
Chris@43
|
250 Node()));
|
Chris@43
|
251 if (maker.type == Node::Literal) {
|
Chris@43
|
252 info.maker = maker.value;
|
Chris@46
|
253 } else if (maker != Node()) {
|
Chris@46
|
254 maker = store.complete(Triple(maker,
|
Chris@46
|
255 store.expand("foaf:name"),
|
Chris@46
|
256 Node()));
|
Chris@46
|
257 if (maker.type == Node::Literal) {
|
Chris@46
|
258 info.maker = maker.value;
|
Chris@46
|
259 }
|
Chris@43
|
260 }
|
Chris@46
|
261
|
Chris@43
|
262 Node desc = store.complete(Triple(t.subject(),
|
Chris@43
|
263 store.expand("dc:description"),
|
Chris@43
|
264 Node()));
|
Chris@43
|
265 if (desc.type == Node::Literal) {
|
Chris@43
|
266 info.description = desc.value;
|
Chris@43
|
267 }
|
Chris@78
|
268
|
Chris@78
|
269 Node page = store.complete(Triple(t.subject(),
|
Chris@78
|
270 store.expand("foaf:page"),
|
Chris@78
|
271 Node()));
|
Chris@79
|
272 if (page.type == Node::URI) {
|
Chris@79
|
273 info.page = page.value;
|
Chris@78
|
274 }
|
Chris@43
|
275
|
Chris@47
|
276 Triples pp = store.match(Triple(t.subject(),
|
Chris@47
|
277 store.expand("vamp:available_plugin"),
|
Chris@47
|
278 Node()));
|
Chris@47
|
279 for (auto p: pp) {
|
Chris@47
|
280 Node ptitle = store.complete(Triple(p.object(),
|
Chris@47
|
281 store.expand("dc:title"),
|
Chris@47
|
282 Node()));
|
Chris@47
|
283 if (ptitle.type == Node::Literal) {
|
Chris@47
|
284 info.pluginTitles.push_back(ptitle.value);
|
Chris@47
|
285 }
|
Chris@67
|
286
|
Chris@67
|
287 Node pident = store.complete(Triple(p.object(),
|
Chris@67
|
288 store.expand("vamp:identifier"),
|
Chris@67
|
289 Node()));
|
Chris@67
|
290 Node pversion = store.complete(Triple(p.object(),
|
Chris@67
|
291 store.expand("owl:versionInfo"),
|
Chris@67
|
292 Node()));
|
Chris@67
|
293 if (pident.type == Node::Literal &&
|
Chris@67
|
294 pversion.type == Node::Literal) {
|
Chris@67
|
295 bool ok = false;
|
Chris@67
|
296 int version = pversion.value.toInt(&ok);
|
Chris@67
|
297 if (ok) {
|
Chris@67
|
298 info.pluginVersions[pident.value] = version;
|
Chris@67
|
299 }
|
Chris@67
|
300 }
|
Chris@47
|
301 }
|
Chris@74
|
302
|
Chris@74
|
303 info.licence = identifyLicence(libId.value);
|
Chris@74
|
304 SVCERR << "licence = " << info.licence << endl;
|
Chris@47
|
305
|
Chris@43
|
306 results.push_back(info);
|
Chris@50
|
307 wanted.erase(libId.value);
|
Chris@43
|
308 }
|
Chris@43
|
309
|
Chris@50
|
310 for (auto wp: wanted) {
|
Chris@51
|
311 SVCERR << "Failed to find any RDF information about library "
|
Chris@51
|
312 << wp.second << endl;
|
Chris@50
|
313 }
|
Chris@50
|
314
|
Chris@43
|
315 return results;
|
Chris@43
|
316 }
|
Chris@43
|
317
|
Chris@67
|
318 struct TempFileDeleter {
|
Chris@67
|
319 ~TempFileDeleter() {
|
Chris@67
|
320 if (tempFile != "") {
|
Chris@67
|
321 QFile(tempFile).remove();
|
Chris@67
|
322 }
|
Chris@67
|
323 }
|
Chris@67
|
324 QString tempFile;
|
Chris@67
|
325 };
|
Chris@67
|
326
|
Chris@67
|
327 map<QString, int>
|
Chris@70
|
328 getLibraryPluginVersions(QString libraryFilePath)
|
Chris@67
|
329 {
|
Chris@67
|
330 static QMutex mutex;
|
Chris@67
|
331 static QString tempFileName;
|
Chris@67
|
332 static TempFileDeleter deleter;
|
Chris@67
|
333 static bool initHappened = false, initSucceeded = false;
|
Chris@67
|
334
|
Chris@67
|
335 QMutexLocker locker (&mutex);
|
Chris@67
|
336
|
Chris@67
|
337 if (!initHappened) {
|
Chris@67
|
338 initHappened = true;
|
Chris@67
|
339
|
Chris@67
|
340 QTemporaryFile tempFile;
|
Chris@67
|
341 tempFile.setAutoRemove(false);
|
Chris@67
|
342 if (!tempFile.open()) {
|
Chris@67
|
343 SVCERR << "ERROR: Failed to open a temporary file" << endl;
|
Chris@67
|
344 return {};
|
Chris@67
|
345 }
|
Chris@67
|
346
|
Chris@67
|
347 // We can't make the QTemporaryFile static, as it will hold
|
Chris@67
|
348 // the file open and that prevents us from executing it. Hence
|
Chris@67
|
349 // the separate deleter.
|
Chris@67
|
350
|
Chris@67
|
351 tempFileName = tempFile.fileName();
|
Chris@67
|
352 deleter.tempFile = tempFileName;
|
Chris@67
|
353
|
Chris@67
|
354 #ifdef Q_OS_WIN32
|
Chris@67
|
355 QString helperPath = ":out/get-version.exe";
|
Chris@67
|
356 #else
|
Chris@67
|
357 QString helperPath = ":out/get-version";
|
Chris@67
|
358 #endif
|
Chris@67
|
359 QFile helper(helperPath);
|
Chris@67
|
360 if (!helper.open(QFile::ReadOnly)) {
|
Chris@67
|
361 SVCERR << "ERROR: Failed to read helper code" << endl;
|
Chris@67
|
362 return {};
|
Chris@67
|
363 }
|
Chris@67
|
364 QByteArray content = helper.readAll();
|
Chris@67
|
365 helper.close();
|
Chris@67
|
366
|
Chris@67
|
367 if (tempFile.write(content) != content.size()) {
|
Chris@67
|
368 SVCERR << "ERROR: Incomplete write to temporary file" << endl;
|
Chris@67
|
369 return {};
|
Chris@67
|
370 }
|
Chris@67
|
371 tempFile.close();
|
Chris@67
|
372
|
Chris@67
|
373 if (!QFile::setPermissions
|
Chris@67
|
374 (tempFileName,
|
Chris@67
|
375 QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner)) {
|
Chris@67
|
376 SVCERR << "ERROR: Failed to set execute permission on helper "
|
Chris@67
|
377 << tempFileName << endl;
|
Chris@67
|
378 return {};
|
Chris@67
|
379 }
|
Chris@67
|
380
|
Chris@67
|
381 initSucceeded = true;
|
Chris@67
|
382 }
|
Chris@67
|
383
|
Chris@67
|
384 if (!initSucceeded) {
|
Chris@67
|
385 return {};
|
Chris@67
|
386 }
|
Chris@67
|
387
|
Chris@67
|
388 QProcess process;
|
Chris@67
|
389 process.start(tempFileName, { libraryFilePath });
|
Chris@67
|
390
|
Chris@67
|
391 if (!process.waitForStarted()) {
|
Chris@67
|
392 QProcess::ProcessError err = process.error();
|
Chris@67
|
393 if (err == QProcess::FailedToStart) {
|
Chris@67
|
394 SVCERR << "Unable to start helper process " << tempFileName << endl;
|
Chris@67
|
395 } else if (err == QProcess::Crashed) {
|
Chris@67
|
396 SVCERR << "Helper process " << tempFileName
|
Chris@67
|
397 << " crashed on startup" << endl;
|
Chris@67
|
398 } else {
|
Chris@67
|
399 SVCERR << "Helper process " << tempFileName
|
Chris@67
|
400 << " failed on startup with error code " << err << endl;
|
Chris@67
|
401 }
|
Chris@67
|
402 return {};
|
Chris@67
|
403 }
|
Chris@67
|
404 process.waitForFinished();
|
Chris@67
|
405
|
Chris@67
|
406 QByteArray stdOut = process.readAllStandardOutput();
|
Chris@67
|
407 QByteArray stdErr = process.readAllStandardError();
|
Chris@67
|
408
|
Chris@67
|
409 QString errStr = QString::fromUtf8(stdErr);
|
Chris@67
|
410 if (!errStr.isEmpty()) {
|
Chris@67
|
411 SVCERR << "Note: Helper process stderr follows:" << endl;
|
Chris@67
|
412 SVCERR << errStr << endl;
|
Chris@67
|
413 SVCERR << "Note: Helper process stderr ends" << endl;
|
Chris@67
|
414 }
|
Chris@67
|
415
|
Chris@67
|
416 QStringList lines = QString::fromUtf8(stdOut).split
|
Chris@67
|
417 (QRegExp("[\\r\\n]+"), QString::SkipEmptyParts);
|
Chris@67
|
418 map<QString, int> versions;
|
Chris@67
|
419 for (QString line: lines) {
|
Chris@67
|
420 QStringList parts = line.split(":");
|
Chris@67
|
421 if (parts.size() != 2) {
|
Chris@67
|
422 SVCERR << "Unparseable output line: " << line << endl;
|
Chris@67
|
423 continue;
|
Chris@67
|
424 }
|
Chris@67
|
425 bool ok = false;
|
Chris@67
|
426 int version = parts[1].toInt(&ok);
|
Chris@67
|
427 if (!ok) {
|
Chris@67
|
428 SVCERR << "Unparseable version number in line: " << line << endl;
|
Chris@67
|
429 continue;
|
Chris@67
|
430 }
|
Chris@67
|
431 versions[parts[0]] = version;
|
Chris@67
|
432 }
|
Chris@67
|
433
|
Chris@67
|
434 return versions;
|
Chris@67
|
435 }
|
Chris@67
|
436
|
Chris@67
|
437 bool isLibraryNewer(map<QString, int> a, map<QString, int> b)
|
Chris@67
|
438 {
|
Chris@67
|
439 // a and b are maps from plugin id to plugin version for libraries
|
Chris@67
|
440 // A and B. (There is no overarching library version number.) We
|
Chris@67
|
441 // deem library A to be newer than library B if:
|
Chris@67
|
442 //
|
Chris@67
|
443 // 1. A contains a plugin id that is also in B, whose version in
|
Chris@67
|
444 // A is newer than that in B, or
|
Chris@67
|
445 //
|
Chris@67
|
446 // 2. B is not newer than A according to rule 1, and neither A or
|
Chris@67
|
447 // B is empty, and A contains a plugin id that is not in B, and B
|
Chris@67
|
448 // does not contain any plugin id that is not in A
|
Chris@67
|
449 //
|
Chris@67
|
450 // (The not-empty part of rule 2 is just to avoid false positives
|
Chris@67
|
451 // when a library or its metadata could not be read at all.)
|
Chris@67
|
452
|
Chris@67
|
453 auto containsANewerPlugin = [](const map<QString, int> &m1,
|
Chris@67
|
454 const map<QString, int> &m2) {
|
Chris@67
|
455 for (auto p: m1) {
|
Chris@67
|
456 if (m2.find(p.first) != m2.end() &&
|
Chris@67
|
457 p.second > m2.at(p.first)) {
|
Chris@67
|
458 return true;
|
Chris@67
|
459 }
|
Chris@67
|
460 }
|
Chris@67
|
461 return false;
|
Chris@67
|
462 };
|
Chris@67
|
463
|
Chris@67
|
464 auto containsANovelPlugin = [](const map<QString, int> &m1,
|
Chris@67
|
465 const map<QString, int> &m2) {
|
Chris@67
|
466 for (auto p: m1) {
|
Chris@67
|
467 if (m2.find(p.first) == m2.end()) {
|
Chris@67
|
468 return true;
|
Chris@67
|
469 }
|
Chris@67
|
470 }
|
Chris@67
|
471 return false;
|
Chris@67
|
472 };
|
Chris@67
|
473
|
Chris@67
|
474 if (containsANewerPlugin(a, b)) {
|
Chris@67
|
475 return true;
|
Chris@67
|
476 }
|
Chris@67
|
477
|
Chris@67
|
478 if (!containsANewerPlugin(b, a) &&
|
Chris@67
|
479 !a.empty() &&
|
Chris@67
|
480 !b.empty() &&
|
Chris@67
|
481 containsANovelPlugin(a, b) &&
|
Chris@67
|
482 !containsANovelPlugin(b, a)) {
|
Chris@67
|
483 return true;
|
Chris@67
|
484 }
|
Chris@67
|
485
|
Chris@67
|
486 return false;
|
Chris@67
|
487 }
|
Chris@67
|
488
|
Chris@67
|
489 QString
|
Chris@67
|
490 versionsString(const map<QString, int> &vv)
|
Chris@67
|
491 {
|
Chris@67
|
492 QStringList pv;
|
Chris@67
|
493 for (auto v: vv) {
|
Chris@67
|
494 pv.push_back(QString("%1:%2").arg(v.first).arg(v.second));
|
Chris@67
|
495 }
|
Chris@67
|
496 return "{ " + pv.join(", ") + " }";
|
Chris@67
|
497 }
|
Chris@67
|
498
|
Chris@75
|
499 enum class RelativeStatus {
|
Chris@75
|
500 New,
|
Chris@75
|
501 Same,
|
Chris@75
|
502 Upgrade,
|
Chris@75
|
503 Downgrade,
|
Chris@75
|
504 TargetNotLoadable
|
Chris@75
|
505 };
|
Chris@75
|
506
|
Chris@75
|
507 QString
|
Chris@75
|
508 relativeStatusLabel(RelativeStatus status) {
|
Chris@75
|
509 switch (status) {
|
Chris@76
|
510 case RelativeStatus::New: return QObject::tr("Not yet installed");
|
Chris@76
|
511 case RelativeStatus::Same: return QObject::tr("Already installed");
|
Chris@76
|
512 case RelativeStatus::Upgrade: return QObject::tr("Update");
|
Chris@76
|
513 case RelativeStatus::Downgrade: return QObject::tr("Newer version installed");
|
Chris@84
|
514 case RelativeStatus::TargetNotLoadable: return QObject::tr("Installed version not working");
|
Chris@79
|
515 default: return {};
|
Chris@75
|
516 }
|
Chris@75
|
517 }
|
Chris@75
|
518
|
Chris@75
|
519 RelativeStatus
|
Chris@75
|
520 getRelativeStatus(LibraryInfo info, QString targetDir)
|
Chris@75
|
521 {
|
Chris@75
|
522 QString destination = targetDir + "/" + info.fileName;
|
Chris@75
|
523
|
Chris@75
|
524 RelativeStatus status = RelativeStatus::New;
|
Chris@75
|
525
|
Chris@75
|
526 SVCERR << "\ngetRelativeStatus: " << info.fileName << ":\n";
|
Chris@75
|
527
|
Chris@75
|
528 if (QFileInfo(destination).exists()) {
|
Chris@75
|
529
|
Chris@75
|
530 auto installed = getLibraryPluginVersions(destination);
|
Chris@75
|
531
|
Chris@75
|
532 SVCERR << " * installed: " << versionsString(installed)
|
Chris@75
|
533 << "\n * packaged: " << versionsString(info.pluginVersions)
|
Chris@75
|
534 << endl;
|
Chris@75
|
535
|
Chris@75
|
536 status = RelativeStatus::Same;
|
Chris@75
|
537
|
Chris@75
|
538 if (installed.empty()) {
|
Chris@75
|
539 status = RelativeStatus::TargetNotLoadable;
|
Chris@75
|
540 }
|
Chris@75
|
541
|
Chris@75
|
542 if (isLibraryNewer(installed, info.pluginVersions)) {
|
Chris@75
|
543 status = RelativeStatus::Downgrade;
|
Chris@75
|
544 }
|
Chris@75
|
545
|
Chris@75
|
546 if (isLibraryNewer(info.pluginVersions, installed)) {
|
Chris@75
|
547 status = RelativeStatus::Upgrade;
|
Chris@75
|
548 }
|
Chris@75
|
549 }
|
Chris@75
|
550
|
Chris@75
|
551 SVCERR << " - relative status: " << relativeStatusLabel(status) << endl;
|
Chris@75
|
552
|
Chris@75
|
553 return status;
|
Chris@75
|
554 }
|
Chris@75
|
555
|
Chris@81
|
556 QString
|
Chris@75
|
557 installLibrary(LibraryInfo info, QString targetDir)
|
Chris@42
|
558 {
|
Chris@75
|
559 QString library = info.fileName;
|
Chris@52
|
560 QString source = ":out";
|
Chris@52
|
561 QFile f(source + "/" + library);
|
Chris@75
|
562 QString destination = targetDir + "/" + library;
|
Chris@67
|
563
|
Chris@67
|
564 if (QFileInfo(destination).exists()) {
|
Chris@70
|
565 auto installed = getLibraryPluginVersions(destination);
|
Chris@68
|
566 } else {
|
Chris@68
|
567 SVCERR << "Note: library " << library
|
Chris@68
|
568 << " is not yet installed, not comparing versions" << endl;
|
Chris@67
|
569 }
|
Chris@82
|
570
|
Chris@82
|
571 //!!! if destination exists, move it aside
|
Chris@52
|
572
|
Chris@51
|
573 SVCERR << "Copying " << library.toStdString() << " to "
|
Chris@51
|
574 << destination.toStdString() << "..." << endl;
|
Chris@42
|
575 if (!f.copy(destination)) {
|
Chris@51
|
576 SVCERR << "Failed to copy " << library.toStdString()
|
Chris@51
|
577 << " to target " << destination.toStdString() << endl;
|
Chris@81
|
578 return QObject::tr("Failed to copy library to destination directory");
|
Chris@42
|
579 }
|
Chris@42
|
580 if (!QFile::setPermissions
|
Chris@42
|
581 (destination,
|
Chris@42
|
582 QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner |
|
Chris@42
|
583 QFile::ReadGroup | QFile::ExeGroup |
|
Chris@42
|
584 QFile::ReadOther | QFile::ExeOther)) {
|
Chris@51
|
585 SVCERR << "Failed to set permissions on "
|
Chris@51
|
586 << library.toStdString() << endl;
|
Chris@81
|
587 return QObject::tr("Failed to set correct permissions on installed library");
|
Chris@42
|
588 }
|
Chris@52
|
589
|
Chris@52
|
590 QString base = QFileInfo(library).baseName();
|
Chris@52
|
591 QDir dir(source);
|
Chris@52
|
592 auto entries = dir.entryList({ base + "*" });
|
Chris@52
|
593 for (auto e: entries) {
|
Chris@52
|
594 if (e == library) continue;
|
Chris@75
|
595 QString destination = targetDir + "/" + e;
|
Chris@52
|
596 SVCERR << "Copying " << e.toStdString() << " to "
|
Chris@52
|
597 << destination.toStdString() << "..." << endl;
|
Chris@52
|
598 if (!QFile(source + "/" + e).copy(destination)) {
|
Chris@52
|
599 SVCERR << "Failed to copy " << e.toStdString()
|
Chris@52
|
600 << " to target " << destination.toStdString()
|
Chris@52
|
601 << " (ignoring)" << endl;
|
Chris@68
|
602 continue;
|
Chris@68
|
603 }
|
Chris@68
|
604 if (!QFile::setPermissions
|
Chris@68
|
605 (destination,
|
Chris@68
|
606 QFile::ReadOwner | QFile::WriteOwner |
|
Chris@68
|
607 QFile::ReadGroup |
|
Chris@68
|
608 QFile::ReadOther)) {
|
Chris@68
|
609 SVCERR << "Failed to set permissions on "
|
Chris@68
|
610 << destination.toStdString()
|
Chris@68
|
611 << " (ignoring)" << endl;
|
Chris@68
|
612 continue;
|
Chris@52
|
613 }
|
Chris@52
|
614 }
|
Chris@81
|
615
|
Chris@81
|
616 return {};
|
Chris@42
|
617 }
|
Chris@42
|
618
|
Chris@75
|
619 vector<LibraryInfo>
|
Chris@75
|
620 getUserApprovedPluginLibraries(vector<LibraryInfo> libraries,
|
Chris@75
|
621 QString targetDir)
|
Chris@42
|
622 {
|
Chris@42
|
623 QDialog dialog;
|
Chris@46
|
624
|
Chris@84
|
625 int fontHeight = QFontMetrics(dialog.font()).height();
|
Chris@84
|
626 int dpratio = dialog.devicePixelRatio();
|
Chris@84
|
627
|
Chris@46
|
628 auto mainLayout = new QGridLayout;
|
Chris@47
|
629 mainLayout->setSpacing(0);
|
Chris@46
|
630 dialog.setLayout(mainLayout);
|
Chris@46
|
631
|
Chris@46
|
632 int mainRow = 0;
|
Chris@46
|
633
|
Chris@74
|
634 auto selectionFrame = new QWidget;
|
Chris@74
|
635 mainLayout->addWidget(selectionFrame, mainRow, 0);
|
Chris@47
|
636 ++mainRow;
|
Chris@46
|
637
|
Chris@46
|
638 auto selectionLayout = new QGridLayout;
|
Chris@84
|
639 selectionLayout->setContentsMargins(0, 0, 0, 0);
|
Chris@84
|
640 selectionLayout->setSpacing(fontHeight / 6);
|
Chris@46
|
641 selectionFrame->setLayout(selectionLayout);
|
Chris@84
|
642
|
Chris@46
|
643 int selectionRow = 0;
|
Chris@84
|
644 int checkColumn = 0;
|
Chris@84
|
645 int titleColumn = 1;
|
Chris@84
|
646 int statusColumn = 2;
|
Chris@84
|
647 int infoColumn = 3;
|
Chris@79
|
648
|
Chris@79
|
649 selectionLayout->addWidget
|
Chris@79
|
650 (new QLabel(QObject::tr("<b>Vamp Plugin Pack</b> v%1")
|
Chris@79
|
651 .arg(PACK_VERSION)),
|
Chris@84
|
652 selectionRow, titleColumn, 1, 3);
|
Chris@79
|
653 ++selectionRow;
|
Chris@79
|
654
|
Chris@79
|
655 selectionLayout->addWidget
|
Chris@79
|
656 (new QLabel(QObject::tr("Select the plugin libraries to install:")),
|
Chris@84
|
657 selectionRow, titleColumn, 1, 3);
|
Chris@79
|
658 ++selectionRow;
|
Chris@74
|
659
|
Chris@74
|
660 auto checkAll = new QCheckBox;
|
Chris@74
|
661 checkAll->setChecked(true);
|
Chris@84
|
662 selectionLayout->addWidget
|
Chris@84
|
663 (checkAll, selectionRow, checkColumn, Qt::AlignHCenter);
|
Chris@74
|
664 ++selectionRow;
|
Chris@74
|
665
|
Chris@74
|
666 auto checkArrow = new QLabel("▼");
|
Chris@74
|
667 checkArrow->setTextFormat(Qt::RichText);
|
Chris@84
|
668 selectionLayout->addWidget
|
Chris@84
|
669 (checkArrow, selectionRow, checkColumn, Qt::AlignHCenter);
|
Chris@74
|
670 ++selectionRow;
|
Chris@42
|
671
|
Chris@67
|
672 map<QString, QCheckBox *> checkBoxMap; // filename -> checkbox
|
Chris@67
|
673 map<QString, LibraryInfo> libFileInfo; // filename -> info
|
Chris@76
|
674 map<QString, RelativeStatus> statuses; // filename -> status
|
Chris@43
|
675
|
Chris@67
|
676 map<QString, LibraryInfo, function<bool (QString, QString)>>
|
Chris@49
|
677 orderedInfo
|
Chris@49
|
678 ([](QString k1, QString k2) {
|
Chris@49
|
679 return k1.localeAwareCompare(k2) < 0;
|
Chris@49
|
680 });
|
Chris@43
|
681 for (auto info: libraries) {
|
Chris@43
|
682 orderedInfo[info.title] = info;
|
Chris@43
|
683 }
|
Chris@53
|
684
|
Chris@77
|
685 QPixmap infoMap(fontHeight * dpratio, fontHeight * dpratio);
|
Chris@77
|
686 QPixmap moreMap(fontHeight * dpratio * 2, fontHeight * dpratio * 2);
|
Chris@74
|
687 infoMap.fill(Qt::transparent);
|
Chris@74
|
688 moreMap.fill(Qt::transparent);
|
Chris@74
|
689 QSvgRenderer renderer(QString(":icons/scalable/info.svg"));
|
Chris@74
|
690 QPainter painter;
|
Chris@74
|
691 painter.begin(&infoMap);
|
Chris@74
|
692 renderer.render(&painter);
|
Chris@74
|
693 painter.end();
|
Chris@74
|
694 painter.begin(&moreMap);
|
Chris@74
|
695 renderer.render(&painter);
|
Chris@74
|
696 painter.end();
|
Chris@74
|
697
|
Chris@76
|
698 auto shouldCheck = [](RelativeStatus status) {
|
Chris@76
|
699 return (status == RelativeStatus::New ||
|
Chris@76
|
700 status == RelativeStatus::Upgrade ||
|
Chris@76
|
701 status == RelativeStatus::TargetNotLoadable);
|
Chris@76
|
702 };
|
Chris@76
|
703
|
Chris@43
|
704 for (auto ip: orderedInfo) {
|
Chris@46
|
705
|
Chris@46
|
706 auto cb = new QCheckBox;
|
Chris@84
|
707 selectionLayout->addWidget
|
Chris@84
|
708 (cb, selectionRow, checkColumn, Qt::AlignHCenter);
|
Chris@46
|
709
|
Chris@43
|
710 LibraryInfo info = ip.second;
|
Chris@72
|
711
|
Chris@76
|
712 auto shortLabel = new QLabel(info.title);
|
Chris@84
|
713 selectionLayout->addWidget(shortLabel, selectionRow, titleColumn);
|
Chris@76
|
714
|
Chris@75
|
715 RelativeStatus relativeStatus = getRelativeStatus(info, targetDir);
|
Chris@76
|
716 auto statusLabel = new QLabel(relativeStatusLabel(relativeStatus));
|
Chris@84
|
717 selectionLayout->addWidget(statusLabel, selectionRow, statusColumn);
|
Chris@76
|
718 cb->setChecked(shouldCheck(relativeStatus));
|
Chris@75
|
719
|
Chris@79
|
720 auto infoButton = new QToolButton;
|
Chris@79
|
721 infoButton->setAutoRaise(true);
|
Chris@79
|
722 infoButton->setIcon(infoMap);
|
Chris@79
|
723 infoButton->setIconSize(QSize(fontHeight, fontHeight));
|
Chris@77
|
724
|
Chris@77
|
725 #ifdef Q_OS_MAC
|
Chris@79
|
726 infoButton->setFixedSize(QSize(int(fontHeight * 1.2),
|
Chris@77
|
727 int(fontHeight * 1.2)));
|
Chris@79
|
728 infoButton->setStyleSheet("QToolButton { border: none; }");
|
Chris@77
|
729 #endif
|
Chris@77
|
730
|
Chris@84
|
731 selectionLayout->addWidget(infoButton, selectionRow, infoColumn);
|
Chris@46
|
732
|
Chris@46
|
733 ++selectionRow;
|
Chris@46
|
734
|
Chris@77
|
735 QString moreTitleText = QObject::tr("<b>%1</b><br><i>%2</i>")
|
Chris@72
|
736 .arg(info.title)
|
Chris@77
|
737 .arg(info.maker);
|
Chris@77
|
738
|
Chris@79
|
739 QString moreInfoText = info.description;
|
Chris@79
|
740
|
Chris@79
|
741 if (info.page != "") {
|
Chris@79
|
742 moreInfoText += QObject::tr("<br><a href=\"%1\">%2</a>")
|
Chris@79
|
743 .arg(info.page)
|
Chris@79
|
744 .arg(info.page);
|
Chris@79
|
745 }
|
Chris@79
|
746
|
Chris@79
|
747 moreInfoText += QObject::tr("<br><br>Library contains:<ul>");
|
Chris@73
|
748
|
Chris@73
|
749 int n = 0;
|
Chris@73
|
750 bool closed = false;
|
Chris@73
|
751 for (auto title: info.pluginTitles) {
|
Chris@73
|
752 if (n == 10 && info.pluginTitles.size() > 15) {
|
Chris@77
|
753 moreInfoText += QObject::tr("</ul>");
|
Chris@77
|
754 moreInfoText += QObject::tr("... and %n other plugins.<br><br>",
|
Chris@77
|
755 "",
|
Chris@77
|
756 info.pluginTitles.size() - n);
|
Chris@73
|
757 closed = true;
|
Chris@73
|
758 break;
|
Chris@73
|
759 }
|
Chris@77
|
760 moreInfoText += QObject::tr("<li>%1</li>").arg(title);
|
Chris@73
|
761 ++n;
|
Chris@73
|
762 }
|
Chris@73
|
763
|
Chris@73
|
764 if (!closed) {
|
Chris@77
|
765 moreInfoText += QObject::tr("</ul>");
|
Chris@73
|
766 }
|
Chris@74
|
767
|
Chris@74
|
768 if (info.licence != "") {
|
Chris@77
|
769 moreInfoText += QObject::tr("Provided under the %1.<br>")
|
Chris@77
|
770 .arg(info.licence);
|
Chris@74
|
771 }
|
Chris@72
|
772
|
Chris@79
|
773 QObject::connect(infoButton, &QAbstractButton::clicked,
|
Chris@72
|
774 [=]() {
|
Chris@74
|
775 QMessageBox mbox;
|
Chris@74
|
776 mbox.setIconPixmap(moreMap);
|
Chris@74
|
777 mbox.setWindowTitle(QObject::tr("Library contents"));
|
Chris@77
|
778 mbox.setText(moreTitleText);
|
Chris@77
|
779 mbox.setInformativeText(moreInfoText);
|
Chris@74
|
780 mbox.exec();
|
Chris@72
|
781 });
|
Chris@72
|
782
|
Chris@43
|
783 checkBoxMap[info.fileName] = cb;
|
Chris@67
|
784 libFileInfo[info.fileName] = info;
|
Chris@76
|
785 statuses[info.fileName] = relativeStatus;
|
Chris@42
|
786 }
|
Chris@42
|
787
|
Chris@79
|
788 selectionLayout->addItem(new QSpacerItem(1, (fontHeight*2) / 3),
|
Chris@79
|
789 selectionRow, 0);
|
Chris@79
|
790 ++selectionRow;
|
Chris@79
|
791
|
Chris@79
|
792 selectionLayout->addWidget
|
Chris@79
|
793 (new QLabel(QObject::tr("Installation will be to: %1").arg(targetDir)),
|
Chris@84
|
794 selectionRow, titleColumn, 1, 3);
|
Chris@79
|
795 ++selectionRow;
|
Chris@79
|
796
|
Chris@47
|
797 QObject::connect(checkAll, &QCheckBox::toggled,
|
Chris@72
|
798 [=](bool toCheck) {
|
Chris@47
|
799 for (auto p: checkBoxMap) {
|
Chris@47
|
800 p.second->setChecked(toCheck);
|
Chris@47
|
801 }
|
Chris@47
|
802 });
|
Chris@79
|
803
|
Chris@79
|
804 mainLayout->addItem(new QSpacerItem(1, fontHeight), mainRow, 0);
|
Chris@79
|
805 ++mainRow;
|
Chris@79
|
806
|
Chris@42
|
807 auto bb = new QDialogButtonBox(QDialogButtonBox::Ok |
|
Chris@76
|
808 QDialogButtonBox::Cancel |
|
Chris@76
|
809 QDialogButtonBox::Reset);
|
Chris@79
|
810 bb->button(QDialogButtonBox::Ok)->setText(QObject::tr("Install"));
|
Chris@74
|
811 mainLayout->addWidget(bb, mainRow, 0);
|
Chris@46
|
812 ++mainRow;
|
Chris@47
|
813
|
Chris@74
|
814 mainLayout->setRowStretch(0, 10);
|
Chris@74
|
815 mainLayout->setColumnStretch(0, 10);
|
Chris@74
|
816 selectionLayout->setColumnMinimumWidth(0, 50);
|
Chris@74
|
817 selectionLayout->setColumnStretch(1, 10);
|
Chris@47
|
818
|
Chris@76
|
819 QObject::connect
|
Chris@76
|
820 (bb, &QDialogButtonBox::clicked,
|
Chris@76
|
821 [&](QAbstractButton *button) {
|
Chris@76
|
822
|
Chris@76
|
823 auto role = bb->buttonRole(button);
|
Chris@76
|
824
|
Chris@76
|
825 switch (role) {
|
Chris@76
|
826
|
Chris@76
|
827 case QDialogButtonBox::AcceptRole: {
|
Chris@76
|
828 bool downgrade = false;
|
Chris@76
|
829 for (const auto &p: checkBoxMap) {
|
Chris@76
|
830 if (p.second->isChecked() &&
|
Chris@76
|
831 statuses.at(p.first) == RelativeStatus::Downgrade) {
|
Chris@76
|
832 downgrade = true;
|
Chris@76
|
833 break;
|
Chris@76
|
834 }
|
Chris@76
|
835 }
|
Chris@76
|
836 if (downgrade) {
|
Chris@76
|
837 if (QMessageBox::warning
|
Chris@76
|
838 (bb, QObject::tr("Downgrade?"),
|
Chris@76
|
839 QObject::tr("You have asked to downgrade one or more plugin libraries that are already installed.<br><br>Are you sure?"),
|
Chris@76
|
840 QMessageBox::Ok | QMessageBox::Cancel,
|
Chris@76
|
841 QMessageBox::Cancel) == QMessageBox::Ok) {
|
Chris@76
|
842 dialog.accept();
|
Chris@76
|
843 }
|
Chris@76
|
844 } else {
|
Chris@76
|
845 dialog.accept();
|
Chris@76
|
846 }
|
Chris@76
|
847 break;
|
Chris@76
|
848 }
|
Chris@76
|
849
|
Chris@76
|
850 case QDialogButtonBox::RejectRole:
|
Chris@76
|
851 dialog.reject();
|
Chris@76
|
852 break;
|
Chris@76
|
853
|
Chris@76
|
854 case QDialogButtonBox::ResetRole:
|
Chris@76
|
855 for (const auto &p: checkBoxMap) {
|
Chris@76
|
856 p.second->setChecked(shouldCheck(statuses.at(p.first)));
|
Chris@76
|
857 }
|
Chris@76
|
858 break;
|
Chris@76
|
859
|
Chris@76
|
860 default:
|
Chris@76
|
861 SVCERR << "WARNING: Unexpected role " << role << endl;
|
Chris@76
|
862 }
|
Chris@76
|
863 });
|
Chris@53
|
864
|
Chris@70
|
865 if (dialog.exec() != QDialog::Accepted) {
|
Chris@51
|
866 SVCERR << "rejected" << endl;
|
Chris@70
|
867 return {};
|
Chris@42
|
868 }
|
Chris@42
|
869
|
Chris@75
|
870 vector<LibraryInfo> approved;
|
Chris@42
|
871 for (const auto &p: checkBoxMap) {
|
Chris@42
|
872 if (p.second->isChecked()) {
|
Chris@75
|
873 approved.push_back(libFileInfo[p.first]);
|
Chris@33
|
874 }
|
Chris@42
|
875 }
|
Chris@42
|
876
|
Chris@42
|
877 return approved;
|
Chris@42
|
878 }
|
Chris@42
|
879
|
Chris@42
|
880 int main(int argc, char **argv)
|
Chris@42
|
881 {
|
Chris@42
|
882 QApplication app(argc, argv);
|
Chris@42
|
883
|
Chris@51
|
884 QApplication::setOrganizationName("sonic-visualiser");
|
Chris@51
|
885 QApplication::setOrganizationDomain("sonicvisualiser.org");
|
Chris@51
|
886 QApplication::setApplicationName(QApplication::tr("Vamp Plugin Pack Installer"));
|
Chris@51
|
887
|
Chris@77
|
888 QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
Chris@77
|
889
|
Chris@51
|
890 #ifdef Q_OS_WIN32
|
Chris@51
|
891 QFont font(QApplication::font());
|
Chris@51
|
892 QString preferredFamily = "Segoe UI";
|
Chris@51
|
893 font.setFamily(preferredFamily);
|
Chris@51
|
894 if (QFontInfo(font).family() == preferredFamily) {
|
Chris@51
|
895 font.setPointSize(10);
|
Chris@51
|
896 QApplication::setFont(font);
|
Chris@51
|
897 }
|
Chris@77
|
898 #else
|
Chris@77
|
899 #ifdef Q_OS_MAC
|
Chris@77
|
900 QFont font(QApplication::font());
|
Chris@77
|
901 QString preferredFamily = "Lucida Grande";
|
Chris@77
|
902 font.setFamily(preferredFamily);
|
Chris@77
|
903 if (QFontInfo(font).family() == preferredFamily) {
|
Chris@77
|
904 QApplication::setFont(font);
|
Chris@77
|
905 }
|
Chris@77
|
906 #endif
|
Chris@51
|
907 #endif
|
Chris@51
|
908
|
Chris@42
|
909 QString target = getDefaultInstallDirectory();
|
Chris@42
|
910 if (target == "") {
|
Chris@42
|
911 return 1;
|
Chris@42
|
912 }
|
Chris@42
|
913
|
Chris@42
|
914 QStringList libraries = getPluginLibraryList();
|
Chris@42
|
915
|
Chris@43
|
916 auto rdfStore = loadLibrariesRdf();
|
Chris@43
|
917
|
Chris@43
|
918 auto info = getLibraryInfo(*rdfStore, libraries);
|
Chris@43
|
919
|
Chris@75
|
920 vector<LibraryInfo> toInstall =
|
Chris@75
|
921 getUserApprovedPluginLibraries(info, target);
|
Chris@52
|
922
|
Chris@83
|
923 if (toInstall.empty()) { // Cancelled, or nothing selected
|
Chris@83
|
924 return 0;
|
Chris@83
|
925 }
|
Chris@83
|
926
|
Chris@83
|
927 if (!QDir(target).exists()) {
|
Chris@83
|
928 QDir().mkpath(target);
|
Chris@52
|
929 }
|
Chris@81
|
930
|
Chris@81
|
931 QProgressDialog progress(QObject::tr("Installing..."),
|
Chris@81
|
932 QObject::tr("Stop"), 0, toInstall.size() + 1);
|
Chris@81
|
933 progress.setMinimumDuration(0);
|
Chris@81
|
934
|
Chris@81
|
935 int pval = 0;
|
Chris@81
|
936 bool complete = true;
|
Chris@42
|
937
|
Chris@42
|
938 for (auto lib: toInstall) {
|
Chris@81
|
939 progress.setValue(++pval);
|
Chris@81
|
940 QThread::currentThread()->msleep(40);
|
Chris@81
|
941 app.processEvents();
|
Chris@81
|
942 if (progress.wasCanceled()) {
|
Chris@81
|
943 complete = false;
|
Chris@81
|
944 break;
|
Chris@81
|
945 }
|
Chris@81
|
946 QString error = installLibrary(lib, target);
|
Chris@81
|
947 if (error != "") {
|
Chris@81
|
948 complete = false;
|
Chris@81
|
949 if (QMessageBox::critical
|
Chris@81
|
950 (&progress,
|
Chris@81
|
951 QObject::tr("Install failed"),
|
Chris@81
|
952 QObject::tr("Failed to install library \"%1\": %2")
|
Chris@81
|
953 .arg(lib.title)
|
Chris@81
|
954 .arg(error),
|
Chris@81
|
955 QMessageBox::Abort | QMessageBox::Ignore,
|
Chris@81
|
956 QMessageBox::Ignore) ==
|
Chris@81
|
957 QMessageBox::Abort) {
|
Chris@81
|
958 break;
|
Chris@81
|
959 }
|
Chris@81
|
960 }
|
Chris@81
|
961 }
|
Chris@81
|
962
|
Chris@81
|
963 progress.hide();
|
Chris@81
|
964
|
Chris@81
|
965 if (complete) {
|
Chris@81
|
966 QMessageBox::information
|
Chris@81
|
967 (&progress,
|
Chris@81
|
968 QObject::tr("Complete"),
|
Chris@81
|
969 QObject::tr("Installation completed successfully"),
|
Chris@81
|
970 QMessageBox::Ok,
|
Chris@81
|
971 QMessageBox::Ok);
|
Chris@81
|
972 } else {
|
Chris@81
|
973 QMessageBox::information
|
Chris@81
|
974 (&progress,
|
Chris@81
|
975 QObject::tr("Incomplete"),
|
Chris@81
|
976 QObject::tr("Installation was not complete. Exiting"),
|
Chris@81
|
977 QMessageBox::Ok,
|
Chris@81
|
978 QMessageBox::Ok);
|
Chris@33
|
979 }
|
Chris@33
|
980
|
Chris@83
|
981 return (complete ? 0 : 2);
|
Chris@32
|
982 }
|