X-Git-Url: https://vilimpoc.org/repos/dotfiles/blobdiff_plain/0b4125206461c1a63a971ac9cf503319bcb05798..refs/heads/master:/setup-windows-current.ps1?ds=sidebyside diff --git a/setup-windows-current.ps1 b/setup-windows-current.ps1 index be07ef7..b14a791 100644 --- a/setup-windows-current.ps1 +++ b/setup-windows-current.ps1 @@ -1,16 +1,19 @@ <# setup-windows-current.ps1 - is this step's program already current? - setup-windows.bat asks this before the two installs that would otherwise run - in full on every re-run, because neither the installer nor winget can tell - that what is on the box is already the latest: + setup-windows.bat asks this before the installs that would otherwise run in + full on every re-run, because neither the installer nor winget can tell that + what is on the box is already the latest: - ClaudeCode Anthropic's installer script always downloads the release - (a couple of hundred MB) and reinstalls it; it has no "already - current" check of its own. - NASM its installer falls back to a per-user directory when it cannot - write to Program Files, and registers nothing there - so winget - cannot see it, and reruns the installer every time. + ClaudeCode Anthropic's installer script always downloads the release + (a couple of hundred MB) and reinstalls it; it has no + "already current" check of its own. + NASM its installer falls back to a per-user directory when it + cannot write to Program Files, and registers nothing there - + so winget cannot see it, and reruns the installer every time. + AndroidStudio an install that did not come from winget is one winget + cannot match to its package, so it would install over it. + And Android Studio updates itself; winget never upgrades it. Exit code 0 means already current: skip the install. Anything else means go ahead as before - and that includes this script failing (no network, a version @@ -22,7 +25,7 @@ "Re-running" note lists how each one decides. #> param( - [Parameter(Mandatory)] [ValidateSet('ClaudeCode', 'NASM')] [string] $Step, + [Parameter(Mandatory)] [ValidateSet('ClaudeCode', 'NASM', 'AndroidStudio')] [string] $Step, # As setup-windows.bat worked it out, from the registry: AMD64, ARM64 or x86. [string] $HostArch ) @@ -109,10 +112,33 @@ function Test-NasmCurrent { $true } +function Test-AndroidStudioCurrent { + # Installed at all counts as current, because Android Studio keeps itself + # current: it updates in the app (Help > Check for Updates), and the winget + # package is published with UpgradeBehavior: deny and RequireExplicitUpgrade, + # so winget would not upgrade it anyway. The check matters for an install + # that did not come from winget - measured on the x64 laptop, where winget + # lists Studio only as "ARP\Machine\X64\Android Studio", unmatched to + # Google.AndroidStudio - since `winget install` would then run the installer + # over it. Looked for both ways: the Add/Remove Programs entry its installer + # writes, and studio64.exe where that installer puts it. + $arp = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*', + 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*', + 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' -ErrorAction SilentlyContinue | + Where-Object { $_.DisplayName -eq 'Android Studio' } + $exe = @((Join-Path $env:ProgramFiles 'Android\Android Studio\bin\studio64.exe'), + (Join-Path $env:LOCALAPPDATA 'Programs\Android Studio\bin\studio64.exe')) | Where-Object { Test-Path $_ } + if (-not $arp -and -not $exe) { Say 'AndroidStudio: not installed yet.'; return $false } + $ver = @($arp)[0].DisplayVersion + Say "AndroidStudio: $(if ($ver) { $ver } else { 'an existing install' }) is already here, and it updates itself (Help > Check for Updates); not reinstalling." + $true +} + try { $current = switch ($Step) { - 'ClaudeCode' { Test-ClaudeCodeCurrent } - 'NASM' { Test-NasmCurrent } + 'ClaudeCode' { Test-ClaudeCodeCurrent } + 'NASM' { Test-NasmCurrent } + 'AndroidStudio' { Test-AndroidStudioCurrent } } } catch { Say "${Step}: the version check failed ($($_.Exception.Message)); installing as usual."