Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix kb name check #34

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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