Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit aa49c6c

Browse files
authored
Merge pull request #49 from Romanitho/Review-the-list-installed-apps
Reviewed the "Installed apps" process
2 parents 6d522b9 + a27cec0 commit aa49c6c

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

Sources/Winget-Install-GUI.ps1

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function Get-WingetStatus {
109109
$hasAppInstaller = Get-AppXPackage -Name 'Microsoft.DesktopAppInstaller'
110110
[Version]$AppInstallerVers = $hasAppInstaller.version
111111

112-
if (!($AppInstallerVers -gt "1.18.1391.0")) {
112+
if (!($AppInstallerVers -ge "1.18.1391.0")) {
113113

114114
#installing dependencies
115115
if (!(Get-AppxPackage -Name 'Microsoft.UI.Xaml.2.7')) {
@@ -184,7 +184,7 @@ function Get-WingetAppInfo ($SearchApp) {
184184
[string]$Id
185185
}
186186

187-
#Get list of available upgrades on winget format
187+
#Search for winget apps
188188
$AppResult = & $Winget search $SearchApp --accept-source-agreements --source winget
189189

190190
#Start Convertion of winget format to an array. Check if "-----" exists
@@ -212,18 +212,18 @@ function Get-WingetAppInfo ($SearchApp) {
212212
$versionStart = $lines[$fl].IndexOf($index[2])
213213

214214
# Now cycle in real package and split accordingly
215-
$upgradeList = @()
215+
$searchList = @()
216216
For ($i = $fl + 2; $i -le $lines.Length; $i++) {
217217
$line = $lines[$i]
218218
if ($line.Length -gt ($sourceStart + 5)) {
219219
$software = [Software]::new()
220220
$software.Name = $line.Substring(0, $idStart).TrimEnd()
221221
$software.Id = $line.Substring($idStart, $versionStart - $idStart).TrimEnd()
222222
#add formated soft to list
223-
$upgradeList += $software
223+
$searchList += $software
224224
}
225225
}
226-
return $upgradeList
226+
return $searchList
227227
}
228228

229229
function Get-WingetInstalledApps {
@@ -232,8 +232,8 @@ function Get-WingetInstalledApps {
232232
[string]$Id
233233
}
234234

235-
#Get list of available upgrades on winget format
236-
$AppResult = & $Winget list $SearchApp --accept-source-agreements --source winget
235+
#Get list of installed apps on winget format
236+
$AppResult = & $Winget list --accept-source-agreements --source winget
237237

238238
#Start Convertion of winget format to an array. Check if "-----" exists
239239
if (!($AppResult -match "-----")) {
@@ -260,18 +260,33 @@ function Get-WingetInstalledApps {
260260
$versionStart = $lines[$fl].IndexOf($index[2])
261261

262262
# Now cycle in real package and split accordingly
263-
$upgradeList = @()
263+
$installedList = @()
264264
For ($i = $fl + 2; $i -le $lines.Length; $i++) {
265265
$line = $lines[$i]
266266
if ($line.Length -gt ($sourceStart + 5)) {
267267
$software = [Software]::new()
268268
$software.Name = $line.Substring(0, $idStart).TrimEnd()
269269
$software.Id = $line.Substring($idStart, $versionStart - $idStart).TrimEnd()
270270
#add formated soft to list
271-
$upgradeList += $software
271+
$installedList += $software
272272
}
273273
}
274-
return $upgradeList
274+
return $installedList
275+
}
276+
277+
function Get-WingetInstalledAppsV2 {
278+
279+
#Json File where to export install apps
280+
$jsonFile = "$Location\Installed_Apps.json"
281+
282+
#Get list of installed Winget apps to json file
283+
& $Winget export -o $jsonFile --accept-source-agreements | Out-Null
284+
285+
#Convert from json file
286+
$InstalledApps = get-content $jsonFile | ConvertFrom-Json
287+
288+
#Return app list
289+
return $InstalledApps.Sources.Packages.PackageIdentifier
275290
}
276291

277292
function Start-InstallGUI {
@@ -866,9 +881,9 @@ function Start-InstallGUI {
866881
$InstalledAppButton.add_click({
867882
Start-PopUp "Getting installed apps..."
868883
$AppListBox.Items.Clear()
869-
$List = Get-WingetInstalledApps
884+
$List = Get-WingetInstalledAppsV2
870885
foreach ($L in $List) {
871-
$AppListBox.Items.Add($L.ID)
886+
$AppListBox.Items.Add($L)
872887
}
873888
Close-PopUp
874889
})

0 commit comments

Comments
 (0)