diff --git a/CMakeLists.txt b/CMakeLists.txt index ebc8905..8d3984f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,6 @@ add_executable(${PROJECT_NAME} WIN32 zjuconnectcontroller/zjuconnectcontroller.cpp portforwardingwindow/portforwardingwindow.cpp settingwindow/settingwindow.cpp - networkdetector/networkdetector.cpp utils/utils.cpp resource.qrc ${CMAKE_CURRENT_SOURCE_DIR}/resource/icon.rc diff --git a/main.cpp b/main.cpp index 9ccefd3..6949d0a 100644 --- a/main.cpp +++ b/main.cpp @@ -8,7 +8,7 @@ int main(int argc, char *argv[]) { SingleApplication app(argc, argv); QApplication::setApplicationName("HITsz Connect for Windows"); - QApplication::setApplicationVersion("1.1.3"); + QApplication::setApplicationVersion("1.1.3-preview"); MainWindow mainWindow; diff --git a/mainwindow.cpp b/mainwindow.cpp index 08e3bdc..95947e5 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -22,7 +22,6 @@ MainWindow::MainWindow(QWidget *parent) : zjuConnectController = nullptr; networkAccessManager = new QNetworkAccessManager(this); - networkDetector = new NetworkDetector(); process = new QProcess(this); processForL2tp = new QProcess(this); @@ -126,7 +125,7 @@ MainWindow::MainWindow(QWidget *parent) : return; } - if (mode == "RVPN" && isSystemProxySet) + if (isSystemProxySet) { ui->pushButton2->click(); } @@ -155,91 +154,6 @@ MainWindow::MainWindow(QWidget *parent) : } ); - // 检查更新 - /* - QTimer::singleShot(10000, [&]() - { - QNetworkRequest request(QUrl("https://zjuconnect.myth.cx/version.json")); - request.setHeader( - QNetworkRequest::UserAgentHeader, - QApplication::applicationName() + " v" + QApplication::applicationVersion() - ); - networkAccessManager->get(request); - }); - */ - - connect(networkAccessManager, &QNetworkAccessManager::finished, - [&](QNetworkReply *reply) - { - if (reply->error() == QNetworkReply::NoError) - { - QJsonDocument jsonDocument = QJsonDocument::fromJson(reply->readAll()); - QJsonObject jsonObject = jsonDocument.object(); - QString version = jsonObject["version"].toString(); - QString description = jsonObject["description"].toString(); - QString url = jsonObject["url"].toString(); - - if (version != QApplication::applicationVersion()) - { - disconnect(trayIcon, &QSystemTrayIcon::messageClicked, nullptr, nullptr); - trayIcon->showMessage( - "有新版本可用", - "v" + version + "\n更新内容:" + description + "\n点击查看详情", - QSystemTrayIcon::Information, - 10000 - ); - - connect(trayIcon, &QSystemTrayIcon::messageClicked, this, [&, url]() - { - disconnect(trayIcon, &QSystemTrayIcon::messageClicked, nullptr, nullptr); - - QDesktopServices::openUrl(QUrl(url)); - - show(); - setWindowState(Qt::WindowState::WindowActive); - }); - } - } - }); - - // 网络检测 - connect(networkDetector, &NetworkDetector::finished, this, - [&](const NetworkDetectResult &result) - { - networkDetectResult = result; - - QString resultString = ""; - resultString += "网络检测结果 | "; - if (result.isDefaultDnsAvailable) - { - resultString += "默认 DNS 可用:是 | "; - } - else - { - resultString += "默认 DNS 可用:否 | "; - } - - if (result.isInternetAvailable) - { - resultString += "互联网连接:是 | "; - } - else - { - resultString += "互联网连接:否 | "; - } - - if (result.isProxyEnabled) - { - resultString += "是否启用代理:是"; - } - else - { - resultString += "是否启用代理:否"; - } - - ui->logPlainTextEdit->appendPlainText(resultString); - }); - connect(this, &MainWindow::SetModeFinished, this, [&]() { if (isFirstTimeSetMode) @@ -280,7 +194,7 @@ void MainWindow::upgradeSettings() int configVersion = settings->value("Common/ConfigVersion", 1).toInt(); if (configVersion > 2) { - addLog("警告:配置文件版本高于 2。请使用关闭当前 ZJU Connect 并运行新版本!"); + addLog("警告:配置文件版本高于 2。请运行新版本!"); } else if (configVersion == 2) { @@ -293,7 +207,7 @@ void MainWindow::upgradeSettings() QSettings::NativeFormat ); autoStartSettings.setValue( - "ZjuConnectForWindows", + "HITszConnectForWindows", QCoreApplication::applicationFilePath().replace('/', '\\') ); } @@ -301,44 +215,6 @@ void MainWindow::upgradeSettings() return; } - - if (settings->contains("EasyConnect/ServerAddress")) - { - settings->setValue("ZJUConnect/ServerAddress", settings->value("EasyConnect/ServerAddress")); - settings->remove("EasyConnect/ServerAddress"); - } - - if (settings->contains("EasyConnect/ServerPort")) - { - settings->setValue("ZJUConnect/ServerPort", settings->value("EasyConnect/ServerPort")); - settings->remove("EasyConnect/ServerPort"); - } - - if (settings->contains("EasyConnect/Username")) - { - settings->setValue("Common/Username", settings->value("EasyConnect/Username")); - settings->remove("EasyConnect/Username"); - - } - - if (settings->contains("EasyConnect/Password")) - { - settings->setValue("Common/Password", settings->value("EasyConnect/Password")); - settings->remove("EasyConnect/Password"); - } - - if (settings->contains("GUI/AutoReconnect")) - { - settings->setValue("ZJUConnect/AutoReconnect", settings->value("GUI/AutoReconnect")); - settings->remove("GUI/AutoReconnect"); - } - - if (settings->contains("GUI/ReconnectTime")) - { - settings->setValue("ZJUConnect/ReconnectTime", settings->value("GUI/ReconnectTime")); - settings->remove("GUI/ReconnectTime"); - } - settings->sync(); } @@ -381,8 +257,6 @@ void MainWindow::cleanUpWhenQuit() MainWindow::~MainWindow() { - delete networkDetector; - if (zjuConnectController != nullptr) { disconnect(zjuConnectController, &ZjuConnectController::finished, nullptr, nullptr); diff --git a/mainwindow.h b/mainwindow.h index a3e2ee4..ad2dbe3 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -10,7 +10,6 @@ #include "portforwardingwindow/portforwardingwindow.h" #include "zjuconnectcontroller/zjuconnectcontroller.h" -#include "networkdetector/networkdetector.h" #include "settingwindow/settingwindow.h" #include "QrCodeGenerator/QrCodeGenerator.h" @@ -64,7 +63,6 @@ private: QAction *trayShowAction; QAction *trayCloseAction; ZjuConnectController *zjuConnectController; - NetworkDetector *networkDetector; QNetworkAccessManager *networkAccessManager; QSettings *settings; QProcess *process; @@ -79,7 +77,6 @@ private: SettingWindow *settingWindow; QString mode; - NetworkDetectResult networkDetectResult; bool isFirstTimeSetMode; diff --git a/mainwindow.ui b/mainwindow.ui index 3bd1c9b..cf409ce 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -139,7 +139,8 @@ Windows Version: Arch Linux - 提示:左上角“功能”->“设置”里可以填写账号信息 + 提示:左上角“功能”->“设置”里可以填写账号信息 +可以使用 TUN 模式解决部分软件的代理问题 @@ -206,6 +207,10 @@ Windows Version: Arch Linux + pushButton1 + pushButton2 + tunCheckBox + copyLogPushButton logPlainTextEdit diff --git a/networkdetector/networkdetector.cpp b/networkdetector/networkdetector.cpp deleted file mode 100644 index 86675d2..0000000 --- a/networkdetector/networkdetector.cpp +++ /dev/null @@ -1,180 +0,0 @@ -#include -#include "networkdetector.h" -#include "../utils/utils.h" - -NetworkDetector::NetworkDetector() -{ - process = new QProcess(this); -} - -void NetworkDetector::start() -{ - result.isDefaultDnsAvailable = false; - result.isZjuNet = false; - result.isZjuDnsCorrect = false; - result.isZjuWlan = false; - result.isZjuWlanSecure = false; - result.isZjuLan = false; - result.zjuLanGateway = ""; - result.isInternetAvailable = false; - result.isProxyEnabled = false; - - disconnect(process, &QProcess::finished, this, nullptr); - connect(process, &QProcess::finished, this, [&]() - { - disconnect(process, &QProcess::finished, this, nullptr); - connect(process, &QProcess::finished, this, [&]() - { - QString output = Utils::ConsoleOutputToQString(process->readAllStandardOutput()); - if (!output.contains("timed out")) - { - result.isDefaultDnsAvailable = true; - - if (output.contains("Address: 10.")) - { - result.isZjuNet = true; - result.isZjuDnsCorrect = true; - checkZjuWlan(); - return; - } - } - else - { - result.isDefaultDnsAvailable = false; - } - - disconnect(process, &QProcess::finished, this, nullptr); - connect(process, &QProcess::finished, this, [&]() - { - QString output = Utils::ConsoleOutputToQString(process->readAllStandardOutput()); - if (!output.contains("timed out")) - { - result.isZjuNet = true; - checkZjuWlan(); - } - - checkInternet(); - }); - - process->start("nslookup", QStringList() << "dns1.zju.edu.cn" << "10.10.0.21"); - }); - - process->start("nslookup", QStringList() << "dns1.zju.edu.cn"); - }); - - process->start("ipconfig", QStringList() << "/flushdns"); -} - -void NetworkDetector::checkZjuWlan() -{ - disconnect(process, &QProcess::finished, this, nullptr); - connect(process, &QProcess::finished, this, [&]() - { - QString output = Utils::ConsoleOutputToQString(process->readAllStandardOutput()); - if (output.contains("ZJUWLAN")) - { - if (output.contains("ZJUWLAN-Secure")) - { - result.isZjuWlanSecure = true; - } - else - { - result.isZjuWlan = true; - } - - checkZjuLan(); - return; - } - - checkZjuLan(); - }); - - process->start("netsh", QStringList() << "wlan" << "show" << "interfaces"); -} - -void NetworkDetector::checkZjuLan() -{ - disconnect(process, &QProcess::finished, this, nullptr); - connect(process, &QProcess::finished, this, [&]() - { - QString output = Utils::ConsoleOutputToQString(process->readAllStandardOutput()); - QString line; - QTextStream stream(&output); - - bool waitForIp = false; - bool waitForGateway = false; - QString ip; - - while (!stream.atEnd()) - { - line = stream.readLine(); - if (line.contains("以太网") || line.contains("Ethernet")) - { - waitForIp = true; - } - else if ((line.contains("IP 地址") || line.contains("IP Address")) && waitForIp) - { - ip = line.split(":").at(1).trimmed(); - if (ip.startsWith("10.")) - { - waitForGateway = true; - } - - waitForIp = false; - } - else if ((line.contains("默认网关") || line.contains("Default Gateway")) && waitForGateway) - { - result.zjuLanGateway = line.split(":").at(1).trimmed(); - - if (result.zjuLanGateway.startsWith("10.")) - { - result.isZjuLan = true; - checkInternet(); - return; - } - - result.zjuLanGateway = ""; - } - else if ((line.contains("接口 \"") || line.contains("interface \"")) && (waitForIp || waitForGateway)) - { - waitForIp = false; - waitForGateway = false; - } - } - - checkInternet(); - }); - - process->start("netsh", QStringList() << "interface" << "ipv4" << "show" << "addresses"); -} - -void NetworkDetector::checkInternet() -{ - disconnect(process, &QProcess::finished, this, nullptr); - connect(process, &QProcess::finished, this, [&]() - { - QString output = Utils::ConsoleOutputToQString(process->readAllStandardOutput()); - if (output.contains("(0%") && !output.contains("unreachable") && !output.contains("无法")) - { - result.isInternetAvailable = true; - checkProxy(); - return; - } - - checkProxy(); - }); - - process->start("ping", QStringList() << "223.5.5.5" << "-n" << "1"); -} - -void NetworkDetector::checkProxy() -{ - QSettings proxySettings( - R"(HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings)", - QSettings::NativeFormat - ); - - result.isProxyEnabled = proxySettings.value("ProxyEnable", 0).toInt() == 1; - - emit finished(result); -} diff --git a/networkdetector/networkdetector.h b/networkdetector/networkdetector.h deleted file mode 100644 index adb01f5..0000000 --- a/networkdetector/networkdetector.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef NETWORKDETECTOR_H -#define NETWORKDETECTOR_H - -#include - -struct NetworkDetectResult -{ - bool isDefaultDnsAvailable = false; - bool isZjuNet = false; - bool isZjuDnsCorrect = false; - bool isZjuWlan = false; - bool isZjuWlanSecure = false; - bool isZjuLan = false; - QString zjuLanGateway = ""; - bool isInternetAvailable = false; - bool isProxyEnabled = false; -}; - -class NetworkDetector : public QObject -{ -Q_OBJECT - -public: - NetworkDetector(); - - void start(); - -private: - void checkZjuWlan(); - - void checkZjuLan(); - - void checkInternet(); - - void checkProxy(); - -signals: - - void finished(NetworkDetectResult result); - -private: - QProcess *process; - NetworkDetectResult result; -}; - - -#endif //NETWORKDETECTOR_H diff --git a/settingwindow/settingwindow.cpp b/settingwindow/settingwindow.cpp index 83fe56c..9ee630b 100644 --- a/settingwindow/settingwindow.cpp +++ b/settingwindow/settingwindow.cpp @@ -14,10 +14,6 @@ SettingWindow::SettingWindow(QWidget *parent, QSettings *inputSettings) : this->settings = inputSettings; - setWindowIcon(QIcon(QPixmap(":/resource/icon.png").scaled( - 512, 512, Qt::KeepAspectRatio, Qt::SmoothTransformation - ))); - setWindowFlag(Qt::Window); setWindowModality(Qt::WindowModal); setAttribute(Qt::WA_DeleteOnClose); @@ -111,7 +107,7 @@ SettingWindow::SettingWindow(QWidget *parent, QSettings *inputSettings) : QSettings::NativeFormat ); autoStartSettings.setValue( - "ZjuConnectForWindows", + "HITszConnectForWindows", QCoreApplication::applicationFilePath().replace('/', '\\') ); } @@ -121,17 +117,13 @@ SettingWindow::SettingWindow(QWidget *parent, QSettings *inputSettings) : R"(HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run)", QSettings::NativeFormat ); - autoStartSettings.remove("ZjuConnectForWindows"); + autoStartSettings.remove("HITszConnectForWindows"); } - ui->cancelPushButton->setText("关闭"); - }); - - connect(ui->cancelPushButton, &QPushButton::clicked, - [&]() - { close(); }); + + connect(ui->cancelPushButton, &QPushButton::clicked, [&]() { close(); }); } SettingWindow::~SettingWindow() diff --git a/settingwindow/settingwindow.ui b/settingwindow/settingwindow.ui index 58a068a..1e4156b 100644 --- a/settingwindow/settingwindow.ui +++ b/settingwindow/settingwindow.ui @@ -27,7 +27,7 @@ - 1 + 0 @@ -385,6 +385,13 @@ + + + + 确定 + + + @@ -398,15 +405,30 @@ - - - - 应用 - - - + + usernameLineEdit + passwordLineEdit + autoStartComboBox + connectAfterStartComboBox + tabWidget + applyPushButton + cancelPushButton + serverAddressLineEdit + serverPortSpinBox + socks5PortSpinBox + httpPortSpinBox + reconnectTimeSpinBox + multiLineCheckBox + proxyAllCheckBox + autoReconnectCheckBox + autoSetProxyCheckBox + portForwardingPushButton + debugCheckBox + routeCheckBox + dnsLineEdit + diff --git a/zjuconnectcontroller/zjuconnectcontroller.cpp b/zjuconnectcontroller/zjuconnectcontroller.cpp index 0498d98..9207c90 100644 --- a/zjuconnectcontroller/zjuconnectcontroller.cpp +++ b/zjuconnectcontroller/zjuconnectcontroller.cpp @@ -131,11 +131,6 @@ void ZjuConnectController::start( args.append(udpPortForwarding); } - QString cmd = program; - for (const auto& arg : args) - cmd += " " + arg; - emit outputRead(cmd); - zjuConnectProcess->start(program, args); zjuConnectProcess->waitForStarted(); } diff --git a/zjuconnectmode.cpp b/zjuconnectmode.cpp index cdba177..c8bd6ea 100644 --- a/zjuconnectmode.cpp +++ b/zjuconnectmode.cpp @@ -10,7 +10,6 @@ void MainWindow::setModeToZjuConnect() clearLog(); - networkDetector->start(); ui->tunCheckBox->show(); if (settings->contains("ZJUConnect/TunMode")) @@ -29,8 +28,6 @@ void MainWindow::setModeToZjuConnect() ui->pushButton2->setText("设置系统代理"); ui->pushButton2->hide(); - addLog("工作模式设置为:RVPN"); - // 连接服务器 connect(zjuConnectController, &ZjuConnectController::outputRead, this, [&](const QString &output) { @@ -70,8 +67,8 @@ void MainWindow::setModeToZjuConnect() return; } - addLog("RVPN 断开!"); - showNotification("RVPN", "RVPN 断开!", QSystemTrayIcon::MessageIcon::Warning); + addLog("VPN 断开!"); + showNotification("VPN", "VPN 断开!", QSystemTrayIcon::MessageIcon::Warning); isZjuConnectLinked = false; ui->pushButton1->setText("连接服务器"); @@ -159,7 +156,11 @@ void MainWindow::setModeToZjuConnect() { if (!isSystemProxySet) { - if (networkDetectResult.isProxyEnabled) + QSettings proxySettings( + R"(HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings)", + QSettings::NativeFormat + ); + if (proxySettings.value("ProxyEnable", 0).toInt() == 1) { QMessageBox messageBox(this); messageBox.setWindowTitle("警告");