2021-02-18 22:25:36 +01:00
|
|
|
#include "fastfetch.h"
|
2022-07-25 13:15:01 +02:00
|
|
|
#include "common/printing.h"
|
2022-09-04 12:43:30 +02:00
|
|
|
#include "detection/host/host.h"
|
2022-01-10 15:20:51 +01:00
|
|
|
|
2021-04-15 18:59:26 +02:00
|
|
|
#define FF_HOST_MODULE_NAME "Host"
|
2022-12-24 22:48:10 +08:00
|
|
|
#define FF_HOST_NUM_FORMAT_ARGS 5
|
2021-04-15 18:59:26 +02:00
|
|
|
|
2021-02-27 18:30:05 +01:00
|
|
|
void ffPrintHost(FFinstance* instance)
|
2021-02-18 22:25:36 +01:00
|
|
|
{
|
2022-09-04 12:43:30 +02:00
|
|
|
const FFHostResult* host = ffDetectHost();
|
2021-06-16 10:50:16 +02:00
|
|
|
|
2022-10-05 00:41:43 +08:00
|
|
|
if(host->error.length > 0)
|
|
|
|
|
{
|
|
|
|
|
ffPrintError(instance, FF_HOST_MODULE_NAME, 0, &instance->config.host, "%*s", host->error.length, host->error.chars);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-04 12:43:30 +02:00
|
|
|
if(host->productFamily.length == 0 && host->productName.length == 0)
|
2021-04-03 21:51:50 +02:00
|
|
|
{
|
2022-06-17 18:15:36 +02:00
|
|
|
ffPrintError(instance, FF_HOST_MODULE_NAME, 0, &instance->config.host, "neither product_family nor product_name is set by O.E.M.");
|
2021-04-03 21:51:50 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-17 11:39:10 +08:00
|
|
|
if(instance->config.host.outputFormat.length == 0)
|
|
|
|
|
{
|
|
|
|
|
ffPrintLogoAndKey(instance, FF_HOST_MODULE_NAME, 0, &instance->config.host.key);
|
2021-03-19 20:57:07 +01:00
|
|
|
|
2022-12-17 11:39:10 +08:00
|
|
|
FFstrbuf output;
|
|
|
|
|
ffStrbufInit(&output);
|
|
|
|
|
|
|
|
|
|
if(host->productName.length > 0)
|
|
|
|
|
ffStrbufAppend(&output, &host->productName);
|
|
|
|
|
else
|
|
|
|
|
ffStrbufAppend(&output, &host->productFamily);
|
2021-04-15 18:59:26 +02:00
|
|
|
|
2022-12-17 11:39:10 +08:00
|
|
|
if(host->productVersion.length > 0)
|
|
|
|
|
{
|
|
|
|
|
ffStrbufAppendF(&output, " (%s)", host->productVersion.chars);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ffStrbufPutTo(&output, stdout);
|
|
|
|
|
|
|
|
|
|
ffStrbufDestroy(&output);
|
|
|
|
|
}
|
|
|
|
|
else
|
2021-06-16 10:50:16 +02:00
|
|
|
{
|
2022-12-17 11:39:10 +08:00
|
|
|
ffPrintFormat(instance, FF_HOST_MODULE_NAME, 0, &instance->config.host, FF_HOST_NUM_FORMAT_ARGS, (FFformatarg[]) {
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, &host->productFamily},
|
|
|
|
|
{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->sysVendor}
|
|
|
|
|
});
|
2021-03-23 19:48:52 +01:00
|
|
|
}
|
2021-03-27 18:14:19 +01:00
|
|
|
}
|