From 068cbafe3dfe847fa0c533d5b126f2ea30861418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 18 Jan 2023 23:08:53 +0800 Subject: [PATCH] Packages: detect pacman package count inside MSYS2 env (Windows) --- CHANGELOG.md | 1 + src/detection/packages/packages_windows.c | 24 +++++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d55e32538..1d35baf7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ Features: * Add Wifi module support for Linux * Detect scaled resolutions (Windows, macOS) * Optimise font module printing (Windows) +* Detect pacman package count inside MSYS2 environment (Windows) Logos: * Raspbian (@IamNoRobot, #373) diff --git a/src/detection/packages/packages_windows.c b/src/detection/packages/packages_windows.c index fa50bdd5b..afd016c6d 100644 --- a/src/detection/packages/packages_windows.c +++ b/src/detection/packages/packages_windows.c @@ -17,10 +17,10 @@ static uint32_t getNumElements(const char* searchPath /* including `\*` suffix * counter++; } while (FindNextFileA(hFind, &wfd)); FindClose(hFind); - } - if(type == FILE_ATTRIBUTE_DIRECTORY && counter >= 2) - counter -= 2; // accounting for . and .. + if(type == FILE_ATTRIBUTE_DIRECTORY && counter >= 2) + counter -= 2; // accounting for . and .. + } return counter; } @@ -35,10 +35,8 @@ static void detectScoop(const FFinstance* instance, FFPackagesResult* result) result->scoop--; // scoop } -static void detectChoco(const FFinstance* instance, FFPackagesResult* result) +static void detectChoco(FF_MAYBE_UNUSED const FFinstance* instance, FFPackagesResult* result) { - FF_UNUSED(instance); - const char* chocoInstall = getenv("ChocolateyInstall"); if(!chocoInstall || chocoInstall[0] == '\0') return; @@ -51,8 +49,22 @@ static void detectChoco(const FFinstance* instance, FFPackagesResult* result) result->choco--; // choco } +static void detectPacman(FF_MAYBE_UNUSED const FFinstance* instance, FFPackagesResult* result) +{ + const char* msystemPrefix = getenv("MSYSTEM_PREFIX"); + if(!msystemPrefix) + return; + + // MSYS2 + char pacmanPath[MAX_PATH + 3]; + strcpy(pacmanPath, msystemPrefix); + strncat(pacmanPath, "/../var/lib/pacman/local/*", sizeof(pacmanPath) - 1 - strlen(pacmanPath)); + result->pacman = getNumElements(pacmanPath, FILE_ATTRIBUTE_DIRECTORY); +} + void ffDetectPackagesImpl(const FFinstance* instance, FFPackagesResult* result) { detectScoop(instance, result); detectChoco(instance, result); + detectPacman(instance, result); }