diff --git a/WinDebloatTools.ps1 b/WinDebloatTools.ps1 index a9710a9a..44e1cf1b 100644 --- a/WinDebloatTools.ps1 +++ b/WinDebloatTools.ps1 @@ -420,8 +420,7 @@ function Show-GUI() { $InstallOpenSuse = New-CheckBox -Text "Open SUSE 42" -Width $LayoutT2.PanelElementWidth -Height $LayoutT2.CheckBoxHeight -LocationX $LayoutT2.PanelElementX -FontSize $LayoutT2.Heading[3] -ElementBefore $InstallKaliLinux $InstallSles = New-CheckBox -Text "SLES v12" -Width $LayoutT2.PanelElementWidth -Height $LayoutT2.CheckBoxHeight -LocationX $LayoutT2.PanelElementX -FontSize $LayoutT2.Heading[3] -ElementBefore $InstallOpenSuse $InstallUbuntu = New-CheckBox -Text "Ubuntu" -Width $LayoutT2.PanelElementWidth -Height $LayoutT2.CheckBoxHeight -LocationX $LayoutT2.PanelElementX -FontSize $LayoutT2.Heading[3] -ElementBefore $InstallSles - $InstallUbuntu16Lts = New-CheckBox -Text "Ubuntu 16.04 LTS" -Width $LayoutT2.PanelElementWidth -Height $LayoutT2.CheckBoxHeight -LocationX $LayoutT2.PanelElementX -FontSize $LayoutT2.Heading[3] -ElementBefore $InstallUbuntu - $InstallUbuntu18Lts = New-CheckBox -Text "Ubuntu 18.04 LTS" -Width $LayoutT2.PanelElementWidth -Height $LayoutT2.CheckBoxHeight -LocationX $LayoutT2.PanelElementX -FontSize $LayoutT2.Heading[3] -ElementBefore $InstallUbuntu16Lts + $InstallUbuntu18Lts = New-CheckBox -Text "Ubuntu 18.04 LTS" -Width $LayoutT2.PanelElementWidth -Height $LayoutT2.CheckBoxHeight -LocationX $LayoutT2.PanelElementX -FontSize $LayoutT2.Heading[3] -ElementBefore $InstallUbuntu $InstallUbuntu20Lts = New-CheckBox -Text "Ubuntu 20.04 LTS" -Width $LayoutT2.PanelElementWidth -Height $LayoutT2.CheckBoxHeight -LocationX $LayoutT2.PanelElementX -FontSize $LayoutT2.Heading[3] -ElementBefore $InstallUbuntu18Lts $ClDevelopment = New-Label -Text "⌨ Development on Windows" -Width $LayoutT2.PanelElementWidth -Height $LayoutT2.CaptionLabelHeight -LocationX $LayoutT2.PanelElementX -FontSize $LayoutT2.Heading[2] -FontStyle 'Bold' -ElementBefore $InstallUbuntu20Lts @@ -491,7 +490,7 @@ function Show-GUI() { $T2Panel3.Controls.AddRange(@($ClRecordingAndStreaming, $InstallElgatoStreamDeck, $InstallHandBrake, $InstallObsStudio, $InstallStreamlabs)) $T2Panel3.Controls.AddRange(@($ClEmulation, $InstallBSnesHd, $InstallCemu, $InstallDolphin, $InstallKegaFusion, $InstallMGba, $InstallPPSSPP, $InstallProject64, $InstallRetroArch, $InstallRyujinx, $InstallSnes9x)) $T2Panel4.Controls.AddRange(@($ClTextEditors, $InstallJetBrainsToolbox, $InstallNotepadPlusPlus, $InstallVisualStudioCommunity, $InstallVSCode, $InstallVSCodium)) - $T2Panel4.Controls.AddRange(@($ClWsl, $InstallWSL, $InstallArchWSL, $InstallDebian, $InstallKaliLinux, $InstallOpenSuse, $InstallSles, $InstallUbuntu, $InstallUbuntu16Lts, $InstallUbuntu18Lts, $InstallUbuntu20Lts)) + $T2Panel4.Controls.AddRange(@($ClWsl, $InstallWSL, $InstallArchWSL, $InstallDebian, $InstallKaliLinux, $InstallOpenSuse, $InstallSles, $InstallUbuntu, $InstallUbuntu18Lts, $InstallUbuntu20Lts)) $T2Panel4.Controls.AddRange(@($ClDevelopment, $InstallWindowsTerminal, $InstallNerdFonts, $InstallGitGnupgSshSetup, $InstallAdb, $InstallAndroidStudio, $InstallDockerDesktop, $InstallInsomnia, $InstallJavaJdks, $InstallJavaJre, $InstallMySql, $InstallNodeJs, $InstallNodeJsLts, $InstallPostgreSql, $InstallPython3, $InstallPythonAnaconda3, $InstallRuby, $InstallRubyMsys, $InstallRustGnu, $InstallRustMsvc)) # <===== CLICK EVENTS =====> @@ -1501,11 +1500,6 @@ function Show-GUI() { $InstallUbuntu.CheckState = "Unchecked" } - If ($InstallUbuntu16Lts.CheckState -eq "Checked") { - $AppsSelected.WSLDistros.Add("Ubuntu-16.04") - $InstallUbuntu16Lts.CheckState = "Unchecked" - } - If ($InstallUbuntu18Lts.CheckState -eq "Checked") { $AppsSelected.WSLDistros.Add("Ubuntu-18.04") $InstallUbuntu18Lts.CheckState = "Unchecked" diff --git a/src/lib/package-managers/Install-PackageManager.psm1 b/src/lib/package-managers/Install-PackageManager.psm1 index bbab8ea8..dba6e523 100644 --- a/src/lib/package-managers/Install-PackageManager.psm1 +++ b/src/lib/package-managers/Install-PackageManager.psm1 @@ -12,14 +12,16 @@ function Install-PackageManager() { [ScriptBlock] $CheckExistenceBlock, [Parameter(Position = 2, Mandatory)] [ScriptBlock] $InstallCommandBlock, - [ScriptBlock] $PostInstallBlock + [ScriptBlock] $PostInstallBlock, + [Switch] $Force ) Try { $Err = (Invoke-Expression "$CheckExistenceBlock") - If (($LASTEXITCODE)) { throw $Err } # 0 = False, 1 = True + If (($LASTEXITCODE -or $Force)) { throw $Err } # 0 = False, 1 = True Write-Status -Types "?", $PackageManagerFullName -Status "$PackageManagerFullName is already installed." -Warning } Catch { + Write-Status -Types "@", $PackageManagerFullName -Status "FORCE INSTALLING $PackageManagerFullName." -Warning Write-Status -Types "?", $PackageManagerFullName -Status "$PackageManagerFullName was not found." -Warning Write-Status -Types "+", $PackageManagerFullName -Status "Downloading and Installing $PackageManagerFullName package manager." diff --git a/src/lib/package-managers/Manage-Chocolatey.psm1 b/src/lib/package-managers/Manage-Chocolatey.psm1 index d438224a..3a5d46fa 100644 --- a/src/lib/package-managers/Manage-Chocolatey.psm1 +++ b/src/lib/package-managers/Manage-Chocolatey.psm1 @@ -1,6 +1,5 @@ Import-Module -DisableNameChecking "$PSScriptRoot\Install-PackageManager.psm1" Import-Module -DisableNameChecking "$PSScriptRoot\Manage-DailyUpgradeJob.psm1" -Import-Module -DisableNameChecking "$PSScriptRoot\Manage-Software.psm1" Import-Module -DisableNameChecking "$PSScriptRoot\..\Title-Templates.psm1" Import-Module -DisableNameChecking "$PSScriptRoot\..\ui\Show-MessageDialog.psm1" @@ -8,6 +7,11 @@ $Script:DoneTitle = "Information" $Script:DoneMessage = "Process Completed!" function Install-Chocolatey() { + [CmdletBinding()] + param ( + [Switch] $Force + ) + Begin { $ChocolateyParams = @{ Name = "Chocolatey" @@ -18,14 +22,21 @@ function Install-Chocolatey() { [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) } - PostInstallBlock = { choco install --ignore-dependencies --yes "chocolatey-core.extension" "chocolatey-fastanswers.extension" "dependency-windows10" } + PostInstallBlock = { choco install --ignore-dependencies --yes "chocolatey-core.extension" "chocolatey-fastanswers.extension" } } } Process { - # Install Chocolatey on Windows - Install-PackageManager -PackageManagerFullName $ChocolateyParams.Name -CheckExistenceBlock $ChocolateyParams.CheckExistenceBlock -InstallCommandBlock $ChocolateyParams.InstallCommandBlock -PostInstallBlock $ChocolateyParams.PostInstallBlock - Show-MessageDialog -Title "$DoneTitle" -Message "$DoneMessage" + If ($Force) { + # Install Chocolatey on Windows + Install-PackageManager -PackageManagerFullName $ChocolateyParams.Name -CheckExistenceBlock $ChocolateyParams.CheckExistenceBlock -InstallCommandBlock $ChocolateyParams.InstallCommandBlock -PostInstallBlock $ChocolateyParams.PostInstallBlock -Force + } Else { + Install-PackageManager -PackageManagerFullName $ChocolateyParams.Name -CheckExistenceBlock $ChocolateyParams.CheckExistenceBlock -InstallCommandBlock $ChocolateyParams.InstallCommandBlock -PostInstallBlock $ChocolateyParams.PostInstallBlock + } + + If (!$Force) { + Show-MessageDialog -Title "$DoneTitle" -Message "$DoneMessage" + } } } @@ -169,12 +180,12 @@ function Unregister-ChocolateyDailyUpgrade() { function Remove-AllChocolateyPackage() { Begin { + Import-Module -DisableNameChecking "$PSScriptRoot\Manage-Software.psm1" $Ask = "Are you sure you want to remove:`n$((choco list) -match '\w \d.*\d' | ForEach-Object { "`n- $_" })`n`nPress YES to confirm." $Question = Show-Question -Title "Remove ALL Chocolatey Packages?" -Message $Ask -BoxIcon "Warning" } Process { - switch ($Question) { 'Yes' { Uninstall-Software -Name "All Chocolatey Packages" -Packages @("all") -PackageProvider 'Chocolatey' diff --git a/src/lib/package-managers/Manage-Software.psm1 b/src/lib/package-managers/Manage-Software.psm1 index cbcfb8d3..d1a3cd3b 100644 --- a/src/lib/package-managers/Manage-Software.psm1 +++ b/src/lib/package-managers/Manage-Software.psm1 @@ -1,3 +1,6 @@ +Import-Module -DisableNameChecking "$PSScriptRoot\Manage-Chocolatey.psm1" +Import-Module -DisableNameChecking "$PSScriptRoot\Manage-Winget.psm1" +Import-Module -DisableNameChecking "$PSScriptRoot\..\Open-File.psm1" Import-Module -DisableNameChecking "$PSScriptRoot\..\Title-Templates.psm1" Import-Module -DisableNameChecking "$PSScriptRoot\..\ui\Show-MessageDialog.psm1" @@ -17,18 +20,41 @@ function Install-Software() { [Switch] $NoDialog ) - $DoneTitle = "Information" - $DoneMessage = "$Name installed successfully!" + [ScriptBlock] $CheckVersionCommand + $Script:DoneTitle = "Information" + $Script:DoneMessage = "$Name installed successfully!" + + If ($PackageProvider -in @('Winget', 'MsStore')) { + $CheckVersionCommand = { winget --version } + } If ($PackageProvider -eq 'Chocolatey') { + $CheckVersionCommand = { choco --version } $InstallBlock = { choco install --ignore-dependencies --yes $Package } Write-Status -Types "?" -Status "Chocolatey is configured to ignore dependencies (bloat), you may need to install it before using any program." -Warning } If ($PackageProvider -eq 'WSL') { + $CheckVersionCommand = { wsl --version } $InstallBlock = { wsl --install --distribution $Package } } + Try { + $Err = (Invoke-Expression "$CheckVersionCommand") + If (($LASTEXITCODE)) { throw $Err } # 0 = False, 1 = True + Write-Status -Types "?", $PackageProvider -Status "$PackageProvider is already installed." -Warning + } Catch { + If ($PackageProvider -in @('Winget', 'MsStore')) { + Install-Winget -Force + } + If ($PackageProvider -in @('Chocolatey')) { + Install-Chocolatey -Force + } + If ($PackageProvider -in @('WSL')) { + Open-PowerShellFilesCollection -RelativeLocation "src\scripts\other-scripts" -Scripts @("Install-WSL.ps1") -NoDialog + } + } + Write-Title "Installing $($Name) via $PackageProvider" $DoneMessage += "`n`nInstalled via $PackageProvider`:`n" diff --git a/src/lib/package-managers/Manage-Winget.psm1 b/src/lib/package-managers/Manage-Winget.psm1 index 0d7e378e..b3c46234 100644 --- a/src/lib/package-managers/Manage-Winget.psm1 +++ b/src/lib/package-managers/Manage-Winget.psm1 @@ -13,6 +13,11 @@ $Script:DoneTitle = "Information" $Script:DoneMessage = "Process Completed!" function Install-Winget() { + [CmdletBinding()] + param ( + [Switch] $Force + ) + Begin { $WingetParams = @{ Name = "Winget" @@ -61,12 +66,21 @@ function Install-Winget() { } Process { - # Install Winget on Windows (Method 1) - Install-PackageManager -PackageManagerFullName $WingetParams.Name -CheckExistenceBlock $WingetParams.CheckExistenceBlock -InstallCommandBlock $WingetParams.InstallCommandBlock - # Install Winget on Windows (Method 2) + If ($Force) { + # Install Winget on Windows (Method 1) + Install-PackageManager -PackageManagerFullName $WingetParams.Name -CheckExistenceBlock $WingetParams.CheckExistenceBlock -InstallCommandBlock $WingetParams.InstallCommandBlock -Force + # Install Winget on Windows (Method 2) + } Else { + # Install Winget on Windows (Method 1) + Install-PackageManager -PackageManagerFullName $WingetParams.Name -CheckExistenceBlock $WingetParams.CheckExistenceBlock -InstallCommandBlock $WingetParams.InstallCommandBlock + # Install Winget on Windows (Method 2) + } + Install-PackageManager -PackageManagerFullName $WingetParams2.Name -CheckExistenceBlock $WingetParams2.CheckExistenceBlock -InstallCommandBlock $WingetParams2.InstallCommandBlock - Show-MessageDialog -Title "$DoneTitle" -Message "$DoneMessage" + If (!$Force) { + Show-MessageDialog -Title "$DoneTitle" -Message "$DoneMessage" + } } }