Skip to content

Commit

Permalink
Fix kb name check (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasNieto authored Oct 8, 2024
1 parent 81d5e98 commit f21e554
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/AnyPackage.Msu.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Description = 'Windows Msu provider for AnyPackage.'
PowerShellVersion = '5.1'
RequiredModules = @(
@{ ModuleName = 'AnyPackage'; ModuleVersion = '0.5.0' })
@{ ModuleName = 'AnyPackage'; ModuleVersion = '0.7.0' })
FunctionsToExport = @()
CmdletsToExport = @()
AliasesToExport = @()
Expand Down
17 changes: 15 additions & 2 deletions src/code/MsuProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Linq;
using System.Management;
using System.Management.Automation;
using System.Text.RegularExpressions;

namespace AnyPackage.Provider.Msu;

Expand All @@ -28,7 +29,7 @@ public void FindPackage(PackageRequest request)
}

string line;
Dictionary<string, object> metadata = [];
Dictionary<string, object?> metadata = [];
using var reader = file.OpenText();

while ((line = reader.ReadLine()) is not null)
Expand All @@ -46,7 +47,7 @@ public void FindPackage(PackageRequest request)
{
var kb = string.Format("KB{0}", metadata["KBArticleNumber"]);
var source = new PackageSourceInfo(request.Path, request.Path, ProviderInfo);
var package = new PackageInfo(kb, null, source, (string)metadata["PackageType"], null, metadata, ProviderInfo);
var package = new PackageInfo(kb, null, source, (string)metadata["PackageType"]!, null, metadata, ProviderInfo);
request.WritePackage(package);
}
}
Expand Down Expand Up @@ -93,6 +94,18 @@ public void InstallPackage(PackageRequest request)

public void UninstallPackage(PackageRequest request)
{
var regex = new Regex(@"KB\d+", RegexOptions.IgnoreCase);

if (!regex.Match(request.Name).Success)
{
return;
}

if (request.IsVersionFiltered)
{
return;
}

using var process = new Process();
process.StartInfo.FileName = "wusa.exe";
var kb = request.Name.Replace("KB", "");
Expand Down
2 changes: 1 addition & 1 deletion src/code/MsuProvider.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AnyPackage" Version="0.5.0" />
<PackageReference Include="AnyPackage" Version="0.7.0" />
<PackageReference Include="MSFTCompressionCab" Version="1.0.0" />
<PackageReference Include="PowerShellStandard.Library" Version="5.1.1" />
<PackageReference Include="System.Management" Version="6.0.0" />
Expand Down

0 comments on commit f21e554

Please sign in to comment.