From cf8787a700ffe5049e6ac951619c3565a391fe81 Mon Sep 17 00:00:00 2001
From: Matt Creekmore <48491595+mcreekmore@users.noreply.github.com>
Date: Tue, 28 Jan 2025 14:59:00 -0500
Subject: [PATCH] Fixed impartial nerd font uninstallation (#3171)
* fix: nerdfonts uninstall now deletes corresponding registry keys
* change ErrorAction to SilentlyContinue
* fix some code styling
* removed unused files/docs as per Cryostrixx advice
* restored portions of the feature.json
---
config/feature.json | 6 +--
.../PowerShell-Profile/PSProfileInstall.md | 38 --------------
.../PowerShell-Profile/PSProfileUninstall.md | 38 --------------
.../Invoke-WinUtilUninstallPSProfile.ps1 | 44 ++++++++++++++++
functions/private/Invoke-WinUtilpsProfile.ps1 | 50 -------------------
5 files changed, 46 insertions(+), 130 deletions(-)
delete mode 100644 docs/dev/features/PowerShell-Profile/PSProfileInstall.md
delete mode 100644 docs/dev/features/PowerShell-Profile/PSProfileUninstall.md
delete mode 100644 functions/private/Invoke-WinUtilpsProfile.ps1
diff --git a/config/feature.json b/config/feature.json
index afa423a7..4a296cf5 100644
--- a/config/feature.json
+++ b/config/feature.json
@@ -312,8 +312,7 @@
"panel": "2",
"Order": "a083_",
"Type": "Button",
- "ButtonWidth": "300",
- "link": "https://christitustech.github.io/winutil/dev/features/Powershell-Profile/PSProfileInstall"
+ "ButtonWidth": "300"
},
"WPFWinUtilUninstallPSProfile": {
"Content": "Uninstall CTT PowerShell Profile",
@@ -321,8 +320,7 @@
"panel": "2",
"Order": "a084_",
"Type": "Button",
- "ButtonWidth": "300",
- "link": "https://christitustech.github.io/winutil/dev/features/Powershell-Profile/PSProfileUninstall"
+ "ButtonWidth": "300"
},
"WPFWinUtilSSHServer": {
"Content": "Enable OpenSSH Server",
diff --git a/docs/dev/features/PowerShell-Profile/PSProfileInstall.md b/docs/dev/features/PowerShell-Profile/PSProfileInstall.md
deleted file mode 100644
index 6d2d12d4..00000000
--- a/docs/dev/features/PowerShell-Profile/PSProfileInstall.md
+++ /dev/null
@@ -1,38 +0,0 @@
-# Install CTT PowerShell Profile
-
-Last Updated: 2024-10-01
-
-
-!!! info
- The Development Documentation is auto generated for every compilation of WinUtil, meaning a part of it will always stay up-to-date. **Developers do have the ability to add custom content, which won't be updated automatically.**
-
-
-
-
-
-
-
-Preview Code
-
-```json
-{
- "Content": "Install CTT PowerShell Profile",
- "category": "Powershell Profile",
- "panel": "2",
- "Order": "a083_",
- "Type": "Button",
- "ButtonWidth": "300",
- "link": "https://christitustech.github.io/winutil/dev/features/Powershell-Profile/PSProfileInstall"
-}
-```
-
-
-
-
-
-
-
-
-
-[View the JSON file](https://github.com/ChrisTitusTech/winutil/tree/main/config/feature.json)
-
diff --git a/docs/dev/features/PowerShell-Profile/PSProfileUninstall.md b/docs/dev/features/PowerShell-Profile/PSProfileUninstall.md
deleted file mode 100644
index 2afc72fa..00000000
--- a/docs/dev/features/PowerShell-Profile/PSProfileUninstall.md
+++ /dev/null
@@ -1,38 +0,0 @@
-# Uninstall CTT PowerShell Profile
-
-Last Updated: 2024-10-01
-
-
-!!! info
- The Development Documentation is auto generated for every compilation of WinUtil, meaning a part of it will always stay up-to-date. **Developers do have the ability to add custom content, which won't be updated automatically.**
-
-
-
-
-
-
-
-Preview Code
-
-```json
-{
- "Content": "Uninstall CTT PowerShell Profile",
- "category": "Powershell Profile",
- "panel": "2",
- "Order": "a084_",
- "Type": "Button",
- "ButtonWidth": "300",
- "link": "https://christitustech.github.io/winutil/dev/features/Powershell-Profile/PSProfileUninstall"
-}
-```
-
-
-
-
-
-
-
-
-
-[View the JSON file](https://github.com/ChrisTitusTech/winutil/tree/main/config/feature.json)
-
diff --git a/functions/private/Invoke-WinUtilUninstallPSProfile.ps1 b/functions/private/Invoke-WinUtilUninstallPSProfile.ps1
index d97442d0..72272993 100644
--- a/functions/private/Invoke-WinUtilUninstallPSProfile.ps1
+++ b/functions/private/Invoke-WinUtilUninstallPSProfile.ps1
@@ -38,6 +38,32 @@ function Invoke-WinUtilUninstallPSProfile {
if (-not $Fonts) {
Write-Host "===> Successfully Uninstalled: Nerd Fonts. <===" -ForegroundColor Yellow
}
+
+ }
+
+ # Helper function used to uninstall a specific Nerd Fonts font corresponding registry keys.
+ function Uninstall-NerdFontRegKeys {
+ # Define the parameters block for the Uninstall-NerdFontsRegKey function.
+ param (
+ [string]$FontsRegPath = "HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts",
+ [string]$FontFamilyName = "CaskaydiaCove"
+ )
+
+ try {
+ # Get all properties (font registrations) from the registry path
+ $registryProperties = Get-ItemProperty -Path $FontsRegPath
+
+ # Filter and remove properties that match the font family name
+ $registryProperties.PSObject.Properties |
+ Where-Object { $_.Name -match $FontFamilyName } |
+ ForEach-Object {
+ If ($_.Name -like "*$FontFamilyName*") {
+ Remove-ItemProperty -path $FontsRegPath -Name $_.Name -ErrorAction SilentlyContinue
+ }
+ }
+ } catch {
+ Write-Host "Error removing registry keys: $($_.exception.message)" -ForegroundColor Red
+ }
}
# Check if Chris Titus Tech's PowerShell profile is currently available in the PowerShell profile folder.
@@ -87,11 +113,28 @@ function Invoke-WinUtilUninstallPSProfile {
# Call the function used to uninstall the specified Nerd Fonts package from the system.
Uninstall-NerdFonts -FontsPath $FontsPath -FontFamilyName $FontFamilyName
+
} catch {
# Let the user know that an error was encountered when uninstalling Nerd Fonts.
Write-Host "Failed to uninstall Nerd Fonts. Error: $_" -ForegroundColor Red
}
+ # Attempt to uninstall the specified Nerd Fonts registry keys from the system.
+ try {
+ # Specify the registry path that the specified font registry keys will be uninstalled from.
+ [string]$FontsRegPath = "HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"
+
+ # Specify the name of the font registry keys that is to be uninstalled from the system.
+ [string]$FontFamilyName = "CaskaydiaCove"
+
+ # Call the function used to uninstall the specified Nerd Fonts registry keys from the system.
+ Uninstall-NerdFontRegKeys -FontsPath $FontsRegPath -FontFamilyName $FontFamilyName
+
+ } catch {
+ # Let the user know that an error was encountered when uninstalling Nerd Font registry keys.
+ Write-Host "Failed to uninstall Nerd Font Registry Keys. Error: $_" -ForegroundColor Red
+ }
+
# Attempt to uninstall the Terminal-Icons PowerShell module from the system.
try {
# Get the content of the backup PowerShell profile and store it in-memory.
@@ -185,3 +228,4 @@ function Invoke-WinUtilUninstallPSProfile {
}
}
}
+
diff --git a/functions/private/Invoke-WinUtilpsProfile.ps1 b/functions/private/Invoke-WinUtilpsProfile.ps1
deleted file mode 100644
index 318e7921..00000000
--- a/functions/private/Invoke-WinUtilpsProfile.ps1
+++ /dev/null
@@ -1,50 +0,0 @@
-function Invoke-WinUtilpsProfile {
- <#
- .SYNOPSIS
- Installs & applies the CTT Powershell Profile
- #>
- Invoke-WPFRunspace -Argumentlist $PROFILE -DebugPreference $DebugPreference -ScriptBlock {
- param ( $psprofile)
- function Invoke-PSSetup {
- $url = "https://raw.githubusercontent.com/ChrisTitusTech/powershell-profile/main/Microsoft.PowerShell_profile.ps1"
- $oldhash = Get-FileHash $psprofile -ErrorAction SilentlyContinue
- Invoke-RestMethod $url -OutFile "$env:temp/Microsoft.PowerShell_profile.ps1"
- $newhash = Get-FileHash "$env:temp/Microsoft.PowerShell_profile.ps1"
- if ($newhash.Hash -ne $oldhash.Hash) {
- write-host "===> Installing Profile.. <===" -ForegroundColor Yellow
- # Starting new hidden shell process bc setup does not work in a runspace
- Start-Process -FilePath "pwsh" -ArgumentList "-ExecutionPolicy Bypass -NoProfile -Command `"Invoke-Expression (Invoke-WebRequest `'https://github.com/ChrisTitusTech/powershell-profile/raw/main/setup.ps1`')`"" -WindowStyle Hidden -Wait
- Write-Host "Profile has been installed. Please restart your shell to reflect changes!" -ForegroundColor Magenta
- write-host "===> Finished <===" -ForegroundColor Yellow
- } else {
- Write-Host "Profile is up to date" -ForegroundColor Green
- }
- }
-
- if (Get-Command "pwsh" -ErrorAction SilentlyContinue) {
- if ($PSVersionTable.PSVersion.Major -ge 7) {
- Invoke-PSSetup
- }
- else {
- write-host "Profile requires Powershell 7, which is currently installed but not used!" -ForegroundColor Red
- # Load the necessary assembly for Windows Forms
- Add-Type -AssemblyName System.Windows.Forms
- # Display the Yes/No message box
- $question = [System.Windows.Forms.MessageBox]::Show("Profile requires Powershell 7, which is currently installed but not used! Do you want to install Profile for Powershell 7?", "Question",
- [System.Windows.Forms.MessageBoxButtons]::YesNo,
- [System.Windows.Forms.MessageBoxIcon]::Question)
-
- # Check the result
- if ($question -eq [System.Windows.Forms.DialogResult]::Yes) {
- Invoke-PSSetup
- }
- else {
- Write-Host "Not proceeding with the profile setup!"
- }
- }
- }
- else {
- write-host "Profile requires Powershell 7, which is not installed!" -ForegroundColor Red
- }
- }
-}