diff --git a/src/Qv2rayBase.h b/src/Qv2rayBase.h index acd5f046..712eb145 100644 --- a/src/Qv2rayBase.h +++ b/src/Qv2rayBase.h @@ -5,7 +5,7 @@ #include "QvTinyLog.h" #include "QvCoreConfigObjects.h" -#define QV2RAY_VERSION_STRING "v" QV_MAJOR_VERSION ".5" +#define QV2RAY_VERSION_STRING "v" QV_MAJOR_VERSION ".5.2" #define QV2RAY_CONFIG_VERSION 2 #define QV2RAY_CONFIG_DIR_PATH (Qv2ray::Utils::GetConfigDirPath() + "/") diff --git a/src/QvConfigUpgrade.cpp b/src/QvConfigUpgrade.cpp index 85e5a2a0..31afe90d 100644 --- a/src/QvConfigUpgrade.cpp +++ b/src/QvConfigUpgrade.cpp @@ -8,28 +8,35 @@ #define UPGRADELOG(item, old, _new) LOG(MODULE_CONFIG, "Upgrading " item " from old value " + old + " to " + _new); #define XConfLog(oldVersion, newVersion) LOG(MODULE_CONFIG, "Migrating config from version " + oldVersion + " to " + newVersion); -namespace Qv2ray { - namespace QvConfigModels { +namespace Qv2ray +{ + namespace QvConfigModels + { // Secret member - QJsonObject UpgradeConfig_Inc(int fromVersion, QJsonObject root) { + QJsonObject UpgradeConfig_Inc(int fromVersion, QJsonObject root) + { XConfLog(to_string(fromVersion), to_string(fromVersion + 1)); + switch (fromVersion) { - case 1: - // From 1 to 2, we changed the config_version from 'string' to 'int' - auto old_config_version = root["config_version"].toString(); - root.remove("config_version"); - root["config_version"] = 2; - UPGRADELOG("config_version", old_config_version.toStdString(), "2") - break; + case 1: + // From 1 to 2, we changed the config_version from 'string' to 'int' + auto old_config_version = root["config_version"].toString(); + root.remove("config_version"); + root["config_version"] = 2; + UPGRADELOG("config_version", old_config_version.toStdString(), "2") + break; } + return root; } // Exported function - QJsonObject UpgradeConfig(int fromVersion, int toVersion, QJsonObject root) { + QJsonObject UpgradeConfig(int fromVersion, int toVersion, QJsonObject root) + { for (int i = fromVersion; i < toVersion; i++) { root = UpgradeConfig_Inc(i, root); } + return root; } diff --git a/src/QvCoreConfigOperations_Generation.cpp b/src/QvCoreConfigOperations_Generation.cpp index 676d526a..71603e4b 100644 --- a/src/QvCoreConfigOperations_Generation.cpp +++ b/src/QvCoreConfigOperations_Generation.cpp @@ -179,11 +179,8 @@ namespace Qv2ray // // root.insert("stats", QJsonObject()); - // - if (!root.contains("inbounds")) { - root.insert("inbounds", QJsonArray()); - } + QJsonArray inboundsList; // HTTP InBound if (gConf.inBoundSettings.http_port != 0) { @@ -198,7 +195,7 @@ namespace Qv2ray httpInBoundObject.insert("settings", httpInSettings); } - root["inbounds"].toArray().append(httpInBoundObject); + inboundsList.append(httpInBoundObject); } // SOCKS InBound @@ -208,9 +205,13 @@ namespace Qv2ray socksInBoundObject.insert("port", gConf.inBoundSettings.socks_port); socksInBoundObject.insert("protocol", "socks"); socksInBoundObject.insert("tag", "socks_IN"); - auto socksInSettings = GenerateSocksIN(gConf.inBoundSettings.socks_useAuth ? "password" : "noauth", QList() << gConf.inBoundSettings.socksAccount); + auto socksInSettings = GenerateSocksIN(gConf.inBoundSettings.socks_useAuth ? "password" : "noauth", QList() << gConf.inBoundSettings.socksAccount); socksInBoundObject.insert("settings", socksInSettings); - root["inbounds"].toArray().append(socksInBoundObject); + inboundsList.append(socksInBoundObject); + } + + if (!root.contains("inbounds") || root["inbounds"].toArray().count() == 0) { + root.insert("inbounds", inboundsList); } // TODO: MultiOutbound Settings