Compare commits

...

4 Commits

Author SHA1 Message Date
MyDrift
8b158df8c4 read throw error 2024-08-25 21:23:24 +02:00
MyDrift
494ad3c802 remove $automation entirely 2024-08-25 21:13:43 +02:00
MyDrift
a4d1d0fd67 fix splitting up in wpfrunspace & catch errors 2024-08-25 21:12:13 +02:00
MyDrift
cb6898d835 fix 2024-08-25 20:06:33 +02:00
8 changed files with 14 additions and 29 deletions

View File

@ -2430,12 +2430,6 @@
"Order": "a001_", "Order": "a001_",
"InvokeScript": [ "InvokeScript": [
" "
# Check if the user has administrative privileges
if (-Not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host \"Please run this script as an administrator.\"
return
}
# Check if System Restore is enabled for the main drive # Check if System Restore is enabled for the main drive
try { try {
# Try getting restore points to check if System Restore is enabled # Try getting restore points to check if System Restore is enabled

View File

@ -59,8 +59,8 @@ function Invoke-WinUtilTweaks {
Write-Debug "Service $($service.Name) was changed in the past to $($service.StartType.ToString()) from it's original type of $($psitem.$($values.OriginalService)), will not change it to $($psitem.$($values.service))" Write-Debug "Service $($service.Name) was changed in the past to $($service.StartType.ToString()) from it's original type of $($psitem.$($values.OriginalService)), will not change it to $($psitem.$($values.service))"
$changeservice = $false $changeservice = $false
} }
} catch [System.ServiceProcess.ServiceNotFoundException] { } catch {
Write-Warning "Service $($psitem.Name) was not found" write-host "Unable to get service $($psitem.Name)"
} }
} }

View File

@ -26,11 +26,7 @@ Function Set-WinUtilService {
# Service exists, proceed with changing properties # Service exists, proceed with changing properties
$service | Set-Service -StartupType $StartupType -ErrorAction Stop $service | Set-Service -StartupType $StartupType -ErrorAction Stop
} catch [System.ServiceProcess.ServiceNotFoundException] {
Write-Warning "Service $Name was not found"
} catch { } catch {
Write-Warning "Unable to set $Name due to unhandled exception" write-host "Unable to get service $($Name)"
Write-Warning $_.Exception.Message
} }
} }

View File

@ -85,6 +85,6 @@ function Set-WinUtilTaskbaritem {
$sync["Form"].taskbarItemInfo.Description = $description $sync["Form"].taskbarItemInfo.Description = $description
} }
} catch { } catch {
#nothing #do nothing
} }
} }

View File

@ -18,14 +18,12 @@ function Invoke-WPFFeatureInstall {
if ($FeatureConfig) { if ($FeatureConfig) {
$Features = $FeatureConfig $Features = $FeatureConfig
$automation = $true
} else { } else {
$Features = (Get-WinUtilCheckBoxes)["WPFFeature"] $Features = (Get-WinUtilCheckBoxes)["WPFFeature"]
$automation = $false
} }
Invoke-WPFRunspace -ArgumentList $Features, $automation -DebugPreference $DebugPreference -ScriptBlock { Invoke-WPFRunspace -ArgumentList $Features -DebugPreference $DebugPreference -ScriptBlock {
param($Features, $automation, $DebugPreference) param($Features, $DebugPreference)
$sync.ProcessRunning = $true $sync.ProcessRunning = $true
if ($Features.count -eq 1) { if ($Features.count -eq 1) {
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" -value 0.01 -overlay "logo" }) $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" -value 0.01 -overlay "logo" })

View File

@ -18,10 +18,8 @@ function Invoke-WPFInstall {
if ($InstallConfig) { if ($InstallConfig) {
$PackagesToInstall = $InstallConfig $PackagesToInstall = $InstallConfig
$automation = $true
} else { } else {
$PackagesToInstall = (Get-WinUtilCheckBoxes)["Install"] $PackagesToInstall = (Get-WinUtilCheckBoxes)["Install"]
$automation = $false
} }
if ($PackagesToInstall.Count -eq 0) { if ($PackagesToInstall.Count -eq 0) {
@ -31,8 +29,8 @@ function Invoke-WPFInstall {
} }
Invoke-WPFRunspace -ArgumentList $PackagesToInstall, $automation -DebugPreference $DebugPreference -ScriptBlock { Invoke-WPFRunspace -ArgumentList $PackagesToInstall -DebugPreference $DebugPreference -ScriptBlock {
param($PackagesToInstall, $automation, $DebugPreference) param($PackagesToInstall, $DebugPreference)
if ($PackagesToInstall.count -eq 1) { if ($PackagesToInstall.count -eq 1) {
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" -value 0.01 -overlay "logo" }) $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" -value 0.01 -overlay "logo" })
} else { } else {

View File

@ -22,13 +22,14 @@ function Invoke-WPFRunspace {
Param ( Param (
$ScriptBlock, $ScriptBlock,
$ArgumentList, $ArgumentList,
$DebugPreference, $DebugPreference
$automation
) )
if ($automation = $true) { if ($PARAM_RUN) {
write-host "Running in Main Thread"
& $ScriptBlock @ArgumentList @DebugPreference & $ScriptBlock @ArgumentList @DebugPreference
} else { } else {
write-host "Running in Runspace"
# Create a PowerShell instance # Create a PowerShell instance
$script:powershell = [powershell]::Create() $script:powershell = [powershell]::Create()

View File

@ -18,10 +18,8 @@ function Invoke-WPFtweaksbutton {
if ($TweaksConfig) { if ($TweaksConfig) {
$Tweaks = $TweaksConfig $Tweaks = $TweaksConfig
$automation = $true
} else { } else {
$Tweaks = (Get-WinUtilCheckBoxes)["WPFTweaks"] $Tweaks = (Get-WinUtilCheckBoxes)["WPFTweaks"]
$automation = $false
} }
Set-WinUtilDNS -DNSProvider $sync["WPFchangedns"].text Set-WinUtilDNS -DNSProvider $sync["WPFchangedns"].text
@ -34,8 +32,8 @@ function Invoke-WPFtweaksbutton {
Write-Debug "Number of tweaks to process: $($Tweaks.Count)" Write-Debug "Number of tweaks to process: $($Tweaks.Count)"
Invoke-WPFRunspace -ArgumentList $Tweaks, $automation -DebugPreference $DebugPreference -ScriptBlock { Invoke-WPFRunspace -ArgumentList $Tweaks -DebugPreference $DebugPreference -ScriptBlock {
param($Tweaks, $automation, $DebugPreference) param($Tweaks, $DebugPreference)
Write-Debug "Inside Number of tweaks to process: $($Tweaks.Count)" Write-Debug "Inside Number of tweaks to process: $($Tweaks.Count)"
$sync.ProcessRunning = $true $sync.ProcessRunning = $true