mirror of
https://github.com/tnodir/fort
synced 2024-11-15 09:17:28 +00:00
UI: ServiceInfoManager: Simplify getServiceInfoList()
This commit is contained in:
parent
322a4e44e3
commit
b562e4d848
@ -1155,7 +1155,7 @@ void ConfManager::updateServices()
|
||||
{
|
||||
auto serviceInfoManager = IoC<ServiceInfoManager>();
|
||||
|
||||
int runningServicesCount;
|
||||
int runningServicesCount = 0;
|
||||
const QVector<ServiceInfo> services =
|
||||
serviceInfoManager->loadServiceInfoList(ServiceInfo::TypeWin32, ServiceInfo::StateAll,
|
||||
/*displayName=*/false, &runningServicesCount);
|
||||
|
@ -65,28 +65,10 @@ bool checkIsSvcHostService(const RegKey &svcReg)
|
||||
return true;
|
||||
}
|
||||
|
||||
QVector<ServiceInfo> getServiceInfoList(SC_HANDLE mngr, DWORD serviceType = SERVICE_WIN32,
|
||||
DWORD state = SERVICE_STATE_ALL, bool displayName = true,
|
||||
int *runningServicesCount = nullptr)
|
||||
void fillServiceInfoList(QVector<ServiceInfo> &infoList, const RegKey &servicesReg,
|
||||
const ENUM_SERVICE_STATUS_PROCESSW *service, DWORD serviceCount, bool displayName,
|
||||
int &runningCount)
|
||||
{
|
||||
QVector<ServiceInfo> infoList;
|
||||
|
||||
const RegKey servicesReg(RegKey::HKLM, servicesSubKey);
|
||||
|
||||
constexpr DWORD bufferMaxSize = 32 * 1024;
|
||||
ENUM_SERVICE_STATUS_PROCESSW buffer[bufferMaxSize / sizeof(ENUM_SERVICE_STATUS_PROCESSW)];
|
||||
DWORD bytesRemaining = 0;
|
||||
DWORD serviceCount = 0;
|
||||
DWORD resumePoint = 0;
|
||||
|
||||
int runningCount = 0;
|
||||
|
||||
while (EnumServicesStatusExW(mngr, SC_ENUM_PROCESS_INFO, serviceType, state, (LPBYTE) buffer,
|
||||
sizeof(buffer), &bytesRemaining, &serviceCount, &resumePoint, nullptr)
|
||||
|| GetLastError() == ERROR_MORE_DATA) {
|
||||
|
||||
const ENUM_SERVICE_STATUS_PROCESSW *service = &buffer[0];
|
||||
|
||||
for (int infoIndex = infoList.size(); serviceCount > 0;
|
||||
--serviceCount, ++service, ++infoIndex) {
|
||||
|
||||
@ -116,15 +98,40 @@ QVector<ServiceInfo> getServiceInfoList(SC_HANDLE mngr, DWORD serviceType = SERV
|
||||
|
||||
infoList.append(info);
|
||||
}
|
||||
}
|
||||
|
||||
QVector<ServiceInfo> getServiceInfoList(SC_HANDLE mngr, DWORD serviceType = SERVICE_WIN32,
|
||||
DWORD state = SERVICE_STATE_ALL, bool displayName = true,
|
||||
int *runningServicesCount = nullptr)
|
||||
{
|
||||
QVector<ServiceInfo> infoList;
|
||||
|
||||
const RegKey servicesReg(RegKey::HKLM, servicesSubKey);
|
||||
|
||||
constexpr DWORD bufferMaxSize = 32 * 1024;
|
||||
ENUM_SERVICE_STATUS_PROCESSW buffer[bufferMaxSize / sizeof(ENUM_SERVICE_STATUS_PROCESSW)];
|
||||
DWORD bytesRemaining = 0;
|
||||
DWORD serviceCount = 0;
|
||||
DWORD resumePoint = 0;
|
||||
|
||||
while (EnumServicesStatusExW(mngr, SC_ENUM_PROCESS_INFO, serviceType, state, (LPBYTE) buffer,
|
||||
sizeof(buffer), &bytesRemaining, &serviceCount, &resumePoint, nullptr)
|
||||
|| GetLastError() == ERROR_MORE_DATA) {
|
||||
|
||||
const ENUM_SERVICE_STATUS_PROCESSW *service = &buffer[0];
|
||||
|
||||
int runningCount = 0;
|
||||
fillServiceInfoList(
|
||||
infoList, servicesReg, service, serviceCount, displayName, runningCount);
|
||||
|
||||
if (runningServicesCount) {
|
||||
*runningServicesCount += runningCount;
|
||||
}
|
||||
|
||||
if (bytesRemaining == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (runningServicesCount) {
|
||||
*runningServicesCount = runningCount;
|
||||
}
|
||||
|
||||
return infoList;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user