Skip to content

Commit

Permalink
update resource manager to download instruments_*.qm too
Browse files Browse the repository at this point in the history
  • Loading branch information
lasconic committed Aug 17, 2014
1 parent 9e7bed5 commit 7302fa0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
60 changes: 53 additions & 7 deletions mscore/resourceManager.cpp
Expand Up @@ -12,6 +12,7 @@

#include "resourceManager.h"
#include "ui_resourceManager.h"
#include "thirdparty/qzip/qzipreader_p.h"

namespace Ms {

Expand All @@ -25,7 +26,7 @@ ResourceManager::ResourceManager(QWidget *parent) :
setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
QDir dir;
dir.mkpath(dataPath + "/locale");
baseAddr = "http://extensions.musescore.org/";
baseAddr = "http://extensions.musescore.org/2.0/";
displayPlugins();
displayLanguages();
languagesTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
Expand Down Expand Up @@ -92,12 +93,20 @@ void ResourceManager::displayLanguages()

languagesTable->setIndexWidget(languagesTable->model()->index(row, col++), temp);

QString local = dataPath + "/locale/" + filename;
QFileInfo fileLocal(local);
if(!fileLocal.exists())
local = mscoreGlobalShare + "locale/" + filename;;
// get hash mscore and instruments
QJsonObject mscoreObject = value.value("mscore").toObject();
QString hashMscore = mscoreObject.value("hash").toString();
QString filenameMscore = mscoreObject.value("file_name").toString();

bool verifyMScore = verifyLanguageFile(filenameMscore, hashMscore);

QJsonObject instrumentsObject = value.value("instruments").toObject();
QString hashInstruments = instrumentsObject.value("hash").toString();
QString filenameInstruments = instrumentsObject.value("file_name").toString();

bool verifyInstruments = verifyLanguageFile(filenameMscore, hashMscore);

if(verifyFile(local, hashValue)) { // compare local file with distant hash
if (verifyMScore || verifyInstruments) { // compare local file with distant hash
temp->setText(tr("No update"));
temp->setDisabled(1);
}
Expand All @@ -108,6 +117,16 @@ void ResourceManager::displayLanguages()
}
}

bool ResourceManager::verifyLanguageFile(QString filename, QString hash)
{
QString local = dataPath + "/locale/" + filename;
QFileInfo fileLocal(local);
if(!fileLocal.exists())
local = mscoreGlobalShare + "locale/" + filename;;

return verifyFile(local, hash);
}

void ResourceManager::download()
{
QPushButton *button = dynamic_cast<QPushButton*>( sender() );
Expand All @@ -127,7 +146,34 @@ void ResourceManager::download()
button->setEnabled(1);
}
else {
button->setText(tr("Updated"));
// unzip and delete
MQZipReader zipFile(localPath);
QFileInfo zfi(localPath);
QString destinationDir(zfi.absolutePath());
QList<MQZipReader::FileInfo> allFiles = zipFile.fileInfoList();
bool result = true;
foreach (MQZipReader::FileInfo fi, allFiles) {
const QString absPath = destinationDir + QDir::separator() + fi.filePath;
if (fi.isFile) {
QFile f(absPath);
if (!f.open(QIODevice::WriteOnly)) {
result = false;
break;
}
f.write(zipFile.fileData(fi.filePath));
f.setPermissions(fi.permissions);
f.close();
}
}

if (result) {
QFile::remove(localPath);
button->setText(tr("Updated"));
}
else {
button->setText(tr("Failed, try again"));
button->setEnabled(1);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions mscore/resourceManager.h
Expand Up @@ -28,6 +28,7 @@ class ResourceManager : public QDialog, public Ui::Resource
void displayLanguages();
void displayPlugins();
bool verifyFile(QString path, QString hash);
bool verifyLanguageFile(QString filename, QString hash);

private:
QMap <QPushButton *, QString> buttonMap; // QPushButton -> filename
Expand Down

0 comments on commit 7302fa0

Please sign in to comment.