#ifndef WIDGET_H #define WIDGET_H #include #include "CCSocket.h" #include "CCThread.h" #include "nlohmann/json.hpp" #include "QMessageBox" #include "ctime" #include #include #include #include #include #include #include #include "QDateTime" #include "QCoreApplication" #include "CCString.h" #include "QFile" #include "CCFile.h" #include "vector" #include "Tools/CText.h" #include #include #include #include #include #include #include #include #include #include #include #include "CCSocket.h" #include "vector" #include "CCTimeData.h" #include "widgetyz.h" #include "csinfow4.h" #include "W5/sub_ipui.h" #ifdef _WIN32 #include #include #include #include // 包含 ShellLink 和 IPersistFile 接口 #elif __linux__ #endif QT_BEGIN_NAMESPACE namespace Ui { class Widget; } QT_END_NAMESPACE namespace fs = std::filesystem; class Widget : public QWidget { Q_OBJECT private: CCThread WebThread, ServerThread; std::vector CSPortList; #ifdef _WIN32 const CCString OpenKit = "C:/ProgramData/Microsoft/Windows/Start Menu/Programs/StartUp/"; #elif __linux__ #endif QRect m_areaMovable;//可移动窗口的区域,鼠标只有在该区域按下才能移动窗口 bool m_bPressed,closeflag = false;//鼠标按下标志(不分左右键) QPoint m_ptPress;//鼠标按下的初始位置 QProcess* NginxP; 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; int OpenSleepValue = 10; 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); void onCurrentIndexChangedCSIP(int index); void SetSuBState(bool F); void SetWebState(bool F); void SetSaveBtn(); void Initlogo(); void slotCheckedChanged(int i); void ReadCSInfoFun(); void PrintMessage(CCString str); void ReadSub_IP(); void Deploy(); void InitUi(); private: Ui::Widget *ui; bool ServerFlag = false; std::vector Btns; void OpenFlagBtn(bool F); void SetPage(int i); void SetBtn(int i); void ServerConfigInit(); void onTextChanged(const QString &text); 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; } } 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 #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