[FIX] This commit fixed #35

This commit is contained in:
Leroy.H.Y 2019-09-03 21:34:12 +08:00
parent d4f54a70ec
commit 9dc329506e
No known key found for this signature in database
GPG Key ID: 6AC1673B587DC37D
3 changed files with 27 additions and 19 deletions

View File

@ -5,7 +5,7 @@
#include "QvTinyLog.h" #include "QvTinyLog.h"
#include "QvCoreConfigObjects.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_VERSION 2
#define QV2RAY_CONFIG_DIR_PATH (Qv2ray::Utils::GetConfigDirPath() + "/") #define QV2RAY_CONFIG_DIR_PATH (Qv2ray::Utils::GetConfigDirPath() + "/")

View File

@ -8,28 +8,35 @@
#define UPGRADELOG(item, old, _new) LOG(MODULE_CONFIG, "Upgrading " item " from old value " + old + " to " + _new); #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); #define XConfLog(oldVersion, newVersion) LOG(MODULE_CONFIG, "Migrating config from version " + oldVersion + " to " + newVersion);
namespace Qv2ray { namespace Qv2ray
namespace QvConfigModels { {
namespace QvConfigModels
{
// Secret member // Secret member
QJsonObject UpgradeConfig_Inc(int fromVersion, QJsonObject root) { QJsonObject UpgradeConfig_Inc(int fromVersion, QJsonObject root)
{
XConfLog(to_string(fromVersion), to_string(fromVersion + 1)); XConfLog(to_string(fromVersion), to_string(fromVersion + 1));
switch (fromVersion) { switch (fromVersion) {
case 1: case 1:
// From 1 to 2, we changed the config_version from 'string' to 'int' // From 1 to 2, we changed the config_version from 'string' to 'int'
auto old_config_version = root["config_version"].toString(); auto old_config_version = root["config_version"].toString();
root.remove("config_version"); root.remove("config_version");
root["config_version"] = 2; root["config_version"] = 2;
UPGRADELOG("config_version", old_config_version.toStdString(), "2") UPGRADELOG("config_version", old_config_version.toStdString(), "2")
break; break;
} }
return root; return root;
} }
// Exported function // 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++) { for (int i = fromVersion; i < toVersion; i++) {
root = UpgradeConfig_Inc(i, root); root = UpgradeConfig_Inc(i, root);
} }
return root; return root;
} }

View File

@ -179,11 +179,8 @@ namespace Qv2ray
// //
// //
root.insert("stats", QJsonObject()); root.insert("stats", QJsonObject());
// //
if (!root.contains("inbounds")) { QJsonArray inboundsList;
root.insert("inbounds", QJsonArray());
}
// HTTP InBound // HTTP InBound
if (gConf.inBoundSettings.http_port != 0) { if (gConf.inBoundSettings.http_port != 0) {
@ -198,7 +195,7 @@ namespace Qv2ray
httpInBoundObject.insert("settings", httpInSettings); httpInBoundObject.insert("settings", httpInSettings);
} }
root["inbounds"].toArray().append(httpInBoundObject); inboundsList.append(httpInBoundObject);
} }
// SOCKS InBound // SOCKS InBound
@ -208,9 +205,13 @@ namespace Qv2ray
socksInBoundObject.insert("port", gConf.inBoundSettings.socks_port); socksInBoundObject.insert("port", gConf.inBoundSettings.socks_port);
socksInBoundObject.insert("protocol", "socks"); socksInBoundObject.insert("protocol", "socks");
socksInBoundObject.insert("tag", "socks_IN"); socksInBoundObject.insert("tag", "socks_IN");
auto socksInSettings = GenerateSocksIN(gConf.inBoundSettings.socks_useAuth ? "password" : "noauth", QList<AccountObject>() << gConf.inBoundSettings.socksAccount); auto socksInSettings = GenerateSocksIN(gConf.inBoundSettings.socks_useAuth ? "password" : "noauth", QList<AccountObject>() << gConf.inBoundSettings.socksAccount);
socksInBoundObject.insert("settings", socksInSettings); 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 // TODO: MultiOutbound Settings