mirror of
https://github.com/Qv2ray/Qv2ray.git
synced 2025-05-20 19:00:22 +08:00
Have sleep
This commit is contained in:
parent
6f358d7cb9
commit
38c86fddab
@ -118,7 +118,7 @@ namespace Qv2ray
|
||||
// Qv2ray runtime config
|
||||
inline bool isExiting = false;
|
||||
inline QString Qv2rayConfigPath = "";
|
||||
inline base::config::Qv2rayConfig GlobalConfig = base::config::Qv2rayConfig();
|
||||
inline base::config::Qv2rayConfigObject GlobalConfig = base::config::Qv2rayConfigObject();
|
||||
//
|
||||
inline void ExitQv2ray()
|
||||
{
|
||||
|
@ -5,41 +5,95 @@
|
||||
#include <QtCore>
|
||||
namespace Qv2ray::base
|
||||
{
|
||||
template<typename T>
|
||||
class IDType final
|
||||
{
|
||||
public:
|
||||
explicit IDType() : m_id("null"){};
|
||||
explicit IDType(const QString &id) : m_id(id){};
|
||||
friend bool operator==(const IDType<T> &lhs, const IDType<T> &rhs)
|
||||
{
|
||||
return lhs.m_id == rhs.m_id;
|
||||
}
|
||||
friend bool operator!=(const IDType<T> &lhs, const IDType<T> &rhs)
|
||||
{
|
||||
return lhs.toString() != rhs.toString();
|
||||
}
|
||||
const QString &toString() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
uint qHash(uint seed) const
|
||||
{
|
||||
return ::qHash(m_id, seed);
|
||||
}
|
||||
|
||||
void loadJson(const QJsonValue &d)
|
||||
{
|
||||
m_id = d.toString("null");
|
||||
}
|
||||
|
||||
QJsonValue toJson() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
private:
|
||||
QString m_id;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
uint qHash(const IDType<T> &key, uint seed = 0)
|
||||
{
|
||||
return key.qHash(seed);
|
||||
}
|
||||
// Define several safetypes to prevent misuse of QString.
|
||||
class __QvGroup;
|
||||
class __QvConnection;
|
||||
typedef IDType<__QvGroup> GroupId;
|
||||
typedef IDType<__QvConnection> ConnectionId;
|
||||
//
|
||||
constexpr unsigned int QVTCPING_VALUE_ERROR = 99999;
|
||||
constexpr unsigned int QVTCPING_VALUE_NODATA = QVTCPING_VALUE_ERROR - 1;
|
||||
using namespace std::chrono;
|
||||
// Common struct for Groups and Subscriptions
|
||||
struct GroupObject_Config
|
||||
|
||||
struct __Qv2rayConfigObjectBase
|
||||
{
|
||||
QString displayName;
|
||||
QList<QString> connections;
|
||||
qint64 importDate;
|
||||
GroupObject_Config() : displayName(), connections(), importDate(){};
|
||||
JSONSTRUCT_REGISTER(GroupObject_Config, F(displayName, connections, importDate))
|
||||
qint64 creationDate;
|
||||
qint64 lastUpdatedDate;
|
||||
__Qv2rayConfigObjectBase()
|
||||
: displayName(), creationDate(system_clock::to_time_t(system_clock::now())), //
|
||||
lastUpdatedDate(system_clock::to_time_t(system_clock::now())) //
|
||||
{};
|
||||
JSONSTRUCT_REGISTER(__Qv2rayConfigObjectBase, F(displayName, creationDate, lastUpdatedDate))
|
||||
};
|
||||
|
||||
struct SubscriptionObject_Config : GroupObject_Config
|
||||
struct SubscriptionConfigObject
|
||||
{
|
||||
//
|
||||
QString address;
|
||||
qint64 lastUpdated;
|
||||
float updateInterval;
|
||||
SubscriptionObject_Config() : address(""), lastUpdated(system_clock::to_time_t(system_clock::now())), updateInterval(10){};
|
||||
JSONSTRUCT_REGISTER(SubscriptionObject_Config, F(lastUpdated, updateInterval, address), B(GroupObject_Config))
|
||||
SubscriptionConfigObject() : address(""), updateInterval(10){};
|
||||
JSONSTRUCT_REGISTER(SubscriptionConfigObject, F(updateInterval, address))
|
||||
};
|
||||
|
||||
struct ConnectionObject_Config
|
||||
struct Qv2rayGroupConfigObject : __Qv2rayConfigObjectBase
|
||||
{
|
||||
QList<ConnectionId> connections;
|
||||
bool isSubscription;
|
||||
SubscriptionConfigObject subscriptionSettings;
|
||||
Qv2rayGroupConfigObject() : __Qv2rayConfigObjectBase(), connections(), isSubscription(false), subscriptionSettings(){};
|
||||
JSONSTRUCT_REGISTER(Qv2rayGroupConfigObject, F(connections, isSubscription, subscriptionSettings), B(__Qv2rayConfigObjectBase))
|
||||
};
|
||||
|
||||
struct Qv2rayConnectionObject : __Qv2rayConfigObjectBase
|
||||
{
|
||||
QString displayName;
|
||||
qint64 importDate;
|
||||
qint64 lastConnected;
|
||||
qint64 latency;
|
||||
qint64 upLinkData;
|
||||
qint64 downLinkData;
|
||||
ConnectionObject_Config()
|
||||
: displayName(), importDate(system_clock::to_time_t(system_clock::now())), lastConnected(), latency(QVTCPING_VALUE_NODATA),
|
||||
upLinkData(0), downLinkData(0){};
|
||||
JSONSTRUCT_REGISTER(ConnectionObject_Config, F(displayName, importDate, lastConnected, latency, upLinkData, downLinkData))
|
||||
Qv2rayConnectionObject() : lastConnected(), latency(QVTCPING_VALUE_NODATA), upLinkData(0), downLinkData(0){};
|
||||
JSONSTRUCT_REGISTER(Qv2rayConnectionObject, F(lastConnected, latency, upLinkData, downLinkData), B(__Qv2rayConfigObjectBase))
|
||||
};
|
||||
} // namespace Qv2ray::base
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
#include <chrono>
|
||||
|
||||
const int QV2RAY_CONFIG_VERSION = 11;
|
||||
const int QV2RAY_CONFIG_VERSION = 12;
|
||||
|
||||
namespace Qv2ray::base::config
|
||||
{
|
||||
@ -19,9 +19,7 @@ namespace Qv2ray::base::config
|
||||
QString Message;
|
||||
QvBarLine()
|
||||
: Family("Consolas"), Bold(true), Italic(false), ColorA(255), ColorR(255), ColorG(255), ColorB(255), ContentType(0), Size(9),
|
||||
Message("")
|
||||
{
|
||||
}
|
||||
Message(""){};
|
||||
JSONSTRUCT_REGISTER(QvBarLine, F(Bold, Italic, ColorA, ColorR, ColorG, ColorB, Size, Family, Message, ContentType))
|
||||
};
|
||||
|
||||
@ -29,19 +27,17 @@ namespace Qv2ray::base::config
|
||||
{
|
||||
int OffsetYpx;
|
||||
QList<QvBarLine> Lines;
|
||||
QvBarPage() : OffsetYpx(5)
|
||||
{
|
||||
}
|
||||
QvBarPage() : OffsetYpx(5){};
|
||||
JSONSTRUCT_REGISTER(QvBarPage, F(OffsetYpx, Lines))
|
||||
};
|
||||
|
||||
struct Qv2rayToolBarConfig
|
||||
struct Qv2rayConfig_ToolBar
|
||||
{
|
||||
QList<QvBarPage> Pages;
|
||||
JSONSTRUCT_REGISTER(Qv2rayToolBarConfig, F(Pages))
|
||||
JSONSTRUCT_REGISTER(Qv2rayConfig_ToolBar, F(Pages))
|
||||
};
|
||||
|
||||
struct Qv2rayForwardProxyConfig
|
||||
struct Qv2rayConfig_ForwardProxy
|
||||
{
|
||||
bool enableForwardProxy;
|
||||
QString type;
|
||||
@ -50,14 +46,12 @@ namespace Qv2ray::base::config
|
||||
bool useAuth;
|
||||
QString username;
|
||||
QString password;
|
||||
Qv2rayForwardProxyConfig()
|
||||
: enableForwardProxy(false), type("http"), serverAddress("127.0.0.1"), port(8008), useAuth(false), username(), password()
|
||||
{
|
||||
}
|
||||
JSONSTRUCT_REGISTER(Qv2rayForwardProxyConfig, F(enableForwardProxy, type, serverAddress, port, useAuth, username, password))
|
||||
Qv2rayConfig_ForwardProxy()
|
||||
: enableForwardProxy(false), type("http"), serverAddress("127.0.0.1"), port(8008), useAuth(false), username(), password(){};
|
||||
JSONSTRUCT_REGISTER(Qv2rayConfig_ForwardProxy, F(enableForwardProxy, type, serverAddress, port, useAuth, username, password))
|
||||
};
|
||||
|
||||
struct Qv2rayInboundsConfig
|
||||
struct Qv2rayConfig_Inbounds
|
||||
{
|
||||
QString listenip;
|
||||
bool setSystemProxy;
|
||||
@ -88,30 +82,26 @@ namespace Qv2ray::base::config
|
||||
QString tproxy_mode;
|
||||
bool dnsIntercept;
|
||||
|
||||
Qv2rayInboundsConfig()
|
||||
Qv2rayConfig_Inbounds()
|
||||
: listenip("127.0.0.1"), setSystemProxy(true), useSocks(true), socks_port(1089), socks_useAuth(false), socksUDP(true),
|
||||
socksLocalIP("127.0.0.1"), socksAccount(), socksSniffing(false), useHTTP(true), http_port(8889), http_useAuth(false),
|
||||
httpAccount(), httpSniffing(false), useTPROXY(false), tproxy_ip("127.0.0.1"), tproxy_port(12345), tproxy_use_tcp(true),
|
||||
tproxy_use_udp(false), tproxy_followRedirect(true), tproxy_mode("tproxy"), dnsIntercept(true)
|
||||
{
|
||||
}
|
||||
tproxy_use_udp(false), tproxy_followRedirect(true), tproxy_mode("tproxy"), dnsIntercept(true){};
|
||||
|
||||
JSONSTRUCT_REGISTER(Qv2rayInboundsConfig,
|
||||
JSONSTRUCT_REGISTER(Qv2rayConfig_Inbounds,
|
||||
F(setSystemProxy, listenip, useSocks, useHTTP, socks_port, socks_useAuth, socksAccount, socksSniffing, socksUDP,
|
||||
socksLocalIP, http_port, http_useAuth, httpAccount, httpSniffing, useTPROXY),
|
||||
F(tproxy_ip, tproxy_port, tproxy_use_tcp, tproxy_use_udp, tproxy_followRedirect, tproxy_mode, dnsIntercept))
|
||||
};
|
||||
|
||||
struct Qv2rayOutboundsConfig
|
||||
struct Qv2rayConfig_Outbounds
|
||||
{
|
||||
int mark;
|
||||
Qv2rayOutboundsConfig() : mark(255)
|
||||
{
|
||||
}
|
||||
JSONSTRUCT_REGISTER(Qv2rayOutboundsConfig, F(mark))
|
||||
Qv2rayConfig_Outbounds() : mark(255){};
|
||||
JSONSTRUCT_REGISTER(Qv2rayConfig_Outbounds, F(mark))
|
||||
};
|
||||
|
||||
struct Qv2rayUIConfig
|
||||
struct Qv2rayConfig_UI
|
||||
{
|
||||
QString theme;
|
||||
QString language;
|
||||
@ -121,96 +111,88 @@ namespace Qv2ray::base::config
|
||||
bool useDarkTrayIcon;
|
||||
int maximumLogLines;
|
||||
int maxJumpListCount;
|
||||
Qv2rayUIConfig()
|
||||
: theme("Fusion"), language("en_US"), useDarkTheme(false), useDarkTrayIcon(true), maximumLogLines(500), maxJumpListCount(20)
|
||||
{
|
||||
}
|
||||
JSONSTRUCT_REGISTER(Qv2rayUIConfig,
|
||||
Qv2rayConfig_UI()
|
||||
: theme("Fusion"), language("en_US"), useDarkTheme(false), useDarkTrayIcon(true), maximumLogLines(500), maxJumpListCount(20){};
|
||||
JSONSTRUCT_REGISTER(Qv2rayConfig_UI,
|
||||
F(theme, language, quietMode, useDarkTheme, useDarkTrayIcon, maximumLogLines, maxJumpListCount, recentConnections))
|
||||
};
|
||||
|
||||
struct Qv2rayRouteConfig_Impl
|
||||
struct Qv2rayConfig_Routing
|
||||
{
|
||||
QList<QString> direct;
|
||||
QList<QString> block;
|
||||
QList<QString> proxy;
|
||||
Qv2rayRouteConfig_Impl(){};
|
||||
friend bool operator==(const Qv2rayRouteConfig_Impl &left, const Qv2rayRouteConfig_Impl &right)
|
||||
struct Qv2rayRouteConfig_Impl
|
||||
{
|
||||
return left.direct == right.direct && left.block == right.block && left.proxy == left.proxy;
|
||||
}
|
||||
Qv2rayRouteConfig_Impl(const QList<QString> &_direct, const QList<QString> &_block, const QList<QString> &_proxy)
|
||||
: direct(_direct), block(_block), proxy(_proxy){};
|
||||
JSONSTRUCT_REGISTER(Qv2rayRouteConfig_Impl, F(proxy, block, direct))
|
||||
};
|
||||
|
||||
struct Qv2rayRouteConfig
|
||||
{
|
||||
QList<QString> direct;
|
||||
QList<QString> block;
|
||||
QList<QString> proxy;
|
||||
Qv2rayRouteConfig_Impl(){};
|
||||
friend bool operator==(const Qv2rayRouteConfig_Impl &left, const Qv2rayRouteConfig_Impl &right)
|
||||
{
|
||||
return left.direct == right.direct && left.block == right.block && left.proxy == left.proxy;
|
||||
}
|
||||
Qv2rayRouteConfig_Impl(const QList<QString> &_direct, const QList<QString> &_block, const QList<QString> &_proxy)
|
||||
: direct(_direct), block(_block), proxy(_proxy){};
|
||||
JSONSTRUCT_REGISTER(Qv2rayRouteConfig_Impl, F(proxy, block, direct))
|
||||
};
|
||||
QString domainStrategy;
|
||||
Qv2rayRouteConfig_Impl domains;
|
||||
Qv2rayRouteConfig_Impl ips;
|
||||
friend bool operator==(const Qv2rayRouteConfig &left, const Qv2rayRouteConfig &right)
|
||||
friend bool operator==(const Qv2rayConfig_Routing &left, const Qv2rayConfig_Routing &right)
|
||||
{
|
||||
return left.domainStrategy == right.domainStrategy && left.domains == right.domains && left.ips == right.ips;
|
||||
}
|
||||
Qv2rayRouteConfig(){};
|
||||
Qv2rayRouteConfig(const Qv2rayRouteConfig_Impl &_domains, const Qv2rayRouteConfig_Impl &_ips, const QString &ds)
|
||||
Qv2rayConfig_Routing(){};
|
||||
Qv2rayConfig_Routing(const Qv2rayRouteConfig_Impl &_domains, const Qv2rayRouteConfig_Impl &_ips, const QString &ds)
|
||||
: domainStrategy(ds), domains(_domains), ips(_ips){};
|
||||
JSONSTRUCT_REGISTER(Qv2rayRouteConfig, F(domainStrategy, domains, ips))
|
||||
JSONSTRUCT_REGISTER(Qv2rayConfig_Routing, F(domainStrategy, domains, ips))
|
||||
};
|
||||
|
||||
struct Qv2rayPluginConfig
|
||||
struct Qv2rayConfig_Plugin
|
||||
{
|
||||
QMap<QString, bool> pluginStates;
|
||||
bool v2rayIntegration;
|
||||
int portAllocationStart;
|
||||
Qv2rayPluginConfig() : pluginStates(), v2rayIntegration(true), portAllocationStart(15000){};
|
||||
JSONSTRUCT_REGISTER(Qv2rayPluginConfig, F(pluginStates, v2rayIntegration, portAllocationStart))
|
||||
Qv2rayConfig_Plugin() : pluginStates(), v2rayIntegration(true), portAllocationStart(15000){};
|
||||
JSONSTRUCT_REGISTER(Qv2rayConfig_Plugin, F(pluginStates, v2rayIntegration, portAllocationStart))
|
||||
};
|
||||
|
||||
struct Qv2rayConnectionConfig
|
||||
struct Qv2rayConfig_Connection
|
||||
{
|
||||
bool bypassCN;
|
||||
bool bypassBT;
|
||||
bool enableProxy;
|
||||
bool v2rayFreedomDNS;
|
||||
bool withLocalDNS;
|
||||
Qv2rayRouteConfig routeConfig;
|
||||
Qv2rayConfig_Routing routeConfig;
|
||||
QList<QString> dnsList;
|
||||
Qv2rayForwardProxyConfig forwardProxyConfig;
|
||||
Qv2rayConnectionConfig()
|
||||
Qv2rayConfig_ForwardProxy forwardProxyConfig;
|
||||
Qv2rayConfig_Connection()
|
||||
: bypassCN(true), bypassBT(false), enableProxy(true), v2rayFreedomDNS(false), withLocalDNS(false), routeConfig(),
|
||||
dnsList(QStringList{ "8.8.4.4", "1.1.1.1" })
|
||||
{
|
||||
}
|
||||
JSONSTRUCT_REGISTER(Qv2rayConnectionConfig,
|
||||
dnsList(QStringList{ "8.8.4.4", "1.1.1.1" }){};
|
||||
JSONSTRUCT_REGISTER(Qv2rayConfig_Connection,
|
||||
F(bypassCN, bypassBT, enableProxy, v2rayFreedomDNS, withLocalDNS, dnsList, forwardProxyConfig, routeConfig))
|
||||
};
|
||||
|
||||
struct Qv2rayAPIConfig
|
||||
struct Qv2rayConfig_API
|
||||
{
|
||||
bool enableAPI;
|
||||
int statsPort;
|
||||
Qv2rayAPIConfig() : enableAPI(true), statsPort(15490)
|
||||
{
|
||||
}
|
||||
JSONSTRUCT_REGISTER(Qv2rayAPIConfig, F(enableAPI, statsPort))
|
||||
Qv2rayConfig_API() : enableAPI(true), statsPort(15490){};
|
||||
JSONSTRUCT_REGISTER(Qv2rayConfig_API, F(enableAPI, statsPort))
|
||||
};
|
||||
|
||||
struct Qv2rayKernelConfig
|
||||
struct Qv2rayConfig_Kernel
|
||||
{
|
||||
QString v2CorePath_linux;
|
||||
QString v2AssetsPath_linux;
|
||||
QString v2CorePath_macx;
|
||||
QString v2AssetsPath_macx;
|
||||
QString v2CorePath_win;
|
||||
QString v2AssetsPath_win; //
|
||||
Qv2rayKernelConfig()
|
||||
QString v2AssetsPath_win;
|
||||
Qv2rayConfig_Kernel()
|
||||
: v2CorePath_linux(), v2AssetsPath_linux(), //
|
||||
v2CorePath_macx(), v2AssetsPath_macx(), //
|
||||
v2CorePath_win(), v2AssetsPath_win() //
|
||||
{
|
||||
}
|
||||
{};
|
||||
//
|
||||
#ifdef Q_OS_LINUX
|
||||
#define _VARNAME_VCOREPATH_ v2CorePath_linux
|
||||
@ -235,11 +217,11 @@ namespace Qv2ray::base::config
|
||||
#undef _VARNAME_VCOREPATH_
|
||||
#undef _VARNAME_VASSETSPATH_
|
||||
|
||||
JSONSTRUCT_REGISTER(Qv2rayKernelConfig,
|
||||
JSONSTRUCT_REGISTER(Qv2rayConfig_Kernel,
|
||||
F(v2CorePath_linux, v2AssetsPath_linux, v2CorePath_macx, v2AssetsPath_macx, v2CorePath_win, v2AssetsPath_win))
|
||||
};
|
||||
|
||||
struct Qv2rayUpdateConfig
|
||||
struct Qv2rayConfig_Update
|
||||
{
|
||||
QString ignoredVersion;
|
||||
///
|
||||
@ -247,18 +229,18 @@ namespace Qv2ray::base::config
|
||||
/// 0: Stable
|
||||
/// 1: Testing
|
||||
int updateChannel;
|
||||
JSONSTRUCT_REGISTER(Qv2rayUpdateConfig, F(ignoredVersion, updateChannel))
|
||||
JSONSTRUCT_REGISTER(Qv2rayConfig_Update, F(ignoredVersion, updateChannel))
|
||||
};
|
||||
|
||||
struct Qv2rayAdvancedConfig
|
||||
struct Qv2rayConfig_Advanced
|
||||
{
|
||||
bool setAllowInsecure;
|
||||
bool setAllowInsecureCiphers;
|
||||
bool testLatencyPeriodcally;
|
||||
JSONSTRUCT_REGISTER(Qv2rayAdvancedConfig, F(setAllowInsecure, setAllowInsecureCiphers, testLatencyPeriodcally))
|
||||
JSONSTRUCT_REGISTER(Qv2rayConfig_Advanced, F(setAllowInsecure, setAllowInsecureCiphers, testLatencyPeriodcally))
|
||||
};
|
||||
|
||||
struct Qv2rayNetworkConfig
|
||||
struct Qv2rayConfig_Network
|
||||
{
|
||||
enum Qv2rayProxyType : int
|
||||
{
|
||||
@ -271,16 +253,16 @@ namespace Qv2ray::base::config
|
||||
QString type;
|
||||
int port;
|
||||
QString userAgent;
|
||||
Qv2rayNetworkConfig()
|
||||
Qv2rayConfig_Network()
|
||||
: proxyType(QVPROXY_NONE), //
|
||||
address("127.0.0.1"), //
|
||||
type("http"), //
|
||||
port(8000), //
|
||||
userAgent("Qv2ray/$VERSION WebRequestHelper"){};
|
||||
JSONSTRUCT_REGISTER(Qv2rayNetworkConfig, F(proxyType, type, address, port, userAgent))
|
||||
JSONSTRUCT_REGISTER(Qv2rayConfig_Network, F(proxyType, type, address, port, userAgent))
|
||||
};
|
||||
|
||||
struct Qv2rayConfig
|
||||
struct Qv2rayConfigObject
|
||||
{
|
||||
int config_version;
|
||||
bool tProxySupport;
|
||||
@ -289,31 +271,27 @@ namespace Qv2ray::base::config
|
||||
QString autoStartId;
|
||||
//
|
||||
// Key = groupId, connectionId
|
||||
QMap<QString, GroupObject_Config> groups;
|
||||
QMap<QString, SubscriptionObject_Config> subscriptions;
|
||||
/// Connections are used privately.
|
||||
QMap<QString, ConnectionObject_Config> connections;
|
||||
QList<GroupId> groups;
|
||||
QList<ConnectionId> connections;
|
||||
//
|
||||
Qv2rayUIConfig uiConfig;
|
||||
Qv2rayAPIConfig apiConfig;
|
||||
Qv2rayPluginConfig pluginConfig;
|
||||
Qv2rayKernelConfig kernelConfig;
|
||||
Qv2rayUpdateConfig updateConfig;
|
||||
Qv2rayNetworkConfig networkConfig;
|
||||
Qv2rayToolBarConfig toolBarConfig;
|
||||
Qv2rayInboundsConfig inboundConfig;
|
||||
Qv2rayOutboundsConfig outboundConfig;
|
||||
Qv2rayAdvancedConfig advancedConfig;
|
||||
Qv2rayConnectionConfig connectionConfig;
|
||||
Qv2rayConfig_UI uiConfig;
|
||||
Qv2rayConfig_API apiConfig;
|
||||
Qv2rayConfig_Plugin pluginConfig;
|
||||
Qv2rayConfig_Kernel kernelConfig;
|
||||
Qv2rayConfig_Update updateConfig;
|
||||
Qv2rayConfig_Network networkConfig;
|
||||
Qv2rayConfig_ToolBar toolBarConfig;
|
||||
Qv2rayConfig_Inbounds inboundConfig;
|
||||
Qv2rayConfig_Outbounds outboundConfig;
|
||||
Qv2rayConfig_Advanced advancedConfig;
|
||||
Qv2rayConfig_Connection connectionConfig;
|
||||
|
||||
Qv2rayConfig()
|
||||
Qv2rayConfigObject()
|
||||
: config_version(QV2RAY_CONFIG_VERSION), //
|
||||
tProxySupport(false), //
|
||||
logLevel(), //
|
||||
autoStartId("null"), //
|
||||
groups(), //
|
||||
subscriptions(), //
|
||||
connections(), //
|
||||
uiConfig(), //
|
||||
apiConfig(), //
|
||||
pluginConfig(), //
|
||||
@ -324,29 +302,25 @@ namespace Qv2ray::base::config
|
||||
inboundConfig(), //
|
||||
outboundConfig(), //
|
||||
advancedConfig(), //
|
||||
connectionConfig()
|
||||
{
|
||||
}
|
||||
connectionConfig(){};
|
||||
|
||||
JSONSTRUCT_REGISTER(Qv2rayConfig,
|
||||
F(config_version, //
|
||||
tProxySupport, //
|
||||
logLevel, //
|
||||
uiConfig, //
|
||||
pluginConfig, //
|
||||
updateConfig, //
|
||||
kernelConfig, //
|
||||
networkConfig, //
|
||||
groups, //
|
||||
connections, //
|
||||
subscriptions, //
|
||||
autoStartId, //
|
||||
inboundConfig, //
|
||||
outboundConfig, //
|
||||
connectionConfig),
|
||||
F(toolBarConfig, //
|
||||
advancedConfig, //
|
||||
apiConfig //
|
||||
JSONSTRUCT_REGISTER(Qv2rayConfigObject,
|
||||
F(config_version, //
|
||||
tProxySupport, //
|
||||
logLevel, //
|
||||
uiConfig, //
|
||||
pluginConfig, //
|
||||
updateConfig, //
|
||||
kernelConfig, //
|
||||
networkConfig, //
|
||||
groups, //
|
||||
autoStartId, //
|
||||
inboundConfig, //
|
||||
outboundConfig, //
|
||||
connectionConfig, //
|
||||
toolBarConfig, //
|
||||
advancedConfig, //
|
||||
apiConfig //
|
||||
))
|
||||
};
|
||||
} // namespace Qv2ray::base::config
|
||||
|
@ -26,18 +26,18 @@ namespace Qv2ray::common
|
||||
{
|
||||
switch (GlobalConfig.networkConfig.proxyType)
|
||||
{
|
||||
case Qv2rayNetworkConfig::QVPROXY_NONE:
|
||||
case Qv2rayConfig_Network::QVPROXY_NONE:
|
||||
{
|
||||
DEBUG(MODULE_NETWORK, "Get without proxy.")
|
||||
accessManager.setProxy(QNetworkProxy(QNetworkProxy::ProxyType::NoProxy));
|
||||
break;
|
||||
}
|
||||
case Qv2rayNetworkConfig::QVPROXY_SYSTEM:
|
||||
case Qv2rayConfig_Network::QVPROXY_SYSTEM:
|
||||
{
|
||||
accessManager.setProxy(QNetworkProxyFactory::systemProxyForQuery().first());
|
||||
break;
|
||||
}
|
||||
case Qv2rayNetworkConfig::QVPROXY_CUSTOM:
|
||||
case Qv2rayConfig_Network::QVPROXY_CUSTOM:
|
||||
{
|
||||
QNetworkProxy p{
|
||||
GlobalConfig.networkConfig.type == "http" ? QNetworkProxy::HttpProxy : QNetworkProxy::Socks5Proxy, //
|
||||
|
@ -2,12 +2,12 @@
|
||||
#include "base/models/QvSettingsObject.hpp"
|
||||
namespace Qv2ray::components::route
|
||||
{
|
||||
const inline Qv2ray::base::config::Qv2rayRouteConfig emptyScheme;
|
||||
const inline Qv2ray::base::config::Qv2rayConfig_Routing emptyScheme;
|
||||
/**
|
||||
* @brief The Qv2rayRouteScheme struct
|
||||
* @author DuckSoft <realducksoft@gmail.com>
|
||||
*/
|
||||
struct Qv2rayRouteScheme : config::Qv2rayRouteConfig
|
||||
struct Qv2rayRouteScheme : config::Qv2rayConfig_Routing
|
||||
{
|
||||
/**
|
||||
* @brief the name of the scheme.
|
||||
|
@ -153,6 +153,6 @@ namespace Qv2ray::components::route::presets::v2rayN
|
||||
};
|
||||
const inline QList<QString> IPsBlock{};
|
||||
const inline QList<QString> IPsDirect{};
|
||||
const inline Qv2ray::base::config::Qv2rayRouteConfig v2rayNScheme({ DomainsDirect, DomainsBlock, DomainsProxy },
|
||||
const inline Qv2ray::base::config::Qv2rayConfig_Routing v2rayNScheme({ DomainsDirect, DomainsBlock, DomainsProxy },
|
||||
{ IPsDirect, IPsBlock, IPsProxy }, "AsIs");
|
||||
} // namespace Qv2ray::components::route::presets::v2rayN
|
||||
|
@ -8,43 +8,6 @@
|
||||
|
||||
namespace Qv2ray::core
|
||||
{
|
||||
static const inline auto QV2RAY_SERIALIZATION_COMPLEX_CONFIG_PLACEHOLDER = QObject::tr("(Complex config)");
|
||||
template<typename T>
|
||||
class IDType final
|
||||
{
|
||||
public:
|
||||
explicit IDType() : m_id("null")
|
||||
{
|
||||
}
|
||||
explicit IDType(const QString &id) : m_id(id)
|
||||
{
|
||||
}
|
||||
friend bool operator==(const IDType<T> &lhs, const IDType<T> &rhs)
|
||||
{
|
||||
return lhs.m_id == rhs.m_id;
|
||||
}
|
||||
friend bool operator!=(const IDType<T> &lhs, const IDType<T> &rhs)
|
||||
{
|
||||
return lhs.toString() != rhs.toString();
|
||||
}
|
||||
const QString &toString() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
uint qHash(uint seed) const
|
||||
{
|
||||
return ::qHash(m_id, seed);
|
||||
}
|
||||
|
||||
private:
|
||||
QString m_id;
|
||||
};
|
||||
|
||||
// Define several safetypes to prevent misuse of QString.
|
||||
class __QvGroup;
|
||||
class __QvConnection;
|
||||
typedef IDType<__QvGroup> GroupId;
|
||||
typedef IDType<__QvConnection> ConnectionId;
|
||||
|
||||
inline const static auto NullConnectionId = ConnectionId("null");
|
||||
inline const static auto NullGroupId = GroupId("null");
|
||||
@ -53,12 +16,7 @@ namespace Qv2ray::core
|
||||
QList<IDType> StringsToIdList(const QList<QString> &strings)
|
||||
{
|
||||
QList<IDType> list;
|
||||
|
||||
for (auto str : strings)
|
||||
{
|
||||
list << IDType(str);
|
||||
}
|
||||
|
||||
for (const auto &str : strings) list << IDType(str);
|
||||
return list;
|
||||
}
|
||||
|
||||
@ -66,65 +24,9 @@ namespace Qv2ray::core
|
||||
QList<QString> IdListToStrings(const QList<IDType> &ids)
|
||||
{
|
||||
QList<QString> list;
|
||||
|
||||
for (auto id : ids)
|
||||
{
|
||||
list << id.toString();
|
||||
}
|
||||
|
||||
for (const auto &id : ids) list << id.toString();
|
||||
return list;
|
||||
}
|
||||
template<typename T>
|
||||
uint qHash(const IDType<T> &key, uint seed = 0)
|
||||
{
|
||||
return key.qHash(seed);
|
||||
}
|
||||
//
|
||||
/// Metadata object representing a connection.
|
||||
struct ConnectionMetaObject final : ConnectionObject_Config
|
||||
{
|
||||
GroupId groupId = NullGroupId;
|
||||
ConnectionMetaObject() : ConnectionObject_Config()
|
||||
{
|
||||
}
|
||||
// Suger for down casting.
|
||||
ConnectionMetaObject(const ConnectionObject_Config &base) : ConnectionMetaObject()
|
||||
{
|
||||
this->latency = base.latency;
|
||||
this->lastConnected = base.lastConnected;
|
||||
this->importDate = base.lastConnected;
|
||||
this->upLinkData = base.upLinkData;
|
||||
this->downLinkData = base.downLinkData;
|
||||
this->displayName = base.displayName;
|
||||
}
|
||||
};
|
||||
|
||||
/// Metadata object representing a group.
|
||||
struct GroupMetaObject final : SubscriptionObject_Config
|
||||
{
|
||||
// Implicit base of two types, since group object is actually the group base object.
|
||||
bool isSubscription = false;
|
||||
QList<ConnectionId> connections;
|
||||
// Suger for down casting.
|
||||
GroupMetaObject() : connections()
|
||||
{
|
||||
}
|
||||
GroupMetaObject(const GroupObject_Config &base) : GroupMetaObject()
|
||||
{
|
||||
this->isSubscription = false;
|
||||
this->displayName = base.displayName;
|
||||
this->importDate = base.importDate;
|
||||
this->connections = StringsToIdList<ConnectionId>(base.connections);
|
||||
}
|
||||
// Suger for down casting.
|
||||
GroupMetaObject(const SubscriptionObject_Config &base) : GroupMetaObject((GroupObject_Config) base)
|
||||
{
|
||||
this->address = base.address;
|
||||
this->lastUpdated = base.lastUpdated;
|
||||
this->updateInterval = base.updateInterval;
|
||||
this->isSubscription = true;
|
||||
}
|
||||
};
|
||||
} // namespace Qv2ray::core
|
||||
|
||||
using namespace Qv2ray::core;
|
||||
|
@ -15,7 +15,7 @@ namespace Qv2ray::core::connection
|
||||
QMultiHash<QString, CONFIGROOT> connectionConf;
|
||||
if (link.startsWith("vmess://"))
|
||||
{
|
||||
auto conf = ConvertConfigFromVMessString(link, prefix, errMessage);
|
||||
auto conf = vmess::Deserialize(link, prefix, errMessage);
|
||||
//
|
||||
if (GlobalConfig.advancedConfig.setAllowInsecureCiphers || GlobalConfig.advancedConfig.setAllowInsecure)
|
||||
{
|
||||
@ -36,13 +36,13 @@ namespace Qv2ray::core::connection
|
||||
}
|
||||
else if (link.startsWith("ss://"))
|
||||
{
|
||||
auto conf = ConvertConfigFromSSString(link, prefix, errMessage);
|
||||
auto conf = ss::Deserialize(link, prefix, errMessage);
|
||||
connectionConf.insert(*prefix, conf);
|
||||
}
|
||||
else if (link.startsWith("ssd://"))
|
||||
{
|
||||
QStringList errMessageList;
|
||||
connectionConf = ConvertConfigFromSSDString(link, newGroupName, &errMessageList);
|
||||
connectionConf = ssd::Deserialize(link, newGroupName, &errMessageList);
|
||||
*errMessage = errMessageList.join(NEWLINE);
|
||||
}
|
||||
else
|
||||
@ -91,12 +91,12 @@ namespace Qv2ray::core::connection
|
||||
{
|
||||
auto vmessServer = VMessServerObject::fromJson(settings["vnext"].toArray().first().toObject());
|
||||
auto transport = StreamSettingsObject::fromJson(outbound["streamSettings"].toObject());
|
||||
sharelink = vmess::ConvertConfigToVMessString(transport, vmessServer, alias);
|
||||
sharelink = vmess::Serialize(transport, vmessServer, alias);
|
||||
}
|
||||
else if (type == "shadowsocks")
|
||||
{
|
||||
auto ssServer = ShadowSocksServerObject::fromJson(settings["servers"].toArray().first().toObject());
|
||||
sharelink = ss::ConvertConfigToSSString(ssServer, alias, isSip002);
|
||||
sharelink = ss::Serialize(ssServer, alias, isSip002);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -6,13 +6,14 @@ namespace Qv2ray::core::connection
|
||||
{
|
||||
namespace Serialization
|
||||
{
|
||||
const inline auto QV2RAY_SERIALIZATION_COMPLEX_CONFIG_PLACEHOLDER = QObject::tr("(Complex config)");
|
||||
/**
|
||||
* pattern for the nodes in ssd links.
|
||||
* %1: airport name
|
||||
* %2: node name
|
||||
* %3: rate
|
||||
*/
|
||||
inline auto QV2RAY_SSD_DEFAULT_NAME_PATTERN = QObject::tr("%1 - %2 (rate %3)");
|
||||
const inline auto QV2RAY_SSD_DEFAULT_NAME_PATTERN = QObject::tr("%1 - %2 (rate %3)");
|
||||
//
|
||||
// General
|
||||
QString DecodeSubscriptionString(const QByteArray &arr);
|
||||
@ -24,16 +25,15 @@ namespace Qv2ray::core::connection
|
||||
// VMess URI Protocol
|
||||
namespace vmess
|
||||
{
|
||||
CONFIGROOT ConvertConfigFromVMessString(const QString &vmess, QString *alias, QString *errMessage);
|
||||
const QString ConvertConfigToVMessString(const StreamSettingsObject &transfer, const VMessServerObject &server,
|
||||
const QString &alias);
|
||||
CONFIGROOT Deserialize(const QString &vmess, QString *alias, QString *errMessage);
|
||||
const QString Serialize(const StreamSettingsObject &transfer, const VMessServerObject &server, const QString &alias);
|
||||
} // namespace vmess
|
||||
//
|
||||
// SS URI Protocol
|
||||
namespace ss
|
||||
{
|
||||
CONFIGROOT ConvertConfigFromSSString(const QString &ss, QString *alias, QString *errMessage);
|
||||
const QString ConvertConfigToSSString(const ShadowSocksServerObject &server, const QString &alias, bool isSip002);
|
||||
CONFIGROOT Deserialize(const QString &ss, QString *alias, QString *errMessage);
|
||||
const QString Serialize(const ShadowSocksServerObject &server, const QString &alias, bool isSip002);
|
||||
} // namespace ss
|
||||
//
|
||||
// SSD URI Protocol
|
||||
@ -50,7 +50,7 @@ namespace Qv2ray::core::connection
|
||||
* - log list
|
||||
* in case of error, no objects will be returned.
|
||||
*/
|
||||
QMultiHash<QString, CONFIGROOT> ConvertConfigFromSSDString(const QString &uri, QString *groupName, QStringList *logList);
|
||||
QMultiHash<QString, CONFIGROOT> Deserialize(const QString &uri, QString *groupName, QStringList *logList);
|
||||
} // namespace ssd
|
||||
//
|
||||
} // namespace Serialization
|
||||
@ -59,6 +59,3 @@ namespace Qv2ray::core::connection
|
||||
using namespace Qv2ray::core;
|
||||
using namespace Qv2ray::core::connection;
|
||||
using namespace Qv2ray::core::connection::Serialization;
|
||||
using namespace Qv2ray::core::connection::Serialization::ss;
|
||||
using namespace Qv2ray::core::connection::Serialization::ssd;
|
||||
using namespace Qv2ray::core::connection::Serialization::vmess;
|
||||
|
@ -7,7 +7,7 @@ namespace Qv2ray::core::connection
|
||||
{
|
||||
namespace Serialization::ss
|
||||
{
|
||||
CONFIGROOT ConvertConfigFromSSString(const QString &ssUri, QString *alias, QString *errMessage)
|
||||
CONFIGROOT Deserialize(const QString &ssUri, QString *alias, QString *errMessage)
|
||||
{
|
||||
ShadowSocksServerObject server;
|
||||
QString d_name;
|
||||
@ -107,7 +107,7 @@ namespace Qv2ray::core::connection
|
||||
return root;
|
||||
}
|
||||
|
||||
const QString ConvertConfigToSSString(const ShadowSocksServerObject &server, const QString &alias, bool isSip002)
|
||||
const QString Serialize(const ShadowSocksServerObject &server, const QString &alias, bool isSip002)
|
||||
{
|
||||
auto myAlias = QUrl::toPercentEncoding(alias);
|
||||
|
||||
|
@ -73,7 +73,7 @@ namespace Qv2ray::core::connection::Serialization
|
||||
// A pair of an error string list, together with some optionally existed pair, which contains a QString for airport name and a List of
|
||||
// pairs that contains a QString for connection name and finally, our ShadowSocksServerObject
|
||||
//
|
||||
QMultiHash<QString, CONFIGROOT> ConvertConfigFromSSDString(const QString &uri, QString *groupName, QStringList *logList)
|
||||
QMultiHash<QString, CONFIGROOT> Deserialize(const QString &uri, QString *groupName, QStringList *logList)
|
||||
{
|
||||
// ssd links should begin with "ssd://"
|
||||
if (!uri.startsWith("ssd://"))
|
||||
|
@ -10,7 +10,7 @@ namespace Qv2ray::core::connection
|
||||
{
|
||||
|
||||
// From https://github.com/2dust/v2rayN/wiki/分享链接格式说明(ver-2)
|
||||
const QString ConvertConfigToVMessString(const StreamSettingsObject &transfer, const VMessServerObject &server, const QString &alias)
|
||||
const QString Serialize(const StreamSettingsObject &transfer, const VMessServerObject &server, const QString &alias)
|
||||
{
|
||||
QJsonObject vmessUriRoot;
|
||||
// Constant
|
||||
@ -58,7 +58,7 @@ namespace Qv2ray::core::connection
|
||||
return "vmess://" + vmessPart;
|
||||
}
|
||||
// This generates global config containing only one outbound....
|
||||
CONFIGROOT ConvertConfigFromVMessString(const QString &vmessStr, QString *alias, QString *errMessage)
|
||||
CONFIGROOT Deserialize(const QString &vmessStr, QString *alias, QString *errMessage)
|
||||
{
|
||||
#define default CONFIGROOT()
|
||||
LOG(MODULE_SETTINGS, "Trying to convert from a vmess string.")
|
||||
|
@ -12,65 +12,65 @@ namespace Qv2ray::core::handlers
|
||||
{
|
||||
DEBUG(MODULE_CORE_HANDLER, "ConnectionHandler Constructor.")
|
||||
|
||||
// Do we need to check how many of them are loaded?
|
||||
// Do not use: for (const auto &key : connections), why?
|
||||
for (auto i = 0; i < GlobalConfig.connections.count(); i++)
|
||||
{
|
||||
auto const &id = ConnectionId(GlobalConfig.connections.keys().at(i));
|
||||
connections[id] = GlobalConfig.connections.values().at(i);
|
||||
}
|
||||
|
||||
for (const auto &key : GlobalConfig.subscriptions.keys())
|
||||
{
|
||||
GroupId gkey(key);
|
||||
if (gkey == NullGroupId)
|
||||
{
|
||||
LOG(MODULE_CORE_HANDLER, "Removed a null subscription id")
|
||||
continue;
|
||||
}
|
||||
auto const &val = GlobalConfig.subscriptions[key];
|
||||
groups[gkey] = val;
|
||||
|
||||
for (auto conn : val.connections)
|
||||
{
|
||||
connections[ConnectionId(conn)].groupId = GroupId(key);
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &key : GlobalConfig.groups.keys())
|
||||
{
|
||||
GroupId gkey(key);
|
||||
if (gkey == NullGroupId)
|
||||
{
|
||||
LOG(MODULE_CORE_HANDLER, "Removed a null group id")
|
||||
continue;
|
||||
}
|
||||
auto const &val = GlobalConfig.groups.value(key);
|
||||
groups[gkey] = val;
|
||||
|
||||
for (auto conn : val.connections)
|
||||
{
|
||||
connections[ConnectionId(conn)].groupId = GroupId(key);
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &id : connections.keys())
|
||||
{
|
||||
DEBUG(MODULE_CORE_HANDLER, "Loading connection: " + connections.value(id).displayName + " to cache.")
|
||||
auto const &group = connections.value(id).groupId;
|
||||
if (group != NullGroupId)
|
||||
{
|
||||
auto path = group.toString() + "/" + id.toString() + QV2RAY_CONFIG_FILE_EXTENSION;
|
||||
path.prepend(groups[group].isSubscription ? QV2RAY_SUBSCRIPTION_DIR : QV2RAY_CONNECTIONS_DIR);
|
||||
//
|
||||
connectionRootCache[id] = CONFIGROOT(JsonFromString(StringFromFile(path)));
|
||||
}
|
||||
else
|
||||
{
|
||||
connections.remove(id);
|
||||
LOG(MODULE_CORE_HANDLER, "Dropped connection id: " + id.toString() + " since it's not in a group")
|
||||
}
|
||||
}
|
||||
// // Do we need to check how many of them are loaded?
|
||||
// // Do not use: for (const auto &key : connections), why?
|
||||
// for (auto i = 0; i < GlobalConfig.connectionConfig.count(); i++)
|
||||
// {
|
||||
// auto const &id = ConnectionId(GlobalConfig.connections.keys().at(i));
|
||||
// connections[id] = GlobalConfig.connections.values().at(i);
|
||||
// }
|
||||
//
|
||||
// for (const auto &key : GlobalConfig.subscriptions.keys())
|
||||
// {
|
||||
// GroupId gkey(key);
|
||||
// if (gkey == NullGroupId)
|
||||
// {
|
||||
// LOG(MODULE_CORE_HANDLER, "Removed a null subscription id")
|
||||
// continue;
|
||||
// }
|
||||
// auto const &val = GlobalConfig.subscriptions[key];
|
||||
// groups[gkey] = val;
|
||||
//
|
||||
// for (auto conn : val.connections)
|
||||
// {
|
||||
// connections[ConnectionId(conn)].groupId = GroupId(key);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// for (const auto &key : GlobalConfig.groups )
|
||||
// {
|
||||
// GroupId gkey(key);
|
||||
// if (gkey == NullGroupId)
|
||||
// {
|
||||
// LOG(MODULE_CORE_HANDLER, "Removed a null group id")
|
||||
// continue;
|
||||
// }
|
||||
// auto const &val = GlobalConfig.groups.value(key);
|
||||
// groups[gkey] = val;
|
||||
//
|
||||
// for (auto conn : val.connections)
|
||||
// {
|
||||
// connections[ConnectionId(conn)].groupId = GroupId(key);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// for (const auto &id : connections.keys())
|
||||
// {
|
||||
// DEBUG(MODULE_CORE_HANDLER, "Loading connection: " + connections.value(id).displayName + " to cache.")
|
||||
// auto const &group = connections.value(id).groupId;
|
||||
// if (group != NullGroupId)
|
||||
// {
|
||||
// auto path = group.toString() + "/" + id.toString() + QV2RAY_CONFIG_FILE_EXTENSION;
|
||||
// path.prepend(groups[group].isSubscription ? QV2RAY_SUBSCRIPTION_DIR : QV2RAY_CONNECTIONS_DIR);
|
||||
// //
|
||||
// connectionRootCache[id] = CONFIGROOT(JsonFromString(StringFromFile(path)));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// connections.remove(id);
|
||||
// LOG(MODULE_CORE_HANDLER, "Dropped connection id: " + id.toString() + " since it's not in a group")
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Force default group name.
|
||||
groups[DefaultGroupId].displayName = tr("Default Group");
|
||||
@ -99,7 +99,6 @@ namespace Qv2ray::core::handlers
|
||||
auto &newGlobalConfig = GlobalConfig;
|
||||
newGlobalConfig.connections.clear();
|
||||
newGlobalConfig.groups.clear();
|
||||
newGlobalConfig.subscriptions.clear();
|
||||
|
||||
for (auto i = 0; i < connections.count(); i++)
|
||||
{
|
||||
@ -118,7 +117,7 @@ namespace Qv2ray::core::handlers
|
||||
}
|
||||
else
|
||||
{
|
||||
GroupObject_Config o = groups.values()[i];
|
||||
Qv2rayGroupConfigObject o = groups.values()[i];
|
||||
o.connections = connections;
|
||||
newGlobalConfig.groups[groups.keys()[i].toString()] = o;
|
||||
}
|
||||
@ -413,7 +412,7 @@ namespace Qv2ray::core::handlers
|
||||
GroupId id(GenerateRandomString());
|
||||
groups[id].displayName = displayName;
|
||||
groups[id].isSubscription = isSubscription;
|
||||
groups[id].importDate = system_clock::to_time_t(system_clock::now());
|
||||
groups[id].creationDate = system_clock::to_time_t(system_clock::now());
|
||||
PluginHost->Send_ConnectionEvent({ displayName, "", Events::ConnectionEntry::ConnectionEvent_Created });
|
||||
emit OnGroupCreated(id, displayName);
|
||||
CHSaveConfigData();
|
||||
@ -443,7 +442,7 @@ namespace Qv2ray::core::handlers
|
||||
return result;
|
||||
}
|
||||
|
||||
return { groups[id].address, groups[id].lastUpdated, groups[id].updateInterval };
|
||||
return { groups[id].address, groups[id].lastUpdatedDate, groups[id].updateInterval };
|
||||
}
|
||||
|
||||
bool QvConfigHandler::SetSubscriptionData(const GroupId &id, bool isSubscription, const QString &address, float updateInterval)
|
||||
@ -583,7 +582,7 @@ namespace Qv2ray::core::handlers
|
||||
}
|
||||
|
||||
// Update the time
|
||||
groups[id].lastUpdated = system_clock::to_time_t(system_clock::now());
|
||||
groups[id].lastUpdatedDate = system_clock::to_time_t(system_clock::now());
|
||||
|
||||
return hasErrorOccured;
|
||||
}
|
||||
|
@ -38,16 +38,16 @@ namespace Qv2ray::core::handlers
|
||||
CheckGroupExistanceEx(groupId, {});
|
||||
return groups[groupId].connections;
|
||||
}
|
||||
inline const QList<GroupId> AllGroups() const
|
||||
inline QList<GroupId> AllGroups() const
|
||||
{
|
||||
return groups.keys();
|
||||
}
|
||||
inline const ConnectionMetaObject GetConnectionMetaObject(const ConnectionId &id) const
|
||||
inline const Qv2rayConnectionObject GetConnectionMetaObject(const ConnectionId &id) const
|
||||
{
|
||||
CheckConnectionExistanceEx(id, {});
|
||||
return connections[id];
|
||||
}
|
||||
inline const GroupMetaObject GetGroupMetaObject(const GroupId &id) const
|
||||
inline Qv2rayGroupConfigObject GetGroupMetaObject(const GroupId &id) const
|
||||
{
|
||||
CheckGroupExistanceEx(id, {});
|
||||
return groups[id];
|
||||
@ -140,8 +140,8 @@ namespace Qv2ray::core::handlers
|
||||
int saveTimerId;
|
||||
int pingAllTimerId;
|
||||
int pingConnectionTimerId;
|
||||
QHash<GroupId, GroupMetaObject> groups;
|
||||
QHash<ConnectionId, ConnectionMetaObject> connections;
|
||||
QHash<GroupId, Qv2rayGroupConfigObject> groups;
|
||||
QHash<ConnectionId, Qv2rayConnectionObject> connections;
|
||||
QHash<ConnectionId, CONFIGROOT> connectionRootCache;
|
||||
|
||||
private:
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Qv2ray::core::config
|
||||
{
|
||||
void SaveGlobalSettings(const Qv2rayConfig &conf)
|
||||
void SaveGlobalSettings(const Qv2rayConfigObject &conf)
|
||||
{
|
||||
GlobalConfig = conf;
|
||||
SaveGlobalSettings();
|
||||
|
@ -4,7 +4,7 @@
|
||||
namespace Qv2ray::core::config
|
||||
{
|
||||
void SaveGlobalSettings();
|
||||
void SaveGlobalSettings(const Qv2rayConfig &conf);
|
||||
void SaveGlobalSettings(const Qv2rayConfigObject &conf);
|
||||
void SetConfigDirPath(const QString &path);
|
||||
bool CheckSettingsPathAvailability(const QString &_path, bool checkExistingConfig);
|
||||
} // namespace Qv2ray::core::config
|
||||
|
@ -19,79 +19,79 @@ namespace Qv2ray
|
||||
// Cases 1, 2, and 3 are not supported anymore.
|
||||
// --------------------------------------------------------------------------------------
|
||||
// Below is for Qv2ray version 2
|
||||
case 4:
|
||||
{
|
||||
// We changed the "proxyCN" to "bypassCN" as it's easier to
|
||||
// understand....
|
||||
auto v2_oldProxyCN = root["proxyCN"].toBool();
|
||||
//
|
||||
// From 3 to 4, we changed 'runAsRoot' to 'tProxySupport'
|
||||
auto v3_oldrunAsRoot = root["runAsRoot"].toBool();
|
||||
root.insert("tProxySupport", v3_oldrunAsRoot);
|
||||
UPGRADELOG("Upgrading runAsRoot to tProxySupport, the value is not changed: " + QSTRN(v3_oldrunAsRoot))
|
||||
//
|
||||
QString path;
|
||||
path = QV2RAY_DEFAULT_VCORE_PATH;
|
||||
root["v2CorePath"] = path;
|
||||
UPGRADELOG("Added v2CorePath to the config file.")
|
||||
//
|
||||
QJsonObject uiSettings;
|
||||
uiSettings["language"] = root["language"].toString("en-US").replace("-", "_");
|
||||
root["uiConfig"] = uiSettings;
|
||||
//
|
||||
root["inboundConfig"] = root["inBoundSettings"];
|
||||
root.remove("inBoundSettings");
|
||||
UPGRADELOG("Renamed inBoundSettings to inboundConfig.")
|
||||
//
|
||||
// connectionConfig
|
||||
QJsonObject o;
|
||||
o["dnsList"] = root["dnsList"];
|
||||
o["withLocalDNS"] = root["withLocalDNS"];
|
||||
o["enableProxy"] = root["enableProxy"];
|
||||
o["bypassCN"] = !v2_oldProxyCN;
|
||||
o["enableStats"] = true;
|
||||
o["statsPort"] = 13459;
|
||||
UPGRADELOG("Default statistics enabled.")
|
||||
root["connectionConfig"] = o;
|
||||
UPGRADELOG("Renamed some connection configs to connectionConfig.")
|
||||
//
|
||||
// Do we need renaming here?
|
||||
// //auto inbound = root["inboundConfig"].toObject();
|
||||
// //auto pacConfig = inbound["pacConfig"].toObject();
|
||||
// //pacConfig["enablePAC"] = pacConfig["usePAC"].toBool();
|
||||
// //inbound["pacConfig"] = pacConfig;
|
||||
// //root["inboundConfig"] = inbound;
|
||||
// //UPDATELOG("Renamed usePAC to enablePAC.")
|
||||
//
|
||||
QJsonObject i;
|
||||
i["connectionName"] = root["autoStartConfig"].toString();
|
||||
root["autoStartConfig"] = i;
|
||||
UPGRADELOG("Added subscription feature to autoStartConfig.")
|
||||
break;
|
||||
}
|
||||
// case 4:
|
||||
// {
|
||||
// // We changed the "proxyCN" to "bypassCN" as it's easier to
|
||||
// // understand....
|
||||
// auto v2_oldProxyCN = root["proxyCN"].toBool();
|
||||
// //
|
||||
// // From 3 to 4, we changed 'runAsRoot' to 'tProxySupport'
|
||||
// auto v3_oldrunAsRoot = root["runAsRoot"].toBool();
|
||||
// root.insert("tProxySupport", v3_oldrunAsRoot);
|
||||
// UPGRADELOG("Upgrading runAsRoot to tProxySupport, the value is not changed: " + QSTRN(v3_oldrunAsRoot))
|
||||
// //
|
||||
// QString path;
|
||||
// path = QV2RAY_DEFAULT_VCORE_PATH;
|
||||
// root["v2CorePath"] = path;
|
||||
// UPGRADELOG("Added v2CorePath to the config file.")
|
||||
// //
|
||||
// QJsonObject uiSettings;
|
||||
// uiSettings["language"] = root["language"].toString("en-US").replace("-", "_");
|
||||
// root["uiConfig"] = uiSettings;
|
||||
// //
|
||||
// root["inboundConfig"] = root["inBoundSettings"];
|
||||
// root.remove("inBoundSettings");
|
||||
// UPGRADELOG("Renamed inBoundSettings to inboundConfig.")
|
||||
// //
|
||||
// // connectionConfig
|
||||
// QJsonObject o;
|
||||
// o["dnsList"] = root["dnsList"];
|
||||
// o["withLocalDNS"] = root["withLocalDNS"];
|
||||
// o["enableProxy"] = root["enableProxy"];
|
||||
// o["bypassCN"] = !v2_oldProxyCN;
|
||||
// o["enableStats"] = true;
|
||||
// o["statsPort"] = 13459;
|
||||
// UPGRADELOG("Default statistics enabled.")
|
||||
// root["connectionConfig"] = o;
|
||||
// UPGRADELOG("Renamed some connection configs to connectionConfig.")
|
||||
// //
|
||||
// // Do we need renaming here?
|
||||
// // //auto inbound = root["inboundConfig"].toObject();
|
||||
// // //auto pacConfig = inbound["pacConfig"].toObject();
|
||||
// // //pacConfig["enablePAC"] = pacConfig["usePAC"].toBool();
|
||||
// // //inbound["pacConfig"] = pacConfig;
|
||||
// // //root["inboundConfig"] = inbound;
|
||||
// // //UPDATELOG("Renamed usePAC to enablePAC.")
|
||||
// //
|
||||
// QJsonObject i;
|
||||
// i["connectionName"] = root["autoStartConfig"].toString();
|
||||
// root["autoStartConfig"] = i;
|
||||
// UPGRADELOG("Added subscription feature to autoStartConfig.")
|
||||
// break;
|
||||
// }
|
||||
|
||||
// Qv2ray version 2, RC 2
|
||||
case 5:
|
||||
{
|
||||
// Added subscription auto update
|
||||
auto subs = root["subscribes"].toObject();
|
||||
root.remove("subscribes");
|
||||
QJsonObject newSubscriptions;
|
||||
// // Qv2ray version 2, RC 2
|
||||
// case 5:
|
||||
// {
|
||||
// // Added subscription auto update
|
||||
// auto subs = root["subscribes"].toObject();
|
||||
// root.remove("subscribes");
|
||||
// QJsonObject newSubscriptions;
|
||||
|
||||
for (auto item = subs.begin(); item != subs.end(); item++)
|
||||
{
|
||||
auto key = item.key();
|
||||
SubscriptionObject_Config _conf;
|
||||
_conf.address = item.value().toString();
|
||||
_conf.lastUpdated = system_clock::to_time_t(system_clock::now());
|
||||
_conf.updateInterval = 5;
|
||||
newSubscriptions[key] = _conf.toJson();
|
||||
}
|
||||
// for (auto item = subs.begin(); item != subs.end(); item++)
|
||||
// {
|
||||
// auto key = item.key();
|
||||
// Qv2rayGroupConfigObject _conf;
|
||||
// _conf..address = item.value().toString();
|
||||
// _conf.lastUpdated = system_clock::to_time_t(system_clock::now());
|
||||
// _conf.updateInterval = 5;
|
||||
// newSubscriptions[key] = _conf.toJson();
|
||||
// }
|
||||
|
||||
root["subscriptions"] = newSubscriptions;
|
||||
UPGRADELOG("Added subscription renewal options.")
|
||||
break;
|
||||
}
|
||||
// root["subscriptions"] = newSubscriptions;
|
||||
// UPGRADELOG("Added subscription renewal options.")
|
||||
// break;
|
||||
// }
|
||||
|
||||
// Qv2ray version 2, RC 4
|
||||
case 6:
|
||||
@ -286,6 +286,12 @@ namespace Qv2ray
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Splitted Qv2ray.conf,
|
||||
case 11:
|
||||
{
|
||||
//
|
||||
}
|
||||
default:
|
||||
{
|
||||
//
|
||||
@ -301,7 +307,7 @@ namespace Qv2ray
|
||||
qApp->exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
abort();
|
||||
root["config_version"] = root["config_version"].toInt() + 1;
|
||||
return root;
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ bool initialiseQv2ray()
|
||||
return false;
|
||||
}
|
||||
|
||||
Qv2rayConfig conf;
|
||||
Qv2rayConfigObject conf;
|
||||
conf.kernelConfig.KernelPath(QString(QV2RAY_DEFAULT_VCORE_PATH));
|
||||
conf.kernelConfig.AssetsPath(QString(QV2RAY_DEFAULT_VASSETS_PATH));
|
||||
conf.logLevel = 3;
|
||||
@ -312,7 +312,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// Load config object from upgraded config QJsonObject
|
||||
auto confObject = Qv2rayConfig::fromJson(conf);
|
||||
auto confObject = Qv2rayConfigObject::fromJson(conf);
|
||||
|
||||
if (confObject.uiConfig.language.isEmpty())
|
||||
{
|
||||
|
@ -266,8 +266,8 @@ void GroupManager::on_groupList_itemClicked(QListWidgetItem *item)
|
||||
const auto &groupMetaObject = ConnectionManager->GetGroupMetaObject(currentGroupId);
|
||||
groupIsSubscriptionGroup->setChecked(groupMetaObject.isSubscription);
|
||||
subAddrTxt->setText(groupMetaObject.address);
|
||||
lastUpdatedLabel->setText(timeToString(groupMetaObject.lastUpdated));
|
||||
createdAtLabel->setText(timeToString(groupMetaObject.importDate));
|
||||
lastUpdatedLabel->setText(timeToString(groupMetaObject.lastUpdatedDate));
|
||||
createdAtLabel->setText(timeToString(groupMetaObject.creationDate));
|
||||
updateIntervalSB->setValue(groupMetaObject.updateInterval);
|
||||
//
|
||||
connectionsList->clear();
|
||||
|
@ -52,7 +52,7 @@ void MainWindow::CheckSubscriptionsUpdate()
|
||||
if (info.updateInterval == 0)
|
||||
continue;
|
||||
//
|
||||
const auto &lastRenewDate = QDateTime::fromTime_t(info.lastUpdated);
|
||||
const auto &lastRenewDate = QDateTime::fromTime_t(info.lastUpdatedDate);
|
||||
const auto &renewTime = lastRenewDate.addSecs(info.updateInterval * 86400);
|
||||
LOG(MODULE_SUBSCRIPTION, //
|
||||
"Subscription \"" + info.displayName + "\": " + //
|
||||
|
@ -123,7 +123,7 @@ void PluginManageWindow::on_openPluginFolder_clicked()
|
||||
pluginPath.mkpath(QV2RAY_CONFIG_DIR + "plugins/");
|
||||
}
|
||||
#ifdef Q_OS_LINUX
|
||||
QProcess::execute("xdg-open", { pluginPath.absolutePath() });
|
||||
QProcess::execute("xdg-open", { "\"" + pluginPath.absolutePath() + "\"" });
|
||||
#else
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(pluginPath.absolutePath()));
|
||||
#endif
|
||||
|
@ -155,17 +155,17 @@ PreferencesWindow::PreferencesWindow(QWidget *parent) : QDialog(parent), Current
|
||||
qvNetworkUATxt->setText(CurrentConfig.networkConfig.userAgent);
|
||||
switch (CurrentConfig.networkConfig.proxyType)
|
||||
{
|
||||
case Qv2rayNetworkConfig::QVPROXY_NONE:
|
||||
case Qv2rayConfig_Network::QVPROXY_NONE:
|
||||
{
|
||||
qvProxyNoProxy->setChecked(true);
|
||||
break;
|
||||
}
|
||||
case Qv2rayNetworkConfig::QVPROXY_SYSTEM:
|
||||
case Qv2rayConfig_Network::QVPROXY_SYSTEM:
|
||||
{
|
||||
qvProxySystemProxy->setChecked(true);
|
||||
break;
|
||||
}
|
||||
case Qv2rayNetworkConfig::QVPROXY_CUSTOM:
|
||||
case Qv2rayConfig_Network::QVPROXY_CUSTOM:
|
||||
{
|
||||
qvProxyCustomProxy->setChecked(true);
|
||||
break;
|
||||
@ -1300,17 +1300,17 @@ void PreferencesWindow::on_dnsIntercept_toggled(bool checked)
|
||||
|
||||
void PreferencesWindow::on_qvProxyCustomProxy_clicked()
|
||||
{
|
||||
CurrentConfig.networkConfig.proxyType = Qv2rayNetworkConfig::QVPROXY_CUSTOM;
|
||||
CurrentConfig.networkConfig.proxyType = Qv2rayConfig_Network::QVPROXY_CUSTOM;
|
||||
}
|
||||
|
||||
void PreferencesWindow::on_qvProxySystemProxy_clicked()
|
||||
{
|
||||
CurrentConfig.networkConfig.proxyType = Qv2rayNetworkConfig::QVPROXY_SYSTEM;
|
||||
CurrentConfig.networkConfig.proxyType = Qv2rayConfig_Network::QVPROXY_SYSTEM;
|
||||
}
|
||||
|
||||
void PreferencesWindow::on_qvProxyNoProxy_clicked()
|
||||
{
|
||||
CurrentConfig.networkConfig.proxyType = Qv2rayNetworkConfig::QVPROXY_NONE;
|
||||
CurrentConfig.networkConfig.proxyType = Qv2rayConfig_Network::QVPROXY_NONE;
|
||||
}
|
||||
|
||||
void PreferencesWindow::on_DnsFreedomCb_stateChanged(int arg1)
|
||||
|
@ -223,5 +223,5 @@ class PreferencesWindow
|
||||
//
|
||||
bool NeedRestart = false;
|
||||
bool finishedLoading = false;
|
||||
Qv2rayConfig CurrentConfig;
|
||||
Qv2rayConfigObject CurrentConfig;
|
||||
};
|
||||
|
@ -48,7 +48,7 @@ QList<QAction *> RouteSettingsMatrixWidget::getBuiltInSchemes()
|
||||
return list;
|
||||
}
|
||||
|
||||
QAction *RouteSettingsMatrixWidget::schemeToAction(const QString &name, const Qv2ray::base::config::Qv2rayRouteConfig &scheme)
|
||||
QAction *RouteSettingsMatrixWidget::schemeToAction(const QString &name, const Qv2ray::base::config::Qv2rayConfig_Routing &scheme)
|
||||
{
|
||||
QAction *action = new QAction(this);
|
||||
action->setText(name);
|
||||
@ -56,7 +56,7 @@ QAction *RouteSettingsMatrixWidget::schemeToAction(const QString &name, const Qv
|
||||
return action;
|
||||
}
|
||||
|
||||
void RouteSettingsMatrixWidget::SetRouteConfig(const Qv2rayRouteConfig &conf)
|
||||
void RouteSettingsMatrixWidget::SetRouteConfig(const Qv2rayConfig_Routing &conf)
|
||||
{
|
||||
domainStrategyCombo->setCurrentText(conf.domainStrategy);
|
||||
//
|
||||
@ -69,9 +69,9 @@ void RouteSettingsMatrixWidget::SetRouteConfig(const Qv2rayRouteConfig &conf)
|
||||
proxyIPTxt->setText(conf.ips.proxy.join(NEWLINE));
|
||||
}
|
||||
|
||||
Qv2rayRouteConfig RouteSettingsMatrixWidget::GetRouteConfig() const
|
||||
Qv2rayConfig_Routing RouteSettingsMatrixWidget::GetRouteConfig() const
|
||||
{
|
||||
config::Qv2rayRouteConfig conf;
|
||||
config::Qv2rayConfig_Routing conf;
|
||||
conf.domainStrategy = this->domainStrategyCombo->currentText();
|
||||
conf.domains.block = SplitLines(blockDomainTxt->toPlainText().replace(" ", ""));
|
||||
conf.domains.direct = SplitLines(directDomainTxt->toPlainText().replace(" ", ""));
|
||||
@ -116,7 +116,7 @@ void RouteSettingsMatrixWidget::on_importSchemeBtn_clicked()
|
||||
return;
|
||||
|
||||
// write the scheme onto the window
|
||||
this->SetRouteConfig(static_cast<Qv2rayRouteConfig>(scheme));
|
||||
this->SetRouteConfig(static_cast<Qv2rayConfig_Routing>(scheme));
|
||||
|
||||
// done
|
||||
LOG(MODULE_SETTINGS, "Imported route config: " + scheme.name + " by: " + scheme.author)
|
||||
|
@ -15,15 +15,15 @@ class RouteSettingsMatrixWidget
|
||||
|
||||
public:
|
||||
RouteSettingsMatrixWidget(const QString &assetsDirPath, QWidget *parent = nullptr);
|
||||
void SetRouteConfig(const Qv2ray::base::config::Qv2rayRouteConfig &conf);
|
||||
Qv2ray::base::config::Qv2rayRouteConfig GetRouteConfig() const;
|
||||
void SetRouteConfig(const Qv2ray::base::config::Qv2rayConfig_Routing &conf);
|
||||
Qv2ray::base::config::Qv2rayConfig_Routing GetRouteConfig() const;
|
||||
~RouteSettingsMatrixWidget();
|
||||
|
||||
private:
|
||||
std::optional<QString> openFileDialog();
|
||||
std::optional<QString> saveFileDialog();
|
||||
QList<QAction *> getBuiltInSchemes();
|
||||
QAction *schemeToAction(const QString &name, const Qv2ray::base::config::Qv2rayRouteConfig &scheme);
|
||||
QAction *schemeToAction(const QString &name, const Qv2ray::base::config::Qv2rayConfig_Routing &scheme);
|
||||
|
||||
private:
|
||||
QMenu *builtInSchemesMenu;
|
||||
|
Loading…
Reference in New Issue
Block a user