void ResourceManager::download() { QPushButton *button = dynamic_cast<QPushButton*>( sender() ); QString data = buttonMap[button]; QString hash = buttonHashMap[button]; button->setText(tr("Updating")); button->setDisabled(1); QString baseAddress = baseAddr + data; DownloadUtils *dl = new DownloadUtils(this); dl->setTarget(baseAddress); qDebug() << baseAddress; QString localPath = dataPath + "/locale/" + data.split('/')[1]; dl->setLocalFile(localPath); dl->download(); if( !dl->saveFile() || !verifyFile(localPath, hash)) { button->setText(tr("Failed, try again")); button->setEnabled(1); } else { // 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(); } } zipFile.close(); if (result) { QFile::remove(localPath); button->setText(tr("Updated")); // retranslate the UI if current language is updated if (data == buttonMap.first()) setMscoreLocale(localeName); } else { button->setText(tr("Failed, try again")); button->setEnabled(1); } } }
void ResourceManager::download() { QPushButton *button = dynamic_cast<QPushButton*>( sender() ); QString data = buttonMap[button]; QString hash = buttonHashMap[button]; button->setText(tr("Updating")); button->setDisabled(1); QString baseAddress = baseAddr + data; DownloadUtils *dl = new DownloadUtils(this); dl->setTarget(baseAddress); qDebug() << baseAddress; QString localPath = dataPath + "/locale/" + data.split('/')[1]; dl->setLocalFile(localPath); dl->download(); if( !dl->saveFile() || !verifyFile(localPath, hash)) { button->setText(tr("Failed, try again")); button->setEnabled(1); } else { button->setText(tr("Updated")); } }