ExportPackageCmdlet.cs (3488B)
1 // ----------------------------------------------------------------------------- 2 // <copyright file="ExportPackageCmdlet.cs" company="Microsoft Corporation"> 3 // Copyright (c) Microsoft Corporation. Licensed under the MIT License. 4 // </copyright> 5 // ----------------------------------------------------------------------------- 6 7 namespace Microsoft.WinGet.Client.Commands 8 { 9 using System.Management.Automation; 10 using Microsoft.WinGet.Client.Common; 11 using Microsoft.WinGet.Client.Engine.Commands; 12 using Microsoft.WinGet.Client.Engine.PSObjects; 13 14 /// <summary> 15 /// Downloads a package installer from the pipeline or from a configured source. 16 /// </summary> 17 [Cmdlet( 18 VerbsData.Export, 19 Constants.WinGetNouns.Package, 20 DefaultParameterSetName = Constants.FoundSet, 21 SupportsShouldProcess = true)] 22 [Alias("ewgp")] 23 [OutputType(typeof(PSDownloadResult))] 24 public sealed class ExportPackageCmdlet : InstallerSelectionCmdlet 25 { 26 private DownloadCommand command = null; 27 28 /// <summary> 29 /// Gets or sets the directory where the installer will be downloaded to. 30 /// </summary> 31 [Parameter(ValueFromPipelineByPropertyName = true)] 32 public string DownloadDirectory { get; set; } 33 34 /// <summary> 35 /// Gets or sets a value indicating whether to skip acquiring the license from a Store package. 36 /// </summary> 37 [Parameter(ValueFromPipelineByPropertyName = true)] 38 public SwitchParameter SkipMicrosoftStoreLicense { get; set; } 39 40 /// <summary> 41 /// Gets or sets the platform to download the package for. 42 /// </summary> 43 [Parameter(ValueFromPipelineByPropertyName = true)] 44 public PSObjects.PSWindowsPlatform Platform { get; set; } 45 46 /// <summary> 47 /// Gets or sets the target OS version to download for. 48 /// </summary> 49 [Parameter(ValueFromPipelineByPropertyName = true)] 50 public string TargetOSVersion { get; set; } 51 52 /// <summary> 53 /// Installs a package from the pipeline or from a configured source. 54 /// </summary> 55 protected override void ProcessRecord() 56 { 57 this.command = new DownloadCommand( 58 this, 59 this.PSCatalogPackage, 60 this.Version, 61 this.Id, 62 this.Name, 63 this.Moniker, 64 this.Source, 65 this.Query, 66 this.AllowHashMismatch.ToBool(), 67 this.SkipDependencies.ToBool(), 68 this.Locale); 69 this.command.Download( 70 this.DownloadDirectory, 71 this.MatchOption.ToString(), 72 this.Scope.ToString(), 73 this.Architecture.ToString(), 74 this.InstallerType.ToString(), 75 this.SkipMicrosoftStoreLicense.ToBool(), 76 this.Platform.ToString(), 77 this.TargetOSVersion); 78 } 79 80 /// <summary> 81 /// Interrupts currently running code within the command. 82 /// </summary> 83 protected override void StopProcessing() 84 { 85 if (this.command != null) 86 { 87 this.command.Cancel(); 88 } 89 } 90 } 91 }