-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTargetPlatformSDK.cs
210 lines (180 loc) · 6.73 KB
/
TargetPlatformSDK.cs
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Globalization;
namespace EnumSDKs.Extracted
{
/// <summary>
/// Structure to represent a target platform sdk
/// </summary>
public class TargetPlatformSDK : IEquatable<TargetPlatformSDK>
{
/// <summary>
/// Path to the platform sdk may be null if not a platform sdk.
/// </summary>
private string _path;
/// <summary>
/// Object containing the properties in the SDK manifest
/// </summary>
private SDKManifest _manifest;
/// <summary>
/// Cache for min Visual Studio version from manifest
/// </summary>
private Version _minVSVersion;
/// <summary>
/// Cache for min OS version from manifest
/// </summary>
private Version _minOSVersion;
/// <summary>
/// Constructor
/// </summary>
public TargetPlatformSDK(string targetPlatformIdentifier, Version targetPlatformVersion, string path)
{
//ErrorUtilities.VerifyThrowArgumentNull(targetPlatformIdentifier, nameof(targetPlatformIdentifier));
//ErrorUtilities.VerifyThrowArgumentNull(targetPlatformVersion, nameof(targetPlatformVersion));
TargetPlatformIdentifier = targetPlatformIdentifier;
TargetPlatformVersion = targetPlatformVersion;
Path = path;
ExtensionSDKs = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
Platforms = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
}
/// <summary>
/// Min Visual Studio version from manifest
/// </summary>
public Version MinVSVersion
{
get
{
if (_minVSVersion == null && Manifest?.MinVSVersion != null)
{
if (!Version.TryParse(Manifest.MinVSVersion, out _minVSVersion))
{
_minVSVersion = null;
}
}
return _minVSVersion;
}
}
/// <summary>
/// Min OS version from manifest
/// </summary>
public Version MinOSVersion
{
get
{
if (_minOSVersion == null && Manifest?.MinOSVersion != null)
{
if (!Version.TryParse(Manifest.MinOSVersion, out _minOSVersion))
{
_minOSVersion = null;
}
}
return _minOSVersion;
}
}
/// <summary>
/// Target platform identifier
/// </summary>
public string TargetPlatformIdentifier { get; }
/// <summary>
/// Target platform version
/// </summary>
public Version TargetPlatformVersion { get; }
/// <summary>
/// Path to target platform sdk if it exists, it may not if there is no target platform is installed
/// </summary>
public string Path
{
get => _path;
set => _path = value != null ? EnsureTrailingSlash(value) : null;
}
internal static string EnsureTrailingSlash(string fileSpec)
{
fileSpec = FixFilePath(fileSpec);
if (fileSpec.Length > 0 && !IsSlash(fileSpec[fileSpec.Length - 1]))
{
fileSpec += System.IO.Path.DirectorySeparatorChar;
}
return fileSpec;
}
internal static string FixFilePath(string path)
{
return string.IsNullOrEmpty(path) || System.IO.Path.DirectorySeparatorChar == '\\' ? path : path.Replace('\\', '/');//.Replace("//", "/");
}
internal static bool IsSlash(char c)
{
return (c == System.IO.Path.DirectorySeparatorChar) || (c == System.IO.Path.AltDirectorySeparatorChar);
}
/// <summary>
/// The SDK's display name, or null if one is not defined.
/// </summary>
public string DisplayName => Manifest?.DisplayName;
/// <summary>
/// Extension sdks within this platform,
/// </summary>
internal Dictionary<string, string> ExtensionSDKs { get; }
/// <summary>
/// Set of platforms supported by this SDK.
/// </summary>
internal Dictionary<string, string> Platforms { get; }
/// <summary>
/// Reference to manifest object
/// Makes it is instantiated only once
/// </summary>
private SDKManifest Manifest
{
get
{
// Load manifest from disk the first time it is needed
if (_manifest == null && _path != null)
{
_manifest = new SDKManifest(_path);
}
return _manifest;
}
}
/// <summary>
/// Override GetHashCode
/// </summary>
public override int GetHashCode() => TargetPlatformIdentifier.ToLowerInvariant().GetHashCode() ^ TargetPlatformVersion.GetHashCode();
/// <summary>
/// Override equals
/// </summary>
public override bool Equals(object obj)
{
if (!(obj is TargetPlatformSDK moniker))
{
return false;
}
if (ReferenceEquals(this, moniker))
{
return true;
}
return Equals(moniker);
}
/// <summary>
/// Implement IEquatable
/// </summary>
public bool Equals(TargetPlatformSDK other)
{
if (other == null)
{
return false;
}
return TargetPlatformIdentifier.Equals(other.TargetPlatformIdentifier, StringComparison.OrdinalIgnoreCase) && TargetPlatformVersion.Equals(other.TargetPlatformVersion);
}
/// <summary>
/// Returns true if this SDK supports the given platform, or false otherwise.
/// </summary>
public bool ContainsPlatform(string targetPlatformIdentifier, string targetPlatformVersion)
{
string sdkKey = GetSdkKey(targetPlatformIdentifier, targetPlatformVersion);
return Platforms.ContainsKey(sdkKey);
}
/// <summary>
/// Given an identifier and version, construct a string to use as a key for that combination.
/// </summary>
internal static string GetSdkKey(string sdkIdentifier, string sdkVersion) => string.Format(CultureInfo.InvariantCulture, "{0}, Version={1}", sdkIdentifier, sdkVersion);
}
}