Code Formatting of Repo - Add Preprocessing to Compilation Process - Introduction of Dev/Build Tools to WinUtil (Although very simple at the moment) (#2383)

* Replace Tabs with Spaces to follow the conventions

* Add Preprocessing in Compiler

* Compile from Anywhere you want - Running 'Compile.ps1' Works in any directory you call it from

* Code Formatting Changes

* Result of Preprocessing Step in 'Compile.ps1' Script - Remove Trailing Whitespace Characters

* Make Preprocessing more advanced

* Move Preprocessing to a separate script file

* Make Self Modification impossible for 'tools/Do-PreProcessing.ps1' Script - Make the workingdir same as sync.PSScriptRoot for consistency

* Revert commit b5dffd671f

* Patched a Bug of some Excluded Files not actually get excluded in 'Get-ChildItem' PS Cmdlet

* Update Replace Regex for Code Formatting in 'Do-PreProcessing' Script Tool

* Rename 'Do-PreProcessing' to 'Invoke-Preprocessing' - Update some Comments

* Make 'Invoke-Preprocessing' Modular - Update RegEx to handle more cases - Update Documentation - Add Validations & Useful feedback upon error

* Replace Tabs with Spaces to follow the conventions - 'applications.json' File

* Code Formatting Changes - 'Copy-Files' Private Function

* Update Replace Regex for Code Formatting in 'Invoke-Preprocessing' Script Tool

* Replace Tabs with Spaces to follow the conventions - Make 'ExcludedFiles' validation step check all filepaths before finally checking if any has failed

* Result of 'Invoke-Preprocessing' Script

* Update Replace Regex for Code Formatting in 'Invoke-Preprocessing' Script Tool
This commit is contained in:
Mr.k
2024-08-06 23:35:17 +03:00
committed by GitHub
parent 3b2af3fa2b
commit 3903eaaa24
94 changed files with 4523 additions and 4623 deletions

View File

@ -57,9 +57,9 @@ function ConvertTo-Icon {
#>
param(
[Parameter(Mandatory=$true, position=0)]
[Parameter(Mandatory, position=0)]
[string]$bitmapPath,
[Parameter(Mandatory=$true, position=1)]
[Parameter(Mandatory, position=1)]
[string]$iconPath,
[Parameter(position=2)]
[bool]$overrideIconFile = $true
@ -86,8 +86,7 @@ function ConvertTo-Icon {
$icon.Save($file)
$file.Close()
$icon.Dispose()
}
else {
} else {
throw [System.IO.FileNotFoundException] "[ConvertTo-Icon] The provided bitmap File Path is not found at '$bitmapPath'."
}
}

View File

@ -10,39 +10,34 @@ function Copy-Files {
#>
param (
[string] $Path,
[string] $Destination,
[switch] $Recurse = $false,
[switch] $Force = $false
[string]$Path,
[string]$Destination,
[switch]$Recurse = $false,
[switch]$Force = $false
)
try {
$files = Get-ChildItem -Path $path -Recurse:$recurse
Write-Host "Copy $($files.Count)(s) from $path to $destination"
$files = Get-ChildItem -Path $path -Recurse:$recurse
Write-Host "Copy $($files.Count)(s) from $path to $destination"
foreach($file in $files)
{
foreach ($file in $files) {
$status = "Copy files {0} on {1}: {2}" -f $counter, $files.Count, $file.Name
Write-Progress -Activity "Copy Windows files" -Status $status -PercentComplete ($counter++/$files.count*100)
$restpath = $file.FullName -Replace $path, ''
if($file.PSIsContainer -eq $true)
{
if ($file.PSIsContainer -eq $true) {
Write-Debug "Creating $($destination + $restpath)"
New-Item ($destination+$restpath) -Force:$force -Type Directory -ErrorAction SilentlyContinue
}
else
{
} else {
Write-Debug "Copy from $($file.FullName) to $($destination+$restpath)"
Copy-Item $file.FullName ($destination+$restpath) -ErrorAction SilentlyContinue -Force:$force
Set-ItemProperty -Path ($destination+$restpath) -Name IsReadOnly -Value $false
}
}
Write-Progress -Activity "Copy Windows files" -Status "Ready" -Completed
}
Catch{
} catch {
Write-Warning "Unable to Copy all the files due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}
}
}

View File

@ -31,4 +31,4 @@ function Get-LocalizedYesNo {
# Return the array of characters
return $charactersArray
}
}

View File

@ -1,15 +1,17 @@
function Get-Oscdimg {
<#
.DESCRIPTION
This function will download oscdimg file from github Release folders and put it into env:temp folder
.EXAMPLE
Get-Oscdimg
#>
param( [Parameter(Mandatory=$true)]
param(
[Parameter(Mandatory, position=0)]
[string]$oscdimgPath
)
$oscdimgPath = "$env:TEMP\oscdimg.exe"
$downloadUrl = "https://github.com/ChrisTitusTech/winutil/raw/main/releases/oscdimg.exe"
Invoke-RestMethod -Uri $downloadUrl -OutFile $oscdimgPath

View File

@ -1,19 +1,23 @@
function Get-TabXaml {
<#
.SYNOPSIS
Generates XAML for a tab in the WinUtil GUI
This function is used to generate the XAML for the applications tab in the WinUtil GUI
It takes the tabname and the number of columns to display the applications in as input and returns the XAML for the tab as output
.PARAMETER tabname
The name of the tab to generate XAML for
Note: the 'tabname' parameter must equal one of the json files found in $sync.configs variable
Otherwise, it'll throw an exception
.PARAMETER columncount
The number of columns to display the applications in, default is 0
.OUTPUTS
The XAML for the tab
.EXAMPLE
Get-TabXaml "applications" 3
.SYNOPSIS
Generates XAML for a tab in the WinUtil GUI
This function is used to generate the XAML for the applications tab in the WinUtil GUI
It takes the tabname and the number of columns to display the applications in as input and returns the XAML for the tab as output
.PARAMETER tabname
The name of the tab to generate XAML for
Note: the 'tabname' parameter must equal one of the json files found in $sync.configs variable
Otherwise, it'll throw an exception
.PARAMETER columncount
The number of columns to display the applications in, default is 0
.OUTPUTS
The XAML for the tab
.EXAMPLE
Get-TabXaml "applications" 3
#>
@ -115,7 +119,7 @@ function Get-TabXaml {
}
# Dot-source the Get-WPFObjectName function
. .\functions\private\Get-WPFObjectName
. "$($sync.PSScriptRoot)\functions\private\Get-WPFObjectName.ps1"
$categorycontent = $($category -replace '^.__', '')
$categoryname = Get-WPFObjectName -type "Label" -name $categorycontent
@ -188,7 +192,7 @@ function Get-TabXaml {
# else it is a checkbox
default {
$checkedStatus = If ($appInfo.Checked -eq $null) {""} Else {" IsChecked=""$($appInfo.Checked)"""}
$checkedStatus = If ($appInfo.Checked -eq $null) {""} else {" IsChecked=""$($appInfo.Checked)"""}
if ($appInfo.Link -eq $null) {
$blockXml += $precal_indent +
"<CheckBox Name=""$($appInfo.Name)"" Content=""$($appInfo.Content)""$($checkedStatus) Margin=""5,0""" + " " +

View File

@ -1,27 +1,31 @@
function Get-WPFObjectName {
<#
.SYNOPSIS
This is a helper function that generates an objectname with the prefix WPF that can be used as a Powershell Variable after compilation.
To achieve this, all characters that are not a-z, A-Z or 0-9 are simply removed from the name.
.PARAMETER type
The type of object for which the name should be generated. (e.g. Label, Button, CheckBox...)
.PARAMETER name
The name or description to be used for the object. (invalid characters are removed)
.OUTPUTS
A string that can be used as a object/variable name in powershell.
For example: WPFLabelMicrosoftTools
<#
.SYNOPSIS
This is a helper function that generates an objectname with the prefix WPF that can be used as a Powershell Variable after compilation.
To achieve this, all characters that are not a-z, A-Z or 0-9 are simply removed from the name.
.EXAMPLE
Get-WPFObjectName -type Label -name "Microsoft Tools"
.PARAMETER type
The type of object for which the name should be generated. (e.g. Label, Button, CheckBox...)
.PARAMETER name
The name or description to be used for the object. (invalid characters are removed)
.OUTPUTS
A string that can be used as a object/variable name in powershell.
For example: WPFLabelMicrosoftTools
.EXAMPLE
Get-WPFObjectName -type Label -name "Microsoft Tools"
#>
param( [Parameter(Mandatory=$true)]
$type,
$name
)
param(
[Parameter(Mandatory, position=0)]
[string]$type,
$Output = $("WPF"+$type+$name) -replace '[^a-zA-Z0-9]', ''
[Parameter(position=1)]
[string]$name
)
return $Output
}
$Output = $("WPF"+$type+$name) -replace '[^a-zA-Z0-9]', ''
return $Output
}

View File

@ -14,11 +14,11 @@ function Get-WinUtilInstallerProcess {
param($Process)
if ($Null -eq $Process){
if ($Null -eq $Process) {
return $false
}
if (Get-Process -Id $Process.Id -ErrorAction SilentlyContinue){
if (Get-Process -Id $Process.Id -ErrorAction SilentlyContinue) {
return $true
}
return $false
}
}

View File

@ -13,125 +13,112 @@ Function Get-WinUtilToggleStatus {
#>
Param($ToggleSwitch)
if($ToggleSwitch -eq "WPFToggleDarkMode"){
if($ToggleSwitch -eq "WPFToggleDarkMode") {
$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){
if($app -eq 0 -and $system -eq 0) {
return $true
}
else{
} else {
return $false
}
}
if($ToggleSwitch -eq "WPFToggleBingSearch"){
if($ToggleSwitch -eq "WPFToggleBingSearch") {
$bingsearch = (Get-ItemProperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Search').BingSearchEnabled
if($bingsearch -eq 0){
if($bingsearch -eq 0) {
return $false
}
else{
} else {
return $true
}
}
if($ToggleSwitch -eq "WPFToggleNumLock"){
if($ToggleSwitch -eq "WPFToggleNumLock") {
$numlockvalue = (Get-ItemProperty -path 'HKCU:\Control Panel\Keyboard').InitialKeyboardIndicators
if($numlockvalue -eq 2){
if($numlockvalue -eq 2) {
return $true
}
else{
} else {
return $false
}
}
if($ToggleSwitch -eq "WPFToggleVerboseLogon"){
if($ToggleSwitch -eq "WPFToggleVerboseLogon") {
$VerboseStatusvalue = (Get-ItemProperty -path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System').VerboseStatus
if($VerboseStatusvalue -eq 1){
if($VerboseStatusvalue -eq 1) {
return $true
}
else{
} else {
return $false
}
}
if($ToggleSwitch -eq "WPFToggleShowExt"){
if($ToggleSwitch -eq "WPFToggleShowExt") {
$hideextvalue = (Get-ItemProperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced').HideFileExt
if($hideextvalue -eq 0){
if($hideextvalue -eq 0) {
return $true
}
else{
} else {
return $false
}
}
if($ToggleSwitch -eq "WPFToggleSnapWindow"){
if($ToggleSwitch -eq "WPFToggleSnapWindow") {
$hidesnap = (Get-ItemProperty -path 'HKCU:\Control Panel\Desktop').WindowArrangementActive
if($hidesnap -eq 0){
if($hidesnap -eq 0) {
return $false
}
else{
} else {
return $true
}
}
if($ToggleSwitch -eq "WPFToggleSnapFlyout"){
if($ToggleSwitch -eq "WPFToggleSnapFlyout") {
$hidesnap = (Get-ItemProperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced').EnableSnapAssistFlyout
if($hidesnap -eq 0){
if($hidesnap -eq 0) {
return $false
}
else{
} else {
return $true
}
}
if($ToggleSwitch -eq "WPFToggleSnapSuggestion"){
if($ToggleSwitch -eq "WPFToggleSnapSuggestion") {
$hidesnap = (Get-ItemProperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced').SnapAssist
if($hidesnap -eq 0){
if($hidesnap -eq 0) {
return $false
}
else{
} else {
return $true
}
}
if($ToggleSwitch -eq "WPFToggleMouseAcceleration"){
if($ToggleSwitch -eq "WPFToggleMouseAcceleration") {
$MouseSpeed = (Get-ItemProperty -path 'HKCU:\Control Panel\Mouse').MouseSpeed
$MouseThreshold1 = (Get-ItemProperty -path 'HKCU:\Control Panel\Mouse').MouseThreshold1
$MouseThreshold2 = (Get-ItemProperty -path 'HKCU:\Control Panel\Mouse').MouseThreshold2
if($MouseSpeed -eq 1 -and $MouseThreshold1 -eq 6 -and $MouseThreshold2 -eq 10){
if($MouseSpeed -eq 1 -and $MouseThreshold1 -eq 6 -and $MouseThreshold2 -eq 10) {
return $true
}
else{
} else {
return $false
}
}
if($ToggleSwitch -eq "WPFToggleTaskbarSearch"){
if($ToggleSwitch -eq "WPFToggleTaskbarSearch") {
$SearchButton = (Get-ItemProperty -path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search").SearchboxTaskbarMode
if($SearchButton -eq 0){
if($SearchButton -eq 0) {
return $false
}
else{
} else {
return $true
}
}
if ($ToggleSwitch -eq "WPFToggleStickyKeys") {
$StickyKeys = (Get-ItemProperty -path 'HKCU:\Control Panel\Accessibility\StickyKeys').Flags
if($StickyKeys -eq 58){
if($StickyKeys -eq 58) {
return $false
}
else{
} else {
return $true
}
}
if ($ToggleSwitch -eq "WPFToggleTaskView") {
$TaskView = (Get-ItemProperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced').ShowTaskViewButton
if($TaskView -eq 0){
if($TaskView -eq 0) {
return $false
}
else{
} else {
return $true
}
}
if ($ToggleSwitch -eq "WPFToggleHiddenFiles") {
$HiddenFiles = (Get-ItemProperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced').Hidden
if($HiddenFiles -eq 0){
if($HiddenFiles -eq 0) {
return $false
}
else{
} else {
return $true
}
}
@ -140,8 +127,7 @@ Function Get-WinUtilToggleStatus {
$TaskbarWidgets = (Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced").TaskBarDa
if($TaskbarWidgets -eq 0) {
return $false
}
else{
} else {
return $true
}
}
@ -149,8 +135,7 @@ Function Get-WinUtilToggleStatus {
$TaskbarAlignment = (Get-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced").TaskbarAl
if($TaskbarAlignment -eq 0) {
return $false
}
else{
} else {
return $true
}
}
@ -158,8 +143,7 @@ Function Get-WinUtilToggleStatus {
$DetailedBSoD = (Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl').DisplayParameters
if($DetailedBSoD -eq 0) {
return $false
}
else{
} else {
return $true
}
}

View File

@ -14,13 +14,12 @@ function Get-WinUtilVariables {
$keys = ($sync.keys).where{ $_ -like "WPF*" }
if ($Type) {
$output = $keys | ForEach-Object {
Try {
try {
$objType = $sync["$psitem"].GetType().Name
if ($Type -contains $objType) {
Write-Output $psitem
}
}
Catch {
} catch {
<#I am here so errors don't get outputted for a couple variables that don't have the .GetType() attribute#>
}
}

View File

@ -8,7 +8,7 @@ function Get-WinUtilWingetLatest {
# Invoke-WebRequest is notoriously slow when the byte progress is displayed. The following lines disable the progress bar and reset them at the end of the function
$PreviousProgressPreference = $ProgressPreference
$ProgressPreference = "silentlyContinue"
Try{
try {
# Grabs the latest release of Winget from the Github API for the install process.
$response = Invoke-RestMethod -Uri "https://api.github.com/repos/microsoft/Winget-cli/releases/latest" -Method Get -ErrorAction Stop
$latestVersion = $response.tag_name #Stores version number of latest release.
@ -19,8 +19,7 @@ function Get-WinUtilWingetLatest {
Invoke-WebRequest -Uri $licenseWingetUrl -OutFile $ENV:TEMP\License1.xml
# The only pain is that the msixbundle for winget-cli is 246MB. In some situations this can take a bit, with slower connections.
Invoke-WebRequest -Uri $assetUrl -OutFile $ENV:TEMP\Microsoft.DesktopAppInstaller.msixbundle
}
Catch{
} catch {
throw [WingetFailedInstall]::new('Failed to get latest Winget release and license')
}
$ProgressPreference = $PreviousProgressPreference

View File

@ -17,13 +17,12 @@ function Get-WinUtilWingetPrerequisites {
$fileUIXaml = "https://github.com/microsoft/microsoft-ui-xaml/releases/download/v${versionUIXamlPatch}/Microsoft.UI.Xaml.${versionUIXamlMinor}.x64.appx"
# Write-Host "$fileUIXaml"
Try{
try {
Write-Host "Downloading Microsoft.VCLibs Dependency..."
Invoke-WebRequest -Uri $fileVCLibs -OutFile $ENV:TEMP\Microsoft.VCLibs.x64.Desktop.appx
Write-Host "Downloading Microsoft.UI.Xaml Dependency...`n"
Invoke-WebRequest -Uri $fileUIXaml -OutFile $ENV:TEMP\Microsoft.UI.Xaml.x64.appx
}
Catch{
} catch {
throw [WingetFailedInstall]::new('Failed to install prerequsites')
}
}

View File

@ -18,8 +18,7 @@ function Install-WinUtilChoco {
Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) -ErrorAction Stop
powershell choco feature enable -n allowGlobalConfirmation
}
Catch {
} catch {
Write-Host "===========================================" -Foregroundcolor Red
Write-Host "-- Chocolatey failed to install ---" -Foregroundcolor Red
Write-Host "===========================================" -Foregroundcolor Red

View File

@ -33,26 +33,26 @@ function Install-WinUtilProgramChoco {
Write-Host "==========================================="
Write-Host "-- Configuring Chocolatey pacakages ---"
Write-Host "==========================================="
Foreach ($Program in $ProgramsToInstall){
Foreach ($Program in $ProgramsToInstall) {
Write-Progress -Activity "$manage Applications" -Status "$manage $($Program.choco) $($x + 1) of $count" -PercentComplete $($x/$count*100)
if($manage -eq "Installing"){
if($manage -eq "Installing") {
write-host "Starting install of $($Program.choco) with Chocolatey."
try{
try {
$tryUpgrade = $false
$installOutputFilePath = "$env:TEMP\Install-WinUtilProgramChoco.install-command.output.txt"
$installOutputFilePath = "$env:TEMP\Install-WinUtilProgramChoco.install-command.output.txt"
New-Item -ItemType File -Path $installOutputFilePath
$chocoInstallStatus = $(Start-Process -FilePath "choco" -ArgumentList "install $($Program.choco) -y" -Wait -PassThru -RedirectStandardOutput $installOutputFilePath).ExitCode
$chocoInstallStatus = $(Start-Process -FilePath "choco" -ArgumentList "install $($Program.choco) -y" -Wait -PassThru -RedirectStandardOutput $installOutputFilePath).ExitCode
if(($chocoInstallStatus -eq 0) -AND (Test-Path -Path $installOutputFilePath)) {
$keywordsFound = Get-Content -Path $installOutputFilePath | Where-Object {$_ -match "reinstall" -OR $_ -match "already installed"}
if ($keywordsFound) {
$tryUpgrade = $true
}
if ($keywordsFound) {
$tryUpgrade = $true
}
}
# TODO: Implement the Upgrade part using 'choco upgrade' command, this will make choco consistent with WinGet, as WinGet tries to Upgrade when you use the install command.
if ($tryUpgrade) {
throw "Automatic Upgrade for Choco isn't implemented yet, a feature to make it consistent with WinGet, the install command using choco simply failed because $($Program.choco) is already installed."
}
if(($chocoInstallStatus -eq 0) -AND ($tryUpgrade -eq $false)){
# TODO: Implement the Upgrade part using 'choco upgrade' command, this will make choco consistent with WinGet, as WinGet tries to Upgrade when you use the install command.
if ($tryUpgrade) {
throw "Automatic Upgrade for Choco isn't implemented yet, a feature to make it consistent with WinGet, the install command using choco simply failed because $($Program.choco) is already installed."
}
if(($chocoInstallStatus -eq 0) -AND ($tryUpgrade -eq $false)) {
Write-Host "$($Program.choco) installed successfully using Chocolatey."
$X++
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value ($x/$count) })
@ -69,13 +69,13 @@ function Install-WinUtilProgramChoco {
}
}
if($manage -eq "Uninstalling"){
if($manage -eq "Uninstalling") {
write-host "Starting uninstall of $($Program.choco) with Chocolatey."
try{
$uninstallOutputFilePath = "$env:TEMP\Install-WinUtilProgramChoco.uninstall-command.output.txt"
try {
$uninstallOutputFilePath = "$env:TEMP\Install-WinUtilProgramChoco.uninstall-command.output.txt"
New-Item -ItemType File -Path $uninstallOutputFilePath
$chocoUninstallStatus = $(Start-Process -FilePath "choco" -ArgumentList "uninstall $($Program.choco) -y" -Wait -PassThru).ExitCode
if($chocoUninstallStatus -eq 0){
$chocoUninstallStatus = $(Start-Process -FilePath "choco" -ArgumentList "uninstall $($Program.choco) -y" -Wait -PassThru).ExitCode
if($chocoUninstallStatus -eq 0) {
Write-Host "$($Program.choco) uninstalled successfully using Chocolatey."
$x++
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value ($x/$count) })
@ -90,13 +90,13 @@ function Install-WinUtilProgramChoco {
$x++
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" -value ($x/$count) })
}
}
}
}
Write-Progress -Activity "$manage Applications" -Status "Finished" -Completed
# Cleanup leftovers files
if(Test-Path -Path $installOutputFilePath){ Remove-Item -Path $installOutputFilePath }
if(Test-Path -Path $uninstallOutputFilePath){ Remove-Item -Path $uninstallOutputFilePath }
if(Test-Path -Path $installOutputFilePath) { Remove-Item -Path $installOutputFilePath }
if(Test-Path -Path $uninstallOutputFilePath) { Remove-Item -Path $uninstallOutputFilePath }
return;
}

View File

@ -9,7 +9,7 @@ function Install-WinUtilWinget {
#>
$isWingetInstalled = Test-WinUtilPackageManager -winget
Try {
try {
if ($isWingetInstalled -eq "installed") {
Write-Host "`nWinget is already installed.`r" -ForegroundColor Green
return
@ -21,7 +21,7 @@ function Install-WinUtilWinget {
# Gets the computer's information
if ($null -eq $sync.ComputerInfo){
if ($null -eq $sync.ComputerInfo) {
$ComputerInfo = Get-ComputerInfo -ErrorAction Stop
} else {
$ComputerInfo = $sync.ComputerInfo
@ -41,8 +41,8 @@ function Install-WinUtilWinget {
Get-WinUtilWingetLatest
Write-Host "Installing Winget w/ Prerequsites`r"
Add-AppxProvisionedPackage -Online -PackagePath $ENV:TEMP\Microsoft.DesktopAppInstaller.msixbundle -DependencyPackagePath $ENV:TEMP\Microsoft.VCLibs.x64.Desktop.appx, $ENV:TEMP\Microsoft.UI.Xaml.x64.appx -LicensePath $ENV:TEMP\License1.xml
Write-Host "Manually adding Winget Sources, from Winget CDN."
Add-AppxPackage -Path https://cdn.winget.microsoft.com/cache/source.msix #Seems some installs of Winget don't add the repo source, this should makes sure that it's installed every time.
Write-Host "Manually adding Winget Sources, from Winget CDN."
Add-AppxPackage -Path https://cdn.winget.microsoft.com/cache/source.msix #Seems some installs of Winget don't add the repo source, this should makes sure that it's installed every time.
Write-Host "Winget Installed" -ForegroundColor Green
Write-Host "Enabling NuGet and Module..."
Install-PackageProvider -Name NuGet -Force
@ -50,17 +50,17 @@ function Install-WinUtilWinget {
# Winget only needs a refresh of the environment variables to be used.
Write-Output "Refreshing Environment Variables...`n"
$ENV:PATH = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
} Catch {
} catch {
Write-Host "Failure detected while installing via GitHub method. Continuing with Chocolatey method as fallback." -ForegroundColor Red
# In case install fails via GitHub method.
Try {
try {
# Install Choco if not already present
Install-WinUtilChoco
Start-Process -Verb runas -FilePath powershell.exe -ArgumentList "choco install winget-cli"
Write-Host "Winget Installed" -ForegroundColor Green
Write-Output "Refreshing Environment Variables...`n"
$ENV:PATH = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
} Catch {
} catch {
throw [WingetFailedInstall]::new('Failed to install!')
}
}

File diff suppressed because it is too large Load Diff

View File

@ -9,26 +9,22 @@ function Invoke-WinUtilBingSearch {
#>
Param($Enabled)
Try{
if ($Enabled -eq $false){
try {
if ($Enabled -eq $false) {
Write-Host "Enabling Bing Search"
$value = 1
}
else {
} else {
Write-Host "Disabling Bing Search"
$value = 0
}
$Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search"
Set-ItemProperty -Path $Path -Name BingSearchEnabled -Value $value
}
Catch [System.Security.SecurityException] {
} catch [System.Security.SecurityException] {
Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception"
}
Catch [System.Management.Automation.ItemNotFoundException] {
} catch [System.Management.Automation.ItemNotFoundException] {
Write-Warning $psitem.Exception.ErrorRecord
}
Catch{
} catch {
Write-Warning "Unable to set $Name due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}
}
}

View File

@ -14,7 +14,7 @@ Function Invoke-WinUtilCurrentSystem {
$CheckBox
)
if ($checkbox -eq "winget"){
if ($checkbox -eq "winget") {
$originalEncoding = [Console]::OutputEncoding
[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new()
@ -31,9 +31,9 @@ Function Invoke-WinUtilCurrentSystem {
}
}
if($CheckBox -eq "tweaks"){
if($CheckBox -eq "tweaks") {
if(!(Test-Path 'HKU:\')){New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS}
if(!(Test-Path 'HKU:\')) {New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS}
$ScheduledTasks = Get-ScheduledTask
$sync.configs.tweaks | Get-Member -MemberType NoteProperty | ForEach-Object {
@ -44,59 +44,57 @@ Function Invoke-WinUtilCurrentSystem {
$scheduledtaskKeys = $sync.configs.tweaks.$Config.scheduledtask
$serviceKeys = $sync.configs.tweaks.$Config.service
if($registryKeys -or $scheduledtaskKeys -or $serviceKeys){
if($registryKeys -or $scheduledtaskKeys -or $serviceKeys) {
$Values = @()
Foreach ($tweaks in $registryKeys){
Foreach($tweak in $tweaks){
Foreach ($tweaks in $registryKeys) {
Foreach($tweak in $tweaks) {
if(test-path $tweak.Path){
if(test-path $tweak.Path) {
$actualValue = Get-ItemProperty -Name $tweak.Name -Path $tweak.Path -ErrorAction SilentlyContinue | Select-Object -ExpandProperty $($tweak.Name)
$expectedValue = $tweak.Value
if ($expectedValue -notlike $actualValue){
if ($expectedValue -notlike $actualValue) {
$values += $False
}
}
else {
} else {
$values += $False
}
}
}
Foreach ($tweaks in $scheduledtaskKeys){
Foreach($tweak in $tweaks){
Foreach ($tweaks in $scheduledtaskKeys) {
Foreach($tweak in $tweaks) {
$task = $ScheduledTasks | Where-Object {$($psitem.TaskPath + $psitem.TaskName) -like "\$($tweak.name)"}
if($task){
if($task) {
$actualValue = $task.State
$expectedValue = $tweak.State
if ($expectedValue -ne $actualValue){
if ($expectedValue -ne $actualValue) {
$values += $False
}
}
}
}
Foreach ($tweaks in $serviceKeys){
Foreach($tweak in $tweaks){
Foreach ($tweaks in $serviceKeys) {
Foreach($tweak in $tweaks) {
$Service = Get-Service -Name $tweak.Name
if($Service){
if($Service) {
$actualValue = $Service.StartType
$expectedValue = $tweak.StartupType
if ($expectedValue -ne $actualValue){
if ($expectedValue -ne $actualValue) {
$values += $False
}
}
}
}
if($values -notcontains $false){
if($values -notcontains $false) {
Write-Output $Config
}
}
}
}
}

View File

@ -9,12 +9,11 @@ Function Invoke-WinUtilDarkMode {
#>
Param($DarkMoveEnabled)
Try{
if ($DarkMoveEnabled -eq $false){
try {
if ($DarkMoveEnabled -eq $false) {
Write-Host "Enabling Dark Mode"
$DarkMoveValue = 0
}
else {
} else {
Write-Host "Disabling Dark Mode"
$DarkMoveValue = 1
}
@ -22,15 +21,12 @@ Function Invoke-WinUtilDarkMode {
$Path = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize"
Set-ItemProperty -Path $Path -Name AppsUseLightTheme -Value $DarkMoveValue
Set-ItemProperty -Path $Path -Name SystemUsesLightTheme -Value $DarkMoveValue
}
Catch [System.Security.SecurityException] {
} catch [System.Security.SecurityException] {
Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception"
}
Catch [System.Management.Automation.ItemNotFoundException] {
} catch [System.Management.Automation.ItemNotFoundException] {
Write-Warning $psitem.Exception.ErrorRecord
}
Catch{
} catch {
Write-Warning "Unable to set $Name due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}
}
}

View File

@ -8,27 +8,23 @@ Function Invoke-WinUtilDetailedBSoD {
#>
Param($Enabled)
Try{
if ($Enabled -eq $false){
try {
if ($Enabled -eq $false) {
Write-Host "Enabling Detailed BSoD"
$value = 1
}
else {
} else {
Write-Host "Disabling Detailed BSoD"
$value =0
}
$Path = "HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl"
Set-ItemProperty -Path $Path -Name DisplayParameters -Value $value
}
Catch [System.Security.SecurityException] {
} catch [System.Security.SecurityException] {
Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception"
}
Catch [System.Management.Automation.ItemNotFoundException] {
} catch [System.Management.Automation.ItemNotFoundException] {
Write-Warning $psitem.Exception.ErrorRecord
}
Catch{
} catch {
Write-Warning "Unable to set $Name due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}
}
}

View File

@ -13,19 +13,16 @@ function Invoke-WinUtilFeatureInstall {
$x = 0
$CheckBox | ForEach-Object {
if($sync.configs.feature.$psitem.feature){
Foreach( $feature in $sync.configs.feature.$psitem.feature ){
Try{
if($sync.configs.feature.$psitem.feature) {
Foreach( $feature in $sync.configs.feature.$psitem.feature ) {
try {
Write-Host "Installing $feature"
Enable-WindowsOptionalFeature -Online -FeatureName $feature -All -NoRestart
}
Catch{
if ($psitem.Exception.Message -like "*requires elevation*"){
} catch {
if ($psitem.Exception.Message -like "*requires elevation*") {
Write-Warning "Unable to Install $feature due to permissions. Are you running as admin?"
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
}
else{
} else {
Write-Warning "Unable to Install $feature due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
@ -33,21 +30,18 @@ function Invoke-WinUtilFeatureInstall {
}
}
}
if($sync.configs.feature.$psitem.InvokeScript){
Foreach( $script in $sync.configs.feature.$psitem.InvokeScript ){
Try{
if($sync.configs.feature.$psitem.InvokeScript) {
Foreach( $script in $sync.configs.feature.$psitem.InvokeScript ) {
try {
$Scriptblock = [scriptblock]::Create($script)
Write-Host "Running Script for $psitem"
Invoke-Command $scriptblock -ErrorAction stop
}
Catch{
if ($psitem.Exception.Message -like "*requires elevation*"){
} catch {
if ($psitem.Exception.Message -like "*requires elevation*") {
Write-Warning "Unable to Install $feature due to permissions. Are you running as admin?"
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
}
else{
} else {
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
Write-Warning "Unable to Install $feature due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace

View File

@ -11,11 +11,11 @@ function Invoke-WinUtilGPU {
)
foreach ($gpu in $gpuInfo) {
foreach ($gpuPattern in $lowPowerGPUs){
foreach ($gpuPattern in $lowPowerGPUs) {
if ($gpu.Name -like $gpuPattern) {
return $false
}
}
}
return $true
}
}

View File

@ -9,25 +9,21 @@ function Invoke-WinUtilHiddenFiles {
#>
Param($Enabled)
Try{
if ($Enabled -eq $false){
try {
if ($Enabled -eq $false) {
Write-Host "Enabling Hidden Files"
$value = 1
}
else {
} else {
Write-Host "Disabling Hidden Files"
$value = 0
}
$Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
Set-ItemProperty -Path $Path -Name Hidden -Value $value
}
Catch [System.Security.SecurityException] {
} catch [System.Security.SecurityException] {
Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception"
}
Catch [System.Management.Automation.ItemNotFoundException] {
} catch [System.Management.Automation.ItemNotFoundException] {
Write-Warning $psitem.Exception.ErrorRecord
}
Catch{
} catch {
Write-Warning "Unable to set $Name due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}

View File

@ -9,14 +9,13 @@ Function Invoke-WinUtilMouseAcceleration {
#>
Param($MouseAccelerationEnabled)
Try{
if ($MouseAccelerationEnabled -eq $false){
try {
if ($MouseAccelerationEnabled -eq $false) {
Write-Host "Enabling Mouse Acceleration"
$MouseSpeed = 1
$MouseThreshold1 = 6
$MouseThreshold2 = 10
}
else {
} else {
Write-Host "Disabling Mouse Acceleration"
$MouseSpeed = 0
$MouseThreshold1 = 0
@ -28,15 +27,12 @@ Function Invoke-WinUtilMouseAcceleration {
Set-ItemProperty -Path $Path -Name MouseSpeed -Value $MouseSpeed
Set-ItemProperty -Path $Path -Name MouseThreshold1 -Value $MouseThreshold1
Set-ItemProperty -Path $Path -Name MouseThreshold2 -Value $MouseThreshold2
}
Catch [System.Security.SecurityException] {
} catch [System.Security.SecurityException] {
Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception"
}
Catch [System.Management.Automation.ItemNotFoundException] {
} catch [System.Management.Automation.ItemNotFoundException] {
Write-Warning $psitem.Exception.ErrorRecord
}
Catch{
} catch {
Write-Warning "Unable to set $Name due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}
}
}

View File

@ -6,12 +6,11 @@ function Invoke-WinUtilNumLock {
Indicates whether to enable or disable Numlock on startup
#>
Param($Enabled)
Try{
if ($Enabled -eq $false){
try {
if ($Enabled -eq $false) {
Write-Host "Enabling Numlock on startup"
$value = 2
}
else {
} else {
Write-Host "Disabling Numlock on startup"
$value = 0
}
@ -23,12 +22,10 @@ function Invoke-WinUtilNumLock {
}
Catch [System.Security.SecurityException] {
Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception"
}
Catch [System.Management.Automation.ItemNotFoundException] {
} catch [System.Management.Automation.ItemNotFoundException] {
Write-Warning $psitem.Exception.ErrorRecord
}
Catch{
} catch {
Write-Warning "Unable to set $Name due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}
}
}

View File

@ -20,30 +20,25 @@ function Invoke-WinUtilScript {
[scriptblock]$scriptblock
)
Try {
try {
Write-Host "Running Script for $name"
Invoke-Command $scriptblock -ErrorAction Stop
}
Catch [System.Management.Automation.CommandNotFoundException] {
} catch [System.Management.Automation.CommandNotFoundException] {
Write-Warning "The specified command was not found."
Write-Warning $PSItem.Exception.message
}
Catch [System.Management.Automation.RuntimeException] {
} catch [System.Management.Automation.RuntimeException] {
Write-Warning "A runtime exception occurred."
Write-Warning $PSItem.Exception.message
}
Catch [System.Security.SecurityException] {
} catch [System.Security.SecurityException] {
Write-Warning "A security exception occurred."
Write-Warning $PSItem.Exception.message
}
Catch [System.UnauthorizedAccessException] {
} catch [System.UnauthorizedAccessException] {
Write-Warning "Access denied. You do not have permission to perform this operation."
Write-Warning $PSItem.Exception.message
}
Catch {
} catch {
# Generic catch block to handle any other type of exception
Write-Warning "Unable to run script for $name due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}
}
}

View File

@ -6,26 +6,22 @@ function Invoke-WinUtilShowExt {
Indicates whether to enable or disable Show file extentions
#>
Param($Enabled)
Try{
if ($Enabled -eq $false){
try {
if ($Enabled -eq $false) {
Write-Host "Showing file extentions"
$value = 0
}
else {
} else {
Write-Host "hiding file extensions"
$value = 1
}
$Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
Set-ItemProperty -Path $Path -Name HideFileExt -Value $value
}
Catch [System.Security.SecurityException] {
} catch [System.Security.SecurityException] {
Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception"
}
Catch [System.Management.Automation.ItemNotFoundException] {
} catch [System.Management.Automation.ItemNotFoundException] {
Write-Warning $psitem.Exception.ErrorRecord
}
Catch{
} catch {
Write-Warning "Unable to set $Name due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}
}
}

View File

@ -6,12 +6,11 @@ function Invoke-WinUtilSnapFlyout {
Indicates whether to enable or disable Snap Assist Flyout on startup
#>
Param($Enabled)
Try{
if ($Enabled -eq $false){
try {
if ($Enabled -eq $false) {
Write-Host "Enabling Snap Assist Flyout On startup"
$value = 1
}
else {
} else {
Write-Host "Disabling Snap Assist Flyout On startup"
$value = 0
}
@ -20,15 +19,12 @@ function Invoke-WinUtilSnapFlyout {
taskkill.exe /F /IM "explorer.exe"
Set-ItemProperty -Path $Path -Name EnableSnapAssistFlyout -Value $value
Start-Process "explorer.exe"
}
Catch [System.Security.SecurityException] {
} catch [System.Security.SecurityException] {
Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception"
}
Catch [System.Management.Automation.ItemNotFoundException] {
} catch [System.Management.Automation.ItemNotFoundException] {
Write-Warning $psitem.Exception.ErrorRecord
}
Catch{
} catch {
Write-Warning "Unable to set $Name due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}
}
}

View File

@ -6,12 +6,11 @@ function Invoke-WinUtilSnapSuggestion {
Indicates whether to enable or disable Snap Assist Suggestions on startup
#>
Param($Enabled)
Try{
if ($Enabled -eq $false){
try {
if ($Enabled -eq $false) {
Write-Host "Enabling Snap Assist Suggestion On startup"
$value = 1
}
else {
} else {
Write-Host "Disabling Snap Assist Suggestion On startup"
$value = 0
}
@ -20,15 +19,12 @@ function Invoke-WinUtilSnapSuggestion {
taskkill.exe /F /IM "explorer.exe"
Set-ItemProperty -Path $Path -Name SnapAssist -Value $value
Start-Process "explorer.exe"
}
Catch [System.Security.SecurityException] {
} catch [System.Security.SecurityException] {
Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception"
}
Catch [System.Management.Automation.ItemNotFoundException] {
} catch [System.Management.Automation.ItemNotFoundException] {
Write-Warning $psitem.Exception.ErrorRecord
}
Catch{
} catch {
Write-Warning "Unable to set $Name due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}
}
}

View File

@ -6,26 +6,22 @@ function Invoke-WinUtilSnapWindow {
Indicates whether to enable or disable Snapping Windows on startup
#>
Param($Enabled)
Try{
if ($Enabled -eq $false){
try {
if ($Enabled -eq $false) {
Write-Host "Enabling Snap Windows On startup | Relogin Required"
$value = 1
}
else {
} else {
Write-Host "Disabling Snap Windows On startup | Relogin Required"
$value = 0
}
$Path = "HKCU:\Control Panel\Desktop"
Set-ItemProperty -Path $Path -Name WindowArrangementActive -Value $value
}
Catch [System.Security.SecurityException] {
} catch [System.Security.SecurityException] {
Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception"
}
Catch [System.Management.Automation.ItemNotFoundException] {
} catch [System.Management.Automation.ItemNotFoundException] {
Write-Warning $psitem.Exception.ErrorRecord
}
Catch{
} catch {
Write-Warning "Unable to set $Name due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}
}
}

View File

@ -37,9 +37,8 @@ Function Invoke-WinUtilSponsors {
# Return the sponsors
return $sponsors
}
catch {
} catch {
Write-Error "An error occurred while fetching or processing the sponsors: $_"
return $null
}
}
}

View File

@ -6,26 +6,22 @@ Function Invoke-WinUtilStickyKeys {
Indicates whether to enable or disable Sticky Keys on startup
#>
Param($Enabled)
Try {
if ($Enabled -eq $false){
try {
if ($Enabled -eq $false) {
Write-Host "Enabling Sticky Keys On startup"
$value = 510
}
else {
} else {
Write-Host "Disabling Sticky Keys On startup"
$value = 58
}
$Path = "HKCU:\Control Panel\Accessibility\StickyKeys"
Set-ItemProperty -Path $Path -Name Flags -Value $value
}
Catch [System.Security.SecurityException] {
} catch [System.Security.SecurityException] {
Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception"
}
Catch [System.Management.Automation.ItemNotFoundException] {
} catch [System.Management.Automation.ItemNotFoundException] {
Write-Warning $psitem.Exception.ErrorRecord
}
Catch{
} catch {
Write-Warning "Unable to set $Name due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}
}
}

View File

@ -9,25 +9,21 @@ function Invoke-WinUtilTaskView {
#>
Param($Enabled)
Try{
if ($Enabled -eq $false){
try {
if ($Enabled -eq $false) {
Write-Host "Enabling Task View"
$value = 1
}
else {
} else {
Write-Host "Disabling Task View"
$value = 0
}
$Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
Set-ItemProperty -Path $Path -Name ShowTaskViewButton -Value $value
}
Catch [System.Security.SecurityException] {
} catch [System.Security.SecurityException] {
Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception"
}
Catch [System.Management.Automation.ItemNotFoundException] {
} catch [System.Management.Automation.ItemNotFoundException] {
Write-Warning $psitem.Exception.ErrorRecord
}
Catch{
} catch {
Write-Warning "Unable to set $Name due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}

View File

@ -9,25 +9,21 @@ function Invoke-WinUtilTaskbarAlignment {
#>
Param($Enabled)
Try{
if ($Enabled -eq $false){
try {
if ($Enabled -eq $false) {
Write-Host "Making Taskbar Alignment to the Center"
$value = 1
}
else {
} else {
Write-Host "Making Taskbar Alignment to the Left"
$value = 0
}
$Path = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
Set-ItemProperty -Path $Path -Name "TaskbarAl" -Value $value
}
Catch [System.Security.SecurityException] {
} catch [System.Security.SecurityException] {
Write-Warning "Unable to set $Path\$Name to $value due to a Security Exception"
}
Catch [System.Management.Automation.ItemNotFoundException] {
} catch [System.Management.Automation.ItemNotFoundException] {
Write-Warning $psitem.Exception.ErrorRecord
}
Catch{
} catch {
Write-Warning "Unable to set $Name due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}

View File

@ -9,25 +9,21 @@ function Invoke-WinUtilTaskbarSearch {
#>
Param($Enabled)
Try{
if ($Enabled -eq $false){
try {
if ($Enabled -eq $false) {
Write-Host "Enabling Search Button"
$value = 1
}
else {
} else {
Write-Host "Disabling Search Button"
$value = 0
}
$Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search\"
Set-ItemProperty -Path $Path -Name SearchboxTaskbarMode -Value $value
}
Catch [System.Security.SecurityException] {
} catch [System.Security.SecurityException] {
Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception"
}
Catch [System.Management.Automation.ItemNotFoundException] {
} catch [System.Management.Automation.ItemNotFoundException] {
Write-Warning $psitem.Exception.ErrorRecord
}
Catch{
} catch {
Write-Warning "Unable to set $Name due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}

View File

@ -9,25 +9,21 @@ function Invoke-WinUtilTaskbarWidgets {
#>
Param($Enabled)
Try{
if ($Enabled -eq $false){
try {
if ($Enabled -eq $false) {
Write-Host "Enabling Taskbar Widgets"
$value = 1
}
else {
} else {
Write-Host "Disabling Taskbar Widgets"
$value = 0
}
$Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
Set-ItemProperty -Path $Path -Name TaskbarDa -Value $value
}
Catch [System.Security.SecurityException] {
} catch [System.Security.SecurityException] {
Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception"
}
Catch [System.Management.Automation.ItemNotFoundException] {
} catch [System.Management.Automation.ItemNotFoundException] {
Write-Warning $psitem.Exception.ErrorRecord
}
Catch{
} catch {
Write-Warning "Unable to set $Name due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}

View File

@ -22,7 +22,7 @@ function Invoke-WinUtilTweaks {
)
Write-Debug "Tweaks: $($CheckBox)"
if($undo){
if($undo) {
$Values = @{
Registry = "OriginalValue"
ScheduledTask = "OriginalState"
@ -30,8 +30,7 @@ function Invoke-WinUtilTweaks {
ScriptType = "UndoScript"
}
}
Else{
} else {
$Values = @{
Registry = "Value"
ScheduledTask = "State"
@ -40,18 +39,18 @@ function Invoke-WinUtilTweaks {
ScriptType = "InvokeScript"
}
}
if($sync.configs.tweaks.$CheckBox.ScheduledTask){
if($sync.configs.tweaks.$CheckBox.ScheduledTask) {
$sync.configs.tweaks.$CheckBox.ScheduledTask | ForEach-Object {
Write-Debug "$($psitem.Name) and state is $($psitem.$($values.ScheduledTask))"
Set-WinUtilScheduledTask -Name $psitem.Name -State $psitem.$($values.ScheduledTask)
}
}
if($sync.configs.tweaks.$CheckBox.service){
if($sync.configs.tweaks.$CheckBox.service) {
Write-Debug "KeepServiceStartup is $KeepServiceStartup"
$sync.configs.tweaks.$CheckBox.service | ForEach-Object {
$changeservice = $true
# The check for !($undo) is required, without it the script will throw an error for accessing unavailable memeber, which's the 'OriginalService' Property
# The check for !($undo) is required, without it the script will throw an error for accessing unavailable memeber, which's the 'OriginalService' Property
if($KeepServiceStartup -AND !($undo)) {
try {
# Check if the service exists
@ -60,8 +59,7 @@ function Invoke-WinUtilTweaks {
Write-Debug "Service $($service.Name) was changed in the past to $($service.StartType.ToString()) from it's original type of $($psitem.$($values.OriginalService)), will not change it to $($psitem.$($values.service))"
$changeservice = $false
}
}
catch [System.ServiceProcess.ServiceNotFoundException] {
} catch [System.ServiceProcess.ServiceNotFoundException] {
Write-Warning "Service $($psitem.Name) was not found"
}
}
@ -72,13 +70,13 @@ function Invoke-WinUtilTweaks {
}
}
}
if($sync.configs.tweaks.$CheckBox.registry){
if($sync.configs.tweaks.$CheckBox.registry) {
$sync.configs.tweaks.$CheckBox.registry | ForEach-Object {
Write-Debug "$($psitem.Name) and state is $($psitem.$($values.registry))"
Set-WinUtilRegistry -Name $psitem.Name -Path $psitem.Path -Type $psitem.Type -Value $psitem.$($values.registry)
}
}
if($sync.configs.tweaks.$CheckBox.$($values.ScriptType)){
if($sync.configs.tweaks.$CheckBox.$($values.ScriptType)) {
$sync.configs.tweaks.$CheckBox.$($values.ScriptType) | ForEach-Object {
Write-Debug "$($psitem) and state is $($psitem.$($values.ScriptType))"
$Scriptblock = [scriptblock]::Create($psitem)
@ -86,8 +84,8 @@ function Invoke-WinUtilTweaks {
}
}
if(!$undo){
if($sync.configs.tweaks.$CheckBox.appx){
if(!$undo) {
if($sync.configs.tweaks.$CheckBox.appx) {
$sync.configs.tweaks.$CheckBox.appx | ForEach-Object {
Write-Debug "UNDO $($psitem.Name)"
Remove-WinUtilAPPX -Name $psitem

View File

@ -6,26 +6,22 @@ function Invoke-WinUtilVerboseLogon {
Indicates whether to enable or disable VerboseLogon messages
#>
Param($Enabled)
Try{
if ($Enabled -eq $false){
try {
if ($Enabled -eq $false) {
Write-Host "Enabling Verbose Logon Messages"
$value = 1
}
else {
} else {
Write-Host "Disabling Verbose Logon Messages"
$value = 0
}
$Path = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"
Set-ItemProperty -Path $Path -Name VerboseStatus -Value $value
}
Catch [System.Security.SecurityException] {
} catch [System.Security.SecurityException] {
Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception"
}
Catch [System.Management.Automation.ItemNotFoundException] {
} catch [System.Management.Automation.ItemNotFoundException] {
Write-Warning $psitem.Exception.ErrorRecord
}
Catch{
} catch {
Write-Warning "Unable to set $Name due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}
}
}

View File

@ -15,8 +15,7 @@ Function Invoke-WinUtilWingetProgram {
#>
param(
[Parameter(Mandatory, Position=0)]
$Programs,
[Parameter(Mandatory, Position=0)]$Programs,
[Parameter(Mandatory, Position=1)]
[ValidateSet("Install", "Uninstall")]
@ -47,10 +46,9 @@ Function Invoke-WinUtilWingetProgram {
)
$commonArguments = "--id $wingetId --silent"
$arguments = if ($Action -eq "Install"){
$arguments = if ($Action -eq "Install") {
"install $commonArguments --accept-source-agreements --accept-package-agreements $(if ($scope) {" --scope $scope"})"
}
else {
} else {
"uninstall $commonArguments"
}

View File

@ -15,22 +15,19 @@ function Remove-WinUtilAPPX {
$Name
)
Try {
try {
Write-Host "Removing $Name"
Get-AppxPackage "*$Name*" | Remove-AppxPackage -ErrorAction SilentlyContinue
Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like "*$Name*" | Remove-AppxProvisionedPackage -Online -ErrorAction SilentlyContinue
}
Catch [System.Exception] {
} catch [System.Exception] {
if ($psitem.Exception.Message -like "*The requested operation requires elevation*") {
Write-Warning "Unable to uninstall $name due to a Security Exception"
}
else {
} else {
Write-Warning "Unable to uninstall $name due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}
}
Catch{
} catch {
Write-Warning "Unable to uninstall $name due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}
}
}

View File

@ -12,24 +12,22 @@ function Set-WinUtilDNS {
#>
param($DNSProvider)
if($DNSProvider -eq "Default"){return}
Try{
if($DNSProvider -eq "Default") {return}
try {
$Adapters = Get-NetAdapter | Where-Object {$_.Status -eq "Up"}
Write-Host "Ensuring DNS is set to $DNSProvider on the following interfaces"
Write-Host $($Adapters | Out-String)
Foreach ($Adapter in $Adapters){
if($DNSProvider -eq "DHCP"){
Foreach ($Adapter in $Adapters) {
if($DNSProvider -eq "DHCP") {
Set-DnsClientServerAddress -InterfaceIndex $Adapter.ifIndex -ResetServerAddresses
}
Else{
} else {
Set-DnsClientServerAddress -InterfaceIndex $Adapter.ifIndex -ServerAddresses ("$($sync.configs.dns.$DNSProvider.Primary)", "$($sync.configs.dns.$DNSProvider.Secondary)")
Set-DnsClientServerAddress -InterfaceIndex $Adapter.ifIndex -ServerAddresses ("$($sync.configs.dns.$DNSProvider.Primary6)", "$($sync.configs.dns.$DNSProvider.Secondary6)")
}
}
}
Catch{
} catch {
Write-Warning "Unable to set DNS Provider due to an unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}
}
}

View File

@ -16,11 +16,10 @@ function Set-WinUtilProgressbar{
[int]$Percent,
$Hide
)
if ($hide){
if ($hide) {
$sync.form.Dispatcher.Invoke([action]{$sync.ProgressBarLabel.Visibility = "Collapsed"})
$sync.form.Dispatcher.Invoke([action]{$sync.ProgressBar.Visibility = "Collapsed"})
}
else{
} else {
$sync.form.Dispatcher.Invoke([action]{$sync.ProgressBarLabel.Visibility = "Visible"})
$sync.form.Dispatcher.Invoke([action]{$sync.ProgressBar.Visibility = "Visible"})
}
@ -28,4 +27,4 @@ function Set-WinUtilProgressbar{
$sync.form.Dispatcher.Invoke([action]{$sync.ProgressBarLabel.Content.ToolTip = $label})
$sync.form.Dispatcher.Invoke([action]{ $sync.ProgressBar.Value = $percent})
}
}

View File

@ -27,8 +27,8 @@ function Set-WinUtilRegistry {
$Value
)
Try{
if(!(Test-Path 'HKU:\')){New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS}
try {
if(!(Test-Path 'HKU:\')) {New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS}
If (!(Test-Path $Path)) {
Write-Host "$Path was not found, Creating..."
@ -37,14 +37,11 @@ function Set-WinUtilRegistry {
Write-Host "Set $Path\$Name to $Value"
Set-ItemProperty -Path $Path -Name $Name -Type $Type -Value $Value -Force -ErrorAction Stop | Out-Null
}
Catch [System.Security.SecurityException] {
} catch [System.Security.SecurityException] {
Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception"
}
Catch [System.Management.Automation.ItemNotFoundException] {
} catch [System.Management.Automation.ItemNotFoundException] {
Write-Warning $psitem.Exception.ErrorRecord
}
Catch{
} catch {
Write-Warning "Unable to set $Name due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}

View File

@ -19,27 +19,24 @@ function Set-WinUtilScheduledTask {
$State
)
Try{
if($State -eq "Disabled"){
try {
if($State -eq "Disabled") {
Write-Host "Disabling Scheduled Task $Name"
Disable-ScheduledTask -TaskName $Name -ErrorAction Stop
}
if($State -eq "Enabled"){
if($State -eq "Enabled") {
Write-Host "Enabling Scheduled Task $Name"
Enable-ScheduledTask -TaskName $Name -ErrorAction Stop
}
}
Catch [System.Exception]{
if($psitem.Exception.Message -like "*The system cannot find the file specified*"){
} catch [System.Exception] {
if($psitem.Exception.Message -like "*The system cannot find the file specified*") {
Write-Warning "Scheduled Task $name was not Found"
}
Else{
} else {
Write-Warning "Unable to set $Name due to unhandled exception"
Write-Warning $psitem.Exception.Message
}
}
Catch{
} catch {
Write-Warning "Unable to run script for $name due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}
}
}

View File

@ -26,11 +26,9 @@ Function Set-WinUtilService {
# Service exists, proceed with changing properties
$service | Set-Service -StartupType $StartupType -ErrorAction Stop
}
catch [System.ServiceProcess.ServiceNotFoundException] {
} catch [System.ServiceProcess.ServiceNotFoundException] {
Write-Warning "Service $Name was not found"
}
catch {
} catch {
Write-Warning "Unable to set $Name due to unhandled exception"
Write-Warning $_.Exception.Message
}

View File

@ -83,4 +83,4 @@ function Set-WinUtilTaskbaritem {
if ($description) {
$sync["Form"].taskbarItemInfo.Description = $description
}
}
}

View File

@ -1,25 +1,24 @@
function Set-WinUtilUITheme {
<#
.SYNOPSIS
Sets the theme of the XAML file
.SYNOPSIS
Sets the theme of the XAML file
.PARAMETER inputXML
A string representing the XAML object to modify
.PARAMETER inputXML
A string representing the XAML object to modify
.PARAMETER themeName
The name of the theme to set the XAML to. Defaults to 'matrix'
.EXAMPLE
Set-WinUtilUITheme -inputXAML $inputXAML
.PARAMETER themeName
The name of the theme to set the XAML to. Defaults to 'matrix'
.EXAMPLE
Set-WinUtilUITheme -inputXAML $inputXAML
#>
param
(
[Parameter(Mandatory=$true, Position=0)]
[string] $inputXML,
[Parameter(Mandatory=$false, Position=1)]
[string] $themeName = 'matrix'
[Parameter(Mandatory, position=0)]
[string]$inputXML,
[Parameter(position=1)]
[string]$themeName = 'matrix'
)
try {
@ -38,13 +37,11 @@ function Set-WinUtilUITheme {
# Replace the key with the value in the input XML
$inputXML = $inputXML.Replace($formattedKey, $value)
}
}
else {
} else {
Write-Host "Theme '$themeName' not found."
}
}
catch {
} catch {
Write-Warning "Unable to apply theme"
Write-Warning $psitem.Exception.StackTrace
}

View File

@ -30,12 +30,12 @@ function Test-WinUtilPackageManager {
} catch {
Write-Warning "Winget was not found due to un-known reasons, The Stack Trace is:`n$($psitem.Exception.StackTrace)"
$wingetExists = $false
}
}
# If Winget is available, Parse it's Version and give proper information to Terminal Output.
# If it isn't available, the return of this funtion will be "not-installed", indicating that
# If it isn't available, the return of this funtion will be "not-installed", indicating that
# Winget isn't installed/available on The System.
if ($wingetExists) {
if ($wingetExists) {
# Check if Preview Version
if ($wingetVersionFull.Contains("-preview")) {
$wingetVersion = $wingetVersionFull.Trim("-preview")
@ -65,8 +65,7 @@ function Test-WinUtilPackageManager {
if (!$wingetOutdated) {
Write-Host " - Winget is Up to Date" -ForegroundColor Green
$status = "installed"
}
else {
} else {
Write-Host " - Winget is Out of Date" -ForegroundColor Red
$status = "outdated"
}

View File

@ -18,4 +18,4 @@ Function Update-WinUtilProgramWinget {
$global:WinGetInstall = Start-Process -Verb runas powershell -ArgumentList "-command invoke-command -scriptblock {$wingetinstall} -argumentlist '$($ProgramsToInstall -join ",")'" -PassThru
}
}