Skip to content

Instantly share code, notes, and snippets.

@p0w3rsh3ll
Last active August 13, 2017 15:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save p0w3rsh3ll/d94893e1416e749327d67e865d65dd6b to your computer and use it in GitHub Desktop.
Save p0w3rsh3ll/d94893e1416e749327d67e865d65dd6b to your computer and use it in GitHub Desktop.
if (-not(Test-Path ~/Downloads/VSCode -PathType Container)) {
Write-Warning 'Folder ~/Downloads/VSCode not found'
break
}
if (Test-Path ~/Downloads/VSCode/VSCode-win32-stable.zip) {
Write-Warning -Message 'Zip file found in ~/Downloads/VSCode/'
break
}
# version in prod
$localver = (Get-Item -Path 'C:\Program Files (x86)\Microsoft VS Code\Code.exe' -ErrorAction SilentlyContinue).VersionInfo.FileVersion
Write-Verbose -Message "Local version in program files $($localver) detected" -Verbose
# new online version
$uri = 'https://vscode-update.azurewebsites.net/latest/win32-archive/stable'
$onlineloc = (Invoke-WebRequest -Uri $uri -MaximumRedirection 0 -ErrorAction SilentlyContinue -UseBasicParsing).Headers.Location
Write-Verbose -Message "Online location found at $($onlineloc)" -Verbose
$onlinever =([regex]'VSCode-win32-(ia32-)?(?<Version>(\d{1,}\.){1,3}\d{1,})\.zip').Matches(
([uri]$onlineloc).Segments[-1]
).Groups[-1].Value
if ([version]$localver -eq [version]$onlinever) {
Write-Verbose -Message "Already up-to-date: $($localver)" -Verbose
break
} else {
Write-Verbose -Message "You need to update your local version $($localver) to $($onlinever)" -Verbose
}
Write-Verbose "About to download online version $($onlinever)" -Verbose
Invoke-WebRequest -Uri $onlineloc -OutFile ~/Downloads/VSCode/VSCode-win32-stable.zip
if (Test-Path ~/Downloads/VSCode/VSCode-win32-stable.zip) {
# rename folder
if (Test-Path ~/Downloads/VSCode/VSCode-win32-stable) {
Rename-Item -Path ~/Downloads/VSCode/VSCode-win32-stable -NewName ('VSCode-win32-stable-{0}' -f (
dir "~/Downloads/VSCode/VSCode-win32-stable/Code.exe").VersionInfo.FileVersion
) -Verbose
}
# expand zip
Expand-Archive -Path ~/Downloads/VSCode/VSCode-win32-stable.zip -DestinationPath ~/Downloads/VSCode/VSCode-win32-stable -Force
# new version?
(Get-Item -Path '~/Downloads/VSCode/VSCode-win32-stable/Code.exe').VersionInfo |
Select FileVersion,ProductVersion
# signed?
dir '~\Downloads\VSCode\VSCode-win32-stable\*' -Include *.exe,*.dll -Recurse -Force -ErrorAction SilentlyContinue|
Get-AuthenticodeSignature
# push to prod
& (gcm "$($env:systemroot)\system32\robocopy.exe") @(
"$($env:userprofile)\Downloads\VSCode\VSCode-win32-stable",
'C:\Program Files (x86)\Microsoft VS Code','/R:0','/Z','/S','/PURGE','/NP'
)
# ren zip
Rename-Item -Path ~/Downloads\VSCode\VSCode-win32-stable.zip -NewName ('VSCode-win32-stable-{0}.zip' -f (
dir "~/Downloads/VSCode/VSCode-win32-stable/code.exe").VersionInfo.FileVersion
) -Verbose
}
# enjoy!
& 'C:\Program Files (x86)\Microsoft VS Code\Code.exe'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment