diff --git a/src/ui/conf/confmanager.cpp b/src/ui/conf/confmanager.cpp index ffe701e9..d6b6abf5 100644 --- a/src/ui/conf/confmanager.cpp +++ b/src/ui/conf/confmanager.cpp @@ -27,7 +27,7 @@ Q_LOGGING_CATEGORY(CLOG_CONF_MANAGER, "conf") #define logWarning() qCWarning(CLOG_CONF_MANAGER, ) #define logCritical() qCCritical(CLOG_CONF_MANAGER, ) -#define DATABASE_USER_VERSION 9 +#define DATABASE_USER_VERSION 10 namespace { @@ -130,8 +130,7 @@ const char *const sqlUpsertApp = " creat_time = ?6, end_time = ?7" " RETURNING app_id;"; -const char *const sqlInsertAppAlert = "INSERT INTO app_alert(app_id)" - " VALUES(?1);"; +const char *const sqlInsertAppAlert = "INSERT INTO app_alert(app_id) VALUES(?1);"; const char *const sqlDeleteApp = "DELETE FROM app WHERE app_id = ?1;"; @@ -142,9 +141,7 @@ const char *const sqlUpdateApp = "UPDATE app" " blocked = ?5, end_time = ?6" " WHERE app_id = ?1;"; -const char *const sqlUpdateAppName = "UPDATE app" - " SET name = ?2" - " WHERE app_id = ?1;"; +const char *const sqlUpdateAppName = "UPDATE app SET name = ?2 WHERE app_id = ?1;"; const char *const sqlUpdateAppResetGroup = "UPDATE app" " SET app_group_id = ?2" @@ -167,18 +164,15 @@ const char *const sqlUpdateZone = "UPDATE zone" " source_code = ?5, url = ?6, form_data = ?7" " WHERE zone_id = ?1;"; -const char *const sqlUpdateZoneName = "UPDATE zone" - " SET name = ?2" - " WHERE zone_id = ?1;"; +const char *const sqlUpdateZoneName = "UPDATE zone SET name = ?2 WHERE zone_id = ?1;"; -const char *const sqlUpdateZoneEnabled = "UPDATE zone" - " SET enabled = ?2" - " WHERE zone_id = ?1;"; +const char *const sqlUpdateZoneEnabled = "UPDATE zone SET enabled = ?2 WHERE zone_id = ?1;"; -const char *const sqlUpdateZoneResult = "UPDATE zone" - " SET text_checksum = ?2, bin_checksum = ?3," - " source_modtime = ?4, last_run = ?5, last_success = ?6" - " WHERE zone_id = ?1;"; +const char *const sqlUpdateZoneResult = + "UPDATE zone" + " SET address_count = ?2, text_checksum = ?3, bin_checksum = ?4," + " source_modtime = ?5, last_run = ?6, last_success = ?7" + " WHERE zone_id = ?1;"; bool migrateFunc(SqliteDb *db, int version, bool isNewDb, void *ctx) { @@ -954,14 +948,14 @@ bool ConfManager::updateZoneEnabled(int zoneId, bool enabled) return ok; } -bool ConfManager::updateZoneResult(int zoneId, const QString &textChecksum, +bool ConfManager::updateZoneResult(int zoneId, int addressCount, const QString &textChecksum, const QString &binChecksum, const QDateTime &sourceModTime, const QDateTime &lastRun, const QDateTime &lastSuccess) { bool ok = false; - const auto vars = QVariantList() - << zoneId << textChecksum << binChecksum << sourceModTime << lastRun << lastSuccess; + const auto vars = QVariantList() << zoneId << addressCount << textChecksum << binChecksum + << sourceModTime << lastRun << lastSuccess; sqliteDb()->executeEx(sqlUpdateZoneResult, vars, 0, &ok); diff --git a/src/ui/conf/confmanager.h b/src/ui/conf/confmanager.h index 75df8d68..ff26b617 100644 --- a/src/ui/conf/confmanager.h +++ b/src/ui/conf/confmanager.h @@ -86,8 +86,9 @@ public: const QString &url, const QString &formData, bool enabled, bool customUrl); virtual bool updateZoneName(int zoneId, const QString &zoneName); virtual bool updateZoneEnabled(int zoneId, bool enabled); - bool updateZoneResult(int zoneId, const QString &textChecksum, const QString &binChecksum, - const QDateTime &sourceModTime, const QDateTime &lastRun, const QDateTime &lastSuccess); + bool updateZoneResult(int zoneId, int addressCount, const QString &textChecksum, + const QString &binChecksum, const QDateTime &sourceModTime, const QDateTime &lastRun, + const QDateTime &lastSuccess); virtual bool checkPassword(const QString &password); diff --git a/src/ui/conf/migrations/1.sql b/src/ui/conf/migrations/1.sql index 56a42bcb..011bb9fb 100644 --- a/src/ui/conf/migrations/1.sql +++ b/src/ui/conf/migrations/1.sql @@ -6,6 +6,7 @@ CREATE TABLE zone( source_code TEXT NOT NULL, url TEXT, form_data TEXT, + address_count INTEGER, text_checksum TEXT, bin_checksum TEXT, source_modtime INTEGER, diff --git a/src/ui/conf/zone/sources.json b/src/ui/conf/zone/sources.json index 38b29f31..2a239ba2 100644 --- a/src/ui/conf/zone/sources.json +++ b/src/ui/conf/zone/sources.json @@ -10,7 +10,7 @@ "code": "winspyblock", "title": "WindowsSpyBlocker", "zoneType": "gen", - "url": "https://github.com/crazy-max/WindowsSpyBlocker/blob/master/data/firewall/spy.txt", + "url": "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/firewall/spy.txt", "formData": "" }, { diff --git a/src/ui/form/zone/zoneswindow.cpp b/src/ui/form/zone/zoneswindow.cpp index 4b2557ec..fb2dae70 100644 --- a/src/ui/form/zone/zoneswindow.cpp +++ b/src/ui/form/zone/zoneswindow.cpp @@ -29,7 +29,7 @@ namespace { -#define ZONES_HEADER_VERSION 1 +#define ZONES_HEADER_VERSION 2 } @@ -335,11 +335,13 @@ void ZonesWindow::setupTableZonesHeader() header->setSectionResizeMode(0, QHeaderView::Interactive); header->setSectionResizeMode(1, QHeaderView::Interactive); - header->setSectionResizeMode(2, QHeaderView::Stretch); + header->setSectionResizeMode(2, QHeaderView::Interactive); header->setSectionResizeMode(3, QHeaderView::Stretch); + header->setSectionResizeMode(4, QHeaderView::Stretch); - header->resizeSection(0, 350); - header->resizeSection(1, 290); + header->resizeSection(0, 300); + header->resizeSection(1, 300); + header->resizeSection(2, 90); } void ZonesWindow::setupTableZonesChanged() diff --git a/src/ui/model/zonelistmodel.cpp b/src/ui/model/zonelistmodel.cpp index cc9b8186..c8236710 100644 --- a/src/ui/model/zonelistmodel.cpp +++ b/src/ui/model/zonelistmodel.cpp @@ -34,7 +34,7 @@ void ZoneListModel::initialize() int ZoneListModel::columnCount(const QModelIndex &parent) const { - return parent.isValid() ? 0 : 4; + return parent.isValid() ? 0 : 5; } QVariant ZoneListModel::headerData(int section, Qt::Orientation orientation, int role) const @@ -46,8 +46,10 @@ QVariant ZoneListModel::headerData(int section, Qt::Orientation orientation, int case 1: return tr("Source"); case 2: - return tr("Last Run"); + return tr("Addresses"); case 3: + return tr("Last Run"); + case 4: return tr("Last Success"); } } @@ -88,8 +90,10 @@ QVariant ZoneListModel::dataDisplay(const QModelIndex &index) const return zoneSource.title(); } case 2: - return zoneRow.lastRun; + return zoneRow.addressCount; case 3: + return zoneRow.lastRun; + case 4: return zoneRow.lastSuccess; } @@ -163,12 +167,12 @@ bool ZoneListModel::updateZoneEnabled(int zoneId, bool enabled) return confManager()->updateZoneEnabled(zoneId, enabled); } -bool ZoneListModel::updateZoneResult(int zoneId, const QString &textChecksum, +bool ZoneListModel::updateZoneResult(int zoneId, int addressCount, const QString &textChecksum, const QString &binChecksum, const QDateTime &sourceModTime, const QDateTime &lastRun, const QDateTime &lastSuccess) { return confManager()->updateZoneResult( - zoneId, textChecksum, binChecksum, sourceModTime, lastRun, lastSuccess); + zoneId, addressCount, textChecksum, binChecksum, sourceModTime, lastRun, lastSuccess); } void ZoneListModel::deleteZone(int zoneId, int row) @@ -182,8 +186,7 @@ void ZoneListModel::deleteZone(int zoneId, int row) QString ZoneListModel::zoneNameById(int zoneId) { - static const char *const sql = "SELECT name FROM zone" - " WHERE zone_id = ?1;"; + static const char *const sql = "SELECT name FROM zone WHERE zone_id = ?1;"; SqliteStmt stmt; if (sqliteDb()->prepare(stmt, sql, { zoneId }) && stmt.step() == SqliteStmt::StepRow) { @@ -215,11 +218,12 @@ bool ZoneListModel::updateTableRow(int row) const m_zoneRow.sourceCode = stmt.columnText(4); m_zoneRow.url = stmt.columnText(5); m_zoneRow.formData = stmt.columnText(6); - m_zoneRow.textChecksum = stmt.columnText(7); - m_zoneRow.binChecksum = stmt.columnText(8); - m_zoneRow.sourceModTime = stmt.columnDateTime(9); - m_zoneRow.lastRun = stmt.columnDateTime(10); - m_zoneRow.lastSuccess = stmt.columnDateTime(11); + m_zoneRow.addressCount = stmt.columnInt(7); + m_zoneRow.textChecksum = stmt.columnText(8); + m_zoneRow.binChecksum = stmt.columnText(9); + m_zoneRow.sourceModTime = stmt.columnDateTime(10); + m_zoneRow.lastRun = stmt.columnDateTime(11); + m_zoneRow.lastSuccess = stmt.columnDateTime(12); return true; } @@ -234,6 +238,7 @@ QString ZoneListModel::sqlBase() const " source_code," " url," " form_data," + " address_count," " text_checksum," " bin_checksum," " source_modtime," diff --git a/src/ui/model/zonelistmodel.h b/src/ui/model/zonelistmodel.h index 14122692..33de3cc3 100644 --- a/src/ui/model/zonelistmodel.h +++ b/src/ui/model/zonelistmodel.h @@ -16,6 +16,8 @@ struct ZoneRow : TableRow int zoneId = 0; + int addressCount = 0; + QString zoneName; QString sourceCode; @@ -59,8 +61,9 @@ public: const QString &url, const QString &formData, bool enabled, bool customUrl); bool updateZoneName(int zoneId, const QString &zoneName); bool updateZoneEnabled(int zoneId, bool enabled); - bool updateZoneResult(int zoneId, const QString &textChecksum, const QString &binChecksum, - const QDateTime &sourceModTime, const QDateTime &lastRun, const QDateTime &lastSuccess); + bool updateZoneResult(int zoneId, int addressCount, const QString &textChecksum, + const QString &binChecksum, const QDateTime &sourceModTime, const QDateTime &lastRun, + const QDateTime &lastSuccess); void deleteZone(int zoneId, int row); QString zoneNameById(int zoneId); diff --git a/src/ui/task/taskinfozonedownloader.cpp b/src/ui/task/taskinfozonedownloader.cpp index 28050062..89b84dd6 100644 --- a/src/ui/task/taskinfozonedownloader.cpp +++ b/src/ui/task/taskinfozonedownloader.cpp @@ -139,6 +139,7 @@ void TaskInfoZoneDownloader::processSubResult(bool success) auto worker = zoneDownloader(); const auto zoneId = worker->zoneId(); + const auto addressCount = worker->addressCount(); const auto textChecksum = worker->textChecksum(); const auto binChecksum = worker->binChecksum(); @@ -147,7 +148,7 @@ void TaskInfoZoneDownloader::processSubResult(bool success) const auto lastSuccess = success ? now : worker->lastSuccess(); zoneListModel()->updateZoneResult( - zoneId, textChecksum, binChecksum, sourceModTime, now, lastSuccess); + zoneId, addressCount, textChecksum, binChecksum, sourceModTime, now, lastSuccess); addSubResult(worker, success); } diff --git a/src/ui/task/taskzonedownloader.cpp b/src/ui/task/taskzonedownloader.cpp index 663b8a95..23f5994d 100644 --- a/src/ui/task/taskzonedownloader.cpp +++ b/src/ui/task/taskzonedownloader.cpp @@ -41,8 +41,8 @@ void TaskZoneDownloader::downloadFinished(bool success) && (this->textChecksum() != textChecksum || !FileUtil::fileExists(cacheFileBinPath()))) { setTextChecksum(textChecksum); - success = storeAddresses(list); + setAddressCount(success ? list.size() : 0); } } diff --git a/src/ui/task/taskzonedownloader.h b/src/ui/task/taskzonedownloader.h index 846d0c7e..c1ea90cb 100644 --- a/src/ui/task/taskzonedownloader.h +++ b/src/ui/task/taskzonedownloader.h @@ -25,6 +25,9 @@ public: int zoneId() const { return m_zoneId; } void setZoneId(int v) { m_zoneId = v; } + int addressCount() const { return m_addressCount; } + void setAddressCount(int v) { m_addressCount = v; } + QString zoneName() const { return m_zoneName; } void setZoneName(const QString &v) { m_zoneName = v; } @@ -81,6 +84,8 @@ private: int m_zoneId = 0; + int m_addressCount = 0; + QString m_zoneName; QString m_url; diff --git a/src/ui/util/net/netdownloader.cpp b/src/ui/util/net/netdownloader.cpp index 5feb0d3f..7a3d966f 100644 --- a/src/ui/util/net/netdownloader.cpp +++ b/src/ui/util/net/netdownloader.cpp @@ -39,7 +39,9 @@ void NetDownloader::start() m_process.start("curl", args, QIODevice::ReadOnly); - if (!m_process.waitForStarted()) { + if (!m_process.waitForStarted(1000)) { + qWarning() << "NetDownloader: Cannot start `curl`:" << m_process.errorString(); + abort(); } } @@ -73,12 +75,17 @@ void NetDownloader::processError(QProcess::ProcessError error) if (m_aborted) return; - qWarning() << "NetDownloader: Cannot run `curl`:" << error; + qWarning() << "NetDownloader: Cannot run `curl`:" << error << m_process.errorString(); abort(); } void NetDownloader::processFinished(int exitCode, QProcess::ExitStatus exitStatus) { - abort(exitCode == 0 && exitStatus == QProcess::NormalExit && !m_buffer.isEmpty()); + const bool success = (exitCode == 0 && exitStatus == QProcess::NormalExit); + if (!success) { + qWarning() << "NetDownloader: `curl` error code:" << exitCode; + } + + abort(success && !m_buffer.isEmpty()); }