From 1a4305206797e6af91932530554e4bdb6b19dd2e Mon Sep 17 00:00:00 2001 From: Stephan van Rooij <1292510+svrooij@users.noreply.github.com> Date: Mon, 23 Dec 2024 16:28:55 +0100 Subject: [PATCH] Default to temp folder --- src/Svrooij.WinTuner.CmdLets/Commands/ShowMsiInfo.cs | 4 ++-- tests/WinTuner.Cmdlets.Tests/Show-MsiInfo.Tests.ps1 | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Svrooij.WinTuner.CmdLets/Commands/ShowMsiInfo.cs b/src/Svrooij.WinTuner.CmdLets/Commands/ShowMsiInfo.cs index 72889aa..cfc8e91 100644 --- a/src/Svrooij.WinTuner.CmdLets/Commands/ShowMsiInfo.cs +++ b/src/Svrooij.WinTuner.CmdLets/Commands/ShowMsiInfo.cs @@ -44,7 +44,7 @@ public class ShowMsiInfo : DependencyCmdlet /// /// Path to save the MSI file /// - [Parameter(Mandatory = true, Position = 1, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ParameterSetName = nameof(MsiUrl))] + [Parameter(Mandatory = false, Position = 1, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ParameterSetName = nameof(MsiUrl))] public string? OutputPath { get; set; } /// @@ -69,7 +69,7 @@ public override async Task ProcessRecordAsync(CancellationToken cancellationToke else if (MsiUrl is not null) { logger?.LogInformation("Downloading MSI from URL to {OutputPath}: {MsiUrl}", MsiUrl, OutputPath); - var outputFile = Path.Combine(OutputPath!, OutputFilename ?? Path.GetFileName(MsiUrl.LocalPath)); + var outputFile = Path.Combine(OutputPath ?? Path.GetTempPath(), 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; diff --git a/tests/WinTuner.Cmdlets.Tests/Show-MsiInfo.Tests.ps1 b/tests/WinTuner.Cmdlets.Tests/Show-MsiInfo.Tests.ps1 index b9e2537..4a49563 100644 --- a/tests/WinTuner.Cmdlets.Tests/Show-MsiInfo.Tests.ps1 +++ b/tests/WinTuner.Cmdlets.Tests/Show-MsiInfo.Tests.ps1 @@ -6,8 +6,7 @@ Describe 'Show-MsiInfo' { It 'Should download and show MSI info' { $msiUrl = 'https://download.microsoft.com/download/C/7/A/C7AAD914-A8A6-4904-88A1-29E657445D03/LAPS.x64.msi' - $tempFolder = $env:TEMP - $msiInfo = $(Show-MsiInfo -MsiUrl $msiUrl -OutputPath $tempFolder) + $msiInfo = $(Show-MsiInfo -MsiUrl $msiUrl) $msiInfo | Should -Not -BeNullOrEmpty $msiInfo.ProductCode | Should -Be '{97E2CA7B-B657-4FF7-A6DB-30ECC73E1E28}' $msiInfo.ProductVersion | Should -Be '6.2.0.0'