void wxFileConfig::Init() { m_pCurrentGroup = m_pRootGroup = new ConfigGroup(NULL, "", this); m_linesHead = m_linesTail = NULL; // it's not an error if (one of the) file(s) doesn't exist // parse the global file if ( !m_strGlobalFile.IsEmpty() && wxFile::Exists(m_strGlobalFile) ) { wxTextFile fileGlobal(m_strGlobalFile); if ( fileGlobal.Open() ) { Parse(fileGlobal, FALSE /* global */); SetRootPath(); } else wxLogWarning(_("can't open global configuration file '%s'."), m_strGlobalFile.c_str()); } // parse the local file if ( !m_strLocalFile.IsEmpty() && wxFile::Exists(m_strLocalFile) ) { wxTextFile fileLocal(m_strLocalFile); if ( fileLocal.Open() ) { Parse(fileLocal, TRUE /* local */); SetRootPath(); } else wxLogWarning(_("can't open user configuration file '%s'."), m_strLocalFile.c_str()); } }
bool ResourceManager::verifyLanguageFile(QString filename, QString hash) { QString local = dataPath + "/locale/" + filename; QString global = mscoreGlobalShare + "locale/" + filename; QFileInfo fileLocal(local); QFileInfo fileGlobal(global); if(!fileLocal.exists() || (fileLocal.lastModified() <= fileGlobal.lastModified()) ) local = mscoreGlobalShare + "locale/" + filename; return verifyFile(local, hash); }
void ResourceManager::displayLanguages() { tabs->setTabText(0,tr("Languages")); DownloadUtils *js = new DownloadUtils(this); js->setTarget(baseAddr + "languages/details.json"); js->download(); QByteArray json = js->returnData(); QJsonParseError err; QJsonDocument result = QJsonDocument::fromJson(json, &err); if (err.error != QJsonParseError::NoError || !result.isObject()) { qFatal("An error occured during parsing"); return; } int rowCount = result.object().keys().size(); rowCount -= 2; //version and type qDebug() << result.object().keys().size(); qDebug() << result.toJson(); languagesTable->setRowCount(rowCount); int row = 0; int col = 0; QPushButton* updateButtons[rowCount]; QPushButton* temp; languagesTable->verticalHeader()->show(); QCryptographicHash hash(QCryptographicHash::Sha1); for (QString key : result.object().keys()) { if (!result.object().value(key).isObject()) continue; QJsonObject value = result.object().value(key).toObject(); col = 0; QString test = value.value("file_name").toString(); if(test.length() == 0) continue; QString filename = value.value("file_name").toString(); QString name = value.value("name").toString(); QString fileSize = value.value("file_size").toString(); QString hashValue = value.value("hash").toString(); languagesTable->setItem(row,col++,new QTableWidgetItem (name)); languagesTable->setItem(row,col++,new QTableWidgetItem (filename)); languagesTable->setItem(row,col++,new QTableWidgetItem (tr("%1 KB").arg(fileSize))); updateButtons[row] = new QPushButton(tr("Update")); temp = updateButtons[row]; buttonMap[temp] = "languages/" + filename; buttonHashMap[temp] = hashValue; languagesTable->setIndexWidget(languagesTable->model()->index(row,col++), temp); QString local = dataPath + "/locale/" + filename; QFileInfo fileLocal(local); if(!fileLocal.exists()) local = mscoreGlobalShare + "locale/" + filename;; if(verifyFile(local, hashValue)) { temp->setText(tr("No update")); temp->setDisabled(1); } else { connect(temp, SIGNAL(clicked()), this, SLOT(download())); } row++; } }