Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:metablaster/WindowsFirewallRules…
Browse files Browse the repository at this point in the history
…et into develop
  • Loading branch information
metablaster committed Jun 21, 2023
2 parents cffdd5e + 875f27f commit 02750cd
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Config/ProjectSettings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ if (!(Get-Variable -Name CheckReadOnlyVariables -Scope Global -ErrorAction Ignor

# Set to false to avoid checking system and environment requirements
# This will also disable checking for modules and required services
New-Variable -Name ProjectCheck -Scope Global -Option ReadOnly -Value $false
New-Variable -Name ProjectCheck -Scope Global -Option ReadOnly -Value $true

# Set to false to avoid checking if modules are up to date
# Enabling this make sense only for development or code navigation
Expand Down
30 changes: 25 additions & 5 deletions Modules/Ruleset.Initialize/Public/Initialize-Provider.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,25 @@ function Initialize-Provider
# NOTE: If Nuget is not installed Windows PowerShell will ask to install it here and if accepted
# $AllProviders will be initialized to downloaded and installed provider
# TODO: Bootstraping should be handled manually
[Microsoft.PackageManagement.Packaging.SoftwareIdentity[]] $AllProviders = Find-PackageProvider -Name $ProviderName `
-RequiredVersion $RequiredVersion -IncludeDependencies -ErrorAction SilentlyContinue
try
{
[Microsoft.PackageManagement.Packaging.SoftwareIdentity[]] $AllProviders = Find-PackageProvider -Name $ProviderName `
-RequiredVersion $RequiredVersion -IncludeDependencies -ErrorAction Stop
}
catch
{
$InstalledPackage = Get-PackageProvider -Name $ProviderName -ErrorAction SilentlyContinue
$InstalledPackageVersion = $InstalledPackage | Select-Object -ExpandProperty Version

# Grater than because we do not specify revision in $RequiredVersion which is initialized to -1
if ($InstalledPackageVersion -and ($InstalledPackageVersion -gt $RequiredVersion))
{
# NOTE: On Windows 11 system if user chooses to accept downloading the package with
# Find-PackageProvider above it won't initialize $AllProviders but the package may be installed
# This was the case with NuGet on fresh system with out of date NuGet provider
$AllProviders = $InstalledPackage
}
}

# If provider was found with Find-PackageProvider it should be installed with Install-PackageProvider
$UseInstallPackageProvider = $true
Expand Down Expand Up @@ -390,9 +407,13 @@ function Initialize-Provider
# If package source for "FoundProvider" is not registered do nothing, this will be the cause with
# "Bootstrap" provider, which means NuGet was already installed during "Find-PackageProvider" above!
# It may also be the case if a user denied registering a package source.
if ($FoundPackageSource.ProviderName -notin (Get-PackageSource).ProviderName)
if (!$FoundPackageSource -or ($FoundPackageSource.ProviderName -notin (Get-PackageSource).ProviderName))
{
Write-Warning -Message "[$($MyInvocation.InvocationName)] Not using '$($FoundPackageSource.ProviderName)' provider to install package, package source not registered"
# Else warning was diplayed by Get-PackageSource
if ($FoundPackageSource)
{
Write-Warning -Message "[$($MyInvocation.InvocationName)] Not using '$($FoundPackageSource.ProviderName)' provider to install package, package source not registered"
}

# TODO: This scenario needs testing, it currently works for NuGet in Windows PowerShell
return $null -ne (Get-PackageProvider -Name $ProviderName)
Expand Down Expand Up @@ -553,7 +574,6 @@ function Initialize-Provider
return $false
}


return $true
}
else
Expand Down
16 changes: 10 additions & 6 deletions Modules/Ruleset.Initialize/Public/Uninstall-DuplicateModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,10 @@ function Uninstall-DuplicateModule
}
catch
{
Write-Warning -Message "[$($MyInvocation.InvocationName)] Please close down all PowerShell sessions including VSCode, then try again in fresh console"

Write-Error -Category ResourceBusy -TargetObject $LoadedModule `
-Message "Module '$ModuleName' could not be removed from current PS session which is required for uninstallation because: $($_.Exception.Message)"
Write-Warning -Message "[$($MyInvocation.InvocationName)] Please close down all other PowerShell sessions including VSCode, then try again"
continue
}
}
Expand Down Expand Up @@ -237,14 +238,17 @@ function Uninstall-DuplicateModule
}
catch
{
Write-Error -Category OperationStopped -TargetObject $ModuleRoot `
-Message "Module directory '$ModuleRoot' could not be recursively removed because: $($_.Exception.Message)"

if ($ModuleRoot -like "$($pwd.Path)*")
{
Write-Information -Tags $MyInvocation.InvocationName `
-MessageData "INFO: This session's prompt is inside module path, the prompt must leave module path $($pwd.Path)"
Write-Warning -Message "[$($MyInvocation.InvocationName)] This session's prompt is inside module path, the prompt must leave module path $($pwd.Path)"
}
else
{
Write-Warning -Message "[$($MyInvocation.InvocationName)] please close down other PowerShell sessions including VSCode, then try again in fresh console"
}

Write-Error -Category OperationStopped -TargetObject $ModuleRoot `
-Message "Module directory '$ModuleRoot' could not be recursively removed because: $($_.Exception.Message)"
continue
}

Expand Down
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Here is a list of changes for each of the releases.
- `Get-SystemSoftware` renamed to `Get-SystemProgram`
- `Get-UserSoftware` renamed to `Get-UserProgram`
- `Get-SystemProgram` Improved program search
- `Uninstall-DuplicateModule` Improved to show reason for failure and how to fix
- `Initialize-Provider` Was failing in Windows PS on Windows 11, fixed

- Scripts

Expand Down

0 comments on commit 02750cd

Please sign in to comment.