mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-07-05 04:33:53 -05:00
Compare commits
5 Commits
25.03.04
...
9d4ebefd28
Author | SHA1 | Date | |
---|---|---|---|
9d4ebefd28 | |||
d215d0fc2c | |||
52de4690ab | |||
ef97a8da24 | |||
14c6562bf6 |
@ -52,7 +52,7 @@ If you have Issues, refer to [Known Issues](https://christitustech.github.io/win
|
||||
|
||||
These are the sponsors that help keep this project alive with monthly contributions.
|
||||
|
||||
<!-- sponsors --><a href="https://github.com/TriHydera"><img src="https://github.com/TriHydera.png" width="60px" alt="User avatar: TriHydera" /></a><a href="https://github.com/jozozovko"><img src="https://github.com/jozozovko.png" width="60px" alt="User avatar: " /></a><a href="https://github.com/DelDongo"><img src="https://github.com/DelDongo.png" width="60px" alt="User avatar: " /></a><a href="https://github.com/markamos"><img src="https://github.com/markamos.png" width="60px" alt="User avatar: Mark Amos" /></a><a href="https://github.com/dwelfusius"><img src="https://github.com/dwelfusius.png" width="60px" alt="User avatar: " /></a><a href="https://github.com/mews-se"><img src="https://github.com/mews-se.png" width="60px" alt="User avatar: Martin Stockzell" /></a><a href="https://github.com/jdiegmueller"><img src="https://github.com/jdiegmueller.png" width="60px" alt="User avatar: Jason A. Diegmueller" /></a><a href="https://github.com/altugtekiner"><img src="https://github.com/altugtekiner.png" width="60px" alt="User avatar: " /></a><a href="https://github.com/robertsandrock"><img src="https://github.com/robertsandrock.png" width="60px" alt="User avatar: RMS" /></a><a href="https://github.com/KenichiQaz"><img src="https://github.com/KenichiQaz.png" width="60px" alt="User avatar: Stefan" /></a><a href="https://github.com/paulsheets"><img src="https://github.com/paulsheets.png" width="60px" alt="User avatar: Paul" /></a><a href="https://github.com/djones369"><img src="https://github.com/djones369.png" width="60px" alt="User avatar: Dave Jones" /></a><a href="https://github.com/anthonymendez"><img src="https://github.com/anthonymendez.png" width="60px" alt="User avatar: Anthony Mendez" /></a><a href="https://github.com/claudemods"><img src="https://github.com/claudemods.png" width="60px" alt="User avatar: Claudemods" /></a><a href="https://github.com/FatBastard0"><img src="https://github.com/FatBastard0.png" width="60px" alt="User avatar: " /></a><a href="https://github.com/Ascent7910"><img src="https://github.com/Ascent7910.png" width="60px" alt="User avatar: Max" /></a><a href="https://github.com/DursleyGuy"><img src="https://github.com/DursleyGuy.png" width="60px" alt="User avatar: DursleyGuy" /></a><a href="https://github.com/realmuddy"><img src="https://github.com/realmuddy.png" width="60px" alt="User avatar: Phillip Waters" /></a><a href="https://github.com/quaszi"><img src="https://github.com/quaszi.png" width="60px" alt="User avatar: " /></a><a href="https://github.com/DwayneTheRockLobster1"><img src="https://github.com/DwayneTheRockLobster1.png" width="60px" alt="User avatar: " /></a><a href="https://github.com/KieraKujisawa"><img src="https://github.com/KieraKujisawa.png" width="60px" alt="User avatar: Kiera Meredith" /></a><!-- sponsors -->
|
||||
<!-- sponsors --><a href="https://github.com/TriHydera"><img src="https://github.com/TriHydera.png" width="60px" alt="User avatar: TriHydera" /></a><a href="https://github.com/jozozovko"><img src="https://github.com/jozozovko.png" width="60px" alt="User avatar: " /></a><a href="https://github.com/DelDongo"><img src="https://github.com/DelDongo.png" width="60px" alt="User avatar: " /></a><a href="https://github.com/markamos"><img src="https://github.com/markamos.png" width="60px" alt="User avatar: Mark Amos" /></a><a href="https://github.com/dwelfusius"><img src="https://github.com/dwelfusius.png" width="60px" alt="User avatar: " /></a><a href="https://github.com/mews-se"><img src="https://github.com/mews-se.png" width="60px" alt="User avatar: Martin Stockzell" /></a><a href="https://github.com/jdiegmueller"><img src="https://github.com/jdiegmueller.png" width="60px" alt="User avatar: Jason A. Diegmueller" /></a><a href="https://github.com/altugtekiner"><img src="https://github.com/altugtekiner.png" width="60px" alt="User avatar: " /></a><a href="https://github.com/robertsandrock"><img src="https://github.com/robertsandrock.png" width="60px" alt="User avatar: RMS" /></a><a href="https://github.com/KenichiQaz"><img src="https://github.com/KenichiQaz.png" width="60px" alt="User avatar: Stefan" /></a><a href="https://github.com/paulsheets"><img src="https://github.com/paulsheets.png" width="60px" alt="User avatar: Paul" /></a><a href="https://github.com/djones369"><img src="https://github.com/djones369.png" width="60px" alt="User avatar: Dave Jones" /></a><a href="https://github.com/anthonymendez"><img src="https://github.com/anthonymendez.png" width="60px" alt="User avatar: Anthony Mendez" /></a><a href="https://github.com/claudemods"><img src="https://github.com/claudemods.png" width="60px" alt="User avatar: claudemods" /></a><a href="https://github.com/FatBastard0"><img src="https://github.com/FatBastard0.png" width="60px" alt="User avatar: " /></a><a href="https://github.com/Ascent7910"><img src="https://github.com/Ascent7910.png" width="60px" alt="User avatar: Max" /></a><a href="https://github.com/DursleyGuy"><img src="https://github.com/DursleyGuy.png" width="60px" alt="User avatar: DursleyGuy" /></a><a href="https://github.com/realmuddy"><img src="https://github.com/realmuddy.png" width="60px" alt="User avatar: Phillip Waters" /></a><a href="https://github.com/quaszi"><img src="https://github.com/quaszi.png" width="60px" alt="User avatar: " /></a><a href="https://github.com/DwayneTheRockLobster1"><img src="https://github.com/DwayneTheRockLobster1.png" width="60px" alt="User avatar: " /></a><a href="https://github.com/KieraKujisawa"><img src="https://github.com/KieraKujisawa.png" width="60px" alt="User avatar: Kiera Meredith" /></a><!-- sponsors -->
|
||||
|
||||
## 🏅 Thanks to all Contributors
|
||||
Thanks a lot for spending your time helping Winutil grow. Thanks a lot! Keep rocking 🍻.
|
||||
|
171
functions/private/Invoke-WinUtilInteractiveNerdFontInstall.ps1
Normal file
171
functions/private/Invoke-WinUtilInteractiveNerdFontInstall.ps1
Normal file
@ -0,0 +1,171 @@
|
||||
function Invoke-WinUtilInteractiveNerdFontInstall {
|
||||
[CmdletBinding()]
|
||||
param()
|
||||
|
||||
dynamicparam {
|
||||
$url = 'https://raw.githubusercontent.com/ryanoasis/nerd-fonts/master/bin/scripts/lib/fonts.json'
|
||||
$cacheFilePath = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), 'winutil-nerd-fonts.json')
|
||||
$cacheDuration = [TimeSpan]::FromMinutes(2)
|
||||
|
||||
function Get-FontsListFromWeb {
|
||||
try {
|
||||
$fonts = (Invoke-RestMethod -Uri $url -ErrorAction Stop -Verbose:$false -Debug:$false).fonts
|
||||
$releaseUrl = "https://api.github.com/repos/ryanoasis/nerd-fonts/releases/latest"
|
||||
foreach ($font in $fonts) {
|
||||
$font.PSObject.Properties.Add([psnoteproperty]::new("releaseUrl", $releaseUrl))
|
||||
}
|
||||
return $fonts
|
||||
}
|
||||
catch {
|
||||
$PSCmdlet.ThrowTerminatingError($_)
|
||||
}
|
||||
}
|
||||
|
||||
# Check if cache exists and is valid
|
||||
$useCache = $false
|
||||
if (Test-Path $cacheFilePath) {
|
||||
$cacheAge = [DateTime]::Now - (Get-Item $cacheFilePath).LastWriteTime
|
||||
if ($cacheAge -lt $cacheDuration) {
|
||||
$useCache = $true
|
||||
}
|
||||
}
|
||||
|
||||
# Get fonts list either from cache or web
|
||||
try {
|
||||
if ($useCache) {
|
||||
$fonts = Get-Content $cacheFilePath -Raw | ConvertFrom-Json
|
||||
}
|
||||
else {
|
||||
$fonts = Get-FontsListFromWeb
|
||||
$fonts | ConvertTo-Json -Depth 10 | Set-Content $cacheFilePath -Force
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Warning "Failed to get fonts list: $_"
|
||||
return
|
||||
}
|
||||
|
||||
# Create the runtime parameter dictionary
|
||||
$RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
|
||||
|
||||
# Create the collection of attributes
|
||||
$AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
|
||||
|
||||
# Create and set the parameters' attributes
|
||||
$ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
|
||||
$ParameterAttribute.Mandatory = $false # Changed to false to allow interactive mode
|
||||
$ParameterAttribute.Position = 0
|
||||
|
||||
# Add the attributes to the attributes collection
|
||||
$AttributeCollection.Add($ParameterAttribute)
|
||||
|
||||
# Generate and set the ValidateSet
|
||||
$ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($fonts.name)
|
||||
$AttributeCollection.Add($ValidateSetAttribute)
|
||||
|
||||
# Create and return the dynamic parameter
|
||||
$RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter('FontName', [string], $AttributeCollection)
|
||||
$RuntimeParameterDictionary.Add('FontName', $RuntimeParameter)
|
||||
return $RuntimeParameterDictionary
|
||||
}
|
||||
|
||||
begin {
|
||||
$FontName = $PsBoundParameters['FontName']
|
||||
$fontsPath = "$env:LOCALAPPDATA\Microsoft\Windows\Fonts"
|
||||
|
||||
# Create fonts directory if it doesn't exist
|
||||
if (-not (Test-Path $fontsPath)) {
|
||||
New-Item -Path $fontsPath -ItemType Directory -Force | Out-Null
|
||||
}
|
||||
|
||||
# If no font name provided, show interactive menu
|
||||
if (-not $FontName) {
|
||||
Write-Host "`nAvailable Nerd Fonts:" -ForegroundColor Cyan
|
||||
for ($i = 0; $i -lt $fonts.Count; $i++) {
|
||||
Write-Host "$($i + 1). $($fonts[$i].name)"
|
||||
}
|
||||
|
||||
do {
|
||||
$selection = Read-Host "`nEnter the number of the font to install (or 'q' to quit)"
|
||||
|
||||
if ($selection -eq 'q') {
|
||||
return
|
||||
}
|
||||
|
||||
$index = [int]$selection - 1
|
||||
if ($index -ge 0 -and $index -lt $fonts.Count) {
|
||||
$FontName = $fonts[$index].name
|
||||
break
|
||||
}
|
||||
else {
|
||||
Write-Host "Invalid selection. Please try again." -ForegroundColor Red
|
||||
}
|
||||
} while ($true)
|
||||
}
|
||||
|
||||
$selectedFont = $fonts | Where-Object { $_.name -eq $FontName }
|
||||
}
|
||||
|
||||
process {
|
||||
try {
|
||||
Write-Host "`nInstalling $FontName..." -ForegroundColor Yellow
|
||||
|
||||
# Create temp directory
|
||||
$tempDir = Join-Path $env:TEMP "WinUtilNerdFonts"
|
||||
New-Item -Path $tempDir -ItemType Directory -Force | Out-Null
|
||||
|
||||
# Get latest release info
|
||||
$latestRelease = Invoke-RestMethod -Uri $selectedFont.releaseUrl
|
||||
$downloadUrl = $latestRelease.assets |
|
||||
Where-Object { $_.name -like "*$($selectedFont.name)*" } |
|
||||
Select-Object -ExpandProperty browser_download_url -First 1
|
||||
|
||||
if (-not $downloadUrl) {
|
||||
Write-Error "Could not find download URL for $FontName"
|
||||
return
|
||||
}
|
||||
|
||||
# Download font
|
||||
$zipPath = Join-Path $tempDir "$($selectedFont.name).zip"
|
||||
Write-Host "Downloading from $downloadUrl..."
|
||||
Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath
|
||||
|
||||
# Extract and install fonts
|
||||
Write-Host "Extracting and installing fonts..."
|
||||
Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force
|
||||
|
||||
# Get all .ttf and .otf files
|
||||
$fontFiles = Get-ChildItem -Path $tempDir -Recurse -Include "*.ttf","*.otf"
|
||||
|
||||
foreach ($fontFile in $fontFiles) {
|
||||
$destination = Join-Path $fontsPath $fontFile.Name
|
||||
Copy-Item -Path $fontFile.FullName -Destination $destination -Force
|
||||
|
||||
# Add font to registry
|
||||
$fontRegistryPath = "HKCU:\Software\Microsoft\Windows NT\CurrentVersion\Fonts"
|
||||
$fontRegistryName = "$($fontFile.BaseName) (TrueType)"
|
||||
New-ItemProperty -Path $fontRegistryPath -Name $fontRegistryName -Value $fontFile.Name -PropertyType String -Force | Out-Null
|
||||
}
|
||||
|
||||
Write-Host "Successfully installed $FontName!" -ForegroundColor Green
|
||||
|
||||
# Ask if user wants to install another font
|
||||
$installMore = Read-Host "`nWould you like to install another font? (y/n)"
|
||||
if ($installMore -eq 'y') {
|
||||
Invoke-WinUtilInteractiveNerdFontInstall
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Error "Error installing font: $_"
|
||||
Write-Host "Stack Trace: $($_.ScriptStackTrace)" -ForegroundColor Red
|
||||
}
|
||||
finally {
|
||||
# Cleanup
|
||||
if (Test-Path $tempDir) {
|
||||
Remove-Item -Path $tempDir -Recurse -Force
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Export-ModuleMember -Function Invoke-WinUtilInteractiveNerdFontInstall
|
@ -56,7 +56,7 @@ function Test-WinUtilPackageManager {
|
||||
# Check if Winget's Version is too old.
|
||||
$wingetCurrentVersion = [System.Version]::Parse($wingetVersion.Trim('v'))
|
||||
# Grabs the latest release of Winget from the Github API for version check process.
|
||||
$response = winget search -e Microsoft.AppInstaller
|
||||
$response = winget search -e Microsoft.AppInstaller --accept-source-agreements
|
||||
$wingetLatestVersion = ($response | Select-String -Pattern '\d+\.\d+\.\d+\.\d+').Matches.Value
|
||||
Write-Host "Latest Search Version: $wingetLatestVersion" -ForegroundColor White
|
||||
Write-Host "Current Installed Version: $wingetCurrentVersion" -ForegroundColor White
|
||||
|
@ -54,21 +54,27 @@ if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]:
|
||||
$PSBoundParameters.GetEnumerator() | ForEach-Object {
|
||||
$argList += if ($_.Value -is [switch] -and $_.Value) {
|
||||
"-$($_.Key)"
|
||||
} elseif ($_.Value -is [array]) {
|
||||
"-$($_.Key) $($_.Value -join ',')"
|
||||
} elseif ($_.Value) {
|
||||
"-$($_.Key) `"$($_.Value)`""
|
||||
"-$($_.Key) '$($_.Value)'"
|
||||
}
|
||||
}
|
||||
|
||||
$script = if ($MyInvocation.MyCommand.Path) {
|
||||
"& { & '$($MyInvocation.MyCommand.Path)' $argList }"
|
||||
$script = if ($PSCommandPath) {
|
||||
"& { & `'$($PSCommandPath)`' $($argList -join ' ') }"
|
||||
} else {
|
||||
"iex '& { $(irm https://github.com/ChrisTitusTech/winutil/releases/latest/download/winutil.ps1) } $argList'"
|
||||
"&([ScriptBlock]::Create((irm https://github.com/ChrisTitusTech/winutil/releases/latest/download/winutil.ps1))) $($argList -join ' ')"
|
||||
}
|
||||
|
||||
$powershellcmd = if (Get-Command pwsh -ErrorAction SilentlyContinue) { "pwsh" } else { "powershell" }
|
||||
$processCmd = if (Get-Command wt.exe -ErrorAction SilentlyContinue) { "wt.exe" } else { $powershellcmd }
|
||||
$powershellCmd = if (Get-Command pwsh -ErrorAction SilentlyContinue) { "pwsh" } else { "powershell" }
|
||||
$processCmd = if (Get-Command wt.exe -ErrorAction SilentlyContinue) { "wt.exe" } else { "$powershellCmd" }
|
||||
|
||||
Start-Process $processCmd -ArgumentList "$powershellcmd -ExecutionPolicy Bypass -NoProfile -Command $script" -Verb RunAs
|
||||
if ($processCmd -eq "wt.exe") {
|
||||
Start-Process $processCmd -ArgumentList "$powershellCmd -ExecutionPolicy Bypass -NoProfile -Command `"$script`"" -Verb RunAs
|
||||
} else {
|
||||
Start-Process $processCmd -ArgumentList "-ExecutionPolicy Bypass -NoProfile -Command `"$script`"" -Verb RunAs
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
Reference in New Issue
Block a user