From c5907c3e252982c2fd4f061e87e4b38d251b108c Mon Sep 17 00:00:00 2001 From: HUMORCE Date: Thu, 19 Sep 2024 07:41:28 +0000 Subject: [PATCH] first step --- lib/core.ps1 | 14 +++++++++++++- lib/manifest.ps1 | 10 ++++++++++ libexec/scoop-cat.ps1 | 1 + libexec/scoop-download.ps1 | 1 + libexec/scoop-home.ps1 | 1 + libexec/scoop-info.ps1 | 4 ++-- libexec/scoop-virustotal.ps1 | 1 + 7 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/core.ps1 b/lib/core.ps1 index eeaa2c9ad..76c7c2d91 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -1140,7 +1140,19 @@ function applist($apps, $global) { function parse_app([string]$app) { if ($app -match '^(?:(?[a-zA-Z0-9-_.]+)/)?(?.*\.json|[a-zA-Z0-9-_.]+)(?:@(?.*))?$') { - return $Matches['app'], $Matches['bucket'], $Matches['version'] + $app = $Matches['app'] + $bucket = $Matches['bucket'] + $version = $Matches['version'] + if (installed $app) { + $global = installed $app $true + $ver = Select-CurrentVersion -AppName $app -Global:$global + $install_info_path = "$(versiondir $app $ver $global)\install.json" + if (Test-Path $install_info_path) { + $install_info = parse_json $install_info_path + $bucket = $install_info.bucket + } + } + return $app, $bucket, $version } else { return $app, $null, $null } diff --git a/lib/manifest.ps1 b/lib/manifest.ps1 index 9ca618158..c5122681d 100644 --- a/lib/manifest.ps1 +++ b/lib/manifest.ps1 @@ -53,6 +53,16 @@ function Get-Manifest($app) { } } if (!$manifest) { + if (installed $app) { + $global = installed $app $true + $ver = Select-CurrentVersion -AppName $app -Global:$global + $install_info_path = "$(versiondir $app $ver $global)\install.json" + if (Test-Path $install_info_path) { + $install_info = parse_json $install_info_path + $url = $install_info.url + } + $manifest = if (Test-Path $url) { parse_json $url } else { installed_manifest $app $ver $global } + } # couldn't find app in buckets: check if it's a local path if (Test-Path $app) { $url = Convert-Path $app diff --git a/libexec/scoop-cat.ps1 b/libexec/scoop-cat.ps1 index 5cf363162..70863e202 100644 --- a/libexec/scoop-cat.ps1 +++ b/libexec/scoop-cat.ps1 @@ -7,6 +7,7 @@ param($app) . "$PSScriptRoot\..\lib\json.ps1" # 'ConvertToPrettyJson' +. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion' . "$PSScriptRoot\..\lib\manifest.ps1" # 'Get-Manifest' if (!$app) { error ' missing'; my_usage; exit 1 } diff --git a/libexec/scoop-download.ps1 b/libexec/scoop-download.ps1 index f47a672e5..996cb4e8e 100644 --- a/libexec/scoop-download.ps1 +++ b/libexec/scoop-download.ps1 @@ -22,6 +22,7 @@ . "$PSScriptRoot\..\lib\getopt.ps1" . "$PSScriptRoot\..\lib\json.ps1" # 'autoupdate.ps1' (indirectly) . "$PSScriptRoot\..\lib\autoupdate.ps1" # 'generate_user_manifest' (indirectly) +. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion' . "$PSScriptRoot\..\lib\manifest.ps1" # 'generate_user_manifest' 'Get-Manifest' . "$PSScriptRoot\..\lib\download.ps1" if (get_config USE_SQLITE_CACHE) { diff --git a/libexec/scoop-home.ps1 b/libexec/scoop-home.ps1 index da495454a..f76a5e06b 100644 --- a/libexec/scoop-home.ps1 +++ b/libexec/scoop-home.ps1 @@ -2,6 +2,7 @@ # Summary: Opens the app homepage param($app) +. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion' . "$PSScriptRoot\..\lib\manifest.ps1" # 'Get-Manifest' if ($app) { diff --git a/libexec/scoop-info.ps1 b/libexec/scoop-info.ps1 index 7b2354455..45e782fb2 100644 --- a/libexec/scoop-info.ps1 +++ b/libexec/scoop-info.ps1 @@ -5,7 +5,7 @@ . "$PSScriptRoot\..\lib\getopt.ps1" . "$PSScriptRoot\..\lib\manifest.ps1" # 'Get-Manifest' -. "$PSScriptRoot\..\lib\versions.ps1" # 'Get-InstalledVersion' +. "$PSScriptRoot\..\lib\versions.ps1" # 'Get-InstalledVersion', 'Select-CurrentVersion' . "$PSScriptRoot\..\lib\download.ps1" # 'Get-RemoteFileSize' $opt, $app, $err = getopt $args 'v' 'verbose' @@ -23,7 +23,7 @@ if (!$manifest) { $global = installed $app $true $status = app_status $app $global $install = install_info $app $status.version $global -$status.installed = $bucket -and $install.bucket -eq $bucket +$status.installed = installed $app $version_output = $manifest.version $manifest_file = if ($bucket) { manifest_path $app $bucket diff --git a/libexec/scoop-virustotal.ps1 b/libexec/scoop-virustotal.ps1 index 72f1d2f14..8fe63359c 100644 --- a/libexec/scoop-virustotal.ps1 +++ b/libexec/scoop-virustotal.ps1 @@ -29,6 +29,7 @@ # -p, --passthru Return reports as objects . "$PSScriptRoot\..\lib\getopt.ps1" +. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion' . "$PSScriptRoot\..\lib\manifest.ps1" # 'Get-Manifest' . "$PSScriptRoot\..\lib\json.ps1" # 'json_path' . "$PSScriptRoot\..\lib\download.ps1" # 'hash_for_url'