-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reading details from MSI files, was done by a windows only dll. This allows loading those details on any platform by using [OpenMCDF](https://github.com/ironfede/openmcdf). - Packaging MSI files will now work on Linux/mac - `Show-MsiInfo` command to allow reading Msi info for use in your own scripts. Co-authored-by: Miyoyo <[email protected]>
- Loading branch information
Showing
22 changed files
with
826 additions
and
701 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"sdk": { | ||
"version": "8.0.0", | ||
"rollForward": "latestMinor" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using System; | ||
using System.IO; | ||
using System.Management.Automation; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
using Svrooij.PowerShell.DependencyInjection; | ||
using WingetIntune; | ||
using WingetIntune.Msi; | ||
|
||
namespace Svrooij.WinTuner.CmdLets.Commands; | ||
|
||
/// <summary> | ||
/// <para type="synopsis">Show information about an MSI file</para> | ||
/// <para type="description">Show information about an MSI file, this includes the MSI code and version.</para> | ||
/// </summary> | ||
/// <psOrder>100</psOrder> | ||
/// <example> | ||
/// <para type="name">Show information about an MSI file</para> | ||
/// <para type="description">Show information about an MSI file, this includes the MSI code and version.</para> | ||
/// <code>Show-MsiInfo -MsiPath "C:\path\to\file.msi"</code> | ||
/// </example> | ||
/// <example> | ||
/// <para type="name">Show information about an MSI file from URL</para> | ||
/// <para type="description">Download an MSI file and show the details</para> | ||
/// <code>Show-MsiInfo -MsiUrl "https://example.com/file.msi" -OutputPath "C:\path\to"</code> | ||
/// </example> | ||
[Cmdlet(VerbsCommon.Show, "MsiInfo", HelpUri = "https://wintuner.app/docs/wintuner-powershell/Show-MsiInfo", DefaultParameterSetName = nameof(MsiPath))] | ||
[OutputType(typeof(Models.MsiInfo))] | ||
public class ShowMsiInfo : DependencyCmdlet<Startup> | ||
{ | ||
/// <summary> | ||
/// <para type="description">Path to the MSI file</para> | ||
/// </summary> | ||
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ParameterSetName = nameof(MsiPath))] | ||
public string? MsiPath { get; set; } | ||
|
||
/// <summary> | ||
/// <para type="description">URL to the MSI file</para> | ||
/// </summary> | ||
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ParameterSetName = nameof(MsiUrl))] | ||
public Uri? MsiUrl { get; set; } | ||
|
||
/// <summary> | ||
/// <para type="description">Path to save the MSI file</para> | ||
/// </summary> | ||
[Parameter(Mandatory = false, Position = 1, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ParameterSetName = nameof(MsiUrl))] | ||
public string? OutputPath { get; set; } | ||
|
||
/// <summary> | ||
/// <para type="description">Filename to save the MSI file, if cannot be discovered from url</para> | ||
/// </summary> | ||
[Parameter(Mandatory = false, Position = 2, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ParameterSetName = nameof(MsiUrl))] | ||
public string? OutputFilename { get; set; } | ||
|
||
[ServiceDependency] | ||
private ILogger<ShowMsiInfo>? logger; | ||
|
||
[ServiceDependency] | ||
private IFileManager? fileManager; | ||
|
||
/// <inheritdoc/> | ||
public override async Task ProcessRecordAsync(CancellationToken cancellationToken) | ||
{ | ||
if (MsiPath is not null) | ||
{ | ||
logger?.LogInformation("Reading MSI from path: {MsiPath}", MsiPath); | ||
} | ||
else if (MsiUrl is not null) | ||
{ | ||
OutputPath ??= Path.GetTempPath(); | ||
logger?.LogInformation("Downloading MSI from URL {MsiUrl} to {OutputPath}", MsiUrl, OutputPath); | ||
var outputFile = Path.Combine(OutputPath, OutputFilename ?? Path.GetFileName(MsiUrl.LocalPath)); | ||
// The file managed does automatic chunking of the download, so it will also work for very large files. | ||
await fileManager!.DownloadFileAsync(MsiUrl!.ToString(), outputFile, cancellationToken: cancellationToken); | ||
MsiPath = outputFile; | ||
} | ||
else | ||
{ | ||
throw new InvalidOperationException("Either MsiPath or MsiUrl must be set"); | ||
} | ||
|
||
using var msiStream = new FileStream(MsiPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 4096, FileOptions.Asynchronous); | ||
var decoder = new MsiDecoder(msiStream); | ||
var codeFromMsi = decoder.GetCode(); | ||
var versionFromMsi = decoder.GetVersion(); | ||
|
||
WriteObject(new Models.MsiInfo | ||
{ | ||
Path = MsiPath, | ||
ProductCode = codeFromMsi, | ||
ProductVersion = versionFromMsi | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace Svrooij.WinTuner.CmdLets.Models; | ||
|
||
/// <summary> | ||
/// Information about an MSI file | ||
/// </summary> | ||
public class MsiInfo | ||
{ | ||
/// <summary> | ||
/// The path to the MSI file | ||
/// </summary> | ||
public string? Path { get; set; } | ||
/// <summary> | ||
/// The product code of the MSI file | ||
/// </summary> | ||
public string? ProductCode { get; set; } | ||
|
||
/// <summary> | ||
/// The version of the MSI file | ||
/// </summary> | ||
public string? ProductVersion { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.