2024-08-13 17:07:34 +08:00
|
|
|
|
#ifndef WIDGET_H
|
|
|
|
|
|
#define WIDGET_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <QWidget>
|
|
|
|
|
|
#include "CCSocket.h"
|
|
|
|
|
|
#include "CCThread.h"
|
|
|
|
|
|
#include "nlohmann/json.hpp"
|
|
|
|
|
|
#include "QMessageBox"
|
|
|
|
|
|
#include "ctime"
|
|
|
|
|
|
#include <QCloseEvent>
|
|
|
|
|
|
#include <QPaintEvent>
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
#include <QMetaMethod>
|
|
|
|
|
|
#include <QSystemTrayIcon>
|
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
|
#include <QProcess>
|
|
|
|
|
|
#include "QDateTime"
|
|
|
|
|
|
#include "QCoreApplication"
|
|
|
|
|
|
#include "CCString.h"
|
|
|
|
|
|
#include "QFile"
|
|
|
|
|
|
#include "CCFile.h"
|
|
|
|
|
|
#include "vector"
|
|
|
|
|
|
#include "Tools/CText.h"
|
|
|
|
|
|
#include <QAbstractSocket>
|
|
|
|
|
|
#include <QHostAddress>
|
|
|
|
|
|
#include <QNetworkInterface>
|
|
|
|
|
|
#include <QFileDialog>
|
2024-08-22 17:26:05 +08:00
|
|
|
|
#include <QSettings>
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
|
#include <filesystem>
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
#include <QDir>
|
|
|
|
|
|
#include <QDesktopServices>
|
|
|
|
|
|
#include <QShortcut>
|
2024-11-01 16:09:31 +08:00
|
|
|
|
#include "CCSocket.h"
|
|
|
|
|
|
#include "vector"
|
|
|
|
|
|
#include "CCTimeData.h"
|
|
|
|
|
|
#include "widgetyz.h"
|
|
|
|
|
|
#include "csinfow4.h"
|
|
|
|
|
|
#include "W5/sub_ipui.h"
|
2024-08-13 17:07:34 +08:00
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
#include <tchar.h>
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
#include <tlhelp32.h>
|
2024-08-22 17:26:05 +08:00
|
|
|
|
#include <shlobj.h> // 包含 ShellLink 和 IPersistFile 接口
|
2024-08-13 17:07:34 +08:00
|
|
|
|
#elif __linux__
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
namespace Ui { class Widget; }
|
|
|
|
|
|
QT_END_NAMESPACE
|
2024-08-22 17:26:05 +08:00
|
|
|
|
namespace fs = std::filesystem;
|
2024-08-13 17:07:34 +08:00
|
|
|
|
class Widget : public QWidget
|
|
|
|
|
|
{
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
private:
|
|
|
|
|
|
CCThread WebThread, ServerThread;
|
2024-11-01 16:09:31 +08:00
|
|
|
|
std::vector<int> CSPortList;
|
2024-08-13 17:07:34 +08:00
|
|
|
|
#ifdef _WIN32
|
2024-08-22 17:26:05 +08:00
|
|
|
|
const CCString OpenKit = "C:/ProgramData/Microsoft/Windows/Start Menu/Programs/StartUp/";
|
2024-08-13 17:07:34 +08:00
|
|
|
|
#elif __linux__
|
2024-11-01 16:09:31 +08:00
|
|
|
|
|
2024-08-13 17:07:34 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
QRect m_areaMovable;//可移动窗口的区域,鼠标只有在该区域按下才能移动窗口
|
2024-08-22 17:26:05 +08:00
|
|
|
|
bool m_bPressed,closeflag = false;//鼠标按下标志(不分左右键)
|
2024-08-13 17:07:34 +08:00
|
|
|
|
QPoint m_ptPress;//鼠标按下的初始位置
|
2024-08-22 17:26:05 +08:00
|
|
|
|
QProcess* NginxP;
|
2024-08-13 17:07:34 +08:00
|
|
|
|
QSystemTrayIcon *trayIcon = new QSystemTrayIcon(this);
|
|
|
|
|
|
QMenu *trayIconMenu = new QMenu(this);
|
|
|
|
|
|
QAction *quitAction = new QAction(tr("&退出"), this);
|
|
|
|
|
|
QAction *showAction = new QAction(tr("&显示"), this);
|
|
|
|
|
|
int t = 0,h = 0,f = 0,s = 0;
|
2024-08-22 17:26:05 +08:00
|
|
|
|
int OpenSleepValue = 10;
|
2024-08-13 17:07:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
Widget(QWidget *parent = nullptr);
|
|
|
|
|
|
~Widget();
|
|
|
|
|
|
void on_pushButton_clicked();
|
|
|
|
|
|
void on_pushButton_clicked2();
|
|
|
|
|
|
void WebThreadRun();
|
|
|
|
|
|
bool WebRunFun();
|
|
|
|
|
|
void ServerListening();
|
|
|
|
|
|
void OpenServerClick();
|
|
|
|
|
|
bool isJarRunning(const char* jarName);
|
|
|
|
|
|
bool terminateProcessByName(const char* processName);
|
|
|
|
|
|
void ServerReRun();
|
|
|
|
|
|
void onCurrentIndexChanged(int index);
|
2024-11-01 16:09:31 +08:00
|
|
|
|
void onCurrentIndexChangedCSIP(int index);
|
2024-08-13 17:07:34 +08:00
|
|
|
|
void SetSuBState(bool F);
|
|
|
|
|
|
void SetWebState(bool F);
|
|
|
|
|
|
void SetSaveBtn();
|
|
|
|
|
|
void Initlogo();
|
2024-08-22 17:26:05 +08:00
|
|
|
|
void slotCheckedChanged(int i);
|
2024-11-01 16:09:31 +08:00
|
|
|
|
void ReadCSInfoFun();
|
|
|
|
|
|
void PrintMessage(CCString str);
|
|
|
|
|
|
void ReadSub_IP();
|
|
|
|
|
|
void Deploy();
|
|
|
|
|
|
void InitUi();
|
2024-08-13 17:07:34 +08:00
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
Ui::Widget *ui;
|
|
|
|
|
|
bool ServerFlag = false;
|
|
|
|
|
|
std::vector<QPushButton*> Btns;
|
|
|
|
|
|
void OpenFlagBtn(bool F);
|
|
|
|
|
|
void SetPage(int i);
|
|
|
|
|
|
void SetBtn(int i);
|
|
|
|
|
|
void ServerConfigInit();
|
|
|
|
|
|
void onTextChanged(const QString &text);
|
2024-08-22 17:26:05 +08:00
|
|
|
|
void SetServerConfig();
|
|
|
|
|
|
void SetState(bool F);
|
|
|
|
|
|
bool checkAutoStartEntry(const QString &appName);
|
|
|
|
|
|
void SetAutoStart(const QString &path, bool enable);
|
|
|
|
|
|
void OpenSerice(bool F);
|
|
|
|
|
|
void copy_file(const fs::path& source, const fs::path& dest) {
|
|
|
|
|
|
std::ifstream src(source, std::ios::binary);
|
|
|
|
|
|
std::ofstream dst(dest, std::ios::binary);
|
|
|
|
|
|
dst << src.rdbuf();
|
|
|
|
|
|
}
|
|
|
|
|
|
void copy_directory_recursively(const fs::path& source, const fs::path& dest) {
|
|
|
|
|
|
// 如果目标目录不存在,则创建它
|
|
|
|
|
|
if (!fs::exists(dest)) {
|
|
|
|
|
|
fs::create_directories(dest);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (const auto& entry : fs::directory_iterator(source)) {
|
|
|
|
|
|
fs::path dest_path = dest / entry.path().filename();
|
|
|
|
|
|
|
|
|
|
|
|
if (entry.is_regular_file()) {
|
|
|
|
|
|
// 复制文件
|
|
|
|
|
|
copy_file(entry.path(), dest_path);
|
|
|
|
|
|
} else if (entry.is_directory()) {
|
|
|
|
|
|
// 递归复制子目录
|
|
|
|
|
|
copy_directory_recursively(entry.path(), dest_path);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
bool COPYFile(fs::path n,fs::path m){
|
|
|
|
|
|
try {
|
|
|
|
|
|
copy_directory_recursively(n, m);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
} catch (const fs::filesystem_error& e) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-08-13 17:07:34 +08:00
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
void closeEvent(QCloseEvent *event) override;
|
|
|
|
|
|
void paintEvent(QPaintEvent * event) override{
|
|
|
|
|
|
QPainter painter(this);// 创建一个QPainter对象并指定绘制设备为this,即当前窗口
|
|
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing); // 设置绘制选项为反锯齿,使绘制的图形边缘更加平滑
|
|
|
|
|
|
painter.setBrush(QBrush(QColor(255, 255, 255))); //设置画刷颜色,这里为白色
|
|
|
|
|
|
painter.setPen(Qt::transparent); //设置画笔颜色为透明,即不绘制边框线
|
|
|
|
|
|
QRect rect = this->rect(); //获取当前窗口的矩形区域
|
|
|
|
|
|
painter.drawRoundedRect(rect, 15, 15);
|
|
|
|
|
|
}
|
|
|
|
|
|
void mousePressEvent(QMouseEvent *e) override {
|
|
|
|
|
|
// 鼠标左键
|
|
|
|
|
|
if (e->button() == Qt::LeftButton) {
|
|
|
|
|
|
m_ptPress = e->pos();
|
|
|
|
|
|
m_bPressed = true; // 修改这里,总是设置为true,因为我们希望点击控件时移动窗口
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override {
|
|
|
|
|
|
if (m_bPressed) {
|
|
|
|
|
|
move(pos() + e->pos() - m_ptPress);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
void mouseReleaseEvent(QMouseEvent *) override {
|
|
|
|
|
|
m_bPressed = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
void setAreaMovable(const QRect rt) {
|
|
|
|
|
|
// 这里不需要再判断是否改变,因为我们将直接在控件上响应鼠标事件
|
|
|
|
|
|
m_areaMovable = rt;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
#endif // WIDGET_H
|
2024-08-22 17:26:05 +08:00
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
inline void CreateShortO(){
|
|
|
|
|
|
CoInitialize(nullptr);
|
|
|
|
|
|
IShellLink* psl;
|
|
|
|
|
|
CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);
|
|
|
|
|
|
CCString str = QApplication::applicationFilePath().toStdString();
|
|
|
|
|
|
CCString str1 = QApplication::applicationDirPath().toStdString() + "/IPBS_Station.exe.lnk";
|
|
|
|
|
|
CCString workingDir = QApplication::applicationDirPath().toStdString();
|
|
|
|
|
|
psl->SetPath(str.c_str());
|
|
|
|
|
|
psl->SetWorkingDirectory(workingDir.c_str());
|
|
|
|
|
|
IPersistFile* ppf;
|
|
|
|
|
|
psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
|
|
|
|
|
|
WCHAR wszPath[MAX_PATH];
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, str1.c_str(), -1, wszPath, MAX_PATH);
|
|
|
|
|
|
ppf->Save(wszPath, TRUE);
|
|
|
|
|
|
ppf->Release();
|
|
|
|
|
|
psl->Release();
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
|
|
}
|
|
|
|
|
|
#elif __linux__
|
|
|
|
|
|
#endif
|