mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 00:37:23 +01:00
Processes: add support for Windows
This commit is contained in:
@@ -284,6 +284,7 @@ if(LINUX OR ANDROID OR BSD)
|
||||
src/detection/temps/temps_linux.c
|
||||
src/detection/users/users_linux.c
|
||||
src/detection/opengl/opengl_linux.c
|
||||
src/detection/processes/processes_linux.c
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -319,6 +320,7 @@ if(WIN_MSYS)
|
||||
src/detection/opengl/opengl_windows.c
|
||||
src/detection/users/users_windows.cpp
|
||||
src/detection/os/os_windows.cpp
|
||||
src/detection/processes/processes_windows.cpp
|
||||
src/util/windows/wmi.cpp
|
||||
|
||||
# Shared
|
||||
@@ -359,6 +361,7 @@ if(APPLE)
|
||||
src/detection/font/font_apple.m
|
||||
src/detection/users/users_linux.c
|
||||
src/detection/opengl/opengl_apple.c
|
||||
src/detection/processes/processes_apple.c
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef FF_INCLUDED_detection_processes_processes
|
||||
#define FF_INCLUDED_detection_processes_processes
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
uint32_t ffDetectProcesses(FFinstance* instance, FFstrbuf* error);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "processes.h"
|
||||
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
uint32_t ffDetectProcesses(FFinstance* instance, FFstrbuf* error)
|
||||
{
|
||||
FF_UNUSED(instance);
|
||||
|
||||
int request[] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL};
|
||||
size_t length;
|
||||
|
||||
if(sysctl(request, sizeof(request) / sizeof(*request), NULL, &length, NULL, 0) != 0)
|
||||
{
|
||||
ffStrbufAppend(error, "sysctl() failed");
|
||||
return 0;
|
||||
}
|
||||
return (uint32_t)(length / sizeof(struct kinfo_proc));
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#include "processes.h"
|
||||
|
||||
uint32_t ffDetectProcesses(FFinstance* instance, FFstrbuf* error)
|
||||
{
|
||||
#if FF_HAVE_SYSINFO_H
|
||||
FF_UNUSED(error);
|
||||
return (uint32_t) instance->state.sysinfo.procs;
|
||||
#else
|
||||
ffStrbufAppendS(error, "Unimplemented");
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
extern "C" {
|
||||
#include "processes.h"
|
||||
}
|
||||
#include "util/windows/wmi.hpp"
|
||||
|
||||
uint32_t ffDetectProcesses(FFinstance* instance, FFstrbuf* error)
|
||||
{
|
||||
FF_UNUSED(instance);
|
||||
|
||||
IEnumWbemClassObject* pEnumerator = ffQueryWmi(L"SELECT NumberOfProcesses FROM Win32_OperatingSystem", error);
|
||||
|
||||
if(!pEnumerator)
|
||||
return 0;
|
||||
|
||||
IWbemClassObject *pclsObj = NULL;
|
||||
ULONG uReturn = 0;
|
||||
|
||||
if(FAILED(pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn)) || uReturn == 0)
|
||||
{
|
||||
ffStrbufAppendS(error, "No Wmi result returned");
|
||||
pEnumerator->Release();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t result = 0;
|
||||
ffGetWmiObjInteger(pclsObj, L"NumberOfProcesses", &result);
|
||||
pclsObj->Release();
|
||||
pEnumerator->Release();
|
||||
return (uint32_t)result;
|
||||
}
|
||||
+10
-23
@@ -1,47 +1,34 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "detection/processes/processes.h"
|
||||
|
||||
#define FF_PROCESSES_MODULE_NAME "Processes"
|
||||
#define FF_PROCESSES_NUM_FORMAT_ARGS 1
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
void ffPrintProcesses(FFinstance* instance)
|
||||
{
|
||||
#if __APPLE__
|
||||
int request[] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL};
|
||||
size_t length;
|
||||
FFstrbuf error;
|
||||
ffStrbufInit(&error);
|
||||
uint32_t numProcesses = ffDetectProcesses(instance, &error);
|
||||
|
||||
if(sysctl(request, sizeof(request) / sizeof(*request), NULL, &length, NULL, 0) != 0)
|
||||
{
|
||||
ffPrintError(instance, FF_PROCESSES_MODULE_NAME, 0, &instance->config.processes, "sysctl() failed");
|
||||
return;
|
||||
}
|
||||
uint16_t numProcesses = (uint16_t)(length / sizeof(struct kinfo_proc));
|
||||
#elif FF_HAVE_SYSINFO_H
|
||||
uint16_t numProcesses = (uint16_t) instance->state.sysinfo.procs;
|
||||
#else
|
||||
uint16_t numProcesses = 0;
|
||||
#endif
|
||||
|
||||
if(numProcesses == 0)
|
||||
if(error.length > 0)
|
||||
{
|
||||
ffPrintError(instance, FF_PROCESSES_MODULE_NAME, 0, &instance->config.processes, "Could not get number of processes");
|
||||
ffPrintError(instance, FF_PROCESSES_MODULE_NAME, 0, &instance->config.processes, "%*s", error.length, error.chars);
|
||||
ffStrbufDestroy(&error);
|
||||
return;
|
||||
}
|
||||
ffStrbufDestroy(&error);
|
||||
|
||||
if(instance->config.processes.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_PROCESSES_MODULE_NAME, 0, &instance->config.processes.key);
|
||||
|
||||
printf("%hu\n", numProcesses);
|
||||
printf("%u\n", numProcesses);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_PROCESSES_MODULE_NAME, 0, &instance->config.processes, FF_PROCESSES_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_UINT16, &numProcesses}
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &numProcesses}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user