Global: remove caching except image caching

This commit is contained in:
李通洲
2022-12-17 11:39:10 +08:00
parent 6a49ae60a1
commit ff6e982050
23 changed files with 133 additions and 565 deletions
+14 -10
View File
@@ -1,6 +1,5 @@
#include "fastfetch.h"
#include "common/printing.h"
#include "common/caching.h"
#include "detection/bios/bios.h"
#define FF_BIOS_MODULE_NAME "Bios"
@@ -8,9 +7,6 @@
void ffPrintBios(FFinstance* instance)
{
if(ffPrintFromCache(instance, FF_BIOS_MODULE_NAME, &instance->config.bios, FF_BIOS_NUM_FORMAT_ARGS))
return;
FFBiosResult result;
ffDetectBios(&result);
@@ -26,12 +22,20 @@ void ffPrintBios(FFinstance* instance)
goto exit;
}
ffPrintAndWriteToCache(instance, FF_BIOS_MODULE_NAME, &instance->config.bios, &result.biosRelease, FF_BIOS_NUM_FORMAT_ARGS, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_STRBUF, &result.biosDate},
{FF_FORMAT_ARG_TYPE_STRBUF, &result.biosRelease},
{FF_FORMAT_ARG_TYPE_STRBUF, &result.biosVendor},
{FF_FORMAT_ARG_TYPE_STRBUF, &result.biosVersion},
});
if(instance->config.bios.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_BIOS_MODULE_NAME, 0, &instance->config.bios.key);
puts(result.biosRelease.chars);
}
else
{
ffPrintFormat(instance, FF_BIOS_MODULE_NAME, 0, &instance->config.bios, FF_BIOS_NUM_FORMAT_ARGS, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_STRBUF, &result.biosDate},
{FF_FORMAT_ARG_TYPE_STRBUF, &result.biosRelease},
{FF_FORMAT_ARG_TYPE_STRBUF, &result.biosVendor},
{FF_FORMAT_ARG_TYPE_STRBUF, &result.biosVersion},
});
}
exit:
ffStrbufDestroy(&result.biosDate);
+13 -9
View File
@@ -1,6 +1,5 @@
#include "fastfetch.h"
#include "common/printing.h"
#include "common/caching.h"
#include "detection/board/board.h"
#define FF_BOARD_MODULE_NAME "Board"
@@ -8,9 +7,6 @@
void ffPrintBoard(FFinstance* instance)
{
if(ffPrintFromCache(instance, FF_BOARD_MODULE_NAME, &instance->config.board, FF_BOARD_NUM_FORMAT_ARGS))
return;
FFBoardResult result;
ffDetectBoard(&result);
@@ -26,11 +22,19 @@ void ffPrintBoard(FFinstance* instance)
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},
});
if(instance->config.board.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_BOARD_MODULE_NAME, 0, &instance->config.board.key);
puts(result.boardName.chars);
}
else
{
ffPrintFormat(instance, FF_BOARD_MODULE_NAME, 0, &instance->config.board, 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);
-1
View File
@@ -1,6 +1,5 @@
#include "fastfetch.h"
#include "common/printing.h"
#include "common/caching.h"
#include "detection/cpu/cpu.h"
#define FF_CPU_MODULE_NAME "CPU"
+35 -35
View File
@@ -1,6 +1,5 @@
#include "fastfetch.h"
#include "common/printing.h"
#include "common/caching.h"
#include "detection/host/host.h"
#include "detection/gpu/gpu.h"
@@ -9,41 +8,47 @@
#define FF_GPU_MODULE_NAME "GPU"
#define FF_GPU_NUM_FORMAT_ARGS 5
static void printGPUResult(FFinstance* instance, uint8_t index, FFcache* cache, FFGPUResult* gpu)
static void printGPUResult(FFinstance* instance, uint8_t index, FFGPUResult* gpu)
{
FFstrbuf output;
ffStrbufInitA(&output, gpu->vendor.length + 1 + gpu->name.length);
if(gpu->vendor.length > 0 && !ffStrbufStartsWith(&gpu->name, &gpu->vendor))
if(instance->config.gpu.outputFormat.length == 0)
{
ffStrbufAppend(&output, &gpu->vendor);
ffStrbufAppendC(&output, ' ');
ffPrintLogoAndKey(instance, FF_GPU_MODULE_NAME, 0, &instance->config.gpu.key);
FFstrbuf output;
ffStrbufInitA(&output, gpu->vendor.length + 1 + gpu->name.length);
if(gpu->vendor.length > 0 && !ffStrbufStartsWith(&gpu->name, &gpu->vendor))
{
ffStrbufAppend(&output, &gpu->vendor);
ffStrbufAppendC(&output, ' ');
}
ffStrbufAppend(&output, &gpu->name);
if(gpu->coreCount != FF_GPU_CORE_COUNT_UNSET)
ffStrbufAppendF(&output, " (%d)", gpu->coreCount);
if(gpu->temperature == gpu->temperature) //FF_GPU_TEMP_UNSET
ffStrbufAppendF(&output, " - %.1f°C", gpu->temperature);
ffStrbufPutTo(&output, stdout);
ffStrbufDestroy(&output);
}
else
{
ffPrintFormat(instance, FF_GPU_MODULE_NAME, index, &instance->config.gpu, FF_GPU_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &gpu->vendor},
{FF_FORMAT_ARG_TYPE_STRBUF, &gpu->name},
{FF_FORMAT_ARG_TYPE_STRBUF, &gpu->driver},
{FF_FORMAT_ARG_TYPE_DOUBLE, &gpu->temperature},
{FF_FORMAT_ARG_TYPE_INT, &gpu->coreCount},
});
}
ffStrbufAppend(&output, &gpu->name);
if(gpu->coreCount != FF_GPU_CORE_COUNT_UNSET)
ffStrbufAppendF(&output, " (%d)", gpu->coreCount);
if(gpu->temperature == gpu->temperature) //FF_GPU_TEMP_UNSET
ffStrbufAppendF(&output, " - %.1f°C", gpu->temperature);
ffPrintAndAppendToCache(instance, FF_GPU_MODULE_NAME, index, &instance->config.gpu, cache, &output, FF_GPU_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &gpu->vendor},
{FF_FORMAT_ARG_TYPE_STRBUF, &gpu->name},
{FF_FORMAT_ARG_TYPE_STRBUF, &gpu->driver},
{FF_FORMAT_ARG_TYPE_DOUBLE, &gpu->temperature}, //FIXME: temperature shouldn't be cached
{FF_FORMAT_ARG_TYPE_INT, &gpu->coreCount},
});
ffStrbufDestroy(&output);
}
void ffPrintGPU(FFinstance* instance)
{
if(ffPrintFromCache(instance, FF_GPU_MODULE_NAME, &instance->config.gpu, FF_GPU_NUM_FORMAT_ARGS))
return;
const FFlist* gpus = ffDetectGPU(instance);
if(gpus->length == 0)
@@ -52,11 +57,6 @@ void ffPrintGPU(FFinstance* instance)
return;
}
FFcache cache;
ffCacheOpenWrite(instance, FF_GPU_MODULE_NAME, &cache);
for(uint8_t i = 0; i < (uint8_t) gpus->length; i++)
printGPUResult(instance, gpus->length == 1 ? 0 : (uint8_t) (i + 1), &cache, ffListGet(gpus, i));
ffCacheClose(&cache);
printGPUResult(instance, gpus->length == 1 ? 0 : (uint8_t) (i + 1), ffListGet(gpus, i));
}
+32 -27
View File
@@ -1,6 +1,5 @@
#include "fastfetch.h"
#include "common/printing.h"
#include "common/caching.h"
#include "detection/host/host.h"
#define FF_HOST_MODULE_NAME "Host"
@@ -8,9 +7,6 @@
void ffPrintHost(FFinstance* instance)
{
if(ffPrintFromCache(instance, FF_HOST_MODULE_NAME, &instance->config.host, FF_HOST_NUM_FORMAT_ARGS))
return;
const FFHostResult* host = ffDetectHost();
if(host->error.length > 0)
@@ -25,29 +21,38 @@ void ffPrintHost(FFinstance* instance)
return;
}
FFstrbuf output;
ffStrbufInit(&output);
if(host->productName.length > 0)
ffStrbufAppend(&output, &host->productName);
else
ffStrbufAppend(&output, &host->productFamily);
if(host->productVersion.length > 0)
if(instance->config.host.outputFormat.length == 0)
{
ffStrbufAppendF(&output, " (%s)", host->productVersion.chars);
ffPrintLogoAndKey(instance, FF_HOST_MODULE_NAME, 0, &instance->config.host.key);
FFstrbuf output;
ffStrbufInit(&output);
if(host->productName.length > 0)
ffStrbufAppend(&output, &host->productName);
else
ffStrbufAppend(&output, &host->productFamily);
if(host->productVersion.length > 0)
{
ffStrbufAppendF(&output, " (%s)", host->productVersion.chars);
}
ffStrbufPutTo(&output, stdout);
ffStrbufDestroy(&output);
}
else
{
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->chassisType},
{FF_FORMAT_ARG_TYPE_STRBUF, &host->chassisVendor},
{FF_FORMAT_ARG_TYPE_STRBUF, &host->chassisVersion},
{FF_FORMAT_ARG_TYPE_STRBUF, &host->sysVendor}
});
}
ffPrintAndWriteToCache(instance, FF_HOST_MODULE_NAME, &instance->config.host, &output, 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->chassisType},
{FF_FORMAT_ARG_TYPE_STRBUF, &host->chassisVendor},
{FF_FORMAT_ARG_TYPE_STRBUF, &host->chassisVersion},
{FF_FORMAT_ARG_TYPE_STRBUF, &host->sysVendor}
});
ffStrbufDestroy(&output);
}
+11 -7
View File
@@ -1,5 +1,4 @@
#include "fastfetch.h"
#include "common/caching.h"
#include "common/printing.h"
#include "detection/locale/locale.h"
@@ -8,9 +7,6 @@
void ffPrintLocale(FFinstance* instance)
{
if(ffPrintFromCache(instance, FF_LOCALE_MODULE_NAME, &instance->config.locale, FF_LOCALE_NUM_FORMAT_ARGS))
return;
FFstrbuf locale;
ffStrbufInit(&locale);
@@ -21,9 +17,17 @@ void ffPrintLocale(FFinstance* instance)
return;
}
ffPrintAndWriteToCache(instance, FF_LOCALE_MODULE_NAME, &instance->config.locale, &locale, FF_LOCALE_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &locale}
});
if(instance->config.locale.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_LOCALE_MODULE_NAME, 0, &instance->config.locale.key);
ffStrbufPutTo(&locale, stdout);
}
else
{
ffPrintFormat(instance, FF_LOCALE_MODULE_NAME, 0, &instance->config.locale, FF_LOCALE_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &locale}
});
}
ffStrbufDestroy(&locale);
}