Skip to content

Instantly share code, notes, and snippets.

@Jaykul
Created November 1, 2016 01:10
Show Gist options
  • Save Jaykul/4841faa179a3caf3142710541ae59878 to your computer and use it in GitHub Desktop.
Save Jaykul/4841faa179a3caf3142710541ae59878 to your computer and use it in GitHub Desktop.
Update-VSCode
function Get-VSCodeProduct {
#.Synopsis
# Get the current VSCode Product Info
Get-Item "${Env:ProgramFiles(x86)}\Microsoft VS Code*\Resources\app\product.json" | Get-Content | ConvertFrom-Json
}
function Get-WebFile {
#.Synopsis
# Get a file from the web using Invoke-WebRequest silently
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]$Url,
[string]$OutFile = 'vscode.exe'
)
$ProgressPreference = "SilentlyContinue"
if(!(Split-Path $OutFile))
{
$OutFile = Join-Path $env:Temp $OutFile
}
Invoke-WebRequest $Url -OutFile $OutFile
Get-Item $OutFile
}
function Find-VSCodeUpdate {
#.Synopsis
# Find a (newer) VS Code build
#.Description
# Calls the VS Code Update API to check for updates.
# If any are found, returns results, otherwise nothing.
[CmdletBinding()]
param(
# The platform (defaults to "win32" and probably doesn't work otherwise)
[ValidateSet('darwin','win32')]
[Parameter(ValueFromPipelineByPropertyName)]
$Platform='win32',
# The build quality (defaults to "insider" and probably doesn't work otherwise)
[Parameter(ValueFromPipelineByPropertyName)]
$Quality='insider',
# The commmit -- if there's no build for a commit newer than this (on this quality and platform), will return nothing
[Parameter(ValueFromPipelineByPropertyName)]
$Commit = '0'
)
$Current = Get-VSCodeProduct
if($Current) {
if(!$PSBoundParameters.ContainsKey("Commit"))
{
$Commit = $Current.Commit
}
if(!$PSBoundParameters.ContainsKey("Quality"))
{
$Quality = $Current.Quality
}
}
Write-Verbose "Searching for Platform: $Platform, Quality: $Quality, and a Commit newer than $Commit"
Invoke-RestMethod "https://vscode-update.azurewebsites.net/api/update/$Platform/$Quality/$Commit"
}
function Update-VSCode {
[CmdletBinding()]
param(
$Platform='win32',
$version = '1.0',
[switch]$DesktopIcon,
[switch]$FileContextMenu,
[switch]$DirectoryContextMenu,
[switch]$AddToPath
)
$Version = Find-VSCodeUpdate
switch($Platform) {
"win32" {
$Installer = Get-WebFile -Url $version.Url -OutFile $Version.Name + $Version.ProductVersion + '.exe'
$Tasks = "!runcode"
if($DesktopIcon) {
$Tasks += ",desktopicon"
}
if($FileContextMenu) {
$Tasks += ",addcontextmenufiles"
}
if($DirectoryContextMenu) {
$Tasks += ",addcontextmenufolders"
}
if($AddToPath) {
$Tasks += ",addtopath"
}
# http://www.jrsoftware.org/ishelp/index.php?topic=setupcmdline
Start $Installer.FullName "/SP- /VERYSILENT /SUPPRESSMSGBOXES /LOG /NORESTART /CLOSEAPPLICATIONS /RESTARTAPPLICATIONS /mergetasks=`"$tasks`""
}
default {
throw "Platform $platform not supported (yet)"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment