From d4318107080879889c5bc180401667308b87d434 Mon Sep 17 00:00:00 2001 From: Thomas Nieto <38873752+ThomasNieto@users.noreply.github.com> Date: Mon, 7 Oct 2024 20:16:36 -0500 Subject: [PATCH] Fix kb name check --- src/AnyPackage.Msu.psd1 | 2 +- src/code/MsuProvider.cs | 17 +++++++++++++++-- src/code/MsuProvider.csproj | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/AnyPackage.Msu.psd1 b/src/AnyPackage.Msu.psd1 index 82d5cd4..df1a159 100644 --- a/src/AnyPackage.Msu.psd1 +++ b/src/AnyPackage.Msu.psd1 @@ -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 = @() diff --git a/src/code/MsuProvider.cs b/src/code/MsuProvider.cs index 38d63ac..1599e3e 100644 --- a/src/code/MsuProvider.cs +++ b/src/code/MsuProvider.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Management; using System.Management.Automation; +using System.Text.RegularExpressions; namespace AnyPackage.Provider.Msu; @@ -28,7 +29,7 @@ public void FindPackage(PackageRequest request) } string line; - Dictionary metadata = []; + Dictionary metadata = []; using var reader = file.OpenText(); while ((line = reader.ReadLine()) is not null) @@ -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); } } @@ -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", ""); diff --git a/src/code/MsuProvider.csproj b/src/code/MsuProvider.csproj index 95ef492..58ad6f4 100644 --- a/src/code/MsuProvider.csproj +++ b/src/code/MsuProvider.csproj @@ -8,7 +8,7 @@ - +