Skip to content

Commit 1ae4980

Browse files
committed
CRXUpdateInfo
- added Id, FileName - changed Version type Functions load order (private vs public) Get-CRX. Test-CRXUpdateAvailable - support two parameters set
1 parent 74de841 commit 1ae4980

File tree

5 files changed

+51
-20
lines changed

5 files changed

+51
-20
lines changed

CRX/CRX.psd1

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11

22
@{
3-
RootModule = 'CRX.psm1'
4-
ModuleVersion = '0.1.1'
5-
GUID = 'b5433b6c-b423-4049-8c5e-b3a50566fcf2'
6-
Author = 'Alan Plocieniak'
7-
CompanyName = 'Alan Plocieniak'
8-
Copyright = '(c) 2025 Alan Plocieniak. All rights reserved.'
9-
Description = 'Module for downloading CRX (extension package) for Chromium-based browsers.'
3+
RootModule = 'CRX.psm1'
4+
ModuleVersion = '0.2.0'
5+
GUID = 'b5433b6c-b423-4049-8c5e-b3a50566fcf2'
6+
Author = 'Alan Plocieniak'
7+
CompanyName = 'Alan Plocieniak'
8+
Copyright = '(c) 2025 Alan Plocieniak. All rights reserved.'
9+
Description = 'Module for downloading CRX (extension package) for Chromium-based browsers.'
1010
PowerShellVersion = '5.1'
1111
CompatiblePSEditions = 'Desktop', 'Core'
12-
FunctionsToExport = '*'
12+
FunctionsToExport = '*'
1313
PrivateData = @{
1414
PSData = @{
1515
Tags = @('powershell', 'crx', 'ps', 'power-shell', 'CRX', 'chrome', 'extension' )

CRX/CRX.psm1

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
$Public = @( Get-ChildItem -Path $PSScriptRoot\Public -Recurse -Filter *.ps1 -ErrorAction SilentlyContinue )
22
$Private = @( Get-ChildItem -Path $PSScriptRoot\Private -Recurse -Filter *.ps1 -ErrorAction SilentlyContinue )
33

4-
Foreach ($import in @($Public + $Private)) {
4+
Foreach ($import in @($Private + $Public )) {
55
try {
66
. $import.fullname
77
}

CRX/Private/CRXUpdateInfo.ps1

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
class CRXUpdateInfo {
2-
[string]$Version
2+
[string]$Id
3+
[string]$FileName
4+
[version]$Version
35
[string]$Url
46
[string]$SHA256
57
[string]$Status
68
[int]$Size
79

810
CRXUpdateInfo($obj) {
9-
$this.Version = $obj.version
11+
if ($obj.version.Contains('.')) {
12+
$this.Version = $obj.version
13+
}
14+
else {
15+
$this.Version = $obj.version + ".0"
16+
}
17+
1018
$this.Url = $obj.codebase
19+
$this.FileName = Split-Path -Leaf $this.Url.ToLower()
20+
$this.Id = $this.FileName.Substring(0, 32)
1121
$this.SHA256 = $obj.hash_sha256
1222
$this.Status = $obj.status
1323
$this.Size = $obj.size

CRX/Public/Get-CRX.ps1

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
function Get-CRX {
2-
[CmdletBinding()]
2+
[CmdletBinding(DefaultParameterSetName = 'ById')]
33
param (
4-
[Parameter(Mandatory = $true)]
4+
[Parameter(Mandatory = $true, ParameterSetName = 'ById')]
55
[string]$Id,
66

7+
[Parameter(Mandatory = $true, ParameterSetName = 'ByInfo')]
8+
$UpdateInfo,
9+
710
[Parameter(Mandatory = $true)]
811
[string]$OutputDirectory
912
)
1013

11-
$info = Get-CRXUpdateInfo -Id $Id
14+
if ($PSCmdlet.ParameterSetName -eq 'ById') {
15+
$info = Get-CRXUpdateInfo -Id $Id
16+
}
17+
else {
18+
$info = $UpdateInfo
19+
}
20+
21+
if ($null -eq $info) {
22+
return $null
23+
}
24+
1225
try {
13-
$outputPath = Join-Path -Path $OutputDirectory -ChildPath (Split-Path -Leaf $info.Url)
26+
$outputPath = Join-Path -Path $OutputDirectory -ChildPath $info.FileName
1427
Invoke-WebRequest -Uri $info.Url -OutFile $outputPath
1528
Get-Item -Path $outputPath
1629
}

CRX/Public/Test-CRXUpdateAvailable.ps1

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
function Test-CRXUpdateAvailable {
2-
[CmdletBinding()]
2+
[CmdletBinding(DefaultParameterSetName = 'ById')]
33
param (
4-
[Parameter(Mandatory = $true)]
4+
[Parameter(Mandatory = $true, ParameterSetName = 'ById')]
55
[string]$Id,
66

7+
[Parameter(Mandatory = $true, ParameterSetName = 'ByInfo')]
8+
[CRXUpdateInfo]$UpdateInfo,
9+
710
[Parameter(Mandatory = $true)]
811
[version]$currentVersion
912
)
1013

11-
$updateInfo = Get-CRXUpdateInfo $Id
14+
if ($PSCmdlet.ParameterSetName -eq 'ById') {
15+
$updateInfo = Get-CRXUpdateInfo -Id $Id
16+
}
17+
else {
18+
$updateInfo = $UpdateInfo
19+
}
20+
1221
if ($updateInfo) {
13-
$updateVersion = [version]$updateInfo.Version
14-
return $updateVersion -gt $currentVersion
22+
return $updateInfo.Version -gt $currentVersion
1523
}
1624
else {
1725
return $false

0 commit comments

Comments
 (0)