diff --git a/Build.Counter b/Build.Counter index bf6950a4..081da695 100644 --- a/Build.Counter +++ b/Build.Counter @@ -1 +1 @@ -3387 +3400 diff --git a/Qv2ray.pro b/Qv2ray.pro index 17dfb93c..7630adb4 100644 --- a/Qv2ray.pro +++ b/Qv2ray.pro @@ -118,7 +118,7 @@ Qv2rayAddSource(components, plugins/toolbar, QvToolbar, cpp, hpp) #Qv2rayAddSource(components, plugins/toolbar, QvToolbar_win, cpp) Qv2rayAddSource(components, proxy, QvProxyConfigurator, cpp, hpp) Qv2rayAddSource(components, tcping, QvTCPing, cpp, hpp) -Qv2rayAddSource(core, config, ConfigBackend, cpp) +Qv2rayAddSource(core, config, ConfigBackend, cpp, hpp) Qv2rayAddSource(core, config, ConfigUpgrade, cpp) Qv2rayAddSource(core, connection, ConnectionConfig_Convertion, cpp) Qv2rayAddSource(core, connection, ConnectionConfig_Generation, cpp) diff --git a/src/base/Qv2rayBase.hpp b/src/base/Qv2rayBase.hpp index b8334f3c..92602efd 100644 --- a/src/base/Qv2rayBase.hpp +++ b/src/base/Qv2rayBase.hpp @@ -1,6 +1,7 @@ #pragma once #include #include +#include #include #include #include @@ -96,4 +97,10 @@ namespace Qv2ray { // Extra header for QvConfigUpgrade.cpp QJsonObject UpgradeConfig(int fromVersion, int toVersion, QJsonObject root); + + inline void ExitQv2ray() + { + isExiting = true; + QApplication::quit(); + } } diff --git a/src/common/CommandArgs.cpp b/src/common/CommandArgs.cpp index c2504d6b..54081b41 100644 --- a/src/common/CommandArgs.cpp +++ b/src/common/CommandArgs.cpp @@ -1,5 +1,5 @@ #include "CommandArgs.hpp" -#include +#include "base/Qv2rayBase.hpp" namespace Qv2ray::common { diff --git a/src/common/CommandArgs.hpp b/src/common/CommandArgs.hpp index 724741e4..72092b52 100644 --- a/src/common/CommandArgs.hpp +++ b/src/common/CommandArgs.hpp @@ -1,5 +1,7 @@ #pragma once -#include "base/Qv2rayBase.hpp" + +#include + namespace Qv2ray::common { enum CommandLineParseResult { diff --git a/src/common/HTTPRequestHelper.hpp b/src/common/HTTPRequestHelper.hpp index 271e1dc3..f67221dc 100644 --- a/src/common/HTTPRequestHelper.hpp +++ b/src/common/HTTPRequestHelper.hpp @@ -58,3 +58,5 @@ namespace Qv2ray::common QNetworkAccessManager accessManager; }; } + +using namespace Qv2ray::common; diff --git a/src/common/QvHelpers.cpp b/src/common/QvHelpers.cpp index f9592b09..6b5076be 100644 --- a/src/common/QvHelpers.cpp +++ b/src/common/QvHelpers.cpp @@ -1,5 +1,4 @@ #include "common/QvHelpers.hpp" -#include "common/CommandArgs.hpp" #include namespace Qv2ray::common @@ -191,16 +190,6 @@ namespace Qv2ray::common } } - void QFastAppendTextDocument(const QString &message, QTextDocument *doc) - { - QTextCursor cursor(doc); - cursor.movePosition(QTextCursor::End); - cursor.beginEditBlock(); - cursor.insertBlock(); - cursor.insertHtml(message); - cursor.endEditBlock(); - } - QStringList ConvertQStringList(const QList &stdListString) { QStringList listQt; diff --git a/src/common/QvHelpers.hpp b/src/common/QvHelpers.hpp index f1a47d24..5b27cdb4 100644 --- a/src/common/QvHelpers.hpp +++ b/src/common/QvHelpers.hpp @@ -34,7 +34,6 @@ namespace Qv2ray::common // QString FormatBytes(long long bytes); void DeducePossibleFileName(const QString &baseDir, QString *fileName, const QString &extension); - void QFastAppendTextDocument(const QString &message, QTextDocument *doc); QStringList ConvertQStringList(const QList &stdListString); std::list ConvertStdStringList(const QStringList &qStringList); // diff --git a/src/components/autolaunch/QvAutoLaunch.hpp b/src/components/autolaunch/QvAutoLaunch.hpp index 4bb2f45b..1c9e6443 100644 --- a/src/components/autolaunch/QvAutoLaunch.hpp +++ b/src/components/autolaunch/QvAutoLaunch.hpp @@ -6,4 +6,5 @@ namespace Qv2ray::components::autolaunch void SetLaunchAtLoginStatus(bool enable); } +using namespace Qv2ray::components; using namespace Qv2ray::components::autolaunch; diff --git a/src/components/pac/QvPACHandler.cpp b/src/components/pac/QvPACHandler.cpp index ac031d7f..f534e7b3 100644 --- a/src/components/pac/QvPACHandler.cpp +++ b/src/components/pac/QvPACHandler.cpp @@ -2,6 +2,7 @@ #include "qhttprequest.h" #include "qhttpresponse.h" #include "core/CoreUtils.hpp" +#include "common/QvHelpers.hpp" namespace Qv2ray::components::pac { @@ -13,8 +14,13 @@ namespace Qv2ray::components::pac } PACServer::~PACServer() { - pacServer->close(); - delete pacServer; + if (isStarted) { + pacServer->close(); + } + + if (pacServer != nullptr) { + delete pacServer; + } } void PACServer::SetProxyString(const QString &proxyString) { diff --git a/src/components/pac/QvPACHandler.hpp b/src/components/pac/QvPACHandler.hpp index 0faa3a6d..a2c3e787 100644 --- a/src/components/pac/QvPACHandler.hpp +++ b/src/components/pac/QvPACHandler.hpp @@ -27,4 +27,5 @@ namespace Qv2ray::components::pac }; } +using namespace Qv2ray::components; using namespace Qv2ray::components::pac; diff --git a/src/components/plugins/toolbar/QvToolbar.hpp b/src/components/plugins/toolbar/QvToolbar.hpp index cdf858b9..84e45967 100644 --- a/src/components/plugins/toolbar/QvToolbar.hpp +++ b/src/components/plugins/toolbar/QvToolbar.hpp @@ -51,5 +51,7 @@ namespace Qv2ray::components::plugins QString GetAnswerToRequest(const QString &pchRequest); } } + +using namespace Qv2ray::components; using namespace Qv2ray::components::plugins::Toolbar; diff --git a/src/components/proxy/QvProxyConfigurator.hpp b/src/components/proxy/QvProxyConfigurator.hpp index a4066648..82425be6 100644 --- a/src/components/proxy/QvProxyConfigurator.hpp +++ b/src/components/proxy/QvProxyConfigurator.hpp @@ -8,4 +8,5 @@ namespace Qv2ray::components::proxy bool SetSystemProxy(const QString &address, int port, bool usePAC); } +using namespace Qv2ray::components; using namespace Qv2ray::components::proxy; diff --git a/src/components/tcping/QvTCPing.hpp b/src/components/tcping/QvTCPing.hpp index ce35aefc..8b6b1b1d 100644 --- a/src/components/tcping/QvTCPing.hpp +++ b/src/components/tcping/QvTCPing.hpp @@ -9,8 +9,7 @@ #endif #include #include -#include "common/QvHelpers.hpp" - +#include "base/Qv2rayBase.hpp" namespace Qv2ray::components::tcping { diff --git a/src/core/CoreUtils.cpp b/src/core/CoreUtils.cpp index 2cd0d0a8..9503f709 100644 --- a/src/core/CoreUtils.cpp +++ b/src/core/CoreUtils.cpp @@ -1,42 +1,9 @@ #include "CoreUtils.hpp" +#include "common/QvHelpers.hpp" #include "QApplication" namespace Qv2ray::core { - void SaveGlobalConfig(Qv2rayConfig conf) - { - GlobalConfig = conf; - QFile config(QV2RAY_CONFIG_FILE); - QString str = StructToJsonString(conf); - StringToFile(&str, &config); - } - - void SetConfigDirPath(const QString &path) - { - Qv2rayConfigPath = path; - - if (!path.endsWith("/")) { - Qv2rayConfigPath += "/"; - } - } - - void LoadGlobalConfig() - { - QFile file(QV2RAY_CONFIG_FILE); - file.open(QFile::ReadOnly); - QTextStream stream(&file); - auto str = stream.readAll(); - auto config = StructFromJsonString(str); - SaveGlobalConfig(config); - file.close(); - } - - void ExitQv2ray() - { - isExiting = true; - QApplication::quit(); - } - tuple GetConnectionInfo(const CONFIGROOT &root) { bool validOutboundFound = false; @@ -63,7 +30,7 @@ namespace Qv2ray::core // Set initial values. *host = QObject::tr("N/A"); *port = 0; - *protocol = out["protocol"].toString(QObject::tr("N/A")); + *protocol = out["protocol"].toString(QObject::tr("N/A")).toLower(); if (*protocol == "vmess") { auto Server = StructFromJsonString(JsonToString(out["settings"].toObject()["vnext"].toArray().first().toObject())); diff --git a/src/core/CoreUtils.hpp b/src/core/CoreUtils.hpp index 10b3d9c9..4b8e75ab 100644 --- a/src/core/CoreUtils.hpp +++ b/src/core/CoreUtils.hpp @@ -1,14 +1,10 @@ #pragma once #include "base/Qv2rayBase.hpp" -#include "common/QvHelpers.hpp" +#include "core/config/ConfigBackend.hpp" namespace Qv2ray::core { - void SaveGlobalConfig(Qv2rayConfig conf); - void LoadGlobalConfig(); - void SetConfigDirPath(const QString &path); - // inline QString getTag(const INBOUND &in) { return in["tag"].toString(); @@ -19,7 +15,11 @@ namespace Qv2ray::core return in["tag"].toString(); } - void ExitQv2ray(); + inline QString getTag(const RuleObject &in) + { + return in.QV2RAY_RULE_TAG; + } + tuple GetConnectionInfo(const CONFIGROOT &alias); bool GetOutboundData(const OUTBOUND &out, QString *host, int *port, QString *protocol); } diff --git a/src/core/config/ConfigBackend.cpp b/src/core/config/ConfigBackend.cpp index e69de29b..d22b4de2 100644 --- a/src/core/config/ConfigBackend.cpp +++ b/src/core/config/ConfigBackend.cpp @@ -0,0 +1,35 @@ +#include "ConfigBackend.hpp" +#include "common/QvHelpers.hpp" + +namespace Qv2ray::core::config +{ + void SaveGlobalConfig(Qv2rayConfig conf) + { + GlobalConfig = conf; + QFile config(QV2RAY_CONFIG_FILE); + QString str = StructToJsonString(conf); + StringToFile(&str, &config); + } + + void SetConfigDirPath(const QString &path) + { + Qv2rayConfigPath = path; + + if (!path.endsWith("/")) { + Qv2rayConfigPath += "/"; + } + } + + void LoadGlobalConfig() + { + QFile file(QV2RAY_CONFIG_FILE); + file.open(QFile::ReadOnly); + QTextStream stream(&file); + auto str = stream.readAll(); + auto config = StructFromJsonString(str); + SaveGlobalConfig(config); + file.close(); + } +} + +using namespace Qv2ray::core::config; diff --git a/src/core/config/ConfigBackend.hpp b/src/core/config/ConfigBackend.hpp new file mode 100644 index 00000000..08f94a1a --- /dev/null +++ b/src/core/config/ConfigBackend.hpp @@ -0,0 +1,11 @@ +#include "base/Qv2rayBase.hpp" + +namespace Qv2ray::core::config +{ + void SaveGlobalConfig(Qv2rayConfig conf); + void SetConfigDirPath(const QString &path); + void LoadGlobalConfig(); +} + +using namespace Qv2ray::core; +using namespace Qv2ray::core::config; diff --git a/src/core/connection/ConnectionConfigOperations.hpp b/src/core/connection/ConnectionConfigOperations.hpp index 21b8ec62..bb56b024 100644 --- a/src/core/connection/ConnectionConfigOperations.hpp +++ b/src/core/connection/ConnectionConfigOperations.hpp @@ -71,5 +71,5 @@ namespace Qv2ray::core::connection } } - +using namespace Qv2ray::core; using namespace Qv2ray::core::connection; diff --git a/src/core/kernel/QvKernelInteractions.cpp b/src/core/kernel/QvKernelInteractions.cpp index be2f458c..b90943ae 100644 --- a/src/core/kernel/QvKernelInteractions.cpp +++ b/src/core/kernel/QvKernelInteractions.cpp @@ -1,6 +1,7 @@ #include #include #include +#include "common/QvHelpers.hpp" #include "QvKernelInteractions.hpp" #include "core/connection/ConnectionConfigOperations.hpp" diff --git a/src/core/kernel/QvKernelInteractions.hpp b/src/core/kernel/QvKernelInteractions.hpp index 09ed827f..43dd6919 100644 --- a/src/core/kernel/QvKernelInteractions.hpp +++ b/src/core/kernel/QvKernelInteractions.hpp @@ -1,6 +1,6 @@ #pragma once #include -#include "core/CoreUtils.hpp" +#include "base/Qv2rayBase.hpp" #ifdef WITH_LIB_GRPCPP #include #include "libs/gen/v2ray_api_commands.pb.h" diff --git a/src/ui/editors/w_InboundEditor.cpp b/src/ui/editors/w_InboundEditor.cpp index 23df9504..82683738 100644 --- a/src/ui/editors/w_InboundEditor.cpp +++ b/src/ui/editors/w_InboundEditor.cpp @@ -1,5 +1,6 @@ #include "w_InboundEditor.hpp" #include "core/CoreUtils.hpp" +#include "common/QvHelpers.hpp" #include "core/connection/ConnectionConfigOperations.hpp" static bool isLoading = false; diff --git a/src/ui/w_PreferencesWindow.cpp b/src/ui/w_PreferencesWindow.cpp index 0eb6d78b..3f427fba 100644 --- a/src/ui/w_PreferencesWindow.cpp +++ b/src/ui/w_PreferencesWindow.cpp @@ -5,7 +5,9 @@ #include #include +#include "common/QvHelpers.hpp" #include "common/HTTPRequestHelper.hpp" +#include "core/config/ConfigBackend.hpp" #include "core/kernel/QvKernelInteractions.hpp" #include "core/connection/ConnectionConfigOperations.hpp" #include "components/plugins/toolbar/QvToolbar.hpp" @@ -26,7 +28,7 @@ PreferencesWindow::PreferencesWindow(QWidget *parent) : QDialog(parent), networkToolbarPage->setEnabled(StartupOption.enableToolbarPlguin); if (!StartupOption.enableToolbarPlguin) { - networkToolbarInfoLabel->setText(tr("Qv2ray Network Toolbar is disabled and still under test. Add --withNetworkToolbar to enable.")); + networkToolbarInfoLabel->setText(tr("Qv2ray Network Toolbar is disabled and still under test. Add --withToolbarPlugin to enable.")); } // We add locales diff --git a/src/ui/w_PreferencesWindow.hpp b/src/ui/w_PreferencesWindow.hpp index 6bcf0e1c..a21ec994 100644 --- a/src/ui/w_PreferencesWindow.hpp +++ b/src/ui/w_PreferencesWindow.hpp @@ -2,7 +2,7 @@ #include #include -#include "common/QvHelpers.hpp" +#include "base/Qv2rayBase.hpp" class PreferencesWindow : public QDialog, private Ui::PreferencesWindow { diff --git a/src/ui/w_SubscriptionManager.cpp b/src/ui/w_SubscriptionManager.cpp index 0bc2933d..d115cd70 100644 --- a/src/ui/w_SubscriptionManager.cpp +++ b/src/ui/w_SubscriptionManager.cpp @@ -1,4 +1,6 @@ #include "w_SubscriptionManager.hpp" +#include "common/QvHelpers.hpp" +#include "core/CoreUtils.hpp" #include "core/connection/ConnectionConfigOperations.hpp" SubscribeEditor::SubscribeEditor(QWidget *parent) : diff --git a/src/ui/w_SubscriptionManager.hpp b/src/ui/w_SubscriptionManager.hpp index 47f91cf0..6552d9da 100644 --- a/src/ui/w_SubscriptionManager.hpp +++ b/src/ui/w_SubscriptionManager.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include "core/CoreUtils.hpp" +#include "base/Qv2rayBase.hpp" #include "common/HTTPRequestHelper.hpp" #include "ui_w_SubscriptionManager.h"