mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
[CommandNotFound]Upgrade to use PSGallery release and support arm64 (#32766)
* [CommandNotFound] Add support for upgrading the module * upgrade module as a part of upgrade installation; actually set content in EnableModule.ps1 * Fix XAML style to pass CI * Remove CmdNotFound project from sln as well * Remove CmdNotFound psd1 file from installer * More installer fixes * UpgradeCommandNotFound runs after InstallFiles * Fix NOTICE.md * Fix custom action condition * Pass install folder to the custom action * Upgrade-Module --> Update-Module * actually install the module * spell * verify updated scripts work; make necessary changes --------- Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
This commit is contained in:
@@ -10,10 +10,25 @@ else
|
||||
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
|
||||
}
|
||||
|
||||
if (Get-Module -ListAvailable -Name Microsoft.WinGet.Client)
|
||||
if ($mods = Get-Module -ListAvailable -Name Microsoft.WinGet.Client)
|
||||
{
|
||||
Write-Host "WinGet Client module detected."
|
||||
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
|
||||
|
||||
$needsUpdate = $true;
|
||||
foreach ($mod in $mods)
|
||||
{
|
||||
if ($mod.Version -ge "1.8.1133")
|
||||
{
|
||||
$needsUpdate = $false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($needsUpdate)
|
||||
{
|
||||
Write-Host "WinGet Client module needs to be updated."
|
||||
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Host "WinGet Client module not detected. Installation instructions can be found on https://www.powershellgallery.com/packages/Microsoft.WinGet.Client `r`n"
|
||||
@@ -30,6 +45,11 @@ if (!(Test-Path $PROFILE))
|
||||
$profileContent = Get-Content -Path $PROFILE -Raw
|
||||
|
||||
if ((-not [string]::IsNullOrEmpty($profileContent)) -and ($profileContent.Contains("34de4b3d-13a8-4540-b76d-b9e8d3851756")))
|
||||
{
|
||||
Write-Host "Outdated version of Command Not Found module found in the profile file."
|
||||
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
|
||||
}
|
||||
elseif ((-not [string]::IsNullOrEmpty($profileContent)) -and ($profileContent.Contains("f45873b3-b655-43a6-b217-97c00aa0db58")))
|
||||
{
|
||||
Write-Host "Command Not Found module is registered in the profile file."
|
||||
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
|
||||
|
||||
@@ -5,14 +5,14 @@ $linesToDeleteFound = $False
|
||||
$atLeastOneInstanceFound = $False
|
||||
|
||||
$profileContent | ForEach-Object {
|
||||
if ($_.Contains("34de4b3d-13a8-4540-b76d-b9e8d3851756") -and !$linesToDeleteFound)
|
||||
if (($_.Contains("34de4b3d-13a8-4540-b76d-b9e8d3851756") -or $_.Contains("f45873b3-b655-43a6-b217-97c00aa0db58")) -and !$linesToDeleteFound)
|
||||
{
|
||||
$linesToDeleteFound = $True
|
||||
$atLeastOneInstanceFound = $True
|
||||
return
|
||||
}
|
||||
|
||||
if ($_.Contains("34de4b3d-13a8-4540-b76d-b9e8d3851756") -and $linesToDeleteFound)
|
||||
if (($_.Contains("34de4b3d-13a8-4540-b76d-b9e8d3851756") -or $_.Contains("f45873b3-b655-43a6-b217-97c00aa0db58")) -and $linesToDeleteFound)
|
||||
{
|
||||
$linesToDeleteFound = $False
|
||||
return
|
||||
|
||||
@@ -9,13 +9,36 @@ Enable-ExperimentalFeature PSFeedbackProvider
|
||||
Write-Host "Enabling experimental feature: PSCommandNotFoundSuggestion"
|
||||
Enable-ExperimentalFeature PSCommandNotFoundSuggestion
|
||||
|
||||
if (Get-Module -ListAvailable -Name Microsoft.WinGet.Client) {
|
||||
$wingetModules = Get-Module -ListAvailable -Name Microsoft.WinGet.Client
|
||||
if ($wingetModules) {
|
||||
|
||||
$moduleUpToDate = $false;
|
||||
foreach ($mod in $wingetModules) {
|
||||
if ($mod.Version -ge "1.8.1133") {
|
||||
$moduleUpToDate = $true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($moduleUpToDate) {
|
||||
Write-Host "WinGet Client module detected"
|
||||
} else {
|
||||
Write-Host "WinGet module needs to be updated. Run `"Update-Module -Name Microsoft.WinGet.Client`" to update `r`n"
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Host "WinGet module was not found. Installation instructions can be found on https://www.powershellgallery.com/packages/Microsoft.WinGet.Client `r`n"
|
||||
}
|
||||
|
||||
$CNFModule = Get-Module -ListAvailable -Name Microsoft.WinGet.CommandNotFound
|
||||
if ($CNFModule) {
|
||||
Write-Host "Microsoft.WinGet.CommandNotFound module detected"
|
||||
} else {
|
||||
Write-Host "Microsoft.WinGet.CommandNotFound was not found. Installing...`r`n"
|
||||
Install-Module -Name Microsoft.WinGet.CommandNotFound -Force
|
||||
Write-Host "Microsoft.WinGet.CommandNotFound module installed`r`n"
|
||||
}
|
||||
|
||||
if (!(Test-Path $PROFILE))
|
||||
{
|
||||
Write-Host "Profile file $PROFILE not found".
|
||||
@@ -26,15 +49,28 @@ if (!(Test-Path $PROFILE))
|
||||
$profileContent = Get-Content -Path $PROFILE -Raw
|
||||
|
||||
if ((-not [string]::IsNullOrEmpty($profileContent)) -and ($profileContent.Contains("34de4b3d-13a8-4540-b76d-b9e8d3851756")))
|
||||
{
|
||||
if ($profileContent.Contains("Import-Module `"$scriptPath\WinGetCommandNotFound.psd1`""))
|
||||
{
|
||||
$profileContent = $profileContent.Replace("Import-Module `"$scriptPath\WinGetCommandNotFound.psd1`"",
|
||||
"Import-Module -Name Microsoft.WinGet.CommandNotFound")
|
||||
$profileContent = $profileContent.Replace("34de4b3d-13a8-4540-b76d-b9e8d3851756",
|
||||
"f45873b3-b655-43a6-b217-97c00aa0db58")
|
||||
Set-Content -Path $PROFILE -Value $profileContent
|
||||
Write-Host "Module was successfully upgraded in the profile file."
|
||||
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
|
||||
}
|
||||
}
|
||||
elseif ((-not [string]::IsNullOrEmpty($profileContent)) -and ($profileContent.Contains("f45873b3-b655-43a6-b217-97c00aa0db58")))
|
||||
{
|
||||
Write-Host "Module is already registered in the profile file."
|
||||
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
|
||||
}
|
||||
else
|
||||
{
|
||||
Add-Content -Path $PROFILE -Value "`r`n#34de4b3d-13a8-4540-b76d-b9e8d3851756 PowerToys CommandNotFound module"
|
||||
Add-Content -Path $PROFILE -Value "`r`nImport-Module `"$scriptPath\WinGetCommandNotFound.psd1`""
|
||||
Add-Content -Path $PROFILE -Value "#34de4b3d-13a8-4540-b76d-b9e8d3851756"
|
||||
Add-Content -Path $PROFILE -Value "`r`n#f45873b3-b655-43a6-b217-97c00aa0db58 PowerToys CommandNotFound module"
|
||||
Add-Content -Path $PROFILE -Value "`r`nImport-Module -Name Microsoft.WinGet.CommandNotFound"
|
||||
Add-Content -Path $PROFILE -Value "#f45873b3-b655-43a6-b217-97c00aa0db58"
|
||||
Write-Host "Module was successfully registered in the profile file."
|
||||
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
|
||||
}
|
||||
|
||||
@@ -1,7 +1,46 @@
|
||||
if (Get-Module -ListAvailable -Name Microsoft.WinGet.Client)
|
||||
$wingetModules = Get-Module -ListAvailable -Name Microsoft.WinGet.Client
|
||||
if ($wingetModules)
|
||||
{
|
||||
Write-Host "WinGet Client module detected."
|
||||
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
|
||||
$needsUpdate = $true;
|
||||
foreach ($mod in $wingetModules)
|
||||
{
|
||||
if ($mod.Version -ge "1.8.1133")
|
||||
{
|
||||
$needsUpdate = $false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($needsUpdate)
|
||||
{
|
||||
Update-Module -Name Microsoft.WinGet.Client -Force
|
||||
$wingetModules = Get-Module -ListAvailable -Name Microsoft.WinGet.Client
|
||||
$updated = $false;
|
||||
foreach ($mod in $wingetModules)
|
||||
{
|
||||
if ($mod.Version -ge "1.8.1133")
|
||||
{
|
||||
$updated = $true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($updated)
|
||||
{
|
||||
Write-Host "WinGet Client module updated."
|
||||
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host "WinGet Client module detected."
|
||||
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host "WinGet Client module detected."
|
||||
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
|
||||
}
|
||||
}
|
||||
else {
|
||||
Install-Module -Name Microsoft.WinGet.Client
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
if (!(Test-Path $PROFILE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$profileContent = Get-Content -Path $PROFILE -Raw
|
||||
$legacyGuid = "34de4b3d-13a8-4540-b76d-b9e8d3851756"
|
||||
if ((-not [string]::IsNullOrEmpty($profileContent)) -and ($profileContent.Contains($legacyGuid)))
|
||||
{
|
||||
# Upgrade Microsoft.WinGet.Client module
|
||||
$wingetModule = Get-Module -ListAvailable -Name Microsoft.WinGet.Client
|
||||
if ($wingetModule -and $wingetModule.Version -lt "1.8.1133") {
|
||||
Update-Module -Name Microsoft.WinGet.Client
|
||||
}
|
||||
|
||||
# Install Microsoft.WinGet.CommandNotFound module
|
||||
if (-Not (Get-Module -ListAvailable -Name Microsoft.WinGet.CommandNotFound)) {
|
||||
Install-Module -Name Microsoft.WinGet.CommandNotFound -Force
|
||||
}
|
||||
|
||||
# Replace old module with new one (and new GUID comment)
|
||||
$regex = "Import-Module .*WinGetCommandNotFound.psd1`""
|
||||
if ($profileContent -match $regex)
|
||||
{
|
||||
$profileContent = $profileContent -replace $regex, "Import-Module -Name Microsoft.WinGet.CommandNotFound"
|
||||
$profileContent = $profileContent -replace $legacyGuid, "f45873b3-b655-43a6-b217-97c00aa0db58"
|
||||
Set-Content -Path $PROFILE -Value $profileContent
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user