winutil/scripts/main.ps1
Chris Titus 68927444b6
05 16 23 testing (#881)
* Fix power profile (#766) (#767)

* Fix power profile query

* fix syntax

* fix

* Update Invoke-WPFUltimatePerformance.ps1

* Update winutil.ps1

* power profile fix

* add reset network with netsh (#768)

* add verbose logon (#773)

* add verbose logon

Enable or disable verbose sign in status messages. Verbose status messages may be helpful when you are troubleshooting slow startup, shutdown, logon, or logoff behavior.

* compress-into-one-checkbox

* compile winutil.ps1

* Update README.md (#774)

* Update README.md

* Update README.md

* Adding 3 programs to the install tab (#789)

* Prism Launcher - Custom FOSS minecraft launcher

* Gsudo - Command line program that allows you to elevate a program as admin.

* WingetUI - Graphical front end for winget, chochlatey and scoop

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

* add undoscript feature + implement it on every tweaks (#776)

* add undoscript feature + implement it on right click menu

- add undoscript feature
- add undo for right click menu to go back to windows 11 default right click menu by implementing undoscript feature

* undoscript for WPFMiscTweaksDisplay

* undoscript for WPFEssTweaksRemoveEdge

* undoscript for WPFEssTweaksRemoveCortana

* undoscript for WPFEssTweaksStorage

* Update Invoke-WinUtilTweaks.ps1

thanks to @DeveloperDurp

* compile

* Fix packages name (#815)

* fix-winrar_package_name

* fix-vc++_package_name

* fix #687

* implement check for admin (#818)

check if script is running as admin or not and if not then it attempt to relaunch with admin privilege.

* add "NetFx4Extended-ASPNET45" under dotnet features (#831)

* add-docker-desktop (#834)

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

* Fix 'Get Installed' for multiple-dependency apps (#835)

* Update winutil.ps1 (#858)

fix typos

* Fixing AcceptEULA on Autologin

* Program Update: Replace Origin with EA App #544 (#875)

* New Theme support, initial functions.  (#878)

* Fix power profile (#766)

* Fix power profile query

* fix syntax

* fix

* Update Invoke-WPFUltimatePerformance.ps1

* Update winutil.ps1

* power profile fix

* Adding Nomacs Opensource free and fast Image viewer

* Adding theme support

Later when this is tested well, we can do one of 2 things.
1. Pass theme on a command line so people with bad vision will have an option to have a better (more visible theme)
2. Create a drop down with themes and a save button which would save it ti some local config file

* Fix for the compile script

---------

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

* Dark Mode Enable

* auto detect theme

---------

Co-authored-by: Padsala Tushal <57517785+padsalatushal@users.noreply.github.com>
Co-authored-by: Taken <taken@mairimashita.org>
Co-authored-by: Yurin Doctrine <bayramyurgidenn@gmail.com>
Co-authored-by: Aaron <54756786+AaronVickers@users.noreply.github.com>
Co-authored-by: Sahil Jassal <56100355+shljsl75891@users.noreply.github.com>
Co-authored-by: supplefrog <78985073+supplefrog@users.noreply.github.com>
Co-authored-by: KonTy <9524513+KonTy@users.noreply.github.com>
2023-07-13 15:46:00 -05:00

137 lines
5.0 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'
$app = (Get-ItemProperty -path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize').AppsUseLightTheme
$system = (Get-ItemProperty -path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize').SystemUsesLightTheme
if($app -eq 0 -and $system -eq 0){
$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 &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