]> vilimpoc.org git repositories - dotfiles/blobdiff - setup-windows-current.ps1
dotfiles: register UI.Xaml 2.8 for the account before installing Terminal
[dotfiles] / setup-windows-current.ps1
index be07ef7c821a1ddf7eb6033f60225f5a85f40223..b14a791cf37acd3e3a81e035bd9cfb5108296924 100644 (file)
@@ -1,16 +1,19 @@
 <#
   setup-windows-current.ps1 - is this step's program already current?
 
 <#
   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
 
   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(
   "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
 )
     # As setup-windows.bat worked it out, from the registry: AMD64, ARM64 or x86.
     [string] $HostArch
 )
@@ -109,10 +112,33 @@ function Test-NasmCurrent {
     $true
 }
 
     $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) {
 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."
     }
 } catch {
     Say "${Step}: the version check failed ($($_.Exception.Message)); installing as usual."