
This should make our scripts compatible with PowerShell 2 or newer. PowerShell 2 was released in October 2009 and shipped with Windows 7 as default. (I suspect the scripts are now also compatible with PowerShell 1, but that's unconfirmed). This fixes #8606. The PR also introduces better error handling when Flutter fail to download the Dart SDK to fix #8627.
35 lines
1.4 KiB
PowerShell
35 lines
1.4 KiB
PowerShell
# Copyright 2017 The Chromium Authors. All rights reserved.
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
|
|
# This is a wrapper arround flutter.bat, which checks if the terminal supports
|
|
# ANSI codes to work around https://github.com/dart-lang/sdk/issues/28614.
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
Add-Type -MemberDefinition @"
|
|
[DllImport("kernel32.dll", SetLastError=true)]
|
|
public static extern bool SetConsoleMode(IntPtr hConsoleHandle, int mode);
|
|
[DllImport("kernel32.dll", SetLastError=true)]
|
|
public static extern IntPtr GetStdHandle(int handle);
|
|
[DllImport("kernel32.dll", SetLastError=true)]
|
|
public static extern bool GetConsoleMode(IntPtr handle, out int mode);
|
|
"@ -Namespace Win32 -Name NativeMethods
|
|
|
|
If (Test-Path Env:\FLUTTER_ANSI_TERMINAL) { Remove-Item Env:\FLUTTER_ANSI_TERMINAL }
|
|
$stdout = [Win32.NativeMethods]::GetStdHandle(-11) # STD_OUTPUT_HANDLE
|
|
If ($stdout -ne -1) {
|
|
$mode = 0
|
|
If ([Win32.NativeMethods]::GetConsoleMode($stdout, [ref]$mode)) {
|
|
$mode = $mode -bor 4 # ENABLE_VIRTUAL_TERMINAL_PROCESSING
|
|
If ([Win32.NativeMethods]::SetConsoleMode($stdout, $mode)) {
|
|
$env:FLUTTER_ANSI_TERMINAL = "true"
|
|
}
|
|
}
|
|
}
|
|
|
|
# Cannot use $PSScriptRoot as that requires PowerShell 3 or newer
|
|
$scriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
|
|
& $scriptRoot\flutter.bat $args
|
|
exit $LastExitCode
|