Commit d538265d605aa3f2e9ceaa7422f89ca382c6c2b5
1 parent
af93bf85
Exists in
master
Correção da leitura do json do getConfig() para refletir sua nova versão.
Showing
1 changed file
with
39 additions
and
14 deletions
Show diff stats
cacic-daemon/cacicD/cacictimer.cpp
... | ... | @@ -120,10 +120,6 @@ void CacicTimer::lerArquivoConfig ( const QJsonObject& jsonConfig ) |
120 | 120 | /* lê json de configurações e armazena quais módulos executáveis. |
121 | 121 | * E faz o mesmo tipo de comparação de hashs, com o fim de: |
122 | 122 | * ou mantem o binário do módulo ou baixa um novo. |
123 | - * | |
124 | - * Aqui estou assumindo um formato do .json em que: | |
125 | - * há a key modulos contem uma lista com o nome dos executaveis e os seus valores hash md5 | |
126 | - * há a key metodo que explicita o método de download dos executaveis | |
127 | 123 | */ |
128 | 124 | foreach( QJsonValue individualModule, jsonConfig["modulos"].toArray() ) { |
129 | 125 | QString moduloKey, moduloValue; |
... | ... | @@ -134,12 +130,27 @@ void CacicTimer::lerArquivoConfig ( const QJsonObject& jsonConfig ) |
134 | 130 | moduleMap.insert(moduloKey, moduloValue); |
135 | 131 | } |
136 | 132 | |
137 | - foreach (QJsonValue individualMetodo, jsonConfig["metodoDownload"].toArray() ) { | |
133 | + if ( jsonConfig["metodoDownload"].isArray() ) { | |
134 | + | |
135 | + foreach (QJsonValue individualMetodo, jsonConfig["metodoDownload"].toArray() ) { | |
136 | + QMap<QString, QString> newEntry; | |
137 | + | |
138 | + newEntry.insert(QString("tipo"), individualMetodo.toObject()["tipo"].toString() ); | |
139 | + newEntry.insert(QString("url"), individualMetodo.toObject()["url"].toString() ); | |
140 | + newEntry.insert(QString("path"), individualMetodo.toObject()["path"].toString() ); | |
141 | + newEntry.insert(QString("usuario"), individualMetodo.toObject()["usario"].toString() ); | |
142 | + newEntry.insert(QString("senha"), individualMetodo.toObject()["senha"].toString() ); | |
143 | + | |
144 | + metodosDownload.append( newEntry ); | |
145 | + } | |
146 | + } else { | |
138 | 147 | QMap<QString, QString> newEntry; |
139 | 148 | |
140 | - newEntry.insert(QString("tipo"), individualMetodo.toObject()["tipo"].toString() ); | |
141 | - newEntry.insert(QString("url"), individualMetodo.toObject()["url"].toString() ); | |
142 | - newEntry.insert(QString("path"), individualMetodo.toObject()["path"].toString() ); | |
149 | + newEntry.insert(QString("tipo"), jsonConfig["metodoDownload"].toObject()["tipo"].toString() ); | |
150 | + newEntry.insert(QString("url"), jsonConfig["metodoDownload"].toObject()["url"].toString() ); | |
151 | + newEntry.insert(QString("path"), jsonConfig["metodoDownload"].toObject()["path"].toString() ); | |
152 | + newEntry.insert(QString("usuario"), jsonConfig["metodoDownload"].toObject()["usario"].toString() ); | |
153 | + newEntry.insert(QString("senha"), jsonConfig["metodoDownload"].toObject()["senha"].toString() ); | |
143 | 154 | |
144 | 155 | metodosDownload.append( newEntry ); |
145 | 156 | } |
... | ... | @@ -255,8 +266,10 @@ QStringList CacicTimer::verificarModulos(){ |
255 | 266 | // mantem o mais recente; caso iguais simplesmente apaga o novo. |
256 | 267 | QFile *fileOld; |
257 | 268 | QFile *fileNew; |
269 | + | |
258 | 270 | fileOld = new QFile(this->applicationDirPath + "/getConfig.json"); |
259 | 271 | fileNew = new QFile(this->applicationDirPath + "/getConfigNew.json"); |
272 | + | |
260 | 273 | if( fileOld->exists() && fileNew->exists() ){ |
261 | 274 | if( Md5IsEqual(QVariant::fromValue(fileOld), QVariant::fromValue(fileNew)) ) { |
262 | 275 | fileNew->remove(); |
... | ... | @@ -278,29 +291,41 @@ QStringList CacicTimer::verificarModulos(){ |
278 | 291 | QStringList nomesModulos; |
279 | 292 | |
280 | 293 | int countExecNotFound = 0; |
281 | - QMap<QString, QString>::const_iterator mapIterator = moduleMap.constBegin(); | |
282 | - while (mapIterator != moduleMap.constEnd()) { | |
283 | - QString nomeModulo = mapIterator.value(); | |
284 | - QString hashModulo = mapIterator.key(); | |
294 | + QMap<QString, QString>::const_iterator moduloIterator = moduleMap.constBegin(); | |
295 | + while (moduloIterator != moduleMap.constEnd()) { | |
296 | + QString nomeModulo = moduloIterator.value(); | |
297 | + QString hashModulo = moduloIterator.key(); | |
285 | 298 | // Calcula hash do binario atual |
286 | 299 | #if defined(Q_OS_WIN) |
287 | - fileOld = new QFile(this->applicationDirPath + "/" + modulo + ".exe"); | |
300 | + fileOld = new QFile(this->applicationDirPath + "/" + nomeModulo + ".exe"); | |
288 | 301 | #else |
289 | 302 | fileOld = new QFile(this->applicationDirPath + "/" + nomeModulo); |
290 | 303 | #endif |
291 | 304 | if(!fileOld->exists()) { |
292 | 305 | QLogger::QLog_Error("Cacic Daemon (Timer)", QString("Módulo ").append(nomeModulo).append(" não encontrado.")); |
293 | 306 | countExecNotFound++; |
307 | + | |
294 | 308 | if( countExecNotFound == moduleMap.size() ) { |
295 | 309 | QLogger::QLog_Error("Cacic Daemon (Timer)", "Não foi possível encontrar nenhum módulo executável!"); |
296 | 310 | return QStringList(); |
297 | 311 | } |
312 | + | |
313 | + // pula para o próximo módulo no moduloMap | |
314 | + moduloIterator++; | |
298 | 315 | continue; |
299 | 316 | } |
317 | + | |
300 | 318 | QString oldMd5 = QString(QCryptographicHash::hash(fileOld->readAll(),QCryptographicHash::Md5).toHex()); |
301 | 319 | if ( oldMd5 != hashModulo ) { |
320 | + | |
321 | +#if defined(Q_OS_WIN) | |
322 | + fileOld->rename(this->applicationDirPath + "/" + nomeModulo + ".exe", | |
323 | + this->applicationDirPath + "/" + nomeModulo + "Old.exe"); | |
324 | +#elif defined(Q_OS_LINUX) | |
302 | 325 | fileOld->rename(this->applicationDirPath + "/" + nomeModulo, |
303 | 326 | this->applicationDirPath + "/" + nomeModulo + "Old"); |
327 | +#endif | |
328 | + | |
304 | 329 | // Download nova versão do executável |
305 | 330 | QList<QMap<QString,QString> >::const_iterator metodosIterator = metodosDownload.constBegin(); |
306 | 331 | bool downloadSucess = false; |
... | ... | @@ -320,7 +345,7 @@ QStringList CacicTimer::verificarModulos(){ |
320 | 345 | |
321 | 346 | nomesModulos.append(nomeModulo); |
322 | 347 | |
323 | - mapIterator++; | |
348 | + moduloIterator++; | |
324 | 349 | } |
325 | 350 | |
326 | 351 | return nomesModulos; | ... | ... |