From c71b04ba93ae82098047b3497b3128aca660becb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 29 Apr 2024 23:28:20 +0800 Subject: [PATCH 01/13] Disk (Windows): add `--disk-ignore-remote` --- CHANGELOG.md | 1 + doc/json_schema.json | 5 +++++ src/data/help.json | 10 ++++++++++ src/detection/disk/disk.c | 4 ++-- src/detection/disk/disk_bsd.c | 2 +- src/detection/disk/disk_linux.c | 2 +- src/detection/disk/disk_windows.c | 4 ++-- src/modules/disk/disk.c | 15 +++++++++++++++ src/modules/disk/option.h | 1 + 9 files changed, 38 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17f58128a..5408b652c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ Features: * Better max CPU frequency detection support with `CPUID / 16H` instruction (CPU, Windows) * This requires Core I Gen 6 or newer, and with `Virtual Machine Platform` Windows feature disabled. X86 only. * Improve performance of nix packages detection (Packages, Linux) +* Add option `--disk-ignore-remote` to ignore remote disks to improve performance (Disk, Windows) # 2.10.2 diff --git a/doc/json_schema.json b/doc/json_schema.json index 5804b2292..a7d338dca 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -1265,6 +1265,11 @@ "description": "Set if unknown (unable to detect sizes) volumes should be printed", "default": false }, + "ignoreRemote": { + "type": "boolean", + "description": "Set if remote volumes should be ignored when detecting for performance reasons. Windows only", + "default": false + }, "useAvailable": { "type": "boolean", "description": "Use f_bavail (lpFreeBytesAvailableToCaller for Windows) instead of f_bfree to calculate used bytes", diff --git a/src/data/help.json b/src/data/help.json index f7cdfb2ec..9f1cb52a5 100644 --- a/src/data/help.json +++ b/src/data/help.json @@ -1007,6 +1007,16 @@ "default": false } }, + { + "long": "disk-ignore-remote", + "desc": "Set if remote volumes should be ignored when detecting for performance reasons", + "remark": "Windows only", + "arg": { + "type": "bool", + "optional": true, + "default": false + } + }, { "long": "disk-use-available", "desc": "Use f_bavail (lpFreeBytesAvailableToCaller for Windows) instead of f_bfree to calculate used bytes", diff --git a/src/detection/disk/disk.c b/src/detection/disk/disk.c index e712a9c12..17dd553b1 100644 --- a/src/detection/disk/disk.c +++ b/src/detection/disk/disk.c @@ -1,6 +1,6 @@ #include "disk.h" -const char* ffDetectDisksImpl(FFlist* disks); +const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks); static int compareDisks(const FFDisk* disk1, const FFDisk* disk2) { @@ -9,7 +9,7 @@ static int compareDisks(const FFDisk* disk1, const FFDisk* disk2) const char* ffDetectDisks(FFDiskOptions* options, FFlist* disks) { - const char* error = ffDetectDisksImpl(disks); + const char* error = ffDetectDisksImpl(options, disks); if (error) return error; if (disks->length == 0) return "No disks found"; diff --git a/src/detection/disk/disk_bsd.c b/src/detection/disk/disk_bsd.c index c6f9a1c82..227800db1 100644 --- a/src/detection/disk/disk_bsd.c +++ b/src/detection/disk/disk_bsd.c @@ -90,7 +90,7 @@ void detectFsInfo(struct statfs* fs, FFDisk* disk) } #endif -const char* ffDetectDisksImpl(FFlist* disks) +const char* ffDetectDisksImpl(FF_MAYBE_UNUSED FFDiskOptions* options, FFlist* disks) { int size = getfsstat(NULL, 0, MNT_WAIT); diff --git a/src/detection/disk/disk_linux.c b/src/detection/disk/disk_linux.c index 31715e6d5..41701ce7e 100644 --- a/src/detection/disk/disk_linux.c +++ b/src/detection/disk/disk_linux.c @@ -250,7 +250,7 @@ static void detectStats(FFDisk* disk) #endif } -const char* ffDetectDisksImpl(FFlist* disks) +const char* ffDetectDisksImpl(FF_MAYBE_UNUSED FFDiskOptions* options, FFlist* disks) { FILE* mountsFile = setmntent("/proc/mounts", "r"); if(mountsFile == NULL) diff --git a/src/detection/disk/disk_windows.c b/src/detection/disk/disk_windows.c index ef5329e50..3aada23c7 100644 --- a/src/detection/disk/disk_windows.c +++ b/src/detection/disk/disk_windows.c @@ -6,7 +6,7 @@ #include #include -const char* ffDetectDisksImpl(FFlist* disks) +const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks) { wchar_t buf[MAX_PATH + 1]; uint32_t length = GetLogicalDriveStringsW(sizeof(buf) / sizeof(*buf), buf); @@ -18,7 +18,7 @@ const char* ffDetectDisksImpl(FFlist* disks) wchar_t* mountpoint = buf + i; UINT driveType = GetDriveTypeW(mountpoint); - if(driveType == DRIVE_NO_ROOT_DIR) + if(driveType == DRIVE_NO_ROOT_DIR || (driveType == DRIVE_REMOTE && options->ignoreRemote)) { i += (uint32_t)wcslen(mountpoint); continue; diff --git a/src/modules/disk/disk.c b/src/modules/disk/disk.c index 364d5bf2d..52719ece0 100644 --- a/src/modules/disk/disk.c +++ b/src/modules/disk/disk.c @@ -281,6 +281,12 @@ bool ffParseDiskCommandOptions(FFDiskOptions* options, const char* key, const ch return true; } + if (ffStrEqualsIgnCase(subKey, "ignore-remote")) + { + options->ignoreRemote = ffOptionParseBoolean(value); + return true; + } + if (ffPercentParseCommandOptions(key, subKey, value, &options->percent)) return true; @@ -351,6 +357,12 @@ void ffParseDiskJsonObject(FFDiskOptions* options, yyjson_val* module) continue; } + if (ffStrEqualsIgnCase(key, "ignoreRemote")) + { + options->ignoreRemote = yyjson_get_bool(val); + continue; + } + if (ffStrEqualsIgnCase(key, "useAvailable")) { if (yyjson_get_bool(val)) @@ -398,6 +410,9 @@ void ffGenerateDiskJsonConfig(FFDiskOptions* options, yyjson_mut_doc* doc, yyjso if (defaultOptions.calcType != options->calcType) yyjson_mut_obj_add_bool(doc, module, "useAvailable", options->calcType == FF_DISK_CALC_TYPE_AVAILABLE); + if (defaultOptions.ignoreRemote != options->ignoreRemote) + yyjson_mut_obj_add_bool(doc, module, "ignoreRemote", options->ignoreRemote); + ffPercentGenerateJsonConfig(doc, module, defaultOptions.percent, options->percent); } diff --git a/src/modules/disk/option.h b/src/modules/disk/option.h index 7c2abdcaa..e1fef2e6b 100644 --- a/src/modules/disk/option.h +++ b/src/modules/disk/option.h @@ -31,4 +31,5 @@ typedef struct FFDiskOptions FFDiskVolumeType showTypes; FFDiskCalcType calcType; FFColorRangeConfig percent; + bool ignoreRemote; } FFDiskOptions; From c309dbb84465b1c1aa7f0574b33063e12b9ee0d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 29 Apr 2024 23:30:55 +0800 Subject: [PATCH 02/13] Doc: update bug report template --- .github/ISSUE_TEMPLATE/bug_report.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index ecd7ec7a1..be682e7b0 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -59,6 +59,10 @@ strace /path/to/fastfetch --multithreading false -s {MODULE} --pipe If you cannot do the instructions above, please upload the core dump file: +## If fastfetch is slow + +Use `time fastfetch --stat` to show time usage for each module. + ## If my image logo didn't show / work From 0576d4ca260d21809041bc29fd61528db107f611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 29 Apr 2024 23:33:18 +0800 Subject: [PATCH 03/13] Disk: init variables --- src/modules/disk/disk.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/disk/disk.c b/src/modules/disk/disk.c index 52719ece0..60b60b368 100644 --- a/src/modules/disk/disk.c +++ b/src/modules/disk/disk.c @@ -520,6 +520,7 @@ void ffInitDiskOptions(FFDiskOptions* options) options->showTypes = FF_DISK_VOLUME_TYPE_REGULAR_BIT | FF_DISK_VOLUME_TYPE_EXTERNAL_BIT | FF_DISK_VOLUME_TYPE_READONLY_BIT; options->calcType = FF_DISK_CALC_TYPE_FREE; options->percent = (FFColorRangeConfig) { 50, 80 }; + options->ignoreRemote = false; } void ffDestroyDiskOptions(FFDiskOptions* options) From 315bbb3020aa8322434f63b92a769c381f84bbee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 29 Apr 2024 14:17:13 +0800 Subject: [PATCH 04/13] GPU (Linux): constantly use `*_vis_*` --- src/detection/gpu/gpu_linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index 7afe12ada..a8801cb31 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -84,7 +84,7 @@ static void pciDetectAmdSpecific(const FFGPUOptions* options, FFGPUResult* gpu, if (ffReadFileBuffer(pciDir->chars, buffer) && (value = ffStrbufToUInt(buffer, 0))) { ffStrbufSubstrBefore(pciDir, pciDir->length - (uint32_t) strlen("/mem_info_vis_vram_total")); - ffStrbufAppendS(pciDir, "/mem_info_vram_used"); + ffStrbufAppendS(pciDir, "/mem_info_vis_vram_used"); if (ffReadFileBuffer(pciDir->chars, buffer) && (value = ffStrbufToUInt(buffer, 0))) { if (gpu->type == FF_GPU_TYPE_DISCRETE) From e12642e0b9ee09bf78cd97c1d90f2e259c320f65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 30 Apr 2024 09:15:57 +0800 Subject: [PATCH 05/13] Fastfetch: make config in jsonc overridable Fix #821 --- src/fastfetch.c | 60 ++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/fastfetch.c b/src/fastfetch.c index 3959d7f8a..629c4dad0 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -321,21 +321,42 @@ static void parseOption(FFdata* data, const char* key, const char* value); static bool parseJsoncFile(const char* path) { - yyjson_read_err error; - yyjson_doc* doc = yyjson_read_file(path, YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS | YYJSON_READ_ALLOW_INF_AND_NAN, NULL, &error); - if (!doc) + assert(!instance.state.configDoc); + { - if (error.code != YYJSON_READ_ERROR_FILE_OPEN) + yyjson_read_err error; + instance.state.configDoc = yyjson_read_file(path, YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS | YYJSON_READ_ALLOW_INF_AND_NAN, NULL, &error); + if (!instance.state.configDoc) { - fprintf(stderr, "Error: failed to parse JSON config file `%s` at pos %zu: %s\n", path, error.pos, error.msg); + if (error.code != YYJSON_READ_ERROR_FILE_OPEN) + { + fprintf(stderr, "Error: failed to parse JSON config file `%s` at pos %zu: %s\n", path, error.pos, error.msg); + exit(477); + } + return false; + } + } + + { + const char* error = NULL; + + yyjson_val* const root = yyjson_doc_get_root(instance.state.configDoc); + if (!yyjson_is_obj(root)) + error = "Invalid JSON config format. Root value must be an object"; + + if ( + error || + (error = ffOptionsParseLogoJsonConfig(&instance.config.logo, root)) || + (error = ffOptionsParseGeneralJsonConfig(&instance.config.general, root)) || + (error = ffOptionsParseDisplayJsonConfig(&instance.config.display, root)) || + (error = ffOptionsParseLibraryJsonConfig(&instance.config.library, root)) || + false + ) { + fprintf(stderr, "JsonConfig Error: %s\n", error); exit(477); } - return false; } - if (instance.state.configDoc) - yyjson_doc_free(instance.state.configDoc); // for `--load-config` - instance.state.configDoc = doc; return true; } @@ -779,27 +800,6 @@ static void parseArguments(FFdata* data, int argc, char** argv, void (*parser)(F static void run(FFdata* data) { - if (instance.state.configDoc) - { - const char* error = NULL; - - yyjson_val* const root = yyjson_doc_get_root(instance.state.configDoc); - if (!yyjson_is_obj(root)) - error = "Invalid JSON config format. Root value must be an object"; - - if ( - error || - (error = ffOptionsParseLogoJsonConfig(&instance.config.logo, root)) || - (error = ffOptionsParseGeneralJsonConfig(&instance.config.general, root)) || - (error = ffOptionsParseDisplayJsonConfig(&instance.config.display, root)) || - (error = ffOptionsParseLibraryJsonConfig(&instance.config.library, root)) || - false - ) { - fprintf(stderr, "JsonConfig Error: %s\n", error); - exit(477); - } - } - const bool useJsonConfig = data->structure.length == 0 && instance.state.configDoc; if (useJsonConfig) From 8721cc1ab5cc0488d3f134e4dd5e626abdb863c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 30 Apr 2024 14:43:12 +0800 Subject: [PATCH 06/13] CPU (Windows): silence compiler warnings --- src/detection/cpu/cpu_windows.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/detection/cpu/cpu_windows.c b/src/detection/cpu/cpu_windows.c index 6a4d8195e..81bae35a1 100644 --- a/src/detection/cpu/cpu_windows.c +++ b/src/detection/cpu/cpu_windows.c @@ -68,7 +68,7 @@ inline static const char* detectSpeedByCpuid(FFCPUResult* cpu) #else -inline static const char* detectSpeedByCpuid(FFCPUResult* cpu) +inline static const char* detectSpeedByCpuid(FF_MAYBE_UNUSED FFCPUResult* cpu) { return "Unsupported platform"; } From 1058e876a71a52ddbe102d9e0c6e1fb9ece8b4d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 30 Apr 2024 14:46:26 +0800 Subject: [PATCH 07/13] Revert "Disk (Windows): add `--disk-ignore-remote`" This reverts commit c71b04ba93ae82098047b3497b3128aca660becb. --- CHANGELOG.md | 1 - doc/json_schema.json | 5 ----- src/data/help.json | 10 ---------- src/detection/disk/disk.c | 4 ++-- src/detection/disk/disk_bsd.c | 2 +- src/detection/disk/disk_linux.c | 2 +- src/detection/disk/disk_windows.c | 4 ++-- src/modules/disk/disk.c | 15 --------------- src/modules/disk/option.h | 1 - 9 files changed, 6 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5408b652c..17f58128a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,6 @@ Features: * Better max CPU frequency detection support with `CPUID / 16H` instruction (CPU, Windows) * This requires Core I Gen 6 or newer, and with `Virtual Machine Platform` Windows feature disabled. X86 only. * Improve performance of nix packages detection (Packages, Linux) -* Add option `--disk-ignore-remote` to ignore remote disks to improve performance (Disk, Windows) # 2.10.2 diff --git a/doc/json_schema.json b/doc/json_schema.json index a7d338dca..5804b2292 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -1265,11 +1265,6 @@ "description": "Set if unknown (unable to detect sizes) volumes should be printed", "default": false }, - "ignoreRemote": { - "type": "boolean", - "description": "Set if remote volumes should be ignored when detecting for performance reasons. Windows only", - "default": false - }, "useAvailable": { "type": "boolean", "description": "Use f_bavail (lpFreeBytesAvailableToCaller for Windows) instead of f_bfree to calculate used bytes", diff --git a/src/data/help.json b/src/data/help.json index 9f1cb52a5..f7cdfb2ec 100644 --- a/src/data/help.json +++ b/src/data/help.json @@ -1007,16 +1007,6 @@ "default": false } }, - { - "long": "disk-ignore-remote", - "desc": "Set if remote volumes should be ignored when detecting for performance reasons", - "remark": "Windows only", - "arg": { - "type": "bool", - "optional": true, - "default": false - } - }, { "long": "disk-use-available", "desc": "Use f_bavail (lpFreeBytesAvailableToCaller for Windows) instead of f_bfree to calculate used bytes", diff --git a/src/detection/disk/disk.c b/src/detection/disk/disk.c index 17dd553b1..e712a9c12 100644 --- a/src/detection/disk/disk.c +++ b/src/detection/disk/disk.c @@ -1,6 +1,6 @@ #include "disk.h" -const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks); +const char* ffDetectDisksImpl(FFlist* disks); static int compareDisks(const FFDisk* disk1, const FFDisk* disk2) { @@ -9,7 +9,7 @@ static int compareDisks(const FFDisk* disk1, const FFDisk* disk2) const char* ffDetectDisks(FFDiskOptions* options, FFlist* disks) { - const char* error = ffDetectDisksImpl(options, disks); + const char* error = ffDetectDisksImpl(disks); if (error) return error; if (disks->length == 0) return "No disks found"; diff --git a/src/detection/disk/disk_bsd.c b/src/detection/disk/disk_bsd.c index 227800db1..c6f9a1c82 100644 --- a/src/detection/disk/disk_bsd.c +++ b/src/detection/disk/disk_bsd.c @@ -90,7 +90,7 @@ void detectFsInfo(struct statfs* fs, FFDisk* disk) } #endif -const char* ffDetectDisksImpl(FF_MAYBE_UNUSED FFDiskOptions* options, FFlist* disks) +const char* ffDetectDisksImpl(FFlist* disks) { int size = getfsstat(NULL, 0, MNT_WAIT); diff --git a/src/detection/disk/disk_linux.c b/src/detection/disk/disk_linux.c index 41701ce7e..31715e6d5 100644 --- a/src/detection/disk/disk_linux.c +++ b/src/detection/disk/disk_linux.c @@ -250,7 +250,7 @@ static void detectStats(FFDisk* disk) #endif } -const char* ffDetectDisksImpl(FF_MAYBE_UNUSED FFDiskOptions* options, FFlist* disks) +const char* ffDetectDisksImpl(FFlist* disks) { FILE* mountsFile = setmntent("/proc/mounts", "r"); if(mountsFile == NULL) diff --git a/src/detection/disk/disk_windows.c b/src/detection/disk/disk_windows.c index 3aada23c7..ef5329e50 100644 --- a/src/detection/disk/disk_windows.c +++ b/src/detection/disk/disk_windows.c @@ -6,7 +6,7 @@ #include #include -const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks) +const char* ffDetectDisksImpl(FFlist* disks) { wchar_t buf[MAX_PATH + 1]; uint32_t length = GetLogicalDriveStringsW(sizeof(buf) / sizeof(*buf), buf); @@ -18,7 +18,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks) wchar_t* mountpoint = buf + i; UINT driveType = GetDriveTypeW(mountpoint); - if(driveType == DRIVE_NO_ROOT_DIR || (driveType == DRIVE_REMOTE && options->ignoreRemote)) + if(driveType == DRIVE_NO_ROOT_DIR) { i += (uint32_t)wcslen(mountpoint); continue; diff --git a/src/modules/disk/disk.c b/src/modules/disk/disk.c index 60b60b368..f3c231e83 100644 --- a/src/modules/disk/disk.c +++ b/src/modules/disk/disk.c @@ -281,12 +281,6 @@ bool ffParseDiskCommandOptions(FFDiskOptions* options, const char* key, const ch return true; } - if (ffStrEqualsIgnCase(subKey, "ignore-remote")) - { - options->ignoreRemote = ffOptionParseBoolean(value); - return true; - } - if (ffPercentParseCommandOptions(key, subKey, value, &options->percent)) return true; @@ -357,12 +351,6 @@ void ffParseDiskJsonObject(FFDiskOptions* options, yyjson_val* module) continue; } - if (ffStrEqualsIgnCase(key, "ignoreRemote")) - { - options->ignoreRemote = yyjson_get_bool(val); - continue; - } - if (ffStrEqualsIgnCase(key, "useAvailable")) { if (yyjson_get_bool(val)) @@ -410,9 +398,6 @@ void ffGenerateDiskJsonConfig(FFDiskOptions* options, yyjson_mut_doc* doc, yyjso if (defaultOptions.calcType != options->calcType) yyjson_mut_obj_add_bool(doc, module, "useAvailable", options->calcType == FF_DISK_CALC_TYPE_AVAILABLE); - if (defaultOptions.ignoreRemote != options->ignoreRemote) - yyjson_mut_obj_add_bool(doc, module, "ignoreRemote", options->ignoreRemote); - ffPercentGenerateJsonConfig(doc, module, defaultOptions.percent, options->percent); } diff --git a/src/modules/disk/option.h b/src/modules/disk/option.h index e1fef2e6b..7c2abdcaa 100644 --- a/src/modules/disk/option.h +++ b/src/modules/disk/option.h @@ -31,5 +31,4 @@ typedef struct FFDiskOptions FFDiskVolumeType showTypes; FFDiskCalcType calcType; FFColorRangeConfig percent; - bool ignoreRemote; } FFDiskOptions; From 418106c485ad4f1b1251dd9ded893def949ef9b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 30 Apr 2024 14:46:54 +0800 Subject: [PATCH 08/13] Revert "Disk: init variables" This reverts commit 0576d4ca260d21809041bc29fd61528db107f611. --- src/modules/disk/disk.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/modules/disk/disk.c b/src/modules/disk/disk.c index f3c231e83..364d5bf2d 100644 --- a/src/modules/disk/disk.c +++ b/src/modules/disk/disk.c @@ -505,7 +505,6 @@ void ffInitDiskOptions(FFDiskOptions* options) options->showTypes = FF_DISK_VOLUME_TYPE_REGULAR_BIT | FF_DISK_VOLUME_TYPE_EXTERNAL_BIT | FF_DISK_VOLUME_TYPE_READONLY_BIT; options->calcType = FF_DISK_CALC_TYPE_FREE; options->percent = (FFColorRangeConfig) { 50, 80 }; - options->ignoreRemote = false; } void ffDestroyDiskOptions(FFDiskOptions* options) From 36a0c273f992893003aa914e35427cc335e26406 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 30 Apr 2024 10:33:21 +0800 Subject: [PATCH 09/13] Processing: suggest increasing `--processing-timeout` when child process timeouts --- src/common/processing_linux.c | 2 +- src/common/processing_windows.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/processing_linux.c b/src/common/processing_linux.c index e0f2db4d9..4401e3212 100644 --- a/src/common/processing_linux.c +++ b/src/common/processing_linux.c @@ -68,7 +68,7 @@ const char* ffProcessAppendOutput(FFstrbuf* buffer, char* const argv[], bool use { kill(childPid, SIGTERM); waitpid(childPid, NULL, 0); - return "poll(&pollfd, 1, timeout) timeout"; + return "poll(&pollfd, 1, timeout) timeout (try increasing --processing-timeout)"; } else if (pollfd.revents & POLLERR) { diff --git a/src/common/processing_windows.c b/src/common/processing_windows.c index c93e5a9e4..5cbd0819f 100644 --- a/src/common/processing_windows.c +++ b/src/common/processing_windows.c @@ -96,7 +96,7 @@ const char* ffProcessAppendOutput(FFstrbuf* buffer, char* const argv[], bool use { CancelIo(hChildPipeRead); TerminateProcess(hProcess, 1); - return "WaitForSingleObject(hChildPipeRead) failed or timeout"; + return "WaitForSingleObject(hChildPipeRead) failed or timeout (try increasing --processing-timeout)"; } if (!GetOverlappedResult(hChildPipeRead, &overlapped, &nRead, FALSE)) From 367264e54907f981fa8a34f82322ec57e1ff3e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 30 Apr 2024 15:12:49 +0800 Subject: [PATCH 10/13] Disk: only detect folders that specified by `--disk-folders` Can be used to improve performance by ignoring network disks --- src/detection/disk/disk.c | 27 ++++++++++++-- src/detection/disk/disk.h | 3 ++ src/detection/disk/disk_bsd.c | 9 +++-- src/detection/disk/disk_linux.c | 9 +++-- src/detection/disk/disk_windows.c | 20 +++++++---- src/modules/disk/disk.c | 59 ++++--------------------------- 6 files changed, 62 insertions(+), 65 deletions(-) diff --git a/src/detection/disk/disk.c b/src/detection/disk/disk.c index e712a9c12..21520b532 100644 --- a/src/detection/disk/disk.c +++ b/src/detection/disk/disk.c @@ -1,6 +1,29 @@ #include "disk.h" -const char* ffDetectDisksImpl(FFlist* disks); +bool ffDiskMatchMountpoint(FFDiskOptions* options, const char* mountpoint) +{ + #ifdef _WIN32 + const char separator = ';'; + #else + const char separator = ':'; + #endif + + uint32_t mountpointLength = (uint32_t) strlen(mountpoint); + + uint32_t startIndex = 0; + while(startIndex < options->folders.length) + { + uint32_t colonIndex = ffStrbufNextIndexC(&options->folders, startIndex, separator); + + uint32_t folderLength = colonIndex - startIndex; + if (folderLength == mountpointLength && memcmp(options->folders.chars + startIndex, mountpoint, mountpointLength) == 0) + return true; + + startIndex = colonIndex + 1; + } + + return false; +} static int compareDisks(const FFDisk* disk1, const FFDisk* disk2) { @@ -9,7 +32,7 @@ static int compareDisks(const FFDisk* disk1, const FFDisk* disk2) const char* ffDetectDisks(FFDiskOptions* options, FFlist* disks) { - const char* error = ffDetectDisksImpl(disks); + const char* error = ffDetectDisksImpl(options, disks); if (error) return error; if (disks->length == 0) return "No disks found"; diff --git a/src/detection/disk/disk.h b/src/detection/disk/disk.h index dc70bb88a..1700c6078 100644 --- a/src/detection/disk/disk.h +++ b/src/detection/disk/disk.h @@ -26,3 +26,6 @@ typedef struct FFDisk * If error is not set, disks contains at least one disk. */ const char* ffDetectDisks(FFDiskOptions* options, FFlist* disks /* list of FFDisk */); + +const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks); +bool ffDiskMatchMountpoint(FFDiskOptions* options, const char* mountpoint); diff --git a/src/detection/disk/disk_bsd.c b/src/detection/disk/disk_bsd.c index c6f9a1c82..dcd6cc507 100644 --- a/src/detection/disk/disk_bsd.c +++ b/src/detection/disk/disk_bsd.c @@ -90,7 +90,7 @@ void detectFsInfo(struct statfs* fs, FFDisk* disk) } #endif -const char* ffDetectDisksImpl(FFlist* disks) +const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks) { int size = getfsstat(NULL, 0, MNT_WAIT); @@ -103,7 +103,12 @@ const char* ffDetectDisksImpl(FFlist* disks) for(struct statfs* fs = buf; fs < buf + size; ++fs) { - if(!ffStrStartsWith(fs->f_mntfromname, "/dev/") && !ffStrEquals(fs->f_fstypename, "zfs")) + if(__builtin_expect(options->folders.length, 0)) + { + if(!ffDiskMatchMountpoint(options, fs->f_mntonname)) + continue; + } + else if(!ffStrStartsWith(fs->f_mntfromname, "/dev/") && !ffStrEquals(fs->f_fstypename, "zfs")) continue; #ifdef __FreeBSD__ diff --git a/src/detection/disk/disk_linux.c b/src/detection/disk/disk_linux.c index 31715e6d5..812cb5884 100644 --- a/src/detection/disk/disk_linux.c +++ b/src/detection/disk/disk_linux.c @@ -250,7 +250,7 @@ static void detectStats(FFDisk* disk) #endif } -const char* ffDetectDisksImpl(FFlist* disks) +const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks) { FILE* mountsFile = setmntent("/proc/mounts", "r"); if(mountsFile == NULL) @@ -260,7 +260,12 @@ const char* ffDetectDisksImpl(FFlist* disks) while((device = getmntent(mountsFile))) { - if(!isPhysicalDevice(device)) + if (__builtin_expect(options->folders.length, 0)) + { + if (!ffDiskMatchMountpoint(options, device->mnt_dir)) + continue; + } + else if(!isPhysicalDevice(device)) continue; //We have a valid device, add it to the list diff --git a/src/detection/disk/disk_windows.c b/src/detection/disk/disk_windows.c index ef5329e50..8c0890eb6 100644 --- a/src/detection/disk/disk_windows.c +++ b/src/detection/disk/disk_windows.c @@ -6,23 +6,31 @@ #include #include -const char* ffDetectDisksImpl(FFlist* disks) +const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks) { wchar_t buf[MAX_PATH + 1]; uint32_t length = GetLogicalDriveStringsW(sizeof(buf) / sizeof(*buf), buf); if (length == 0 || length >= sizeof(buf) / sizeof(*buf)) return "GetLogicalDriveStringsW(sizeof(buf) / sizeof(*buf), buf) failed"; + FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate(); + for(uint32_t i = 0; i < length; i++) { wchar_t* mountpoint = buf + i; + ffStrbufSetWS(&buffer, mountpoint); + i += buffer.length; + UINT driveType = GetDriveTypeW(mountpoint); - if(driveType == DRIVE_NO_ROOT_DIR) + + if (__builtin_expect((long) options->folders.length, 0)) { - i += (uint32_t)wcslen(mountpoint); - continue; + if (!ffDiskMatchMountpoint(options, buffer.chars)) + continue; } + else if(driveType == DRIVE_NO_ROOT_DIR) + continue; FFDisk* disk = ffListAdd(disks); @@ -77,7 +85,7 @@ const char* ffDetectDisksImpl(FFlist* disks) else disk->createTime = 0; - ffStrbufInitWS(&disk->mountpoint, mountpoint); + ffStrbufInitMove(&disk->mountpoint, &buffer); if (mountpoint[2] == L'\\' && mountpoint[3] == L'\0') { wchar_t volumeName[MAX_PATH + 1]; @@ -91,8 +99,6 @@ const char* ffDetectDisksImpl(FFlist* disks) //Unsupported disk->filesUsed = 0; disk->filesTotal = 0; - - i += disk->mountpoint.length; } return NULL; diff --git a/src/modules/disk/disk.c b/src/modules/disk/disk.c index 364d5bf2d..d4946cf05 100644 --- a/src/modules/disk/disk.c +++ b/src/modules/disk/disk.c @@ -131,54 +131,6 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk) } } -static void printMountpoint(FFDiskOptions* options, const FFlist* disks, const char* mountpoint) -{ - FF_LIST_FOR_EACH(FFDisk, disk, *disks) - { - if(ffStrbufEqualS(&disk->mountpoint, mountpoint)) - { - printDisk(options, disk); - return; - } - } - - ffPrintError(FF_DISK_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No disk found for mountpoint: %s", mountpoint); -} - -static void printMountpoints(FFDiskOptions* options, const FFlist* disks) -{ - #ifdef _WIN32 - const char separator = ';'; - #else - const char separator = ':'; - #endif - - FF_STRBUF_AUTO_DESTROY mountpoints = ffStrbufCreateCopy(&options->folders); - ffStrbufTrim(&mountpoints, separator); - - uint32_t startIndex = 0; - while(startIndex < mountpoints.length) - { - uint32_t colonIndex = ffStrbufNextIndexC(&mountpoints, startIndex, separator); - mountpoints.chars[colonIndex] = '\0'; - - printMountpoint(options, disks, mountpoints.chars + startIndex); - - startIndex = colonIndex + 1; - } -} - -static void printAutodetected(FFDiskOptions* options, const FFlist* disks) -{ - FF_LIST_FOR_EACH(FFDisk, disk, *disks) - { - if(disk->type & ~options->showTypes) - continue; - - printDisk(options, disk); - } -} - void ffPrintDisk(FFDiskOptions* options) { FF_LIST_AUTO_DESTROY disks = ffListCreate(sizeof (FFDisk)); @@ -190,10 +142,13 @@ void ffPrintDisk(FFDiskOptions* options) } else { - if(options->folders.length == 0) - printAutodetected(options, &disks); - else - printMountpoints(options, &disks); + FF_LIST_FOR_EACH(FFDisk, disk, disks) + { + if(__builtin_expect(options->folders.length == 0, 1) && (disk->type & ~options->showTypes)) + continue; + + printDisk(options, disk); + } } FF_LIST_FOR_EACH(FFDisk, disk, disks) From c42711ee262ae1736267fc3bf2ca32ce5ae755cf Mon Sep 17 00:00:00 2001 From: Carter Li Date: Tue, 30 Apr 2024 18:56:45 +0800 Subject: [PATCH 11/13] Camera (macOS): try silence system deprecation warnings --- src/detection/camera/camera_apple.m | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/detection/camera/camera_apple.m b/src/detection/camera/camera_apple.m index cf8d8cec1..8912b2364 100644 --- a/src/detection/camera/camera_apple.m +++ b/src/detection/camera/camera_apple.m @@ -4,7 +4,14 @@ const char* ffDetectCamera(FFlist* result) { - AVCaptureDeviceDiscoverySession* session = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWideAngleCamera] mediaType:AVMediaTypeVideo position:AVCaptureDevicePositionUnspecified]; + AVCaptureDeviceType externalType; + if (@available(macOS 14, *)) // #822 + externalType = AVCaptureDeviceTypeContinuityCamera; + else + externalType = AVCaptureDeviceTypeExternalUnknown; + AVCaptureDeviceDiscoverySession* session = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWideAngleCamera, externalType] + mediaType:AVMediaTypeVideo + position:AVCaptureDevicePositionUnspecified]; if (!session) return "Failed to create AVCaptureDeviceDiscoverySession"; From 78c903c40321a997fdfec6b01a207e434b2ed81b Mon Sep 17 00:00:00 2001 From: Carter Li Date: Tue, 30 Apr 2024 19:22:45 +0800 Subject: [PATCH 12/13] Camera (macOS): fix building on old xcode --- src/detection/camera/camera_apple.m | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/detection/camera/camera_apple.m b/src/detection/camera/camera_apple.m index 8912b2364..a3da90540 100644 --- a/src/detection/camera/camera_apple.m +++ b/src/detection/camera/camera_apple.m @@ -1,15 +1,12 @@ #include "camera.h" +#include "common/io/io.h" #import const char* ffDetectCamera(FFlist* result) { - AVCaptureDeviceType externalType; - if (@available(macOS 14, *)) // #822 - externalType = AVCaptureDeviceTypeContinuityCamera; - else - externalType = AVCaptureDeviceTypeExternalUnknown; - AVCaptureDeviceDiscoverySession* session = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWideAngleCamera, externalType] + FF_SUPPRESS_IO(); // #822 + AVCaptureDeviceDiscoverySession* session = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWideAngleCamera, AVCaptureDeviceTypeExternalUnknown] mediaType:AVMediaTypeVideo position:AVCaptureDevicePositionUnspecified]; if (!session) From 3fe2d8091adbc1f844ac972857fde92db7708615 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Tue, 30 Apr 2024 19:43:26 +0800 Subject: [PATCH 13/13] Release: v2.11.0 --- CHANGELOG.md | 11 +++++++++-- CMakeLists.txt | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17f58128a..0c6c673fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# 2.10.3 +# 2.11.0 Changes: * Default `hideCursor` to false. It doesn't make much difference but makes user's terminal unusable if fastfetch is not exited correctly. @@ -10,14 +10,21 @@ Bugfixes: * Fix wifi detection on platforms that don't use NetworkManager (#811, Wifi, Linux) * Fix NixOS wrapped process name (#814, Terminal, Linux) * Fix GPU type detection for AMD cards (#816, GPU, Linux) +* Silence system deprecation warnings (#822, Camera, macOS) Features: * Add basic support DE detection support for UKUI (DE, Linux) * Support printing total number of nix / flatpak / brew packages (Packages) * See `fastfetch -h packages-format` for detail * Better max CPU frequency detection support with `CPUID / 16H` instruction (CPU, Windows) - * This requires Core I Gen 6 or newer, and with `Virtual Machine Platform` Windows feature disabled. X86 only. + * This requires Intel Core I Gen 6 or newer, and with `Virtual Machine Platform` Windows feature disabled. X86 only. * Improve performance of nix packages detection (Packages, Linux) +* Make config specified in JSONC overridable by command line flags + * Note this change only make global config overridable; module configs are still not +* Suggest increasing `--processing-timeout` when child process timeouts +* Only detect folders that specified by `--disk-folders` + * Previously `--disk-folders` only omits unmatched disks from output + * This option can be used to improve detection performance by ignoring slow network drives # 2.10.2 diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f2fff8dc..1bcbb32cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs & project homepage url project(fastfetch - VERSION 2.10.3 + VERSION 2.11.0 LANGUAGES C DESCRIPTION "Fast neofetch-like system information tool" HOMEPAGE_URL "https://github.com/fastfetch-cli/fastfetch"