mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 00:37:23 +01:00
Packages (Windows): find scoop installation path by parsing scoop config file
This commit is contained in:
@@ -37,7 +37,8 @@ typedef struct FFPackagesResult
|
||||
uint32_t pkgsrc;
|
||||
uint32_t pkgtool;
|
||||
uint32_t rpm;
|
||||
uint32_t scoop;
|
||||
uint32_t scoopUser;
|
||||
uint32_t scoopGlobal;
|
||||
uint32_t snap;
|
||||
uint32_t soar;
|
||||
uint32_t sorcery;
|
||||
|
||||
@@ -34,23 +34,53 @@ static uint32_t getNumElements(const char* searchPath /* including `\*` suffix *
|
||||
return counter;
|
||||
}
|
||||
|
||||
static inline void wrapYyjsonFree(yyjson_doc** doc)
|
||||
{
|
||||
assert(doc);
|
||||
if (*doc)
|
||||
yyjson_doc_free(*doc);
|
||||
}
|
||||
|
||||
static void detectScoop(FFPackagesResult* result)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY scoopPath = ffStrbufCreateA(MAX_PATH + 3);
|
||||
ffStrbufAppendS(&scoopPath, instance.state.platform.homeDir.chars);
|
||||
ffStrbufAppendS(&scoopPath, ".config/scoop/config.json");
|
||||
|
||||
if(ffFindExecutableInPath("scoop.cmd", &scoopPath) == NULL)
|
||||
yyjson_val* root = NULL;
|
||||
|
||||
yyjson_doc* __attribute__((__cleanup__(wrapYyjsonFree))) doc = yyjson_read_file(scoopPath.chars, 0, NULL, NULL);
|
||||
if (doc)
|
||||
{
|
||||
// C:\Users\$USER\scoop\shims\scoop.cmd
|
||||
ffStrbufSubstrBeforeLastC(&scoopPath, '\\');
|
||||
ffStrbufSubstrBeforeLastC(&scoopPath, '\\');
|
||||
root = yyjson_doc_get_root(doc);
|
||||
if (!yyjson_is_obj(root)) root = NULL;
|
||||
}
|
||||
|
||||
{
|
||||
ffStrbufClear(&scoopPath);
|
||||
if (root)
|
||||
ffStrbufSetS(&scoopPath, yyjson_get_str(yyjson_obj_get(root, "root_path")));
|
||||
if (scoopPath.length == 0)
|
||||
{
|
||||
ffStrbufSet(&scoopPath, &instance.state.platform.homeDir);
|
||||
ffStrbufAppendS(&scoopPath, "/scoop");
|
||||
}
|
||||
ffStrbufAppendS(&scoopPath, "/apps/*");
|
||||
result->scoopUser = getNumElements(scoopPath.chars, FILE_ATTRIBUTE_DIRECTORY, "scoop");
|
||||
}
|
||||
else
|
||||
|
||||
{
|
||||
ffStrbufAppendS(&scoopPath, instance.state.platform.homeDir.chars);
|
||||
ffStrbufAppendS(&scoopPath, "/scoop/apps/*");
|
||||
ffStrbufClear(&scoopPath);
|
||||
if (root)
|
||||
ffStrbufSetS(&scoopPath, yyjson_get_str(yyjson_obj_get(root, "global_path")));
|
||||
if (scoopPath.length == 0)
|
||||
{
|
||||
ffStrbufSetS(&scoopPath, getenv("ProgramData"));
|
||||
ffStrbufAppendS(&scoopPath, "/scoop");
|
||||
}
|
||||
ffStrbufAppendS(&scoopPath, "/apps/*");
|
||||
result->scoopGlobal = getNumElements(scoopPath.chars, FILE_ATTRIBUTE_DIRECTORY, "scoop");
|
||||
}
|
||||
result->scoop = getNumElements(scoopPath.chars, FILE_ATTRIBUTE_DIRECTORY, "scoop");
|
||||
}
|
||||
|
||||
static void detectChoco(FF_MAYBE_UNUSED FFPackagesResult* result)
|
||||
|
||||
Reference in New Issue
Block a user