mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2025-02-20 11:43:27 +08:00
Board: split out from host; add support for Windows
This commit is contained in:
parent
c7e6e45078
commit
230d2ac39d
@ -224,6 +224,7 @@ set(LIBFASTFETCH_SRC
|
||||
src/modules/os.c
|
||||
src/modules/host.c
|
||||
src/modules/bios.c
|
||||
src/modules/board.c
|
||||
src/modules/kernel.c
|
||||
src/modules/uptime.c
|
||||
src/modules/processes.c
|
||||
@ -288,6 +289,7 @@ if(LINUX OR BSD)
|
||||
list(APPEND LIBFASTFETCH_SRC
|
||||
src/detection/host/host_linux.c
|
||||
src/detection/bios/bios_linux.c
|
||||
src/detection/board/board_linux.c
|
||||
src/detection/os/os_linux.c
|
||||
src/detection/gpu/gpu_linux.c
|
||||
src/detection/battery/battery_linux.c
|
||||
@ -307,6 +309,7 @@ if(WIN_MSYS)
|
||||
list(APPEND LIBFASTFETCH_SRC
|
||||
src/detection/host/host_windows.cpp
|
||||
src/detection/bios/bios_windows.cpp
|
||||
src/detection/board/board_windows.cpp
|
||||
src/detection/os/os_linux.c
|
||||
src/detection/gpu/gpu_linux.c
|
||||
src/detection/battery/battery_linux.c
|
||||
@ -326,6 +329,7 @@ if(APPLE)
|
||||
src/util/apple/osascript.m
|
||||
src/detection/host/host_apple.c
|
||||
src/detection/bios/bios_apple.c
|
||||
src/detection/board/board_apple.c
|
||||
src/detection/os/os_apple.m
|
||||
src/detection/cpu/cpu_apple.c
|
||||
src/detection/gpu/gpu_apple.c
|
||||
@ -353,6 +357,7 @@ if(ANDROID)
|
||||
list(APPEND LIBFASTFETCH_SRC
|
||||
src/detection/host/host_android.c
|
||||
src/detection/bios/bios_android.c
|
||||
src/detection/board/board_android.c
|
||||
src/detection/os/os_android.c
|
||||
src/detection/gpu/gpu_android.c
|
||||
src/detection/battery/battery_android.c
|
||||
|
@ -163,6 +163,7 @@ static void defaultConfig(FFinstance* instance)
|
||||
initModuleArg(&instance->config.os);
|
||||
initModuleArg(&instance->config.host);
|
||||
initModuleArg(&instance->config.bios);
|
||||
initModuleArg(&instance->config.board);
|
||||
initModuleArg(&instance->config.kernel);
|
||||
initModuleArg(&instance->config.uptime);
|
||||
initModuleArg(&instance->config.processes);
|
||||
|
18
src/detection/board/board.h
Normal file
18
src/detection/board/board.h
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef FF_INCLUDED_detection_board_board
|
||||
#define FF_INCLUDED_detection_board_board
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
typedef struct FFBoardResult
|
||||
{
|
||||
FFstrbuf boardName;
|
||||
FFstrbuf boardVendor;
|
||||
FFstrbuf boardVersion;
|
||||
FFstrbuf error;
|
||||
} FFBoardResult;
|
||||
|
||||
void ffDetectBoard(FFBoardResult* result);
|
||||
|
||||
#endif
|
10
src/detection/board/board_android.c
Normal file
10
src/detection/board/board_android.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include "board.h"
|
||||
|
||||
void ffDetectBoard(FFBoardResult* board)
|
||||
{
|
||||
ffStrbufInitS(&board->error, "Not supported on Android");
|
||||
|
||||
ffStrbufInit(&board->boardName);
|
||||
ffStrbufInit(&board->boardVendor);
|
||||
ffStrbufInit(&board->boardVersion);
|
||||
}
|
10
src/detection/board/board_apple.c
Normal file
10
src/detection/board/board_apple.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include "board.h"
|
||||
|
||||
void ffDetectBoard(FFBoardResult* board)
|
||||
{
|
||||
ffStrbufInitS(&board->error, "Not supported on macOS");
|
||||
|
||||
ffStrbufInit(&board->boardName);
|
||||
ffStrbufInit(&board->boardVendor);
|
||||
ffStrbufInit(&board->boardVersion);
|
||||
}
|
55
src/detection/board/board_linux.c
Normal file
55
src/detection/board/board_linux.c
Normal file
@ -0,0 +1,55 @@
|
||||
#include "board.h"
|
||||
#include "common/io.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
static bool hostValueSet(FFstrbuf* value)
|
||||
{
|
||||
return
|
||||
value->length > 0 &&
|
||||
ffStrbufStartsWithIgnCaseS(value, "To be filled") != true &&
|
||||
ffStrbufStartsWithIgnCaseS(value, "To be set") != true &&
|
||||
ffStrbufStartsWithIgnCaseS(value, "OEM") != true &&
|
||||
ffStrbufStartsWithIgnCaseS(value, "O.E.M.") != true &&
|
||||
ffStrbufIgnCaseCompS(value, "None") != 0 &&
|
||||
ffStrbufIgnCaseCompS(value, "System Product") != 0 &&
|
||||
ffStrbufIgnCaseCompS(value, "System Product Name") != 0 &&
|
||||
ffStrbufIgnCaseCompS(value, "System Product Version") != 0 &&
|
||||
ffStrbufIgnCaseCompS(value, "System Name") != 0 &&
|
||||
ffStrbufIgnCaseCompS(value, "System Version") != 0 &&
|
||||
ffStrbufIgnCaseCompS(value, "Default string") != 0 &&
|
||||
ffStrbufIgnCaseCompS(value, "Undefined") != 0 &&
|
||||
ffStrbufIgnCaseCompS(value, "Not Specified") != 0 &&
|
||||
ffStrbufIgnCaseCompS(value, "Not Applicable") != 0 &&
|
||||
ffStrbufIgnCaseCompS(value, "INVALID") != 0 &&
|
||||
ffStrbufIgnCaseCompS(value, "Type1ProductConfigId") != 0 &&
|
||||
ffStrbufIgnCaseCompS(value, "All Series") != 0
|
||||
;
|
||||
}
|
||||
|
||||
static void getHostValue(const char* devicesPath, const char* classPath, FFstrbuf* buffer)
|
||||
{
|
||||
ffReadFileBuffer(devicesPath, buffer);
|
||||
if(hostValueSet(buffer))
|
||||
return;
|
||||
|
||||
ffReadFileBuffer(classPath, buffer);
|
||||
if(hostValueSet(buffer))
|
||||
return;
|
||||
|
||||
ffStrbufClear(buffer);
|
||||
}
|
||||
|
||||
void ffDetectBoard(FFBoardResult* board)
|
||||
{
|
||||
ffStrbufInit(&board->error);
|
||||
|
||||
ffStrbufInit(&board->boardName);
|
||||
getHostValue("/sys/devices/virtual/dmi/id/board_name", "/sys/class/dmi/id/board_name", &board->boardName);
|
||||
|
||||
ffStrbufInit(&board->boardVendor);
|
||||
getHostValue("/sys/devices/virtual/dmi/id/board_vendor", "/sys/class/dmi/id/board_vendor", &board->boardVendor);
|
||||
|
||||
ffStrbufInit(&board->boardVersion);
|
||||
getHostValue("/sys/devices/virtual/dmi/id/board_version", "/sys/class/dmi/id/board_version", &board->boardVersion);
|
||||
}
|
36
src/detection/board/board_windows.cpp
Normal file
36
src/detection/board/board_windows.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
extern "C" {
|
||||
#include "board.h"
|
||||
}
|
||||
#include "util/windows/wmi.hpp"
|
||||
|
||||
extern "C" void ffDetectBoard(FFBoardResult* board)
|
||||
{
|
||||
ffStrbufInit(&board->error);
|
||||
|
||||
ffStrbufInit(&board->boardName);
|
||||
ffStrbufInit(&board->boardVendor);
|
||||
ffStrbufInit(&board->boardVersion);
|
||||
|
||||
IEnumWbemClassObject* pEnumerator = ffQueryWmi(L"SELECT Product, Version, Manufacturer FROM Win32_BaseBoard", &board->error);
|
||||
if(!pEnumerator)
|
||||
return;
|
||||
|
||||
IWbemClassObject *pclsObj = NULL;
|
||||
ULONG uReturn = 0;
|
||||
|
||||
pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
|
||||
|
||||
if(uReturn == 0)
|
||||
{
|
||||
ffStrbufInitS(&board->error, "No Wmi result returned");
|
||||
pEnumerator->Release();
|
||||
return;
|
||||
}
|
||||
|
||||
ffGetWmiObjValue(pclsObj, L"Product", &board->boardName);
|
||||
ffGetWmiObjValue(pclsObj, L"Manufacturer", &board->boardVendor);
|
||||
ffGetWmiObjValue(pclsObj, L"Version", &board->boardVersion);
|
||||
|
||||
pclsObj->Release();
|
||||
pEnumerator->Release();
|
||||
}
|
@ -14,9 +14,6 @@ typedef struct FFHostResult
|
||||
FFstrbuf productName;
|
||||
FFstrbuf productVersion;
|
||||
FFstrbuf productSku;
|
||||
FFstrbuf boardName;
|
||||
FFstrbuf boardVendor;
|
||||
FFstrbuf boardVersion;
|
||||
FFstrbuf chassisType;
|
||||
FFstrbuf chassisVendor;
|
||||
FFstrbuf chassisVersion;
|
||||
|
@ -34,9 +34,6 @@ void ffDetectHostImpl(FFHostResult* host)
|
||||
|
||||
ffStrbufInitA(&host->productVersion, 0);
|
||||
ffStrbufInitA(&host->productSku, 0);
|
||||
ffStrbufInitA(&host->boardName, 0);
|
||||
ffStrbufInitA(&host->boardVendor, 0);
|
||||
ffStrbufInitA(&host->boardVersion, 0);
|
||||
ffStrbufInitA(&host->chassisType, 0);
|
||||
ffStrbufInitA(&host->chassisVendor, 0);
|
||||
ffStrbufInitA(&host->chassisVersion, 0);
|
||||
|
@ -120,9 +120,6 @@ void ffDetectHostImpl(FFHostResult* host)
|
||||
ffStrbufInit(&host->productSku);
|
||||
|
||||
ffStrbufInitA(&host->sysVendor, 0);
|
||||
ffStrbufInitA(&host->boardName, 0);
|
||||
ffStrbufInitA(&host->boardVendor, 0);
|
||||
ffStrbufInitA(&host->boardVersion, 0);
|
||||
ffStrbufInitA(&host->chassisType, 0);
|
||||
ffStrbufInitA(&host->chassisVendor, 0);
|
||||
ffStrbufInitA(&host->chassisVersion, 0);
|
||||
|
@ -74,15 +74,6 @@ void ffDetectHostImpl(FFHostResult* host)
|
||||
ffStrbufInit(&host->productSku);
|
||||
getHostValue("/sys/devices/virtual/dmi/id/product_sku", "/sys/class/dmi/id/product_sku", &host->productSku);
|
||||
|
||||
ffStrbufInit(&host->boardName);
|
||||
getHostValue("/sys/devices/virtual/dmi/id/board_name", "/sys/class/dmi/id/board_name", &host->boardName);
|
||||
|
||||
ffStrbufInit(&host->boardVendor);
|
||||
getHostValue("/sys/devices/virtual/dmi/id/board_vendor", "/sys/class/dmi/id/board_vendor", &host->boardVendor);
|
||||
|
||||
ffStrbufInit(&host->boardVersion);
|
||||
getHostValue("/sys/devices/virtual/dmi/id/board_version", "/sys/class/dmi/id/board_version", &host->boardVersion);
|
||||
|
||||
ffStrbufInit(&host->chassisType);
|
||||
getHostValue("/sys/devices/virtual/dmi/id/chassis_type", "/sys/class/dmi/id/chassis_type", &host->chassisType);
|
||||
|
||||
|
@ -12,9 +12,6 @@ extern "C" void ffDetectHostImpl(FFHostResult* host)
|
||||
ffStrbufInit(&host->productVersion);
|
||||
ffStrbufInit(&host->productSku);
|
||||
ffStrbufInit(&host->sysVendor);
|
||||
ffStrbufInit(&host->boardName);
|
||||
ffStrbufInit(&host->boardVendor);
|
||||
ffStrbufInit(&host->boardVersion);
|
||||
ffStrbufInit(&host->chassisType);
|
||||
ffStrbufInit(&host->chassisVendor);
|
||||
ffStrbufInit(&host->chassisVersion);
|
||||
|
@ -71,14 +71,11 @@ static inline void printCommandHelp(const char* command)
|
||||
}
|
||||
else if(strcasecmp(command, "host-format") == 0)
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("host", "{2} {3}", 11,
|
||||
constructAndPrintCommandHelpFormat("host", "{2} {3}", 8,
|
||||
"product family",
|
||||
"product name",
|
||||
"product version",
|
||||
"product sku",
|
||||
"board name",
|
||||
"board vendor",
|
||||
"board version",
|
||||
"chassis type",
|
||||
"chassis vendor",
|
||||
"chassis version",
|
||||
@ -94,6 +91,14 @@ static inline void printCommandHelp(const char* command)
|
||||
"bios version"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "board-format") == 0)
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("board", "{2} {3}", 3,
|
||||
"board name",
|
||||
"board vendor",
|
||||
"board version"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "kernel-format") == 0)
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("kernel", "{2}", 3,
|
||||
@ -1380,6 +1385,8 @@ static void parseStructureCommand(FFinstance* instance, FFdata* data, const char
|
||||
ffPrintHost(instance);
|
||||
else if(strcasecmp(line, "bios") == 0)
|
||||
ffPrintBios(instance);
|
||||
else if(strcasecmp(line, "board") == 0)
|
||||
ffPrintBoard(instance);
|
||||
else if(strcasecmp(line, "kernel") == 0)
|
||||
ffPrintKernel(instance);
|
||||
else if(strcasecmp(line, "uptime") == 0)
|
||||
|
@ -95,6 +95,7 @@ typedef struct FFconfig
|
||||
FFModuleArgs os;
|
||||
FFModuleArgs host;
|
||||
FFModuleArgs bios;
|
||||
FFModuleArgs board;
|
||||
FFModuleArgs kernel;
|
||||
FFModuleArgs uptime;
|
||||
FFModuleArgs processes;
|
||||
@ -251,6 +252,7 @@ void ffPrintSeparator(FFinstance* instance);
|
||||
void ffPrintOS(FFinstance* instance);
|
||||
void ffPrintHost(FFinstance* instance);
|
||||
void ffPrintBios(FFinstance* instance);
|
||||
void ffPrintBoard(FFinstance* instance);
|
||||
void ffPrintKernel(FFinstance* instance);
|
||||
void ffPrintUptime(FFinstance* instance);
|
||||
void ffPrintProcesses(FFinstance* instance);
|
||||
|
@ -23,6 +23,7 @@ int main(int argc, char** argv)
|
||||
ffPrintOS(&instance);
|
||||
ffPrintHost(&instance);
|
||||
//ffPrintBios(&instance);
|
||||
//ffPrintBoard(&instance);
|
||||
ffPrintKernel(&instance);
|
||||
ffPrintUptime(&instance);
|
||||
//ffPrintProcesses(&instance);
|
||||
|
40
src/modules/board.c
Normal file
40
src/modules/board.c
Normal file
@ -0,0 +1,40 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "common/caching.h"
|
||||
#include "detection/board/board.h"
|
||||
|
||||
#define FF_BOARD_MODULE_NAME "Board"
|
||||
#define FF_BOARD_NUM_FORMAT_ARGS 3
|
||||
|
||||
void ffPrintBoard(FFinstance* instance)
|
||||
{
|
||||
if(ffPrintFromCache(instance, FF_BOARD_MODULE_NAME, &instance->config.board, FF_BOARD_NUM_FORMAT_ARGS))
|
||||
return;
|
||||
|
||||
FFBoardResult result;
|
||||
ffDetectBoard(&result);
|
||||
|
||||
if(result.error.length > 0)
|
||||
{
|
||||
ffPrintError(instance, FF_BOARD_MODULE_NAME, 0, &instance->config.board, "%*s", result.error.length, result.error.chars);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if(result.boardName.length == 0)
|
||||
{
|
||||
ffPrintError(instance, FF_BOARD_MODULE_NAME, 0, &instance->config.board, "board_name is not set.");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ffPrintAndWriteToCache(instance, FF_BOARD_MODULE_NAME, &instance->config.board, &result.boardName, FF_BOARD_NUM_FORMAT_ARGS, (FFformatarg[]) {
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result.boardName},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result.boardVendor},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result.boardVersion},
|
||||
});
|
||||
|
||||
exit:
|
||||
ffStrbufDestroy(&result.boardName);
|
||||
ffStrbufDestroy(&result.boardVendor);
|
||||
ffStrbufDestroy(&result.boardVersion);
|
||||
ffStrbufDestroy(&result.error);
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
#include "detection/host/host.h"
|
||||
|
||||
#define FF_HOST_MODULE_NAME "Host"
|
||||
#define FF_HOST_NUM_FORMAT_ARGS 11
|
||||
#define FF_HOST_NUM_FORMAT_ARGS 8
|
||||
|
||||
void ffPrintHost(FFinstance* instance)
|
||||
{
|
||||
@ -44,9 +44,6 @@ void ffPrintHost(FFinstance* instance)
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &host->productName},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &host->productVersion},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &host->productSku},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &host->boardName},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &host->boardVendor},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &host->boardVersion},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &host->chassisType},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &host->chassisVendor},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &host->chassisVersion},
|
||||
|
Loading…
x
Reference in New Issue
Block a user