winutil/scripts/main.ps1
Chris Titus 075f2e9a50
Test 03 2023 (#726)
* Update inputXML.xaml

* Compile Winutil

* Update main.ps1 (#641)

Fix DarkMode

* Compile Winutil

* Compile Winutil

* Compile Winutil

* Update tweaks.json

* fix hovertime

* shortcut (#643)

add ability to create a shortcut to invoke winutil more easily

* Compile Winutil

* Tweaks Check (#646)

* Tweaks Check

Added check for no checked tweaks plus formatting

* more formating fixing

* Compile Winutil

* [ooshutup10] Fixed link to ooshutup10 settings file (#665)

* Compile Winutil

* Features Migrated to config and runspaces (#667)

* Compile Winutil

* Document Calendar Disable/Enable

Check Disable Notification and click undo tweaks to re-enable calendar

* Compile Winutil

* Update Edge_Removal.bat

* Update Edge_Removal.bat (#660)

* garbage commit - read system

Trying to read current system registry values state and do a checkbox for enabled or disabled values

* Compile Winutil

* Add Ubisoft Connect & WinRAR as install options. (#678)

* Compile Winutil

* adding the code from asheroto to install winget (#684)

* adding the code from asheroto to get winget

with Server versions of Windows, that come without winget , the script seems unable to install it and then refuses to install any programs. so by adding two lines of code (hopefully) you can include the installation of winget and then fulfill the requirement and let the program run and do all the cool things

* instaling winget from asheroto

so the script will check if winget is installed on server and LTSC versions of Windows.  and tries to install it, when for some reason it can't, then a condition on the code gets fulfilled and the function breaks, this code from the asheroto repo should, (hopefully) make it so winget can get installed and the condition is never met, therefore allowing it the script to continue

* Compile Winutil

* Add Neovim and Node Version Manager (#691)

* Compile Winutil

* Preload Winget and tweaks with already installed (#682)

* winget

* updated runspaces and winget to update gui outside of main thread

* registry check for tweaks

* add impex to winget

* add uninstall button

* tweaks done

* update tests

---------

Co-authored-by: Chris Titus <contact@christitus.com>

* Compile Winutil

* feat: add postman into developement (#695)

Co-authored-by: Chris Titus <contact@christitus.com>

* Update inputXML.xaml (#701)

Some of the items were missing WPF in the name

* Compile Winutil

* Split up AllowGameDVR to fix breaking Xbox Game Bar (#692)

* Split up AllowGameDVR to fix breaking Xbox Game Bar

* Undo changes to winutil

* Compile Winutil

* Removed Atom due to it having been sunsetted (#711)

Co-authored-by: Chris Titus <contact@christitus.com>

* Add application GeForce NOW to Applications/Games (#724)

* Compile Winutil

* Fix syntax and typo

* Compile Winutil

* Fixing Original Service Types

* Compile Winutil

* Update inputXML.xaml (#725)

Fix typo as upgrade selection will upgrade all

* Compile Winutil

---------

Co-authored-by: ChrisTitusTech <ChrisTitusTech@users.noreply.github.com>
Co-authored-by: DeveloperDurp <developerdurp@durp.info>
Co-authored-by: jokerwrld999 <47574931+jokerwrld999@users.noreply.github.com>
Co-authored-by: Raf <69535896+Rafee-M@users.noreply.github.com>
Co-authored-by: Jack Boecker <boeckerjack@protonmail.com>
Co-authored-by: migno_chrono <75509204+mignochrono@users.noreply.github.com>
Co-authored-by: Umair Raza <52033975+umairraza96@users.noreply.github.com>
Co-authored-by: dreamsyntax <dreamsyntax@gmail.com>
Co-authored-by: Daniel <74148862+Danulal@users.noreply.github.com>
Co-authored-by: tomgrice <tomgrice@gmail.com>
2023-05-09 13:14:27 -05:00

127 lines
4.6 KiB
PowerShell

#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'
[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 &lt;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["WPFToggleDarkMode"].Add_Click({
Invoke-WPFDarkMode -DarkMoveEnabled $(Get-WinUtilDarkMode)
})
$sync["WPFToggleDarkMode"].IsChecked = Get-WinUtilDarkMode
#===========================================================================
# 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