Skip to content

Commit

Permalink
Comment Spacing, Indentation, and Capitalization (#1084)
Browse files Browse the repository at this point in the history
* Comment Spacing, Indentation, and Capitalization

* Comment Grammar and Spacing

Makes grammar in comments better and more consistent
Adds space before comment and centers word in `Write-Host` commands

* More Grammar and Formatting

* Add some comments

* Populate PlaceHolder comments in functions

Files I found that has issues:
Get-WinUtilRegistry.ps1
Install-WinUtilWinget.ps1
Invoke-WinUtilDarkMode.ps1
Remove-WinUtilAPPX.ps1
Test-WinUtilPackageManager.ps1
Update-WinUtilProgramWinget.ps1

Invoke-WPFUpdatessecurity.ps1

* Tweak a few more comments

* Tweak another write-host statement

* Undo Catch statement adjustment

It's outside of the scope of this pull request
  • Loading branch information
Carterpersall committed Jan 26, 2024
1 parent 932ec6a commit acc2b5b
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 474 deletions.
4 changes: 2 additions & 2 deletions functions/private/Get-WinUtilRegistry.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ function Get-WinUtilRegistry {
.EXAMPLE
Get-WinUtilRegistry -Name "PublishUserActivities" -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\System" -Type "DWord" -Value "0"
#>
#>
param (
$Name,
$Path,
$Type,
$Value
)

Try{
Try{
$syscheckvalue = Get-ItemPropertyValue -Path $Path -Value $Value # Return Value

}
Expand Down
20 changes: 10 additions & 10 deletions functions/private/Get-WinUtilVariables.ps1
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
function Get-WinUtilVariables {

<#
.SYNOPSIS
Gets every form object of the provided type
.OUTPUTS
List containing every object that matches the provided type
#>
param (
[Parameter()]
[string[]]$Type
[ValidateSet("CheckBox", "Button")]
[string]$Type
)

$keys = $sync.keys | Where-Object { $_ -like "WPF*" }
$keys = $sync.keys | Where-Object {$psitem -like "WPF*"}

if ($Type) {
if($type){
$output = $keys | ForEach-Object {
Try {
$objType = $sync["$psitem"].GetType().Name
if ($Type -contains $objType) {
Try{
if ($sync["$psitem"].GetType() -like "*$type*"){
Write-Output $psitem
}
}
Catch {
<#I am here so errors don't get outputted for a couple variables that don't have the .GetType() attribute#>
}
Catch{<#I am here so errors don't get outputted for a couple variables that don't have the .GetType() attribute#>}
}
return $output
return $output
}
return $keys
}
21 changes: 11 additions & 10 deletions functions/private/Install-WinUtilChoco.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@ function Install-WinUtilChoco {
#>

try {
try{
Write-Host "Checking if Chocolatey is Installed..."

if((Test-WinUtilPackageManager -choco)){
Write-Host "Chocolatey Already Installed"
return
}

Write-Host "Seems Chocolatey is not installed, installing now"
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


Write-Host "Seems Chocolatey is not installed, installing now?"
# Let user decide if they want to install Chocolatey
$confirmation = Read-Host "Are you Sure You Want To Proceed:(y/n)"
if ($confirmation -eq 'y') {
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 {
Write-Host "==========================================="
Write-Host "-- Chocolatey failed to install ---"
Write-Host "==========================================="
Catch{
throw [ChocoFailedInstall]::new('Failed to install')
}

}
10 changes: 4 additions & 6 deletions functions/private/Install-WinUtilWinget.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
function Get-LatestHash {
$shaUrl = ((Invoke-WebRequest $apiLatestUrl -UseBasicParsing | ConvertFrom-Json).assets | Where-Object { $_.name -match '^Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.txt$' }).browser_download_url

$shaFile = Join-Path -Path $tempFolder -ChildPath 'Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.txt'
$WebClient.DownloadFile($shaUrl, $shaFile)

Get-Content $shaFile
}

Expand All @@ -14,8 +14,6 @@ function Install-WinUtilWinget {
.SYNOPSIS
Installs Winget if it is not already installed
.DESCRIPTION
This function will download the latest version of winget and install it. If winget is already installed, it will do nothing.
#>
Try{
Write-Host "Checking if Winget is Installed..."
Expand All @@ -40,8 +38,8 @@ function Install-WinUtilWinget {
}

Write-Host "Running Alternative Installer and Direct Installing"
Start-Process -Verb runas -FilePath powershell.exe -ArgumentList "choco install winget"

Start-Process -Verb runas -FilePath powershell.exe -ArgumentList "irm https://raw.githubusercontent.com/ChrisTitusTech/winutil/main/winget.ps1 | iex"
Write-Host "Winget Installed"
}
Catch{
Expand Down
40 changes: 40 additions & 0 deletions functions/private/Set-WinUtilRestorePoint.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
function Set-WinUtilRestorePoint {
<#
.SYNOPSIS
Creates a Restore Point
#>

# Check if the user has administrative privileges
if (-Not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host "Please run this script as an administrator."
return
}

# Check if System Restore is enabled for the main drive
try {
# Try getting restore points to check if System Restore is enabled
Enable-ComputerRestore -Drive "$env:SystemDrive"
} catch {
Write-Host "An error occurred while enabling System Restore: $_"
}

# 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){
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
}

# Get all the restore points for the current day
$existingRestorePoints = Get-ComputerRestorePoint | Where-Object { $_.CreationTime.Date -eq (Get-Date).Date }

# Check if there is already a restore point created today
if ($existingRestorePoints.Count -eq 0) {
$description = "System Restore Point created by WinUtil"

Checkpoint-Computer -Description $description -RestorePointType "MODIFY_SETTINGS"
Write-Host -ForegroundColor Green "System Restore Point Created Successfully"
}
}
13 changes: 7 additions & 6 deletions functions/public/Invoke-WPFButton.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ function Invoke-WPFButton {
The name of the button that was clicked
#>

Param ([string]$Button)
Param ([string]$Button)

# Use this to get the name of the button
#[System.Windows.MessageBox]::Show("$Button","Chris Titus Tech's Windows Utility","OK","Info")
Expand All @@ -24,11 +24,16 @@ function Invoke-WPFButton {
"WPFdesktop" {Invoke-WPFPresets "Desktop"}
"WPFlaptop" {Invoke-WPFPresets "laptop"}
"WPFminimal" {Invoke-WPFPresets "minimal"}
"WPFexport" {Invoke-WPFImpex -type "export" -CheckBox "WPFTweaks"}
"WPFimport" {Invoke-WPFImpex -type "import" -CheckBox "WPFTweaks"}
"WPFexportWinget" {Invoke-WPFImpex -type "export" -CheckBox "WPFInstall"}
"WPFimportWinget" {Invoke-WPFImpex -type "import" -CheckBox "WPFInstall"}
"WPFclear" {Invoke-WPFPresets -preset $null -imported $true}
"WPFclearWinget" {Invoke-WPFPresets -preset $null -imported $true -CheckBox "WPFInstall"}
"WPFtweaksbutton" {Invoke-WPFtweaksbutton}
"WPFAddUltPerf" {Invoke-WPFUltimatePerformance -State "Enabled"}
"WPFRemoveUltPerf" {Invoke-WPFUltimatePerformance -State "Disabled"}
"WPFToggleDarkMode" {Invoke-WPFDarkMode -DarkMoveEnabled $(Get-WinUtilDarkMode)}
"WPFundoall" {Invoke-WPFundoall}
"WPFFeatureInstall" {Invoke-WPFFeatureInstall}
"WPFPanelDISM" {Invoke-WPFPanelDISM}
Expand All @@ -42,15 +47,11 @@ function Invoke-WPFButton {
"WPFPaneluser" {Invoke-WPFControlPanel -Panel $button}
"WPFUpdatesdefault" {Invoke-WPFUpdatesdefault}
"WPFFixesUpdate" {Invoke-WPFFixesUpdate}
"WPFFixesWinget" {Invoke-WPFFixesWinget}
"WPFFixesNetwork" {Invoke-WPFFixesNetwork}
"WPFUpdatesdisable" {Invoke-WPFUpdatesdisable}
"WPFUpdatessecurity" {Invoke-WPFUpdatessecurity}
"WPFWinUtilShortcut" {Invoke-WPFShortcut -ShortcutToAdd "WinUtil"}
"WPFGetInstalled" {Invoke-WPFGetInstalled -CheckBox "winget"}
"WPFGetInstalledTweaks" {Invoke-WPFGetInstalled -CheckBox "tweaks"}
"WPFGetIso" {Invoke-WPFGetIso}
"WPFMicrowin" {Invoke-WPFMicrowin}
"WPFCloseButton" {Invoke-WPFCloseButton}
}
}
20 changes: 14 additions & 6 deletions functions/public/Invoke-WPFInstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,37 @@ function Invoke-WPFInstall {
#>

if($sync.ProcessRunning){
$msg = "[Invoke-WPFInstall] Install process is currently running."
$msg = "Install process is currently running."
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
return
}

$WingetInstall = (Get-WinUtilCheckBoxes)["Install"]
$WingetInstall = Get-WinUtilCheckBoxes -Group "WPFInstall"

if ($wingetinstall.Count -eq 0) {
$WarningMsg = "Please select the program(s) to install"
[System.Windows.MessageBox]::Show($WarningMsg, $AppTitle, [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
return
}

Invoke-WPFRunspace -ArgumentList $WingetInstall,$DebugPreference -ScriptBlock {
param($WingetInstall, $DebugPreference)

Invoke-WPFRunspace -ArgumentList $WingetInstall -scriptblock {
param($WingetInstall)
try{
$sync.ProcessRunning = $true

# Ensure winget is installed
Install-WinUtilWinget

# Install all selected programs in new window
Install-WinUtilProgramWinget -ProgramsToInstall $WingetInstall

$ButtonType = [System.Windows.MessageBoxButton]::OK
$MessageboxTitle = "Installs are Finished "
$Messageboxbody = ("Done")
$MessageIcon = [System.Windows.MessageBoxImage]::Information

[System.Windows.MessageBox]::Show($Messageboxbody, $MessageboxTitle, $ButtonType, $MessageIcon)

Write-Host "==========================================="
Write-Host "-- Installs have finished ---"
Write-Host "==========================================="
Expand All @@ -38,7 +47,6 @@ function Invoke-WPFInstall {
Write-Host "-- Winget failed to install ---"
Write-Host "==========================================="
}
Start-Sleep -Seconds 5
$sync.ProcessRunning = $False
}
}
8 changes: 3 additions & 5 deletions functions/public/Invoke-WPFRunspace.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,17 @@ function Invoke-WPFRunspace {
[CmdletBinding()]
Param (
$ScriptBlock,
$ArgumentList,
$DebugPreference
)
$ArgumentList
)

# Create a PowerShell instance
$script:powershell = [powershell]::Create()

# Add Scriptblock and Arguments to runspace
$script:powershell.AddScript($ScriptBlock)
$script:powershell.AddArgument($ArgumentList)
$script:powershell.AddArgument($DebugPreference) # Pass DebugPreference to the script block
$script:powershell.RunspacePool = $sync.runspace

# Execute the RunspacePool
$script:handle = $script:powershell.BeginInvoke()

Expand Down
10 changes: 3 additions & 7 deletions functions/public/Invoke-WPFToggle.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ function Invoke-WPFToggle {
The name of the toggle to invoke
#>

Param ([string]$Button)
Param ([string]$Button)

# Use this to get the name of the button
#[System.Windows.MessageBox]::Show("$Button","Chris Titus Tech's Windows Utility","OK","Info")
Expand All @@ -19,10 +19,6 @@ function Invoke-WPFToggle {

"WPFToggleDarkMode" {Invoke-WinUtilDarkMode -DarkMoveEnabled $(Get-WinUtilToggleStatus WPFToggleDarkMode)}
"WPFToggleBingSearch" {Invoke-WinUtilBingSearch $(Get-WinUtilToggleStatus WPFToggleBingSearch)}
"WPFToggleNumLock" {Invoke-WinUtilNumLock $(Get-WinUtilToggleStatus WPFToggleNumLock)}
"WPFToggleVerboseLogon" {Invoke-WinUtilVerboseLogon $(Get-WinUtilToggleStatus WPFToggleVerboseLogon)}
"WPFToggleShowExt" {Invoke-WinUtilShowExt $(Get-WinUtilToggleStatus WPFToggleShowExt)}
"WPFToggleSnapFlyout" {Invoke-WinUtilSnapFlyout $(Get-WinUtilToggleStatus WPFToggleSnapFlyout)}
"WPFToggleMouseAcceleration" {Invoke-WinUtilMouseAcceleration $(Get-WinUtilToggleStatus WPFToggleMouseAcceleration)}

}
}
11 changes: 5 additions & 6 deletions functions/public/Invoke-WPFUnInstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ function Invoke-WPFUnInstall {
#>

if($sync.ProcessRunning){
$msg = "[Invoke-WPFUnInstall] Install process is currently running"
$msg = "Install process is currently running"
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
return
}

$WingetInstall = (Get-WinUtilCheckBoxes)["Install"]
$WingetInstall = Get-WinUtilCheckBoxes -Group "WPFInstall"

if ($wingetinstall.Count -eq 0) {
$WarningMsg = "Please select the program(s) to install"
Expand All @@ -29,9 +29,8 @@ function Invoke-WPFUnInstall {

if($confirm -eq "No"){return}

Invoke-WPFRunspace -ArgumentList $WingetInstall,$DebugPreference -ScriptBlock {
param($WingetInstall, $DebugPreference)

Invoke-WPFRunspace -ArgumentList $WingetInstall -scriptblock {
param($WingetInstall)
try{
$sync.ProcessRunning = $true

Expand All @@ -42,7 +41,7 @@ function Invoke-WPFUnInstall {
$MessageboxTitle = "Uninstalls are Finished "
$Messageboxbody = ("Done")
$MessageIcon = [System.Windows.MessageBoxImage]::Information

[System.Windows.MessageBox]::Show($Messageboxbody, $MessageboxTitle, $ButtonType, $MessageIcon)

Write-Host "==========================================="
Expand Down
27 changes: 27 additions & 0 deletions pester/winutil.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Load Variables needed for testing

./Compile.ps1

$script = Get-Content .\winutil.ps1
# Remove the part of the script that shows the form, leaving only the variable and function declarations
$script[0..($script.count - 21)] | Out-File .\pester.ps1


BeforeAll {
# Execute the truncated script, bringing the variabes into the current scope
. .\pester.ps1
}

Describe "GUI" {
Context "XML" {
It "Imports with no errors" {
$inputXML | should -Not -BeNullOrEmpty
}
}

Context "Form" {
It "Imports with no errors" {
$sync.Form | should -Not -BeNullOrEmpty
}
}
}
Loading

0 comments on commit acc2b5b

Please sign in to comment.