From c67be395bab18eac007b75b3341447949c5c9c41 Mon Sep 17 00:00:00 2001 From: qingchao <2199458@.com> Date: Sat, 14 Dec 2024 09:01:16 +0800 Subject: [PATCH] V1.5 --- .idea/misc.xml | 8 - CMakeLists.txt | 2 + ObjectVariable/Configuration.h | 51 +++- SDK/CCServlet/src/CCResponse.cpp | 2 +- SDK/include/CCFile.h | 1 - SDK/include/CCObject.h | 506 +++++++++++++++++++++++++++++++ UI/W1/widget.cpp | 201 ++++++------ UI/W1/widget.h | 12 +- UI/W1/widget.ui | 37 ++- UI/W3/widget3.cpp | 9 +- UI/W3/widget3.ui | 51 +++- 11 files changed, 742 insertions(+), 138 deletions(-) create mode 100644 SDK/include/CCObject.h diff --git a/.idea/misc.xml b/.idea/misc.xml index 56e425f..db293e8 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,13 +1,5 @@ - - diff --git a/CMakeLists.txt b/CMakeLists.txt index 2375cc6..2c6f792 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,8 @@ project(IPBS_Station LANGUAGES CXX) add_subdirectory(SDK) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") +#set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/Bin) +#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mwindows") set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) diff --git a/ObjectVariable/Configuration.h b/ObjectVariable/Configuration.h index 658c688..15dc3f6 100644 --- a/ObjectVariable/Configuration.h +++ b/ObjectVariable/Configuration.h @@ -6,7 +6,6 @@ #include #include #include -#include #include #include @@ -21,6 +20,10 @@ #define Sub_ImgBuffer "ImgBuffer/" #ifdef _WIN32 +#include +#include +#include +#include // 包含 ShellLink 和 IPersistFile 接口 #define SubControl_Java "SubControl/WebSub/jreWin/bin/Sub_Server.exe" #define SubControl_Web_Exe "SubControl/Sub_Web.exe" #define IPBS_NSSM_Exe "IPBS_NSSM.exe" @@ -60,6 +63,7 @@ public: inline static std::vector CSIPList; inline static std::vector SubIPList; inline static CCProcess WebRun,SubRun; + inline static int PostMax = 5417; public: static int GetInt(char h1, char h2) { @@ -84,7 +88,7 @@ public: CORSEn = A["CORSEn"]; FirstRun = A["FirstRun"].to_int(); } - Configuration::Web_URL = "http://" + Web_IP + ":" + Web_Port + "/"; + Configuration::Web_URL = "http://" + Web_IP + ":" + Web_Port; } static void ReadCSInfo(const std::function& fun = nullptr){ CCUniqueLock lock(_mutex); @@ -195,12 +199,15 @@ public: } } } - CCVar Ports = getAvailablePorts(3,5417); + if(PostMax == Sub_Port.to_int()){ + PostMax = PostMax + 3; + } + CCVar Ports = getAvailablePorts(3,PostMax); Sub_Port = Ports[0].to_String(); Sub_Audio_Port = Ports[1].to_String(); Web_Port = Ports[2].to_String(); Web_IP = Sub_IP; - Sub_Org = "['http://" + Sub_IP + ":" + Sub_Port + "']"; + Sub_Org = "['http://" + Web_IP + ":" + Web_Port + "']"; } static bool isPortAvailable(int port,TORU ipvx = TCP) { @@ -383,13 +390,43 @@ public: fclose(fp); return true; } + static bool 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 + } static void IPBS_NSSMF(bool F){ if(F){ - CCString cmd = "cd " + ExePath + " && " + IPBS_NSSMPath; - QProcess::startDetached(cmd.c_str()); + const CCString str = CCString("./") + IPBS_NSSM_Exe; + QProcess::startDetached(str.c_str()); } else{ - QProcess::startDetached("taskkill /f /t /im IPBS_NSSM.exe"); +#ifdef _WIN32 + terminateProcessByName("IPBS_NSSM"); +#elif __linux__ +#endif } } }; diff --git a/SDK/CCServlet/src/CCResponse.cpp b/SDK/CCServlet/src/CCResponse.cpp index 5772023..af527b5 100644 --- a/SDK/CCServlet/src/CCResponse.cpp +++ b/SDK/CCServlet/src/CCResponse.cpp @@ -199,7 +199,7 @@ CCString HTTPResponse::sha1(const CCString &input) { return base64_encode(hash, SHA_DIGEST_LENGTH); } -std::streamoff HTTPResponse::getFileSize(const string &filePath) { +std::streamoff HTTPResponse::getFileSize(const String &filePath) { std::ifstream file(filePath, std::ios::binary | std::ios::ate); if (!file.is_open()) { return -1; // 文件打开失败 diff --git a/SDK/include/CCFile.h b/SDK/include/CCFile.h index d908d15..54e0039 100644 --- a/SDK/include/CCFile.h +++ b/SDK/include/CCFile.h @@ -1,6 +1,5 @@ #ifndef IMGUICPPDEMO_CCIOS_H #define IMGUICPPDEMO_CCIOS_H -#include #include "cstdio" #include "vector" diff --git a/SDK/include/CCObject.h b/SDK/include/CCObject.h new file mode 100644 index 0000000..e255cee --- /dev/null +++ b/SDK/include/CCObject.h @@ -0,0 +1,506 @@ +#ifndef CCObject_H +#define CCObject_H +#pragma once +#pragma GCC system_header + +#include +#include +#include +#include +#include + +using namespace std; + +class bad_CCObject_cast : public bad_cast +{ +public: + virtual const char* what() const noexcept { return "bad CCObject_cast"; } +}; + +[[gnu::noreturn]] inline void __throw_bad_CCObject_cast() +{ +#if __cpp_exceptions + throw bad_CCObject_cast{}; +#else + __builtin_abort(); +#endif +} + +#define __cpp_lib_CCObject 201606L + +class CCObject +{ + // Holds either pointer to a heap object or the contained object itself. + union _Storage + { + constexpr _Storage() : _M_ptr{nullptr} {} + + // Prevent trivial copies of this type, buffer might hold a non-POD. + _Storage(const _Storage&) = delete; + _Storage& operator=(const _Storage&) = delete; + + void* _M_ptr; + aligned_storage::type _M_buffer; + }; + + template, + bool _Fits = (sizeof(_Tp) <= sizeof(_Storage)) + && (alignof(_Tp) <= alignof(_Storage))> + using _Internal = std::integral_constant; + + template + struct _Manager_internal; // uses small-object optimization + + template + struct _Manager_external; // creates contained object on the heap + + template + using _Manager = __conditional_t<_Internal<_Tp>::value, + _Manager_internal<_Tp>, + _Manager_external<_Tp>>; + + template> + using _Decay_if_not_CCObject = enable_if_t, _VTp>; + + /// Emplace with an object created from @p __args as the contained object. + template > + void __do_emplace(_Args&&... __args) + { + reset(); + _Mgr::_S_create(_M_storage, std::forward<_Args>(__args)...); + _M_manager = &_Mgr::_S_manage; + } + template > + void __do_emplace(initializer_list<_Up> __il, _Args&&... __args) + { + reset(); + _Mgr::_S_create(_M_storage, __il, std::forward<_Args>(__args)...); + _M_manager = &_Mgr::_S_manage; + } + + template + using __CCObject_constructible + = enable_if<__and_, + is_constructible<_Tp, _Args...>>::value, + _Res>; + + template + using __CCObject_constructible_t + = typename __CCObject_constructible::type; + + template + using __emplace_t + = typename __CCObject_constructible<_VTp&, _VTp, _Args...>::type; + +public: + constexpr CCObject() noexcept : _M_manager(nullptr) { } + CCObject(const CCObject& __other) + { + if (!__other.has_value()) + _M_manager = nullptr; + else + { + _Arg __arg; + __arg._M_CCObject = this; + __other._M_manager(_Op_clone, &__other, &__arg); + } + } + CCObject(CCObject&& __other) noexcept + { + if (!__other.has_value()) + _M_manager = nullptr; + else + { + _Arg __arg; + __arg._M_CCObject = this; + __other._M_manager(_Op_xfer, &__other, &__arg); + } + } + template , + typename _Mgr = _Manager<_VTp>, + enable_if_t + && !__is_in_place_type_v<_VTp>, bool> = true> + CCObject(_Tp&& __value) + : _M_manager(&_Mgr::_S_manage) + { + _Mgr::_S_create(_M_storage, std::forward<_Tp>(__value)); + } + template , + typename _Mgr = _Manager<_VTp>, + __CCObject_constructible_t<_VTp, _Args&&...> = false> + explicit + CCObject(in_place_type_t<_Tp>, _Args&&... __args) + : _M_manager(&_Mgr::_S_manage) + { + _Mgr::_S_create(_M_storage, std::forward<_Args>(__args)...); + } + template , typename _Mgr = _Manager<_VTp>, + __CCObject_constructible_t<_VTp, initializer_list<_Up>&, + _Args&&...> = false> + explicit + CCObject(in_place_type_t<_Tp>, initializer_list<_Up> __il, _Args&&... __args) + : _M_manager(&_Mgr::_S_manage) + { + _Mgr::_S_create(_M_storage, __il, std::forward<_Args>(__args)...); + } + ~CCObject() { reset(); } + CCObject& + operator=(const CCObject& __rhs) + { + *this = CCObject(__rhs); + return *this; + } + CCObject& + operator=(CCObject&& __rhs) noexcept + { + if (!__rhs.has_value()) + reset(); + else if (this != &__rhs) + { + reset(); + _Arg __arg; + __arg._M_CCObject = this; + __rhs._M_manager(_Op_xfer, &__rhs, &__arg); + } + return *this; + } + template + enable_if_t>::value, CCObject&> + operator=(_Tp&& __rhs) + { + *this = CCObject(std::forward<_Tp>(__rhs)); + return *this; + } + template + __emplace_t, _Args...> + emplace(_Args&&... __args) + { + using _VTp = decay_t<_Tp>; + __do_emplace<_VTp>(std::forward<_Args>(__args)...); + return *CCObject::_Manager<_VTp>::_S_access(_M_storage); + } + template + __emplace_t, initializer_list<_Up>&, _Args&&...> + emplace(initializer_list<_Up> __il, _Args&&... __args) + { + using _VTp = decay_t<_Tp>; + __do_emplace<_VTp, _Up>(__il, std::forward<_Args>(__args)...); + return *CCObject::_Manager<_VTp>::_S_access(_M_storage); + } + void reset() noexcept + { + if (has_value()) + { + _M_manager(_Op_destroy, this, nullptr); + _M_manager = nullptr; + } + } + void swap(CCObject& __rhs) noexcept + { + if (!has_value() && !__rhs.has_value()) + return; + + if (has_value() && __rhs.has_value()) + { + if (this == &__rhs) + return; + + CCObject __tmp; + _Arg __arg; + __arg._M_CCObject = &__tmp; + __rhs._M_manager(_Op_xfer, &__rhs, &__arg); + __arg._M_CCObject = &__rhs; + _M_manager(_Op_xfer, this, &__arg); + __arg._M_CCObject = this; + __tmp._M_manager(_Op_xfer, &__tmp, &__arg); + } + else + { + CCObject* __empty = !has_value() ? this : &__rhs; + CCObject* __full = !has_value() ? &__rhs : this; + _Arg __arg; + __arg._M_CCObject = __empty; + __full->_M_manager(_Op_xfer, __full, &__arg); + } + } + bool has_value() const noexcept { return _M_manager != nullptr; } + CCObject Get(){return *this;} + void * GetPointer() const; + const char* ToString() const; + operator int () const; + operator double () const; + operator float () const; + operator const char* () const; + +#if __cpp_rtti + const type_info& type() const noexcept + { + if (!has_value()) + return typeid(void); + _Arg __arg; + _M_manager(_Op_get_type_info, this, &__arg); + return *__arg._M_typeinfo; + } +#endif + template + static constexpr bool __is_valid_cast() + { return __or_, is_copy_constructible<_Tp>>::value; } + +private: + enum _Op { + _Op_access, _Op_get_type_info, _Op_clone, _Op_destroy, _Op_xfer + }; + union _Arg + { + void* _M_obj; + const std::type_info* _M_typeinfo; + CCObject* _M_CCObject; + }; + void (*_M_manager)(_Op, const CCObject*, _Arg*); + _Storage _M_storage; + template + friend void* __CCObject_caster(const CCObject* __CCObject); + template + struct _Manager_internal + { + static void + _S_manage(_Op __which, const CCObject* __CCObjectp, _Arg* __arg); + + template + static void + _S_create(_Storage& __storage, _Up&& __value) + { + void* __addr = &__storage._M_buffer; + ::new (__addr) _Tp(std::forward<_Up>(__value)); + } + + template + static void + _S_create(_Storage& __storage, _Args&&... __args) + { + void* __addr = &__storage._M_buffer; + ::new (__addr) _Tp(std::forward<_Args>(__args)...); + } + + static _Tp* + _S_access(const _Storage& __storage) + { + // The contained object is in __storage._M_buffer + const void* __addr = &__storage._M_buffer; + return static_cast<_Tp*>(const_cast(__addr)); + } + }; + template + struct _Manager_external + { + static void + _S_manage(_Op __which, const CCObject* __CCObjectp, _Arg* __arg); + + template + static void + _S_create(_Storage& __storage, _Up&& __value) + { + __storage._M_ptr = new _Tp(std::forward<_Up>(__value)); + } + template + static void + _S_create(_Storage& __storage, _Args&&... __args) + { + __storage._M_ptr = new _Tp(std::forward<_Args>(__args)...); + } + static _Tp* + _S_access(const _Storage& __storage) + { + // The contained object is in *__storage._M_ptr + return static_cast<_Tp*>(__storage._M_ptr); + } + }; +}; + + + + +inline void swap(CCObject& __x, CCObject& __y) noexcept { __x.swap(__y); } +template +inline +enable_if_t, _Args...>, CCObject> +make_CCObject(_Args&&... __args) +{ +return CCObject(in_place_type<_Tp>, std::forward<_Args>(__args)...); +} +template +inline +enable_if_t, +initializer_list<_Up>&, _Args...>, CCObject> +make_CCObject(initializer_list<_Up> __il, _Args&&... __args) +{ +return CCObject(in_place_type<_Tp>, __il, std::forward<_Args>(__args)...); +} +template +inline _ValueType CCObject_cast(const CCObject& __CCObject) +{ + using _Up = __remove_cvref_t<_ValueType>; + static_assert(CCObject::__is_valid_cast<_ValueType>(), + "模板参数必须是引用或 CopyConstructible 类型"); + static_assert(is_constructible_v<_ValueType, const _Up&>, + "模板参数必须可以从 const 值构造。"); + auto __p = CCObject_cast<_Up>(&__CCObject); + if (__p) + return static_cast<_ValueType>(*__p); + __throw_bad_CCObject_cast(); +} +template +inline _ValueType CCObject_cast(CCObject& __CCObject) +{ + using _Up = __remove_cvref_t<_ValueType>; + static_assert(CCObject::__is_valid_cast<_ValueType>(), + "模板参数必须是引用或 CopyConstructible 类型"); + static_assert(is_constructible_v<_ValueType, _Up&>, + "模板参数必须可以从左值构造。"); + auto __p = CCObject_cast<_Up>(&__CCObject); + if (__p) + return static_cast<_ValueType>(*__p); + __throw_bad_CCObject_cast(); +} +template +inline _ValueType CCObject_cast(CCObject&& __CCObject) +{ + using _Up = __remove_cvref_t<_ValueType>; + static_assert(CCObject::__is_valid_cast<_ValueType>(), + "模板参数必须是引用或 CopyConstructible 类型"); + static_assert(is_constructible_v<_ValueType, _Up>, + "模板参数必须可以从右值构造。"); + auto __p = CCObject_cast<_Up>(&__CCObject); + if (__p) + return static_cast<_ValueType>(std::move(*__p)); + __throw_bad_CCObject_cast(); +} +template +void* __CCObject_caster(const CCObject* __CCObject) +{ + using _Up = remove_cv_t<_Tp>; + if constexpr (!is_same_v, _Up>) + return nullptr; + else if constexpr (!is_copy_constructible_v<_Up>) + return nullptr; + else if (__CCObject->_M_manager == &CCObject::_Manager<_Up>::_S_manage + #if __cpp_rtti + || __CCObject->type() == typeid(_Tp) +#endif + ) + { + return CCObject::_Manager<_Up>::_S_access(__CCObject->_M_storage); + } + return nullptr; +} +template +inline const _ValueType* CCObject_cast(const CCObject* __CCObject) noexcept +{ + if constexpr (is_object_v<_ValueType>) + if (__CCObject) + return static_cast<_ValueType*>(__CCObject_caster<_ValueType>(__CCObject)); + return nullptr; +} +template +inline _ValueType* CCObject_cast(CCObject* __CCObject) noexcept +{ + if constexpr (is_object_v<_ValueType>) + if (__CCObject) + return static_cast<_ValueType*>(__CCObject_caster<_ValueType>(__CCObject)); + return nullptr; +} +template +void +CCObject::_Manager_internal<_Tp>:: +_S_manage(_Op __which, const CCObject* __CCObject, _Arg* __arg) +{ + + auto __ptr = reinterpret_cast(&__CCObject->_M_storage._M_buffer); + switch (__which) + { + case _Op_access: + __arg->_M_obj = const_cast<_Tp*>(__ptr); + break; + case _Op_get_type_info: +#if __cpp_rtti + __arg->_M_typeinfo = &typeid(_Tp); +#endif + break; + case _Op_clone: + ::new(&__arg->_M_CCObject->_M_storage._M_buffer) _Tp(*__ptr); + __arg->_M_CCObject->_M_manager = __CCObject->_M_manager; + break; + case _Op_destroy: + __ptr->~_Tp(); + break; + case _Op_xfer: + ::new(&__arg->_M_CCObject->_M_storage._M_buffer) _Tp + (std::move(*const_cast<_Tp*>(__ptr))); + __ptr->~_Tp(); + __arg->_M_CCObject->_M_manager = __CCObject->_M_manager; + const_cast(__CCObject)->_M_manager = nullptr; + break; + } +} +template +void +CCObject::_Manager_external<_Tp>:: +_S_manage(_Op __which, const CCObject* __CCObject, _Arg* __arg) +{ + auto __ptr = static_cast(__CCObject->_M_storage._M_ptr); + switch (__which) + { + case _Op_access: + __arg->_M_obj = const_cast<_Tp*>(__ptr); + break; + case _Op_get_type_info: +#if __cpp_rtti + __arg->_M_typeinfo = &typeid(_Tp); +#endif + break; + case _Op_clone: + __arg->_M_CCObject->_M_storage._M_ptr = new _Tp(*__ptr); + __arg->_M_CCObject->_M_manager = __CCObject->_M_manager; + break; + case _Op_destroy: + delete __ptr; + break; + case _Op_xfer: + __arg->_M_CCObject->_M_storage._M_ptr = __CCObject->_M_storage._M_ptr; + __arg->_M_CCObject->_M_manager = __CCObject->_M_manager; + const_cast(__CCObject)->_M_manager = nullptr; + break; + } +} +inline CCObject::operator int() const { + int i = CCObject_cast(*this); + return i; +} +inline CCObject::operator double() const { + auto d = CCObject_cast(*this); + return d; +} +inline CCObject::operator float() const { + auto f = CCObject_cast(*this); + return f; +} +inline const char *CCObject::ToString() const { + return (const char*)*this; +} + +inline void *CCObject::GetPointer() const { + if (auto p = CCObject_cast(*this)) + return p; + return nullptr; +} + +inline CCObject::operator const char *() const { + if (auto s = CCObject_cast(*this)) + return s; + return nullptr; +} + +#endif diff --git a/UI/W1/widget.cpp b/UI/W1/widget.cpp index 3b9b33e..f1e3a82 100644 --- a/UI/W1/widget.cpp +++ b/UI/W1/widget.cpp @@ -1,8 +1,6 @@ #include #include "widget.h" - #include - #include "./ui_widget.h" Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget){ @@ -42,7 +40,13 @@ Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget){ connect(ui->OpenPCStart, &QCheckBox::stateChanged,this, &Widget::slotCheckedChanged); connect(ui->RapidDeployment, &QPushButton::clicked, this, [this]() { - CCThread(&Widget::Deploy,this).detach(); + CCThread([this](){ + QMetaObject::invokeMethod(this,[this]() + { + this->Deploy(this); + }); + }).detach(); + // Deploy(); }); if(Configuration::CORSEn == "true"){ ui->CORSEn->setChecked(true); @@ -148,6 +152,14 @@ Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget){ ServerThread.SetThread(&Widget::ServerListening,this); ServerThread.Start(); OpenSerice(true); + JSON Ret;std::vector Value; + for (int i = 0;i<1000;i++){ + JSON A; + A["Vol"] = 8; + A["IP"] = "127.0.0.1"; + Value.push_back(A); + } + Ret["State"] = Value; //------------------------------------------------------------------------------------------------ } @@ -170,7 +182,8 @@ void Widget::WebThreadRun() { while (Configuration::SubRun.IsRunning()){ CCString Line = Configuration::SubRun.ReadLineBuffer(); if(!Line.empty()){ - PrintMessage(Line); + CCString A = CCEncode::Format(Line,Encode.GBK,Encode.UTF8); + PrintMessage(A); } Threading::Sleep(1000 * 50); } @@ -224,6 +237,12 @@ bool Widget::WebRunFun() { } PrintMessage("网址: " + Configuration::Web_URL); }).detach(); + QMetaObject::invokeMethod(this,[this]() + { + ui->URL_Text->setOpenExternalLinks(true);//设置为true才能打开网页 + const CCString URL1 = " "+ Configuration::Web_URL +""; + ui->URL_Text->setText(URL1.c_str()); + }); } } return true; @@ -376,48 +395,20 @@ bool Widget::isJarRunning(const char *jarName) { #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); + OpenFlagBtn(false); + WebThread.Stop(); + PrintMessage("Server Close"); ui->RunTime->setVisible(false); t = 0;h = 0;f = 0;s = 0; } + Configuration::CloseSub_Server(); + Configuration::CloseSub_Web(); } catch (const std::exception& e) { std::cerr << "Error: " << e.what() << std::endl; @@ -520,24 +511,26 @@ void Widget::SetSaveBtn() { 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; + if(ServerFlag){ + try { + if(ServerFlag){ + ServerFlag = false; + SetState(ServerFlag); + OpenFlagBtn(false); + WebThread.Stop(); + PrintMessage("Server Close"); + ui->RunTime->setVisible(false); + t = 0;h = 0;f = 0;s = 0; + } + Configuration::CloseSub_Server(); + Configuration::CloseSub_Web(); } + catch (const std::exception& e) { + PrintMessage("Error: " + CCString(e.what())); + } + CCThread::Sleep(1000 * 100); } - catch (const std::exception& e) { - std::cerr << "Error: " << e.what() << std::endl; - } - OpenServerClick(); + ServerReRun(); } else { // 用户点击了“否”按钮 } @@ -546,7 +539,14 @@ void Widget::SetSaveBtn() { void Widget::ServerConfigInit() { Configuration::CfgInit(); SetPage(1); - QMessageBox::information(this, "提示", "初始化已完成!"); + const QMessageBox::StandardButton reply = QMessageBox::question(this, "提示", + "初始化已完成,是否保存?", + QMessageBox::Yes | QMessageBox::No); + if (reply == QMessageBox::Yes) { + SetSaveBtn(); + } else { + + } } void Widget::Initlogo() { @@ -696,7 +696,7 @@ void Widget::PrintMessage(CCString str) { QMetaObject::invokeMethod(this,[this,str]() { - CCTimeData time; + const CCTimeData time; CCString S = "[" + time.to_String() + "] -> " + str; ui->ServerConsele->append(S.c_str()); }); @@ -711,7 +711,19 @@ void Widget::ReadSub_IP(){ sub->show(); } -void Widget::Deploy(){ +void Widget::Deploy(QWidget* PR){ + Configuration::CloseSub_Server(); + Configuration::CloseSub_Web(); + if(ServerFlag){ + const QMessageBox::StandardButton reply = QMessageBox::question(PR, "提示", + "检测到服务已经启动是否先停止?", + QMessageBox::Yes | QMessageBox::No); + if (reply == QMessageBox::Yes) { + ServerReRun(); + } else { + QMessageBox::information(PR, "提示", "已取消快速配置!"); + } + } boolean F1 = false,F2 = false; PrintMessage("正在配置IP-Web分控IP地址..."); while (true){ @@ -720,7 +732,7 @@ void Widget::Deploy(){ if(!Configuration::SubIPList.empty()){ if(Configuration::SubIPList.size() > 1){ PrintMessage("检测到多个IP地址,请选择要使用的IP地址!"); - CCVar* sub = new Sub_IPUI(this); + CCVar* sub = new Sub_IPUI(nullptr); int top = this->geometry().top(); int left = this->geometry().left(); int screenWidth = this->width(); @@ -748,20 +760,20 @@ void Widget::Deploy(){ 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地址配置跳过!"); - } - }); + bool A1 = false,A2 = false; + const QMessageBox::StandardButton reply = QMessageBox::question(PR, "提示", + "未检测到合法IPV4地址,请检查网络,是否继续检测?", + QMessageBox::Yes | QMessageBox::No); + if (reply == QMessageBox::Yes) { + A2 = true; + A1 = true; + } else { + Configuration::Sub_IP = ""; + A2 = true; + F2 = false; + PrintMessage("Web分控IP地址配置跳过!"); + } + // while (A2); if(A1){ continue; } @@ -778,7 +790,7 @@ void Widget::Deploy(){ if(!Configuration::CSIPList.empty()){ if(Configuration::CSIPList.size() > 1){ PrintMessage("在局域网检测到多个C/S服务器,请选择需要使用的C/S服务器!"); - CCVar* cs4 = new CSInfoW4(this); + CCVar* cs4 = new CSInfoW4(nullptr); int top = this->geometry().top(); int left = this->geometry().left(); int screenWidth = this->width(); @@ -812,22 +824,19 @@ void Widget::Deploy(){ bool A1 = false; Configuration::CS_IP = ""; Configuration::CS_Port = ""; - QMetaObject::invokeMethod(this,[this,&F1,&A1]() - { - QMessageBox::StandardButton reply = QMessageBox::question(nullptr, "提示", + QMessageBox::StandardButton reply = QMessageBox::question(PR, "提示", "在局域网未检测到可用的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 (reply == QMessageBox::Yes) { + A1 = true; + } + else { + Configuration::CS_IP = ""; + Configuration::CS_Port = ""; + F1 = false; + PrintMessage("C/S服务器信息配置跳过!"); + A1 = false; + } if(A1){ continue; } @@ -838,10 +847,18 @@ void Widget::Deploy(){ } 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; + if(Ports.size() == 3){ + 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; + } + else{ + Configuration::Sub_Port = ""; + Configuration::Sub_Audio_Port = ""; + Configuration::Web_Port = ""; + Configuration::Web_IP = Configuration::Sub_IP = ""; + } PrintMessage("IP-Web分控服务端口分配完成!"); PrintMessage("IP-Web分控服务正在设置跨域..."); Configuration::Sub_Org = "['http://" + Configuration::Web_IP + ":" + Configuration::Web_Port + "']"; @@ -867,8 +884,8 @@ void Widget::Deploy(){ PrintMessage("IP-Web分控服务设置保存完成"); if(F1 && F2){ try { - terminateProcessByName("java"); - terminateProcessByName("nginx"); + Configuration::terminateProcessByName("java"); + Configuration::terminateProcessByName("nginx"); if(ServerFlag){ WebThread.Stop(); ui->ServerConsele->append("Server Close"); diff --git a/UI/W1/widget.h b/UI/W1/widget.h index efc7d5f..063bda1 100644 --- a/UI/W1/widget.h +++ b/UI/W1/widget.h @@ -40,10 +40,7 @@ #include "W5/sub_ipui.h" #ifdef _WIN32 -#include -#include -#include -#include // 包含 ShellLink 和 IPersistFile 接口 + #elif __linux__ #endif @@ -64,9 +61,9 @@ private: #endif QRect m_areaMovable;//可移动窗口的区域,鼠标只有在该区域按下才能移动窗口 - bool m_bPressed,closeflag = false;//鼠标按下标志(不分左右键) + bool m_bPressed{},closeflag = false;//鼠标按下标志(不分左右键) QPoint m_ptPress;//鼠标按下的初始位置 - QProcess* NginxP; + QProcess* NginxP{}; QSystemTrayIcon *trayIcon = new QSystemTrayIcon(this); QMenu *trayIconMenu = new QMenu(this); QAction *quitAction = new QAction(tr("&退出"), this); @@ -85,7 +82,6 @@ public: void ServerListening(); void OpenServerClick(); bool isJarRunning(const char* jarName); - bool terminateProcessByName(const char* processName); void ServerReRun(); void onCurrentIndexChanged(int index); void onCurrentIndexChangedCSIP(int index); @@ -97,7 +93,7 @@ public: void ReadCSInfoFun(); void PrintMessage(CCString str); void ReadSub_IP(); - void Deploy(); + void Deploy(QWidget* PR = nullptr); void InitUi(); private: diff --git a/UI/W1/widget.ui b/UI/W1/widget.ui index 4a73993..af9c791 100644 --- a/UI/W1/widget.ui +++ b/UI/W1/widget.ui @@ -455,7 +455,7 @@ QPushButton:hover{ } - 快速部署 + 快速配置 @@ -1071,7 +1071,7 @@ color: rgb(0, 0, 0); 130 - 170 + 220 111 41 @@ -1106,7 +1106,7 @@ QPushButton:hover{ 0 - 170 + 220 111 41 @@ -1137,6 +1137,37 @@ QPushButton:hover{ 初始化设置 + + + + 0 + 160 + 311 + 51 + + + + + + + 分控前端网址: + + + + + + + + 13 + + + + + + + + + diff --git a/UI/W3/widget3.cpp b/UI/W3/widget3.cpp index faa1171..0bf108e 100644 --- a/UI/W3/widget3.cpp +++ b/UI/W3/widget3.cpp @@ -39,10 +39,15 @@ void widget3::SelectFile() { if(!fileNames.isEmpty()){ CCString fileName = fileNames[0].toStdString(); CCFile file = CCFile(fileName.c_str(), CC::ios::rb, false); - CCString str = WebSubPaths + "html/assets/logo-CuXNbvLG.png"; +#ifdef _WIN32 + CCString Path = CCEncode::Format(WebSubPaths,Encode.UTF8,Encode.GBK); +#elif __linux__ + CCString Path = CCEncode::Format(WebSubPaths,Encode.UTF8,Encode.UTF8); +#endif + CCString str = Path + "SubControl/html/assets/logo-CuXNbvLG.png"; bool F = file.Copy(str); if(F){ - CCString str = WebSubPaths + "html/assets/logo-CuXNbvLG.png"; + CCString str = WebSubPaths + "SubControl/html/assets/logo-CuXNbvLG.png"; QPixmap pixmap(str.c_str()); // 替换为你的图片路径 if(ImGLoad != nullptr) { diff --git a/UI/W3/widget3.ui b/UI/W3/widget3.ui index 887cba9..04ff123 100644 --- a/UI/W3/widget3.ui +++ b/UI/W3/widget3.ui @@ -59,22 +59,6 @@ 图片必须是100x40的大小 - - - - 60 - 80 - 341 - 211 - - - - background-color: rgba(255, 255, 255, 0); - - - - - @@ -110,6 +94,41 @@ QPushButton:hover{ 更改logo图片 + + + + 30 + 70 + 121 + 41 + + + + + Bahnschrift Light + 13 + + + + Qt::TabFocus + + + QPushButton{ + border-radius:10px; + color: rgb(255, 255, 255); + background-color: rgba(255,68,138,255); +} + +QPushButton:hover{ + border-radius:10px; + color: rgb(255, 255, 255); + background-color: rgba(255,100,150, 255); +} + + + 本地更新 + +