Skip to content

Commit

Permalink
Add Find-Package (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasNieto authored Mar 28, 2023
1 parent 563bb83 commit d8c45c7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
4 changes: 3 additions & 1 deletion BuildSettings.psd1
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@{
Path = @(
'./src/code/bin/Release/netstandard2.0/MsuProvider.dll',
'./src/code/bin/Release/net461/MsuProvider.dll',
'./src/code/bin/Release/net461/Microsoft.Deployment.Compression.dll',
'./src/code/bin/Release/net461/Microsoft.Deployment.Compression.Cab.dll',
'./src/AnyPackage.Msu.psd1'
)
Destination = './module'
Expand Down
42 changes: 41 additions & 1 deletion src/code/MsuProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,58 @@
// You may use, distribute and modify this code under the
// terms of the MIT license.

using Microsoft.Deployment.Compression.Cab;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Management;

namespace AnyPackage.Provider.Msu
{
[PackageProvider("Msu")]
public sealed class MsuProvider : PackageProvider, IGetPackage
public sealed class MsuProvider : PackageProvider, IFindPackage, IGetPackage
{
private readonly static Guid s_id = new Guid("314633fe-c7e9-4eeb-824b-382a8a4e92b8");

public MsuProvider() : base(s_id) { }

public void FindPackage(PackageRequest request)
{
var file = new CabInfo(request.Name).GetFiles()
.Where(x => Path.GetExtension(x.Name) == ".txt")
.FirstOrDefault();

if (file is null)
{
return;
}

string line;
Dictionary<string, string> metadata = new Dictionary<string, string>();
using var reader = file.OpenText();

while ((line = reader.ReadLine()) is not null)
{
var values = line.Split('=');
var key = values[0].Replace(" ", "");

// Remove quotes around value
var value = values[1].Substring(1, values[1].Length - 2);

metadata.Add(key, value);
}

if (metadata.ContainsKey("KBArticleNumber"))
{
var kb = string.Format("KB{0}", metadata["KBArticleNumber"]);
request.WritePackage(kb,
new PackageVersion("0"),
metadata["PackageType"],
request.NewSourceInfo(request.Name, request.Name));
}
}

public void GetPackage(PackageRequest request)
{
var quickFix = new ManagementObjectSearcher(@"root\cimv2", "select * from Win32_QuickFixEngineering");
Expand Down
5 changes: 3 additions & 2 deletions src/code/MsuProvider.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net461</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<Copyright>© 2023 Thomas Nieto. All rights reserved.</Copyright>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AnyPackage" Version="0.4.2" />
<PackageReference Include="MSFTCompressionCab" Version="1.0.0" />
<PackageReference Include="PowerShellStandard.Library" Version="5.1.1" />
<PackageReference Include="System.Management" Version="7.0.0" />
<PackageReference Include="System.Management" Version="6.0.0" />
</ItemGroup>

</Project>

0 comments on commit d8c45c7

Please sign in to comment.