From 9c2b1928bfaf66eed97a32a0a32784d002478330 Mon Sep 17 00:00:00 2001 From: xxzl0130 Date: Fri, 29 Oct 2021 22:18:57 +0800 Subject: [PATCH] fix network --- ChipDataWindow/GetChipWindow.cpp | 38 ++++++++++++++++++-------------- ChipDataWindow/GetChipWindow.h | 2 +- CodeX/AboutDialog.cpp | 2 +- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/ChipDataWindow/GetChipWindow.cpp b/ChipDataWindow/GetChipWindow.cpp index 13d86aa..f0f69ab 100644 --- a/ChipDataWindow/GetChipWindow.cpp +++ b/ChipDataWindow/GetChipWindow.cpp @@ -2,10 +2,11 @@ #include "GetChipWindow.h" #include "ui_GetChipWindow.h" #include +#include constexpr auto pacUrl = "http://static.xuanxuan.tech/GF/GF.pac"; constexpr auto serverHost = "https://codex.xuanxuan.tech:8080/"; -static QString localHost = "http://127.0.0.1:8080"; +static QString localHost = "http://127.0.0.1:8080/"; constexpr auto jsonPath = "chipJson"; #ifdef Q_OS_WIN constexpr auto exeName = "GF_Tool_Server.exe"; @@ -190,25 +191,28 @@ void GetChipWindow::processError(QProcess::ProcessError error) void GetChipWindow::processDataReady() { - auto data = QString::fromUtf8(process_->readAllStandardOutput()); - // 解析本地地址 - if(data.indexOf(u8"代理地址") != -1) + while (process_->canReadLine()) { - auto lines = data.split("\n"); - auto proxyList = lines[0].split(" ")[2].split(":"); - this->localProxyAddr_ = proxyList[0]; - this->localProxyPort_ = proxyList[1]; - if(lines.size() > 1) + auto data = QString::fromUtf8(process_->readLine().trimmed()); + if(data.startsWith(u8"代理地址")) { - auto webList = lines[1].split(" "); - if(webList.size() > 2) - { - localHost = webList[2]; - request_->setUrl(QUrl(QString(localHost) + localWebPort_ + "/" + jsonPath)); - } + auto proxyList = data.split(" ")[2].split(":"); + this->localProxyAddr_ = proxyList[0]; + this->localProxyPort_ = proxyList[1]; + setLocalProxy(); + QMessageBox::information(this, trUtf8(u8"成功"), trUtf8(u8"本地代理程序启动成功!")); + } + else if(data.startsWith(u8"网页地址")) + { + auto webList = data.split(" "); + localHost = QString("http://127.0.0.1:%1/").arg(webList[2].split(":")[1]); + request_->setUrl(QUrl(localHost + jsonPath)); + } + else if(data.contains(u8"失败")) + { + QMessageBox::warning(this, u8"失败", data); + return; } - setLocalProxy(); - QMessageBox::information(this, trUtf8(u8"成功"), trUtf8(u8"本地代理程序启动成功!")); } } diff --git a/ChipDataWindow/GetChipWindow.h b/ChipDataWindow/GetChipWindow.h index ccb0fcd..3d34a55 100644 --- a/ChipDataWindow/GetChipWindow.h +++ b/ChipDataWindow/GetChipWindow.h @@ -55,5 +55,5 @@ protected slots: QNetworkRequest* request_; QNetworkAccessManager* accessManager_; QProcess* process_; - QString localProxyAddr_, localProxyPort_, localWebPort_; + QString localProxyAddr_, localProxyPort_; }; diff --git a/CodeX/AboutDialog.cpp b/CodeX/AboutDialog.cpp index 2a5e56c..c16b75c 100644 --- a/CodeX/AboutDialog.cpp +++ b/CodeX/AboutDialog.cpp @@ -4,7 +4,7 @@ AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent), - version(2,3,2), + version(2,3,3), ui(new Ui::AboutDialog()), accessManager_(new QNetworkAccessManager(this)) {