diff --git a/src/ui/conf/addressgroup.cpp b/src/ui/conf/addressgroup.cpp index eb9ab479..d84b4419 100644 --- a/src/ui/conf/addressgroup.cpp +++ b/src/ui/conf/addressgroup.cpp @@ -60,27 +60,3 @@ void AddressGroup::copy(const AddressGroup &o) m_includeText = o.includeText(); m_excludeText = o.excludeText(); } - -QVariant AddressGroup::toVariant() const -{ - QVariantMap map; - - map["includeAll"] = includeAll(); - map["excludeAll"] = excludeAll(); - - map["includeText"] = includeText(); - map["excludeText"] = excludeText(); - - return map; -} - -void AddressGroup::fromVariant(const QVariant &v) -{ - const QVariantMap map = v.toMap(); - - m_includeAll = map["includeAll"].toBool(); - m_excludeAll = map["excludeAll"].toBool(); - - m_includeText = map["includeText"].toString(); - m_excludeText = map["excludeText"].toString(); -} diff --git a/src/ui/conf/addressgroup.h b/src/ui/conf/addressgroup.h index 37310a73..291dfd54 100644 --- a/src/ui/conf/addressgroup.h +++ b/src/ui/conf/addressgroup.h @@ -35,9 +35,6 @@ public: void copy(const AddressGroup &o); - QVariant toVariant() const; - void fromVariant(const QVariant &v); - signals: void includeAllChanged(); void excludeAllChanged(); diff --git a/src/ui/conf/appgroup.cpp b/src/ui/conf/appgroup.cpp index 270cad8b..08cdeff2 100644 --- a/src/ui/conf/appgroup.cpp +++ b/src/ui/conf/appgroup.cpp @@ -209,45 +209,3 @@ void AppGroup::copy(const AppGroup &o) m_blockText = o.blockText(); m_allowText = o.allowText(); } - -QVariant AppGroup::toVariant() const -{ - QVariantMap map; - - map["fragmentPacket"] = fragmentPacket(); - - map["periodEnabled"] = periodEnabled(); - map["periodFrom"] = periodFrom(); - map["periodTo"] = periodTo(); - - map["limitInEnabled"] = limitInEnabled(); - map["limitOutEnabled"] = limitOutEnabled(); - map["speedLimitIn"] = speedLimitIn(); - map["speedLimitOut"] = speedLimitOut(); - - map["name"] = name(); - map["blockText"] = blockText(); - map["allowText"] = allowText(); - - return map; -} - -void AppGroup::fromVariant(const QVariant &v) -{ - const QVariantMap map = v.toMap(); - - m_fragmentPacket = map["fragmentPacket"].toBool(); - - m_periodEnabled = map["periodEnabled"].toBool(); - m_periodFrom = DateUtil::reformatTime(map["periodFrom"].toString()); - m_periodTo = DateUtil::reformatTime(map["periodTo"].toString()); - - m_limitInEnabled = map["limitInEnabled"].toBool(); - m_limitOutEnabled = map["limitOutEnabled"].toBool(); - m_speedLimitIn = map["speedLimitIn"].toUInt(); - m_speedLimitOut = map["speedLimitOut"].toUInt(); - - m_name = map["name"].toString(); - m_blockText = map["blockText"].toString(); - m_allowText = map["allowText"].toString(); -} diff --git a/src/ui/conf/appgroup.h b/src/ui/conf/appgroup.h index 3523a74e..7e145647 100644 --- a/src/ui/conf/appgroup.h +++ b/src/ui/conf/appgroup.h @@ -77,9 +77,6 @@ public: void clear(); void copy(const AppGroup &o); - QVariant toVariant() const; - void fromVariant(const QVariant &v); - signals: void enabledChanged(); void fragmentPacketChanged(); diff --git a/src/ui/conf/confmanager.cpp b/src/ui/conf/confmanager.cpp index 10aa911d..24cb82bc 100644 --- a/src/ui/conf/confmanager.cpp +++ b/src/ui/conf/confmanager.cpp @@ -267,21 +267,6 @@ bool ConfManager::load(FirewallConf &conf) return false; } - // COMPAT: v3.0.0 - if (isNewConf) { - if (!m_fortSettings->readConf(conf, isNewConf)) { - setErrorMessage(m_fortSettings->errorMessage()); - return false; - } - - if (!isNewConf) { - for (AppGroup *appGroup : conf.appGroups()) { - appGroup->setBlockText(migrateAppsText(appGroup->blockText())); - appGroup->setAllowText(migrateAppsText(appGroup->allowText())); - } - } - } - if (isNewConf) { setupDefault(conf); } @@ -301,10 +286,6 @@ bool ConfManager::save(const FirewallConf &conf, bool onlyFlags) return false; } - // Remove old JSON config. - FileUtil::removeFile(m_fortSettings->confOldFilePath()); - FileUtil::removeFile(m_fortSettings->confBackupFilePath()); - return true; } @@ -778,42 +759,3 @@ bool ConfManager::saveTask(TaskInfo *taskInfo) } return true; } - -QString ConfManager::migrateAppsText(const QString &text) -{ - if (text.isEmpty()) - return QString(); - - QStringList list; - - const QLatin1String systemPath("System"); - - for (const auto &line : text.splitRef('\n')) { - QString fixedLine = line.toString(); - - const auto lineTrimmed = line.trimmed(); - if (!(lineTrimmed.isEmpty() - || lineTrimmed.startsWith('#'))) { - - QStringRef path = lineTrimmed; - bool addQuotes = false; - if (path.startsWith('"') && path.endsWith('"')) { - path = path.mid(1, path.size() - 2); - addQuotes = true; - } - - if (!path.isEmpty() - && QStringRef::compare(path, systemPath, Qt::CaseInsensitive) != 0 - && !path.endsWith(".exe")) { - fixedLine = path + "**"; - if (addQuotes) { - fixedLine = '"' + fixedLine + '"'; - } - } - } - - list.append(fixedLine); - } - - return list.join('\n'); -} diff --git a/src/ui/conf/confmanager.h b/src/ui/conf/confmanager.h index 9bce6ba6..0595d0cf 100644 --- a/src/ui/conf/confmanager.h +++ b/src/ui/conf/confmanager.h @@ -87,8 +87,6 @@ private: bool loadTask(TaskInfo *taskInfo); bool saveTask(TaskInfo *taskInfo); - static QString migrateAppsText(const QString &text); - private: QString m_errorMessage; diff --git a/src/ui/conf/firewallconf.cpp b/src/ui/conf/firewallconf.cpp index 2b2f7057..d65cd960 100644 --- a/src/ui/conf/firewallconf.cpp +++ b/src/ui/conf/firewallconf.cpp @@ -345,41 +345,3 @@ void FirewallConf::copy(const FirewallConf &o) addAppGroup(appGroup); } } - -QVariant FirewallConf::toVariant() const -{ - QVariantMap map; - - QVariantList addresses; - for (const AddressGroup *addressGroup : addressGroups()) { - addresses.append(addressGroup->toVariant()); - } - map["addressGroups"] = addresses; - - QVariantList groups; - for (const AppGroup *appGroup : appGroups()) { - groups.append(appGroup->toVariant()); - } - map["appGroups"] = groups; - - return map; -} - -void FirewallConf::fromVariant(const QVariant &v) -{ - const QVariantMap map = v.toMap(); - - const QVariantList addresses = map["addressGroups"].toList(); - int addrGroupIndex = 0; - for (const QVariant &av : addresses) { - AddressGroup *addressGroup = m_addressGroups.at(addrGroupIndex++); - addressGroup->fromVariant(av); - } - - const QVariantList groups = map["appGroups"].toList(); - for (const QVariant &gv : groups) { - auto appGroup = new AppGroup(); - appGroup->fromVariant(gv); - addAppGroup(appGroup); - } -} diff --git a/src/ui/conf/firewallconf.h b/src/ui/conf/firewallconf.h index c15f5652..bd3ac154 100644 --- a/src/ui/conf/firewallconf.h +++ b/src/ui/conf/firewallconf.h @@ -121,9 +121,6 @@ public: void copy(const FirewallConf &o); - QVariant toVariant() const; - void fromVariant(const QVariant &v); - signals: void provBootChanged(); void filterEnabledChanged(); diff --git a/src/ui/fortsettings.cpp b/src/ui/fortsettings.cpp index ede596c1..113e1a45 100644 --- a/src/ui/fortsettings.cpp +++ b/src/ui/fortsettings.cpp @@ -202,79 +202,6 @@ QString FortSettings::confFilePath() const return profilePath() + QLatin1String("FortFirewall.config"); } -QString FortSettings::confOldFilePath() const -{ - return profilePath() + QLatin1String("FortFirewall.conf"); -} - -QString FortSettings::confBackupFilePath() const -{ - return confOldFilePath() + QLatin1String(".backup"); -} - -bool FortSettings::readConf(FirewallConf &conf, bool &isNew) -{ - const QString filePath = confOldFilePath(); - const QString backupFilePath = confBackupFilePath(); - - const bool fileExists = FileUtil::fileExists(filePath); - const bool backupFileExists = FileUtil::fileExists(backupFilePath); - - isNew = !(fileExists || backupFileExists); - - return isNew || (fileExists && tryToReadConf(conf, filePath)) - || tryToReadConf(conf, backupFilePath); -} - -bool FortSettings::tryToReadConf(FirewallConf &conf, const QString &filePath) -{ - const QByteArray data = FileUtil::readFileData(filePath); - - QJsonParseError jsonParseError{}; - const QJsonDocument jsonDoc = QJsonDocument::fromJson( - data, &jsonParseError); - if (jsonParseError.error != QJsonParseError::NoError) { - setErrorMessage(jsonParseError.errorString()); - return false; - } - - QVariant confVar = jsonDoc.toVariant(); - - confVar = migrateConf(confVar); - - conf.fromVariant(confVar); - - return true; -} - -bool FortSettings::writeConf(const FirewallConf &conf) -{ - const QString filePath = confOldFilePath(); - const QString backupFilePath = confBackupFilePath(); - - if (!writeConfIni(conf)) { - setErrorMessage(tr("Can't write .ini file")); - return false; - } - - const QJsonDocument jsonDoc = QJsonDocument::fromVariant( - conf.toVariant()); - - const QByteArray data = jsonDoc.toJson(QJsonDocument::Indented); - - if (!FileUtil::writeFileData(backupFilePath, data)) { - setErrorMessage(tr("Can't create backup .conf file")); - return false; - } - - if (!FileUtil::writeFileData(filePath, data)) { - setErrorMessage(tr("Can't create .conf file")); - return false; - } - - return true; -} - void FortSettings::readConfIni(FirewallConf &conf) const { m_ini->beginGroup("confFlags"); @@ -345,55 +272,20 @@ bool FortSettings::writeConfIni(const FirewallConf &conf) return iniSync(); } -QVariant FortSettings::migrateConf(const QVariant &confVar) -{ - const int version = iniVersion(); - if (version == appVersion()) - return confVar; - - QVariantMap map = confVar.toMap(); - - // COMPAT: v1.7.0: AddressGroups - if (version < 0x010700) { - const QVariantMap oldIncMap = map["ipInclude"].toMap(); - const QVariantMap oldExcMap = map["ipExclude"].toMap(); - - QVariantMap inetMap; - - inetMap["includeAll"] = iniBool("confFlags/ipIncludeAll"); - inetMap["excludeAll"] = iniBool("confFlags/ipExcludeAll"); - - inetMap["includeText"] = oldIncMap["text"]; - inetMap["excludeText"] = oldExcMap["text"]; - - QVariantList addrList; - addrList.append(inetMap); - - map["addressGroups"] = addrList; - } - - // COMPAT: v3.0.0: PasswordHash - if (version < 0x030000) { - const QString oldPasswordHash = map["passwordHash"].toString(); - - setPasswordHash(oldPasswordHash); - } - - return map; -} - void FortSettings::migrateIniOnStartup() { const int version = iniVersion(); if (version == appVersion()) return; +#if 0 // COMPAT: v3.0.0: Options Window if (version < 0x030000) { setCacheValue("optWindow/geometry", m_ini->value("window/geometry")); setCacheValue("optWindow/maximized", m_ini->value("window/maximized")); // Abandon "window/addrSplit" & "window/appsSplit" } +#endif } void FortSettings::migrateIniOnWrite() @@ -404,23 +296,14 @@ void FortSettings::migrateIniOnWrite() setIniVersion(appVersion()); - // COMPAT: v1.7.0: AddressGroups - if (version < 0x010700) { - removeIniKey("confFlags/ipIncludeAll"); - removeIniKey("confFlags/ipExcludeAll"); - } - - // COMPAT: v1.10.0: Log Errors - if (version < 0x011000) { - removeIniKey("confFlags/logErrors"); - } - +#if 0 // COMPAT: v3.0.0: Options Window if (version < 0x030000) { removeIniKey("window"); m_ini->setValue("optWindow/geometry", cacheValue("optWindow/geometry")); m_ini->setValue("optWindow/maximized", cacheValue("optWindow/maximized")); } +#endif } bool FortSettings::confMigrated() const @@ -429,9 +312,11 @@ bool FortSettings::confMigrated() const if (version == appVersion()) return false; +#if 0 // COMPAT: v3.0.0 if (version < 0x030000 && appVersion() >= 0x030000) return true; +#endif return false; } diff --git a/src/ui/fortsettings.h b/src/ui/fortsettings.h index e4e2ef1d..3edfd1fc 100644 --- a/src/ui/fortsettings.h +++ b/src/ui/fortsettings.h @@ -186,9 +186,6 @@ public: QString confFilePath() const; - QString confOldFilePath() const; - QString confBackupFilePath() const; - QString controlCommand() const { return m_controlCommand; } QStringList args() const { return m_args; } @@ -203,9 +200,6 @@ signals: void errorMessageChanged(); public slots: - bool readConf(FirewallConf &conf, bool &isNew); - bool writeConf(const FirewallConf &conf); - void readConfIni(FirewallConf &conf) const; bool writeConfIni(const FirewallConf &conf); @@ -221,10 +215,6 @@ private: void setErrorMessage(const QString &errorMessage); - bool tryToReadConf(FirewallConf &conf, const QString &filePath); - - QVariant migrateConf(const QVariant &confVar); - void migrateIniOnStartup(); void migrateIniOnWrite();