annotate base/HelperExecPath.cpp @ 1765:2e2497cba59e by-id

Remove comment - these are now connected
author Chris Cannam
date Wed, 17 Jul 2019 12:59:57 +0100
parents a9d0b5a2c242
children 008e413f6aaf
rev   line source
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@1246 23 QStringList
Chris@1246 24 HelperExecPath::getTags()
Chris@1243 25 {
Chris@1243 26 if (sizeof(void *) == 8) {
Chris@1246 27 if (m_type == NativeArchitectureOnly) {
Chris@1246 28 return { "64", "" };
Chris@1246 29 } else {
Chris@1246 30 return { "64", "", "32" };
Chris@1246 31 }
Chris@1243 32 } else {
Chris@1246 33 return { "", "32" };
Chris@1243 34 }
Chris@1243 35 }
Chris@1243 36
Chris@1243 37 static bool
Chris@1243 38 isGood(QString path)
Chris@1243 39 {
Chris@1243 40 return QFile(path).exists() && QFileInfo(path).isExecutable();
Chris@1243 41 }
Chris@1243 42
Chris@1246 43 QList<HelperExecPath::HelperExec>
Chris@1243 44 HelperExecPath::getHelperExecutables(QString basename)
Chris@1243 45 {
Chris@1243 46 QStringList dummy;
Chris@1243 47 return search(basename, dummy);
Chris@1243 48 }
Chris@1243 49
Chris@1243 50 QString
Chris@1243 51 HelperExecPath::getHelperExecutable(QString basename)
Chris@1243 52 {
Chris@1246 53 auto execs = getHelperExecutables(basename);
Chris@1243 54 if (execs.empty()) return "";
Chris@1246 55 else return execs[0].executable;
Chris@1243 56 }
Chris@1243 57
Chris@1243 58 QStringList
Chris@1243 59 HelperExecPath::getHelperDirPaths()
Chris@1243 60 {
Chris@1694 61 // Helpers are expected to exist either in the same directory as
Chris@1694 62 // this executable was found, or in either a subdirectory called
Chris@1694 63 // helpers, or on the Mac only, a sibling called Resources.
Chris@1694 64
Chris@1243 65 QStringList dirs;
Chris@1243 66 QString myDir = QCoreApplication::applicationDirPath();
Chris@1694 67 #ifdef Q_OS_MAC
Chris@1694 68 dirs.push_back(myDir + "/../Resources");
Chris@1694 69 #else
Chris@1243 70 dirs.push_back(myDir + "/helpers");
Chris@1694 71 #endif
Chris@1243 72 dirs.push_back(myDir);
Chris@1243 73 return dirs;
Chris@1243 74 }
Chris@1243 75
Chris@1243 76 QStringList
Chris@1243 77 HelperExecPath::getHelperCandidatePaths(QString basename)
Chris@1243 78 {
Chris@1243 79 QStringList candidates;
Chris@1243 80 (void)search(basename, candidates);
Chris@1243 81 return candidates;
Chris@1243 82 }
Chris@1243 83
Chris@1246 84 QList<HelperExecPath::HelperExec>
Chris@1243 85 HelperExecPath::search(QString basename, QStringList &candidates)
Chris@1243 86 {
Chris@1243 87 QString extension = "";
Chris@1243 88 #ifdef _WIN32
Chris@1243 89 extension = ".exe";
Chris@1243 90 #endif
Chris@1243 91
Chris@1246 92 QList<HelperExec> executables;
Chris@1243 93 QStringList dirs = getHelperDirPaths();
Chris@1243 94
Chris@1246 95 for (QString t: getTags()) {
Chris@1243 96 for (QString d: dirs) {
Chris@1246 97 QString path = d + QDir::separator() + basename;
Chris@1246 98 if (t != QString()) path += "-" + t;
Chris@1246 99 path += extension;
Chris@1243 100 candidates.push_back(path);
Chris@1243 101 if (isGood(path)) {
Chris@1246 102 executables.push_back({ path, t });
Chris@1243 103 break;
Chris@1243 104 }
Chris@1243 105 }
Chris@1243 106 }
Chris@1243 107
Chris@1243 108 return executables;
Chris@1243 109 }
Chris@1243 110