Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions functions/private/Invoke-WinUtilScript.ps1

This file was deleted.

103 changes: 37 additions & 66 deletions functions/private/Invoke-WinUtilTweaks.ps1
Original file line number Diff line number Diff line change
@@ -1,80 +1,51 @@
function Invoke-WinUtilTweaks {
<#
function Invoke-WinUtilTweaks ($CheckBox, $undo) {
$tweak = $sync.configs.tweaks.$CheckBox

.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.
#>
$keys = if ($undo) {
@{ Registry = "OriginalValue"; Service = "OriginalType"; ScriptType = "UndoScript" }
} else {
@{ Registry = "Value"; Service = "StartupType"; OriginalService = "OriginalType"; ScriptType = "InvokeScript" }
}

param(
$CheckBox,
$undo = $false,
$KeepServiceStartup = $true
)
foreach ($svc in $tweak.service) {
Write-Host "Setting Service $($svc.Name) to $($svc.$($keys.Service))"
Set-Service -Name $svc.Name -StartupType $svc.$($keys.Service)
}

if ($undo) {
$Values = @{
Registry = "OriginalValue"
Service = "OriginalType"
ScriptType = "UndoScript"
}
foreach ($reg in $tweak.registry) {
$Name = $reg.Name
$Path = $reg.Path
$Type = $reg.Type
$Value = $reg.($keys.Registry)

} else {
$Values = @{
Registry = "Value"
Service = "StartupType"
OriginalService = "OriginalType"
ScriptType = "InvokeScript"
}
}
if ($sync.configs.tweaks.$CheckBox.service) {
$sync.configs.tweaks.$CheckBox.service | ForEach-Object {
$changeservice = $true
try {
if (-not (Get-PSDrive -Name HKU)) {
New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
}

# The check for !($undo) is required, without it the script will throw an error for accessing unavailable member, 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))) {
$changeservice = $false
}
} catch [System.ServiceProcess.ServiceNotFoundException] {
Write-Warning "Service $($psitem.Name) was not found."
}
if (-not (Test-Path $Path)) {
Write-Host "$Path was not found. Creating..."
New-Item -Path $Path -Force -ErrorAction Stop
}

if ($changeservice) {
Set-WinUtilService -Name $psitem.Name -StartupType $psitem.$($values.Service)
if ($Value -ne "<RemoveEntry>") {
Write-Host "Set $Path\$Name to $Value"
Set-ItemProperty -Path $Path -Name $Name -Type $Type -Value $Value -Force -ErrorAction Stop
} else {
Write-Host "Remove $Path\$Name"
Remove-ItemProperty -Path $Path -Name $Name -Force -ErrorAction Stop
}
}
}
if ($sync.configs.tweaks.$CheckBox.registry) {
$sync.configs.tweaks.$CheckBox.registry | ForEach-Object {
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 {
$Scriptblock = [scriptblock]::Create($psitem)
Invoke-WinUtilScript -ScriptBlock $scriptblock -Name $CheckBox
} catch {
Write-Warning $_.Exception.Message
}
}

if (!$undo) {
if($sync.configs.tweaks.$CheckBox.appx) {
$sync.configs.tweaks.$CheckBox.appx | ForEach-Object {
Remove-WinUtilAPPX -Name $psitem
}
foreach ($script in $tweak.($keys.ScriptType)) {
try {
Write-Host "Running Script for $CheckBox"
Invoke-Command ([scriptblock]::Create($script)) -ErrorAction Stop
} catch {
Write-Warning $_.Exception.Message
}
}
}
21 changes: 0 additions & 21 deletions functions/private/Remove-WinUtilAPPX.ps1

This file was deleted.

56 changes: 0 additions & 56 deletions functions/private/Set-WinUtilRegistry.ps1

This file was deleted.

40 changes: 0 additions & 40 deletions functions/private/Set-WinUtilService.ps1

This file was deleted.