@@ -105,6 +105,85 @@ if ($status.installed) {
105105 $installed_output += if ($verbose ) { versiondir $app $_ $global } else { " $_ $ ( if ($global ) { " *global*" }) " }
106106 }
107107 $item.Installed = $installed_output -join " `n "
108+
109+ if ($verbose ) {
110+ # Show size of installation
111+ $appsdir = appsdir $global
112+
113+ # Collect file list from each location
114+ $appFiles = Get-ChildItem $appsdir - Filter $app
115+ $currentFiles = Get-ChildItem $appFiles - Filter (Select-CurrentVersion $app $global )
116+ $persistFiles = Get-ChildItem $persist_dir - ErrorAction Ignore # Will fail if app does not persist data
117+ $cacheFiles = Get-ChildItem $cachedir - Filter " $app #*"
118+
119+ # Get the sum of each file list
120+ $fileTotals = @ ()
121+ foreach ($fileType in ($appFiles , $currentFiles , $persistFiles , $cacheFiles )) {
122+ if ($null -ne $fileType ) {
123+ $fileSum = (Get-ChildItem $fileType - Recurse | Measure-Object - Property Length - Sum).Sum
124+ $fileTotals += coalesce $fileSum 0
125+ } else {
126+ $fileTotals += 0
127+ }
128+ }
129+
130+ # Old versions = app total - current version size
131+ $fileTotals += $fileTotals [0 ] - $fileTotals [1 ]
132+
133+ if ($fileTotals [2 ] + $fileTotals [3 ] + $fileTotals [4 ] -eq 0 ) {
134+ # Simple app size output if no old versions, persisted data, cached downloads
135+ $item .' Installed size' = filesize $fileTotals [1 ]
136+ } else {
137+ $fileSizes = [ordered ] @ {
138+ ' Current version: ' = $fileTotals [1 ]
139+ ' Old versions: ' = $fileTotals [4 ]
140+ ' Persisted data: ' = $fileTotals [2 ]
141+ ' Cached downloads: ' = $fileTotals [3 ]
142+ ' Total: ' = $fileTotals [0 ] + $fileTotals [2 ] + $fileTotals [3 ]
143+ }
144+
145+ $fileSizeOutput = @ ()
146+
147+ # Don't output empty categories
148+ $fileSizes.GetEnumerator () | ForEach-Object {
149+ if ($_.Value -ne 0 ) {
150+ $fileSizeOutput += $_.Key + (filesize $_.Value )
151+ }
152+ }
153+
154+ $item .' Installed size' = $fileSizeOutput -join " `n "
155+ }
156+ }
157+ } else {
158+ if ($verbose ) {
159+ # Get download size if app not installed
160+ $totalPackage = 0
161+ foreach ($url in @ (url $manifest (default_architecture))) {
162+ try {
163+ if (Test-Path (fullpath (cache_path $app $manifest.version $url ))) {
164+ $cached = " (latest version is cached)"
165+ } else {
166+ $cached = $null
167+ }
168+
169+ [int ]$urlLength = (Invoke-WebRequest $url - Method Head).Headers.' Content-Length' [0 ]
170+ $totalPackage += $urlLength
171+ } catch [System.Management.Automation.RuntimeException ] {
172+ $totalPackage = 0
173+ $packageError = " the server at $ ( ([System.Uri ]$url ).Host) did not send a Content-Length header"
174+ break
175+ } catch {
176+ $totalPackage = 0
177+ $packageError = " the server at $ ( ([System.Uri ]$url ).Host) is down"
178+ break
179+ }
180+ }
181+ if ($totalPackage -ne 0 ) {
182+ $item .' Download size' = " $ ( filesize $totalPackage ) $cached "
183+ } else {
184+ $item .' Download size' = " Unknown ($packageError )$cached "
185+ }
186+ }
108187}
109188
110189$binaries = @ (arch_specific ' bin' $manifest $install.architecture )
0 commit comments