From 71c57901245ee4287c30a0561c47ef7ce42acb80 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Sun, 20 Oct 2019 15:32:38 +0500 Subject: [PATCH] UI: StatManager: Remove m_filePath. --- src/ui/3rdparty/sqlite/sqlitedb.cpp | 12 ++++++++---- src/ui/3rdparty/sqlite/sqlitedb.h | 10 ++++++---- src/ui/stat/statmanager.cpp | 12 ++++++------ src/ui/stat/statmanager.h | 4 ---- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/ui/3rdparty/sqlite/sqlitedb.cpp b/src/ui/3rdparty/sqlite/sqlitedb.cpp index d6e827c7..99c8b9b0 100644 --- a/src/ui/3rdparty/sqlite/sqlitedb.cpp +++ b/src/ui/3rdparty/sqlite/sqlitedb.cpp @@ -9,8 +9,9 @@ #include -SqliteDb::SqliteDb() : - m_db(nullptr) +SqliteDb::SqliteDb(const QString &filePath) : + m_db(nullptr), + m_filePath(filePath) { sqlite3_initialize(); } @@ -24,8 +25,11 @@ SqliteDb::~SqliteDb() bool SqliteDb::open(const QString &filePath) { - m_filePath = filePath; - return sqlite3_open16(filePath.utf16(), &m_db) == SQLITE_OK; + if (!filePath.isEmpty()) { + m_filePath = filePath; + } + + return sqlite3_open16(m_filePath.utf16(), &m_db) == SQLITE_OK; } void SqliteDb::close() diff --git a/src/ui/3rdparty/sqlite/sqlitedb.h b/src/ui/3rdparty/sqlite/sqlitedb.h index 50e6e129..87a5c7c9 100644 --- a/src/ui/3rdparty/sqlite/sqlitedb.h +++ b/src/ui/3rdparty/sqlite/sqlitedb.h @@ -14,17 +14,19 @@ using SQLITEDB_MIGRATE_FUNC = bool (*)(SqliteDb *db, int version, void *context) class SqliteDb { public: - explicit SqliteDb(); + explicit SqliteDb(const QString &filePath = QString()); ~SqliteDb(); CLASS_DEFAULT_COPY_MOVE(SqliteDb) - bool open(const QString &filePath); + struct sqlite3 *db() const { return m_db; } + + QString filePath() const { return m_filePath; } + + bool open(const QString &filePath = QString()); void close(); bool recreateDb(); - struct sqlite3 *db() const { return m_db; } - bool execute(const char *sql); bool execute16(const ushort *sql); bool executeStr(const QString &sql); diff --git a/src/ui/stat/statmanager.cpp b/src/ui/stat/statmanager.cpp index 49739de8..21b1dcc3 100644 --- a/src/ui/stat/statmanager.cpp +++ b/src/ui/stat/statmanager.cpp @@ -67,10 +67,9 @@ StatManager::StatManager(const QString &filePath, m_lastTrafDay(0), m_lastTrafMonth(0), m_lastTick(0), - m_filePath(filePath), m_quotaManager(quotaManager), m_conf(nullptr), - m_sqliteDb(new SqliteDb()) + m_sqliteDb(new SqliteDb(filePath)) { } @@ -97,9 +96,9 @@ bool StatManager::initialize() { m_lastTrafHour = m_lastTrafDay = m_lastTrafMonth = 0; - if (!m_sqliteDb->open(m_filePath)) { + if (!m_sqliteDb->open()) { qCritical(CLOG_STAT_MANAGER()) << "File open error:" - << m_filePath + << m_sqliteDb->filePath() << m_sqliteDb->errorMessage(); return false; } @@ -108,7 +107,8 @@ bool StatManager::initialize() if (!m_sqliteDb->migrate(":/stat/migrations", DATABASE_USER_VERSION, false, &migrateFunc)) { - qCritical(CLOG_STAT_MANAGER()) << "Migration error" << m_filePath; + qCritical(CLOG_STAT_MANAGER()) << "Migration error" + << m_sqliteDb->filePath(); return false; } @@ -155,7 +155,7 @@ void StatManager::clear() m_sqliteDb->close(); - FileUtil::removeFile(m_filePath); + FileUtil::removeFile(m_sqliteDb->filePath()); initialize(); diff --git a/src/ui/stat/statmanager.h b/src/ui/stat/statmanager.h index 2977b985..c154f260 100644 --- a/src/ui/stat/statmanager.h +++ b/src/ui/stat/statmanager.h @@ -27,8 +27,6 @@ public: const FirewallConf *firewallConf() const { return m_conf; } void setFirewallConf(const FirewallConf *conf); - SqliteDb *sqliteDb() const { return m_sqliteDb; } - bool initialize(); void logProcNew(quint32 pid, const QString &appPath); @@ -105,8 +103,6 @@ private: qint32 m_lastTick; - QString m_filePath; - QuotaManager *m_quotaManager; const FirewallConf *m_conf;