diff --git a/src/ui/conf/confmanager.cpp b/src/ui/conf/confmanager.cpp index ff20bacd..91d2255c 100644 --- a/src/ui/conf/confmanager.cpp +++ b/src/ui/conf/confmanager.cpp @@ -1151,7 +1151,7 @@ bool ConfManager::validateDriver() return driverManager->validate(buf, verSize); } -void ConfManager::updateDriverServices() +void ConfManager::updateServices() { auto serviceInfoManager = IoC(); @@ -1162,9 +1162,14 @@ void ConfManager::updateDriverServices() serviceInfoManager->monitorServices(services); - if (runningServicesCount == 0) - return; + if (runningServicesCount > 0) { + updateDriverServices(services, runningServicesCount); + } +} +void ConfManager::updateDriverServices( + const QVector &services, int runningServicesCount) +{ ConfUtil confUtil; QByteArray buf; diff --git a/src/ui/conf/confmanager.h b/src/ui/conf/confmanager.h index 2c3c7b01..16ef35b7 100644 --- a/src/ui/conf/confmanager.h +++ b/src/ui/conf/confmanager.h @@ -9,6 +9,7 @@ #include #include #include +#include #include class App; @@ -85,8 +86,12 @@ public: virtual bool checkPassword(const QString &password); bool validateDriver(); - void updateDriverServices(); + + void updateServices(); + void updateDriverServices(const QVector &services, int runningServicesCount); + virtual bool updateDriverConf(bool onlyFlags = false); + void updateDriverZones(quint32 zonesMask, quint32 enabledMask, quint32 dataSize, const QList &zonesData); diff --git a/src/ui/fortmanager.cpp b/src/ui/fortmanager.cpp index 1e47d5aa..26c2b01e 100644 --- a/src/ui/fortmanager.cpp +++ b/src/ui/fortmanager.cpp @@ -88,6 +88,7 @@ void FortManager::initialize() setupConfManager(); setupQuotaManager(); setupTaskManager(); + setupServiceInfoManager(); setupDriver(); loadConf(); @@ -252,7 +253,7 @@ bool FortManager::setupDriver() } if (ok) { - confManager->updateDriverServices(); + confManager->updateServices(); } return ok; @@ -329,6 +330,14 @@ void FortManager::setupTaskManager() }); } +void FortManager::setupServiceInfoManager() +{ + auto serviceInfoManager = IoC(); + + connect(serviceInfoManager, &ServiceInfoManager::servicesStarted, IoC(), + &ConfManager::updateDriverServices); +} + void FortManager::setupTranslationManager() { IoC()->switchLanguageByName(IoC()->iniUser().language()); diff --git a/src/ui/fortmanager.h b/src/ui/fortmanager.h index d98ca38d..2dd61358 100644 --- a/src/ui/fortmanager.h +++ b/src/ui/fortmanager.h @@ -47,6 +47,7 @@ private: void setupConfManager(); void setupQuotaManager(); void setupTaskManager(); + void setupServiceInfoManager(); void setupTranslationManager(); diff --git a/src/ui/manager/serviceinfomanager.cpp b/src/ui/manager/serviceinfomanager.cpp index 10243e83..1f0dfece 100644 --- a/src/ui/manager/serviceinfomanager.cpp +++ b/src/ui/manager/serviceinfomanager.cpp @@ -90,9 +90,8 @@ QVector getServiceInfoList(SC_HANDLE mngr, DWORD serviceType = SERV for (int infoIndex = infoList.size(); serviceCount > 0; --serviceCount, ++service, ++infoIndex) { - const auto originalServiceName = - QString::fromUtf16((const char16_t *) service->lpServiceName); - const auto serviceName = resolveSvcHostServiceName(servicesReg, originalServiceName); + auto serviceName = QString::fromUtf16((const char16_t *) service->lpServiceName); + serviceName = resolveSvcHostServiceName(servicesReg, serviceName); const RegKey svcReg(servicesReg, serviceName); @@ -251,7 +250,16 @@ void ServiceInfoManager::stopServiceMonitor(ServiceMonitor *serviceMonitor) void ServiceInfoManager::onServicesCreated(const QStringList &serviceNames) { - for (const QString &serviceName : serviceNames) { + const RegKey servicesReg(RegKey::HKLM, servicesSubKey); + + for (const QString &name : serviceNames) { + const QString serviceName = resolveSvcHostServiceName(servicesReg, name); + + const RegKey svcReg(servicesReg, serviceName); + + if (!checkIsSvcHostService(svcReg)) + continue; + setupServiceMonitor(serviceName); } } @@ -262,10 +270,24 @@ void ServiceInfoManager::onServiceStateChanged(ServiceMonitor *serviceMonitor) case ServiceMonitor::ServiceStateUnknown: { } break; case ServiceMonitor::ServiceRunning: { - emit serviceStarted(serviceMonitor->serviceName(), serviceMonitor->processId()); + onServiceStarted(serviceMonitor); } break; case ServiceMonitor::ServiceDeleting: { stopServiceMonitor(serviceMonitor); } break; } } + +void ServiceInfoManager::onServiceStarted(ServiceMonitor *serviceMonitor) +{ + constexpr int servicesCount = 1; + + QVector services(servicesCount); + + ServiceInfo &info = services[0]; + info.isRunning = true; + info.processId = serviceMonitor->processId(); + info.serviceName = serviceMonitor->serviceName(); + + emit servicesStarted(services, servicesCount); +} diff --git a/src/ui/manager/serviceinfomanager.h b/src/ui/manager/serviceinfomanager.h index c0e20484..6f44f1c1 100644 --- a/src/ui/manager/serviceinfomanager.h +++ b/src/ui/manager/serviceinfomanager.h @@ -26,7 +26,7 @@ public: static QString getSvcHostServiceDll(const QString &serviceName); signals: - void serviceStarted(const QString &serviceName, qint32 processId); + void servicesStarted(const QVector &services, int runningServicesCount); public slots: virtual void trackService(const QString &serviceName); @@ -45,6 +45,7 @@ protected: private: void onServicesCreated(const QStringList &serviceNames); void onServiceStateChanged(ServiceMonitor *serviceMonitor); + void onServiceStarted(ServiceMonitor *serviceMonitor); private: ServiceListMonitor *m_serviceListMonitor = nullptr; diff --git a/src/ui/util/service/serviceinfo.h b/src/ui/util/service/serviceinfo.h index 176b4ef6..01acbc3d 100644 --- a/src/ui/util/service/serviceinfo.h +++ b/src/ui/util/service/serviceinfo.h @@ -22,7 +22,7 @@ public: bool isTracked() const { return trackFlags != 0; } - bool isRunning = 0; + bool isRunning = false; quint32 trackFlags = 0; quint32 processId = 0; QString serviceName;