Packages (Windows): add option --packages-winget

This commit is contained in:
李通洲
2023-10-29 19:37:31 +08:00
parent 627d5fc659
commit 3a84a1a5fa
10 changed files with 55 additions and 14 deletions
+1
View File
@@ -7,6 +7,7 @@ Changes:
* Display keys `percent*` and `size*` in JSON config are restructured. `{ "sizeNdigits": 1 }` is now `{ "size": { "ndigits": 1 } }`
* With the introduction of `--migrate-config`, the old flag based config file is deprecated, and will be removed in 3.0.0 (next major version)
* Support of `--gen-config conf` is deprecated accordingly, and will be removed in 2.3.0 (next minor version)
* A new flag `--packages-winget` is introduced to control whether `winget` packages count should be detected. It was controlled by `--allow-slow-operations` previously. Note it's a very slow operation, please enable it with caution.
Features:
* Quirks for MIPS platforms (CPU, Linux)
+14 -4
View File
@@ -708,10 +708,6 @@
"const": "os",
"description": "Print operating system name and version"
},
{
"const": "packages",
"description": "List installed package managers and count of installed packages"
},
{
"const": "player",
"description": "Print music player name"
@@ -1282,6 +1278,20 @@
},
"additionalProperties": false
},
{
"title": "Packages",
"properties": {
"type": {
"const": "packages",
"description": "List installed package managers and count of installed packages"
},
"winget": {
"description": "Set if winget package count should be detected.\nNote this is very slow operation. Please make sure `winget list` works before enable this option\nWindows only",
"type": "boolean",
"default": false
}
}
},
{
"title": "Public IP",
"properties": {
+1
View File
@@ -137,6 +137,7 @@ Module specific options:
--disk-use-available <?value>: Use f_bavail (lpFreeBytesAvailableToCaller for Windows) instead of f_bfree to calculate used bytes. Default is false
--diskio-name-prefix <str>: Show disks with given name prefix only. Default is empty
--bluetooth-show-disconnected: <?value>: Set if disconnected bluetooth devices should be printed. Default is false
--packages-winget: <?value>: Set if winget package count should be detected. Default is false
--display-compact-type: <?string>: Set if all displays should be printed in one line. Default is none
--display-detect-name: <?value>: Set if display name should be detected and printed (if supported). Default is false
--display-precise-refresh-rate: <?value>:Set if decimal refresh rates should not be rounded into integers when printing. Default is true
+3 -3
View File
@@ -3,11 +3,11 @@
#include <stddef.h>
void ffDetectPackagesImpl(FFPackagesResult* result);
void ffDetectPackagesImpl(FFPackagesResult* result, FFPackagesOptions* options);
const char* ffDetectPackages(FFPackagesResult* result)
const char* ffDetectPackages(FFPackagesResult* result, FFPackagesOptions* options)
{
ffDetectPackagesImpl(result);
ffDetectPackagesImpl(result, options);
for(uint32_t i = 0; i < offsetof(FFPackagesResult, all) / sizeof(uint32_t); ++i)
result->all += ((uint32_t *)result)[i];
+1 -1
View File
@@ -36,6 +36,6 @@ typedef struct FFPackagesResult
FFstrbuf pacmanBranch;
} FFPackagesResult;
const char* ffDetectPackages(FFPackagesResult* result);
const char* ffDetectPackages(FFPackagesResult* result, FFPackagesOptions* options);
#endif
+1 -1
View File
@@ -68,7 +68,7 @@ static uint32_t getMacPortsPackages()
return countMacPortsPackages(FASTFETCH_TARGET_DIR_ROOT"/opt/local");
}
void ffDetectPackagesImpl(FFPackagesResult* result)
void ffDetectPackagesImpl(FFPackagesResult* result, FF_MAYBE_UNUSED FFPackagesOptions* options)
{
getBrewPackages(result);
result->port = getMacPortsPackages();
+1 -1
View File
@@ -327,7 +327,7 @@ static void getPackageCountsBedrock(FFstrbuf* baseDir, FFPackagesResult* package
ffStrbufSubstrBefore(baseDir, baseDirLength);
}
void ffDetectPackagesImpl(FFPackagesResult* result)
void ffDetectPackagesImpl(FFPackagesResult* result, FF_MAYBE_UNUSED FFPackagesOptions* options)
{
FF_STRBUF_AUTO_DESTROY baseDir = ffStrbufCreateA(512);
ffStrbufAppendS(&baseDir, FASTFETCH_TARGET_DIR_ROOT);
+2 -2
View File
@@ -105,11 +105,11 @@ static void detectWinget(FFPackagesResult* result)
result->winget = count;
}
void ffDetectPackagesImpl(FFPackagesResult* result)
void ffDetectPackagesImpl(FFPackagesResult* result, FFPackagesOptions* options)
{
detectScoop(result);
detectChoco(result);
detectPacman(result);
if (instance.config.general.allowSlowOperations)
if (options->winget)
detectWinget(result);
}
+4
View File
@@ -8,4 +8,8 @@ typedef struct FFPackagesOptions
{
FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs;
#ifdef _WIN32
bool winget;
#endif
} FFPackagesOptions;
+27 -2
View File
@@ -11,7 +11,7 @@ void ffPrintPackages(FFPackagesOptions* options)
FFPackagesResult counts = {};
ffStrbufInit(&counts.pacmanBranch);
const char* error = ffDetectPackages(&counts);
const char* error = ffDetectPackages(&counts, options);
if(error)
{
@@ -109,6 +109,14 @@ bool ffParsePackagesCommandOptions(FFPackagesOptions* options, const char* key,
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
return true;
#ifdef _WIN32
if(ffStrEqualsIgnCase(subKey, "winget"))
{
options->winget = ffOptionParseBoolean(value);
return true;
}
#endif
return false;
}
@@ -125,6 +133,14 @@ void ffParsePackagesJsonObject(FFPackagesOptions* options, yyjson_val* module)
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
continue;
#ifdef _WIN32
if (ffStrEqualsIgnCase(key, "winget"))
{
options->winget = yyjson_get_bool(val);
continue;
}
#endif
ffPrintError(FF_PACKAGES_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
}
@@ -135,6 +151,11 @@ void ffGeneratePackagesJsonConfig(FFPackagesOptions* options, yyjson_mut_doc* do
ffInitPackagesOptions(&defaultOptions);
ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs);
#ifdef _WIN32
if (options->winget != defaultOptions.winget)
yyjson_mut_obj_add_bool(doc, module, "winget", options->winget);
#endif
}
void ffGeneratePackagesJsonResult(FF_MAYBE_UNUSED FFPackagesOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
@@ -142,7 +163,7 @@ void ffGeneratePackagesJsonResult(FF_MAYBE_UNUSED FFPackagesOptions* options, yy
FFPackagesResult counts = {};
ffStrbufInit(&counts.pacmanBranch);
const char* error = ffDetectPackages(&counts);
const char* error = ffDetectPackages(&counts, options);
if(error)
{
@@ -225,6 +246,10 @@ void ffInitPackagesOptions(FFPackagesOptions* options)
ffGeneratePackagesJsonConfig
);
ffOptionInitModuleArg(&options->moduleArgs);
#ifdef _WIN32
options->winget = false;
#endif
}
void ffDestroyPackagesOptions(FFPackagesOptions* options)