Compare commits

..

No commits in common. "5621b50762c40b10eb24df6282073696ff30de4d" and "ae87100c611438cc9f7f66aded3e008e58716ffe" have entirely different histories.

7 changed files with 106 additions and 129 deletions

View File

@ -3091,8 +3091,8 @@
"panel": "1", "panel": "1",
"Order": "a002_", "Order": "a002_",
"InvokeScript": [ "InvokeScript": [
"Get-ChildItem -Path \"C:\\Windows\\Temp\" *.* -Recurse | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue "Get-ChildItem -Path \"C:\\Windows\\Temp\" *.* -Recurse | Remove-Item -Force -Recurse
Get-ChildItem -Path $env:TEMP *.* -Recurse | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue" Get-ChildItem -Path $env:TEMP *.* -Recurse | Remove-Item -Force -Recurse"
], ],
"link": "https://christitustech.github.io/winutil/dev/tweaks/Essential-Tweaks/DeleteTempFiles" "link": "https://christitustech.github.io/winutil/dev/tweaks/Essential-Tweaks/DeleteTempFiles"
}, },

View File

@ -43,48 +43,44 @@ function Set-WinUtilTaskbaritem {
[string]$description [string]$description
) )
try { if ($value) {
if ($value) { $sync["Form"].taskbarItemInfo.ProgressValue = $value
$sync["Form"].taskbarItemInfo.ProgressValue = $value }
}
if ($state) { if ($state) {
switch ($state) { switch ($state) {
'None' { $sync["Form"].taskbarItemInfo.ProgressState = "None" } 'None' { $sync["Form"].taskbarItemInfo.ProgressState = "None" }
'Indeterminate' { $sync["Form"].taskbarItemInfo.ProgressState = "Indeterminate" } 'Indeterminate' { $sync["Form"].taskbarItemInfo.ProgressState = "Indeterminate" }
'Normal' { $sync["Form"].taskbarItemInfo.ProgressState = "Normal" } 'Normal' { $sync["Form"].taskbarItemInfo.ProgressState = "Normal" }
'Error' { $sync["Form"].taskbarItemInfo.ProgressState = "Error" } 'Error' { $sync["Form"].taskbarItemInfo.ProgressState = "Error" }
'Paused' { $sync["Form"].taskbarItemInfo.ProgressState = "Paused" } 'Paused' { $sync["Form"].taskbarItemInfo.ProgressState = "Paused" }
default { throw "[Set-WinUtilTaskbarItem] Invalid state" } default { throw "[Set-WinUtilTaskbarItem] Invalid state" }
}
}
if ($overlay) {
switch ($overlay) {
'logo' {
$sync["Form"].taskbarItemInfo.Overlay = "$env:LOCALAPPDATA\winutil\cttlogo.png"
} }
} 'checkmark' {
$sync["Form"].taskbarItemInfo.Overlay = "$env:LOCALAPPDATA\winutil\checkmark.png"
if ($overlay) { }
switch ($overlay) { 'warning' {
'logo' { $sync["Form"].taskbarItemInfo.Overlay = "$env:LOCALAPPDATA\winutil\warning.png"
$sync["Form"].taskbarItemInfo.Overlay = "$env:LOCALAPPDATA\winutil\cttlogo.png" }
} 'None' {
'checkmark' { $sync["Form"].taskbarItemInfo.Overlay = $null
$sync["Form"].taskbarItemInfo.Overlay = "$env:LOCALAPPDATA\winutil\checkmark.png" }
} default {
'warning' { if (Test-Path $overlay) {
$sync["Form"].taskbarItemInfo.Overlay = "$env:LOCALAPPDATA\winutil\warning.png" $sync["Form"].taskbarItemInfo.Overlay = $overlay
}
'None' {
$sync["Form"].taskbarItemInfo.Overlay = $null
}
default {
if (Test-Path $overlay) {
$sync["Form"].taskbarItemInfo.Overlay = $overlay
}
} }
} }
} }
}
if ($description) { if ($description) {
$sync["Form"].taskbarItemInfo.Description = $description $sync["Form"].taskbarItemInfo.Description = $description
}
} catch {
#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,32 +22,27 @@ function Invoke-WPFRunspace {
Param ( Param (
$ScriptBlock, $ScriptBlock,
$ArgumentList, $ArgumentList,
$DebugPreference, $DebugPreference
$automation
) )
if ($automation = $true) { # Create a PowerShell instance
& $ScriptBlock @ArgumentList @DebugPreference $script:powershell = [powershell]::Create()
} else {
# Create a PowerShell instance
$script:powershell = [powershell]::Create()
# Add Scriptblock and Arguments to runspace # Add Scriptblock and Arguments to runspace
$script:powershell.AddScript($ScriptBlock) $script:powershell.AddScript($ScriptBlock)
$script:powershell.AddArgument($ArgumentList) $script:powershell.AddArgument($ArgumentList)
$script:powershell.AddArgument($DebugPreference) # Pass DebugPreference to the script block $script:powershell.AddArgument($DebugPreference) # Pass DebugPreference to the script block
$script:powershell.RunspacePool = $sync.runspace $script:powershell.RunspacePool = $sync.runspace
# Execute the RunspacePool # Execute the RunspacePool
$script:handle = $script:powershell.BeginInvoke() $script:handle = $script:powershell.BeginInvoke()
# Clean up the RunspacePool threads when they are complete, and invoke the garbage collector to clean up the memory # Clean up the RunspacePool threads when they are complete, and invoke the garbage collector to clean up the memory
if ($script:handle.IsCompleted) { if ($script:handle.IsCompleted) {
$script:powershell.EndInvoke($script:handle) $script:powershell.EndInvoke($script:handle)
$script:powershell.Dispose() $script:powershell.Dispose()
$sync.runspace.Dispose() $sync.runspace.Dispose()
$sync.runspace.Close() $sync.runspace.Close()
[System.GC]::Collect() [System.GC]::Collect()
}
} }
} }

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

View File

@ -145,61 +145,13 @@ Invoke-WPFRunspace -ScriptBlock {
} | Out-Null } | Out-Null
#===========================================================================
# Print Logo into Console
#===========================================================================
Invoke-WPFFormVariables
#===========================================================================
# Run Automation
#===========================================================================
if ($PARAM_CONFIG) {
if ($PARAM_RUN) {
$installConfig = Get-Content $PARAM_CONFIG -Raw | ConvertFrom-Json
if ($installConfig.WPFInstall) {
write-host "Installing Programs"
# 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
}
if ($installConfig.WPFTweaks) {
write-host "Running Tweaks"
Invoke-WPFtweaksbutton -TweaksConfig $installConfig.WPFTweaks
}
if ($installConfig.WPFFeature) {
write-host "Installing Features"
Invoke-WPFFeatureInstall -FeatureConfig $installConfig.WPFFeature
}
} else {
Invoke-WPFImpex -type "import" -Config $PARAM_CONFIG
}
}
#=========================================================================== #===========================================================================
# Setup and Show the Form # Setup and Show the Form
#=========================================================================== #===========================================================================
# Print the logo
Invoke-WPFFormVariables
# Progress bar in taskbaritem > Set-WinUtilProgressbar # Progress bar in taskbaritem > Set-WinUtilProgressbar
$sync["Form"].TaskbarItemInfo = New-Object System.Windows.Shell.TaskbarItemInfo $sync["Form"].TaskbarItemInfo = New-Object System.Windows.Shell.TaskbarItemInfo
Set-WinUtilTaskbaritem -state "None" Set-WinUtilTaskbaritem -state "None"
@ -366,6 +318,49 @@ Add-Type @"
Invoke-WPFTab "WPFTab1BT" Invoke-WPFTab "WPFTab1BT"
$sync["Form"].Focus() $sync["Form"].Focus()
# maybe this is not the best place to load and execute config file?
# maybe community can help?
if ($PARAM_CONFIG) {
if ($PARAM_RUN) {
$installConfig = Get-Content $PARAM_CONFIG -Raw | ConvertFrom-Json
if ($installConfig.WPFTweaks) {
write-host "Running Tweaks"
Invoke-WPFtweaksbutton -TweaksConfig $installConfig.WPFTweaks
}
if ($installConfig.WPFFeature) {
write-host "Installing Features"
Invoke-WPFFeatureInstall -FeatureConfig $installConfig.WPFFeature
}
if ($installConfig.WPFInstall) {
write-host "Installing Programs"
# 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
}
} else {
Invoke-WPFImpex -type "import" -Config $PARAM_CONFIG
}
}
}) })
# Load Checkboxes and Labels outside of the Filter function only once on startup for performance reasons # Load Checkboxes and Labels outside of the Filter function only once on startup for performance reasons
@ -540,8 +535,5 @@ $sync["SponsorMenuItem"].Add_Click({
$Height = $sync.configs.themes.$ctttheme.CustomDialogHeight $Height = $sync.configs.themes.$ctttheme.CustomDialogHeight
Show-CustomDialog -Message $authorInfo -Width $Width -Height $Height -FontSize $FontSize -HeaderFontSize $HeaderFontSize -IconSize $IconSize -EnableScroll $true Show-CustomDialog -Message $authorInfo -Width $Width -Height $Height -FontSize $FontSize -HeaderFontSize $HeaderFontSize -IconSize $IconSize -EnableScroll $true
}) })
$sync["Form"].ShowDialog() | out-null
if (!$PARAM_RUN) { Stop-Transcript
$sync["Form"].ShowDialog() | out-null
Stop-Transcript
}