Last active
November 5, 2024 07:02
-
-
Save eddiezato/e81fe690529d449c9cffce00a24a97ad to your computer and use it in GitHub Desktop.
Powershell: script to update VS Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$downloadpath = "D:\Downloads" | |
$curversion = (Get-Content -Path "resources\app\package.json" | ConvertFrom-Json).version | |
$newversion = (Invoke-WebRequest -Uri "https://api.github.com/repos/microsoft/vscode/releases/latest" | ConvertFrom-Json).tag_name | |
Write-Host "Visual Studio Code - Updater" -ForegroundColor Cyan | |
Write-Host "Current version: " -NoNewLine | |
Write-Host $curversion -ForegroundColor Yellow | |
Write-Host "New version: " -NoNewLine | |
Write-Host $newversion -ForegroundColor Green | |
$choice = Read-Host -Prompt "Type 'y' or 'yes' to update current version" | |
If (-not ($choice.ToLower() -in @("y", "yes"))) { exit } | |
$download = @{ | |
Source = "https://code.visualstudio.com/sha/download?build=stable&os=win32-x64-archive" | |
Destination = "$downloadpath\vsc$newversion.zip" | |
DisplayName = "Download VS Code" | |
Description = "Version $newversion" | |
} | |
Write-Host "Download new version..." -NoNewLine | |
Start-BitsTransfer @download | Out-Null | |
if ($? -and (Test-Path -Path $download.Destination)) { | |
Write-Host "ok" -ForegroundColor Green | |
Write-Host "Extract archive..." -NoNewLine | |
Expand-Archive -Path "$downloadpath\vsc$newversion.zip" -DestinationPath "$downloadpath\vsc$newversion\" | |
Write-Host "ok" -ForegroundColor Green | |
Write-Host "Remove unnecessary items..." -NoNewLine | |
Remove-Item -Path "$downloadpath\vsc$newversion.zip" | |
Remove-Item -Path "$downloadpath\vsc$newversion\locales\*" -Exclude "en-US.pak" | |
Write-Host "ok" -ForegroundColor Green | |
Write-Host "Update with new version..." -NoNewLine | |
Get-ChildItem -Exclude "data","_vscupdate.ps1" | Remove-Item -Recurse | |
Remove-Item -Path "data\user-data\CachedData\*" -Recurse | |
Move-Item -Path "$downloadpath\vsc$newversion\*" | |
Remove-Item -Path "$downloadpath\vsc$newversion" | |
Write-Host "ok" -ForegroundColor Green | |
} | |
else { Write-Host "fail" -ForegroundColor Red } | |
Write-Host "Press any key..." -NoNewLine | |
$Host.UI.RawUI.ReadKey() | Out-Null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment