mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-07-01 10:32:35 -05:00
Compare commits
4 Commits
winget-fix
...
25.03.05
Author | SHA1 | Date | |
---|---|---|---|
52de4690ab | |||
ef97a8da24 | |||
18a7f17a0b | |||
5a8cf5deb6 |
@ -2934,5 +2934,13 @@
|
|||||||
"description": "Fork - a fast and friendly git client.",
|
"description": "Fork - a fast and friendly git client.",
|
||||||
"link": "https://git-fork.com/",
|
"link": "https://git-fork.com/",
|
||||||
"winget": "Fork.Fork"
|
"winget": "Fork.Fork"
|
||||||
|
},
|
||||||
|
"ZenBrowser": {
|
||||||
|
"category": "Browsers",
|
||||||
|
"choco": "na",
|
||||||
|
"content": "Zen Browser",
|
||||||
|
"description": "The modern, privacy-focused, performance-driven browser built on Firefox",
|
||||||
|
"link": "https://zen-browser.app/",
|
||||||
|
"winget": "Zen-Team.Zen-Browser"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,103 +48,29 @@ function Install-WinUtilWinget {
|
|||||||
Write-Information "WinGet not found or update failed. Attempting to install from Microsoft Store..."
|
Write-Information "WinGet not found or update failed. Attempting to install from Microsoft Store..."
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
# Try to close any running WinGet processes
|
Write-Host "Attempting to repair WinGet using Repair-WinGetPackageManager..." -ForegroundColor Yellow
|
||||||
Get-Process -Name "DesktopAppInstaller", "winget" -ErrorAction SilentlyContinue | ForEach-Object {
|
|
||||||
Write-Information "Stopping running WinGet process..."
|
|
||||||
$_.Kill()
|
|
||||||
Start-Sleep -Seconds 2
|
|
||||||
}
|
|
||||||
|
|
||||||
# Try to load Windows Runtime assemblies more reliably
|
# Check if Windows version supports Repair-WinGetPackageManager (24H2 and above)
|
||||||
$null = [System.Runtime.WindowsRuntime.WindowsRuntimeSystemExtensions]
|
if ([System.Environment]::OSVersion.Version.Build -ge 26100) {
|
||||||
Add-Type -AssemblyName System.Runtime.WindowsRuntime
|
Repair-WinGetPackageManager -Force -Latest -Verbose
|
||||||
|
# Verify if repair was successful
|
||||||
# Load required assemblies from Windows SDK
|
$wingetCmd = Get-Command winget -ErrorAction Stop
|
||||||
$null = @(
|
Write-Host "WinGet repair successful!" -ForegroundColor Green
|
||||||
[Windows.Management.Deployment.PackageManager, Windows.Management.Deployment, ContentType = WindowsRuntime]
|
|
||||||
[Windows.Foundation.Uri, Windows.Foundation, ContentType = WindowsRuntime]
|
|
||||||
[Windows.Management.Deployment.DeploymentOptions, Windows.Management.Deployment, ContentType = WindowsRuntime]
|
|
||||||
)
|
|
||||||
|
|
||||||
# Initialize PackageManager
|
|
||||||
$packageManager = New-Object Windows.Management.Deployment.PackageManager
|
|
||||||
|
|
||||||
# Rest of the Microsoft Store installation logic
|
|
||||||
$appxPackage = "https://aka.ms/getwinget"
|
|
||||||
$uri = New-Object Windows.Foundation.Uri($appxPackage)
|
|
||||||
$deploymentOperation = $packageManager.AddPackageAsync($uri, $null, "Add")
|
|
||||||
|
|
||||||
# Add timeout check for deployment operation
|
|
||||||
$timeout = 300
|
|
||||||
$timer = [System.Diagnostics.Stopwatch]::StartNew()
|
|
||||||
|
|
||||||
while ($deploymentOperation.Status -eq 0) {
|
|
||||||
if ($timer.Elapsed.TotalSeconds -gt $timeout) {
|
|
||||||
throw "Installation timed out after $timeout seconds"
|
|
||||||
}
|
|
||||||
Start-Sleep -Milliseconds 100
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($deploymentOperation.Status -eq 1) {
|
|
||||||
Write-Information "Successfully installed WinGet from Microsoft Store"
|
|
||||||
Write-Output "Refreshing Environment Variables...`n"
|
|
||||||
$ENV:PATH = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
|
|
||||||
return
|
|
||||||
} else {
|
} else {
|
||||||
throw "Installation failed with status: $($deploymentOperation.Status)"
|
Write-Host "Repair-WinGetPackageManager is only available on Windows 24H2 and above. Your version doesn't support this method." -ForegroundColor Yellow
|
||||||
}
|
throw "Windows version not supported for repair method"
|
||||||
} catch {
|
|
||||||
Write-Information "Microsoft Store installation failed. Attempting to install from Nuget..."
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
## Nuget Method
|
|
||||||
Write-Host "Enabling NuGet and Module..."
|
|
||||||
# Enable TLS 1.2 for the PowerShell session
|
|
||||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
|
||||||
|
|
||||||
# Try to register the NuGet package source if not present
|
|
||||||
if (-not (Get-PackageSource -Name "NuGet" -ErrorAction SilentlyContinue)) {
|
|
||||||
Register-PackageSource -Name "NuGet" -Location "https://www.nuget.org/api/v2" -ProviderName NuGet -Force
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Install NuGet provider with error handling
|
|
||||||
try {
|
|
||||||
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Confirm:$false -ErrorAction Stop
|
|
||||||
} catch {
|
|
||||||
Write-Warning "Failed to install NuGet provider through standard method. Trying alternative approach..."
|
|
||||||
Install-PackageProvider -Name NuGet -Source "https://www.powershellgallery.com/api/v2" -Force -Confirm:$false
|
|
||||||
}
|
|
||||||
Install-Module -Name Microsoft.WinGet.Client -Confirm:$false -Force
|
|
||||||
|
|
||||||
# Check if WinGet was installed successfully through NuGet
|
|
||||||
$wingetCmd = Get-Command winget -ErrorAction Stop
|
|
||||||
Write-Information "Successfully installed WinGet through NuGet"
|
|
||||||
Write-Output "Refreshing Environment Variables...`n"
|
Write-Output "Refreshing Environment Variables...`n"
|
||||||
$ENV:PATH = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
|
$ENV:PATH = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
|
||||||
return
|
return
|
||||||
} catch {
|
|
||||||
Write-Warning "NuGet installation failed. Attempting to install from GitHub..."
|
|
||||||
}
|
|
||||||
# GitHub fallback installation method
|
|
||||||
$releases_url = "https://api.github.com/repos/microsoft/winget-cli/releases/latest"
|
|
||||||
$asset = (Invoke-RestMethod -Uri $releases_url).assets |
|
|
||||||
Where-Object { $_.name -match "\.msixbundle$" } |
|
|
||||||
Select-Object -First 1
|
|
||||||
|
|
||||||
$download_url = $asset.browser_download_url
|
|
||||||
$output_path = Join-Path $env:TEMP $asset.name
|
|
||||||
|
|
||||||
Invoke-WebRequest -Uri $download_url -OutFile $output_path
|
|
||||||
Add-AppxPackage -Path $output_path -ErrorAction Stop
|
|
||||||
|
|
||||||
# Verify installation
|
|
||||||
$wingetCmd = Get-Command winget -ErrorAction Stop
|
|
||||||
Write-Information "Successfully installed WinGet through GitHub"
|
|
||||||
Write-Output "Refreshing Environment Variables...`n"
|
|
||||||
$ENV:PATH = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
|
|
||||||
return
|
|
||||||
} catch {
|
} catch {
|
||||||
Write-Error "All installation methods failed. Unable to install WinGet."
|
Write-Error "All installation methods failed. Unable to install WinGet."
|
||||||
throw
|
throw
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
Write-Error "An error occurred during WinGet installation: $_"
|
||||||
|
throw
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,15 @@ function Test-WinUtilPackageManager {
|
|||||||
# Check if Winget is available while getting it's Version if it's available
|
# Check if Winget is available while getting it's Version if it's available
|
||||||
$wingetExists = $true
|
$wingetExists = $true
|
||||||
try {
|
try {
|
||||||
$wingetVersionFull = winget --version
|
$wingetInfo = winget --info
|
||||||
|
# Extract the package version from the output
|
||||||
|
$wingetVersionFull = ($wingetInfo | Select-String -Pattern 'Microsoft\.DesktopAppInstaller v\d+\.\d+\.\d+\.\d+').Matches.Value
|
||||||
|
if ($wingetVersionFull) {
|
||||||
|
$wingetVersionFull = $wingetVersionFull.Split(' ')[-1].TrimStart('v')
|
||||||
|
} else {
|
||||||
|
# Fallback in case the pattern isn't found
|
||||||
|
$wingetVersionFull = ($wingetInfo | Select-String -Pattern 'Package Manager v\d+\.\d+\.\d+').Matches.Value.Split(' ')[-1]
|
||||||
|
}
|
||||||
} catch [System.Management.Automation.CommandNotFoundException], [System.Management.Automation.ApplicationFailedException] {
|
} catch [System.Management.Automation.CommandNotFoundException], [System.Management.Automation.ApplicationFailedException] {
|
||||||
Write-Warning "Winget was not found due to un-availablity reasons"
|
Write-Warning "Winget was not found due to un-availablity reasons"
|
||||||
$wingetExists = $false
|
$wingetExists = $false
|
||||||
@ -48,13 +56,14 @@ function Test-WinUtilPackageManager {
|
|||||||
# Check if Winget's Version is too old.
|
# Check if Winget's Version is too old.
|
||||||
$wingetCurrentVersion = [System.Version]::Parse($wingetVersion.Trim('v'))
|
$wingetCurrentVersion = [System.Version]::Parse($wingetVersion.Trim('v'))
|
||||||
# Grabs the latest release of Winget from the Github API for version check process.
|
# Grabs the latest release of Winget from the Github API for version check process.
|
||||||
$response = Invoke-RestMethod -Uri "https://api.github.com/repos/microsoft/Winget-cli/releases/latest" -Method Get -ErrorAction Stop
|
$response = winget search -e Microsoft.AppInstaller --accept-source-agreements
|
||||||
$wingetLatestVersion = [System.Version]::Parse(($response.tag_name).Trim('v')) #Stores version number of latest release.
|
$wingetLatestVersion = ($response | Select-String -Pattern '\d+\.\d+\.\d+\.\d+').Matches.Value
|
||||||
$wingetOutdated = $wingetCurrentVersion -lt $wingetLatestVersion
|
Write-Host "Latest Search Version: $wingetLatestVersion" -ForegroundColor White
|
||||||
|
Write-Host "Current Installed Version: $wingetCurrentVersion" -ForegroundColor White
|
||||||
|
$wingetOutdated = $wingetCurrentVersion -lt [System.Version]::Parse($wingetLatestVersion)
|
||||||
Write-Host "===========================================" -ForegroundColor Green
|
Write-Host "===========================================" -ForegroundColor Green
|
||||||
Write-Host "--- Winget is installed ---" -ForegroundColor Green
|
Write-Host "--- Winget is installed ---" -ForegroundColor Green
|
||||||
Write-Host "===========================================" -ForegroundColor Green
|
Write-Host "===========================================" -ForegroundColor Green
|
||||||
Write-Host "Version: $wingetVersionFull" -ForegroundColor White
|
|
||||||
|
|
||||||
if (!$wingetPreview) {
|
if (!$wingetPreview) {
|
||||||
Write-Host " - Winget is a release version." -ForegroundColor Green
|
Write-Host " - Winget is a release version." -ForegroundColor Green
|
||||||
|
@ -54,21 +54,27 @@ if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]:
|
|||||||
$PSBoundParameters.GetEnumerator() | ForEach-Object {
|
$PSBoundParameters.GetEnumerator() | ForEach-Object {
|
||||||
$argList += if ($_.Value -is [switch] -and $_.Value) {
|
$argList += if ($_.Value -is [switch] -and $_.Value) {
|
||||||
"-$($_.Key)"
|
"-$($_.Key)"
|
||||||
|
} elseif ($_.Value -is [array]) {
|
||||||
|
"-$($_.Key) $($_.Value -join ',')"
|
||||||
} elseif ($_.Value) {
|
} elseif ($_.Value) {
|
||||||
"-$($_.Key) `"$($_.Value)`""
|
"-$($_.Key) '$($_.Value)'"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$script = if ($MyInvocation.MyCommand.Path) {
|
$script = if ($PSCommandPath) {
|
||||||
"& { & '$($MyInvocation.MyCommand.Path)' $argList }"
|
"& { & `'$($PSCommandPath)`' $($argList -join ' ') }"
|
||||||
} else {
|
} 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" }
|
$powershellCmd = if (Get-Command pwsh -ErrorAction SilentlyContinue) { "pwsh" } else { "powershell" }
|
||||||
$processCmd = if (Get-Command wt.exe -ErrorAction SilentlyContinue) { "wt.exe" } else { $powershellcmd }
|
$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
|
break
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user