From ae87100c611438cc9f7f66aded3e008e58716ffe Mon Sep 17 00:00:00 2001 From: MyDrift Date: Sat, 24 Aug 2024 21:31:28 +0200 Subject: [PATCH] improve automation - runs everything at the same time - does not work without displaying ui --- functions/public/Invoke-WPFFeatureInstall.ps1 | 10 +++- functions/public/Invoke-WPFInstall.ps1 | 12 +++- functions/public/Invoke-WPFtweaksbutton.ps1 | 10 +++- scripts/main.ps1 | 57 +++++++++++-------- 4 files changed, 60 insertions(+), 29 deletions(-) diff --git a/functions/public/Invoke-WPFFeatureInstall.ps1 b/functions/public/Invoke-WPFFeatureInstall.ps1 index dd9995d2..02c37881 100644 --- a/functions/public/Invoke-WPFFeatureInstall.ps1 +++ b/functions/public/Invoke-WPFFeatureInstall.ps1 @@ -6,13 +6,21 @@ function Invoke-WPFFeatureInstall { #> + param ( + $FeatureConfig + ) + if($sync.ProcessRunning) { $msg = "[Invoke-WPFFeatureInstall] Install process is currently running." [System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning) return } - $Features = (Get-WinUtilCheckBoxes)["WPFFeature"] + if ($FeatureConfig) { + $Features = $FeatureConfig + } else { + $Features = (Get-WinUtilCheckBoxes)["WPFFeature"] + } Invoke-WPFRunspace -ArgumentList $Features -DebugPreference $DebugPreference -ScriptBlock { param($Features, $DebugPreference) diff --git a/functions/public/Invoke-WPFInstall.ps1 b/functions/public/Invoke-WPFInstall.ps1 index 0d880c93..120ab56b 100644 --- a/functions/public/Invoke-WPFInstall.ps1 +++ b/functions/public/Invoke-WPFInstall.ps1 @@ -6,14 +6,22 @@ function Invoke-WPFInstall { #> + param ( + $InstallConfig + ) + if($sync.ProcessRunning) { $msg = "[Invoke-WPFInstall] An Install process is currently running." [System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning) return } - $PackagesToInstall = (Get-WinUtilCheckBoxes)["Install"] - Write-Host $PackagesToInstall + if ($InstallConfig) { + $PackagesToInstall = $InstallConfig + } else { + $PackagesToInstall = (Get-WinUtilCheckBoxes)["Install"] + } + if ($PackagesToInstall.Count -eq 0) { $WarningMsg = "Please select the program(s) to install or upgrade" [System.Windows.MessageBox]::Show($WarningMsg, $AppTitle, [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning) diff --git a/functions/public/Invoke-WPFtweaksbutton.ps1 b/functions/public/Invoke-WPFtweaksbutton.ps1 index a4f38193..342ec04b 100644 --- a/functions/public/Invoke-WPFtweaksbutton.ps1 +++ b/functions/public/Invoke-WPFtweaksbutton.ps1 @@ -6,13 +6,21 @@ function Invoke-WPFtweaksbutton { #> + param ( + $TweaksConfig + ) + if($sync.ProcessRunning) { $msg = "[Invoke-WPFtweaksbutton] Install process is currently running." [System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning) return } - $Tweaks = (Get-WinUtilCheckBoxes)["WPFTweaks"] + if ($TweaksConfig) { + $Tweaks = $TweaksConfig + } else { + $Tweaks = (Get-WinUtilCheckBoxes)["WPFTweaks"] + } Set-WinUtilDNS -DNSProvider $sync["WPFchangedns"].text diff --git a/scripts/main.ps1 b/scripts/main.ps1 index c1d476f4..bfc05c52 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -322,38 +322,45 @@ Add-Type @" # maybe this is not the best place to load and execute config file? # maybe community can help? if ($PARAM_CONFIG) { - Invoke-WPFImpex -type "import" -Config $PARAM_CONFIG if ($PARAM_RUN) { - while ($sync.ProcessRunning) { - Start-Sleep -Seconds 5 + $installConfig = Get-Content $PARAM_CONFIG -Raw | ConvertFrom-Json + if ($installConfig.WPFTweaks) { + write-host "Running Tweaks" + Invoke-WPFtweaksbutton -TweaksConfig $installConfig.WPFTweaks } - Start-Sleep -Seconds 5 - - Write-Host "Applying tweaks..." - Invoke-WPFtweaksbutton - while ($sync.ProcessRunning) { - Start-Sleep -Seconds 5 + if ($installConfig.WPFFeature) { + write-host "Installing Features" + Invoke-WPFFeatureInstall -FeatureConfig $installConfig.WPFFeature } - Start-Sleep -Seconds 5 + if ($installConfig.WPFInstall) { + write-host "Installing Programs" - Write-Host "Installing features..." - Invoke-WPFFeatureInstall - while ($sync.ProcessRunning) { - Start-Sleep -Seconds 5 + # Create a new array to hold the combined install configurations + $combinedInstallConfig = @() + + # Iterate over each WPFInstall entry + for ($i = 0; $i -lt $installConfig.WPFInstall.Count; $i++) { + $wpfInstallEntry = $installConfig.WPFInstall[$i] + $installEntry = $installConfig.Install[$i] + + # Create a new object with the combined values + $combinedEntry = @{ + Name = $wpfInstallEntry + Winget = $installEntry.winget + Choco = $installEntry.choco + } + + # Add the combined entry to the array + $combinedInstallConfig += $combinedEntry + } + + # Invoke the WPFInstall function with the combined configuration + Invoke-WPFInstall -InstallConfig $combinedInstallConfig } - - Start-Sleep -Seconds 5 - Write-Host "Installing applications..." - while ($sync.ProcessRunning) { - Start-Sleep -Seconds 1 - } - Invoke-WPFInstall - Start-Sleep -Seconds 5 - - Write-Host "Done." + } else { + Invoke-WPFImpex -type "import" -Config $PARAM_CONFIG } } - }) # Load Checkboxes and Labels outside of the Filter function only once on startup for performance reasons