mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-12-22 14:01:31 -06:00
a56aeefc7f
* Remove Edge from Start Menu and Desktop (#898) * Update edgeremoval.bat * Fix Edge not being deleted from Desktop * Compile Winutil * fix yubikey users service * Compile Winutil * AJRouter and Kiosk Disable * Compile Winutil * TermService enable This service will hang when applying tweaks. Changing to Auto from Manual * Compile Winutil * Fix bug with Telemetry Tweak services should NOT be tweaked here * dupe tweak removal * hibernate off and delete * Compile Winutil * Cleaning Windows Update Folder * Compile Winutil * GameDVR Fix * Compile Winutil * Fixed consistency in variable names and values inside edgeremoval.bat (#902) * Compile Winutil * add spdx license * Compile Winutil * Updated Dark mode check (#904) * Compile Winutil * Update Dark Mode Check updated the theme check to use the existing function * Description update Updated Description --------- Co-authored-by: DeveloperDurp <DeveloperDurp@users.noreply.github.com> * Compile Winutil * fixes #569 * Compile Winutil * Added Bing Search toggle plus some support functions (#908) * Compile Winutil * Update winget.ps1 * Compile Winutil * Fix Winget Install * Compile Winutil * Update Install-WinUtilWinget.ps1 * Compile Winutil * Update Install-WinUtilWinget.ps1 * Compile Winutil * Update Install-WinUtilWinget.ps1 * Compile Winutil * Winget fixes * Compile Winutil --------- Co-authored-by: Antun Nitraj <antnitraj@gmail.com> Co-authored-by: ChrisTitusTech <ChrisTitusTech@users.noreply.github.com> Co-authored-by: DeveloperDurp <developerdurp@durp.info> Co-authored-by: DeveloperDurp <DeveloperDurp@users.noreply.github.com>
151 lines
5.1 KiB
PowerShell
151 lines
5.1 KiB
PowerShell
# SPDX-License-Identifier: MIT
|
|
|
|
#Configure max thread count for RunspacePool.
|
|
$maxthreads = [int]$env:NUMBER_OF_PROCESSORS
|
|
|
|
#Create a new session state for parsing variables ie hashtable into our runspace.
|
|
$hashVars = New-object System.Management.Automation.Runspaces.SessionStateVariableEntry -ArgumentList 'sync',$sync,$Null
|
|
$InitialSessionState = [System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault()
|
|
|
|
#Add the variable to the RunspacePool sessionstate
|
|
$InitialSessionState.Variables.Add($hashVars)
|
|
|
|
#Add functions
|
|
$functions = Get-ChildItem function:\ | Where-Object {$_.name -like "*winutil*" -or $_.name -like "*WPF*"}
|
|
foreach ($function in $functions){
|
|
$functionDefinition = Get-Content function:\$($function.name)
|
|
$functionEntry = New-Object System.Management.Automation.Runspaces.SessionStateFunctionEntry -ArgumentList $($function.name), $functionDefinition
|
|
|
|
# And add it to the iss object
|
|
$initialSessionState.Commands.Add($functionEntry)
|
|
}
|
|
|
|
#Create our runspace pool. We are entering three parameters here min thread count, max thread count and host machine of where these runspaces should be made.
|
|
$sync.runspace = [runspacefactory]::CreateRunspacePool(1,$maxthreads,$InitialSessionState, $Host)
|
|
|
|
#Open a RunspacePool instance.
|
|
$sync.runspace.Open()
|
|
|
|
#region exception classes
|
|
|
|
class WingetFailedInstall : Exception {
|
|
[string] $additionalData
|
|
|
|
WingetFailedInstall($Message) : base($Message) {}
|
|
}
|
|
|
|
class ChocoFailedInstall : Exception {
|
|
[string] $additionalData
|
|
|
|
ChocoFailedInstall($Message) : base($Message) {}
|
|
}
|
|
|
|
class GenericException : Exception {
|
|
[string] $additionalData
|
|
|
|
GenericException($Message) : base($Message) {}
|
|
}
|
|
|
|
#endregion exception classes
|
|
|
|
$inputXML = $inputXML -replace 'mc:Ignorable="d"', '' -replace "x:N", 'N' -replace '^<Win.*', '<Window'
|
|
|
|
if ((Get-WinUtilToggleStatus WPFToggleDarkMode) -eq $True){
|
|
$ctttheme = 'Matrix'
|
|
}
|
|
Else{
|
|
$ctttheme = 'Classic'
|
|
}
|
|
|
|
$inputXML = Set-WinUtilUITheme -inputXML $inputXML -themeName $ctttheme
|
|
|
|
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
|
|
[xml]$XAML = $inputXML
|
|
#Read XAML
|
|
|
|
$reader = (New-Object System.Xml.XmlNodeReader $xaml)
|
|
try { $sync["Form"] = [Windows.Markup.XamlReader]::Load( $reader ) }
|
|
catch [System.Management.Automation.MethodInvocationException] {
|
|
Write-Warning "We ran into a problem with the XAML code. Check the syntax for this control..."
|
|
Write-Host $error[0].Exception.Message -ForegroundColor Red
|
|
If ($error[0].Exception.Message -like "*button*") {
|
|
write-warning "Ensure your <button in the `$inputXML does NOT have a Click=ButtonClick property. PS can't handle this`n`n`n`n"
|
|
}
|
|
}
|
|
catch {
|
|
# If it broke some other way <img draggable="false" role="img" class="emoji" alt="😀" src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/svg/1f600.svg">
|
|
Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."
|
|
}
|
|
|
|
#===========================================================================
|
|
# Store Form Objects In PowerShell
|
|
#===========================================================================
|
|
|
|
$xaml.SelectNodes("//*[@Name]") | ForEach-Object {$sync["$("$($psitem.Name)")"] = $sync["Form"].FindName($psitem.Name)}
|
|
|
|
$sync.keys | ForEach-Object {
|
|
if($sync.$psitem){
|
|
if($($sync["$psitem"].GetType() | Select-Object -ExpandProperty Name) -eq "Button"){
|
|
$sync["$psitem"].Add_Click({
|
|
[System.Object]$Sender = $args[0]
|
|
Invoke-WPFButton $Sender.name
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
$sync.keys | ForEach-Object {
|
|
if($sync.$psitem){
|
|
if(
|
|
$($sync["$psitem"].GetType() | Select-Object -ExpandProperty Name) -eq "CheckBox" `
|
|
-and $sync["$psitem"].Name -like "WPFToggle*"
|
|
){
|
|
$sync["$psitem"].IsChecked = Get-WinUtilToggleStatus $sync["$psitem"].Name
|
|
|
|
$sync["$psitem"].Add_Click({
|
|
[System.Object]$Sender = $args[0]
|
|
Invoke-WPFToggle $Sender.name
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
#===========================================================================
|
|
# Setup background config
|
|
#===========================================================================
|
|
|
|
#Load information in the background
|
|
Invoke-WPFRunspace -ScriptBlock {
|
|
$sync.ConfigLoaded = $False
|
|
|
|
$sync.ComputerInfo = Get-ComputerInfo
|
|
|
|
$sync.ConfigLoaded = $True
|
|
} | Out-Null
|
|
|
|
#===========================================================================
|
|
# Shows the form
|
|
#===========================================================================
|
|
|
|
Invoke-WPFFormVariables
|
|
|
|
try{
|
|
Install-WinUtilChoco
|
|
}
|
|
Catch [ChocoFailedInstall]{
|
|
Write-Host "==========================================="
|
|
Write-Host "-- Chocolatey failed to install ---"
|
|
Write-Host "==========================================="
|
|
}
|
|
$sync["Form"].title = $sync["Form"].title + " " + $sync.version
|
|
$sync["Form"].Add_Closing({
|
|
$sync.runspace.Dispose()
|
|
$sync.runspace.Close()
|
|
[System.GC]::Collect()
|
|
})
|
|
|
|
$sync["Form"].ShowDialog() | out-null
|
|
Stop-Transcript
|