2023-06-01 20:35:29 +00:00
# Create C:\development
New-Item -Path 'C:\development' -ItemType Directory
2023-06-01 21:53:59 +00:00
# Download flutter_windows_3.7.12-stable.zip
Invoke-WebRequest " https://storage.googleapis.com/flutter_infra_release/releases/stable/windows/flutter_windows_3.7.12-stable.zip " -OutFile " C:\development\flutter_windows_3.7.12-stable.zip "
2023-06-01 20:35:29 +00:00
# Extract Flutter SDK
2023-06-01 21:53:59 +00:00
Expand-Archive " C:\development\flutter_windows_3.7.12-stable.zip " -DestinationPath " C:\development "
2023-06-01 20:35:29 +00:00
# See https://stackoverflow.com/a/69239861
function Add-Path {
param (
[ Parameter ( Mandatory , Position = 0 ) ]
[ string ] $LiteralPath ,
[ ValidateSet ( 'User' , 'CurrentUser' , 'Machine' , 'LocalMachine' ) ]
[ string ] $Scope
)
Set-StrictMode -Version 1 ; $ErrorActionPreference = 'Stop'
$isMachineLevel = $Scope -in 'Machine' , 'LocalMachine'
if ( $isMachineLevel -and -not $ ( $ErrorActionPreference = 'Continue' ; net session 2 > $null ) ) { throw " You must run AS ADMIN to update the machine-level Path environment variable. " }
$regPath = 'registry::' + ( 'HKEY_CURRENT_USER\Environment' , 'HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' ) [ $isMachineLevel ]
# Note the use of the .GetValue() method to ensure that the *unexpanded* value is returned.
$currDirs = ( Get-Item -LiteralPath $regPath ) . GetValue ( 'Path' , '' , 'DoNotExpandEnvironmentNames' ) -split ';' -ne ''
if ( $LiteralPath -in $currDirs ) {
Write-Verbose " Already present in the persistent $( ( 'user' , 'machine' ) [ $isMachineLevel ] ) -level Path: $LiteralPath "
return
}
$newValue = ( $currDirs + $LiteralPath ) -join ';'
# Update the registry.
Set-ItemProperty -Type ExpandString -LiteralPath $regPath Path $newValue
# Broadcast WM_SETTINGCHANGE to get the Windows shell to reload the
# updated environment, via a dummy [Environment]::SetEnvironmentVariable() operation.
$dummyName = [ guid ] :: NewGuid ( ) . ToString ( )
[ Environment ] :: SetEnvironmentVariable ( $dummyName , 'foo' , 'User' )
[ Environment ] :: SetEnvironmentVariable ( $dummyName , [ NullString ] :: value , 'User' )
# Finally, also update the current session's `$env:Path` definition.
# Note: For simplicity, we always append to the in-process *composite* value,
# even though for a -Scope Machine update this isn't strictly the same.
$env:Path = ( $env:Path -replace ';$' ) + ';' + $LiteralPath
Write-Verbose " `" $LiteralPath `" successfully appended to the persistent $( ( 'user' , 'machine' ) [ $isMachineLevel ] ) -level Path and also the current-process value. "
}
# Add Flutter SDK to PATH if it's not there already
if ( $Env:Path -split " ; " -contains 'C:\development\flutter\bin' ) {
} else {
Add-Path ( " C:\development\flutter\bin " )
}