mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-12 10:22:12 +02:00
Packages (Windows): support winget packages count
Guarded behind `--allow-slow-operations`
This commit is contained in:
@@ -27,6 +27,7 @@ typedef struct FFPackagesResult
|
||||
uint32_t rpm;
|
||||
uint32_t scoop;
|
||||
uint32_t snap;
|
||||
uint32_t winget;
|
||||
uint32_t xbps;
|
||||
|
||||
uint32_t all; //Make sure this goes last
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "packages.h"
|
||||
#include "common/processing.h"
|
||||
#include "util/stringUtils.h"
|
||||
|
||||
#include <handleapi.h>
|
||||
@@ -62,7 +63,7 @@ static void detectChoco(FF_MAYBE_UNUSED FFPackagesResult* result)
|
||||
result->choco = getNumElements(chocoPath, FILE_ATTRIBUTE_DIRECTORY, "choco");
|
||||
}
|
||||
|
||||
static void detectPacman(FF_MAYBE_UNUSED FFPackagesResult* result)
|
||||
static void detectPacman(FFPackagesResult* result)
|
||||
{
|
||||
const char* msystemPrefix = getenv("MSYSTEM_PREFIX");
|
||||
if(!msystemPrefix)
|
||||
@@ -75,9 +76,40 @@ static void detectPacman(FF_MAYBE_UNUSED FFPackagesResult* result)
|
||||
result->pacman = getNumElements(pacmanPath, FILE_ATTRIBUTE_DIRECTORY, NULL);
|
||||
}
|
||||
|
||||
static void detectWinget(FFPackagesResult* result)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
|
||||
if (ffProcessAppendStdOut(&buffer, (char* []) {
|
||||
"winget.exe",
|
||||
"list",
|
||||
"--disable-interactivity",
|
||||
NULL,
|
||||
}))
|
||||
return;
|
||||
|
||||
uint32_t index = ffStrbufFirstIndexS(&buffer, "--\r\n"); // Ignore garbage and table headers
|
||||
if (index == buffer.length)
|
||||
return;
|
||||
|
||||
uint32_t count = 0;
|
||||
for (
|
||||
index += strlen("--\r\n");
|
||||
(index = ffStrbufNextIndexC(&buffer, index, '\n')) < buffer.length;
|
||||
++index
|
||||
)
|
||||
++count;
|
||||
|
||||
if (buffer.chars[buffer.length - 1] != '\n') // count last line
|
||||
++count;
|
||||
|
||||
result->winget = count;
|
||||
}
|
||||
|
||||
void ffDetectPackagesImpl(FFPackagesResult* result)
|
||||
{
|
||||
detectScoop(result);
|
||||
detectChoco(result);
|
||||
detectPacman(result);
|
||||
if (instance.config.allowSlowOperations)
|
||||
detectWinget(result);
|
||||
}
|
||||
|
||||
+2
-1
@@ -129,7 +129,7 @@ static inline void printCommandHelp(const char* command)
|
||||
}
|
||||
else if(ffStrEqualsIgnCase(command, "packages-format"))
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("packages", "{2} (pacman){?3}[{3}]{?}, {4} (dpkg), {5} (rpm), {6} (emerge), {7} (eopkg), {8} (xbps), {9} (nix-system), {10} (nix-user), {11} (nix-default), {12} (apk), {13} (pkg), {14} (flatpak-system), {15} (flatpack-user), {16} (snap), {17} (brew), {18} (brew-cask), {19} (port), {20} (scoop), {21} (choco), {22} (pkgtool), {23} (paludis)", 23,
|
||||
constructAndPrintCommandHelpFormat("packages", "{2} (pacman){?3}[{3}]{?}, {4} (dpkg), {5} (rpm), {6} (emerge), {7} (eopkg), {8} (xbps), {9} (nix-system), {10} (nix-user), {11} (nix-default), {12} (apk), {13} (pkg), {14} (flatpak-system), {15} (flatpack-user), {16} (snap), {17} (brew), {18} (brew-cask), {19} (port), {20} (scoop), {21} (choco), {22} (pkgtool), {23} (paludis), {24} (winget)", 24,
|
||||
"Number of all packages",
|
||||
"Number of pacman packages",
|
||||
"Pacman branch on manjaro",
|
||||
@@ -153,6 +153,7 @@ static inline void printCommandHelp(const char* command)
|
||||
"Number of choco packages",
|
||||
"Number of pkgtool packages",
|
||||
"Number of paludis packages"
|
||||
"Number of winget packages"
|
||||
);
|
||||
}
|
||||
else if(ffStrEqualsIgnCase(command, "shell-format"))
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "modules/packages/packages.h"
|
||||
#include "util/stringUtils.h"
|
||||
|
||||
#define FF_PACKAGES_NUM_FORMAT_ARGS 22
|
||||
#define FF_PACKAGES_NUM_FORMAT_ARGS 24
|
||||
|
||||
void ffPrintPackages(FFPackagesOptions* options)
|
||||
{
|
||||
@@ -63,6 +63,7 @@ void ffPrintPackages(FFPackagesOptions* options)
|
||||
FF_PRINT_PACKAGE(choco)
|
||||
FF_PRINT_PACKAGE(pkgtool)
|
||||
FF_PRINT_PACKAGE(paludis)
|
||||
FF_PRINT_PACKAGE(winget)
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
@@ -91,6 +92,8 @@ void ffPrintPackages(FFPackagesOptions* options)
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts.scoop},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts.choco},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts.pkgtool},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts.paludis},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts.winget},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user