void GeoIPManager::downloadFinished(const DownloadResult &result) { if (result.status != DownloadStatus::Success) { LogMsg(tr("Couldn't download GeoIP database file. Reason: %1").arg(result.errorString), Log::WARNING); return; } bool ok = false; const QByteArray data = Utils::Gzip::decompress(result.data, &ok); if (!ok) { LogMsg(tr("Could not decompress GeoIP database file."), Log::WARNING); return; } QString error; GeoIPDatabase *geoIPDatabase = GeoIPDatabase::load(data, error); if (geoIPDatabase) { if (!m_geoIPDatabase || (geoIPDatabase->buildEpoch() > m_geoIPDatabase->buildEpoch())) { if (m_geoIPDatabase) delete m_geoIPDatabase; m_geoIPDatabase = geoIPDatabase; LogMsg(tr("GeoIP database loaded. Type: %1. Build time: %2.") .arg(m_geoIPDatabase->type(), m_geoIPDatabase->buildEpoch().toString()), Log::INFO); const QString targetPath = Utils::Fs::expandPathAbs( specialFolderLocation(SpecialFolder::Data) + GEOIP_FOLDER); if (!QDir(targetPath).exists()) QDir().mkpath(targetPath); QFile targetFile(QString("%1/%2").arg(targetPath, GEOIP_FILENAME)); if (!targetFile.open(QFile::WriteOnly) || (targetFile.write(data) == -1)) LogMsg(tr("Couldn't save downloaded GeoIP database file."), Log::WARNING); else LogMsg(tr("Successfully updated GeoIP database."), Log::INFO); } else { delete geoIPDatabase; } } else { LogMsg(tr("Couldn't load GeoIP database. Reason: %1").arg(error), Log::WARNING); } }
void GeoIPManager::downloadFinished(const QString &url, QByteArray data) { Q_UNUSED(url); if (!Utils::Gzip::uncompress(data, data)) { Logger::instance()->addMessage(tr("Could not uncompress GeoIP database file."), Log::WARNING); return; } QString error; GeoIPDatabase *geoIPDatabase = GeoIPDatabase::load(data, error); if (geoIPDatabase) { if (!m_geoIPDatabase || (geoIPDatabase->buildEpoch() > m_geoIPDatabase->buildEpoch())) { if (m_geoIPDatabase) delete m_geoIPDatabase; m_geoIPDatabase = geoIPDatabase; Logger::instance()->addMessage(tr("GeoIP database loaded. Type: %1. Build time: %2.") .arg(m_geoIPDatabase->type()).arg(m_geoIPDatabase->buildEpoch().toString()), Log::INFO); QString targetPath = Utils::Fs::expandPathAbs( Utils::Fs::QDesktopServicesDataLocation() + GEOIP_FOLDER); if (!QDir(targetPath).exists()) QDir().mkpath(targetPath); QFile targetFile(QString("%1/%2").arg(targetPath).arg(GEOIP_FILENAME)); if (!targetFile.open(QFile::WriteOnly) || (targetFile.write(data) == -1)) { Logger::instance()->addMessage( tr("Couldn't save downloaded GeoIP database file."), Log::WARNING); } else { Logger::instance()->addMessage(tr("Successfully updated GeoIP database."), Log::INFO); } } else { delete geoIPDatabase; } } else { Logger::instance()->addMessage(tr("Couldn't load GeoIP database. Reason: %1").arg(error), Log::WARNING); } }