# SPDX-License-Identifier: MIT # Set the maximum number of threads for the RunspacePool to the number of threads on the machine $maxthreads = [int]$env:NUMBER_OF_PROCESSORS # Create a new session state for parsing variables 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 session state $InitialSessionState.Variables.Add($hashVars) # Get every private function and add them to the session state $functions = (Get-ChildItem function:\).where{$_.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 $initialSessionState.Commands.Add($functionEntry) } # Create the runspace pool $sync.runspace = [runspacefactory]::CreateRunspacePool( 1, # Minimum thread count $maxthreads, # Maximum thread count $InitialSessionState, # Initial session state $Host # Machine to create runspaces on ) # Open the RunspacePool instance $sync.runspace.Open() # Create classes for different exceptions 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) {} } $inputXML = $inputXML -replace 'mc:Ignorable="d"', '' -replace "x:N", 'N' -replace '^@christitustech Runspace : @DeveloperDurp MicroWin : @KonTy GitHub : ChrisTitusTech/winutil Version : $($sync.version) "@ $FontSize = $sync.configs.themes.$ctttheme.CustomDialogFontSize $HeaderFontSize = $sync.configs.themes.$ctttheme.CustomDialogFontSizeHeader $IconSize = $sync.configs.themes.$ctttheme.CustomDialogIconSize $Width = $sync.configs.themes.$ctttheme.CustomDialogWidth $Height = $sync.configs.themes.$ctttheme.CustomDialogHeight Show-CustomDialog -Message $authorInfo -Width $Width -Height $Height -FontSize $FontSize -HeaderFontSize $HeaderFontSize -IconSize $IconSize }) $sync["SponsorMenuItem"].Add_Click({ # Handle Export menu item click Write-Debug "Sponsors clicked" $sync["SettingsPopup"].IsOpen = $false $authorInfo = @" Current sponsors for ChrisTitusTech: "@ $authorInfo += "`n" try { # Call the function to get the sponsors $sponsors = Invoke-WinUtilSponsors # Append the sponsors to the authorInfo $sponsors | ForEach-Object { $authorInfo += "$_`n" } } catch { $authorInfo += "An error occurred while fetching or processing the sponsors: $_`n" } $FontSize = $sync.configs.themes.$ctttheme.CustomDialogFontSize $HeaderFontSize = $sync.configs.themes.$ctttheme.CustomDialogFontSizeHeader $IconSize = $sync.configs.themes.$ctttheme.CustomDialogIconSize $Width = $sync.configs.themes.$ctttheme.CustomDialogWidth $Height = $sync.configs.themes.$ctttheme.CustomDialogHeight Show-CustomDialog -Message $authorInfo -Width $Width -Height $Height -FontSize $FontSize -HeaderFontSize $HeaderFontSize -IconSize $IconSize -EnableScroll $true }) $sync["Form"].ShowDialog() | out-null Stop-Transcript