1 //=============================================================================
2 // MusE Score
3 // Linux Music Score Editor
4 //
5 // Copyright (C) 2018 Werner Schweer and others
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //=============================================================================
19
20 #include "extension.h"
21 #include "preferences.h"
22 #include "libmscore/utils.h"
23
24 namespace Ms {
25
26 //---------------------------------------------------------
27 // getDirectoriesByType
28 //---------------------------------------------------------
29
getDirectoriesByType(const char * type)30 QStringList Extension::getDirectoriesByType(const char* type)
31 {
32 QStringList result;
33 QDir d(preferences.getString(PREF_APP_PATHS_MYEXTENSIONS));
34 for (const auto &dd : d.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot| QDir::Readable | QDir::NoSymLinks)) {
35 QDir extensionsDir(dd.absoluteFilePath());
36 auto extDir = extensionsDir.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot| QDir::Readable | QDir::NoSymLinks, QDir::Name);
37 // take the most recent version only
38 if (!extDir.isEmpty()) {
39 QString typeDir = QString("%1/%2").arg(extDir.last().absoluteFilePath(), type);
40 if (QFileInfo::exists(typeDir))
41 result.append(typeDir);
42 }
43 }
44 return result;
45 }
46
47 //---------------------------------------------------------
48 // isInstalled
49 //---------------------------------------------------------
50
isInstalled(QString extensionId)51 bool Extension::isInstalled(QString extensionId)
52 {
53 QDir extensionDir(QString("%1/%2").arg(preferences.getString(PREF_APP_PATHS_MYEXTENSIONS), extensionId));
54 return extensionDir.exists();
55 }
56
57 //---------------------------------------------------------
58 // getLatestVersion
59 //---------------------------------------------------------
60
getLatestVersion(QString extensionId)61 QString Extension::getLatestVersion(QString extensionId)
62 {
63 QString result = "0.0";
64 QDir extensionDir(QString("%1/%2").arg(preferences.getString(PREF_APP_PATHS_MYEXTENSIONS), extensionId));
65 auto extDir = extensionDir.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot| QDir::Readable | QDir::NoSymLinks, QDir::Name);
66 if (!extDir.isEmpty())
67 result = extDir.last().fileName();
68 return result;
69 }
70 }
71