mirror of
https://github.com/tnodir/fort
synced 2024-11-15 10:05:08 +00:00
UI: Remove compatibility code with v1.* & v2.* versions.
This commit is contained in:
parent
38dea5e5c4
commit
341435cceb
@ -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();
|
||||
}
|
||||
|
@ -35,9 +35,6 @@ public:
|
||||
|
||||
void copy(const AddressGroup &o);
|
||||
|
||||
QVariant toVariant() const;
|
||||
void fromVariant(const QVariant &v);
|
||||
|
||||
signals:
|
||||
void includeAllChanged();
|
||||
void excludeAllChanged();
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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');
|
||||
}
|
||||
|
@ -87,8 +87,6 @@ private:
|
||||
bool loadTask(TaskInfo *taskInfo);
|
||||
bool saveTask(TaskInfo *taskInfo);
|
||||
|
||||
static QString migrateAppsText(const QString &text);
|
||||
|
||||
private:
|
||||
QString m_errorMessage;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -121,9 +121,6 @@ public:
|
||||
|
||||
void copy(const FirewallConf &o);
|
||||
|
||||
QVariant toVariant() const;
|
||||
void fromVariant(const QVariant &v);
|
||||
|
||||
signals:
|
||||
void provBootChanged();
|
||||
void filterEnabledChanged();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user