diff --git a/CMakeLists.txt b/CMakeLists.txt index e348e275b..d59a68ecf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -302,6 +302,8 @@ endif() if(BSD OR APPLE) list(APPEND LIBFASTFETCH_SRC src/common/sysctl.c + src/detection/uptime/uptime_bsd.c + src/detection/processes/processes_bsd.c ) endif() @@ -309,7 +311,9 @@ if(LINUX OR ANDROID) list(APPEND LIBFASTFETCH_SRC src/detection/cpu/cpu_linux.c src/detection/memory/memory_linux.c + src/detection/processes/processes_linux.c src/detection/swap/swap_linux.c + src/detection/uptime/uptime_linux.c ) endif() @@ -319,8 +323,6 @@ if(LINUX OR ANDROID OR BSD) src/detection/disk/disk_linux.c src/detection/temps/temps_linux.c src/detection/opengl/opengl_linux.c - src/detection/processes/processes_linux.c - src/detection/uptime/uptime_linux.c src/detection/packages/packages_linux.c src/detection/poweradapter/poweradapter_nosupport.c @@ -378,7 +380,7 @@ if(WIN32) src/util/windows/wmi.cpp src/util/windows/getline.c src/util/windows/pwd.c - src/util/windows/utsname.cpp + src/util/windows/utsname.c src/detection/poweradapter/poweradapter_nosupport.c src/detection/media/media_nosupport.c @@ -406,8 +408,6 @@ if(APPLE) src/detection/temps/temps_apple.c src/detection/font/font_apple.m src/detection/opengl/opengl_apple.c - src/detection/processes/processes_apple.c - src/detection/uptime/uptime_apple.c src/detection/packages/packages_apple.c src/detection/bios/bios_nosupport.c diff --git a/src/detection/disk/disk_apple.m b/src/detection/disk/disk_apple.m index a267d1177..42c2e6a26 100644 --- a/src/detection/disk/disk_apple.m +++ b/src/detection/disk/disk_apple.m @@ -35,12 +35,12 @@ void ffDetectDisksImpl(FFDiskResult* disks) NSError* error; NSNumber* isBrowsable; - if(removable) - disk->type = FF_DISK_TYPE_EXTERNAL; - else if([url getResourceValue:&isBrowsable forKey:NSURLVolumeIsBrowsableKey error:&error] == YES && isBrowsable.boolValue) - disk->type = FF_DISK_TYPE_REGULAR; - else + if([url getResourceValue:&isBrowsable forKey:NSURLVolumeIsBrowsableKey error:&error] == YES && !isBrowsable.boolValue) disk->type = FF_DISK_TYPE_HIDDEN; + else if(removable) + disk->type = FF_DISK_TYPE_EXTERNAL; + else + disk->type = FF_DISK_TYPE_REGULAR; NSString* volumeName; if([url getResourceValue:&volumeName forKey:NSURLVolumeNameKey error:&error] == YES) diff --git a/src/detection/packages/packages.c b/src/detection/packages/packages.c index 08d79e054..2404f74e3 100644 --- a/src/detection/packages/packages.c +++ b/src/detection/packages/packages.c @@ -1,6 +1,8 @@ #include "packages.h" #include "detection/internal.h" +#include + void ffDetectPackagesImpl(const FFinstance* instance, FFPackagesResult* result); const FFPackagesResult* ffDetectPackages(const FFinstance* instance) @@ -11,21 +13,7 @@ const FFPackagesResult* ffDetectPackages(const FFinstance* instance) ffDetectPackagesImpl(instance, &result); - result.all = 0 - + result.pacman - + result.dpkg - + result.rpm - + result.emerge - + result.xbps - + result.nixSystem - + result.nixUser - + result.nixDefault - + result.apk - + result.pkg - + result.flatpak - + result.snap - + result.brew - + result.port - + result.scoop; + for(uint32_t i = 0; i < offsetof(FFPackagesResult, all) / sizeof(uint32_t); ++i) + result.all += ((uint32_t *)&result)[i]; ); } diff --git a/src/detection/packages/packages.h b/src/detection/packages/packages.h index 92bd26d63..1992b8d8d 100644 --- a/src/detection/packages/packages.h +++ b/src/detection/packages/packages.h @@ -7,10 +7,9 @@ typedef struct FFPackagesResult { - uint32_t all; - uint32_t apk; uint32_t brew; + uint32_t choco; uint32_t dpkg; uint32_t emerge; uint32_t flatpak; @@ -25,6 +24,8 @@ typedef struct FFPackagesResult uint32_t snap; uint32_t xbps; + uint32_t all; //Make sure this goes last + FFstrbuf pacmanBranch; } FFPackagesResult; diff --git a/src/detection/packages/packages_windows.c b/src/detection/packages/packages_windows.c index 1a9fe2ade..93739e9bf 100644 --- a/src/detection/packages/packages_windows.c +++ b/src/detection/packages/packages_windows.c @@ -25,15 +25,34 @@ static uint32_t getNumElements(const char* searchPath /* including `\*` suffix * return counter; } -void ffDetectPackagesImpl(const FFinstance* instance, FFPackagesResult* result) +static void detectScoop(const FFinstance* instance, FFPackagesResult* result) +{ + char scoopPath[MAX_PATH + 3]; + strcpy(scoopPath, instance->state.passwd->pw_dir); + strncat(scoopPath, "/scoop/apps/*", sizeof(scoopPath) - 1 - strlen(scoopPath)); + result->scoop = getNumElements(scoopPath, FILE_ATTRIBUTE_DIRECTORY); + if(result->scoop > 0) + result->scoop--; // scoop +} + +static void detectChoco(const FFinstance* instance, FFPackagesResult* result) { FF_UNUSED(instance); - FFstrbuf scoopPath; - ffStrbufInitS(&scoopPath, instance->state.passwd->pw_dir); - ffStrbufAppendS(&scoopPath, "/scoop/apps/*"); - result->scoop = getNumElements(scoopPath.chars, FILE_ATTRIBUTE_DIRECTORY); - if(result->scoop > 0) - result->scoop--; // scoop - ffStrbufDestroy(&scoopPath); + const char* chocoInstall = getenv("ChocolateyInstall"); + if(!chocoInstall || chocoInstall[0] == '\0') + return; + + char chocoPath[MAX_PATH + 3]; + strcpy(chocoPath, chocoInstall); + strncat(chocoPath, "/lib/*", sizeof(chocoPath) - 1 - strlen(chocoPath)); + result->choco = getNumElements(chocoPath, FILE_ATTRIBUTE_DIRECTORY); + if(result->choco > 0) + result->choco--; // choco +} + +void ffDetectPackagesImpl(const FFinstance* instance, FFPackagesResult* result) +{ + detectScoop(instance, result); + detectChoco(instance, result); } diff --git a/src/detection/processes/processes_apple.c b/src/detection/processes/processes_bsd.c similarity index 85% rename from src/detection/processes/processes_apple.c rename to src/detection/processes/processes_bsd.c index bbed0db2d..a09b05a96 100644 --- a/src/detection/processes/processes_apple.c +++ b/src/detection/processes/processes_bsd.c @@ -1,6 +1,10 @@ #include "processes.h" #include +#ifdef __FreeBSD__ + #include + #include +#endif uint32_t ffDetectProcesses(FFinstance* instance, FFstrbuf* error) { diff --git a/src/detection/swap/swap_bsd.c b/src/detection/swap/swap_bsd.c index 8af98a16f..8e8089600 100644 --- a/src/detection/swap/swap_bsd.c +++ b/src/detection/swap/swap_bsd.c @@ -1,6 +1,8 @@ #include "swap.h" +#include "common/sysctl.h" void ffDetectSwapImpl(FFMemoryStorage* swap) { - ffStrbufAppendS(&swap->error, "Not implemented"); + swap->bytesTotal = (uint64_t)ffSysctlGetInt64("vm.swap_total", 0); + swap->bytesUsed = (uint64_t)ffSysctlGetInt64("vm.swap_reserved", 0); } diff --git a/src/detection/terminalfont/terminalfont.c b/src/detection/terminalfont/terminalfont.c index 3cc33bd59..b673ff4fd 100644 --- a/src/detection/terminalfont/terminalfont.c +++ b/src/detection/terminalfont/terminalfont.c @@ -323,7 +323,7 @@ const FFTerminalFontResult* ffDetectTerminalFont(const FFinstance* instance) if(terminalShell->terminalProcessName.length == 0) ffStrbufAppendS(&result.error, "Terminal font needs successfull terminal detection"); - else if(detectTerminalFontCommon(instance, terminalShell, &result)) + else if(!detectTerminalFontCommon(instance, terminalShell, &result)) ffDetectTerminalFontPlatform(instance, terminalShell, &result); if(result.error.length == 0 && result.font.pretty.length == 0) diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c index e04f41f66..5040cede5 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -13,6 +13,10 @@ #ifdef __APPLE__ #include +#elif defined(__FreeBSD__) + #include + #include + #include #endif static void setExeName(FFstrbuf* exe, const char** exeName) @@ -47,7 +51,13 @@ static void getProcessInformation(pid_t pid, FFstrbuf* processName, FFstrbuf* ex #else - //TODO: support bsd (https://www.freebsd.org/cgi/man.cgi?query=kinfo_getproc) + size_t size = exe->allocated; + if(!sysctl( + (int[]){CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, pid}, 4, + exe->chars, &size, + NULL, 0 + )) + exe->length = (uint32_t)size; #endif @@ -92,8 +102,19 @@ static const char* getProcessNameAndPpid(pid_t pid, char* name, pid_t* ppid) #else - //TODO: support bsd (https://www.freebsd.org/cgi/man.cgi?query=kinfo_getproc) - error = "unimplemented"; + struct kinfo_proc proc; + size_t size = sizeof(proc); + if(sysctl( + (int[]){CTL_KERN, KERN_PROC, KERN_PROC_PID, pid}, 4, + &proc, &size, + NULL, 0 + )) + error = "sysctl(KERN_PROC_PID) failed"; + else + { + *ppid = (pid_t)proc.ki_ppid; + strncpy(name, proc.ki_comm, COMMLEN); + } #endif diff --git a/src/detection/uptime/uptime_apple.c b/src/detection/uptime/uptime_bsd.c similarity index 95% rename from src/detection/uptime/uptime_apple.c rename to src/detection/uptime/uptime_bsd.c index c32496ef3..e21eb4183 100644 --- a/src/detection/uptime/uptime_apple.c +++ b/src/detection/uptime/uptime_bsd.c @@ -2,6 +2,7 @@ #include #include +#include uint64_t ffDetectUptime(const FFinstance* instance) { diff --git a/src/logo/builtin.c b/src/logo/builtin.c index cbc16ae4b..4bdeaf4ff 100644 --- a/src/logo/builtin.c +++ b/src/logo/builtin.c @@ -1300,6 +1300,38 @@ static const FFlogo* getLogoWindows11() { FF_LOGO_INIT FF_LOGO_NAMES("Windows 11", "Windows Server 2022") + FF_LOGO_LINES( + "$1\n" + ",,**************/ ///////////////()\n" + "****************/ ///////////////((\n" + "***************// //////////////(((\n" + "**************/// ////////////(((((\n" + "************///// /////////((((((((\n" + "*********//////// /////((((((((((((\n" + "*******////////// ///((((((((((((((\n" + "****///////////// (((((((((((((((((\n" + "\n" + "/////////////(((( (((((((((((((((((\n" + "////////////((((( (((((((((((((((((\n" + "///////////(((((( (((((((((((((((((\n" + "/////////(((((((( (((((((((((((((((\n" + "///////(((((((((( (((((((((((((((((\n" + "////((((((((((((( (((((((((((((((((\n" + "((((((((((((((((( (((((((((((((((((\n" + "((((((((((((((((( (((((((((((((((()" + ) + FF_LOGO_COLORS( + "34" //blue + ) + FF_LOGO_COLOR_KEYS("33"); //yellow + FF_LOGO_COLOR_TITLE("36"); //cyan + FF_LOGO_RETURN +} + +static const FFlogo* getLogoWindows11Old() +{ + FF_LOGO_INIT + FF_LOGO_NAMES("Windows 11_old") FF_LOGO_LINES( "$1\n" "################ ################\n" @@ -1354,7 +1386,7 @@ static const FFlogo* getLogoWindows8() FF_LOGO_COLORS( "36" //cyan ) - FF_LOGO_COLOR_KEYS("36"); //cyan + FF_LOGO_COLOR_KEYS("33"); //yellow FF_LOGO_COLOR_TITLE("37"); //white FF_LOGO_RETURN } @@ -2133,6 +2165,7 @@ GetLogoMethod* ffLogoBuiltinGetAll() getLogoMintOld, getLogoMsys2, getLogoWindows11, + getLogoWindows11Old, getLogoWindows8, getLogoWindows, getLogoNixOS, diff --git a/src/modules/kernel.c b/src/modules/kernel.c index 062b04f42..72096ce55 100644 --- a/src/modules/kernel.c +++ b/src/modules/kernel.c @@ -9,7 +9,15 @@ void ffPrintKernel(FFinstance* instance) if(instance->config.kernel.outputFormat.length == 0) { ffPrintLogoAndKey(instance, FF_KERNEL_MODULE_NAME, 0, &instance->config.kernel.key); - puts(instance->state.utsname.release); + + #ifdef _WIN32 + if(instance->state.utsname.version[0] != '\0') + printf("%s (%s)\n", instance->state.utsname.release, instance->state.utsname.version); + else + puts(instance->state.utsname.release); + #else + puts(instance->state.utsname.release); + #endif } else { diff --git a/src/modules/packages.c b/src/modules/packages.c index 488334bb1..3f9d6d990 100644 --- a/src/modules/packages.c +++ b/src/modules/packages.c @@ -53,6 +53,7 @@ void ffPrintPackages(FFinstance* instance) FF_PRINT_PACKAGE(brew) FF_PRINT_PACKAGE(port) FF_PRINT_PACKAGE(scoop) + FF_PRINT_PACKAGE(choco) //Fix linter warning of unused value of all (void) all; diff --git a/src/util/windows/utsname.c b/src/util/windows/utsname.c new file mode 100644 index 000000000..07f6e52e8 --- /dev/null +++ b/src/util/windows/utsname.c @@ -0,0 +1,114 @@ +#include "fastfetch.h" +#include "utsname.h" + +#define WIN32_LEAN_AND_MEAN 1 +#include + +static int detectSysname(struct utsname *name) +{ + strncpy(name->sysname, "Windows_NT", UTSNAME_MAXLENGTH); + return 0; +} + +static int detectNodename(struct utsname *name) +{ + DWORD bufSize = UTSNAME_MAXLENGTH - 1; + if(!GetComputerNameA(name->nodename, &bufSize)) + return 1; + name->nodename[bufSize] = '\0'; + return 0; +} + +static int detectVersion(struct utsname *name) +{ + HKEY hKey; + if(RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS) + return 1; + + DWORD bufSize; + + DWORD currentMajorVersionNumber; + bufSize = sizeof(currentMajorVersionNumber); + if(RegGetValueA(hKey, NULL, "CurrentMajorVersionNumber", RRF_RT_REG_DWORD, NULL, ¤tMajorVersionNumber, &bufSize) != ERROR_SUCCESS) + { + RegCloseKey(hKey); + return 1; + } + + DWORD currentMinorVersionNumber; + bufSize = sizeof(currentMinorVersionNumber); + if(RegGetValueA(hKey, NULL, "CurrentMinorVersionNumber", RRF_RT_REG_DWORD, NULL, ¤tMinorVersionNumber, &bufSize) != ERROR_SUCCESS) + { + RegCloseKey(hKey); + return 1; + } + + char currentBuildNumber[32]; + bufSize = sizeof(currentBuildNumber); + if(RegGetValueA(hKey, NULL, "CurrentBuildNumber", RRF_RT_REG_SZ, NULL, currentBuildNumber, &bufSize) != ERROR_SUCCESS) + strcpy(currentBuildNumber, "0"); + + DWORD ubr; + bufSize = sizeof(ubr); + if(RegGetValueA(hKey, NULL, "UBR", RRF_RT_REG_DWORD, NULL, &ubr, &bufSize) != ERROR_SUCCESS || bufSize != sizeof(ubr)) + ubr = 0; + + snprintf(name->release, sizeof(name->release), "%u.%u.%s.%u", (unsigned)currentMajorVersionNumber, (unsigned)currentMinorVersionNumber, currentBuildNumber, (unsigned)ubr); + + bufSize = sizeof(name->version); + RegGetValueA(hKey, NULL, "DisplayVersion", RRF_RT_REG_SZ, NULL, name->version, &bufSize); + + RegCloseKey(hKey); + return 0; +} + +static int detectMachine(struct utsname *name) +{ + // Get hardware info + SYSTEM_INFO sysInfo = {0}; + GetNativeSystemInfo(&sysInfo); + + // Set processor architecture + switch(sysInfo.wProcessorArchitecture) + { + case PROCESSOR_ARCHITECTURE_AMD64: + strcpy(name->machine, "x86_64"); + break; + case PROCESSOR_ARCHITECTURE_IA64: + strcpy(name->machine, "ia64"); + break; + case PROCESSOR_ARCHITECTURE_INTEL: + strcpy(name->machine, "x86"); + break; + case PROCESSOR_ARCHITECTURE_ARM64: + strcpy(name->machine, "aarch64"); + break; + case PROCESSOR_ARCHITECTURE_ARM: + strcpy(name->machine, "arm"); + break; + case PROCESSOR_ARCHITECTURE_PPC: + strcpy(name->machine, "ppc"); + break; + case PROCESSOR_ARCHITECTURE_MIPS: + strcpy(name->machine, "mips"); + break; + case PROCESSOR_ARCHITECTURE_UNKNOWN: + default: + strcpy(name->machine, "unknown"); + break; + } + + return 0; +} + +int uname(struct utsname *name) +{ + memset(name, 0, sizeof(*name)); + + int sysnameResult = detectSysname(name); + int nodenameResult = detectNodename(name); + int versionResult = detectVersion(name); + int machineResult = detectMachine(name); + + return sysnameResult || nodenameResult || versionResult || machineResult; +} diff --git a/src/util/windows/utsname.cpp b/src/util/windows/utsname.cpp deleted file mode 100644 index 10c0f7b68..000000000 --- a/src/util/windows/utsname.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "util/windows/wmi.hpp" -extern "C" { - #include "utsname.h" -} - -int uname(struct utsname *name) -{ - memset(name, 0, sizeof(*name)); - - strncpy(name->sysname, "Windows_NT", UTSNAME_MAXLENGTH); - - FFWmiQuery query(L"SELECT Version, CSName, OSArchitecture FROM Win32_OperatingSystem"); - if(!query) - return -1; - - if(FFWmiRecord record = query.next()) - { - FFstrbuf value; - ffStrbufInit(&value); - record.getString(L"Version", &value); - strncpy(name->release, value.chars, UTSNAME_MAXLENGTH); - - ffStrbufClear(&value); - record.getString(L"CSName", &value); - strncpy(name->nodename, value.chars, UTSNAME_MAXLENGTH); - - ffStrbufClear(&value); - record.getString(L"OSArchitecture", &value); - strncpy(name->machine, value.chars, UTSNAME_MAXLENGTH); - - ffStrbufDestroy(&value); - } - - return 0; -}