From 84df1d74cb186cac626a71f46d556d2bad1bd06d Mon Sep 17 00:00:00 2001 From: tech189 Date: Mon, 25 Apr 2022 01:24:03 +0100 Subject: [PATCH 01/15] feat(scoop-info): Show app installed/download size --- libexec/scoop-info.ps1 | 71 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/libexec/scoop-info.ps1 b/libexec/scoop-info.ps1 index e192409626..db208e57bf 100644 --- a/libexec/scoop-info.ps1 +++ b/libexec/scoop-info.ps1 @@ -115,6 +115,77 @@ if ($status.installed) { $installed_output += if ($verbose) { versiondir $app $_ $global } else { "$_$(if ($global) { " *global*" })" } } $item.Installed = $installed_output -join "`n" + + # Show size of installation + $appsdir = appsdir $global + + $appFiles = Get-ChildItem $appsdir | Where-Object -Property Name -Value "^$app$" -Match + $persistFiles = Get-ChildItem $persist_dir -ErrorAction Ignore # Will fail if app does not persist data + $cacheFiles = Get-ChildItem $cachedir | Where-Object -Property Name -Value "^$app#" -Match + + $totalSize = 0 + $fileTotals = @() + foreach ($fileType in ($appFiles, $persistFiles, $cacheFiles)) { + if ($fileType.Length -ne 0) { + $fileSum = (Get-ChildItem $fileType -Recurse | Measure-Object -Property Length -Sum).Sum + $fileTotals += $fileSum + $totalSize += $fileSum + } + else { + $fileTotals += 0 + } + + } + $item.'Installed size' = "App: $(filesize $fileTotals[0])`nPersist: $(filesize $fileTotals[1])`nCache: $(filesize $fileTotals[2])`nTotal: $(filesize $totalSize)" +} +else { + # Get download size if app not installed + $architecture = default_architecture + + if(!(supports_architecture $manifest $architecture)) { + # No available download for current architecture + continue + } + + if ($null -eq $manifest.url) { + # use url for current architecture + $urls = url $manifest $architecture + } + else { + # otherwise use non-architecture url + $urls = $manifest.url + } + + $totalPackage = 0 + foreach($url in $urls) { + try { + [int]$urlLength = (Invoke-WebRequest $url -Method Head).Headers.'Content-Length'[0] + $totalPackage += $urlLength + + if (Test-Path (fullpath (cache_path $app $manifest.version $url))) { + $cached = " (latest version is cached)" + } + else { + $cached = $null + } + } + catch [System.Management.Automation.RuntimeException] { + $totalPackage = 0 + $packageError = "the server at $(([System.Uri]$url).Host) did not send a Content-Length header" + break + } + catch { + $totalPackage = 0 + $packageError = "the server at $(([System.Uri]$url).Host) is down" + break + } + } + if ($totalPackage -ne 0) { + $item.'Download size' = "$(filesize $totalPackage)$cached" + } + else { + $item.'Download size' = "Unknown ($packageError)" + } } $binaries = @(arch_specific 'bin' $manifest $install.architecture) From 2f411afe5442d115ae72287b1a15d6eac2f12aa8 Mon Sep 17 00:00:00 2001 From: tech189 Date: Mon, 25 Apr 2022 11:08:44 +0100 Subject: [PATCH 02/15] scoop-info: Improve spacing for readability --- libexec/scoop-info.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/scoop-info.ps1 b/libexec/scoop-info.ps1 index db208e57bf..d44b18606b 100644 --- a/libexec/scoop-info.ps1 +++ b/libexec/scoop-info.ps1 @@ -134,8 +134,8 @@ if ($status.installed) { else { $fileTotals += 0 } - } + $item.'Installed size' = "App: $(filesize $fileTotals[0])`nPersist: $(filesize $fileTotals[1])`nCache: $(filesize $fileTotals[2])`nTotal: $(filesize $totalSize)" } else { From c4d19cad9831b1a797d091da08323b1eb133b06b Mon Sep 17 00:00:00 2001 From: tech189 Date: Mon, 25 Apr 2022 11:21:22 +0100 Subject: [PATCH 03/15] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d1109de4c..b644d359db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - **update:** Skip logs starting with `(chore)` ([#4800](https://github.com/ScoopInstaller/Scoop/issues/4800)) - **scoop-download:** Add failure check ([#4822](https://github.com/ScoopInstaller/Scoop/pull/4822)) - **install:** Fix issue with installation inside containers ([#4837](https://github.com/ScoopInstaller/Scoop/pull/4837)) +- **scoop-info:** Display a breakdown of an app's installation size, or the download size if not installed (`--verbose` only) ([#4840](https://github.com/ScoopInstaller/Scoop/issues/4840)) ### Performance Improvements From 2fa8b17d5d669d945b3417e1fe9aa93480f0d4ab Mon Sep 17 00:00:00 2001 From: tech189 Date: Wed, 27 Apr 2022 10:31:09 +0100 Subject: [PATCH 04/15] scoop-info: Only get installed/dl size if verbose --- libexec/scoop-info.ps1 | 118 +++++++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 57 deletions(-) diff --git a/libexec/scoop-info.ps1 b/libexec/scoop-info.ps1 index d44b18606b..4e33b7ae94 100644 --- a/libexec/scoop-info.ps1 +++ b/libexec/scoop-info.ps1 @@ -116,76 +116,80 @@ if ($status.installed) { } $item.Installed = $installed_output -join "`n" - # Show size of installation - $appsdir = appsdir $global - - $appFiles = Get-ChildItem $appsdir | Where-Object -Property Name -Value "^$app$" -Match - $persistFiles = Get-ChildItem $persist_dir -ErrorAction Ignore # Will fail if app does not persist data - $cacheFiles = Get-ChildItem $cachedir | Where-Object -Property Name -Value "^$app#" -Match - - $totalSize = 0 - $fileTotals = @() - foreach ($fileType in ($appFiles, $persistFiles, $cacheFiles)) { - if ($fileType.Length -ne 0) { - $fileSum = (Get-ChildItem $fileType -Recurse | Measure-Object -Property Length -Sum).Sum - $fileTotals += $fileSum - $totalSize += $fileSum - } - else { - $fileTotals += 0 + if ($verbose) { + # Show size of installation + $appsdir = appsdir $global + + $appFiles = Get-ChildItem $appsdir | Where-Object -Property Name -Value "^$app$" -Match + $persistFiles = Get-ChildItem $persist_dir -ErrorAction Ignore # Will fail if app does not persist data + $cacheFiles = Get-ChildItem $cachedir | Where-Object -Property Name -Value "^$app#" -Match + + $totalSize = 0 + $fileTotals = @() + foreach ($fileType in ($appFiles, $persistFiles, $cacheFiles)) { + if ($fileType.Length -ne 0) { + $fileSum = (Get-ChildItem $fileType -Recurse | Measure-Object -Property Length -Sum).Sum + $fileTotals += $fileSum + $totalSize += $fileSum + } + else { + $fileTotals += 0 + } } - } - $item.'Installed size' = "App: $(filesize $fileTotals[0])`nPersist: $(filesize $fileTotals[1])`nCache: $(filesize $fileTotals[2])`nTotal: $(filesize $totalSize)" + $item.'Installed size' = "App: $(filesize $fileTotals[0])`nPersist: $(filesize $fileTotals[1])`nCache: $(filesize $fileTotals[2])`nTotal: $(filesize $totalSize)" + } } else { - # Get download size if app not installed - $architecture = default_architecture + if ($verbose) { + # Get download size if app not installed + $architecture = default_architecture - if(!(supports_architecture $manifest $architecture)) { - # No available download for current architecture - continue - } - - if ($null -eq $manifest.url) { - # use url for current architecture - $urls = url $manifest $architecture - } - else { - # otherwise use non-architecture url - $urls = $manifest.url - } + if(!(supports_architecture $manifest $architecture)) { + # No available download for current architecture + continue + } - $totalPackage = 0 - foreach($url in $urls) { - try { - [int]$urlLength = (Invoke-WebRequest $url -Method Head).Headers.'Content-Length'[0] - $totalPackage += $urlLength + if ($null -eq $manifest.url) { + # use url for current architecture + $urls = url $manifest $architecture + } + else { + # otherwise use non-architecture url + $urls = $manifest.url + } - if (Test-Path (fullpath (cache_path $app $manifest.version $url))) { - $cached = " (latest version is cached)" + $totalPackage = 0 + foreach($url in $urls) { + try { + [int]$urlLength = (Invoke-WebRequest $url -Method Head).Headers.'Content-Length'[0] + $totalPackage += $urlLength + + if (Test-Path (fullpath (cache_path $app $manifest.version $url))) { + $cached = " (latest version is cached)" + } + else { + $cached = $null + } } - else { - $cached = $null + catch [System.Management.Automation.RuntimeException] { + $totalPackage = 0 + $packageError = "the server at $(([System.Uri]$url).Host) did not send a Content-Length header" + break + } + catch { + $totalPackage = 0 + $packageError = "the server at $(([System.Uri]$url).Host) is down" + break } } - catch [System.Management.Automation.RuntimeException] { - $totalPackage = 0 - $packageError = "the server at $(([System.Uri]$url).Host) did not send a Content-Length header" - break + if ($totalPackage -ne 0) { + $item.'Download size' = "$(filesize $totalPackage)$cached" } - catch { - $totalPackage = 0 - $packageError = "the server at $(([System.Uri]$url).Host) is down" - break + else { + $item.'Download size' = "Unknown ($packageError)" } } - if ($totalPackage -ne 0) { - $item.'Download size' = "$(filesize $totalPackage)$cached" - } - else { - $item.'Download size' = "Unknown ($packageError)" - } } $binaries = @(arch_specific 'bin' $manifest $install.architecture) From eb78a64a278a4ba9173fe8ea89f7626ed09c47af Mon Sep 17 00:00:00 2001 From: tech189 Date: Mon, 2 May 2022 10:31:27 +0100 Subject: [PATCH 05/15] Apply formatting suggestions from code review Co-authored-by: Rashil Gandhi <46838874+rashil2000@users.noreply.github.com> --- libexec/scoop-info.ps1 | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/libexec/scoop-info.ps1 b/libexec/scoop-info.ps1 index 4e33b7ae94..95efbe995f 100644 --- a/libexec/scoop-info.ps1 +++ b/libexec/scoop-info.ps1 @@ -131,16 +131,14 @@ if ($status.installed) { $fileSum = (Get-ChildItem $fileType -Recurse | Measure-Object -Property Length -Sum).Sum $fileTotals += $fileSum $totalSize += $fileSum - } - else { + } else { $fileTotals += 0 } } $item.'Installed size' = "App: $(filesize $fileTotals[0])`nPersist: $(filesize $fileTotals[1])`nCache: $(filesize $fileTotals[2])`nTotal: $(filesize $totalSize)" } -} -else { +} else { if ($verbose) { # Get download size if app not installed $architecture = default_architecture @@ -153,8 +151,7 @@ else { if ($null -eq $manifest.url) { # use url for current architecture $urls = url $manifest $architecture - } - else { + } else { # otherwise use non-architecture url $urls = $manifest.url } @@ -167,17 +164,14 @@ else { if (Test-Path (fullpath (cache_path $app $manifest.version $url))) { $cached = " (latest version is cached)" - } - else { + } else { $cached = $null } - } - catch [System.Management.Automation.RuntimeException] { + } catch [System.Management.Automation.RuntimeException] { $totalPackage = 0 $packageError = "the server at $(([System.Uri]$url).Host) did not send a Content-Length header" break - } - catch { + } catch { $totalPackage = 0 $packageError = "the server at $(([System.Uri]$url).Host) is down" break @@ -185,8 +179,7 @@ else { } if ($totalPackage -ne 0) { $item.'Download size' = "$(filesize $totalPackage)$cached" - } - else { + } else { $item.'Download size' = "Unknown ($packageError)" } } From 8524a41338339f31499dd81d4102346dea7a0186 Mon Sep 17 00:00:00 2001 From: tech189 Date: Wed, 4 May 2022 00:32:08 +0100 Subject: [PATCH 06/15] Separate app size into current & old versions --- libexec/scoop-info.ps1 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libexec/scoop-info.ps1 b/libexec/scoop-info.ps1 index 95efbe995f..0ef879d77c 100644 --- a/libexec/scoop-info.ps1 +++ b/libexec/scoop-info.ps1 @@ -121,6 +121,7 @@ if ($status.installed) { $appsdir = appsdir $global $appFiles = Get-ChildItem $appsdir | Where-Object -Property Name -Value "^$app$" -Match + $currentFiles = Get-ChildItem $appFiles | Where-Object -Property Name -Value (Select-CurrentVersion $app $global) -Match $persistFiles = Get-ChildItem $persist_dir -ErrorAction Ignore # Will fail if app does not persist data $cacheFiles = Get-ChildItem $cachedir | Where-Object -Property Name -Value "^$app#" -Match @@ -136,7 +137,13 @@ if ($status.installed) { } } - $item.'Installed size' = "App: $(filesize $fileTotals[0])`nPersist: $(filesize $fileTotals[1])`nCache: $(filesize $fileTotals[2])`nTotal: $(filesize $totalSize)" + # Separate so that it doesn't double count in $totalSize + $currentTotal = (Get-ChildItem $currentFiles -Recurse | Measure-Object -Property Length -Sum).Sum + + # Old versions = app total - current version size + $fileTotals += $fileTotals[0] - $currentTotal + + $item.'Installed size' = "Current version: $(filesize $currentTotal)`nOld versions: $(filesize $fileTotals[3])`nPersisted data: $(filesize $fileTotals[1])`nCached downloads: $(filesize $fileTotals[2])`nTotal: $(filesize $totalSize)" } } else { if ($verbose) { From 3e45eeddcafa20b31b24dd8d12d5b2433b98d492 Mon Sep 17 00:00:00 2001 From: tech189 Date: Wed, 4 May 2022 22:05:01 +0100 Subject: [PATCH 07/15] Add consistent spacing for readability --- libexec/scoop-info.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/scoop-info.ps1 b/libexec/scoop-info.ps1 index 0ef879d77c..f6d8c8d4d0 100644 --- a/libexec/scoop-info.ps1 +++ b/libexec/scoop-info.ps1 @@ -143,7 +143,7 @@ if ($status.installed) { # Old versions = app total - current version size $fileTotals += $fileTotals[0] - $currentTotal - $item.'Installed size' = "Current version: $(filesize $currentTotal)`nOld versions: $(filesize $fileTotals[3])`nPersisted data: $(filesize $fileTotals[1])`nCached downloads: $(filesize $fileTotals[2])`nTotal: $(filesize $totalSize)" + $item.'Installed size' = "Current version: $(filesize $currentTotal)`nOld versions: $(filesize $fileTotals[3])`nPersisted data: $(filesize $fileTotals[1])`nCached downloads: $(filesize $fileTotals[2])`nTotal: $(filesize $totalSize)" } } else { if ($verbose) { From 041659a7d6a21ba58c422d16e563e791cd333c5c Mon Sep 17 00:00:00 2001 From: tech189 Date: Wed, 4 May 2022 22:12:37 +0100 Subject: [PATCH 08/15] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c0fb3891f..8fc50c6156 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Features - **install:** Allow downloading from private repositories ([#4254](https://github.com/ScoopInstaller/Scoop/issues/4254)) +- **scoop-info:** Display a breakdown of an app's installation size, or download size if not installed (`--verbose` only) ([#4840](https://github.com/ScoopInstaller/Scoop/issues/4840)) ### Bug Fixes From a3e88681ee334a71bddfca003e69f6d715676641 Mon Sep 17 00:00:00 2001 From: tech189 Date: Thu, 5 May 2022 23:19:09 +0100 Subject: [PATCH 09/15] Split installed size output into multiple lines --- libexec/scoop-info.ps1 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libexec/scoop-info.ps1 b/libexec/scoop-info.ps1 index f6d8c8d4d0..33a3795b87 100644 --- a/libexec/scoop-info.ps1 +++ b/libexec/scoop-info.ps1 @@ -143,7 +143,13 @@ if ($status.installed) { # Old versions = app total - current version size $fileTotals += $fileTotals[0] - $currentTotal - $item.'Installed size' = "Current version: $(filesize $currentTotal)`nOld versions: $(filesize $fileTotals[3])`nPersisted data: $(filesize $fileTotals[1])`nCached downloads: $(filesize $fileTotals[2])`nTotal: $(filesize $totalSize)" + $item.'Installed size' = ( + "Current version: $(filesize $currentTotal)`n" + + "Old versions: $(filesize $fileTotals[3])`n" + + "Persisted data: $(filesize $fileTotals[1])`n" + + "Cached downloads: $(filesize $fileTotals[2])`n" + + "Total: $(filesize $totalSize)" + ) } } else { if ($verbose) { From a4bda12dedf4ed4c02620f41ddde5dede774ac21 Mon Sep 17 00:00:00 2001 From: tech189 Date: Fri, 6 May 2022 23:32:35 +0100 Subject: [PATCH 10/15] Keep output as short as possible, improve comments --- libexec/scoop-info.ps1 | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/libexec/scoop-info.ps1 b/libexec/scoop-info.ps1 index 33a3795b87..ee7c41e57d 100644 --- a/libexec/scoop-info.ps1 +++ b/libexec/scoop-info.ps1 @@ -120,11 +120,13 @@ if ($status.installed) { # Show size of installation $appsdir = appsdir $global + # Collect file list from each location $appFiles = Get-ChildItem $appsdir | Where-Object -Property Name -Value "^$app$" -Match $currentFiles = Get-ChildItem $appFiles | Where-Object -Property Name -Value (Select-CurrentVersion $app $global) -Match $persistFiles = Get-ChildItem $persist_dir -ErrorAction Ignore # Will fail if app does not persist data $cacheFiles = Get-ChildItem $cachedir | Where-Object -Property Name -Value "^$app#" -Match + # Get the sum of each file list and keep a total $totalSize = 0 $fileTotals = @() foreach ($fileType in ($appFiles, $persistFiles, $cacheFiles)) { @@ -137,19 +139,35 @@ if ($status.installed) { } } - # Separate so that it doesn't double count in $totalSize + # This is separate so that current version size doesn't double count in $totalSize $currentTotal = (Get-ChildItem $currentFiles -Recurse | Measure-Object -Property Length -Sum).Sum # Old versions = app total - current version size $fileTotals += $fileTotals[0] - $currentTotal - $item.'Installed size' = ( - "Current version: $(filesize $currentTotal)`n" + - "Old versions: $(filesize $fileTotals[3])`n" + - "Persisted data: $(filesize $fileTotals[1])`n" + - "Cached downloads: $(filesize $fileTotals[2])`n" + - "Total: $(filesize $totalSize)" - ) + if ($currentTotal -eq $totalSize) { + # Simple app size output if no old versions, persisted data, cached downloads + $item.'Installed size' = filesize $currentTotal + } else { + $fileSizes = [ordered] @{ + "Current version: " = $(filesize $currentTotal) + "Old versions: " = $(filesize $fileTotals[3]) + "Persisted data: " = $(filesize $fileTotals[1]) + "Cached downloads: " = $(filesize $fileTotals[2]) + "Total: " = $(filesize $totalSize) + } + + $fileSizeOutput = @() + + # Don't output empty categories + $fileSizes.GetEnumerator() | ForEach-Object { + if ($_.value -ne "0 B") { + $fileSizeOutput += $_.key + $_.value + } + } + + $item.'Installed size' = $fileSizeOutput -join "`n" + } } } else { if ($verbose) { From 2128d37dc6c8f45c2d4b87bf0c20f2805a3916f9 Mon Sep 17 00:00:00 2001 From: Hsiao-nan Cheung Date: Thu, 16 Jun 2022 23:44:36 +0800 Subject: [PATCH 11/15] Update CHANGELOG [skip ci] --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51c922e8a1..a2ccf8e387 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Features - **core:** Add `Get-Encoding` function to fix missing webclient encoding ([#4956](https://github.com/ScoopInstaller/Scoop/issues/4956)) +- **scoop-info:** Display a breakdown of an app's installation size, or download size if not installed (`--verbose` only) ([#4840](https://github.com/ScoopInstaller/Scoop/issues/4840)) - **scoop-virustotal:** Migrate to virustotal api v3, improve flows, and ouput powershell objects ([#4983](https://github.com/ScoopInstaller/Scoop/pull/4983)) ### Bug Fixes @@ -48,7 +49,6 @@ - **relicense:** Relicense to dual-license (Unlicense or MIT) ([#4903](https://github.com/ScoopInstaller/Scoop/issues/4903), [#4870](https://github.com/ScoopInstaller/Scoop/issues/4870)) - **install:** Allow downloading from private repositories ([#4254](https://github.com/ScoopInstaller/Scoop/issues/4254)) -- **scoop-info:** Display a breakdown of an app's installation size, or download size if not installed (`--verbose` only) ([#4840](https://github.com/ScoopInstaller/Scoop/issues/4840)) - **scoop-cleanup:** Add `-a/--all` switch to cleanup all apps ([#4906](https://github.com/ScoopInstaller/Scoop/issues/4906)) ### Bug Fixes From 1b714af49591d4796f1b1a4043add5a1cd4a6818 Mon Sep 17 00:00:00 2001 From: tech189 Date: Tue, 21 Jun 2022 14:32:31 +0100 Subject: [PATCH 12/15] Apply suggestions from code review Simplify `| Where-Object ...` to `-Filter` Replace `totalSize` counter with `coalesce` function from `lib\core.ps1` Move `currentFiles` counter into main `foreach` loop Simplify categorised output by applying `filesize` afterwards Simplify architecture check for download size with `url` function from `lib\manifest.ps1` Co-authored-by: Hsiao-nan Cheung --- libexec/scoop-info.ps1 | 56 ++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 38 deletions(-) diff --git a/libexec/scoop-info.ps1 b/libexec/scoop-info.ps1 index de27ad3446..6f3a629955 100644 --- a/libexec/scoop-info.ps1 +++ b/libexec/scoop-info.ps1 @@ -111,48 +111,43 @@ if ($status.installed) { $appsdir = appsdir $global # Collect file list from each location - $appFiles = Get-ChildItem $appsdir | Where-Object -Property Name -Value "^$app$" -Match - $currentFiles = Get-ChildItem $appFiles | Where-Object -Property Name -Value (Select-CurrentVersion $app $global) -Match + $appFiles = Get-ChildItem $appsdir -Filter $app + $currentFiles = Get-ChildItem $appFiles -Filter (Select-CurrentVersion $app $global) $persistFiles = Get-ChildItem $persist_dir -ErrorAction Ignore # Will fail if app does not persist data - $cacheFiles = Get-ChildItem $cachedir | Where-Object -Property Name -Value "^$app#" -Match + $cacheFiles = Get-ChildItem $cachedir -Filter "$app#*" - # Get the sum of each file list and keep a total - $totalSize = 0 + # Get the sum of each file list $fileTotals = @() - foreach ($fileType in ($appFiles, $persistFiles, $cacheFiles)) { - if ($fileType.Length -ne 0) { + foreach ($fileType in ($appFiles, $currentFiles, $persistFiles, $cacheFiles)) { + if ($null -ne $fileType) { $fileSum = (Get-ChildItem $fileType -Recurse | Measure-Object -Property Length -Sum).Sum - $fileTotals += $fileSum - $totalSize += $fileSum + $fileTotals += coalesce $fileSum 0 } else { $fileTotals += 0 } } - # This is separate so that current version size doesn't double count in $totalSize - $currentTotal = (Get-ChildItem $currentFiles -Recurse | Measure-Object -Property Length -Sum).Sum - # Old versions = app total - current version size - $fileTotals += $fileTotals[0] - $currentTotal + $fileTotals += $fileTotals[0] - $fileTotals[1] - if ($currentTotal -eq $totalSize) { + if ($fileTotals[2] + $fileTotals[3] + $fileTotals[4] -eq 0) { # Simple app size output if no old versions, persisted data, cached downloads - $item.'Installed size' = filesize $currentTotal + $item.'Installed size' = filesize $fileTotals[1] } else { $fileSizes = [ordered] @{ - "Current version: " = $(filesize $currentTotal) - "Old versions: " = $(filesize $fileTotals[3]) - "Persisted data: " = $(filesize $fileTotals[1]) - "Cached downloads: " = $(filesize $fileTotals[2]) - "Total: " = $(filesize $totalSize) + 'Current version: ' = $fileTotals[1] + 'Old versions: ' = $fileTotals[4] + 'Persisted data: ' = $fileTotals[2] + 'Cached downloads: ' = $fileTotals[3] + 'Total: ' = $fileTotals[0] + $fileTotals[2] + $fileTotals[3] } $fileSizeOutput = @() # Don't output empty categories $fileSizes.GetEnumerator() | ForEach-Object { - if ($_.value -ne "0 B") { - $fileSizeOutput += $_.key + $_.value + if ($_.Value -ne 0) { + $fileSizeOutput += $_.Key + (filesize $_.Value) } } @@ -162,23 +157,8 @@ if ($status.installed) { } else { if ($verbose) { # Get download size if app not installed - $architecture = default_architecture - - if(!(supports_architecture $manifest $architecture)) { - # No available download for current architecture - continue - } - - if ($null -eq $manifest.url) { - # use url for current architecture - $urls = url $manifest $architecture - } else { - # otherwise use non-architecture url - $urls = $manifest.url - } - $totalPackage = 0 - foreach($url in $urls) { + foreach ($url in @(url $manifest (default_architecture))) { try { [int]$urlLength = (Invoke-WebRequest $url -Method Head).Headers.'Content-Length'[0] $totalPackage += $urlLength From 7c81621ac8c65fc3ffc7a8a8b146f1d18dab5e63 Mon Sep 17 00:00:00 2001 From: tech189 Date: Tue, 21 Jun 2022 14:45:03 +0100 Subject: [PATCH 13/15] Show if download is cached even when internet is down --- libexec/scoop-info.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libexec/scoop-info.ps1 b/libexec/scoop-info.ps1 index 6f3a629955..74f7aa931a 100644 --- a/libexec/scoop-info.ps1 +++ b/libexec/scoop-info.ps1 @@ -160,14 +160,14 @@ if ($status.installed) { $totalPackage = 0 foreach ($url in @(url $manifest (default_architecture))) { try { - [int]$urlLength = (Invoke-WebRequest $url -Method Head).Headers.'Content-Length'[0] - $totalPackage += $urlLength - if (Test-Path (fullpath (cache_path $app $manifest.version $url))) { $cached = " (latest version is cached)" } else { $cached = $null } + + [int]$urlLength = (Invoke-WebRequest $url -Method Head).Headers.'Content-Length'[0] + $totalPackage += $urlLength } catch [System.Management.Automation.RuntimeException] { $totalPackage = 0 $packageError = "the server at $(([System.Uri]$url).Host) did not send a Content-Length header" @@ -181,7 +181,7 @@ if ($status.installed) { if ($totalPackage -ne 0) { $item.'Download size' = "$(filesize $totalPackage)$cached" } else { - $item.'Download size' = "Unknown ($packageError)" + $item.'Download size' = "Unknown ($packageError)$cached" } } } From b09b43f9db50e1a798b42cd8bc5050b74e9c7314 Mon Sep 17 00:00:00 2001 From: Hsiao-nan Cheung Date: Tue, 21 Jun 2022 23:19:41 +0800 Subject: [PATCH 14/15] Update changelog entry [skip ci] --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9390b06086..f50016d2a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ### Features -- **scoop-info:** Display a breakdown of an app's installation size, or download size if not installed (`--verbose` only) ([#4840](https://github.com/ScoopInstaller/Scoop/issues/4840)) +- **scoop-info:** Show app installed/download size ([#4840](https://github.com/ScoopInstaller/Scoop/issues/4840)) ### Bug Fixes From 6d26aec21b348ac879c2bd5c8607e6427d428bce Mon Sep 17 00:00:00 2001 From: Hsiao-nan Cheung Date: Tue, 21 Jun 2022 23:21:27 +0800 Subject: [PATCH 15/15] Update changelog entry, again [skip ci] --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f50016d2a1..51b296ecd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ### Features -- **scoop-info:** Show app installed/download size ([#4840](https://github.com/ScoopInstaller/Scoop/issues/4840)) +- **scoop-info:** Show app installed/download size ([#4886](https://github.com/ScoopInstaller/Scoop/issues/4886)) ### Bug Fixes