From c42b68404fd8b009eda9a74c3062edd8a91ed062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 7 Nov 2023 15:19:53 +0800 Subject: [PATCH 1/7] Logo (Image): try improving performace of base64 encoding --- src/logo/image/image.c | 54 ++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/src/logo/image/image.c b/src/logo/image/image.c index ac5d405b4..18a33e3a6 100644 --- a/src/logo/image/image.c +++ b/src/logo/image/image.c @@ -11,27 +11,45 @@ #include #endif +// https://github.com/kostya/benchmarks/blob/master/base64/test-nolib.c#L145 +static void base64EncodeRaw(uint32_t size, const char *str, uint32_t *out_size, char *output) +{ + static const char chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + char *out = output; + const char *ends = str + (size - size % 3); + while (str != ends) { + uint32_t n = __builtin_bswap32(*(uint32_t*) str); + *out++ = chars[(n >> 26) & 63]; + *out++ = chars[(n >> 20) & 63]; + *out++ = chars[(n >> 14) & 63]; + *out++ = chars[(n >> 8) & 63]; + str += 3; + } + + if (size % 3 == 1) { + uint64_t n = (uint64_t)*str << 16; + *out++ = chars[(n >> 18) & 63]; + *out++ = chars[(n >> 12) & 63]; + *out++ = '='; + *out++ = '='; + } else if (size % 3 == 2) { + uint64_t n = (uint64_t)*str++ << 16; + n |= (uint64_t)*str << 8; + *out++ = chars[(n >> 18) & 63]; + *out++ = chars[(n >> 12) & 63]; + *out++ = chars[(n >> 6) & 63]; + *out++ = '='; + } + *out = '\0'; + *out_size = (uint32_t) (out - output); +} + static FFstrbuf base64Encode(const FFstrbuf* in) { - const char* base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + FFstrbuf out = ffStrbufCreateA(10 + in->length * 4 / 3); + base64EncodeRaw(in->length, in->chars, &out.length, out.chars); + assert(out.length < out.allocated); - FFstrbuf out = ffStrbufCreateA(8 * (1 + in->length / 6)); - - unsigned val = 0; - int valb = -6; - for (uint32_t i = 0; i < in->length; ++i) - { - unsigned char c = (unsigned char) in->chars[i]; - val = (val << 8) + c; - valb += 8; - while (valb >= 0) - { - ffStrbufAppendC(&out, base64Chars[(val>>valb)&0x3F]); - valb -= 6; - } - } - if (valb > -6) ffStrbufAppendC(&out, base64Chars[((val<<8)>>(valb+8))&0x3F]); - while (out.length % 4) ffStrbufAppendC(&out, '='); return out; } From 864e707224cc784c637cf8f999bc176bc8f0f65e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 7 Nov 2023 20:17:08 +0800 Subject: [PATCH 2/7] LocalIP (Android): don't set `--default-route-only` to true by default on Android As we can't detect default route on that platform --- src/data/help.txt | 4 ++-- src/modules/localip/localip.c | 8 +++++++- src/modules/netio/netio.c | 8 +++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/data/help.txt b/src/data/help.txt index 27f29d6a3..7d5d1b9c6 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -162,10 +162,10 @@ Module specific options: --localip-show-mac : Show mac addresses in local ip module. Default is false --localip-show-loop : Show loop back addresses (127.0.0.1) in local ip module. Default is false --localip-name-prefix : Show interfaces with given interface name prefix only. Default is empty - --localip-default-route-only : Show the interface that is used for default routing only. Default is true + --localip-default-route-only : Show the interface that is used for default routing only. Default is true on non-android platforms --localip-compact : Show all IPs in one line. Default is false --netio-name-prefix : Show interfaces with given name prefix only. Default is empty - --netio-default-route-only : Show the interfac that is used for default routing only. Default is true + --netio-default-route-only : Show the interfac that is used for default routing only. Default is true on non-android platforms --publicip-timeout : Time in milliseconds to wait for the public ip server to respond. Default is disabled (0) --publicip-url : The URL of public IP detection server to be used. --weather-location : Set the location to be used. It must be URI encoded (eg a whitespace must be encoded as `+`). diff --git a/src/modules/localip/localip.c b/src/modules/localip/localip.c index 4d2150f8d..f9a2d475c 100644 --- a/src/modules/localip/localip.c +++ b/src/modules/localip/localip.c @@ -370,7 +370,13 @@ void ffInitLocalIpOptions(FFLocalIpOptions* options) options->showType = FF_LOCALIP_TYPE_IPV4_BIT; ffStrbufInit(&options->namePrefix); - options->defaultRouteOnly = true; + options->defaultRouteOnly = + #ifdef __ANDROID__ + false + #else + true + #endif + ; } void ffDestroyLocalIpOptions(FFLocalIpOptions* options) diff --git a/src/modules/netio/netio.c b/src/modules/netio/netio.c index 6105e52ef..df76fde5f 100644 --- a/src/modules/netio/netio.c +++ b/src/modules/netio/netio.c @@ -230,7 +230,13 @@ void ffInitNetIOOptions(FFNetIOOptions* options) ffOptionInitModuleArg(&options->moduleArgs); ffStrbufInit(&options->namePrefix); - options->defaultRouteOnly = true; + options->defaultRouteOnly = + #ifdef __ANDROID__ + false + #else + true + #endif + ; } void ffDestroyNetIOOptions(FFNetIOOptions* options) From 3e0d97db2ea0e878c285b9b61adccb39fec02605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 8 Nov 2023 00:02:00 +0800 Subject: [PATCH 3/7] Platform: detect system page size --- src/detection/memory/memory_apple.c | 7 +------ src/detection/memory/memory_bsd.c | 7 +------ src/detection/swap/swap_windows.c | 9 ++++----- src/modules/title/title.c | 1 + src/util/platform/FFPlatform.h | 2 ++ src/util/platform/FFPlatform_unix.c | 13 +++++++++++++ src/util/platform/FFPlatform_windows.c | 8 +++++--- 7 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/detection/memory/memory_apple.c b/src/detection/memory/memory_apple.c index 752c588c4..b3a50a1eb 100644 --- a/src/detection/memory/memory_apple.c +++ b/src/detection/memory/memory_apple.c @@ -11,17 +11,12 @@ const char* ffDetectMemory(FFMemoryResult* ram) if (sysctl((int[]){ CTL_HW, HW_MEMSIZE }, 2, &ram->bytesTotal, &length, NULL, 0)) return "Failed to read hw.memsize"; - uint32_t pagesize; - length = sizeof(pagesize); - if (sysctl((int[]){ CTL_HW, HW_PAGESIZE }, 2, &pagesize, &length, NULL, 0)) - return "Failed to read hw.pagesize"; - mach_msg_type_number_t count = HOST_VM_INFO64_COUNT; vm_statistics64_data_t vmstat; if(host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info64_t) (&vmstat), &count) != KERN_SUCCESS) return "Failed to read host_statistics64"; - ram->bytesUsed = ((uint64_t) vmstat.active_count + vmstat.wire_count) * pagesize; + ram->bytesUsed = ((uint64_t) vmstat.active_count + vmstat.wire_count) * instance.state.platform.pageSize; return NULL; } diff --git a/src/detection/memory/memory_bsd.c b/src/detection/memory/memory_bsd.c index 95e587a25..9af77cb70 100644 --- a/src/detection/memory/memory_bsd.c +++ b/src/detection/memory/memory_bsd.c @@ -7,17 +7,12 @@ const char* ffDetectMemory(FFMemoryResult* ram) if (sysctl((int[]){ CTL_HW, HW_PHYSMEM }, 2, &ram->bytesTotal, &length, NULL, 0)) return "Failed to read hw.physmem"; - uint32_t pageSize; - length = sizeof(pageSize); - if (sysctl((int[]){ CTL_HW, HW_PAGESIZE }, 2, &pageSize, &length, NULL, 0)) - return "Failed to read hw.pagesize"; - // vm.stats.vm.* are int values int32_t pagesFree = ffSysctlGetInt("vm.stats.vm.v_free_count", 0) + ffSysctlGetInt("vm.stats.vm.v_inactive_count", 0) + ffSysctlGetInt("vm.stats.vm.v_cache_count", 0); - ram->bytesUsed = ram->bytesTotal - (uint64_t) pagesFree * pageSize; + ram->bytesUsed = ram->bytesTotal - (uint64_t) pagesFree * instance.state.platform.pageSize; return NULL; } diff --git a/src/detection/swap/swap_windows.c b/src/detection/swap/swap_windows.c index f541f1964..a5788a358 100644 --- a/src/detection/swap/swap_windows.c +++ b/src/detection/swap/swap_windows.c @@ -7,9 +7,6 @@ const char* ffDetectSwap(FFSwapResult* swap) { - SYSTEM_INFO sysInfo; - GetNativeSystemInfo(&sysInfo); - ULONG size = sizeof(SYSTEM_PAGEFILE_INFORMATION); SYSTEM_PAGEFILE_INFORMATION* FF_AUTO_FREE pstart = (SYSTEM_PAGEFILE_INFORMATION*)malloc(size); while(true) @@ -24,8 +21,10 @@ const char* ffDetectSwap(FFSwapResult* swap) return "NtQuerySystemInformation(SystemPagefileInformation, size) failed"; break; } - swap->bytesUsed = (uint64_t)pstart->TotalUsed * sysInfo.dwPageSize; - swap->bytesTotal = (uint64_t)pstart->CurrentSize * sysInfo.dwPageSize; + + uint32_t pageSize = instance.state.platform.pageSize; + swap->bytesUsed = (uint64_t)pstart->TotalUsed * pageSize; + swap->bytesTotal = (uint64_t)pstart->CurrentSize * pageSize; return NULL; } diff --git a/src/modules/title/title.c b/src/modules/title/title.c index daad8413f..3e9f7cece 100644 --- a/src/modules/title/title.c +++ b/src/modules/title/title.c @@ -176,6 +176,7 @@ void ffGenerateTitleJsonResult(FF_MAYBE_UNUSED FFTitleOptions* options, yyjson_m yyjson_mut_obj_add_strbuf(doc, obj, "homeDir", &instance.state.platform.homeDir); yyjson_mut_obj_add_strbuf(doc, obj, "exePath", &instance.state.platform.exePath); yyjson_mut_obj_add_strbuf(doc, obj, "userShell", &instance.state.platform.userShell); + yyjson_mut_obj_add_uint(doc, obj, "pageSize", instance.state.platform.pageSize); } void ffPrintTitleHelpFormat(void) diff --git a/src/util/platform/FFPlatform.h b/src/util/platform/FFPlatform.h index 48c72513e..6386cf479 100644 --- a/src/util/platform/FFPlatform.h +++ b/src/util/platform/FFPlatform.h @@ -22,6 +22,8 @@ typedef struct FFPlatform { FFstrbuf systemVersion; FFstrbuf systemArchitecture; FFstrbuf systemDisplayVersion; + + uint32_t pageSize; } FFPlatform; void ffPlatformInit(FFPlatform* platform); diff --git a/src/util/platform/FFPlatform_unix.c b/src/util/platform/FFPlatform_unix.c index 33c76bc69..04687f0be 100644 --- a/src/util/platform/FFPlatform_unix.c +++ b/src/util/platform/FFPlatform_unix.c @@ -10,6 +10,7 @@ #ifdef __APPLE__ #include + #include #elif defined(__FreeBSD__) #include #endif @@ -153,6 +154,16 @@ static void getUserShell(FFPlatform* platform, const struct passwd* pwd) ffStrbufAppendS(&platform->userShell, shell); } +static void getPageSize(FFPlatform* platform) +{ + #if defined(__FreeBSD__) || defined(__APPLE__) + size_t length = sizeof(platform->pageSize); + sysctl((int[]){ CTL_HW, HW_PAGESIZE }, 2, &platform->pageSize, &length, NULL, 0); + #else + platform->pageSize = (uint32_t) sysconf(_SC_PAGESIZE); + #endif +} + void ffPlatformInitImpl(FFPlatform* platform) { struct passwd* pwd = getpwuid(getuid()); @@ -176,4 +187,6 @@ void ffPlatformInitImpl(FFPlatform* platform) ffStrbufAppendS(&platform->systemVersion, uts.version); ffStrbufAppendS(&platform->systemArchitecture, uts.machine); ffStrbufInit(&platform->systemDisplayVersion); + + getPageSize(platform); } diff --git a/src/util/platform/FFPlatform_windows.c b/src/util/platform/FFPlatform_windows.c index 0774c81c3..59696df43 100644 --- a/src/util/platform/FFPlatform_windows.c +++ b/src/util/platform/FFPlatform_windows.c @@ -183,9 +183,9 @@ static void getSystemReleaseAndVersion(FFPlatform* platform) } } -static void getSystemArchitecture(FFPlatform* platform) +static void getSystemArchitectureAndPageSize(FFPlatform* platform) { - SYSTEM_INFO sysInfo = {0}; + SYSTEM_INFO sysInfo; GetNativeSystemInfo(&sysInfo); switch(sysInfo.wProcessorArchitecture) @@ -215,6 +215,8 @@ static void getSystemArchitecture(FFPlatform* platform) default: break; } + + platform->pageSize = sysInfo.dwPageSize; } void ffPlatformInitImpl(FFPlatform* platform) @@ -230,5 +232,5 @@ void ffPlatformInitImpl(FFPlatform* platform) getUserShell(platform); getSystemReleaseAndVersion(platform); - getSystemArchitecture(platform); + getSystemArchitectureAndPageSize(platform); } From f93341ac61ca05436df7d658e7590039ec27380a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 8 Nov 2023 09:02:52 +0800 Subject: [PATCH 4/7] TerminalShell: fix terminal name detection on NixOS oops. No one report that... --- src/detection/terminalshell/terminalshell_linux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c index 460f99fc4..ce4d3dea5 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -361,13 +361,13 @@ const FFTerminalShellResult* ffDetectTerminalShell() ffStrbufInitS(&result.shellPrettyName, result.shellExeName); } - if(result.terminalExeName[0] == '.' && ffStrEndsWith(result.terminalExeName, "-wrapper")) + if(result.terminalExeName[0] == '.' && ffStrEndsWith(result.terminalExeName, "-wrapped")) { // For NixOS. Ref: #510 and https://github.com/NixOS/nixpkgs/pull/249428 // We use terminalProcessName when detecting version and font, overriding it for simplication ffStrbufSetNS( &result.terminalProcessName, - (uint32_t) (strlen(result.terminalExeName) - strlen(".-wrapper")), + (uint32_t) (strlen(result.terminalExeName) - strlen(".-wrapped")), result.terminalExeName + 1); } From 788307e98d9ee414a57d072b0043dc1c67f7c6e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 8 Nov 2023 09:11:16 +0800 Subject: [PATCH 5/7] Doc: update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e61c081f..fe57fe7e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 2.2.3 + +Bugfixes: +* Fix local ips detection on Android. Regression from `2.0.0` (LocalIP, Android) +* Fix terminal detection on NixOS (Terminal) + # 2.2.2 Changes: From df2fdf05e6cdc53957d345dc7ca4cd4cfb55840c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 8 Nov 2023 10:14:31 +0800 Subject: [PATCH 6/7] Release v2.2.3 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 759797071..06e5e4f59 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.2.2 + VERSION 2.2.3 LANGUAGES C DESCRIPTION "Fast neofetch-like system information tool" HOMEPAGE_URL "https://github.com/fastfetch-cli/fastfetch" From ac654ff346475e9b0f7e8bad065ff809144bd38b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 8 Nov 2023 10:42:13 +0800 Subject: [PATCH 7/7] Host (macOS): update the latest models --- CHANGELOG.md | 3 +++ src/detection/host/host_apple.c | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe57fe7e8..bab497143 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # 2.2.3 +Features: +* Update the latest mac models (Host, macOS) + Bugfixes: * Fix local ips detection on Android. Regression from `2.0.0` (LocalIP, Android) * Fix terminal detection on NixOS (Terminal) diff --git a/src/detection/host/host_apple.c b/src/detection/host/host_apple.c index 1c5789c70..d56f125a6 100644 --- a/src/detection/host/host_apple.c +++ b/src/detection/host/host_apple.c @@ -108,6 +108,15 @@ static const char* getProductName(const FFstrbuf* hwModel) else if(ffStrbufStartsWithS(hwModel, "Mac")) { const char* version = hwModel->chars + strlen("Mac"); + if(ffStrEquals(version, "15,3")) return "MacBook Pro (14-inch, Nov 2023, Two Thunderbolt / USB 4 ports)"; + if(ffStrEquals(version, "15,4")) return "iMac (24-inch, 2023, Two Thunderbolt / USB 4 ports)"; + if(ffStrEquals(version, "15,5")) return "iMac (24-inch, 2023, Two Thunderbolt / USB 4 ports, Two USB 3 ports)"; + if(ffStrEquals(version, "15,6") || + ffStrEquals(version, "15,8") || + ffStrEquals(version, "15,10")) return "MacBook Pro (14-inch, Nov 2023, Three Thunderbolt 4 ports)"; + if(ffStrEquals(version, "15,7") || + ffStrEquals(version, "15,9") || + ffStrEquals(version, "15,11")) return "MacBook Pro (16-inch, Nov 2023, Three Thunderbolt 4 ports)"; if(ffStrEquals(version, "14,15")) return "MacBook Air (15-inch, M2, 2023)"; if(ffStrEquals(version, "14,14")) return "Mac Studio (M2 Ultra, 2023, Two Thunderbolt 4 front ports)"; if(ffStrEquals(version, "14,13")) return "Mac Studio (M2 Max, 2023, Two USB-C front ports)";