fix #273558: Add a way to uninstall extensions

This commit is contained in:
lasconic 2018-06-23 13:31:56 +02:00
parent b8d0b9ebc3
commit fdf55e1a2f
8 changed files with 129 additions and 22 deletions

View file

@ -37,9 +37,9 @@ QStringList Extension::getDirectoriesByType(const char* type)
auto extDir = extensionsDir.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot| QDir::Readable | QDir::NoSymLinks, QDir::Name);
// take the most recent version only
if (!extDir.isEmpty()) {
QString sfzDir = QString("%1/%2").arg(extDir.last().absoluteFilePath()).arg(type);
if (QFileInfo(sfzDir).exists())
result.append(sfzDir);
QString typeDir = QString("%1/%2").arg(extDir.last().absoluteFilePath()).arg(type);
if (QFileInfo(typeDir).exists())
result.append(typeDir);
}
}
return result;

View file

@ -39,7 +39,6 @@ class Extension {
static QStringList getDirectoriesByType(const char* type);
static bool isInstalled(QString extensionId);
static QString getLatestVersion(QString extensionId);
static bool importExtension(QString path);
};

View file

@ -808,6 +808,68 @@ bool MuseScore::importExtension(QString path, QWidget* parent)
return true;
}
//---------------------------------------------------------
// uninstallExtension
//---------------------------------------------------------
bool MuseScore::uninstallExtension(QString extensionId)
{
QString version = Extension::getLatestVersion(extensionId);
// Before install: remove sfz from zerberus
QDir sfzDir(QString("%1/%2/%3/%4").arg(preferences.getString(PREF_APP_PATHS_MYEXTENSIONS)).arg(extensionId).arg(version).arg(Extension::sfzsDir));
if (sfzDir.exists()) {
// get all sfz files
QDirIterator it(sfzDir.absolutePath(), QStringList("*.sfz"), QDir::Files, QDirIterator::Subdirectories);
Synthesizer* s = synti->synthesizer("Zerberus");
bool found = it.hasNext();
while (it.hasNext()) {
it.next();
s->removeSoundFont(it.fileInfo().absoluteFilePath());
}
if (found)
synti->storeState();
}
// Before install: remove soundfont from fluid
QDir sfDir(QString("%1/%2/%3/%4").arg(preferences.getString(PREF_APP_PATHS_MYEXTENSIONS)).arg(extensionId).arg(version).arg(Extension::soundfontsDir));
if (sfDir.exists()) {
// get all soundfont files
QStringList filters("*.sf2");
filters.append("*.sf3");
QDirIterator it(sfzDir.absolutePath(), filters, QDir::Files, QDirIterator::Subdirectories);
Synthesizer* s = synti->synthesizer("Fluid");
bool found = it.hasNext();
while (it.hasNext()) {
it.next();
s->removeSoundFont(it.fileInfo().absoluteFilePath());
}
if (found)
synti->storeState();
}
bool refreshWorkspaces = false;
QDir workspacesDir(QString("%1/%2/%3/%4").arg(preferences.getString(PREF_APP_PATHS_MYEXTENSIONS)).arg(extensionId).arg(version).arg(Extension::workspacesDir));
if (workspacesDir.exists()) {
auto wsList = workspacesDir.entryInfoList(QStringList("*.workspace"), QDir::Files);
if (!wsList.isEmpty())
refreshWorkspaces = true;
}
// delete directories
QDir extensionDir(QString("%1/%2").arg(preferences.getString(PREF_APP_PATHS_MYEXTENSIONS)).arg(extensionId));
extensionDir.removeRecursively();
// update UI
delete newWizard;
newWizard = 0;
mscore->reloadInstrumentTemplates();
mscore->updateInstrumentDialog();
if (refreshWorkspaces) {
Workspace::refreshWorkspaces();
paletteBox->updateWorkspaces();
paletteBox->selectWorkspace("Basic");
}
return true;
}
//---------------------------------------------------------
// MuseScore
//---------------------------------------------------------

View file

@ -783,6 +783,7 @@ class MuseScore : public QMainWindow, public MuseScoreCore {
void updateWindowTitle(Score* score);
bool importExtension(QString path, QWidget* parent = nullptr);
bool uninstallExtension(QString extensionId);
};
extern MuseScore* mscore;

View file

@ -89,8 +89,8 @@ void ResourceManager::displayExtensions()
int row = 0;
int col = 0;
QPushButton* updateButtons[rowCount];
QPushButton* temp;
QPushButton* buttonInstall;
QPushButton* buttonUninstall;
extensionsTable->verticalHeader()->show();
QStringList extensions = result.object().keys();
@ -112,26 +112,34 @@ void ResourceManager::displayExtensions()
extensionsTable->setItem(row, col++, new QTableWidgetItem(name));
extensionsTable->setItem(row, col++, new QTableWidgetItem(version));
extensionsTable->setItem(row, col++, new QTableWidgetItem(stringutils::convertFileSizeToHumanReadable(fileSize)));
updateButtons[row] = new QPushButton(tr("Install"));
buttonInstall = new QPushButton(tr("Install"));
buttonUninstall = new QPushButton(tr("Uninstall"));
temp = updateButtons[row];
connect(temp, SIGNAL(clicked()), this, SLOT(downloadExtension()));
extensionButtonMap[temp] = "extensions/" + filename;
extensionButtonHashMap[temp] = hashValue;
extensionsTable->setIndexWidget(extensionsTable->model()->index(row, col++), temp);
connect(buttonInstall, SIGNAL(clicked()), this, SLOT(downloadExtension()));
connect(buttonUninstall, SIGNAL(clicked()), this, SLOT(uninstallExtension()));
buttonInstall->setProperty("path", "extensions/" + filename);
buttonInstall->setProperty("hash", hashValue);
buttonInstall->setProperty("rowId", row);
buttonUninstall->setProperty("extensionId", key);
buttonUninstall->setProperty("rowId", row);
// get the installed version of the extension if any
if (Extension::isInstalled(key)) {
buttonUninstall->setDisabled(false);
QString installedVersion = Extension::getLatestVersion(key);
if (compareVersion(installedVersion, version)) {
temp->setText(tr("Update"));
buttonInstall->setText(tr("Update"));
}
else {
temp->setText(tr("Updated"));
temp->setDisabled(true);
buttonInstall->setText(tr("Updated"));
buttonInstall->setDisabled(true);
}
}
else {
buttonUninstall->setDisabled(true);
}
extensionsTable->setIndexWidget(extensionsTable->model()->index(row, col++), buttonInstall);
extensionsTable->setIndexWidget(extensionsTable->model()->index(row, col++), buttonUninstall);
row++;
}
}
@ -307,9 +315,9 @@ void ResourceManager::downloadLanguage()
void ResourceManager::downloadExtension()
{
QPushButton *button = static_cast<QPushButton*>( sender() );
QString data = extensionButtonMap[button];
QString hash = extensionButtonHashMap[button];
QPushButton* button = static_cast<QPushButton*>(sender());
QString data = button->property("path").toString();
QString hash = button->property("hash").toString();
button->setText(tr("Updating"));
button->setDisabled(true);
QString baseAddress = baseAddr() + data;
@ -341,6 +349,10 @@ void ResourceManager::downloadExtension()
if (result) {
QFile::remove(localPath);
button->setText(tr("Updated"));
// find uninstall button and make it visible
int rowId = button->property("rowId").toInt();
QPushButton* uninstallButton = static_cast<QPushButton*>(extensionsTable->indexWidget(extensionsTable->model()->index(rowId, 4)));
uninstallButton->setDisabled(false);
}
else {
button->setText(tr("Failed, try again"));
@ -349,6 +361,24 @@ void ResourceManager::downloadExtension()
}
}
//---------------------------------------------------------
// uninstallExtension
//---------------------------------------------------------
void ResourceManager::uninstallExtension()
{
QPushButton* uninstallButton = static_cast<QPushButton*>(sender());
QString extensionId = uninstallButton->property("extensionId").toString();
if (mscore->uninstallExtension(extensionId)) {
// find uninstall button and make it visible
int rowId = uninstallButton->property("rowId").toInt();
QPushButton* installButton = static_cast<QPushButton*>(extensionsTable->indexWidget(extensionsTable->model()->index(rowId, 3)));
installButton->setText("Install");
installButton->setDisabled(false);
uninstallButton->setDisabled(true);
}
}
//---------------------------------------------------------
// verifyFile
//---------------------------------------------------------

View file

@ -39,12 +39,11 @@ public:
private:
QMap <QPushButton *, QString> languageButtonMap; // QPushButton -> filename
QMap <QPushButton *, QString> languageButtonHashMap;// QPushButton -> hash of the file
QMap <QPushButton *, QString> extensionButtonMap; // QPushButton -> filename
QMap <QPushButton *, QString> extensionButtonHashMap;// QPushButton -> hash of the file
private slots:
void downloadLanguage();
void downloadExtension();
void uninstallExtension();
};
}

View file

@ -48,7 +48,7 @@
<number>2</number>
</property>
<property name="columnCount">
<number>4</number>
<number>5</number>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
@ -75,6 +75,11 @@
<string>Install/Update</string>
</property>
</column>
<column>
<property name="text">
<string>Uninstall</string>
</property>
</column>
</widget>
</item>
</layout>

View file

@ -459,6 +459,17 @@ void Workspace::save()
QList<Workspace*>& Workspace::workspaces()
{
if (!workspacesRead) {
// Remove all workspaces but Basic and Advanced
QMutableListIterator<Workspace*> i(_workspaces);
int index = 0;
while (i.hasNext()) {
Workspace* w = i.next();
if (index >= 2) {
delete w;
i.remove();
}
index++;
}
QStringList path;
path << mscoreGlobalShare + "workspaces";
path << dataPath + "/workspaces";