mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-12-25 07:21:30 -06:00
3903eaaa24
* 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
97 lines
3.8 KiB
PowerShell
97 lines
3.8 KiB
PowerShell
function Invoke-WinUtilTweaks {
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
Invokes the function associated with each provided checkbox
|
|
|
|
.PARAMETER CheckBox
|
|
The checkbox to invoke
|
|
|
|
.PARAMETER undo
|
|
Indicates whether to undo the operation contained in the checkbox
|
|
|
|
.PARAMETER KeepServiceStartup
|
|
Indicates whether to override the startup of a service with the one given from WinUtil,
|
|
or to keep the startup of said service, if it was changed by the user, or another program, from its default value.
|
|
#>
|
|
|
|
param(
|
|
$CheckBox,
|
|
$undo = $false,
|
|
$KeepServiceStartup = $true
|
|
)
|
|
|
|
Write-Debug "Tweaks: $($CheckBox)"
|
|
if($undo) {
|
|
$Values = @{
|
|
Registry = "OriginalValue"
|
|
ScheduledTask = "OriginalState"
|
|
Service = "OriginalType"
|
|
ScriptType = "UndoScript"
|
|
}
|
|
|
|
} else {
|
|
$Values = @{
|
|
Registry = "Value"
|
|
ScheduledTask = "State"
|
|
Service = "StartupType"
|
|
OriginalService = "OriginalType"
|
|
ScriptType = "InvokeScript"
|
|
}
|
|
}
|
|
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) {
|
|
Write-Debug "KeepServiceStartup is $KeepServiceStartup"
|
|
$sync.configs.tweaks.$CheckBox.service | ForEach-Object {
|
|
$changeservice = $true
|
|
|
|
# The check for !($undo) is required, without it the script will throw an error for accessing unavailable memeber, which's the 'OriginalService' Property
|
|
if($KeepServiceStartup -AND !($undo)) {
|
|
try {
|
|
# Check if the service exists
|
|
$service = Get-Service -Name $psitem.Name -ErrorAction Stop
|
|
if(!($service.StartType.ToString() -eq $psitem.$($values.OriginalService))) {
|
|
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] {
|
|
Write-Warning "Service $($psitem.Name) was not found"
|
|
}
|
|
}
|
|
|
|
if($changeservice) {
|
|
Write-Debug "$($psitem.Name) and state is $($psitem.$($values.service))"
|
|
Set-WinUtilService -Name $psitem.Name -StartupType $psitem.$($values.Service)
|
|
}
|
|
}
|
|
}
|
|
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)) {
|
|
$sync.configs.tweaks.$CheckBox.$($values.ScriptType) | ForEach-Object {
|
|
Write-Debug "$($psitem) and state is $($psitem.$($values.ScriptType))"
|
|
$Scriptblock = [scriptblock]::Create($psitem)
|
|
Invoke-WinUtilScript -ScriptBlock $scriptblock -Name $CheckBox
|
|
}
|
|
}
|
|
|
|
if(!$undo) {
|
|
if($sync.configs.tweaks.$CheckBox.appx) {
|
|
$sync.configs.tweaks.$CheckBox.appx | ForEach-Object {
|
|
Write-Debug "UNDO $($psitem.Name)"
|
|
Remove-WinUtilAPPX -Name $psitem
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|