-
Notifications
You must be signed in to change notification settings - Fork 949
Expand file tree
/
Copy pathExpandChocolateyArchiveCommand.cs
More file actions
94 lines (85 loc) · 3.52 KB
/
ExpandChocolateyArchiveCommand.cs
File metadata and controls
94 lines (85 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using Chocolatey.PowerShell.Helpers;
using Chocolatey.PowerShell.Shared;
using System;
using System.IO;
using System.Management.Automation;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static chocolatey.StringResources.EnvironmentVariables;
namespace Chocolatey.PowerShell.Commands
{
[Cmdlet(VerbsData.Expand, "ChocolateyArchive", DefaultParameterSetName = "Path", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType(typeof(string))]
public class ExpandChocolateyArchiveCommand : ChocolateyCmdlet
{
[Alias("File", "FileFullPath")]
[Parameter(Mandatory = true, Position = 0, ParameterSetName = "Path")]
[Parameter(Mandatory = true, ParameterSetName = "BothPaths")]
public string Path { get; set; } = string.Empty;
[Alias("UnzipLocation")]
[Parameter(Mandatory = true, Position = 1)]
public string Destination { get; set; } = string.Empty;
[Parameter(Position = 2)]
[Alias("SpecificFolder")]
public string FilesToExtract { get; set; }
[Parameter(Position = 3)]
public string PackageName { get; set; }
[Alias("File64", "FileFullPath64")]
[Parameter(Mandatory = true, ParameterSetName = "Path64")]
[Parameter(Mandatory = true, ParameterSetName = "BothPaths")]
public string Path64 { get; set; }
[Parameter]
public SwitchParameter DisableLogging { get; set; }
[Parameter]
public SwitchParameter UseBuiltinCompression { get; set; } = EnvironmentHelper.GetVariable(Package.ChocolateyUseBuiltinCompression) == "true";
protected override void End()
{
var helper = new ExtractArchiveHelper(this, PipelineStopToken);
try
{
helper.ExtractFiles(Path, Path64, PackageName, Destination, FilesToExtract, UseBuiltinCompression, DisableLogging);
WriteObject(Destination);
}
catch (FileNotFoundException error)
{
ThrowTerminatingError(new ErrorRecord(
error,
$"{ErrorId}.FileNotFound",
ErrorCategory.ObjectNotFound,
string.IsNullOrEmpty(Path) ? Path64 : Path));
}
catch (InvalidOperationException error)
{
ThrowTerminatingError(new ErrorRecord(
error,
$"{ErrorId}.ApplicationMissing",
ErrorCategory.InvalidOperation,
targetObject: null));
}
catch (NotSupportedException error)
{
ThrowTerminatingError(new ErrorRecord(
error,
$"{ErrorId}.UnsupportedArchitecture",
ErrorCategory.NotImplemented,
string.IsNullOrEmpty(Path) ? Path64 : Path));
}
catch (SevenZipException error)
{
ThrowTerminatingError(new ErrorRecord(
error,
$"{ErrorId}.ExtractionFailed",
ErrorCategory.InvalidResult,
string.IsNullOrEmpty(Path) ? Path64 : Path));
}
catch (Exception error)
{
ThrowTerminatingError(new ErrorRecord(
error,
$"{ErrorId}.Unknown",
ErrorCategory.NotSpecified,
string.IsNullOrEmpty(Path) ? Path64 : Path));
}
}
}
}