942 lines
34 KiB
C++
942 lines
34 KiB
C++
#include <iostream>
|
||
#include "widget.h"
|
||
#include "./ui_widget.h"
|
||
|
||
Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget){
|
||
ui->setupUi(this);
|
||
//------------------------------------------------------------------------------------------------
|
||
//COPYFile(WebSubPaths,"");
|
||
Configuration::ReadConfigInit();
|
||
InitUi();
|
||
setAttribute(Qt::WA_TranslucentBackground); //设置窗口背景透明
|
||
setWindowFlags(Qt::FramelessWindowHint | Qt::WindowMinMaxButtonsHint); //去掉窗口边框
|
||
setAreaMovable(ui->widget_3->rect());
|
||
this->setWindowIcon(QIcon(":logo.png"));
|
||
CCString logopath = Configuration::ExePath + "logo.png";
|
||
QIcon trayIconIcon(logopath.c_str()); // 使用你的图标路径
|
||
trayIcon->setIcon(trayIconIcon);
|
||
connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
|
||
connect(showAction, &QAction::triggered, this, &Widget::show);
|
||
trayIconMenu->addAction(showAction);
|
||
trayIconMenu->addAction(quitAction);
|
||
trayIcon->setContextMenu(trayIconMenu);
|
||
trayIcon->show();
|
||
SetPage(0);
|
||
Btns.emplace_back(ui->HomeBtn);
|
||
Btns.emplace_back(ui->SettingsBtn);
|
||
Initlogo();
|
||
//------------------------------------------------------------------------------------------------
|
||
connect(ui->HomeBtn, &QPushButton::clicked, this, &Widget::on_pushButton_clicked);
|
||
connect(ui->SelectSub_IPBtn, &QPushButton::clicked, this, &Widget::ReadSub_IP);
|
||
connect(ui->SettingsBtn, &QPushButton::clicked, this, &Widget::on_pushButton_clicked2);
|
||
connect(ui->CloseBtn, &QPushButton::clicked, this, [this](){this->close();});
|
||
connect(ui->MinBtn, &QPushButton::clicked, this, [this](){this->showMinimized();});
|
||
connect(ui->OpenServerBtn, &QPushButton::clicked, this, &Widget::OpenServerClick);
|
||
connect(ui->RestBtn, &QPushButton::clicked, this, &Widget::ServerConfigInit);
|
||
connect(ui->SetSaveBtn, &QPushButton::clicked, this, &Widget::SetSaveBtn);
|
||
connect(ui->ReadCSInfoBtn, &QPushButton::clicked, this, &Widget::ReadCSInfoFun);
|
||
connect(ui->Web_Port, &QLineEdit::textChanged,this, &Widget::onTextChanged);
|
||
connect(ui->OpenPCStart, &QCheckBox::stateChanged,this, &Widget::slotCheckedChanged);
|
||
connect(ui->RapidDeployment, &QPushButton::clicked, this, &Widget::Deploy);
|
||
if(Configuration::CORSEn == "true"){
|
||
ui->CORSEn->setChecked(true);
|
||
}
|
||
ui->Sub_Origins->setEnabled(ui->CORSEn->isChecked());
|
||
connect(ui->CORSEn, &QCheckBox::stateChanged,this, [this]()
|
||
{
|
||
ui->Sub_Origins->setEnabled(ui->CORSEn->isChecked());
|
||
SetState(ServerFlag);
|
||
});
|
||
connect(ui->GJSZBtn, &QPushButton::clicked,this, [this]()
|
||
{
|
||
auto* window = new widgetYZ(this);
|
||
int w = this->width() / 2 - (window->width() / 2);
|
||
int h = this->height() / 2 - (window->height() / 2);
|
||
window->move(w,h);
|
||
window->show();
|
||
});
|
||
ui->HomeBtn->setFocusPolicy(Qt::NoFocus);
|
||
ui->SettingsBtn->setFocusPolicy(Qt::NoFocus);
|
||
ui->CloseBtn->setFocusPolicy(Qt::NoFocus);
|
||
ui->MinBtn->setFocusPolicy(Qt::NoFocus);
|
||
ui->OpenServerBtn->setFocusPolicy(Qt::NoFocus);
|
||
//------------------------------------------------------------------------------------------------
|
||
ui->ServerConsele->append("Path:" + QApplication::applicationDirPath());
|
||
SetBtn(0);
|
||
Configuration::IPBS_NSSMF(false);
|
||
Configuration::CloseSub_Server();
|
||
Configuration::CloseSub_Web();
|
||
Configuration::IPBS_NSSMF(true);
|
||
CCThread([this](){
|
||
CCString State = Configuration::State;
|
||
CCString CORSEn = Configuration::CORSEn;
|
||
int Op = Configuration::OpenSleep;
|
||
if(Op > 0){
|
||
OpenSleepValue = Op;
|
||
}
|
||
if(State == "Open"){
|
||
while (OpenSleepValue > 0){
|
||
Threading::Sleep(1000 * 1000);
|
||
QMetaObject::invokeMethod(this, [this]() {
|
||
ui->ServerConsele->append(CCString(std::to_string(OpenSleepValue) + "秒后自动启动服务").c_str());
|
||
});
|
||
OpenSleepValue--;
|
||
if(ServerFlag){
|
||
break;
|
||
}
|
||
}
|
||
if(!ServerFlag){
|
||
OpenServerClick();
|
||
OpenFlagBtn(true);
|
||
}
|
||
}
|
||
if(CORSEn == "true"){
|
||
ui->CORSEn->setChecked(true);
|
||
}
|
||
else{
|
||
ui->CORSEn->setChecked(false);
|
||
}
|
||
while (ServerThread.Sign()){
|
||
if(ServerFlag){
|
||
char bus[1024] = {0};
|
||
sprintf(bus,"%d天%d小时%d分%d秒",t,h,f,s);
|
||
s++;
|
||
if(s >= 60){
|
||
f++;
|
||
s = 0;
|
||
if(f >= 60){
|
||
f = 0;
|
||
if(h >= 24){
|
||
t++;
|
||
h = 0;
|
||
}
|
||
h++;
|
||
}
|
||
}
|
||
QMetaObject::invokeMethod(this,[this,bus]()
|
||
{
|
||
QString str = bus;
|
||
ui->RunTime->setText(str);
|
||
});
|
||
}
|
||
QMetaObject::invokeMethod(this, [this](){
|
||
// 获取当前的日期和时间
|
||
QDateTime currentDateTime = QDateTime::currentDateTime();
|
||
// 将日期时间对象转换为字符串格式
|
||
QString currentTime = currentDateTime.toString("yyyy-MM-dd-hh:mm:ss");
|
||
ui->NowTime->setText(currentTime);
|
||
|
||
});
|
||
CCThread::Sleep(1000 * 1000);
|
||
}
|
||
}).detach();
|
||
if(Configuration::FirstRun == 1){
|
||
CCThread([this]()
|
||
{
|
||
PrintMessage("检测到首次运行,正在部署IP-Web分控服务,请耐心等待...");
|
||
CCThread::Sleep(1000 * 1000 * 5);
|
||
Deploy();
|
||
// try{
|
||
// QMetaObject::invokeMethod(this, [this]()
|
||
// {
|
||
// QMessageBox::StandardButton reply = QMessageBox::question(nullptr, "提示",
|
||
// "是否现在开始快速部署IP-Web分控?",QMessageBox::Yes | QMessageBox::No);
|
||
// if (reply == QMessageBox::Yes) {
|
||
// Deploy();
|
||
// } else {
|
||
//
|
||
// }
|
||
// });
|
||
// }
|
||
// catch (...){}
|
||
}).detach();
|
||
}
|
||
ui->OpenPCStart->setCheckState(checkAutoStartEntry("IPBS_Station(Web)") ? Qt::Checked:Qt::Unchecked);
|
||
ServerThread.SetThread(&Widget::ServerListening,this);
|
||
ServerThread.Start();
|
||
OpenSerice(true);
|
||
//------------------------------------------------------------------------------------------------
|
||
}
|
||
|
||
Widget::~Widget(){
|
||
delete ui;
|
||
}
|
||
|
||
void Widget::on_pushButton_clicked() {
|
||
SetBtn(0);
|
||
SetPage(0);
|
||
}
|
||
|
||
void Widget::on_pushButton_clicked2() {
|
||
SetBtn(1);
|
||
SetPage(1);
|
||
}
|
||
|
||
void Widget::WebThreadRun() {
|
||
Configuration::OpenSub_Server();
|
||
while (Configuration::SubRun.IsRunning()){
|
||
CCString Line = Configuration::SubRun.ReadLineBuffer();
|
||
if(!Line.empty()){
|
||
PrintMessage(Line);
|
||
}
|
||
Threading::Sleep(1000 * 50);
|
||
}
|
||
// PrintMessage("Sub Close!");
|
||
}
|
||
|
||
void Widget::closeEvent(QCloseEvent *event) {
|
||
QMessageBox msgBox;
|
||
msgBox.setWindowTitle(tr("退出程序"));
|
||
msgBox.setText(tr("你确定要退出吗?"));
|
||
QPushButton *yesButton = msgBox.addButton(tr("结束程序"), QMessageBox::YesRole);
|
||
msgBox.addButton(tr("到托盘"), QMessageBox::NoRole);
|
||
msgBox.exec();
|
||
if (msgBox.clickedButton() == yesButton)
|
||
{
|
||
Configuration::IPBS_NSSMF(false);
|
||
Configuration::CloseSub_Server();
|
||
Configuration::CloseSub_Web();
|
||
Configuration::State = "Close";
|
||
SetServerConfig();
|
||
ServerThread.Stop();
|
||
WebThread.Stop();
|
||
event->accept();
|
||
QCoreApplication::quit();
|
||
}
|
||
else
|
||
{
|
||
this->hide();
|
||
event->ignore(); // 阻止窗口关闭
|
||
}
|
||
}
|
||
|
||
bool Widget::WebRunFun() {
|
||
if(!ServerFlag){
|
||
if(!WebThread.Sign()){
|
||
ServerFlag = true;
|
||
SetState(ServerFlag);
|
||
CCThread(WebThreadRun,this).detach();
|
||
CCThread([this]()
|
||
{
|
||
Configuration::OpenSub_Web();
|
||
while (Configuration::WebRun.IsRunning()){
|
||
CCString Line = Configuration::WebRun.ReadLineBuffer();
|
||
if(!Line.empty()){
|
||
PrintMessage(Line);
|
||
}
|
||
else{
|
||
break;
|
||
}
|
||
CCThread::Sleep(1000 * 1000);
|
||
}
|
||
PrintMessage("网址: " + Configuration::Web_URL);
|
||
}).detach();
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
void Widget::SetPage(int i) {
|
||
// ui->ServerConsele->append(ServerSttingsPath.c_str());
|
||
ui->stackedWidget->setCurrentIndex(i);
|
||
if(i == 1){
|
||
InitUi();
|
||
}
|
||
}
|
||
|
||
void Widget::SetBtn(int i) {
|
||
for (auto & Btn : Btns) {
|
||
Btn->setStyleSheet("QPushButton{\n"
|
||
"\tborder-radius:10px;\n"
|
||
"\tcolor: rgb(255, 255, 255);\n"
|
||
"\tbackground-color: rgba(255, 255, 255, 0);\n"
|
||
"}\n"
|
||
"\n"
|
||
"QPushButton:hover{\n"
|
||
"\tborder-radius:10px;\n"
|
||
"\tcolor: rgb(255, 255, 255);\n"
|
||
"\tbackground-color: rgba(74,89,146, 255);\n"
|
||
"}");
|
||
}
|
||
Btns[i]->setStyleSheet("QPushButton{\n"
|
||
"\tborder-radius:10px;\n"
|
||
"\tcolor: rgb(255, 255, 255);\n"
|
||
"\tbackground-color: rgba(74,89,146, 255);\n"
|
||
"}\n"
|
||
"\n"
|
||
"QPushButton:hover{\n"
|
||
"\tborder-radius:10px;\n"
|
||
"\tcolor: rgb(255, 255, 255);\n"
|
||
"\tbackground-color: rgba(74,89,146, 255);\n"
|
||
"}");
|
||
}
|
||
|
||
void Widget::OpenServerClick() {
|
||
auto A = CText::ReadConfig(Configuration::CfgPath.c_str());
|
||
if(A.size() >= 8){
|
||
try {
|
||
ServerReRun();
|
||
}
|
||
catch (const std::exception& e) {
|
||
std::cerr << "Error: " << e.what() << std::endl;
|
||
}
|
||
}
|
||
else{
|
||
QMessageBox::information(this,"提示","启动参数错误,请先配置服务器参数!");
|
||
}
|
||
}
|
||
|
||
void Widget::OpenFlagBtn(bool F) {
|
||
if(!F){
|
||
ui->OpenServerBtn->setStyleSheet("QPushButton{\n"
|
||
"\tborder-radius:10px;\n"
|
||
"\tcolor: rgb(255, 255, 255);\n"
|
||
"\tbackground-color: rgba(255,68,138,255);\n"
|
||
"}\n"
|
||
"\n"
|
||
"QPushButton:hover{\n"
|
||
"\tborder-radius:10px;\n"
|
||
"\tcolor: rgb(255, 255, 255);\n"
|
||
"\tbackground-color: rgba(255,100,150, 255);\n"
|
||
"}");
|
||
ui->OpenServerBtn->setText("打开服务");
|
||
}
|
||
else{
|
||
ui->OpenServerBtn->setStyleSheet("QPushButton{\n"
|
||
"\tborder-radius:10px;\n"
|
||
"\tcolor: rgb(255, 255, 255);\n"
|
||
"\tbackground-color: rgba(255,0,0,255);\n"
|
||
"}\n"
|
||
"\n"
|
||
"QPushButton:hover{\n"
|
||
"\tborder-radius:10px;\n"
|
||
"\tcolor: rgb(255, 255, 255);\n"
|
||
"\tbackground-color: rgba(255,100,150, 255);\n"
|
||
"}");
|
||
ui->OpenServerBtn->setText("关闭服务");
|
||
}
|
||
}
|
||
|
||
void Widget::ServerListening() {
|
||
bool F = false,S = false;
|
||
while (ServerThread.Sign()){
|
||
Threading::Sleep(1000 * 1000 * 5);
|
||
try {
|
||
F = Configuration::GetSub_Status();
|
||
S = Configuration::GetSub_Web_Status();
|
||
QMetaObject::invokeMethod(this,[this,F,S]()
|
||
{
|
||
SetSuBState(F);
|
||
SetWebState(S);
|
||
});
|
||
if(!F && ServerFlag){
|
||
QMetaObject::invokeMethod(this, [this,&F](){
|
||
if(!F){
|
||
Configuration::OpenSub_Server();
|
||
PrintMessage("Sub Res Start OK!");
|
||
}
|
||
Threading::Sleep(1000 * 1000 * 5);
|
||
});
|
||
}
|
||
if(!S && ServerFlag){
|
||
try{
|
||
if(!S){
|
||
Configuration::OpenSub_Web();
|
||
PrintMessage("Web Res Start OK!");
|
||
PrintMessage("网址: " + Configuration::Web_URL);
|
||
}
|
||
Threading::Sleep(1000 * 1000 * 5);
|
||
}
|
||
catch (const std::exception& e) {
|
||
std::cerr << "Error: " << e.what() << std::endl;
|
||
}
|
||
}
|
||
}
|
||
catch (const std::exception& e) {
|
||
std::cerr << "Error: " << e.what() << std::endl;
|
||
}
|
||
}
|
||
}
|
||
|
||
bool Widget::isJarRunning(const char *jarName) {
|
||
#ifdef _WIN32
|
||
CCString str = jarName;
|
||
str.append(".exe");
|
||
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||
if (hSnapshot == INVALID_HANDLE_VALUE) {
|
||
return false;
|
||
}
|
||
PROCESSENTRY32 pe32;
|
||
pe32.dwSize = sizeof(PROCESSENTRY32);
|
||
if (Process32First(hSnapshot, &pe32)) {
|
||
do {
|
||
if (_tcsstr(pe32.szExeFile, str.c_str()) != nullptr) {
|
||
CloseHandle(hSnapshot);
|
||
return true;
|
||
}
|
||
} while (Process32Next(hSnapshot, &pe32));
|
||
}
|
||
|
||
CloseHandle(hSnapshot);
|
||
return false;
|
||
#elif __linux__
|
||
#endif
|
||
}
|
||
|
||
bool Widget::terminateProcessByName(const char *processName) {
|
||
#ifdef _WIN32
|
||
CCString str = processName;
|
||
str.append(".exe");
|
||
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||
if (hSnapshot == INVALID_HANDLE_VALUE) {
|
||
return false;
|
||
}
|
||
PROCESSENTRY32 pe32;
|
||
pe32.dwSize = sizeof(PROCESSENTRY32);
|
||
if (Process32First(hSnapshot, &pe32)) {
|
||
do {
|
||
if (_tcscmp(pe32.szExeFile, str.c_str()) == 0) {
|
||
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pe32.th32ProcessID);
|
||
if (hProcess != NULL) {
|
||
TerminateProcess(hProcess, 0);
|
||
CloseHandle(hProcess);
|
||
}
|
||
}
|
||
} while (Process32Next(hSnapshot, &pe32));
|
||
}
|
||
CloseHandle(hSnapshot);
|
||
return true;
|
||
#elif __linux__
|
||
|
||
#endif
|
||
}
|
||
|
||
void Widget::ServerReRun() {
|
||
if(ServerFlag){
|
||
try {
|
||
Configuration::CloseSub_Server();
|
||
Configuration::CloseSub_Web();
|
||
if(ServerFlag){
|
||
WebThread.Stop();
|
||
PrintMessage("Server Close");
|
||
OpenFlagBtn(false);
|
||
ServerFlag = false;
|
||
SetState(ServerFlag);
|
||
ui->RunTime->setVisible(false);
|
||
t = 0;h = 0;f = 0;s = 0;
|
||
}
|
||
}
|
||
catch (const std::exception& e) {
|
||
std::cerr << "Error: " << e.what() << std::endl;
|
||
}
|
||
}
|
||
else{
|
||
WebRunFun();
|
||
OpenFlagBtn(true);
|
||
t = 0;h = 0;f = 0;s = 0;
|
||
ui->RunTime->setVisible(true);
|
||
}
|
||
}
|
||
|
||
void Widget::onCurrentIndexChanged(int index) {
|
||
ui->Web_IP->setText(ui->Sub_IP->text());
|
||
CCString URL = ui->Sub_IP->text().toStdString()+":"+ui->Web_Port->text().toStdString();
|
||
Configuration::Web_URL = "http://" + URL + '/';
|
||
QString str = CCString("['http://" + ui->Sub_IP->text().toStdString() + ":" + Configuration::Web_Port + "']").c_str();
|
||
ui->Sub_Origins->setText(str);
|
||
}
|
||
|
||
void Widget::onCurrentIndexChangedCSIP(int index)
|
||
{
|
||
try
|
||
{
|
||
if(CSPortList.empty())
|
||
{
|
||
return;
|
||
}
|
||
CCVar str = CCInt(CSPortList[index]).to_String().c_str();
|
||
ui->CS_Port->setText(str);
|
||
}
|
||
catch (CCException& exception){}
|
||
}
|
||
|
||
void Widget::SetSuBState(bool F) {
|
||
if(F){
|
||
ui->SubLabel->setStyleSheet("color: rgb(0, 255, 0);");
|
||
ui->SubLabel->setText("后端:在线");
|
||
}
|
||
else{
|
||
ui->SubLabel->setStyleSheet("color: rgb(255, 0, 0);");
|
||
ui->SubLabel->setText("后端:离线");
|
||
}
|
||
}
|
||
|
||
void Widget::SetWebState(bool F) {
|
||
if(F){
|
||
ui->WebLabel->setStyleSheet("color: rgb(0, 255, 0);");
|
||
ui->WebLabel->setText("前端:在线");
|
||
}
|
||
else{
|
||
ui->WebLabel->setStyleSheet("color: rgb(255, 0, 0);");
|
||
ui->WebLabel->setText("前端:离线");
|
||
}
|
||
}
|
||
|
||
void Widget::onTextChanged(const QString &text) {
|
||
ui->Web_IP->setText(ui->Sub_IP->text());
|
||
CCString URL = ui->Sub_IP->text().toStdString()+":"+ui->Web_Port->text().toStdString();
|
||
Configuration::Web_URL = "http://" + URL + '/';
|
||
QString str = CCString("['http://" + ui->Web_IP->text().toStdString() + ":" + text.toStdString() + "']").c_str();
|
||
ui->Sub_Origins->setText(str);
|
||
}
|
||
|
||
void Widget::SetSaveBtn() {
|
||
if(ui->CS_IP->text().isEmpty()){
|
||
QMessageBox::information(this, "Error", "C/S_IP不能为空");
|
||
return;
|
||
}
|
||
if(ui->CS_Port->text().isEmpty()){
|
||
QMessageBox::information(this, "Error", "C/S_Port不能为空");
|
||
return;
|
||
}
|
||
if(ui->Sub_IP->text().isEmpty()){
|
||
QMessageBox::information(this, "Error", "Sub_IP不能为空");
|
||
return;
|
||
}
|
||
if(ui->Sub_Port->text().isEmpty()){
|
||
QMessageBox::information(this, "Error", "Sub_Port不能为空");
|
||
return;
|
||
}
|
||
if(ui->Web_Port->text().isEmpty()){
|
||
QMessageBox::information(this, "Error", "Web_Port不能为空");
|
||
return;
|
||
}
|
||
if(ui->Web_IP->text().isEmpty()){
|
||
QMessageBox::information(this, "Error", "Web_IP不能为空");
|
||
return;
|
||
}
|
||
if(ui->Sub_Audio_Port->text().isEmpty()){
|
||
QMessageBox::information(this, "Error", "Sub_Audio_Port不能为空");
|
||
return;
|
||
}
|
||
if(ui->Sub_Origins->text().isEmpty()){
|
||
QMessageBox::information(this, "Error", "Sub_Origins不能为空");
|
||
return;
|
||
}
|
||
SetServerConfig();
|
||
QMessageBox::StandardButton reply = QMessageBox::question(this, "提示", "保存成功是否现在启动?",
|
||
QMessageBox::Yes | QMessageBox::No);
|
||
if (reply == QMessageBox::Yes) {
|
||
// 用户点击了“是”按钮
|
||
try {
|
||
Configuration::CloseSub_Server();
|
||
Configuration::CloseSub_Web();
|
||
if(ServerFlag){
|
||
WebThread.Stop();
|
||
ui->ServerConsele->append("Server Close");
|
||
OpenFlagBtn(false);
|
||
ServerFlag = false;
|
||
SetState(ServerFlag);
|
||
ui->RunTime->setVisible(false);
|
||
t = 0;h = 0;f = 0;s = 0;
|
||
}
|
||
}
|
||
catch (const std::exception& e) {
|
||
std::cerr << "Error: " << e.what() << std::endl;
|
||
}
|
||
OpenServerClick();
|
||
} else {
|
||
// 用户点击了“否”按钮
|
||
}
|
||
}
|
||
|
||
void Widget::ServerConfigInit() {
|
||
Configuration::CfgInit();
|
||
SetPage(1);
|
||
QMessageBox::information(this, "提示", "初始化已完成!");
|
||
}
|
||
|
||
void Widget::Initlogo() {
|
||
CCString str = Configuration::ExePath + Sub_Logo;
|
||
QPixmap pixmap(str.c_str()); // 替换为你的图片路径
|
||
ui->logoIMG->setPixmap(pixmap);
|
||
ui->logoIMG->setScaledContents(true); // 图片自动缩放以适应 QLabel 大小
|
||
ui->logoIMG->setMaximumSize(111,61); // 设置 QLabel 最小尺寸
|
||
ui->logoIMG->setMaximumSize(320,180); // 设置 QLabel 最小尺寸
|
||
ImGLoad = ui->logoIMG;
|
||
}
|
||
|
||
void Widget::SetServerConfig() {
|
||
// FILE *fp = fopen(Configuration::CfgPath.c_str(), "w");
|
||
// if (fp == nullptr) {
|
||
// QMessageBox::information(this, "Error", "Failed to open ServerSttings file");
|
||
// return;
|
||
// }
|
||
// // 写入配置数据
|
||
// fprintf(fp, "C/S_IP:%s\n",ui->CS_IP->text().toStdString().c_str());
|
||
// fprintf(fp, "C/S_PORT:%s\n",ui->CS_Port->text().toStdString().c_str());
|
||
// fprintf(fp, "Sub_Control_IP:%s\n",ui->Sub_IP->text().toStdString().c_str());
|
||
// fprintf(fp, "Sub_Control_PORT:%s\n",ui->Sub_Port->text().toStdString().c_str());
|
||
// fprintf(fp, "Sub_Control_Audio_PORT:%s\n",ui->Sub_Audio_Port->text().toStdString().c_str());
|
||
// fprintf(fp, "Sub_Web_PORT:%s\n",ui->Web_Port->text().toStdString().c_str());
|
||
// fprintf(fp, "Origins:%s\n",ui->Sub_Origins->text().toStdString().c_str());
|
||
// fprintf(fp, "#中文简体,English\n");
|
||
// fprintf(fp, "Language:%s\n",ui->LabguageBox->currentText().toStdString().c_str());
|
||
// fprintf(fp, "OpenSleep:%d\n",ui->OpenSleep->value());
|
||
// fprintf(fp, "State:%s\n",Configuration::State.c_str());
|
||
// fprintf(fp, "CORSEn:%s\n",Configuration::CORSEn.c_str());
|
||
// fprintf(fp, "FirstRun:%d\n",0);
|
||
// fclose(fp);
|
||
// fp = fopen(Configuration::WebCfgPath.c_str(), "w");
|
||
// if (fp == nullptr) {
|
||
// QMessageBox::information(this, "Error", "Failed to open NginxSttings file");
|
||
// return;
|
||
// }
|
||
// // 写入配置数据
|
||
// fprintf(fp, "worker_processes 1;\n"
|
||
// "events {\n"
|
||
// " worker_connections 1024;\n"
|
||
// "}\n"
|
||
// "http {\n"
|
||
// " include mime.types;\n"
|
||
// " default_type application/octet-stream;\n"
|
||
// " sendfile on;\n"
|
||
// " keepalive_timeout 65;\n"
|
||
// " client_max_body_size 500m;\n"
|
||
// " server {\n"
|
||
// " listen %s;\n"
|
||
// " server_name %s;\n"
|
||
// " location / {\n"
|
||
// " root html;\n"
|
||
// " index index.html index.htm;\n"
|
||
// " try_files $uri $uri/ /index.html;\n"
|
||
// " # try_files $uri $uri/ @router;\n"
|
||
// " }\n"
|
||
// " location /api/ {\n"
|
||
// " #rewrite ^.+api/?(.*)$ /$1 break; \n"
|
||
// " rewrite ^/api/(.*)$ /$1 break; \n"
|
||
// " proxy_pass http://%s:%s/;\n"
|
||
// " proxy_redirect off;\n"
|
||
// " proxy_set_header Host $host;\n"
|
||
// " proxy_set_header X-Real-IP $remote_addr;\n"
|
||
// " proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n"
|
||
// " }\n"
|
||
// " error_page 500 502 503 504 /50x.html;\n"
|
||
// " location = /50x.html {\n"
|
||
// " root html;\n"
|
||
// " }\n"
|
||
// " }\n"
|
||
// "}",ui->Web_Port->text().toStdString().c_str(),ui->Web_IP->text().toStdString().c_str(),
|
||
// ui->Sub_IP->text().toStdString().c_str(),ui->Sub_Port->text().toStdString().c_str());
|
||
// fclose(fp);
|
||
Configuration::CS_IP = ui->CS_IP->text().toStdString();
|
||
Configuration::CS_Port = ui->CS_Port->text().toStdString();
|
||
Configuration::Sub_IP = ui->Sub_IP->text().toStdString();
|
||
Configuration::Sub_Port = ui->Sub_Port->text().toStdString();
|
||
Configuration::Sub_Audio_Port = ui->Sub_Audio_Port->text().toStdString();
|
||
Configuration::Web_IP = ui->Web_IP->text().toStdString();
|
||
Configuration::Web_Port = ui->Web_Port->text().toStdString();
|
||
Configuration::Sub_Org = ui->Sub_Origins->text().toStdString();
|
||
Configuration::Language = ui->LabguageBox->currentText().toStdString();
|
||
Configuration::OpenSleep = ui->OpenSleep->value();
|
||
Configuration::SaveJarCfg();
|
||
Configuration::SaveWebCfg();
|
||
Configuration::ReadConfigInit();
|
||
}
|
||
|
||
void Widget::SetState(bool F) {
|
||
Configuration::State = F ? "Open" : "Close";
|
||
Configuration::CORSEn = ui->CORSEn->isChecked() ? "true" : "false";
|
||
SetServerConfig();
|
||
}
|
||
|
||
void Widget::SetAutoStart(const QString &path, bool enable) {
|
||
QSettings startupSettings("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows", QSettings::NativeFormat);
|
||
if (enable) {
|
||
startupSettings.setValue("IPBS_Station(Web)", path);
|
||
} else {
|
||
startupSettings.remove("IPBS_Station(Web)");
|
||
}
|
||
}
|
||
|
||
void Widget::OpenSerice(bool F) {
|
||
#ifdef _WIN32
|
||
|
||
#elif __linux__
|
||
|
||
#endif
|
||
}
|
||
|
||
void Widget::slotCheckedChanged(int i) {
|
||
CCString str = "IPBS_Start";
|
||
if(ui->OpenPCStart->isChecked()){
|
||
SetAutoStart(str.c_str(),true);
|
||
} else{
|
||
SetAutoStart(str.c_str(),false);
|
||
}
|
||
str = Configuration::ExePath + QApplication::applicationName().toStdString() + ".exe.lnk";
|
||
if(ui->OpenPCStart->isChecked()){
|
||
CreateShortO();
|
||
CCString A = OpenKit + QApplication::applicationName().toStdString() + ".exe.lnk";
|
||
CCFile file = CCFile(str.c_str(), CC::ios::w,false);
|
||
file.Copy(A);
|
||
file.Deleted();
|
||
}
|
||
else{
|
||
str = OpenKit + QApplication::applicationName().toStdString() + ".exe.lnk";
|
||
CCFile file = CCFile(str.c_str(), CC::ios::w,false);
|
||
file.Deleted();
|
||
}
|
||
}
|
||
|
||
void Widget::ReadCSInfoFun(){
|
||
CCVar* cs4 = new CSInfoW4(this);
|
||
int w = this->width() / 2 - (cs4->width() / 2);
|
||
int h = this->height() / 2 - (cs4->height() / 2);
|
||
cs4->move(w,h);
|
||
cs4->IPEdit1 = ui->CS_IP;
|
||
cs4->IPEdit2 = ui->CS_Port;
|
||
cs4->exec();
|
||
}
|
||
|
||
void Widget::PrintMessage(CCString str)
|
||
{
|
||
QMetaObject::invokeMethod(this,[this,str]()
|
||
{
|
||
CCTimeData time;
|
||
CCString S = "[" + time.to_String() + "] -> " + str;
|
||
ui->ServerConsele->append(S.c_str());
|
||
});
|
||
}
|
||
|
||
void Widget::ReadSub_IP(){
|
||
CCVar* sub = new Sub_IPUI(this);
|
||
int w = this->width() / 2 - (sub->width() / 2);
|
||
int h = this->height() / 2 - (sub->height() / 2);
|
||
sub->move(w,h);
|
||
sub->IPEdit = ui->Sub_IP;
|
||
sub->show();
|
||
}
|
||
|
||
void Widget::Deploy(){
|
||
boolean F1 = false,F2 = false;
|
||
PrintMessage("正在配置IP-Web分控IP地址...");
|
||
while (true){
|
||
CCThread::Sleep(1000 * 500);
|
||
Configuration::ReadSub_IP();
|
||
if(!Configuration::SubIPList.empty()){
|
||
if(Configuration::SubIPList.size() > 1){
|
||
PrintMessage("检测到多个IP地址,请选择要使用的IP地址!");
|
||
CCVar* sub = new Sub_IPUI(this);
|
||
int w = this->width() / 2 - (sub->width() / 2);
|
||
int h = this->height() / 2 - (sub->height() / 2);
|
||
sub->move(w,h);
|
||
sub->IPEdit = ui->Sub_IP;
|
||
sub->exec();
|
||
PrintMessage("Web分控IP地址配置完成!");
|
||
}
|
||
else{
|
||
Configuration::Sub_IP = Configuration::SubIPList[0];
|
||
PrintMessage("Web分控IP地址配置完成!");
|
||
}
|
||
F2 = true;
|
||
break;
|
||
}
|
||
else{
|
||
bool A1 = false;
|
||
QMetaObject::invokeMethod(this,[this,&F2,&A1]()
|
||
{
|
||
QMessageBox::StandardButton reply = QMessageBox::question(nullptr, "提示",
|
||
"未检测到合法IPV4地址,请检查网络,是否继续检测?",
|
||
QMessageBox::Yes | QMessageBox::No);
|
||
if (reply == QMessageBox::Yes) {
|
||
A1 = true;
|
||
} else {
|
||
Configuration::Sub_IP = "";
|
||
F2 = false;
|
||
PrintMessage("Web分控IP地址配置跳过!");
|
||
}
|
||
});
|
||
if(A1){
|
||
continue;
|
||
}
|
||
else{
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
PrintMessage("正在配置C/S服务器参数...");
|
||
while (true){
|
||
PrintMessage("尝试搜索C/S服务器中...");
|
||
CCThread::Sleep(1000 * 500);
|
||
Configuration::ReadCSInfo();
|
||
if(!Configuration::CSIPList.empty()){
|
||
if(Configuration::CSIPList.size() > 1){
|
||
PrintMessage("在局域网检测到多个C/S服务器,请选择需要使用的C/S服务器!");
|
||
CCVar* cs4 = new CSInfoW4(this);
|
||
int w = this->width() / 2 - (cs4->width() / 2);
|
||
int h = this->height() / 2 - (cs4->height() / 2);
|
||
cs4->move(w,h);
|
||
cs4->IPEdit1 = ui->CS_IP;
|
||
cs4->IPEdit2 = ui->CS_Port;
|
||
cs4->exec();
|
||
PrintMessage("C/S服务器信息配置完成");
|
||
}
|
||
else{
|
||
Configuration::CS_IP = Configuration::CSIPList[0];
|
||
Configuration::CS_Port = Configuration::CSPortList[0].to_String();
|
||
PrintMessage("C/S服务器信息配置完成");
|
||
}
|
||
F1 = true;
|
||
break;
|
||
}
|
||
else{
|
||
bool A1 = false;
|
||
Configuration::CS_IP = "";
|
||
Configuration::CS_Port = "";
|
||
QMetaObject::invokeMethod(this,[this,&F1,&A1]()
|
||
{
|
||
QMessageBox::StandardButton reply = QMessageBox::question(nullptr, "提示",
|
||
"在局域网未检测到可用的C/S服务器,请先启动C/S服务器,是否继续检测?",
|
||
QMessageBox::Yes | QMessageBox::No);
|
||
if (reply == QMessageBox::Yes) {
|
||
A1 = true;
|
||
}
|
||
else {
|
||
Configuration::CS_IP = "";
|
||
Configuration::CS_Port = "";
|
||
F1 = false;
|
||
PrintMessage("C/S服务器信息配置跳过!");
|
||
A1 = false;
|
||
}
|
||
});
|
||
if(A1){
|
||
continue;
|
||
}
|
||
else{
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
PrintMessage("正在分配IP-Web分控服务端口...");
|
||
CCVar Ports = Configuration::getAvailablePorts(3,5417);
|
||
Configuration::Sub_Port = Ports[0].to_String();
|
||
Configuration::Sub_Audio_Port = Ports[1].to_String();
|
||
Configuration::Web_Port = Ports[2].to_String();
|
||
Configuration::Web_IP = Configuration::Sub_IP;
|
||
PrintMessage("IP-Web分控服务端口分配完成!");
|
||
PrintMessage("IP-Web分控服务正在设置跨域...");
|
||
Configuration::Sub_Org = "['http://" + Configuration::Web_IP + ":" + Configuration::Web_Port + "']";
|
||
PrintMessage("IP-Web分控服务跨域设置完成!");
|
||
ui->CS_IP->setText(Configuration::CS_IP.c_str());
|
||
ui->CS_Port->setText(Configuration::CS_Port.c_str());
|
||
ui->Sub_IP->setText(Configuration::Sub_IP.c_str());
|
||
ui->Sub_Port->setText(Configuration::Sub_Port.c_str());
|
||
ui->Sub_Audio_Port->setText(Configuration::Sub_Audio_Port.c_str());
|
||
ui->Sub_Origins->setText(Configuration::Sub_Org.c_str());
|
||
if(Configuration::Language == "English"){
|
||
ui->LabguageBox->setCurrentIndex(1);
|
||
}
|
||
else{
|
||
ui->LabguageBox->setCurrentIndex(0);
|
||
}
|
||
ui->Web_Port->setText(Configuration::Web_Port.c_str());
|
||
ui->Web_IP->setText(ui->Sub_IP->text());
|
||
ui->OpenSleep->setValue(Configuration::OpenSleep);
|
||
PrintMessage("IP-Web分控服务部署设置已完成!");
|
||
PrintMessage("正在保存IP-Web分控服务设置...");
|
||
SetServerConfig();
|
||
PrintMessage("IP-Web分控服务设置保存完成");
|
||
if(F1 && F2){
|
||
try {
|
||
terminateProcessByName("java");
|
||
terminateProcessByName("nginx");
|
||
if(ServerFlag){
|
||
WebThread.Stop();
|
||
ui->ServerConsele->append("Server Close");
|
||
OpenFlagBtn(false);
|
||
ServerFlag = false;
|
||
SetState(ServerFlag);
|
||
ui->RunTime->setVisible(false);
|
||
t = 0;h = 0;f = 0;s = 0;
|
||
}
|
||
}
|
||
catch (const std::exception& e) {
|
||
std::cerr << "Error: " << e.what() << std::endl;
|
||
}
|
||
if(ui->CS_IP->text().isEmpty()){
|
||
QMessageBox::information(this, "Error", "C/S_IP不能为空");
|
||
return;
|
||
}
|
||
if(ui->CS_Port->text().isEmpty()){
|
||
QMessageBox::information(this, "Error", "C/S_Port不能为空");
|
||
return;
|
||
}
|
||
if(ui->Sub_IP->text().isEmpty()){
|
||
QMessageBox::information(this, "Error", "Sub_IP不能为空");
|
||
return;
|
||
}
|
||
if(ui->Sub_Port->text().isEmpty()){
|
||
QMessageBox::information(this, "Error", "Sub_Port不能为空");
|
||
return;
|
||
}
|
||
if(ui->Web_Port->text().isEmpty()){
|
||
QMessageBox::information(this, "Error", "Web_Port不能为空");
|
||
return;
|
||
}
|
||
if(ui->Web_IP->text().isEmpty()){
|
||
QMessageBox::information(this, "Error", "Web_IP不能为空");
|
||
return;
|
||
}
|
||
if(ui->Sub_Audio_Port->text().isEmpty()){
|
||
QMessageBox::information(this, "Error", "Sub_Audio_Port不能为空");
|
||
return;
|
||
}
|
||
if(ui->Sub_Origins->text().isEmpty()){
|
||
QMessageBox::information(this, "Error", "Sub_Origins不能为空");
|
||
return;
|
||
}
|
||
PrintMessage("正在启动IP-Web分控服务...");
|
||
OpenServerClick();
|
||
}
|
||
else{
|
||
QMetaObject::invokeMethod(this,[this,F1,F2]()
|
||
{
|
||
if(!F1){
|
||
PrintMessage("在局域网未检测到C/S服务器,请检查C/S服务器!");
|
||
}
|
||
if(!F2){
|
||
PrintMessage("未检测到合法IPV4地址,请检查网络!");
|
||
}
|
||
PrintMessage("部署未完成!");
|
||
});
|
||
}
|
||
}
|
||
|
||
void Widget::InitUi(){
|
||
ui->CS_IP->setText(Configuration::CS_IP.c_str());
|
||
ui->CS_Port->setText(Configuration::CS_Port.c_str());
|
||
ui->Sub_IP->setText(Configuration::Sub_IP.c_str());
|
||
ui->Sub_Port->setText(Configuration::Sub_Port.c_str());
|
||
ui->Sub_Audio_Port->setText(Configuration::Sub_Audio_Port.c_str());
|
||
ui->Sub_Origins->setText(Configuration::Sub_Org.c_str());
|
||
if(Configuration::Language == "English"){
|
||
ui->LabguageBox->setCurrentIndex(1);
|
||
}
|
||
else{
|
||
ui->LabguageBox->setCurrentIndex(0);
|
||
}
|
||
ui->Web_Port->setText(Configuration::Web_Port.c_str());
|
||
ui->Web_IP->setText(ui->Sub_IP->text());
|
||
ui->OpenSleep->setValue(Configuration::OpenSleep);
|
||
}
|
||
|
||
bool Widget::checkAutoStartEntry(const QString &appName) {
|
||
QSettings startupSettings("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows", QSettings::NativeFormat);
|
||
return startupSettings.contains(appName);
|
||
}
|
||
|
||
|
||
|
||
|