mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-11-14 14:45:52 -06:00
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:
parent
3b2af3fa2b
commit
3903eaaa24
57
Compile.ps1
57
Compile.ps1
@ -1,13 +1,15 @@
|
||||
param (
|
||||
[switch]$Debug,
|
||||
[switch]$Run
|
||||
[switch]$Run,
|
||||
[switch]$SkipPreprocessing
|
||||
)
|
||||
$OFS = "`r`n"
|
||||
$scriptname = "winutil.ps1"
|
||||
$workingdir = $PSScriptRoot
|
||||
|
||||
# Variable to sync between runspaces
|
||||
$sync = [Hashtable]::Synchronized(@{})
|
||||
$sync.PSScriptRoot = $PSScriptRoot
|
||||
$sync.PSScriptRoot = $workingdir
|
||||
$sync.configs = @{}
|
||||
|
||||
function Update-Progress {
|
||||
@ -34,6 +36,17 @@ $header = @"
|
||||
################################################################################################################
|
||||
"@
|
||||
|
||||
if (-NOT $SkipPreprocessing) {
|
||||
Update-Progress "Pre-req: Running Preprocessor..." 0
|
||||
|
||||
# Dot source the 'Invoke-Preprocessing' Function from 'tools/Invoke-Preprocessing.ps1' Script
|
||||
$preprocessingFilePath = ".\tools\Invoke-Preprocessing.ps1"
|
||||
. "$(($workingdir -replace ('\\$', '')) + '\' + ($preprocessingFilePath -replace ('\.\\', '')))"
|
||||
|
||||
$excludedFiles = @('.\.git\', '.\.gitignore', '.\.gitattributes', '.\.github\CODEOWNERS', '.\LICENSE', '.\winutil.ps1', "$preprocessingFilePath", '.\docs\changelog.md', '*.png', '*.exe')
|
||||
$msg = "Pre-req: Code Formatting"
|
||||
Invoke-Preprocessing -WorkingDir "$workingdir" -ExcludedFiles $excludedFiles -ProgressStatusMessage $msg
|
||||
}
|
||||
|
||||
# Create the script in memory.
|
||||
Update-Progress "Pre-req: Allocating Memory" 0
|
||||
@ -43,14 +56,14 @@ Update-Progress "Adding: Header" 5
|
||||
$script_content.Add($header)
|
||||
|
||||
Update-Progress "Adding: Version" 10
|
||||
$script_content.Add($(Get-Content .\scripts\start.ps1).replace('#{replaceme}',"$(Get-Date -Format yy.MM.dd)"))
|
||||
$script_content.Add($(Get-Content "$workingdir\scripts\start.ps1").replace('#{replaceme}',"$(Get-Date -Format yy.MM.dd)"))
|
||||
|
||||
Update-Progress "Adding: Functions" 20
|
||||
Get-ChildItem .\functions -Recurse -File | ForEach-Object {
|
||||
Get-ChildItem "$workingdir\functions" -Recurse -File | ForEach-Object {
|
||||
$script_content.Add($(Get-Content $psitem.FullName))
|
||||
}
|
||||
Update-Progress "Adding: Config *.json" 40
|
||||
Get-ChildItem .\config | Where-Object {$psitem.extension -eq ".json"} | ForEach-Object {
|
||||
Get-ChildItem "$workingdir\config" | Where-Object {$psitem.extension -eq ".json"} | ForEach-Object {
|
||||
|
||||
$json = (Get-Content $psitem.FullName).replace("'","''")
|
||||
|
||||
@ -95,10 +108,10 @@ Get-ChildItem .\config | Where-Object {$psitem.extension -eq ".json"} | ForEach-
|
||||
$script_content.Add($(Write-output "`$sync.configs.$($psitem.BaseName) = '$json' `| convertfrom-json" ))
|
||||
}
|
||||
|
||||
$xaml = (Get-Content .\xaml\inputXML.xaml).replace("'","''")
|
||||
$xaml = (Get-Content "$workingdir\xaml\inputXML.xaml").replace("'","''")
|
||||
|
||||
# Dot-source the Get-TabXaml function
|
||||
. .\functions\private\Get-TabXaml.ps1
|
||||
. "$workingdir\functions\private\Get-TabXaml.ps1"
|
||||
|
||||
Update-Progress "Building: Xaml " 75
|
||||
$appXamlContent = Get-TabXaml "applications" 5
|
||||
@ -114,30 +127,28 @@ $xaml = $xaml -replace "{{InstallPanel_features}}", $featuresXamlContent
|
||||
|
||||
$script_content.Add($(Write-output "`$inputXML = '$xaml'"))
|
||||
|
||||
$script_content.Add($(Get-Content .\scripts\main.ps1))
|
||||
$script_content.Add($(Get-Content "$workingdir\scripts\main.ps1"))
|
||||
|
||||
if ($Debug){
|
||||
if ($Debug) {
|
||||
Update-Progress "Writing debug files" 95
|
||||
$appXamlContent | Out-File -FilePath ".\xaml\inputApp.xaml" -Encoding ascii
|
||||
$tweaksXamlContent | Out-File -FilePath ".\xaml\inputTweaks.xaml" -Encoding ascii
|
||||
$featuresXamlContent | Out-File -FilePath ".\xaml\inputFeatures.xaml" -Encoding ascii
|
||||
}
|
||||
else {
|
||||
$appXamlContent | Out-File -FilePath "$workingdir\xaml\inputApp.xaml" -Encoding ascii
|
||||
$tweaksXamlContent | Out-File -FilePath "$workingdir\xaml\inputTweaks.xaml" -Encoding ascii
|
||||
$featuresXamlContent | Out-File -FilePath "$workingdir\xaml\inputFeatures.xaml" -Encoding ascii
|
||||
} else {
|
||||
Update-Progress "Removing temporary files" 99
|
||||
Remove-Item ".\xaml\inputApp.xaml" -ErrorAction SilentlyContinue
|
||||
Remove-Item ".\xaml\inputTweaks.xaml" -ErrorAction SilentlyContinue
|
||||
Remove-Item ".\xaml\inputFeatures.xaml" -ErrorAction SilentlyContinue
|
||||
Remove-Item "$workingdir\xaml\inputApp.xaml" -ErrorAction SilentlyContinue
|
||||
Remove-Item "$workingdir\xaml\inputTweaks.xaml" -ErrorAction SilentlyContinue
|
||||
Remove-Item "$workingdir\xaml\inputFeatures.xaml" -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
Set-Content -Path $scriptname -Value ($script_content -join "`r`n") -Encoding ascii
|
||||
Set-Content -Path "$workingdir\$scriptname" -Value ($script_content -join "`r`n") -Encoding ascii
|
||||
Write-Progress -Activity "Compiling" -Completed
|
||||
|
||||
if ($run){
|
||||
if ($run) {
|
||||
try {
|
||||
Start-Process -FilePath "pwsh" -ArgumentList ".\$scriptname"
|
||||
}
|
||||
catch {
|
||||
Start-Process -FilePath "powershell" -ArgumentList ".\$scriptname"
|
||||
Start-Process -FilePath "pwsh" -ArgumentList "$workingdir\$scriptname"
|
||||
} catch {
|
||||
Start-Process -FilePath "powershell" -ArgumentList "$workingdir\$scriptname"
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2432,7 +2432,7 @@
|
||||
|
||||
# Check if the SystemRestorePointCreationFrequency value exists
|
||||
$exists = Get-ItemProperty -path \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SystemRestore\" -Name \"SystemRestorePointCreationFrequency\" -ErrorAction SilentlyContinue
|
||||
if($null -eq $exists){
|
||||
if($null -eq $exists) {
|
||||
write-host 'Changing system to allow multiple restore points per day'
|
||||
Set-ItemProperty -Path \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SystemRestore\" -Name \"SystemRestorePointCreationFrequency\" -Value \"0\" -Type DWord -Force -ErrorAction Stop | Out-Null
|
||||
}
|
||||
@ -2666,17 +2666,16 @@
|
||||
$OneDrivePath = $($env:OneDrive)
|
||||
Write-Host \"Removing OneDrive\"
|
||||
$regPath = \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OneDriveSetup.exe\"
|
||||
if (Test-Path $regPath){
|
||||
if (Test-Path $regPath) {
|
||||
$OneDriveUninstallString = Get-ItemPropertyValue \"$regPath\" -Name \"UninstallString\"
|
||||
$OneDriveExe, $OneDriveArgs = $OneDriveUninstallString.Split(\" \")
|
||||
Start-Process -FilePath $OneDriveExe -ArgumentList \"$OneDriveArgs /silent\" -NoNewWindow -Wait
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
Write-Host \"Onedrive dosn't seem to be installed anymore\" -ForegroundColor Red
|
||||
return
|
||||
}
|
||||
# Check if OneDrive got Uninstalled
|
||||
if (-not (Test-Path $regPath)){
|
||||
if (-not (Test-Path $regPath)) {
|
||||
Write-Host \"Copy downloaded Files from the OneDrive Folder to Root UserProfile\"
|
||||
Start-Process -FilePath powershell -ArgumentList \"robocopy '$($OneDrivePath)' '$($env:USERPROFILE.TrimEnd())\\' /mov /e /xj\" -NoNewWindow -Wait
|
||||
|
||||
@ -2738,8 +2737,7 @@
|
||||
Write-Host \"Please Note - The OneDrive folder at $OneDrivePath may still have items in it. You must manually delete it, but all the files should already be copied to the base user folder.\"
|
||||
Write-Host \"If there are Files missing afterwards, please Login to Onedrive.com and Download them manually\" -ForegroundColor Yellow
|
||||
Start-Sleep 5
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
Write-Host \"Something went Wrong during the Unistallation of OneDrive\" -ForegroundColor Red
|
||||
}
|
||||
"
|
||||
@ -2939,8 +2937,7 @@
|
||||
try {
|
||||
Invoke-WebRequest -Uri $remoteHostsUrl -OutFile $tempHostsPath
|
||||
Write-Output \"Downloaded the remote HOSTS file to a temporary location.\"
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
Write-Error \"Failed to download the HOSTS file. Error: $_\"
|
||||
}
|
||||
|
||||
@ -2966,8 +2963,7 @@
|
||||
$combinedContent | Set-Content $localHostsPath -Encoding ASCII
|
||||
Write-Output \"Successfully added the AdobeNetBlock.\"
|
||||
}
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
Write-Error \"Error during processing: $_\"
|
||||
}
|
||||
|
||||
@ -2978,8 +2974,7 @@
|
||||
try {
|
||||
Invoke-Expression \"ipconfig /flushdns\"
|
||||
Write-Output \"DNS cache flushed successfully.\"
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
Write-Error \"Failed to flush DNS cache. Error: $_\"
|
||||
}
|
||||
"
|
||||
@ -2992,8 +2987,7 @@
|
||||
# Load the content of the HOSTS file
|
||||
try {
|
||||
$hostsContent = Get-Content $localHostsPath -ErrorAction Stop
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
Write-Error \"Failed to load the HOSTS file. Error: $_\"
|
||||
return
|
||||
}
|
||||
@ -3019,8 +3013,7 @@
|
||||
try {
|
||||
$newContent | Set-Content $localHostsPath -Encoding ASCII
|
||||
Write-Output \"Successfully removed the AdobeNetBlock section from the HOSTS file.\"
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
Write-Error \"Failed to write back to the HOSTS file. Error: $_\"
|
||||
}
|
||||
|
||||
@ -3028,8 +3021,7 @@
|
||||
try {
|
||||
Invoke-Expression \"ipconfig /flushdns\"
|
||||
Write-Output \"DNS cache flushed successfully.\"
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
Write-Error \"Failed to flush DNS cache. Error: $_\"
|
||||
}
|
||||
"
|
||||
|
@ -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'."
|
||||
}
|
||||
}
|
||||
|
@ -10,10 +10,10 @@ 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 {
|
||||
@ -21,27 +21,22 @@ function Copy-Files {
|
||||
$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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -4,14 +4,18 @@ function Get-TabXaml {
|
||||
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""" + " " +
|
||||
|
@ -3,10 +3,13 @@ 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
|
||||
@ -15,13 +18,14 @@ function Get-WPFObjectName {
|
||||
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]', ''
|
||||
|
||||
return $Output
|
||||
[Parameter(position=1)]
|
||||
[string]$name
|
||||
)
|
||||
|
||||
$Output = $("WPF"+$type+$name) -replace '[^a-zA-Z0-9]', ''
|
||||
return $Output
|
||||
}
|
@ -14,10 +14,10 @@ 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
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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#>
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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')
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -33,11 +33,11 @@ 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"
|
||||
New-Item -ItemType File -Path $installOutputFilePath
|
||||
@ -52,7 +52,7 @@ function Install-WinUtilProgramChoco {
|
||||
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)){
|
||||
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{
|
||||
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){
|
||||
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) })
|
||||
@ -95,8 +95,8 @@ function Install-WinUtilProgramChoco {
|
||||
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;
|
||||
}
|
||||
|
@ -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
|
||||
@ -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!')
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,20 @@
|
||||
function Test-CompatibleImage() {
|
||||
<#
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Checks the version of a Windows image and determines whether or not it is compatible with a specific feature depending on a desired version
|
||||
|
||||
.PARAMETER Name
|
||||
imgVersion - The version of the Windows image
|
||||
desiredVersion - The version to compare the image version with
|
||||
|
||||
#>
|
||||
#>
|
||||
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true, Position=0)] [string] $imgVersion,
|
||||
[Parameter(Mandatory = $true, Position=1)] [Version] $desiredVersion
|
||||
[Parameter(Mandatory, position=0)]
|
||||
[string]$imgVersion,
|
||||
|
||||
[Parameter(Mandatory, position=1)]
|
||||
[Version]$desiredVersion
|
||||
)
|
||||
|
||||
try {
|
||||
@ -24,9 +25,8 @@ function Test-CompatibleImage() {
|
||||
}
|
||||
}
|
||||
|
||||
function Remove-Features([switch] $dumpFeatures = $false, [switch] $keepDefender = $false) {
|
||||
<#
|
||||
|
||||
function Remove-Features([switch]$dumpFeatures = $false, [switch]$keepDefender = $false) {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Removes certain features from ISO image
|
||||
|
||||
@ -36,13 +36,10 @@ function Remove-Features([switch] $dumpFeatures = $false, [switch] $keepDefender
|
||||
|
||||
.EXAMPLE
|
||||
Remove-Features -keepDefender:$false
|
||||
|
||||
#>
|
||||
try
|
||||
{
|
||||
#>
|
||||
try {
|
||||
$featlist = (Get-WindowsOptionalFeature -Path $scratchDir).FeatureName
|
||||
if ($dumpFeatures)
|
||||
{
|
||||
if ($dumpFeatures) {
|
||||
$featlist > allfeaturesdump.txt
|
||||
}
|
||||
|
||||
@ -57,8 +54,7 @@ function Remove-Features([switch] $dumpFeatures = $false, [switch] $keepDefender
|
||||
|
||||
if ($keepDefender) { $featlist = $featlist | Where-Object { $_ -NotLike "*Defender*" }}
|
||||
|
||||
foreach($feature in $featlist)
|
||||
{
|
||||
foreach($feature in $featlist) {
|
||||
$status = "Removing feature $feature"
|
||||
Write-Progress -Activity "Removing features" -Status $status -PercentComplete ($counter++/$featlist.Count*100)
|
||||
Write-Debug "Removing feature $feature"
|
||||
@ -66,17 +62,13 @@ function Remove-Features([switch] $dumpFeatures = $false, [switch] $keepDefender
|
||||
}
|
||||
Write-Progress -Activity "Removing features" -Status "Ready" -Completed
|
||||
Write-Host "You can re-enable the disabled features at any time, using either Windows Update or the SxS folder in <installation media>\Sources."
|
||||
}
|
||||
catch
|
||||
{
|
||||
} catch {
|
||||
Write-Host "Unable to get information about the features. MicroWin processing will continue, but features will not be processed"
|
||||
}
|
||||
}
|
||||
|
||||
function Remove-Packages
|
||||
{
|
||||
try
|
||||
{
|
||||
function Remove-Packages {
|
||||
try {
|
||||
$pkglist = (Get-WindowsPackage -Path "$scratchDir").PackageName
|
||||
|
||||
$pkglist = $pkglist | Where-Object {
|
||||
@ -117,31 +109,25 @@ function Remove-Packages
|
||||
$_ -NotLike "*UI.XaML*"
|
||||
}
|
||||
|
||||
foreach ($pkg in $pkglist)
|
||||
{
|
||||
foreach ($pkg in $pkglist) {
|
||||
try {
|
||||
$status = "Removing $pkg"
|
||||
Write-Progress -Activity "Removing Apps" -Status $status -PercentComplete ($counter++/$pkglist.Count*100)
|
||||
Remove-WindowsPackage -Path "$scratchDir" -PackageName $pkg -NoRestart -ErrorAction SilentlyContinue
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
# This can happen if the package that is being removed is a permanent one, like FodMetadata
|
||||
Write-Host "Could not remove OS package $($pkg)"
|
||||
continue
|
||||
}
|
||||
}
|
||||
Write-Progress -Activity "Removing Apps" -Status "Ready" -Completed
|
||||
}
|
||||
catch
|
||||
{
|
||||
} catch {
|
||||
Write-Host "Unable to get information about the packages. MicroWin processing will continue, but packages will not be processed"
|
||||
}
|
||||
}
|
||||
|
||||
function Remove-ProvisionedPackages([switch] $keepSecurity = $false)
|
||||
{
|
||||
<#
|
||||
|
||||
function Remove-ProvisionedPackages([switch]$keepSecurity = $false) {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Removes AppX packages from a Windows image during MicroWin processing
|
||||
|
||||
@ -150,8 +136,7 @@ function Remove-ProvisionedPackages([switch] $keepSecurity = $false)
|
||||
|
||||
.EXAMPLE
|
||||
Remove-ProvisionedPackages -keepSecurity:$false
|
||||
|
||||
#>
|
||||
#>
|
||||
$appxProvisionedPackages = Get-AppxProvisionedPackage -Path "$($scratchDir)" | Where-Object {
|
||||
$_.PackageName -NotLike "*AppInstaller*" -AND
|
||||
$_.PackageName -NotLike "*Store*" -and
|
||||
@ -165,32 +150,26 @@ function Remove-ProvisionedPackages([switch] $keepSecurity = $false)
|
||||
$_.PackageName -NotLike "*Foundation*"
|
||||
}
|
||||
|
||||
if ($?)
|
||||
{
|
||||
if ($?) {
|
||||
if ($keepSecurity) { $appxProvisionedPackages = $appxProvisionedPackages | Where-Object { $_.PackageName -NotLike "*SecHealthUI*" }}
|
||||
$counter = 0
|
||||
foreach ($appx in $appxProvisionedPackages)
|
||||
{
|
||||
foreach ($appx in $appxProvisionedPackages) {
|
||||
$status = "Removing Provisioned $($appx.PackageName)"
|
||||
Write-Progress -Activity "Removing Provisioned Apps" -Status $status -PercentComplete ($counter++/$appxProvisionedPackages.Count*100)
|
||||
try {
|
||||
Remove-AppxProvisionedPackage -Path $scratchDir -PackageName $appx.PackageName -ErrorAction SilentlyContinue
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
Write-Host "Application $($appx.PackageName) could not be removed"
|
||||
continue
|
||||
}
|
||||
}
|
||||
Write-Progress -Activity "Removing Provisioned Apps" -Status "Ready" -Completed
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Write-Host "Could not get Provisioned App information. Skipping process..."
|
||||
}
|
||||
}
|
||||
|
||||
function Copy-ToUSB([string] $fileToCopy)
|
||||
{
|
||||
function Copy-ToUSB([string]$fileToCopy) {
|
||||
foreach ($volume in Get-Volume) {
|
||||
if ($volume -and $volume.FileSystemLabel -ieq "ventoy") {
|
||||
$destinationPath = "$($volume.DriveLetter):\"
|
||||
@ -214,8 +193,7 @@ function Copy-ToUSB([string] $fileToCopy)
|
||||
Write-Host "Ventoy USB Key is not inserted"
|
||||
}
|
||||
|
||||
function Remove-FileOrDirectory([string] $pathToDelete, [string] $mask = "", [switch] $Directory = $false)
|
||||
{
|
||||
function Remove-FileOrDirectory([string]$pathToDelete, [string]$mask = "", [switch]$Directory = $false) {
|
||||
if(([string]::IsNullOrEmpty($pathToDelete))) { return }
|
||||
if (-not (Test-Path -Path "$($pathToDelete)")) { return }
|
||||
|
||||
@ -240,25 +218,19 @@ function Remove-FileOrDirectory([string] $pathToDelete, [string] $mask = "", [sw
|
||||
|
||||
$itemsToDelete = [System.Collections.ArrayList]::new()
|
||||
|
||||
if ($mask -eq "")
|
||||
{
|
||||
if ($mask -eq "") {
|
||||
Write-Debug "Adding $($pathToDelete) to array."
|
||||
[void]$itemsToDelete.Add($pathToDelete)
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Write-Debug "Adding $($pathToDelete) to array and mask is $($mask)"
|
||||
if ($Directory) { $itemsToDelete = Get-ChildItem $pathToDelete -Include $mask -Recurse -Directory }
|
||||
else { $itemsToDelete = Get-ChildItem $pathToDelete -Include $mask -Recurse }
|
||||
if ($Directory) { $itemsToDelete = Get-ChildItem $pathToDelete -Include $mask -Recurse -Directory } else { $itemsToDelete = Get-ChildItem $pathToDelete -Include $mask -Recurse }
|
||||
}
|
||||
|
||||
foreach($itemToDelete in $itemsToDelete)
|
||||
{
|
||||
foreach($itemToDelete in $itemsToDelete) {
|
||||
$status = "Deleting $($itemToDelete)"
|
||||
Write-Progress -Activity "Removing Items" -Status $status -PercentComplete ($counter++/$itemsToDelete.Count*100)
|
||||
|
||||
if (Test-Path -Path "$($itemToDelete)" -PathType Container)
|
||||
{
|
||||
if (Test-Path -Path "$($itemToDelete)" -PathType Container) {
|
||||
$status = "Deleting directory: $($itemToDelete)"
|
||||
|
||||
takeown /r /d $yesNo[0] /a /f "$($itemToDelete)"
|
||||
@ -267,8 +239,7 @@ function Remove-FileOrDirectory([string] $pathToDelete, [string] $mask = "", [sw
|
||||
icacls $itemToDelete /grant "*S-1-5-32-544:(OI)(CI)F" /t /c /q
|
||||
Remove-Item -Force -Recurse "$($itemToDelete)"
|
||||
}
|
||||
elseif (Test-Path -Path "$($itemToDelete)" -PathType Leaf)
|
||||
{
|
||||
elseif (Test-Path -Path "$($itemToDelete)" -PathType Leaf) {
|
||||
$status = "Deleting file: $($itemToDelete)"
|
||||
|
||||
takeown /a /f "$($itemToDelete)"
|
||||
@ -379,13 +350,10 @@ function New-Unattend {
|
||||
</component>
|
||||
</settings>
|
||||
'@
|
||||
if ((Test-CompatibleImage $imgVersion $([System.Version]::new(10,0,22000,1))) -eq $false)
|
||||
{
|
||||
if ((Test-CompatibleImage $imgVersion $([System.Version]::new(10,0,22000,1))) -eq $false) {
|
||||
# Replace the placeholder text with an empty string to make it valid for Windows 10 Setup
|
||||
$unattend = $unattend.Replace("<#REPLACEME#>", "").Trim()
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
# Replace the placeholder text with the Specialize pass
|
||||
$unattend = $unattend.Replace("<#REPLACEME#>", $specPass).Trim()
|
||||
}
|
||||
@ -472,8 +440,7 @@ function New-FirstRun {
|
||||
$firstRun = @'
|
||||
# Set the global error action preference to continue
|
||||
$ErrorActionPreference = "Continue"
|
||||
function Remove-RegistryValue
|
||||
{
|
||||
function Remove-RegistryValue {
|
||||
param (
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$RegistryPath,
|
||||
@ -483,30 +450,23 @@ function New-FirstRun {
|
||||
)
|
||||
|
||||
# Check if the registry path exists
|
||||
if (Test-Path -Path $RegistryPath)
|
||||
{
|
||||
if (Test-Path -Path $RegistryPath) {
|
||||
$registryValue = Get-ItemProperty -Path $RegistryPath -Name $ValueName -ErrorAction SilentlyContinue
|
||||
|
||||
# Check if the registry value exists
|
||||
if ($registryValue)
|
||||
{
|
||||
if ($registryValue) {
|
||||
# Remove the registry value
|
||||
Remove-ItemProperty -Path $RegistryPath -Name $ValueName -Force
|
||||
Write-Host "Registry value '$ValueName' removed from '$RegistryPath'."
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Write-Host "Registry value '$ValueName' not found in '$RegistryPath'."
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Write-Host "Registry path '$RegistryPath' not found."
|
||||
}
|
||||
}
|
||||
|
||||
function Stop-UnnecessaryServices
|
||||
{
|
||||
function Stop-UnnecessaryServices {
|
||||
$servicesToExclude = @(
|
||||
"AudioSrv",
|
||||
"AudioEndpointBuilder",
|
||||
@ -573,8 +533,7 @@ function New-FirstRun {
|
||||
)
|
||||
|
||||
$runningServices = Get-Service | Where-Object { $servicesToExclude -notcontains $_.Name }
|
||||
foreach($service in $runningServices)
|
||||
{
|
||||
foreach($service in $runningServices) {
|
||||
Stop-Service -Name $service.Name -PassThru
|
||||
Set-Service $service.Name -StartupType Manual
|
||||
"Stopping service $($service.Name)" | Out-File -FilePath c:\windows\LogFirstRun.txt -Append -NoClobber
|
||||
@ -613,10 +572,8 @@ function New-FirstRun {
|
||||
# Delete Edge Icon from the desktop
|
||||
$edgeShortcutFiles = Get-ChildItem -Path $desktopPath -Filter "*Edge*.lnk"
|
||||
# Check if Edge shortcuts exist on the desktop
|
||||
if ($edgeShortcutFiles)
|
||||
{
|
||||
foreach ($shortcutFile in $edgeShortcutFiles)
|
||||
{
|
||||
if ($edgeShortcutFiles) {
|
||||
foreach ($shortcutFile in $edgeShortcutFiles) {
|
||||
# Remove each Edge shortcut
|
||||
Remove-Item -Path $shortcutFile.FullName -Force
|
||||
Write-Host "Edge shortcut '$($shortcutFile.Name)' removed from the desktop."
|
||||
@ -639,8 +596,7 @@ function New-FirstRun {
|
||||
# Create a shortcut object
|
||||
$shortcut = $shell.CreateShortcut($shortcutPath)
|
||||
|
||||
if (Test-Path -Path "c:\Windows\cttlogo.png")
|
||||
{
|
||||
if (Test-Path -Path "c:\Windows\cttlogo.png") {
|
||||
$shortcut.IconLocation = "c:\Windows\cttlogo.png"
|
||||
}
|
||||
|
||||
|
@ -9,25 +9,21 @@ 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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,14 +21,11 @@ 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
|
||||
}
|
||||
|
@ -8,26 +8,22 @@ 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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -11,7 +11,7 @@ function Invoke-WinUtilGPU {
|
||||
)
|
||||
|
||||
foreach ($gpu in $gpuInfo) {
|
||||
foreach ($gpuPattern in $lowPowerGPUs){
|
||||
foreach ($gpuPattern in $lowPowerGPUs) {
|
||||
if ($gpu.Name -like $gpuPattern) {
|
||||
return $false
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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,14 +27,11 @@ 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
|
||||
}
|
||||
|
@ -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,11 +22,9 @@ 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
|
||||
}
|
||||
|
@ -20,27 +20,22 @@ 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
|
||||
|
@ -6,25 +6,21 @@ 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
|
||||
}
|
||||
|
@ -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,14 +19,11 @@ 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
|
||||
}
|
||||
|
@ -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,14 +19,11 @@ 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
|
||||
}
|
||||
|
@ -6,25 +6,21 @@ 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
|
||||
}
|
||||
|
@ -37,8 +37,7 @@ Function Invoke-WinUtilSponsors {
|
||||
|
||||
# Return the sponsors
|
||||
return $sponsors
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
Write-Error "An error occurred while fetching or processing the sponsors: $_"
|
||||
return $null
|
||||
}
|
||||
|
@ -6,25 +6,21 @@ 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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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,13 +39,13 @@ 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
|
||||
@ -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
|
||||
|
@ -6,25 +6,21 @@ 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
|
||||
}
|
||||
|
@ -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"
|
||||
}
|
||||
|
||||
|
@ -15,21 +15,18 @@ 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
|
||||
}
|
||||
|
@ -12,23 +12,21 @@ 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
|
||||
}
|
||||
|
@ -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"})
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -19,26 +19,23 @@ 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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
function Set-WinUtilUITheme {
|
||||
<#
|
||||
|
||||
.SYNOPSIS
|
||||
Sets the theme of the XAML file
|
||||
|
||||
@ -12,14 +11,14 @@ function Set-WinUtilUITheme {
|
||||
|
||||
.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
|
||||
}
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -18,8 +18,7 @@ function Invoke-ScratchDialog {
|
||||
$filePath = $Dialog.SelectedPath
|
||||
Write-Host "No ISO is chosen+ $filePath"
|
||||
|
||||
if ([string]::IsNullOrEmpty($filePath))
|
||||
{
|
||||
if ([string]::IsNullOrEmpty($filePath)) {
|
||||
Write-Host "No Folder had chosen"
|
||||
return
|
||||
}
|
||||
|
@ -14,11 +14,11 @@ function Invoke-WPFButton {
|
||||
|
||||
# Use this to get the name of the button
|
||||
#[System.Windows.MessageBox]::Show("$Button","Chris Titus Tech's Windows Utility","OK","Info")
|
||||
if (-not $sync.ProcessRunning){
|
||||
if (-not $sync.ProcessRunning) {
|
||||
Set-WinUtilProgressBar -label "" -percent 0 -hide $true
|
||||
}
|
||||
|
||||
Switch -Wildcard ($Button){
|
||||
Switch -Wildcard ($Button) {
|
||||
|
||||
"WPFTab?BT" {Invoke-WPFTab $Button}
|
||||
"WPFinstall" {Invoke-WPFInstall}
|
||||
|
@ -10,7 +10,7 @@ function Invoke-WPFControlPanel {
|
||||
#>
|
||||
param($Panel)
|
||||
|
||||
switch ($Panel){
|
||||
switch ($Panel) {
|
||||
"WPFPanelcontrol" {cmd /c control}
|
||||
"WPFPanelnetwork" {cmd /c ncpa.cpl}
|
||||
"WPFPanelpower" {cmd /c powercfg.cpl}
|
||||
|
@ -6,7 +6,7 @@ function Invoke-WPFFeatureInstall {
|
||||
|
||||
#>
|
||||
|
||||
if($sync.ProcessRunning){
|
||||
if($sync.ProcessRunning) {
|
||||
$msg = "[Invoke-WPFFeatureInstall] Install process is currently running."
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
|
||||
return
|
||||
@ -17,7 +17,7 @@ function Invoke-WPFFeatureInstall {
|
||||
Invoke-WPFRunspace -ArgumentList $Features -DebugPreference $DebugPreference -ScriptBlock {
|
||||
param($Features, $DebugPreference)
|
||||
$sync.ProcessRunning = $true
|
||||
if ($Features.count -eq 1){
|
||||
if ($Features.count -eq 1) {
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" -value 0.01 -overlay "logo" })
|
||||
} else {
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value 0.01 -overlay "logo" })
|
||||
|
@ -66,7 +66,7 @@ function Invoke-WPFFixesUpdate {
|
||||
).Trim()} catch {0}) `
|
||||
<# And the current percentage is greater than the previous one #>`
|
||||
-and $percent -gt $oldpercent
|
||||
){
|
||||
) {
|
||||
# Update the progress bar
|
||||
$oldpercent = $percent
|
||||
Write-Progress -Id 1 -ParentId 0 -Activity "Scanning for corruption" -Status "Running chkdsk... ($percent%)" -PercentComplete $percent
|
||||
@ -93,7 +93,7 @@ function Invoke-WPFFixesUpdate {
|
||||
) -join ''
|
||||
).TrimStart()} catch {0}
|
||||
) -and $percent -gt $oldpercent
|
||||
){
|
||||
) {
|
||||
# Update the progress bar
|
||||
$oldpercent = $percent
|
||||
Write-Progress -Id 1 -ParentId 0 -Activity "Scanning for corruption" -Status "Running SFC... ($percent%)" -PercentComplete $percent
|
||||
@ -112,7 +112,7 @@ function Invoke-WPFFixesUpdate {
|
||||
[int]($_ -replace "\[" -replace "=" -replace " " -replace "%" -replace "\]")
|
||||
} catch {0}) `
|
||||
-and $percent -gt $oldpercent
|
||||
){
|
||||
) {
|
||||
# Update the progress bar
|
||||
$oldpercent = $percent
|
||||
Write-Progress -Id 1 -ParentId 0 -Activity "Scanning for corruption" -Status "Running DISM... ($percent%)" -PercentComplete $percent
|
||||
@ -137,7 +137,7 @@ function Invoke-WPFFixesUpdate {
|
||||
) -join ''
|
||||
).TrimStart()} catch {0}
|
||||
) -and $percent -gt $oldpercent
|
||||
){
|
||||
) {
|
||||
# Update the progress bar
|
||||
$oldpercent = $percent
|
||||
Write-Progress -Id 1 -ParentId 0 -Activity "Scanning for corruption" -Status "Running SFC... ($percent%)" -PercentComplete $percent
|
||||
|
@ -10,13 +10,13 @@ function Invoke-WPFGetInstalled {
|
||||
#>
|
||||
param($checkbox)
|
||||
|
||||
if($sync.ProcessRunning){
|
||||
if($sync.ProcessRunning) {
|
||||
$msg = "[Invoke-WPFGetInstalled] Install process is currently running."
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
|
||||
return
|
||||
}
|
||||
|
||||
if(((Test-WinUtilPackageManager -winget) -eq "not-installed") -and $checkbox -eq "winget"){
|
||||
if(((Test-WinUtilPackageManager -winget) -eq "not-installed") -and $checkbox -eq "winget") {
|
||||
return
|
||||
}
|
||||
|
||||
@ -26,17 +26,17 @@ function Invoke-WPFGetInstalled {
|
||||
$sync.ProcessRunning = $true
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" })
|
||||
|
||||
if($checkbox -eq "winget"){
|
||||
if($checkbox -eq "winget") {
|
||||
Write-Host "Getting Installed Programs..."
|
||||
}
|
||||
if($checkbox -eq "tweaks"){
|
||||
if($checkbox -eq "tweaks") {
|
||||
Write-Host "Getting Installed Tweaks..."
|
||||
}
|
||||
|
||||
$Checkboxes = Invoke-WinUtilCurrentSystem -CheckBox $checkbox
|
||||
|
||||
$sync.form.Dispatcher.invoke({
|
||||
foreach($checkbox in $Checkboxes){
|
||||
foreach($checkbox in $Checkboxes) {
|
||||
$sync.$checkbox.ischecked = $True
|
||||
}
|
||||
})
|
||||
|
@ -6,7 +6,7 @@ function Invoke-WPFGetIso {
|
||||
|
||||
Write-Host "Invoking WPFGetIso"
|
||||
|
||||
if($sync.ProcessRunning){
|
||||
if($sync.ProcessRunning) {
|
||||
$msg = "GetIso process is currently running."
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
|
||||
return
|
||||
@ -27,13 +27,11 @@ function Invoke-WPFGetIso {
|
||||
$oscdImgFound = [bool] (Get-Command -ErrorAction Ignore -Type Application oscdimg.exe) -or (Test-Path $oscdimgPath -PathType Leaf)
|
||||
Write-Host "oscdimg.exe on system: $oscdImgFound"
|
||||
|
||||
if (!$oscdImgFound)
|
||||
{
|
||||
if (!$oscdImgFound) {
|
||||
$downloadFromGitHub = $sync.WPFMicrowinDownloadFromGitHub.IsChecked
|
||||
$sync.BusyMessage.Visibility="Hidden"
|
||||
|
||||
if (!$downloadFromGitHub)
|
||||
{
|
||||
if (!$downloadFromGitHub) {
|
||||
# only show the message to people who did check the box to download from github, if you check the box
|
||||
# you consent to downloading it, no need to show extra dialogs
|
||||
[System.Windows.MessageBox]::Show("oscdimge.exe is not found on the system, winutil will now attempt do download and install it using choco. This might take a long time.")
|
||||
@ -42,8 +40,7 @@ function Invoke-WPFGetIso {
|
||||
Install-WinUtilChoco
|
||||
$chocoFound = [bool] (Get-Command -ErrorAction Ignore -Type Application choco)
|
||||
Write-Host "choco on system: $chocoFound"
|
||||
if (!$chocoFound)
|
||||
{
|
||||
if (!$chocoFound) {
|
||||
[System.Windows.MessageBox]::Show("choco.exe is not found on the system, you need choco to download oscdimg.exe")
|
||||
return
|
||||
}
|
||||
@ -51,8 +48,7 @@ function Invoke-WPFGetIso {
|
||||
Start-Process -Verb runas -FilePath powershell.exe -ArgumentList "choco install windows-adk-oscdimg"
|
||||
[System.Windows.MessageBox]::Show("oscdimg is installed, now close, reopen PowerShell terminal and re-launch winutil.ps1")
|
||||
return
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
[System.Windows.MessageBox]::Show("oscdimge.exe is not found on the system, winutil will now attempt do download and install it from github. This might take a long time.")
|
||||
Get-Oscdimg -oscdimgPath $oscdimgPath
|
||||
$oscdImgFound = Test-Path $oscdimgPath -PathType Leaf
|
||||
@ -60,8 +56,7 @@ function Invoke-WPFGetIso {
|
||||
$msg = "oscdimg was not downloaded can not proceed"
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
|
||||
return
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Write-Host "oscdimg.exe was successfully downloaded from github"
|
||||
}
|
||||
}
|
||||
@ -74,16 +69,14 @@ function Invoke-WPFGetIso {
|
||||
$openFileDialog.ShowDialog() | Out-Null
|
||||
$filePath = $openFileDialog.FileName
|
||||
|
||||
if ([string]::IsNullOrEmpty($filePath))
|
||||
{
|
||||
if ([string]::IsNullOrEmpty($filePath)) {
|
||||
Write-Host "No ISO is chosen"
|
||||
$sync.BusyMessage.Visibility="Hidden"
|
||||
return
|
||||
}
|
||||
|
||||
Write-Host "File path $($filePath)"
|
||||
if (-not (Test-Path -Path $filePath -PathType Leaf))
|
||||
{
|
||||
if (-not (Test-Path -Path $filePath -PathType Leaf)) {
|
||||
$msg = "File you've chosen doesn't exist"
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
|
||||
return
|
||||
@ -98,20 +91,16 @@ function Invoke-WPFGetIso {
|
||||
# This is done to guarantee a dynamic solution, as the installation drive may be mounted to a letter different than C
|
||||
$driveSpace = (Get-Volume -DriveLetter ([IO.Path]::GetPathRoot([Environment]::GetFolderPath([Environment+SpecialFolder]::UserProfile)).Replace(":\", "").Trim())).SizeRemaining
|
||||
Write-Debug "Free space on installation drive: $($driveSpace) bytes"
|
||||
if ($driveSpace -lt ($isoSize * 2))
|
||||
{
|
||||
if ($driveSpace -lt ($isoSize * 2)) {
|
||||
# It's not critical and we _may_ continue. Output a warning
|
||||
Write-Warning "You may not have enough space for this operation. Proceed at your own risk."
|
||||
}
|
||||
elseif ($driveSpace -lt $isoSize)
|
||||
{
|
||||
elseif ($driveSpace -lt $isoSize) {
|
||||
# It's critical and we can't continue. Output an error
|
||||
Write-Host "You don't have enough space for this operation. You need at least $([Math]::Round(($isoSize / ([Math]::Pow(1024, 2))) * 2, 2)) MB of free space to copy the ISO files to a temp directory and to be able to perform additional operations."
|
||||
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
|
||||
return
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Write-Host "You have enough space for this operation."
|
||||
}
|
||||
|
||||
@ -151,14 +140,12 @@ function Invoke-WPFGetIso {
|
||||
}
|
||||
|
||||
# Detect if the folders already exist and remove them
|
||||
if (($sync.MicrowinMountDir.Text -ne "") -and (Test-Path -Path $sync.MicrowinMountDir.Text))
|
||||
{
|
||||
if (($sync.MicrowinMountDir.Text -ne "") -and (Test-Path -Path $sync.MicrowinMountDir.Text)) {
|
||||
try {
|
||||
Write-Host "Deleting temporary files from previous run. Please wait..."
|
||||
Remove-Item -Path $sync.MicrowinMountDir.Text -Recurse -Force
|
||||
Remove-Item -Path $sync.MicrowinScratchDir.Text -Recurse -Force
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
Write-Host "Could not delete temporary files. You need to delete those manually."
|
||||
}
|
||||
}
|
||||
@ -199,16 +186,14 @@ function Invoke-WPFGetIso {
|
||||
$wimFile = "$mountDir\sources\install.wim"
|
||||
Write-Host "Getting image information $wimFile"
|
||||
|
||||
if ((-not (Test-Path -Path $wimFile -PathType Leaf)) -and (-not (Test-Path -Path $wimFile.Replace(".wim", ".esd").Trim() -PathType Leaf)))
|
||||
{
|
||||
if ((-not (Test-Path -Path $wimFile -PathType Leaf)) -and (-not (Test-Path -Path $wimFile.Replace(".wim", ".esd").Trim() -PathType Leaf))) {
|
||||
$msg = "Neither install.wim nor install.esd exist in the image, this could happen if you use unofficial Windows images. Please don't use shady images from the internet, use only official images. Here are instructions how to download ISO images if the Microsoft website is not showing the link to download and ISO. https://www.techrepublic.com/article/how-to-download-a-windows-10-iso-file-without-using-the-media-creation-tool/"
|
||||
Write-Host $msg
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
|
||||
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
|
||||
throw
|
||||
}
|
||||
elseif ((-not (Test-Path -Path $wimFile -PathType Leaf)) -and (Test-Path -Path $wimFile.Replace(".wim", ".esd").Trim() -PathType Leaf))
|
||||
{
|
||||
elseif ((-not (Test-Path -Path $wimFile -PathType Leaf)) -and (Test-Path -Path $wimFile.Replace(".wim", ".esd").Trim() -PathType Leaf)) {
|
||||
Write-Host "Install.esd found on the image. It needs to be converted to a WIM file in order to begin processing"
|
||||
$wimFile = $wimFile.Replace(".wim", ".esd").Trim()
|
||||
}
|
||||
@ -221,8 +206,7 @@ function Invoke-WPFGetIso {
|
||||
$sync.MicrowinWindowsFlavors.SelectedIndex = 0
|
||||
Write-Host "Finding suitable Pro edition. This can take some time. Do note that this is an automatic process that might not select the edition you want."
|
||||
Get-WindowsImage -ImagePath $wimFile | ForEach-Object {
|
||||
if ((Get-WindowsImage -ImagePath $wimFile -Index $_.ImageIndex).EditionId -eq "Professional")
|
||||
{
|
||||
if ((Get-WindowsImage -ImagePath $wimFile -Index $_.ImageIndex).EditionId -eq "Professional") {
|
||||
# We have found the Pro edition
|
||||
$sync.MicrowinWindowsFlavors.SelectedIndex = $_.ImageIndex - 1
|
||||
}
|
||||
@ -247,5 +231,3 @@ function Invoke-WPFGetIso {
|
||||
$sync.ProcessRunning = $false
|
||||
Set-WinUtilTaskbaritem -state "None" -overlay "checkmark"
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,31 +19,30 @@ function Invoke-WPFImpex {
|
||||
$Config = $null
|
||||
)
|
||||
|
||||
if ($type -eq "export"){
|
||||
if ($type -eq "export") {
|
||||
$FileBrowser = New-Object System.Windows.Forms.SaveFileDialog
|
||||
}
|
||||
if ($type -eq "import"){
|
||||
if ($type -eq "import") {
|
||||
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog
|
||||
}
|
||||
|
||||
if (-not $Config){
|
||||
if (-not $Config) {
|
||||
$FileBrowser.InitialDirectory = [Environment]::GetFolderPath('Desktop')
|
||||
$FileBrowser.Filter = "JSON Files (*.json)|*.json"
|
||||
$FileBrowser.ShowDialog() | Out-Null
|
||||
|
||||
if($FileBrowser.FileName -eq ""){
|
||||
if($FileBrowser.FileName -eq "") {
|
||||
return
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$Config = $FileBrowser.FileName
|
||||
}
|
||||
}
|
||||
|
||||
if ($type -eq "export"){
|
||||
if ($type -eq "export") {
|
||||
$jsonFile = Get-WinUtilCheckBoxes -unCheck $false
|
||||
$jsonFile | ConvertTo-Json | Out-File $FileBrowser.FileName -Force
|
||||
}
|
||||
if ($type -eq "import"){
|
||||
if ($type -eq "import") {
|
||||
$jsonFile = Get-Content $Config | ConvertFrom-Json
|
||||
|
||||
$flattenedJson = @()
|
||||
|
@ -6,7 +6,7 @@ function Invoke-WPFInstall {
|
||||
|
||||
#>
|
||||
|
||||
if($sync.ProcessRunning){
|
||||
if($sync.ProcessRunning) {
|
||||
$msg = "[Invoke-WPFInstall] An Install process is currently running."
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
|
||||
return
|
||||
@ -23,7 +23,7 @@ function Invoke-WPFInstall {
|
||||
|
||||
Invoke-WPFRunspace -ArgumentList $PackagesToInstall -DebugPreference $DebugPreference -ScriptBlock {
|
||||
param($PackagesToInstall, $DebugPreference)
|
||||
if ($PackagesToInstall.count -eq 1){
|
||||
if ($PackagesToInstall.count -eq 1) {
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" -value 0.01 -overlay "logo" })
|
||||
} else {
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value 0.01 -overlay "logo" })
|
||||
@ -43,15 +43,15 @@ function Invoke-WPFInstall {
|
||||
return $packagesWinget, $packagesChoco
|
||||
}.Invoke($PackagesToInstall)
|
||||
|
||||
try{
|
||||
try {
|
||||
$sync.ProcessRunning = $true
|
||||
$errorPackages = @()
|
||||
if($packagesWinget.Count -gt 0){
|
||||
if($packagesWinget.Count -gt 0) {
|
||||
Install-WinUtilWinget
|
||||
$errorPackages += Invoke-WinUtilWingetProgram -Action Install -Programs $packagesWinget
|
||||
$errorPackages| ForEach-Object {if($_.choco -ne "na") {$packagesChoco += $_}}
|
||||
}
|
||||
if($packagesChoco.Count -gt 0){
|
||||
if($packagesChoco.Count -gt 0) {
|
||||
Install-WinUtilChoco
|
||||
Install-WinUtilProgramChoco -ProgramsToInstall $packagesChoco
|
||||
}
|
||||
@ -59,8 +59,7 @@ function Invoke-WPFInstall {
|
||||
Write-Host "-- Installs have finished ---"
|
||||
Write-Host "==========================================="
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" -overlay "checkmark" })
|
||||
}
|
||||
Catch {
|
||||
} catch {
|
||||
Write-Host "==========================================="
|
||||
Write-Host "Error: $_"
|
||||
Write-Host "==========================================="
|
||||
|
@ -5,11 +5,11 @@ function Invoke-WPFInstallUpgrade {
|
||||
Invokes the function that upgrades all installed programs using winget
|
||||
|
||||
#>
|
||||
if((Test-WinUtilPackageManager -winget) -eq "not-installed"){
|
||||
if((Test-WinUtilPackageManager -winget) -eq "not-installed") {
|
||||
return
|
||||
}
|
||||
|
||||
if(Get-WinUtilInstallerProcess -Process $global:WinGetInstall){
|
||||
if(Get-WinUtilInstallerProcess -Process $global:WinGetInstall) {
|
||||
$msg = "[Invoke-WPFInstallUpgrade] Install process is currently running. Please check for a powershell window labeled 'Winget Install'"
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
|
||||
return
|
||||
|
@ -63,18 +63,14 @@ public class PowerManagement {
|
||||
$scratchDir = $sync.MicrowinScratchDir.Text
|
||||
|
||||
# Detect if the Windows image is an ESD file and convert it to WIM
|
||||
if (-not (Test-Path -Path $mountDir\sources\install.wim -PathType Leaf) -and (Test-Path -Path $mountDir\sources\install.esd -PathType Leaf))
|
||||
{
|
||||
if (-not (Test-Path -Path $mountDir\sources\install.wim -PathType Leaf) -and (Test-Path -Path $mountDir\sources\install.esd -PathType Leaf)) {
|
||||
Write-Host "Exporting Windows image to a WIM file, keeping the index we want to work on. This can take several minutes, depending on the performance of your computer..."
|
||||
Export-WindowsImage -SourceImagePath $mountDir\sources\install.esd -SourceIndex $index -DestinationImagePath $mountDir\sources\install.wim -CompressionType "Max"
|
||||
if ($?)
|
||||
{
|
||||
if ($?) {
|
||||
Remove-Item -Path $mountDir\sources\install.esd -Force
|
||||
# Since we've already exported the image index we wanted, switch to the first one
|
||||
$index = 1
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$msg = "The export process has failed and MicroWin processing cannot continue"
|
||||
Write-Host "Failed to export the image"
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
|
||||
@ -86,8 +82,7 @@ public class PowerManagement {
|
||||
$imgVersion = (Get-WindowsImage -ImagePath $mountDir\sources\install.wim -Index $index).Version
|
||||
|
||||
# Detect image version to avoid performing MicroWin processing on Windows 8 and earlier
|
||||
if ((Test-CompatibleImage $imgVersion $([System.Version]::new(10,0,10240,0))) -eq $false)
|
||||
{
|
||||
if ((Test-CompatibleImage $imgVersion $([System.Version]::new(10,0,10240,0))) -eq $false) {
|
||||
$msg = "This image is not compatible with MicroWin processing. Make sure it isn't a Windows 8 or earlier image."
|
||||
$dlg_msg = $msg + "`n`nIf you want more information, the version of the image selected is $($imgVersion)`n`nIf an image has been incorrectly marked as incompatible, report an issue to the developers."
|
||||
Write-Host $msg
|
||||
@ -98,8 +93,7 @@ public class PowerManagement {
|
||||
|
||||
$mountDirExists = Test-Path $mountDir
|
||||
$scratchDirExists = Test-Path $scratchDir
|
||||
if (-not $mountDirExists -or -not $scratchDirExists)
|
||||
{
|
||||
if (-not $mountDirExists -or -not $scratchDirExists) {
|
||||
Write-Error "Required directories '$mountDirExists' '$scratchDirExists' and do not exist."
|
||||
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
|
||||
return
|
||||
@ -109,68 +103,49 @@ public class PowerManagement {
|
||||
|
||||
Write-Host "Mounting Windows image. This may take a while."
|
||||
Mount-WindowsImage -ImagePath "$mountDir\sources\install.wim" -Index $index -Path "$scratchDir"
|
||||
if ($?)
|
||||
{
|
||||
if ($?) {
|
||||
Write-Host "Mounting complete! Performing removal of applications..."
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Write-Host "Could not mount image. Exiting..."
|
||||
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
|
||||
return
|
||||
}
|
||||
|
||||
if ($importDrivers)
|
||||
{
|
||||
if ($importDrivers) {
|
||||
Write-Host "Exporting drivers from active installation..."
|
||||
if (Test-Path "$env:TEMP\DRV_EXPORT")
|
||||
{
|
||||
if (Test-Path "$env:TEMP\DRV_EXPORT") {
|
||||
Remove-Item "$env:TEMP\DRV_EXPORT" -Recurse -Force
|
||||
}
|
||||
if (($injectDrivers -and (Test-Path $sync.MicrowinDriverLocation.Text)))
|
||||
{
|
||||
if (($injectDrivers -and (Test-Path $sync.MicrowinDriverLocation.Text))) {
|
||||
Write-Host "Using specified driver source..."
|
||||
dism /english /online /export-driver /destination="$($sync.MicrowinDriverLocation.Text)" | Out-Host
|
||||
if ($?)
|
||||
{
|
||||
if ($?) {
|
||||
# Don't add exported drivers yet, that is run later
|
||||
Write-Host "Drivers have been exported successfully."
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Write-Host "Failed to export drivers."
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
New-Item -Path "$env:TEMP\DRV_EXPORT" -ItemType Directory -Force
|
||||
dism /english /online /export-driver /destination="$env:TEMP\DRV_EXPORT" | Out-Host
|
||||
if ($?)
|
||||
{
|
||||
if ($?) {
|
||||
Write-Host "Adding exported drivers..."
|
||||
dism /english /image="$scratchDir" /add-driver /driver="$env:TEMP\DRV_EXPORT" /recurse | Out-Host
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Write-Host "Failed to export drivers. Continuing without importing them..."
|
||||
}
|
||||
if (Test-Path "$env:TEMP\DRV_EXPORT")
|
||||
{
|
||||
if (Test-Path "$env:TEMP\DRV_EXPORT") {
|
||||
Remove-Item "$env:TEMP\DRV_EXPORT" -Recurse -Force
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($injectDrivers)
|
||||
{
|
||||
if ($injectDrivers) {
|
||||
$driverPath = $sync.MicrowinDriverLocation.Text
|
||||
if (Test-Path $driverPath)
|
||||
{
|
||||
if (Test-Path $driverPath) {
|
||||
Write-Host "Adding Windows Drivers image($scratchDir) drivers($driverPath) "
|
||||
dism /English /image:$scratchDir /add-driver /driver:$driverPath /recurse | Out-Host
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Write-Host "Path to drivers is invalid continuing without driver injection"
|
||||
}
|
||||
}
|
||||
@ -179,13 +154,11 @@ public class PowerManagement {
|
||||
Remove-Features -keepDefender:$keepDefender
|
||||
Write-Host "Removing features complete!"
|
||||
|
||||
if (!$keepPackages)
|
||||
{
|
||||
if (!$keepPackages) {
|
||||
Write-Host "Removing OS packages"
|
||||
Remove-Packages
|
||||
}
|
||||
if (!$keepProvisionedPackages)
|
||||
{
|
||||
if (!$keepProvisionedPackages) {
|
||||
Write-Host "Removing Appx Bloat"
|
||||
Remove-ProvisionedPackages -keepSecurity:$keepDefender
|
||||
}
|
||||
@ -196,14 +169,12 @@ public class PowerManagement {
|
||||
Remove-FileOrDirectory -pathToDelete "$($scratchDir)\Windows\System32\WebThreatDefSvc" -Directory
|
||||
|
||||
# Defender is hidden in 2 places we removed a feature above now need to remove it from the disk
|
||||
if (!$keepDefender)
|
||||
{
|
||||
if (!$keepDefender) {
|
||||
Write-Host "Removing Defender"
|
||||
Remove-FileOrDirectory -pathToDelete "$($scratchDir)\Program Files\Windows Defender" -Directory
|
||||
Remove-FileOrDirectory -pathToDelete "$($scratchDir)\Program Files (x86)\Windows Defender"
|
||||
}
|
||||
if (!$keepEdge)
|
||||
{
|
||||
if (!$keepEdge) {
|
||||
Write-Host "Removing Edge"
|
||||
Remove-FileOrDirectory -pathToDelete "$($scratchDir)\Program Files (x86)\Microsoft" -mask "*edge*" -Directory
|
||||
Remove-FileOrDirectory -pathToDelete "$($scratchDir)\Program Files\Microsoft" -mask "*edge*" -Directory
|
||||
@ -311,16 +282,14 @@ public class PowerManagement {
|
||||
reg add "HKLM\zSYSTEM\Setup\LabConfig" /v "BypassTPMCheck" /t REG_DWORD /d 1 /f
|
||||
reg add "HKLM\zSYSTEM\Setup\MoSetup" /v "AllowUpgradesWithUnsupportedTPMOrCPU" /t REG_DWORD /d 1 /f
|
||||
|
||||
if (!$keepEdge)
|
||||
{
|
||||
if (!$keepEdge) {
|
||||
Write-Host "Removing Edge icon from taskbar"
|
||||
reg delete "HKLM\zSOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Taskband" /v "Favorites" /f >$null 2>&1
|
||||
reg delete "HKLM\zSOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Taskband" /v "FavoritesChanges" /f >$null 2>&1
|
||||
reg delete "HKLM\zSOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Taskband" /v "Pinned" /f >$null 2>&1
|
||||
reg delete "HKLM\zSOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Taskband" /v "LayoutCycle" /f >$null 2>&1
|
||||
Write-Host "Edge icon removed from taskbar"
|
||||
if (Test-Path "HKLM:\zSOFTWARE\WOW6432Node")
|
||||
{
|
||||
if (Test-Path "HKLM:\zSOFTWARE\WOW6432Node") {
|
||||
# Remove leftovers of 64-bit installations
|
||||
# ---
|
||||
# Remove registry values first...
|
||||
@ -383,8 +352,7 @@ public class PowerManagement {
|
||||
Remove-Item "$mountDir\sources\install.wim"
|
||||
Rename-Item "$mountDir\sources\install2.wim" "$mountDir\sources\install.wim"
|
||||
|
||||
if (-not (Test-Path -Path "$mountDir\sources\install.wim"))
|
||||
{
|
||||
if (-not (Test-Path -Path "$mountDir\sources\install.wim")) {
|
||||
Write-Error "Something went wrong and '$mountDir\sources\install.wim' doesn't exist. Please report this bug to the devs"
|
||||
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
|
||||
return
|
||||
@ -395,16 +363,12 @@ public class PowerManagement {
|
||||
Write-Host "Mounting boot image $mountDir\sources\boot.wim into $scratchDir"
|
||||
Mount-WindowsImage -ImagePath "$mountDir\sources\boot.wim" -Index 2 -Path "$scratchDir"
|
||||
|
||||
if ($injectDrivers)
|
||||
{
|
||||
if ($injectDrivers) {
|
||||
$driverPath = $sync.MicrowinDriverLocation.Text
|
||||
if (Test-Path $driverPath)
|
||||
{
|
||||
if (Test-Path $driverPath) {
|
||||
Write-Host "Adding Windows Drivers image($scratchDir) drivers($driverPath) "
|
||||
dism /English /image:$scratchDir /add-driver /driver:$driverPath /recurse | Out-Host
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Write-Host "Path to drivers is invalid continuing without driver injection"
|
||||
}
|
||||
}
|
||||
@ -447,8 +411,7 @@ public class PowerManagement {
|
||||
# if it is not in temp it is part of ADK and is in global PATH so just set it to oscdimg.exe
|
||||
$oscdimgPath = Join-Path $env:TEMP 'oscdimg.exe'
|
||||
$oscdImgFound = Test-Path $oscdimgPath -PathType Leaf
|
||||
if (!$oscdImgFound)
|
||||
{
|
||||
if (!$oscdImgFound) {
|
||||
$oscdimgPath = "oscdimg.exe"
|
||||
}
|
||||
|
||||
@ -460,8 +423,7 @@ public class PowerManagement {
|
||||
|
||||
Write-Host "OSCDIMG Error Level : $($oscdimgProc.ExitCode)"
|
||||
|
||||
if ($copyToUSB)
|
||||
{
|
||||
if ($copyToUSB) {
|
||||
Write-Host "Copying target ISO to the USB drive"
|
||||
Copy-ToUSB("$($SaveDialog.FileName)")
|
||||
if ($?) { Write-Host "Done Copying target ISO to USB drive!" } else { Write-Host "ISO copy failed." }
|
||||
@ -485,15 +447,12 @@ public class PowerManagement {
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
|
||||
} else {
|
||||
Write-Host "ISO creation failed. The "$($mountDir)" directory has not been removed."
|
||||
try
|
||||
{
|
||||
try {
|
||||
# This creates a new Win32 exception from which we can extract a message in the system language.
|
||||
# Now, this will NOT throw an exception
|
||||
$exitCode = New-Object System.ComponentModel.Win32Exception($LASTEXITCODE)
|
||||
Write-Host "Reason: $($exitCode.Message)"
|
||||
}
|
||||
catch
|
||||
{
|
||||
} catch {
|
||||
# Could not get error description from Windows APIs
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,7 @@ function Invoke-WPFOOSU {
|
||||
Invoke-WebRequest -Uri "https://dl5.oo-software.com/files/ooshutup10/OOSU10.exe" -OutFile $OOSU_filepath
|
||||
Write-Host "Starting OO Shutup 10 ..."
|
||||
Start-Process $OOSU_filepath
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
Write-Host "Error Downloading and Running OO Shutup 10" -ForegroundColor Red
|
||||
}
|
||||
finally {
|
||||
|
@ -20,10 +20,9 @@ function Invoke-WPFPresets {
|
||||
[bool]$imported = $false
|
||||
)
|
||||
|
||||
if($imported -eq $true){
|
||||
if($imported -eq $true) {
|
||||
$CheckBoxesToCheck = $preset
|
||||
}
|
||||
Else{
|
||||
} else {
|
||||
$CheckBoxesToCheck = $sync.configs.preset.$preset
|
||||
}
|
||||
|
||||
@ -39,8 +38,7 @@ function Invoke-WPFPresets {
|
||||
foreach ($CheckBox in $CheckBoxes) {
|
||||
$checkboxName = $CheckBox.Key
|
||||
|
||||
if (-not $CheckBoxesToCheck)
|
||||
{
|
||||
if (-not $CheckBoxesToCheck) {
|
||||
$sync.$checkboxName.IsChecked = $false
|
||||
continue
|
||||
}
|
||||
|
@ -38,8 +38,7 @@ function Invoke-WPFRunspace {
|
||||
$script:handle = $script:powershell.BeginInvoke()
|
||||
|
||||
# Clean up the RunspacePool threads when they are complete, and invoke the garbage collector to clean up the memory
|
||||
if ($script:handle.IsCompleted)
|
||||
{
|
||||
if ($script:handle.IsCompleted) {
|
||||
$script:powershell.EndInvoke($script:handle)
|
||||
$script:powershell.Dispose()
|
||||
$sync.runspace.Dispose()
|
||||
|
@ -21,10 +21,9 @@ function Invoke-WPFShortcut {
|
||||
Switch ($ShortcutToAdd) {
|
||||
"WinUtil" {
|
||||
# Use Powershell 7 if installed and fallback to PS5 if not
|
||||
if (Get-Command "pwsh" -ErrorAction SilentlyContinue){
|
||||
if (Get-Command "pwsh" -ErrorAction SilentlyContinue) {
|
||||
$shell = "pwsh.exe"
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$shell = "powershell.exe"
|
||||
}
|
||||
|
||||
|
@ -21,8 +21,7 @@ function Invoke-WPFTab {
|
||||
$sync[$PSItem.Name].IsChecked = $false
|
||||
# $tabNumber = [int]($PSItem.Name -replace "WPFTab","" -replace "BT","") - 1
|
||||
# $sync.$tabNav.Items[$tabNumber].IsSelected = $false
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$sync["$ClickedTab"].IsChecked = $true
|
||||
$tabNumber = [int]($ClickedTab-replace "WPFTab","" -replace "BT","") - 1
|
||||
$sync.$tabNav.Items[$tabNumber].IsSelected = $true
|
||||
|
@ -15,7 +15,7 @@ function Invoke-WPFToggle {
|
||||
# Use this to get the name of the button
|
||||
#[System.Windows.MessageBox]::Show("$Button","Chris Titus Tech's Windows Utility","OK","Info")
|
||||
|
||||
Switch -Wildcard ($Button){
|
||||
Switch -Wildcard ($Button) {
|
||||
|
||||
"WPFToggleDarkMode" {Invoke-WinUtilDarkMode -DarkMoveEnabled $(Get-WinUtilToggleStatus WPFToggleDarkMode)}
|
||||
"WPFToggleBingSearch" {Invoke-WinUtilBingSearch $(Get-WinUtilToggleStatus WPFToggleBingSearch)}
|
||||
|
@ -26,13 +26,13 @@ function Invoke-WPFTweakPS7{
|
||||
}
|
||||
}
|
||||
# Check if the Windows Terminal is installed and return if not (Prerequisite for the following code)
|
||||
if (-not (Get-Command "wt" -ErrorAction SilentlyContinue)){
|
||||
if (-not (Get-Command "wt" -ErrorAction SilentlyContinue)) {
|
||||
Write-Host "Windows Terminal not installed. Skipping Terminal preference"
|
||||
return
|
||||
}
|
||||
# Check if the Windows Terminal settings.json file exists and return if not (Prereqisite for the following code)
|
||||
$settingsPath = "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json"
|
||||
if (-not (Test-Path -Path $settingsPath)){
|
||||
if (-not (Test-Path -Path $settingsPath)) {
|
||||
Write-Host "Windows Terminal Settings file not found at $settingsPath"
|
||||
return
|
||||
}
|
||||
|
@ -9,10 +9,10 @@ Function Invoke-WPFUltimatePerformance {
|
||||
|
||||
#>
|
||||
param($State)
|
||||
Try{
|
||||
try {
|
||||
# Check if Ultimate Performance plan is installed
|
||||
$ultimatePlan = powercfg -list | Select-String -Pattern "Ultimate Performance"
|
||||
if($state -eq "Enable"){
|
||||
if($state -eq "Enable") {
|
||||
if ($ultimatePlan) {
|
||||
Write-Host "Ultimate Performance plan is already installed."
|
||||
} else {
|
||||
@ -29,7 +29,7 @@ Function Invoke-WPFUltimatePerformance {
|
||||
|
||||
|
||||
}
|
||||
elseif($state -eq "Disable"){
|
||||
elseif($state -eq "Disable") {
|
||||
if ($ultimatePlan) {
|
||||
# Extract the GUID of the Ultimate Performance plan
|
||||
$ultimatePlanGUID = $ultimatePlan.Line.Split()[3]
|
||||
@ -47,7 +47,7 @@ Function Invoke-WPFUltimatePerformance {
|
||||
Write-Host "Ultimate Performance plan is not installed."
|
||||
}
|
||||
}
|
||||
} Catch{
|
||||
} catch {
|
||||
Write-Warning $psitem.Exception.Message
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ function Invoke-WPFUnInstall {
|
||||
|
||||
#>
|
||||
|
||||
if($sync.ProcessRunning){
|
||||
if($sync.ProcessRunning) {
|
||||
$msg = "[Invoke-WPFUnInstall] Install process is currently running"
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
|
||||
return
|
||||
@ -27,12 +27,12 @@ function Invoke-WPFUnInstall {
|
||||
|
||||
$confirm = [System.Windows.MessageBox]::Show($Messageboxbody, $MessageboxTitle, $ButtonType, $MessageIcon)
|
||||
|
||||
if($confirm -eq "No"){return}
|
||||
if($confirm -eq "No") {return}
|
||||
|
||||
|
||||
Invoke-WPFRunspace -ArgumentList $PackagesToInstall -DebugPreference $DebugPreference -ScriptBlock {
|
||||
param($PackagesToInstall, $DebugPreference)
|
||||
if ($PackagesToInstall.count -eq 1){
|
||||
if ($PackagesToInstall.count -eq 1) {
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" -value 0.01 -overlay "logo" })
|
||||
} else {
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value 0.01 -overlay "logo" })
|
||||
@ -51,14 +51,14 @@ function Invoke-WPFUnInstall {
|
||||
}
|
||||
return $packagesWinget, $packagesChoco
|
||||
}.Invoke($PackagesToInstall)
|
||||
try{
|
||||
try {
|
||||
$sync.ProcessRunning = $true
|
||||
|
||||
# Install all selected programs in new window
|
||||
if($packagesWinget.Count -gt 0){
|
||||
if($packagesWinget.Count -gt 0) {
|
||||
Invoke-WinUtilWingetProgram -Action Uninstall -Programs $packagesWinget
|
||||
}
|
||||
if($packagesChoco.Count -gt 0){
|
||||
if($packagesChoco.Count -gt 0) {
|
||||
Install-WinUtilProgramChoco -ProgramsToInstall $packagesChoco -Manage "Uninstalling"
|
||||
}
|
||||
|
||||
@ -66,8 +66,7 @@ function Invoke-WPFUnInstall {
|
||||
Write-Host "-- Uninstalls have finished ---"
|
||||
Write-Host "==========================================="
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" -overlay "checkmark" })
|
||||
}
|
||||
Catch {
|
||||
} catch {
|
||||
Write-Host "==========================================="
|
||||
Write-Host "Error: $_"
|
||||
Write-Host "==========================================="
|
||||
|
@ -6,7 +6,7 @@ function Invoke-WPFtweaksbutton {
|
||||
|
||||
#>
|
||||
|
||||
if($sync.ProcessRunning){
|
||||
if($sync.ProcessRunning) {
|
||||
$msg = "[Invoke-WPFtweaksbutton] Install process is currently running."
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
|
||||
return
|
||||
@ -16,7 +16,7 @@ function Invoke-WPFtweaksbutton {
|
||||
|
||||
Set-WinUtilDNS -DNSProvider $sync["WPFchangedns"].text
|
||||
|
||||
if ($tweaks.count -eq 0 -and $sync["WPFchangedns"].text -eq "Default"){
|
||||
if ($tweaks.count -eq 0 -and $sync["WPFchangedns"].text -eq "Default") {
|
||||
$msg = "Please check the tweaks you wish to perform."
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
|
||||
return
|
||||
@ -30,17 +30,16 @@ function Invoke-WPFtweaksbutton {
|
||||
|
||||
$sync.ProcessRunning = $true
|
||||
|
||||
if ($Tweaks.count -eq 1){
|
||||
if ($Tweaks.count -eq 1) {
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" -value 0.01 -overlay "logo" })
|
||||
} else {
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value 0.01 -overlay "logo" })
|
||||
}
|
||||
# Execute other selected tweaks
|
||||
|
||||
for ($i = 0; $i -lt $Tweaks.Count; $i++){
|
||||
for ($i = 0; $i -lt $Tweaks.Count; $i++) {
|
||||
Set-WinUtilProgressBar -Label "Applying $($tweaks[$i])" -Percent ($i / $Tweaks.Count * 100)
|
||||
Invoke-WinUtilTweaks $tweaks[$i]
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -value ($i/$Tweaks.Count) })
|
||||
Invoke-WinUtilTweaks $tweaks[$i]$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -value ($i/$Tweaks.Count) })
|
||||
}
|
||||
Set-WinUtilProgressBar -Label "Tweaks finished" -Percent 100
|
||||
$sync.ProcessRunning = $false
|
||||
|
@ -6,7 +6,7 @@ function Invoke-WPFundoall {
|
||||
|
||||
#>
|
||||
|
||||
if($sync.ProcessRunning){
|
||||
if($sync.ProcessRunning) {
|
||||
$msg = "[Invoke-WPFundoall] Install process is currently running."
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
|
||||
return
|
||||
@ -14,7 +14,7 @@ function Invoke-WPFundoall {
|
||||
|
||||
$tweaks = (Get-WinUtilCheckBoxes)["WPFtweaks"]
|
||||
|
||||
if ($tweaks.count -eq 0){
|
||||
if ($tweaks.count -eq 0) {
|
||||
$msg = "Please check the tweaks you wish to undo."
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
|
||||
return
|
||||
@ -24,14 +24,14 @@ function Invoke-WPFundoall {
|
||||
param($tweaks, $DebugPreference)
|
||||
|
||||
$sync.ProcessRunning = $true
|
||||
if ($tweaks.count -eq 1){
|
||||
if ($tweaks.count -eq 1) {
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" -value 0.01 -overlay "logo" })
|
||||
} else {
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value 0.01 -overlay "logo" })
|
||||
}
|
||||
|
||||
|
||||
for ($i = 0; $i -lt $tweaks.Count; $i++){
|
||||
for ($i = 0; $i -lt $tweaks.Count; $i++) {
|
||||
Set-WinUtilProgressBar -Label "Undoing $($tweaks[$i])" -Percent ($i / $tweaks.Count * 100)
|
||||
Invoke-WinUtiltweaks $tweaks[$i] -undo $true
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -value ($i/$tweaks.Count) })
|
||||
|
@ -25,19 +25,19 @@ Describe "Config Files" -ForEach @(
|
||||
name = "tweaks"
|
||||
undo = $true
|
||||
}
|
||||
){
|
||||
) {
|
||||
Context "$name config file" {
|
||||
It "Imports with no errors" {
|
||||
$global:importedconfigs.$name | should -Not -BeNullOrEmpty
|
||||
}
|
||||
if ($config){
|
||||
if ($config) {
|
||||
It "Imports should be the correct structure" {
|
||||
$applications = $global:importedconfigs.$name | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty name
|
||||
$template = $config | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty name
|
||||
$result = New-Object System.Collections.Generic.List[System.Object]
|
||||
Foreach ($application in $applications) {
|
||||
$compare = $global:importedconfigs.$name.$application | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty name
|
||||
if ($(Compare-Object $compare $template) -ne $null){
|
||||
if ($(Compare-Object $compare $template) -ne $null) {
|
||||
$result.Add($application)
|
||||
}
|
||||
}
|
||||
@ -45,12 +45,12 @@ Describe "Config Files" -ForEach @(
|
||||
$result | Select-String "WPF*" | should -BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
if($undo){
|
||||
if($undo) {
|
||||
It "Tweaks should contain original Value" {
|
||||
$tweaks = $global:importedconfigs.$name | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty name
|
||||
$result = New-Object System.Collections.Generic.List[System.Object]
|
||||
|
||||
foreach ($tweak in $tweaks){
|
||||
foreach ($tweak in $tweaks) {
|
||||
$Originals = @(
|
||||
@{
|
||||
name = "registry"
|
||||
@ -65,10 +65,10 @@ Describe "Config Files" -ForEach @(
|
||||
value = "OriginalState"
|
||||
}
|
||||
)
|
||||
Foreach ($original in $Originals){
|
||||
Foreach ($original in $Originals) {
|
||||
$TotalCount = ($global:importedconfigs.$name.$tweak.$($original.name)).count
|
||||
$OriginalCount = ($global:importedconfigs.$name.$tweak.$($original.name).$($original.value) | Where-Object {$_}).count
|
||||
if($TotalCount -ne $OriginalCount){
|
||||
if($TotalCount -ne $OriginalCount) {
|
||||
$result.Add("$Tweak,$($original.name)")
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ $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){
|
||||
foreach ($function in $functions) {
|
||||
$functionDefinition = Get-Content function:\$($function.name)
|
||||
$functionEntry = New-Object System.Management.Automation.Runspaces.SessionStateFunctionEntry -ArgumentList $($function.name), $functionDefinition
|
||||
|
||||
@ -55,12 +55,10 @@ $inputXML = $inputXML -replace 'mc:Ignorable="d"', '' -replace "x:N", 'N' -repla
|
||||
if ((Get-WinUtilToggleStatus WPFToggleDarkMode) -eq $True) {
|
||||
if (Invoke-WinUtilGPU -eq $True) {
|
||||
$ctttheme = 'Matrix'
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$ctttheme = 'Dark'
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$ctttheme = 'Classic'
|
||||
}
|
||||
$inputXML = Set-WinUtilUITheme -inputXML $inputXML -themeName $ctttheme
|
||||
@ -90,9 +88,9 @@ try {
|
||||
$xaml.SelectNodes("//*[@Name]") | ForEach-Object {$sync["$("$($psitem.Name)")"] = $sync["Form"].FindName($psitem.Name)}
|
||||
|
||||
$sync.keys | ForEach-Object {
|
||||
if($sync.$psitem){
|
||||
if($sync.$psitem) {
|
||||
if($($sync["$psitem"].GetType() | Select-Object -ExpandProperty Name) -eq "CheckBox" `
|
||||
-and $sync["$psitem"].Name -like "WPFToggle*"){
|
||||
-and $sync["$psitem"].Name -like "WPFToggle*") {
|
||||
$sync["$psitem"].IsChecked = Get-WinUtilToggleStatus $sync["$psitem"].Name
|
||||
|
||||
$sync["$psitem"].Add_Click({
|
||||
@ -101,14 +99,14 @@ $sync.keys | ForEach-Object {
|
||||
})
|
||||
}
|
||||
|
||||
if($($sync["$psitem"].GetType() | Select-Object -ExpandProperty Name) -eq "ToggleButton"){
|
||||
if($($sync["$psitem"].GetType() | Select-Object -ExpandProperty Name) -eq "ToggleButton") {
|
||||
$sync["$psitem"].Add_Click({
|
||||
[System.Object]$Sender = $args[0]
|
||||
Invoke-WPFButton $Sender.name
|
||||
})
|
||||
}
|
||||
|
||||
if($($sync["$psitem"].GetType() | Select-Object -ExpandProperty Name) -eq "Button"){
|
||||
if($($sync["$psitem"].GetType() | Select-Object -ExpandProperty Name) -eq "Button") {
|
||||
$sync["$psitem"].Add_Click({
|
||||
[System.Object]$Sender = $args[0]
|
||||
Invoke-WPFButton $Sender.name
|
||||
@ -134,7 +132,7 @@ $sync.keys | ForEach-Object {
|
||||
|
||||
# Load computer information in the background
|
||||
Invoke-WPFRunspace -ScriptBlock {
|
||||
try{
|
||||
try {
|
||||
$oldProgressPreference = $ProgressPreference
|
||||
$ProgressPreference = "SilentlyContinue"
|
||||
$sync.ConfigLoaded = $False
|
||||
@ -179,8 +177,7 @@ $commonKeyEvents = {
|
||||
return
|
||||
}
|
||||
|
||||
if ($_.Key -eq "Escape")
|
||||
{
|
||||
if ($_.Key -eq "Escape") {
|
||||
$sync.SearchBar.SelectAll()
|
||||
$sync.SearchBar.Text = ""
|
||||
$sync.SearchBarClearButton.Visibility = "Collapsed"
|
||||
@ -188,8 +185,7 @@ $commonKeyEvents = {
|
||||
}
|
||||
|
||||
# don't ask, I know what I'm doing, just go...
|
||||
if (($_.Key -eq "Q" -and $_.KeyboardDevice.Modifiers -eq "Ctrl"))
|
||||
{
|
||||
if (($_.Key -eq "Q" -and $_.KeyboardDevice.Modifiers -eq "Ctrl")) {
|
||||
$this.Close()
|
||||
}
|
||||
if ($_.KeyboardDevice.Modifiers -eq "Alt") {
|
||||
@ -232,12 +228,9 @@ $sync["Form"].Add_MouseLeftButtonDown({
|
||||
})
|
||||
|
||||
$sync["Form"].Add_MouseDoubleClick({
|
||||
if ($sync["Form"].WindowState -eq [Windows.WindowState]::Normal)
|
||||
{
|
||||
if ($sync["Form"].WindowState -eq [Windows.WindowState]::Normal) {
|
||||
$sync["Form"].WindowState = [Windows.WindowState]::Maximized;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$sync["Form"].WindowState = [Windows.WindowState]::Normal;
|
||||
}
|
||||
})
|
||||
@ -328,9 +321,9 @@ Add-Type @"
|
||||
|
||||
# maybe this is not the best place to load and execute config file?
|
||||
# maybe community can help?
|
||||
if ($PARAM_CONFIG){
|
||||
if ($PARAM_CONFIG) {
|
||||
Invoke-WPFImpex -type "import" -Config $PARAM_CONFIG
|
||||
if ($PARAM_RUN){
|
||||
if ($PARAM_RUN) {
|
||||
while ($sync.ProcessRunning) {
|
||||
Start-Sleep -Seconds 5
|
||||
}
|
||||
@ -377,8 +370,7 @@ $sync["SearchBar"].Add_TextChanged({
|
||||
|
||||
if ($sync.SearchBar.Text -ne "") {
|
||||
$sync.SearchBarClearButton.Visibility = "Visible"
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$sync.SearchBarClearButton.Visibility = "Collapsed"
|
||||
}
|
||||
|
||||
@ -404,8 +396,7 @@ $sync["SearchBar"].Add_TextChanged({
|
||||
if ($textBlock -ne $null) {
|
||||
$textBlock.Visibility = "Visible"
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$CheckBox.Value.Visibility = "Collapsed"
|
||||
# Set the corresponding text block visibility
|
||||
if ($textBlock -ne $null) {
|
||||
@ -415,17 +406,16 @@ $sync["SearchBar"].Add_TextChanged({
|
||||
}
|
||||
$activeCategories = $activeApplications | Select-Object -ExpandProperty category -Unique
|
||||
|
||||
foreach ($category in $activeCategories){
|
||||
foreach ($category in $activeCategories) {
|
||||
$label = $labels[$(Get-WPFObjectName -type "Label" -name $category)]
|
||||
$label.Visibility = "Visible"
|
||||
}
|
||||
if ($activeCategories){
|
||||
if ($activeCategories) {
|
||||
$inactiveCategories = Compare-Object -ReferenceObject $allCategories -DifferenceObject $activeCategories -PassThru
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$inactiveCategories = $allCategories
|
||||
}
|
||||
foreach ($category in $inactiveCategories){
|
||||
foreach ($category in $inactiveCategories) {
|
||||
$label = $labels[$(Get-WPFObjectName -type "Label" -name $category)]
|
||||
$label.Visibility = "Collapsed"}
|
||||
})
|
||||
@ -471,8 +461,7 @@ $sync["SettingsButton"].Add_Click({
|
||||
Write-Debug "SettingsButton clicked"
|
||||
if ($sync["SettingsPopup"].IsOpen) {
|
||||
$sync["SettingsPopup"].IsOpen = $false
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$sync["SettingsPopup"].IsOpen = $true
|
||||
}
|
||||
$_.Handled = $false
|
||||
@ -528,8 +517,7 @@ $sync["SponsorMenuItem"].Add_Click({
|
||||
|
||||
# Append the sponsors to the authorInfo
|
||||
$sponsors | ForEach-Object { $authorInfo += "$_`n" }
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
$authorInfo += "An error occurred while fetching or processing the sponsors: $_`n"
|
||||
}
|
||||
|
||||
|
@ -45,8 +45,7 @@ $sync.configs = @{}
|
||||
$sync.ProcessRunning = $false
|
||||
|
||||
# If script isn't running as admin, show error message and quit
|
||||
If (([Security.Principal.WindowsIdentity]::GetCurrent()).Owner.Value -ne "S-1-5-32-544")
|
||||
{
|
||||
If (([Security.Principal.WindowsIdentity]::GetCurrent()).Owner.Value -ne "S-1-5-32-544") {
|
||||
Write-Host "===========================================" -Foregroundcolor Red
|
||||
Write-Host "-- Scripts must be run as Administrator ---" -Foregroundcolor Red
|
||||
Write-Host "-- Right-Click Start -> Terminal(Admin) ---" -Foregroundcolor Red
|
||||
|
139
tools/Invoke-Preprocessing.ps1
Normal file
139
tools/Invoke-Preprocessing.ps1
Normal file
@ -0,0 +1,139 @@
|
||||
function Invoke-Preprocessing {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
A function that does Code Formatting using RegEx, useful when trying to force specific coding standard(s) to a project.
|
||||
|
||||
.PARAMETER ThrowExceptionOnEmptyFilesList
|
||||
A switch which'll throw an exception upon not finding any files inside the provided 'WorkingDir'.
|
||||
|
||||
.PARAMETER SkipExcludedFilesValidation
|
||||
A switch to stop file path validation on 'ExcludedFiles' list.
|
||||
|
||||
.PARAMETER ExcludedFiles
|
||||
A list of file paths which're *relative to* 'WorkingDir' Folder, every item in the list can be pointing to File (doesn't end with '\') or Directory (ends with '\') or None-Existing File/Directory.
|
||||
By default, it checks if everyitem exists, and throws an exception if one or more are not found (None-Existing), if you want to skip this validation, please consider providing the '-SkipExcludedFilesValidation' switch to skip this check.
|
||||
|
||||
.PARAMETER WorkingDir
|
||||
The folder to search inside recursively for files which're going to be Preprocessed (Code Formatted), unless they're found in 'ExcludedFiles' List.
|
||||
Note: The path should be absolute, NOT relative.
|
||||
|
||||
.PARAMETER ProgressStatusMessage
|
||||
The status message used when displaying the progress bar, which's done through PowerShell 'Write-Progress' Cmdlet.
|
||||
This's a Required Parameter, as the information displayed to terminal is useful when running this function,
|
||||
which might take less than 1 sec to minutes depending on project's scale & hardware performance.
|
||||
|
||||
.PARAMETER ProgressActivity
|
||||
The activity message used when displaying the progress bar, which's done through PowerShell 'Write-Progress' Cmdlet,
|
||||
This's an Optional Parameter, default value is 'Preprocessing', used in combination with 'ProgressStatusMessage' Parameter Value.
|
||||
|
||||
.EXAMPLE
|
||||
Invoke-Preprocessing -WorkingDir "DRIVE:\Path\To\Folder\" -ExcludedFiles @('file.txt', '.\.git\', '*.png') -ProgressStatusMessage "Doing Preprocessing"
|
||||
|
||||
Calls 'Invoke-Preprocessing' function using Named Paramters, with 'WorkingDir' (Mandatory Parameter) which's used as the base folder when searching for files recursively (using 'Get-ChildItem'), other two paramters are, in order from right to left, the Optional 'ExcludeFiles', which can be a path to a file, folder, or pattern-matched (like '*.png'), and the 'ProgressStatusMessage', which's used in Progress Bar.
|
||||
|
||||
.EXAMPLE
|
||||
Invoke-Preprocessing -WorkingDir "DRIVE:\Path\To\Folder\" -ExcludedFiles @('file.txt', '.\.git\', '*.png') -ProgressStatusMessage "Doing Preprocessing" -ProgressActivity "Re-Formatting Code"
|
||||
|
||||
Same as Example No. 1, but uses 'ProgressActivity' which's used in Progress Bar.
|
||||
|
||||
.EXAMPLE
|
||||
Invoke-Preprocessing -ThrowExceptionOnEmptyFilesList -WorkingDir "DRIVE:\Path\To\Folder\" -ExcludedFiles @('file.txt', '.\.git\', '*.png') -ProgressStatusMessage "Doing Preprocessing"
|
||||
|
||||
Same as Example No. 1, but will throw an exception when 'Invoke-Preprocessing' function doesn't find any files in 'WorkingDir' (not including 'ExcludedFiles' list).
|
||||
|
||||
.EXAMPLE
|
||||
Invoke-Preprocessing -Skip -WorkingDir "DRIVE:\Path\To\Folder\" -ExcludedFiles @('file.txt', '.\.git\', '*.png') -ProgressStatusMessage "Doing Preprocessing"
|
||||
|
||||
Same as Example No. 1, but uses '-SkipExcludedFilesValidation', which'll skip the validation step for 'ExcludedFiles' list. This can be useful when 'ExcludedFiles' list is generated from another function, or from unreliable source (you can't guarantee every item in list is a valid path), but you want to silently continue through the function.
|
||||
#>
|
||||
|
||||
param (
|
||||
[Parameter(position=0)]
|
||||
[switch]$SkipExcludedFilesValidation,
|
||||
|
||||
[Parameter(position=1)]
|
||||
[switch]$ThrowExceptionOnEmptyFilesList,
|
||||
|
||||
[Parameter(Mandatory, position=2)]
|
||||
[ValidateScript({[System.IO.Path]::IsPathRooted($_)})]
|
||||
[string]$WorkingDir,
|
||||
|
||||
[Parameter(position=3)]
|
||||
[string[]]$ExcludedFiles,
|
||||
|
||||
[Parameter(Mandatory, position=4)]
|
||||
[string]$ProgressStatusMessage,
|
||||
|
||||
[Parameter(position=5)]
|
||||
[string]$ProgressActivity = "Preprocessing"
|
||||
)
|
||||
|
||||
if (-NOT (Test-Path -PathType Container -Path "$WorkingDir")) {
|
||||
throw "[Invoke-Preprocessing] Invalid Paramter Value for 'WorkingDir', passed value: '$WorkingDir'. Either the path is a File or Non-Existing/Invlid, please double check your code."
|
||||
}
|
||||
|
||||
$count = $ExcludedFiles.Count
|
||||
if ((-NOT ($count -eq 0)) -AND (-NOT $SkipExcludedFilesValidation)) {
|
||||
for ($i = 0; $i -lt $count; $i++) {
|
||||
$excludedFile = $ExcludedFiles[$i]
|
||||
$filePath = "$(($WorkingDir -replace ('\\$', '')) + '\' + ($excludedFile -replace ('\.\\', '')))"
|
||||
if (-NOT (Get-ChildItem -Recurse -Path "$filePath" -File)) {
|
||||
$failedFilesList += "'$filePath', "
|
||||
}
|
||||
}
|
||||
$failedFilesList = $failedFilesList -replace (',\s*$', '')
|
||||
if (-NOT $failedFilesList -eq "") {
|
||||
throw "[Invoke-Preprocessing] One or more File Paths & File Patterns were not found, you can use '-SkipExcludedFilesValidation' switch to skip this check, and the failed files are: $failedFilesList"
|
||||
}
|
||||
}
|
||||
|
||||
$files = Get-ChildItem $WorkingDir -Recurse -Exclude $ExcludedFiles -File
|
||||
$numOfFiles = $files.Count
|
||||
|
||||
if ($numOfFiles -eq 0) {
|
||||
if ($ThrowExceptionOnEmptyFilesList) {
|
||||
throw "[Invoke-Preprocessing] Found 0 Files to Preprocess inside 'WorkingDir' Directory and '-ThrowExceptionOnEmptyFilesList' Switch is provided, value of 'WorkingDir': '$WorkingDir'."
|
||||
} else {
|
||||
return # Do an early return, there's nothing else to do
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 0; $i -lt $numOfFiles; $i++) {
|
||||
$file = $files[$i]
|
||||
|
||||
# If the file is in Exclude List, don't proceed to check/modify said file.
|
||||
$fileIsExcluded = $False
|
||||
for ($j = 0; $j -lt $excludedFiles.Count; $j++) {
|
||||
$excluded = $excludedFiles[$j]
|
||||
$strToCompare = ($excluded) -replace ('^\.\\', '')
|
||||
if ($file.FullName.Contains("$strToCompare")) {
|
||||
$fileIsExcluded = $True
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if ($fileIsExcluded) {
|
||||
continue
|
||||
}
|
||||
|
||||
# TODO:
|
||||
# make more formatting rules, and document them in WinUtil Official Documentation
|
||||
(Get-Content "$file").TrimEnd() `
|
||||
-replace ('\t', ' ') `
|
||||
-replace ('\)\s*\{', ') {') `
|
||||
-replace ('(?<keyword>if|for|foreach)\s*(?<condition>\([.*?]\))\s*\{', '${keyword} ${condition} {') `
|
||||
-replace ('\}\s*elseif\s*(?<condition>\([.*?]\))\s*\{', '} elseif ${condition} {') `
|
||||
-replace ('\}\s*else\s*\{', '} else {') `
|
||||
-replace ('Try\s*\{', 'try {') `
|
||||
-replace ('Catch\s*\{', 'catch {') `
|
||||
-replace ('\}\s*Catch', '} catch') `
|
||||
-replace ('\}\s*Catch\s*(?<exceptions>(\[.*?\]\s*(\,)?\s*)+)\s*\{', '} catch ${exceptions} {') `
|
||||
-replace ('\}\s*Catch\s*(?<exceptions>\[.*?\])\s*\{', '} catch ${exceptions} {') `
|
||||
-replace ('(?<parameter_type>\[.*?\])\s*(?<str_after_type>\$.*?(,|\s*\)))', '${parameter_type}${str_after_type}') `
|
||||
| Set-Content "$file"
|
||||
|
||||
Write-Progress -Activity $ProgressActivity -Status "$ProgressStatusMessage - Finished $i out of $numOfFiles" -PercentComplete (($i/$numOfFiles)*100)
|
||||
}
|
||||
|
||||
Write-Progress -Activity $ProgressActivity -Status "$ProgressStatusMessage - Finished Task Successfully" -Completed
|
||||
}
|
Loading…
Reference in New Issue
Block a user