Skip to content

Commit f21e554

Browse files
authored
Fix kb name check (#34)
1 parent 81d5e98 commit f21e554

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/AnyPackage.Msu.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
Description = 'Windows Msu provider for AnyPackage.'
99
PowerShellVersion = '5.1'
1010
RequiredModules = @(
11-
@{ ModuleName = 'AnyPackage'; ModuleVersion = '0.5.0' })
11+
@{ ModuleName = 'AnyPackage'; ModuleVersion = '0.7.0' })
1212
FunctionsToExport = @()
1313
CmdletsToExport = @()
1414
AliasesToExport = @()

src/code/MsuProvider.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Linq;
1111
using System.Management;
1212
using System.Management.Automation;
13+
using System.Text.RegularExpressions;
1314

1415
namespace AnyPackage.Provider.Msu;
1516

@@ -28,7 +29,7 @@ public void FindPackage(PackageRequest request)
2829
}
2930

3031
string line;
31-
Dictionary<string, object> metadata = [];
32+
Dictionary<string, object?> metadata = [];
3233
using var reader = file.OpenText();
3334

3435
while ((line = reader.ReadLine()) is not null)
@@ -46,7 +47,7 @@ public void FindPackage(PackageRequest request)
4647
{
4748
var kb = string.Format("KB{0}", metadata["KBArticleNumber"]);
4849
var source = new PackageSourceInfo(request.Path, request.Path, ProviderInfo);
49-
var package = new PackageInfo(kb, null, source, (string)metadata["PackageType"], null, metadata, ProviderInfo);
50+
var package = new PackageInfo(kb, null, source, (string)metadata["PackageType"]!, null, metadata, ProviderInfo);
5051
request.WritePackage(package);
5152
}
5253
}
@@ -93,6 +94,18 @@ public void InstallPackage(PackageRequest request)
9394

9495
public void UninstallPackage(PackageRequest request)
9596
{
97+
var regex = new Regex(@"KB\d+", RegexOptions.IgnoreCase);
98+
99+
if (!regex.Match(request.Name).Success)
100+
{
101+
return;
102+
}
103+
104+
if (request.IsVersionFiltered)
105+
{
106+
return;
107+
}
108+
96109
using var process = new Process();
97110
process.StartInfo.FileName = "wusa.exe";
98111
var kb = request.Name.Replace("KB", "");

src/code/MsuProvider.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="AnyPackage" Version="0.5.0" />
11+
<PackageReference Include="AnyPackage" Version="0.7.0" />
1212
<PackageReference Include="MSFTCompressionCab" Version="1.0.0" />
1313
<PackageReference Include="PowerShellStandard.Library" Version="5.1.1" />
1414
<PackageReference Include="System.Management" Version="6.0.0" />

0 commit comments

Comments
 (0)