Use prompt for desktop shortcuts, fixes #914

This commit is contained in:
Julian Ospald 2023-11-06 22:43:11 +08:00
parent 94b4b7c455
commit da078c7362
No known key found for this signature in database
GPG Key ID: 4275CDA6A29BED43
1 changed files with 43 additions and 17 deletions

View File

@ -42,7 +42,9 @@ param (
# The Msys2 version to download (e.g. 20221216)
[string]$Msys2Version,
# The Msys2 sha256sum hash
[string]$Msys2Hash
[string]$Msys2Hash,
# Whether to disable creation of several desktop shortcuts
[switch]$DontWriteDesktopShortcuts
)
$DefaultMsys2Version = "20221216"
@ -410,6 +412,26 @@ if (!($InstallStack)) {
}
}
if ($Interactive) {
$DesktopDecision = $Host.UI.PromptForChoice('Create Desktop shortcuts'
, 'Do you want to create convenience desktop shortcuts (e.g. for uninstallation and msys2 shell)?'
, [System.Management.Automation.Host.ChoiceDescription[]] @('&Yes'
'&No'
'&Abort'), 0)
if ($DesktopDecision -eq 0) {
$InstallDesktopShortcuts = $true
} elseif ($DesktopDecision -eq 2) {
Exit 0
}
} else {
if ($Minimal) {
$InstallDesktopShortcuts = $false
} elseif ($DontWriteDesktopShortcuts) {
$InstallDesktopShortcuts = $false
} else {
$InstallDesktopShortcuts = $true
}
}
# mingw foo
Print-Msg -msg 'First checking for Msys2...'
@ -510,8 +532,11 @@ if (!(Test-Path -Path ('{0}' -f $MsysDir))) {
Start-Sleep -s 5
}
Print-Msg -msg 'Creating shortcuts...'
$uninstallShortCut = @'
if ($InstallDesktopShortcuts) {
Print-Msg -msg 'Creating shortcuts...'
$uninstallShortCut = @'
$decision = $Host.UI.PromptForChoice('Uninstall Haskell'
, 'Do you want to uninstall all of the haskell toolchain, including GHC, Cabal, Stack and GHCup itself?'
, [System.Management.Automation.Host.ChoiceDescription[]] @('&Uninstall'
@ -573,12 +598,13 @@ if ($Host.Name -eq "ConsoleHost")
}
'@
$GhcInstArgs = '-mingw64 -mintty -c "pacman --noconfirm -S --needed base-devel gettext autoconf make libtool automake python p7zip patch unzip"'
Create-Shortcut -SourceExe ('{0}\msys2_shell.cmd' -f $MsysDir) -ArgumentsToSourceExe $GhcInstArgs -DestinationPath 'Install GHC dev dependencies.lnk' -TempPath $GhcupDir
Create-Shortcut -SourceExe ('{0}\msys2_shell.cmd' -f $MsysDir) -ArgumentsToSourceExe '-mingw64' -DestinationPath 'Mingw haskell shell.lnk' -TempPath $GhcupDir
Create-Shortcut -SourceExe 'https://www.msys2.org/docs/package-management' -ArgumentsToSourceExe '' -DestinationPath 'Mingw package management docs.url' -TempPath $GhcupDir
$DesktopDir = [Environment]::GetFolderPath("Desktop")
$null = New-Item -Path $DesktopDir -Name "Uninstall Haskell.ps1" -ItemType "file" -Force -Value $uninstallShortCut
$GhcInstArgs = '-mingw64 -mintty -c "pacman --noconfirm -S --needed base-devel gettext autoconf make libtool automake python p7zip patch unzip"'
Create-Shortcut -SourceExe ('{0}\msys2_shell.cmd' -f $MsysDir) -ArgumentsToSourceExe $GhcInstArgs -DestinationPath 'Install GHC dev dependencies.lnk' -TempPath $GhcupDir
Create-Shortcut -SourceExe ('{0}\msys2_shell.cmd' -f $MsysDir) -ArgumentsToSourceExe '-mingw64' -DestinationPath 'Mingw haskell shell.lnk' -TempPath $GhcupDir
Create-Shortcut -SourceExe 'https://www.msys2.org/docs/package-management' -ArgumentsToSourceExe '' -DestinationPath 'Mingw package management docs.url' -TempPath $GhcupDir
$DesktopDir = [Environment]::GetFolderPath("Desktop")
$null = New-Item -Path $DesktopDir -Name "Uninstall Haskell.ps1" -ItemType "file" -Force -Value $uninstallShortCut
}
Print-Msg -msg ('Adding {0}\bin to Users Path...' -f $GhcupDir)
Add-EnvPath -Path ('{0}\bin' -f ([System.IO.Path]::GetFullPath("$GhcupDir"))) -Container 'User'