From ff6e98205004225d6c7271dbcfb9a21f417c75f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 17 Dec 2022 11:39:10 +0800 Subject: [PATCH] Global: remove caching except image caching --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- .github/workflows/push.yml | 10 +- CMakeLists.txt | 1 - completions/bash | 2 - presets/devinfo | 1 - src/common/caching.c | 327 --------------------------- src/common/caching.h | 33 --- src/common/init.c | 37 --- src/data/config_user.txt | 1 - src/data/help.txt | 2 - src/detection/cpu/cpu.c | 27 +-- src/detection/cpu/cpu_apple.c | 35 ++- src/detection/cpu/cpu_bsd.c | 5 +- src/detection/cpu/cpu_linux.c | 5 +- src/detection/cpu/cpu_windows.c | 6 +- src/fastfetch.c | 9 +- src/fastfetch.h | 1 - src/modules/bios.c | 24 +- src/modules/board.c | 22 +- src/modules/cpu.c | 1 - src/modules/gpu.c | 70 +++--- src/modules/host.c | 59 ++--- src/modules/locale.c | 18 +- 23 files changed, 133 insertions(+), 565 deletions(-) delete mode 100644 src/common/caching.c delete mode 100644 src/common/caching.h diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 5492b9ea2..0fb775db3 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -39,5 +39,5 @@ Output of `fastfetch --list-features`: diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index c798e81d5..3e40c83b2 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -35,7 +35,7 @@ jobs: uses: github/codeql-action/analyze@v2 - name: run fastfetch - run: time ./fastfetch --recache --disable-linewrap false --hide-cursor false --show-errors true --load-config presets/all + run: time ./fastfetch --disable-linewrap false --hide-cursor false --show-errors true --load-config presets/all - name: run flashfetch run: time ./flashfetch @@ -81,7 +81,7 @@ jobs: uses: github/codeql-action/analyze@v2 - name: run fastfetch - run: time ./fastfetch --recache --disable-linewrap false --hide-cursor false --show-errors true --load-config presets/all + run: time ./fastfetch --disable-linewrap false --hide-cursor false --show-errors true --load-config presets/all - name: run flashfetch run: time ./flashfetch @@ -113,7 +113,7 @@ jobs: run: | cmake -DSET_TWEAK=Off -DBUILD_TESTS=On . cmake --build . --target package - time ./fastfetch --recache --disable-linewrap false --hide-cursor false --show-errors true --load-config presets/all + time ./fastfetch --disable-linewrap false --hide-cursor false --show-errors true --load-config presets/all time ./flashfetch ctest @@ -180,7 +180,7 @@ jobs: run: cp /clang64/bin/{libcjson,libOpenCL,vulkan-1}.dll . - name: run fastfetch - run: time ./fastfetch --recache --disable-linewrap false --hide-cursor false --show-errors true --load-config presets/all + run: time ./fastfetch --disable-linewrap false --hide-cursor false --show-errors true --load-config presets/all - name: run flashfetch run: time ./flashfetch @@ -254,7 +254,7 @@ jobs: run: cp /mingw64/bin/{libcjson,libOpenCL,vulkan-1}.dll . - name: run fastfetch - run: time ./fastfetch --recache --disable-linewrap false --hide-cursor false --show-errors true --load-config presets/all + run: time ./fastfetch --disable-linewrap false --hide-cursor false --show-errors true --load-config presets/all - name: run flashfetch run: time ./flashfetch diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f49a1265..c7f8bcb34 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -221,7 +221,6 @@ configure_file(src/fastfetch_config.h.in fastfetch_config.h) set(LIBFASTFETCH_SRC src/common/bar.c - src/common/caching.c src/common/font.c src/common/format.c src/common/init.c diff --git a/completions/bash b/completions/bash index ca9e760ef..10356ce85 100644 --- a/completions/bash +++ b/completions/bash @@ -169,8 +169,6 @@ __fastfetch_completion() local FF_OPTIONS_BOOL=( "-r" - "--recache" - "--nocache" "--show-errors" "--logo-print-remaining" "--multithreading" diff --git a/presets/devinfo b/presets/devinfo index 57859baad..2ddf030b5 100644 --- a/presets/devinfo +++ b/presets/devinfo @@ -1,4 +1,3 @@ --disable-linewrap false --multithreading false --show-errors ---recache diff --git a/src/common/caching.c b/src/common/caching.c deleted file mode 100644 index 14551b120..000000000 --- a/src/common/caching.c +++ /dev/null @@ -1,327 +0,0 @@ -#include "fastfetch.h" -#include "common/caching.h" -#include "common/io.h" -#include "common/printing.h" - -#include -#include - -#define FF_CACHE_VERSION_NAME "cacheversion" -#define FF_CACHE_VERSION_EXTENSION "ffv" - -#define FF_CACHE_VALUE_EXTENSION "ffcv" -#define FF_CACHE_SPLIT_EXTENSION "ffcs" - -#define FF_CACHE_EXTENSION_V1 "ffc1" - -static void getCacheFilePath(const FFinstance* instance, const char* moduleName, const char* extension, FFstrbuf* buffer) -{ - ffStrbufAppend(buffer, &instance->state.cacheDir); - ffStrbufAppendS(buffer, moduleName); - - if(extension != NULL) - { - ffStrbufAppendC(buffer, '.'); - ffStrbufAppendS(buffer, extension); - } -} - -static void readCacheFile(FFinstance* instance, const char* moduleName, const char* extension, FFstrbuf* buffer) -{ - FFstrbuf path; - ffStrbufInitA(&path, 64); - getCacheFilePath(instance, moduleName, extension, &path); - ffAppendFileBuffer(path.chars, buffer); - ffStrbufDestroy(&path); -} - -static void writeCacheFile(FFinstance* instance, const char* moduleName, const char* extension, FFstrbuf* content) -{ - FFstrbuf path; - ffStrbufInitA(&path, 64); - getCacheFilePath(instance, moduleName, extension, &path); - ffWriteFileBuffer(path.chars, content); - ffStrbufDestroy(&path); -} - -void ffCacheValidate(FFinstance* instance) -{ - FFstrbuf content; - ffStrbufInit(&content); - readCacheFile(instance, FF_CACHE_VERSION_NAME, FF_CACHE_VERSION_EXTENSION, &content); - - const char exactVersion[] = FASTFETCH_PROJECT_VERSION FASTFETCH_PROJECT_VERSION_TWEAK; - - bool isSameVersion = ffStrbufCompS(&content, exactVersion) == 0; - ffStrbufDestroy(&content); - if(isSameVersion) - return; - - instance->config.recache = true; - - FFstrbuf version; - ffStrbufInitA(&version, sizeof(exactVersion)); - ffStrbufAppendS(&version, exactVersion); - writeCacheFile(instance, FF_CACHE_VERSION_NAME, FF_CACHE_VERSION_EXTENSION, &version); - ffStrbufDestroy(&version); -} - -void ffCacheOpenWrite(FFinstance* instance, const char* moduleName, FFcache* cache) -{ - FFstrbuf cacheFileValue; - ffStrbufInitA(&cacheFileValue, 64); - getCacheFilePath(instance, moduleName, FF_CACHE_VALUE_EXTENSION, &cacheFileValue); - cache->value = fopen(cacheFileValue.chars, "w"); - ffStrbufDestroy(&cacheFileValue); - - FFstrbuf cacheFileSplit; - ffStrbufInitA(&cacheFileSplit, 64); - getCacheFilePath(instance, moduleName, FF_CACHE_SPLIT_EXTENSION, &cacheFileSplit); - cache->split = fopen(cacheFileSplit.chars, "w"); - ffStrbufDestroy(&cacheFileSplit); -} - -void ffCacheClose(FFcache* cache) -{ - if(cache->value != NULL) - fclose(cache->value); - - if(cache->split != NULL) - fclose(cache->split); -} - -static bool printCachedValue(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs) -{ - FFstrbuf content; - ffStrbufInitA(&content, 512); - readCacheFile(instance, moduleName, FF_CACHE_VALUE_EXTENSION, &content); - - ffStrbufTrimRight(&content, '\0'); //Strbuf always appends a '\0' at the end. We want the last null byte to be at the position of the length - - if(content.length == 0) - { - ffStrbufDestroy(&content); - return false; - } - - uint8_t moduleCounter = 1; - - uint32_t startIndex = 0; - while(startIndex < content.length) - { - uint32_t nullByteIndex = ffStrbufNextIndexC(&content, startIndex, '\0'); - uint8_t moduleIndex = (moduleCounter == 1 && nullByteIndex == content.length) ? 0 : moduleCounter; - ffPrintLogoAndKey(instance, moduleName, moduleIndex, &moduleArgs->key); - puts(content.chars + startIndex); - startIndex = nullByteIndex + 1; - ++moduleCounter; - } - - ffStrbufDestroy(&content); - - return moduleCounter > 1; -} - -static bool printCachedFormat(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs, uint32_t numArgs) -{ - FFstrbuf content; - ffStrbufInitA(&content, 512); - readCacheFile(instance, moduleName, FF_CACHE_SPLIT_EXTENSION, &content); - - ffStrbufTrimRight(&content, '\0'); //Strbuf always appends a '\0' at the end. We want the last null byte to be at the position of the length - - if(content.length == 0) - return false; - - uint8_t moduleCounter = 1; - - FFformatarg* arguments = calloc(numArgs, sizeof(FFformatarg)); - uint32_t argumentCounter = 0; - - uint32_t startIndex = 0; - while(startIndex < content.length) - { - arguments[argumentCounter].type = FF_FORMAT_ARG_TYPE_STRING; - arguments[argumentCounter].value = &content.chars[startIndex]; - ++argumentCounter; - - uint32_t nullByteIndex = ffStrbufNextIndexC(&content, startIndex, '\0'); - - if(argumentCounter == numArgs) - { - uint8_t moduleIndex = (moduleCounter == 1 && nullByteIndex == content.length) ? 0 : moduleCounter; - ffPrintFormat(instance, moduleName, moduleIndex, moduleArgs, numArgs, arguments); - ++moduleCounter; - argumentCounter = 0; - } - - startIndex = nullByteIndex + 1; - } - - free(arguments); - ffStrbufDestroy(&content); - - return moduleCounter > 1; -} - -bool ffPrintFromCache(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs, uint32_t numArgs) -{ - if(instance->config.recache) - return false; - - if(moduleArgs->outputFormat.length == 0) - return printCachedValue(instance, moduleName, moduleArgs); - else - return printCachedFormat(instance, moduleName, moduleArgs, numArgs); -} - -void ffPrintAndAppendToCache(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFcache* cache, const FFstrbuf* value, uint32_t numArgs, const FFformatarg* arguments) -{ - if(moduleArgs->outputFormat.length == 0) - { - ffPrintLogoAndKey(instance, moduleName, moduleIndex, &moduleArgs->key); - ffStrbufPutTo(value, stdout); - } - else - { - ffPrintFormat(instance, moduleName, moduleIndex, moduleArgs, numArgs, arguments); - } - - if(cache->value != NULL) - { - ffStrbufWriteTo(value, cache->value); - fputc('\0', cache->value); - } - - if(cache->split == NULL) - return; - - for(uint32_t i = 0; i < numArgs; i++) - { - FFstrbuf buffer; - ffStrbufInitA(&buffer, 64); - ffFormatAppendFormatArg(&buffer, &arguments[i]); - ffStrbufWriteTo(&buffer, cache->split); - ffStrbufDestroy(&buffer); - fputc('\0', cache->split); - } -} - -void ffPrintAndWriteToCache(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs, const FFstrbuf* value, uint32_t numArgs, const FFformatarg* arguments) -{ - FFcache cache; - ffCacheOpenWrite(instance, moduleName, &cache); - ffPrintAndAppendToCache(instance, moduleName, 0, moduleArgs, &cache, value, numArgs, arguments); - ffCacheClose(&cache); -} - -typedef struct FFCacheRead -{ - FFstrbuf data; - uint32_t position; -} FFCacheRead; - -static bool cacheReadStrbuf(FFCacheRead* cacheRead, FFstrbuf* strbuf) -{ - if(cacheRead->position >= cacheRead->data.length) - return false; - - ffStrbufAppendS(strbuf, cacheRead->data.chars + cacheRead->position); - cacheRead->position += strbuf->length + 1; // skip the null byte too - return true; -} - -static bool cacheReadData(FFCacheRead* cacheRead, size_t dataSize, void* data) -{ - if(cacheRead->position + dataSize > cacheRead->data.length) - return false; - - memcpy(data, cacheRead->data.chars + cacheRead->position, dataSize); - cacheRead->position += (uint32_t) dataSize; - return true; -} - -static bool cacheResetStrbuf(FFCache* cache, FFstrbuf* strbuf) -{ - FF_UNUSED(cache); - ffStrbufClear(strbuf); - return true; -} - -static bool cacheResetData(FFCache* cacheRead, size_t dataSize, void* data) -{ - FF_UNUSED(cacheRead, dataSize, data); - return true; -} - -bool ffCacheRead(const FFinstance* instance, void* obj, const char* cacheName, FFCacheMethodCallback callback) -{ - if(instance->config.recache) - return false; - - FFCacheRead cache; - bool result; - - FFstrbuf path; - ffStrbufInitA(&path, 128); - getCacheFilePath(instance, cacheName, FF_CACHE_EXTENSION_V1, &path); - - cache.position = 0; - - ffStrbufInitA(&cache.data, 256); - result = ffAppendFileBuffer(path.chars, &cache.data); - - if(result) - result = callback(obj, &cache, (FFCacheMethodStrbuf) cacheReadStrbuf, (FFCacheMethodData) cacheReadData); - - if(result) - result = cache.position == cache.data.length; - - if(!result) - callback(obj, NULL, (FFCacheMethodStrbuf) cacheResetStrbuf, (FFCacheMethodData) cacheResetData); - - ffStrbufDestroy(&cache.data); - ffStrbufDestroy(&path); - - return result; -} - -typedef struct FFCacheWrite -{ - FFstrbuf data; -} FFCacheWrite; - -static bool cacheWriteStrbuf(FFCacheWrite* cacheWrite, FFstrbuf* strbuf) -{ - ffStrbufEnsureFree(&cacheWrite->data, strbuf->length); - memcpy(cacheWrite->data.chars + cacheWrite->data.length, strbuf->chars, strbuf->length +1); //Copy the nullbyte too - cacheWrite->data.length += strbuf->length + 1; - return true; -} - -static bool cacheWriteData(FFCacheWrite* cacheWrite, size_t dataSize, const void* data) -{ - ffStrbufEnsureFree(&cacheWrite->data, (uint32_t) dataSize); - memcpy(cacheWrite->data.chars + cacheWrite->data.length, data, dataSize); - cacheWrite->data.length += (uint32_t) dataSize; - return true; -} - -void ffCacheWrite(const FFinstance* instance, void* obj, const char* cacheName, FFCacheMethodCallback callback) -{ - if(!instance->config.cacheSave) - return; - - FFCacheWrite cache; - - FFstrbuf path; - ffStrbufInitA(&path, 128); - getCacheFilePath(instance, cacheName, FF_CACHE_EXTENSION_V1, &path); - - ffStrbufInitA(&cache.data, 256); - callback(obj, &cache, (FFCacheMethodStrbuf) cacheWriteStrbuf, (FFCacheMethodData) cacheWriteData); - ffWriteFileBuffer(path.chars, &cache.data); - - ffStrbufDestroy(&cache.data); - ffStrbufDestroy(&path); -} diff --git a/src/common/caching.h b/src/common/caching.h deleted file mode 100644 index d8e17d473..000000000 --- a/src/common/caching.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#ifndef FF_INCLUDED_common_caching -#define FF_INCLUDED_common_caching - -#include "fastfetch.h" -#include "common/format.h" - -typedef struct FFcache -{ - FILE* value; - FILE* split; -} FFcache; - -void ffCacheValidate(FFinstance* instance); - -void ffCacheOpenWrite(FFinstance* instance, const char* moduleName, FFcache* cache); -void ffCacheClose(FFcache* cache); - -bool ffPrintFromCache(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs, uint32_t numArgs); -void ffPrintAndAppendToCache(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFcache* cache, const FFstrbuf* value, uint32_t numArgs, const FFformatarg* arguments); -void ffPrintAndWriteToCache(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs, const FFstrbuf* value, uint32_t numArgs, const FFformatarg* arguments); - -typedef void FFCache; - -typedef bool(*FFCacheMethodStrbuf)(FFCache* cache, FFstrbuf* strbuf); -typedef bool(*FFCacheMethodData)(FFCache* cache, size_t dataSize, void* data); -typedef bool(*FFCacheMethodCallback)(void* data, FFCache* cache, FFCacheMethodStrbuf strbufMethod, FFCacheMethodData dataMethod); - -bool ffCacheRead(const FFinstance* instance, void* obj, const char* cacheName, FFCacheMethodCallback callback); -void ffCacheWrite(const FFinstance* instance, void* obj, const char* cacheName, FFCacheMethodCallback callback); - -#endif diff --git a/src/common/init.c b/src/common/init.c index b81b2933f..948d5ab88 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -1,5 +1,4 @@ #include "fastfetch.h" -#include "common/caching.h" #include "common/parsing.h" #include "common/thread.h" #include "detection/qt.h" @@ -88,34 +87,6 @@ static void initConfigDirs(FFstate* state) #undef FF_ENSURE_ONLY_ONCE_IN_LIST } -static void initCacheDir(FFstate* state) -{ - ffStrbufInitA(&state->cacheDir, 64); - - ffStrbufAppendS(&state->cacheDir, getenv("XDG_CACHE_HOME")); - - if(state->cacheDir.length == 0) - { - ffStrbufAppendS(&state->cacheDir, state->passwd->pw_dir); - ffStrbufAppendS(&state->cacheDir, "/.cache/"); - } - else - ffStrbufEnsureEndsWithC(&state->cacheDir, '/'); - - mkdir(state->cacheDir.chars - #ifndef WIN32 - , S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH - #endif - ); //I hope everybody has a cache folder, but who knows - - ffStrbufAppendS(&state->cacheDir, "fastfetch/"); - mkdir(state->cacheDir.chars - #ifndef WIN32 - , S_IRWXU | S_IRGRP | S_IROTH - #endif - ); -} - static void initState(FFstate* state) { #ifdef WIN32 @@ -138,7 +109,6 @@ static void initState(FFstate* state) #endif initConfigDirs(state); - initCacheDir(state); } static void initModuleArg(FFModuleArgs* args) @@ -168,7 +138,6 @@ static void defaultConfig(FFinstance* instance) instance->config.showErrors = false; instance->config.recache = false; - instance->config.cacheSave = true; instance->config.allowSlowOperations = false; instance->config.disableLinewrap = true; instance->config.hideCursor = true; @@ -373,10 +342,6 @@ void ffStart(FFinstance* instance) sigaction(SIGQUIT, &action, NULL); #endif - //We do the cache validation here, so we can skip it if --recache is given - if(!instance->config.recache) - ffCacheValidate(instance); - //reset everything to default before we start printing if(!instance->config.pipe) fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout); @@ -495,8 +460,6 @@ static void destroyState(FFinstance* instance) for(uint32_t i = 0; i < instance->state.configDirs.length; ++i) ffStrbufDestroy((FFstrbuf*)ffListGet(&instance->state.configDirs, i)); ffListDestroy(&instance->state.configDirs); - - ffStrbufDestroy(&instance->state.cacheDir); } void ffDestroyInstance(FFinstance* instance) diff --git a/src/data/config_user.txt b/src/data/config_user.txt index fe65a9ee4..2fc0b41fa 100644 --- a/src/data/config_user.txt +++ b/src/data/config_user.txt @@ -185,7 +185,6 @@ # OS file option # Sets the path to the file containing the operating system information. # Should be a valid path to an existing file. -# Note that you might need to run fastfetch with --recache once for it to take affect. # Default is /etc/os-release. #--os-file /etc/os-release diff --git a/src/data/help.txt b/src/data/help.txt index f6579cfde..d65071462 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -14,8 +14,6 @@ Informative options: --print-structure: prints the default stucture and exits General options: - -r,--recache : generate new cached values - --nocache : don't use cached values, but also don't overwrite existing ones --load-config : load a config file or a preset (+) --multithreading : use multiple threads to detect values --stat : print time usage (in ms) for individual modules diff --git a/src/detection/cpu/cpu.c b/src/detection/cpu/cpu.c index 3bfe92e87..62537aaa8 100644 --- a/src/detection/cpu/cpu.c +++ b/src/detection/cpu/cpu.c @@ -1,34 +1,13 @@ #include "cpu.h" -#include "common/caching.h" #include "detection/internal.h" -#define FF_CPU_CACHE_NAME "cpu" - -void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu, bool cached); - -static bool cacheCallback(FFCPUResult* cpu, FFCache* cache, FFCacheMethodStrbuf strbufMethod, FFCacheMethodData dataMethod) -{ - return - strbufMethod(cache, &cpu->vendor) && - strbufMethod(cache, &cpu->name) && - dataMethod(cache, sizeof(cpu->coresPhysical), &cpu->coresPhysical) && - dataMethod(cache, sizeof(cpu->coresLogical), &cpu->coresLogical) && - dataMethod(cache, sizeof(cpu->coresOnline), &cpu->coresOnline) && - dataMethod(cache, sizeof(cpu->frequencyMin), &cpu->frequencyMin) && - dataMethod(cache, sizeof(cpu->frequencyMax), &cpu->frequencyMax); -} - +void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu); static void detectCPU(const FFinstance* instance, FFCPUResult* cpu) { ffStrbufInit(&cpu->name); ffStrbufInit(&cpu->vendor); - bool cached = ffCacheRead(instance, cpu, FF_CPU_CACHE_NAME, (FFCacheMethodCallback) cacheCallback); - - ffDetectCPUImpl(instance, cpu, cached); - - if(cached) - return; + ffDetectCPUImpl(instance, cpu); const char* removeStrings[] = { " CPU", " FPU", " APU", " Processor", @@ -39,8 +18,6 @@ static void detectCPU(const FFinstance* instance, FFCPUResult* cpu) ffStrbufRemoveStringsA(&cpu->name, sizeof(removeStrings) / sizeof(removeStrings[0]), removeStrings); ffStrbufSubstrBeforeFirstC(&cpu->name, '@'); //Cut the speed output in the name as we append our own ffStrbufTrimRight(&cpu->name, ' '); //If we removed the @ in previous step there was most likely a space before it - - ffCacheWrite(instance, cpu, FF_CPU_CACHE_NAME, (FFCacheMethodCallback) cacheCallback); } const FFCPUResult* ffDetectCPU(const FFinstance* instance) diff --git a/src/detection/cpu/cpu_apple.c b/src/detection/cpu/cpu_apple.c index 5f1b35494..3de61f93d 100644 --- a/src/detection/cpu/cpu_apple.c +++ b/src/detection/cpu/cpu_apple.c @@ -41,32 +41,29 @@ static double detectCpuTemp(const FFstrbuf* cpuName) return result; } -void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu, bool cached) +void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu) { FF_UNUSED(instance); - if(!cached) - { - ffSysctlGetString("machdep.cpu.brand_string", &cpu->name); - ffSysctlGetString("machdep.cpu.vendor", &cpu->vendor); + ffSysctlGetString("machdep.cpu.brand_string", &cpu->name); + ffSysctlGetString("machdep.cpu.vendor", &cpu->vendor); - cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.physicalcpu_max", 1); - if(cpu->coresPhysical == 1) - cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.physicalcpu", 1); + cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.physicalcpu_max", 1); + if(cpu->coresPhysical == 1) + cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.physicalcpu", 1); - cpu->coresLogical = (uint16_t) ffSysctlGetInt("hw.logicalcpu_max", 1); - if(cpu->coresLogical == 1) - cpu->coresLogical = (uint16_t) ffSysctlGetInt("hw.ncpu", 1); + cpu->coresLogical = (uint16_t) ffSysctlGetInt("hw.logicalcpu_max", 1); + if(cpu->coresLogical == 1) + cpu->coresLogical = (uint16_t) ffSysctlGetInt("hw.ncpu", 1); - cpu->coresOnline = (uint16_t) ffSysctlGetInt("hw.logicalcpu", 1); - if(cpu->coresOnline == 1) - cpu->coresOnline = (uint16_t) ffSysctlGetInt("hw.activecpu", 1); + cpu->coresOnline = (uint16_t) ffSysctlGetInt("hw.logicalcpu", 1); + if(cpu->coresOnline == 1) + cpu->coresOnline = (uint16_t) ffSysctlGetInt("hw.activecpu", 1); - cpu->frequencyMin = getFrequency("hw.cpufrequency_min"); - cpu->frequencyMax = getFrequency("hw.cpufrequency_max"); - if(cpu->frequencyMax == 0.0) - cpu->frequencyMax = getFrequency("hw.cpufrequency"); - } + cpu->frequencyMin = getFrequency("hw.cpufrequency_min"); + cpu->frequencyMax = getFrequency("hw.cpufrequency_max"); + if(cpu->frequencyMax == 0.0) + cpu->frequencyMax = getFrequency("hw.cpufrequency"); if (instance->config.cpuTemp) cpu->temperature = detectCpuTemp(&cpu->name); diff --git a/src/detection/cpu/cpu_bsd.c b/src/detection/cpu/cpu_bsd.c index 6f71f1ef6..2308c8985 100644 --- a/src/detection/cpu/cpu_bsd.c +++ b/src/detection/cpu/cpu_bsd.c @@ -1,7 +1,7 @@ #include "cpu.h" #include "common/sysctl.h" -void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu, bool cached) +void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu) { FF_UNUSED(instance); @@ -17,9 +17,6 @@ void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu, bool cached) else cpu->temperature = FF_CPU_TEMP_UNSET; - if(cached) - return; - ffSysctlGetString("hw.model", &cpu->name); cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.ncpu", 1); diff --git a/src/detection/cpu/cpu_linux.c b/src/detection/cpu/cpu_linux.c index ea1c45a69..ee68f1e6f 100644 --- a/src/detection/cpu/cpu_linux.c +++ b/src/detection/cpu/cpu_linux.c @@ -82,16 +82,13 @@ static double detectCPUTemp(const FFinstance* instance) return FF_CPU_TEMP_UNSET; } -void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu, bool cached) +void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu) { if(instance->config.cpuTemp) cpu->temperature = detectCPUTemp(instance); else cpu->temperature = FF_CPU_TEMP_UNSET; - if(cached) - return; - FFstrbuf physicalCoresBuffer; ffStrbufInit(&physicalCoresBuffer); diff --git a/src/detection/cpu/cpu_windows.c b/src/detection/cpu/cpu_windows.c index acef000bc..84af8ecfb 100644 --- a/src/detection/cpu/cpu_windows.c +++ b/src/detection/cpu/cpu_windows.c @@ -2,15 +2,11 @@ #include "util/windows/registry.h" #include "util/mallocHelper.h" -void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu, bool cached) +void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu) { FF_UNUSED(instance); cpu->temperature = FF_CPU_TEMP_UNSET; - - if(cached) - return; - cpu->coresPhysical = cpu->coresLogical = cpu->coresOnline = 0; cpu->frequencyMax = cpu->frequencyMin = 0; ffStrbufInit(&cpu->name); diff --git a/src/fastfetch.c b/src/fastfetch.c index 66c2ebb40..be62bb4ad 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -895,16 +895,9 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con /////////////////// else if(strcasecmp(key, "-r") == 0 || strcasecmp(key, "--recache") == 0) - { - //Set cacheSave as well, because the user expects the values to be cached when expliciting using --recache instance->config.recache = optionParseBoolean(value); - instance->config.cacheSave = instance->config.recache; - } else if(strcasecmp(key, "--nocache") == 0) - { - instance->config.recache = optionParseBoolean(value); - instance->config.cacheSave = false; - } + fputs("`--nocache` are obsoleted. Caching functions other than image caching are removed.\n\n", stderr); else if(strcasecmp(key, "--load-config") == 0) optionParseConfigFile(instance, data, key, value); else if(strcasecmp(key, "--thread") == 0 || strcasecmp(key, "--multithreading") == 0) diff --git a/src/fastfetch.h b/src/fastfetch.h index bbd19122c..1198b4fcf 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -85,7 +85,6 @@ typedef struct FFconfig bool showErrors; bool recache; - bool cacheSave; bool allowSlowOperations; bool disableLinewrap; bool hideCursor; diff --git a/src/modules/bios.c b/src/modules/bios.c index 3e443a389..7b3853355 100644 --- a/src/modules/bios.c +++ b/src/modules/bios.c @@ -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); diff --git a/src/modules/board.c b/src/modules/board.c index 8fe85735d..558653892 100644 --- a/src/modules/board.c +++ b/src/modules/board.c @@ -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); diff --git a/src/modules/cpu.c b/src/modules/cpu.c index 89c40fb99..eb38a9805 100644 --- a/src/modules/cpu.c +++ b/src/modules/cpu.c @@ -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" diff --git a/src/modules/gpu.c b/src/modules/gpu.c index 905fd9774..0d0ae8266 100644 --- a/src/modules/gpu.c +++ b/src/modules/gpu.c @@ -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)); } diff --git a/src/modules/host.c b/src/modules/host.c index cd4f50106..f253ceee4 100644 --- a/src/modules/host.c +++ b/src/modules/host.c @@ -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); } diff --git a/src/modules/locale.c b/src/modules/locale.c index cd8f0cd5f..8c56b0638 100644 --- a/src/modules/locale.c +++ b/src/modules/locale.c @@ -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); }