Skip to content

Commit

Permalink
refactor: Write-Status rename paremeter to receive an array
Browse files Browse the repository at this point in the history
- Accepts -Types instead of -Symbol and -Type
- Customize System Features tweaks's show * instead of Default
  • Loading branch information
LeDragoX committed Jun 10, 2022
1 parent ae3b076 commit 2b5aceb
Show file tree
Hide file tree
Showing 34 changed files with 236 additions and 231 deletions.
30 changes: 15 additions & 15 deletions Win10ScriptGUI.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function Request-AdminPrivilege() {
}

function Show-GUI() {
Write-Status -Symbol "@" -Status "Loading GUI Layout..."
Write-Status -Types "@" -Status "Loading GUI Layout..."
# Loading System Libs
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
Expand Down Expand Up @@ -397,17 +397,17 @@ function Show-GUI() {
$CbDarkTheme.Add_Click( {
If ($CbDarkTheme.CheckState -eq "Checked") {
Open-RegFilesCollection -RelativeLocation "src\utils" -Scripts @("use-dark-theme.reg") -NoDialog
$CbDarkTheme.Text = "[ON] Use Dark Theme"
$CbDarkTheme.Text = "[ON] Use Dark Theme"
} Else {
Open-RegFilesCollection -RelativeLocation "src\utils" -Scripts @("use-light-theme.reg") -NoDialog
$CbDarkTheme.Text = "[OFF] Use Dark Theme (D.)"
$CbDarkTheme.Text = "[OFF] Use Dark Theme *"
}
})

$CbActivityHistory.Add_Click( {
If ($CbActivityHistory.CheckState -eq "Checked") {
Open-RegFilesCollection -RelativeLocation "src\utils" -Scripts @("enable-activity-history.reg") -NoDialog
$CbActivityHistory.Text = "[ON] Activity History (Default)"
$CbActivityHistory.Text = "[ON] Activity History *"
} Else {
Open-RegFilesCollection -RelativeLocation "src\utils" -Scripts @("disable-activity-history.reg") -NoDialog
$CbActivityHistory.Text = "[OFF] Activity History"
Expand All @@ -417,7 +417,7 @@ function Show-GUI() {
$CbBackgroundsApps.Add_Click( {
If ($CbBackgroundsApps.CheckState -eq "Checked") {
Open-RegFilesCollection -RelativeLocation "src\utils" -Scripts @("enable-bg-apps.reg") -NoDialog
$CbBackgroundsApps.Text = "[ON] Background Apps (D.)"
$CbBackgroundsApps.Text = "[ON] Background Apps *"
} Else {
Open-RegFilesCollection -RelativeLocation "src\utils" -Scripts @("disable-bg-apps.reg") -NoDialog
$CbBackgroundsApps.Text = "[OFF] Background Apps"
Expand All @@ -427,7 +427,7 @@ function Show-GUI() {
$CbClipboardHistory.Add_Click( {
If ($CbClipboardHistory.CheckState -eq "Checked") {
Open-RegFilesCollection -RelativeLocation "src\utils" -Scripts @("enable-clipboard-history.reg") -NoDialog
$CbClipboardHistory.Text = "[ON] Clipboard History (D.)"
$CbClipboardHistory.Text = "[ON] Clipboard History *"
} Else {
Open-RegFilesCollection -RelativeLocation "src\utils" -Scripts @("disable-clipboard-history.reg") -NoDialog
$CbClipboardHistory.Text = "[OFF] Clipboard History"
Expand All @@ -437,7 +437,7 @@ function Show-GUI() {
$CbCortana.Add_Click( {
If ($CbCortana.CheckState -eq "Checked") {
Open-RegFilesCollection -RelativeLocation "src\utils" -Scripts @("enable-cortana.reg") -NoDialog
$CbCortana.Text = "[ON] Cortana (Default)"
$CbCortana.Text = "[ON] Cortana *"
} Else {
Open-RegFilesCollection -RelativeLocation "src\utils" -Scripts @("disable-cortana.reg") -NoDialog
$CbCortana.Text = "[OFF] Cortana"
Expand All @@ -450,7 +450,7 @@ function Show-GUI() {
$CbOldVolumeControl.Text = "[ON] Old Volume Control"
} Else {
Open-RegFilesCollection -RelativeLocation "src\utils" -Scripts @("disable-old-volume-control.reg") -NoDialog
$CbOldVolumeControl.Text = "[OFF] Old Volume Control (D.)"
$CbOldVolumeControl.Text = "[OFF] Old Volume Control *"
}
})

Expand All @@ -460,14 +460,14 @@ function Show-GUI() {
$CbPhotoViewer.Text = "[ON] Photo Viewer"
} Else {
Open-RegFilesCollection -RelativeLocation "src\utils" -Scripts @("disable-photo-viewer.reg") -NoDialog
$CbPhotoViewer.Text = "[OFF] Photo Viewer (D.)"
$CbPhotoViewer.Text = "[OFF] Photo Viewer *"
}
})

$CbSearchIdx.Add_Click( {
If ($CbSearchIdx.CheckState -eq "Checked") {
Open-PowerShellFilesCollection -RelativeLocation "src\utils" -Scripts @("enable-search-idx-service.ps1") -NoDialog
$CbSearchIdx.Text = "[ON] Search Indexing (Default)"
$CbSearchIdx.Text = "[ON] Search Indexing *"
} Else {
Open-PowerShellFilesCollection -RelativeLocation "src\utils" -Scripts @("disable-search-idx-service.ps1") -NoDialog
$CbSearchIdx.Text = "[OFF] Search Indexing"
Expand All @@ -477,7 +477,7 @@ function Show-GUI() {
$CbTelemetry.Add_Click( {
If ($CbTelemetry.CheckState -eq "Checked") {
Open-RegFilesCollection -RelativeLocation "src\utils" -Scripts @("enable-telemetry.reg") -NoDialog
$CbTelemetry.Text = "[ON] Telemetry (Default)"
$CbTelemetry.Text = "[ON] Telemetry *"
} Else {
Open-RegFilesCollection -RelativeLocation "src\utils" -Scripts @("disable-telemetry.reg") -NoDialog
$CbTelemetry.Text = "[OFF] Telemetry"
Expand All @@ -487,7 +487,7 @@ function Show-GUI() {
$CbXboxGameBarAndDVR.Add_Click( {
If ($CbXboxGameBarAndDVR.CheckState -eq "Checked") {
Open-RegFilesCollection -RelativeLocation "src\utils" -Scripts @("enable-game-bar-dvr.reg") -NoDialog
$CbXboxGameBarAndDVR.Text = "[ON] Xbox GameBar/DVR (D.)"
$CbXboxGameBarAndDVR.Text = "[ON] Xbox GameBar/DVR *"
} Else {
Open-RegFilesCollection -RelativeLocation "src\utils" -Scripts @("disable-game-bar-dvr.reg") -NoDialog
$CbXboxGameBarAndDVR.Text = "[OFF] Xbox GameBar/DVR"
Expand All @@ -500,7 +500,7 @@ function Show-GUI() {
$CbGodMode.Text = "[ON] God Mode"
} Else {
Open-PowerShellFilesCollection -RelativeLocation "src\utils" -Scripts @("disable-god-mode.ps1") -NoDialog
$CbGodMode.Text = "[OFF] God Mode (Default)"
$CbGodMode.Text = "[OFF] God Mode *"
}
})

Expand All @@ -510,7 +510,7 @@ function Show-GUI() {
$CbTakeOwnership.Text = "[ON] Take Ownership menu"
} Else {
Open-RegFilesCollection -RelativeLocation "src\utils" -Scripts @("disable-take-ownership-context-menu.reg") -NoDialog
$CbTakeOwnership.Text = "[OFF] Take Ownership... (D.)"
$CbTakeOwnership.Text = "[OFF] Take Ownership... *"
}
})

Expand All @@ -520,7 +520,7 @@ function Show-GUI() {
$CbShutdownPCShortcut.Text = "[ON] Shutdown PC shortcut"
} Else {
Open-PowerShellFilesCollection -RelativeLocation "src\utils" -Scripts @("disable-shutdown-pc-shortcut.ps1") -NoDialog
$CbShutdownPCShortcut.Text = "[OFF] Shutdown PC... (Default)"
$CbShutdownPCShortcut.Text = "[OFF] Shutdown PC... *"
}
})

Expand Down
8 changes: 4 additions & 4 deletions src/lib/download-web-file.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ function Request-FileDownload {

Write-Verbose "[?] I'm at: $PWD"
If (!(Test-Path "$PSScriptRoot\..\tmp")) {
Write-Status -Symbol "@" -Status "$PSScriptRoot\..\tmp doesn't exist, creating folder..."
Write-Status -Types "@" -Status "$PSScriptRoot\..\tmp doesn't exist, creating folder..."
mkdir "$PSScriptRoot\..\tmp" | Out-Null
}

$FileLocation = "$PSScriptRoot\..\tmp\$OutputFile"

If ($OutputFolder) {
If (!(Test-Path "$PSScriptRoot\..\tmp\$OutputFolder")) {
Write-Status -Symbol "@" -Status "$PSScriptRoot\..\tmp\$OutputFolder doesn't exist, creating folder..."
Write-Status -Types "@" -Status "$PSScriptRoot\..\tmp\$OutputFolder doesn't exist, creating folder..."
mkdir "$PSScriptRoot\..\tmp\$OutputFolder"
}
$FileLocation = "$PSScriptRoot\..\tmp\$OutputFolder\$OutputFile"
}

Import-Module BitsTransfer
Write-Host
Write-Status -Symbol "@" -Status "Downloading from: '$FileURI' as '$OutputFile'"
Write-Status -Symbol "@" -Status "On: '$FileLocation'"
Write-Status -Types "@" -Status "Downloading from: '$FileURI' as '$OutputFile'"
Write-Status -Types "@" -Status "On: '$FileLocation'"
Start-BitsTransfer -Dynamic -RetryTimeout 60 -TransferType Download -Source $FileURI -Destination $FileLocation

return $FileLocation
Expand Down
2 changes: 1 addition & 1 deletion src/lib/get-hardware-info.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function Get-SystemSpec() {
[String] $Separator = '|'
)

Write-Status -Symbol "@" -Status "Loading system specs..."
Write-Status -Types "@" -Status "Loading system specs..."
# Adapted From: https://www.delftstack.com/howto/powershell/find-windows-version-in-powershell/#using-the-wmi-class-with-get-wmiobject-cmdlet-in-powershell-to-get-the-windows-version
$WinVer = (Get-CimInstance -class Win32_OperatingSystem).Caption -replace 'Microsoft ', ''
$DisplayVersion = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").DisplayVersion
Expand Down
6 changes: 3 additions & 3 deletions src/lib/install-font.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function Install-Font() {
ForEach ($FontFile in Get-ChildItem $FontSourceFolder -Include '*.ttf', '*.ttc', '*.otf' -Recurse) {
$TargetPath = Join-Path $SystemFontsPath $FontFile.Name

Write-Status -Symbol "+" -Status "Installing '$($FontFile.Name)' Font on $TargetPath ..."
Write-Status -Types "+" -Status "Installing '$($FontFile.Name)' Font on $TargetPath ..."

Try {
# Extract Font information for Reqistry
Expand All @@ -27,7 +27,7 @@ function Install-Font() {
$RegName = $ShellFolder.GetDetailsOf($ShellFile, 21) + ' ' + $FontType
} Catch {
# This may not be the better way, but this workaround worked
Write-Status -Symbol "@" -Status "Got an error, the font type is OpenType" -Warning
Write-Status -Types "@" -Status "Got an error, the font type is OpenType" -Warning
$FontType = '(OpenType)'
$RegName = ""
$NameHelper = $FontFile.Name.Replace("-", " ").Replace("_", " ").Replace(".ttf", "").Replace(".ttc", "").Replace(".otf", "").Trim(" ")
Expand All @@ -43,7 +43,7 @@ function Install-Font() {
}
}

Write-Status -Symbol "+" -Status "Creating new Registry to $RegName on: $PathToLMWindowsFonts"
Write-Status -Types "+" -Status "Creating new Registry to $RegName on: $PathToLMWindowsFonts"
New-ItemProperty -Path "$PathToLMWindowsFonts" -Name $RegName -PropertyType String -Value $FontFile.Name -Force
Copy-item $FontFile.FullName -Destination $SystemFontsPath
Remove-Item $FontFile.FullName
Expand Down
4 changes: 2 additions & 2 deletions src/lib/manage-software.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function Install-Software() {
$ViaMSStore, $ViaWSL = $false, $false
$PkgMngr = 'Chocolatey'
$InstallBlock = { choco install --ignore-dependencies --yes $Package }
Write-Status -Symbol "?" -Status "Chocolatey is configured to ignore dependencies (bloat), you may need to install it before using any program." -Warning
Write-Status -Types "?" -Status "Chocolatey is configured to ignore dependencies (bloat), you may need to install it before using any program." -Warning
}

If ($ViaMSStore) {
Expand Down Expand Up @@ -86,7 +86,7 @@ function Uninstall-Software() {
$ViaMSStore, $ViaWSL = $false, $false
$PkgMngr = 'Chocolatey'
$UninstallBlock = { choco uninstall --remove-dependencies --yes $Package }
Write-Status -Symbol "?" -Status "Chocolatey is configured to remove dependencies (bloat), you may need to install it before using any program." -Warning
Write-Status -Types "?" -Status "Chocolatey is configured to remove dependencies (bloat), you may need to install it before using any program." -Warning
}

If ($ViaMSStore) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/new-shortcut.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function New-Shortcut() {
)

If (!(Test-Path -Path (Split-Path -Path $ShortcutPath))) {
Write-Status -Symbol "?" -Status "$((Split-Path -Path $ShortcutPath)) does not exist, creating it..."
Write-Status -Types "?" -Status "$((Split-Path -Path $ShortcutPath)) does not exist, creating it..."
New-Item -Path (Split-Path -Path $ShortcutPath) -ItemType Directory -Force
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/remove-uwp-appx.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ function Remove-UWPAppx() {

ForEach ($AppxPackage in $AppxPackages) {
If ((Get-AppxPackage -AllUsers -Name $AppxPackage) -or (Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like $AppxPackage)) {
Write-Status -Symbol "-" -Type $TweakType -Status "Trying to remove $AppxPackage from ALL users ..."
Write-Status -Types "-", $TweakType -Status "Trying to remove $AppxPackage from ALL users ..."
Get-AppxPackage -AllUsers -Name $AppxPackage | Remove-AppxPackage # App
Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like $AppxPackage | Remove-AppxProvisionedPackage -Online -AllUsers # Payload
} Else {
Write-Status -Symbol "?" -Type $TweakType -Status "$AppxPackage was already removed or not found ..." -Warning
Write-Status -Types "?", $TweakType -Status "$AppxPackage was already removed or not found ..." -Warning
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/lib/set-scheduled-task-state.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function Find-ScheduledTask() {
If (Get-ScheduledTaskInfo -TaskName $ScheduledTask -ErrorAction SilentlyContinue) {
return $true
} Else {
Write-Status -Symbol "?" -Type $TweakType -Status "The $ScheduledTask task was not found." -Warning
Write-Status -Types "?", $TweakType -Status "The $ScheduledTask task was not found." -Warning
return $false
}
}
Expand All @@ -36,20 +36,20 @@ function Set-ScheduledTaskState() {
ForEach ($ScheduledTask in $ScheduledTasks) {
If (Find-ScheduledTask $ScheduledTask) {
If ($ScheduledTask -in $Filter) {
Write-Status -Symbol "?" -Type $TweakType -Status "The $ScheduledTask ($((Get-ScheduledTask $ScheduledTask).TaskName)) will be skipped as set on Filter ..." -Warning
Write-Status -Types "?", $TweakType -Status "The $ScheduledTask ($((Get-ScheduledTask $ScheduledTask).TaskName)) will be skipped as set on Filter ..." -Warning
Continue
}

If (!$CustomMessage) {
If ($Disabled) {
Write-Status -Symbol "-" -Type $TweakType -Status "Disabling the $ScheduledTask task ..."
Write-Status -Types "-", $TweakType -Status "Disabling the $ScheduledTask task ..."
} ElseIf ($Ready) {
Write-Status -Symbol "+" -Type $TweakType -Status "Enabling the $ScheduledTask task ..."
Write-Status -Types "+", $TweakType -Status "Enabling the $ScheduledTask task ..."
} Else {
Write-Status -Symbol "?" -Type $TweakType -Status "No parameter received (valid params: -Disabled or -Ready)" -Warning
Write-Status -Types "?", $TweakType -Status "No parameter received (valid params: -Disabled or -Ready)" -Warning
}
} Else {
Write-Status -Symbol "@" -Type $TweakType -Status $(Invoke-Expression "$CustomMessage")
Write-Status -Types "@", $TweakType -Status $(Invoke-Expression "$CustomMessage")
}

If ($Disabled) {
Expand Down
16 changes: 8 additions & 8 deletions src/lib/set-service-startup.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function Find-Service() {
If (Get-Service $Service -ErrorAction SilentlyContinue) {
return $true
} Else {
Write-Status -Symbol "?" -Type $TweakType -Status "The $Service service was not found ..." -Warning
Write-Status -Types "?", $TweakType -Status "The $Service service was not found ..." -Warning
return $false
}
}
Expand Down Expand Up @@ -39,27 +39,27 @@ function Set-ServiceStartup() {
ForEach ($Service in $Services) {
If (Find-Service $Service) {
If (($Service -in $SecurityFilterOnEnable) -and (($Automatic) -or ($Manual))) {
Write-Status -Symbol "?" -Type $TweakType -Status "Skipping $Service ($((Get-Service $Service).DisplayName)) to avoid a security vulnerability ..." -Warning
Write-Status -Types "?", $TweakType -Status "Skipping $Service ($((Get-Service $Service).DisplayName)) to avoid a security vulnerability ..." -Warning
Continue
}

If ($Service -in $Filter) {
Write-Status -Symbol "?" -Type $TweakType -Status "The $Service ($((Get-Service $Service).DisplayName)) will be skipped as set on Filter ..." -Warning
Write-Status -Types "?", $TweakType -Status "The $Service ($((Get-Service $Service).DisplayName)) will be skipped as set on Filter ..." -Warning
Continue
}

If (!$CustomMessage) {
If ($Automatic) {
Write-Status -Symbol "+" -Type $TweakType -Status "Setting $Service ($((Get-Service $Service).DisplayName)) as 'Automatic' on Startup ..."
Write-Status -Types "+", $TweakType -Status "Setting $Service ($((Get-Service $Service).DisplayName)) as 'Automatic' on Startup ..."
} ElseIf ($Disabled) {
Write-Status -Symbol "-" -Type $TweakType -Status "Setting $Service ($((Get-Service $Service).DisplayName)) as 'Disabled' on Startup ..."
Write-Status -Types "-", $TweakType -Status "Setting $Service ($((Get-Service $Service).DisplayName)) as 'Disabled' on Startup ..."
} ElseIf ($Manual) {
Write-Status -Symbol "-" -Type $TweakType -Status "Setting $Service ($((Get-Service $Service).DisplayName)) as 'Manual' on Startup ..."
Write-Status -Types "-", $TweakType -Status "Setting $Service ($((Get-Service $Service).DisplayName)) as 'Manual' on Startup ..."
} Else {
Write-Status -Symbol "?" -Type $TweakType -Status "No parameter received (valid params: -Automatic, -Disabled or -Manual)" -Warning
Write-Status -Types "?", $TweakType -Status "No parameter received (valid params: -Automatic, -Disabled or -Manual)" -Warning
}
} Else {
Write-Status -Symbol "@" -Type $TweakType -Status $(Invoke-Expression "$CustomMessage")
Write-Status -Types "@", $TweakType -Status $(Invoke-Expression "$CustomMessage")
}

If ($Automatic) {
Expand Down
Loading

0 comments on commit 2b5aceb

Please sign in to comment.