Skip to content

Commit 068cbaf

Browse files
committed
Packages: detect pacman package count inside MSYS2 env (Windows)
1 parent 4ce618c commit 068cbaf

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Features:
2626
* Add Wifi module support for Linux
2727
* Detect scaled resolutions (Windows, macOS)
2828
* Optimise font module printing (Windows)
29+
* Detect pacman package count inside MSYS2 environment (Windows)
2930

3031
Logos:
3132
* Raspbian (@IamNoRobot, #373)

src/detection/packages/packages_windows.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ static uint32_t getNumElements(const char* searchPath /* including `\*` suffix *
1717
counter++;
1818
} while (FindNextFileA(hFind, &wfd));
1919
FindClose(hFind);
20-
}
2120

22-
if(type == FILE_ATTRIBUTE_DIRECTORY && counter >= 2)
23-
counter -= 2; // accounting for . and ..
21+
if(type == FILE_ATTRIBUTE_DIRECTORY && counter >= 2)
22+
counter -= 2; // accounting for . and ..
23+
}
2424

2525
return counter;
2626
}
@@ -35,10 +35,8 @@ static void detectScoop(const FFinstance* instance, FFPackagesResult* result)
3535
result->scoop--; // scoop
3636
}
3737

38-
static void detectChoco(const FFinstance* instance, FFPackagesResult* result)
38+
static void detectChoco(FF_MAYBE_UNUSED const FFinstance* instance, FFPackagesResult* result)
3939
{
40-
FF_UNUSED(instance);
41-
4240
const char* chocoInstall = getenv("ChocolateyInstall");
4341
if(!chocoInstall || chocoInstall[0] == '\0')
4442
return;
@@ -51,8 +49,22 @@ static void detectChoco(const FFinstance* instance, FFPackagesResult* result)
5149
result->choco--; // choco
5250
}
5351

52+
static void detectPacman(FF_MAYBE_UNUSED const FFinstance* instance, FFPackagesResult* result)
53+
{
54+
const char* msystemPrefix = getenv("MSYSTEM_PREFIX");
55+
if(!msystemPrefix)
56+
return;
57+
58+
// MSYS2
59+
char pacmanPath[MAX_PATH + 3];
60+
strcpy(pacmanPath, msystemPrefix);
61+
strncat(pacmanPath, "/../var/lib/pacman/local/*", sizeof(pacmanPath) - 1 - strlen(pacmanPath));
62+
result->pacman = getNumElements(pacmanPath, FILE_ATTRIBUTE_DIRECTORY);
63+
}
64+
5465
void ffDetectPackagesImpl(const FFinstance* instance, FFPackagesResult* result)
5566
{
5667
detectScoop(instance, result);
5768
detectChoco(instance, result);
69+
detectPacman(instance, result);
5870
}

0 commit comments

Comments
 (0)