Skip to content

Commit

Permalink
Merge pull request #128 from aaronparker/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
aaronparker authored Mar 15, 2023
2 parents bebf8d7 + 134e0d6 commit 4a70efe
Show file tree
Hide file tree
Showing 50 changed files with 509 additions and 2,188 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/update-manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
$Release = "2017"
Import-Module "${{ github.workspace }}\VcRedist" -Force
New-Item -Path "$env:RUNNER_TEMP\VcRedist" -ItemType "Directory" -ErrorAction "SilentlyContinue" | Out-Null
Save-VcRedist -VcList (Get-VcList -Release $Release) -Path "$env:RUNNER_TEMP\VcRedist" -Verbose | Install-VcRedist
Get-VcList -Release $Release | Save-VcRedist -Path "$env:RUNNER_TEMP\VcRedist" | Install-VcRedist
$params = @{
Release = $Release
Path = "$env:RUNNER_TEMP\VcRedist"
Expand All @@ -66,7 +66,7 @@ jobs:
$Release = "2019"
Import-Module "${{ github.workspace }}\VcRedist" -Force
New-Item -Path "$env:RUNNER_TEMP\VcRedist" -ItemType "Directory" -ErrorAction "SilentlyContinue" | Out-Null
Save-VcRedist -VcList (Get-VcList -Release $Release) -Path "$env:RUNNER_TEMP\VcRedist" -Verbose | Install-VcRedist
Get-VcList -Release $Release | Save-VcRedist -Path "$env:RUNNER_TEMP\VcRedist" | Install-VcRedist
$params = @{
Release = $Release
Path = "$env:RUNNER_TEMP\VcRedist"
Expand All @@ -81,7 +81,7 @@ jobs:
$Release = "2022"
Import-Module "${{ github.workspace }}\VcRedist" -Force
New-Item -Path "$env:RUNNER_TEMP\VcRedist" -ItemType "Directory" -ErrorAction "SilentlyContinue" | Out-Null
Save-VcRedist -VcList (Get-VcList -Release $Release) -Path "$env:RUNNER_TEMP\VcRedist" -Verbose | Install-VcRedist
Get-VcList -Release $Release | Save-VcRedist -Path "$env:RUNNER_TEMP\VcRedist" | Install-VcRedist
$params = @{
Release = $Release
Path = "$env:RUNNER_TEMP\VcRedist"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate-module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ jobs:
run: |
.\tests\Install-Pester.ps1
Import-Module -Name "Pester" -Force -ErrorAction "Stop"
Import-Module -Name "$env:GITHUB_WORKSPACE\VcRedist" -Force
$Config = New-PesterConfiguration
$Config.Run.Path = "$env:GITHUB_WORKSPACE\tests"
$Config.Run.PassThru = $True
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ Redists.json
VcDownloads
codecov.exe
.cache
CodeCoverage-windows-2022.xml
TestResults-windows-2022.xml
56 changes: 34 additions & 22 deletions VcRedist/Private/Test-VcListObject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,47 @@ function Test-VcListObject {
[CmdletBinding()]
[OutputType([System.Boolean])]
param (
[Parameter(Position = 0)]
[System.Management.Automation.PSObject] $InputObject,
[Parameter(
Mandatory = $true,
Position = 0,
ValueFromPipeline = $true,
HelpMessage = "Pass a VcList object from Get-VcList.")]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSObject] $VcList,

[Parameter(Position = 1)]
[System.String[]] $RequiredProperties = @("Architecture", "Install", "Name", "ProductCode", `
"Release", "SilentInstall", "SilentUninstall", "UninstallKey", "URI", "URL", "Version")
"Release", "SilentInstall", "SilentUninstall", "UninstallKey", "URI", "URL", "Version", "Path")
)

$Members = Get-Member -InputObject $InputObject -MemberType "NoteProperty"
$params = @{
ReferenceObject = $RequiredProperties
DifferenceObject = $Members.Name
PassThru = $true
ErrorAction = "Stop"
}
$MissingProperties = Compare-Object @params
process {
foreach ($Item in $VcList) {
$Members = Get-Member -InputObject $Item -MemberType "NoteProperty"
$params = @{
ReferenceObject = $RequiredProperties
DifferenceObject = $Members.Name
PassThru = $true
ErrorAction = "Stop"
}
$MissingProperties = Compare-Object @params

if (-not($missingProperties)) {
return $true
}
else {
$MissingProperties | ForEach-Object {
throw [System.Management.Automation.ValidationMetadataException] "Property: '$_' missing."
}
}
if (-not($missingProperties)) {
$Result = $true
}
else {
$MissingProperties | ForEach-Object {
throw [System.Management.Automation.ValidationMetadataException] "Property: '$_' missing."
}
}

$InputObject.PSObject.Properties | ForEach-Object {
if (([System.String]::IsNullOrEmpty($_.Value))) {
throw [System.Management.Automation.ValidationMetadataException] "Property '$($_.Name)' is null or empty."
$Item.PSObject.Properties | ForEach-Object {
if (([System.String]::IsNullOrEmpty($_.Value))) {
throw [System.Management.Automation.ValidationMetadataException] "Property '$($_.Name)' is null or empty."
}
}
}

# Return true if all is good with the object
return $Result
}
}
2 changes: 1 addition & 1 deletion VcRedist/Public/Get-InstalledVcRedist.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function Get-InstalledVcRedist {
$VcRedists = Get-InstalledSoftware | Where-Object { $_.Name -match $Filter }

# Add Architecture property to each entry
Write-Verbose -Message "Adding Architecture property."
Write-Verbose -Message "Add Architecture property to output object."
$VcRedists | ForEach-Object { if ($_.Name -contains "x64") { $_ | Add-Member -NotePropertyName "Architecture" -NotePropertyValue "x64" } }

# Write the installed VcRedists to the pipeline
Expand Down
70 changes: 35 additions & 35 deletions VcRedist/Public/Get-VcList.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ function Get-VcList {
<#
.EXTERNALHELP VcRedist-help.xml
#>
[Alias("Get-VcRedist")]
[OutputType([System.Management.Automation.PSObject])]
[CmdletBinding(DefaultParameterSetName = "Manifest", HelpURI = "https://vcredist.com/get-vclist/")]
param (
[Parameter(Mandatory = $false, Position = 0, ParameterSetName = "Manifest")]
[ValidateSet("2005", "2008", "2010", "2012", "2013", "2015", "2017", "2019", "2022")]
[ValidateSet("2012", "2013", "2015", "2017", "2019", "2022")]
[System.String[]] $Release = @("2012", "2013", "2022"),

[Parameter(Mandatory = $false, Position = 1, ParameterSetName = "Manifest")]
Expand All @@ -17,86 +18,85 @@ function Get-VcList {
[ValidateScript( { if (Test-Path -Path $_ -PathType "Leaf") { $true } else { throw "Cannot find file $_" } })]
[ValidateNotNullOrEmpty()]
[Alias("Xml")]
[System.String] $Path = (Join-Path -Path $MyInvocation.MyCommand.Module.ModuleBase -ChildPath "VisualCRedistributables.json"),
[System.String] $Path = $(Join-Path -Path $MyInvocation.MyCommand.Module.ModuleBase -ChildPath "VisualCRedistributables.json"),

[Parameter(Mandatory = $false, Position = 0, ParameterSetName = "Export")]
[ValidateSet("Supported", "All", "Unsupported")]
[System.String] $Export = "Supported"
)

process {
Write-Verbose -Message "Reading JSON document [$Path]."
$params = @{
Path = $Path
Raw = $true
ErrorAction = "Stop"
}
$content = Get-Content @params

try {
# Convert the JSON content to an object
Write-Verbose -Message "Reading VcRedist manifest '$Path'."
$params = @{
Path = $Path
Raw = $true
ErrorAction = "Stop"
}
$Content = Get-Content @params
Write-Verbose -Message "Converting JSON."
$json = $content | ConvertFrom-Json -ErrorAction "Continue"
$JsonManifest = $Content | ConvertFrom-Json -ErrorAction "Continue"
}
catch [System.Exception] {
Write-Warning -Message "Unable to convert manifest JSON to required object. Please validate the input manifest."
throw $_
}

if ($null -ne $json) {
if ($null -ne $JsonManifest) {
if ($PSBoundParameters.ContainsKey("Export")) {
switch ($Export) {
"Supported" {
Write-Verbose -Message "Exporting supported VcRedists."
[System.Management.Automation.PSObject] $output = $json.Supported
}
"All" {
Write-Verbose -Message "Exporting all VcRedists."
Write-Warning -Message "This list includes unsupported Visual C++ Redistributables."
[System.Management.Automation.PSObject] $output = $json.Supported + $json.Unsupported
[System.Management.Automation.PSObject] $Output = $JsonManifest.Supported + $JsonManifest.Unsupported
break
}
"Supported" {
Write-Verbose -Message "Exporting supported VcRedists."
[System.Management.Automation.PSObject] $Output = $JsonManifest.Supported
break
}
"Unsupported" {
Write-Verbose -Message "Exporting unsupported VcRedists."
Write-Warning -Message "This list includes unsupported Visual C++ Redistributables."
[System.Management.Automation.PSObject] $output = $json.Unsupported
[System.Management.Automation.PSObject] $Output = $JsonManifest.Unsupported
break
}
}
}
else {
# Filter the list for architecture and release
if ($json | Get-Member -Name "Supported" -MemberType "Properties") {
[System.Management.Automation.PSObject] $supported = $json.Supported
}
else {
[System.Management.Automation.PSObject] $supported = $json
}
[System.Management.Automation.PSObject] $output = $supported | Where-Object { $Release -contains $_.Release } | `
# if ($Release -match $JsonManifest.Unsupported.Release) {
# Write-Warning -Message "This list includes unsupported Visual C++ Redistributables."
# }
[System.Management.Automation.PSObject] $Output = $JsonManifest.Supported | Where-Object { $Release -contains $_.Release } | `
Where-Object { $Architecture -contains $_.Architecture }
}

# Get the count of items in $output; Because it's a PSCustomObject we can't use the .count property so need to measure the object
# Grab a NoteProperty and count how many of those there are to get the object count
try {
$Property = $output | Get-Member -ErrorAction "SilentlyContinue" | Where-Object { $_.MemberType -eq "NoteProperty" } | Select-Object -ExpandProperty "Name" | Select-Object -First 1
$Count = $output.$Property.Count - 1
# Get the count of items in $Output; Because it's a PSCustomObject we can't use the .count property so need to measure the object
# Grab a NoteProperty and count how many of those there are to get the object count
$Property = $Output | Get-Member -ErrorAction "SilentlyContinue" | Where-Object { $_.MemberType -eq "NoteProperty" } | Select-Object -ExpandProperty "Name" | Select-Object -First 1
$Count = $Output.$Property.Count - 1
}
catch {
$Count = 0
}

# Replace strings in the manifest
Write-Verbose -Message "Object count is: $($output.$Property.Count)."
Write-Verbose -Message "Object count is: $($Output.$Property.Count)."
for ($i = 0; $i -le $Count; $i++) {
try {
$output[$i].SilentUninstall = $output[$i].SilentUninstall `
-replace "#Installer", $(Split-Path -Path $output[$i].URI -Leaf) `
-replace "#ProductCode", $output[$i].ProductCode
$Output[$i].SilentUninstall = $Output[$i].SilentUninstall `
-replace "#Installer", $(Split-Path -Path $Output[$i].URI -Leaf) `
-replace "#ProductCode", $Output[$i].ProductCode
}
catch {
Write-Verbose -Message "Failed to replace strings in: $($json[$i].Name)."
Write-Verbose -Message "Failed to replace strings in: $($JsonManifest[$i].Name)."
}
}
Write-Output -InputObject $output
Write-Output -InputObject $Output
}
}
}
Loading

0 comments on commit 4a70efe

Please sign in to comment.