-
Notifications
You must be signed in to change notification settings - Fork 571
Description
Description
1. Currently, the number of applications installed via Scoop is often determined by reading the $ENV:SCOOP
environment variable and counting the number of subfolders in the apps
directory, excluding the scoop
folder itself. I believe this method may originate from traditional installation habits, but Scoop’s official documentation no longer recommends this installation approach. This method depends on the presence of user-defined environment variables and does not cover globally installed applications.
When Scoop is first used to install any application, it appends <root_path>\shims
and <global_path>\shims
entries to the user's and system's Path
environment variables, respectively. Therefore, a more flexible method would be to read the Path
environment variable from the registry, identify entries that contain both scoop
and shims
, infer the root_path
and global_path
of Scoop, and then count the number of subfolders (excluding scoop
itself) in each corresponding apps
directory. This provides a more complete view of the applications installed via Scoop, both locally and globally.
Alternatively, sfsu list
and sfsu list --global
can also be used as complementary tools for application enumeration.
2. Regarding winget, I found a large number of related discussions in this project's issues. Please allow me to summarize and supplement them here.
The currently common method for obtaining the number of applications installed via Winget is by parsing the output of winget list
. However, the results of this command actually include the following categories:
- a. Applications directly installed using
winget install
, which includes these entries; - b. Applications not installed via
winget install
but still manageable by Winget—for example, some programs manually downloaded from the internet or installed through the Microsoft Store; - c. Applications that cannot be managed by Winget, such as games installed via Steam, some Microsoft Store apps, or portable apps that do not write specific registry keys.
In principle, we should only count the first two categories, as these applications can be managed by winget. However, the second category may also include applications installed via other package managers. Due to the inherent characteristics of winget, this issue cannot be resolved. Furthermore, the output of winget list
may include multiple versions or duplicate entries for the same application, which can introduce significant inaccuracies in the statistics.
winget sources are mainly divided into winget
and msstore
. The former will leave records under the directory:
$ENV:TEMP\WinGet\cache\V2_PVD\Microsoft.Winget.Source_8wekyb3d8bbwe\packages.
Specifically, applications installed using winget install
will create subdirectories named after their application IDs within that folder. Additionally, running winget upgrade
may allow applications in the second category above to leave entries there as well. Even if the user manually deletes a subdirectory, running winget upgrade
will automatically recreate it, without duplication. It should be noted that uninstalling a Winget-managed application does not automatically remove its corresponding entry in that directory. As for apps installed from msstore
, I have not yet found any useful records locally. Fortunately, these applications are generally only installable via winget; apps installed through other means will not be marked as originating from msstore
.
In conclusion, rather than using winget list
, which yields highly inaccurate results or may even fail to capture the application count, it is better to count the number of subdirectories under $ENV:TEMP\WinGet\cache\V2_PVD\Microsoft.Winget.Source_8wekyb3d8bbwe\packages
as the basis. I'm not sure whether Winget will automatically clean up records of deleted applications in this folder after a certain period, but regardless of whether users manually clear this folder or not, the resulting error is still significantly lower than using winget list
. I also believe that most users rarely install apps from the msstore
source, so their impact on the statistical results is minimal—or we can simply clarify in the module description that the statistics do not include apps from msstore
.
Motivation
The method for retrieving the number of installed applications using Scoop and Winget exists in the existing module, but the current method has some limitations or issues.
Although using Command Module
meets my needs, integrating it as a native feature of Fastfetch into Fastfetch may be more convenient for users.
Additional context
Below is a test I conducted using sfsu with the following configuration:
It is relatively fast to use sfsu
to count the number from the output. So I think we can first check whether the user has installed sfsu
. If so, we can call it directly. If not, we can read the registry.
┏[ Zertw from ASUS][ 0s][ RAM: 11/15GB][ Sunday at 5:39:13 PM][]
┖[~]
└─Δ fastfetch -c all --format json
[
{
"type": "Command",
"result": "100",
"stat": 767.3283000010997
}
]
┏[ Zertw from ASUS][ 0.836s][ RAM: 11/15GB][ Sunday at 5:39:30 PM][]
┖[~]
└─> (scoop list).Count
Installed apps:
100