-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathContainerProvider.cs
More file actions
141 lines (116 loc) · 4.75 KB
/
ContainerProvider.cs
File metadata and controls
141 lines (116 loc) · 4.75 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE.txt file in the project root for more information.
using Microsoft.Extensions.Logging;
namespace Sign.Core
{
internal sealed class ContainerProvider : IContainerProvider
{
private readonly HashSet<string> _appxBundleExtensions;
private readonly HashSet<string> _appxExtensions;
private readonly IDirectoryService _directoryService;
private readonly IFileMatcher _fileMatcher;
private readonly ICertificateProvider _certificateProvider;
private readonly ILogger<IContainerProvider> _logger;
private readonly IMakeAppxCli _makeAppxCli;
private readonly HashSet<string> _nuGetExtensions;
private readonly HashSet<string> _zipExtensions;
private const string _cabExtension = ".cab";
// Dependency injection requires a public constructor.
public ContainerProvider(
ICertificateProvider certificateProvider,
IDirectoryService directoryService,
IFileMatcher fileMatcher,
IMakeAppxCli makeAppxCli,
ILogger<IContainerProvider> logger)
{
ArgumentNullException.ThrowIfNull(certificateProvider, nameof(certificateProvider));
ArgumentNullException.ThrowIfNull(directoryService, nameof(directoryService));
ArgumentNullException.ThrowIfNull(fileMatcher, nameof(fileMatcher));
ArgumentNullException.ThrowIfNull(makeAppxCli, nameof(makeAppxCli));
ArgumentNullException.ThrowIfNull(logger, nameof(logger));
_certificateProvider = certificateProvider;
_directoryService = directoryService;
_fileMatcher = fileMatcher;
_makeAppxCli = makeAppxCli;
_logger = logger;
_appxBundleExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
".appxbundle",
".eappxbundle",
".emsixbundle",
".msixbundle"
};
_appxExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
".appx",
".eappx",
".emsix",
".msix"
};
_nuGetExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
".nupkg",
".snupkg"
};
_zipExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
".appxupload",
".clickonce",
".msixupload",
".vsix",
".zip"
};
}
public bool IsAppxBundleContainer(FileInfo file)
{
ArgumentNullException.ThrowIfNull(file, nameof(file));
return _appxBundleExtensions.Contains(file.Extension);
}
public bool IsAppxContainer(FileInfo file)
{
ArgumentNullException.ThrowIfNull(file, nameof(file));
return _appxExtensions.Contains(file.Extension);
}
public bool IsNuGetContainer(FileInfo file)
{
ArgumentNullException.ThrowIfNull(file, nameof(file));
return _nuGetExtensions.Contains(file.Extension);
}
public bool IsZipContainer(FileInfo file)
{
ArgumentNullException.ThrowIfNull(file, nameof(file));
return _zipExtensions.Contains(file.Extension);
}
public bool IsCabContainer(FileInfo file)
{
ArgumentNullException.ThrowIfNull(file, nameof(file));
return string.Equals(file.Extension, _cabExtension, StringComparison.OrdinalIgnoreCase);
}
public IContainer? GetContainer(FileInfo file)
{
ArgumentNullException.ThrowIfNull(file, nameof(file));
if (IsAppxBundleContainer(file))
{
return new AppxBundleContainer(file, _directoryService, _fileMatcher, _makeAppxCli, _logger);
}
if (IsAppxContainer(file))
{
return new AppxContainer(file, _certificateProvider, _directoryService, _fileMatcher, _makeAppxCli, _logger);
}
if (IsZipContainer(file))
{
return new ZipContainer(file, _directoryService, _fileMatcher, _logger);
}
if (IsNuGetContainer(file))
{
return new NuGetContainer(file, _directoryService, _fileMatcher, _logger);
}
if (IsCabContainer(file))
{
return new CabContainer(file, _directoryService, _fileMatcher, _logger);
}
return null;
}
}
}