@@ -120,28 +120,42 @@ function Install-Dep {
120120 $action = if ($ForceUpgrade ) { " upgrade" } else { " install" }
121121 Write-Step " $ ( if ($ForceUpgrade ) { ' Updating' } else { ' Installing' } ) $Name via winget..."
122122 $result = winget $action -- id $WingetId -- accept- package- agreements -- accept- source- agreements -- disable-interactivity -- silent 2>&1
123- if ($LASTEXITCODE -eq 0 -or " $result " -match " already installed" -or " $result " -match " No available upgrade" ) {
123+ $resultStr = " $result "
124+ $wingetOk = ($LASTEXITCODE -eq 0 ) -or ($resultStr -match " already installed|No available upgrade|No installed package|No newer package|No applicable update|no applicable|is running" )
125+ if ($wingetOk ) {
124126 Write-Ok " $Name up to date (winget)"
125127 Refresh- Path
126- return $true
128+ return
129+ }
130+ # If upgrade failed, try install (handles version mismatch)
131+ if ($ForceUpgrade ) {
132+ $result2 = winget install -- id $WingetId -- accept- package- agreements -- accept- source- agreements -- disable-interactivity -- silent 2>&1
133+ if ($LASTEXITCODE -eq 0 -or " $result2 " -match " already installed" ) {
134+ Write-Ok " $Name up to date (winget)"
135+ Refresh- Path
136+ return
137+ }
127138 }
128139 }
129140
130141 # Fallback to Chocolatey
131142 if ($hasChoco ) {
132- $action = if ($ForceUpgrade ) { " upgrade" } else { " install" }
133- Write-Step " $ ( if ($ForceUpgrade ) { ' Updating' } else { ' Installing' } ) $Name via Chocolatey..."
134- choco $action $ChocoId - y -- no- progress 2> $null
135- if ($LASTEXITCODE -eq 0 ) {
136- Write-Ok " $Name up to date (Chocolatey)"
137- Refresh- Path
138- return $true
143+ try {
144+ $action = if ($ForceUpgrade ) { " upgrade" } else { " install" }
145+ Write-Step " $ ( if ($ForceUpgrade ) { ' Updating' } else { ' Installing' } ) $Name via Chocolatey..."
146+ choco $action $ChocoId - y -- no- progress 2> $null
147+ if ($LASTEXITCODE -eq 0 ) {
148+ Write-Ok " $Name up to date (Chocolatey)"
149+ Refresh- Path
150+ return
151+ }
152+ } catch {
153+ # Chocolatey binary missing or broken — skip silently
139154 }
140155 }
141156
142157 Write-Err " Could not install $Name automatically"
143158 Write-Warn " Install manually: $ManualUrl "
144- return $false
145159}
146160
147161# ---------------------------------------------------------------------------
@@ -155,35 +169,26 @@ Write-Host " -----------------------" -ForegroundColor DarkGray
155169# Node.js
156170if (Test-Command " node" ) {
157171 $nodeVer = & node -- version 2> $null
158- if ($isUpdate ) {
159- Install-Dep - Name " Node.js LTS" - WingetId " OpenJS.NodeJS.LTS" - ChocoId " nodejs-lts" - ManualUrl " https://nodejs.org" - ForceUpgrade
160- } else {
161- Write-Ok " Node.js $nodeVer (already installed)"
162- }
172+ Write-Ok " Node.js $nodeVer (installed)"
173+ if ($isUpdate ) { Install-Dep - Name " Node.js LTS" - WingetId " OpenJS.NodeJS.LTS" - ChocoId " nodejs-lts" - ManualUrl " https://nodejs.org" - ForceUpgrade }
163174} else {
164175 Install-Dep - Name " Node.js LTS" - WingetId " OpenJS.NodeJS.LTS" - ChocoId " nodejs-lts" - ManualUrl " https://nodejs.org"
165176}
166177
167178# Git
168179if (Test-Command " git" ) {
169180 $gitVer = & git -- version 2> $null
170- if ($isUpdate ) {
171- Install-Dep - Name " Git" - WingetId " Git.Git" - ChocoId " git" - ManualUrl " https://git-scm.com" - ForceUpgrade
172- } else {
173- Write-Ok " $gitVer (already installed)"
174- }
181+ Write-Ok " $gitVer (installed)"
182+ if ($isUpdate ) { Install-Dep - Name " Git" - WingetId " Git.Git" - ChocoId " git" - ManualUrl " https://git-scm.com" - ForceUpgrade }
175183} else {
176184 Install-Dep - Name " Git" - WingetId " Git.Git" - ChocoId " git" - ManualUrl " https://git-scm.com"
177185}
178186
179187# GitHub CLI
180188if (Test-Command " gh" ) {
181189 $ghVer = & gh -- version 2> $null | Select-Object - First 1
182- if ($isUpdate ) {
183- Install-Dep - Name " GitHub CLI" - WingetId " GitHub.cli" - ChocoId " gh" - ManualUrl " https://cli.github.com" - ForceUpgrade
184- } else {
185- Write-Ok " $ghVer (already installed)"
186- }
190+ Write-Ok " $ghVer (installed)"
191+ if ($isUpdate ) { Install-Dep - Name " GitHub CLI" - WingetId " GitHub.cli" - ChocoId " gh" - ManualUrl " https://cli.github.com" - ForceUpgrade }
187192} else {
188193 Install-Dep - Name " GitHub CLI" - WingetId " GitHub.cli" - ChocoId " gh" - ManualUrl " https://cli.github.com"
189194}
0 commit comments