forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostProcessWSA.cs
More file actions
391 lines (362 loc) · 16.4 KB
/
PostProcessWSA.cs
File metadata and controls
391 lines (362 loc) · 16.4 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
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Xml.Linq;
using UnityEditor;
using UnityEditor.Modules;
using UnityEditor.Scripting.Compilers;
using UnityEditor.Utils;
using UnityEngine;
internal abstract class PostProcessWSA : PostProcessWinRT
{
private static Dictionary<PlayerSettings.SplashScreen.UnityLogoStyle, string> _defaultSplashScreens;
protected readonly bool _generateReferenceProjects;
protected readonly ProjectImages _images;
public PostProcessWSA(BuildPostProcessArgs args, WSASDK sdk, string stagingArea = null) : base(args, sdk, stagingArea)
{
this._generateReferenceProjects = EditorUserBuildSettings.wsaGenerateReferenceProjects;
this._images = new ProjectImages();
if (this._generateReferenceProjects)
{
MetroAssemblyCSharpCreator.ResetAssemblyCSharpProjectGUIDs();
}
}
protected string CheckImageConsistencyAndGetName(params string[] strings)
{
string str = null;
string a = null;
foreach (string str3 in strings)
{
if (!string.IsNullOrEmpty(str3))
{
if (str == null)
{
str = str3;
a = Path.GetExtension(str3);
}
else if (!string.Equals(a, Path.GetExtension(str3), StringComparison.InvariantCultureIgnoreCase))
{
throw new Exception($"Inconsistency between images in the same group ({str}). All images should be either PNG or JPEG!");
}
}
}
return str;
}
public override void CheckProfilerCapabilities()
{
if (base.AutoRunPlayer && base.Development)
{
bool capability = PlayerSettings.WSA.GetCapability(PlayerSettings.WSACapability.InternetClientServer);
bool flag2 = PlayerSettings.WSA.GetCapability(PlayerSettings.WSACapability.PrivateNetworkClientServer);
if (!capability || !flag2)
{
Debug.LogWarning("Warning: profiler will not be functional in this build due to missing capabilities. If you require profiler functionality, please enable InternetClientServer and PrivateNetworkClientServer capabilities in the player settings");
}
}
}
public override void CheckSafeProjectOverwrite()
{
string path = Utility.CombinePath(base.InstallPath, base.VisualStudioName);
if (Directory.Exists(path))
{
string str2 = Utility.CombinePath(path, base.VisualStudioName + ".csproj");
string str3 = Utility.CombinePath(path, base.VisualStudioName + ".vcxproj");
string str4 = Utility.CombinePath(path, base.VisualStudioName + ".Shared");
if (base._sdk != WSASDK.UniversalSDK81)
{
if (Directory.Exists(str4))
{
throw new UnityException("Build path contains Universal project which is incompatible with current one.");
}
}
else
{
if (!Directory.Exists(str4))
{
if (File.Exists(str2))
{
throw new UnityException("Build path contains project which is incompatible with current one.");
}
return;
}
path = str4;
str2 = Utility.CombinePath(path, base.VisualStudioName + ".shproj");
}
if (this.UseIL2CPP())
{
if (File.Exists(str2))
{
throw new UnityException("Build path contains project built with .NET scripting backend, while current project is using IL2CPP scripting backend.");
}
}
else if (File.Exists(str3))
{
throw new UnityException("Build path contains project built with IL2CPP scripting backend, while current project is using .NET scripting backend.");
}
if (File.Exists(str2))
{
Version projectFileToolsVersion = GetProjectFileToolsVersion(str2);
Version toolsVersion = this.GetToolsVersion();
if (projectFileToolsVersion != toolsVersion)
{
throw new UnityException($"Build path contains project which is incompatible with current one. Expected tools version '{toolsVersion}', was '{projectFileToolsVersion}'");
}
}
}
}
protected string CopyImage(PlayerSettings.WSAImageType type, PlayerSettings.WSAImageScale scale, string defaultSource, string destinationFileName)
{
string visualAssetsImage = PlayerSettings.WSA.GetVisualAssetsImage(type, scale);
if (string.IsNullOrEmpty(visualAssetsImage))
{
if (string.IsNullOrEmpty(defaultSource))
{
return null;
}
visualAssetsImage = defaultSource;
}
destinationFileName = Path.ChangeExtension(destinationFileName, Path.GetExtension(visualAssetsImage));
string str3 = Path.ChangeExtension(Utility.CombinePath("Assets", Path.GetFileName(!string.IsNullOrEmpty(defaultSource) ? defaultSource : visualAssetsImage)), Path.GetExtension(visualAssetsImage));
if (string.IsNullOrEmpty(destinationFileName))
{
destinationFileName = str3;
}
else
{
destinationFileName = Utility.CombinePath("Assets", Path.GetFileName(destinationFileName));
}
string path = Utility.CombinePath(base.StagingArea, destinationFileName);
Utility.CreateDirectory(Path.GetDirectoryName(path));
FileUtil.CopyFileOrDirectory(visualAssetsImage, path);
return (destinationFileName.Substring(0, destinationFileName.IndexOf('.')) + Path.GetExtension(visualAssetsImage));
}
public override void CopyTemplate()
{
string templateDirectorySource = this.GetTemplateDirectorySource();
string templateDirectoryTarget = this.GetTemplateDirectoryTarget();
FileUtil.CopyDirectoryRecursive(templateDirectorySource, templateDirectoryTarget);
}
public override void CopyTestCertificate()
{
string certificatePath = PlayerSettings.WSA.certificatePath;
string destFileName = Utility.CombinePath(base.StagingArea, Path.GetFileName(certificatePath));
File.Copy(certificatePath, destFileName);
}
private void CopyUnityTools()
{
string[] strArray = new string[] { "SerializationWeaver/Mono.Cecil.dll", "SerializationWeaver/Mono.Cecil.Mdb.dll", "SerializationWeaver/Mono.Cecil.Pdb.dll", "SerializationWeaver/Mono.Cecil.Rocks.dll", "SerializationWeaver/SerializationWeaver.exe", "SerializationWeaver/Unity.CecilTools.dll", "SerializationWeaver/Unity.SerializationLogic.dll", "SerializationWeaver/Unity.SerializationWeaver.Common.dll", "SerializationWeaver/Unity.SerializationWeaver.dll", "SerializationWeaver/Unity.UNetWeaver.dll", "AssemblyConverter.exe", "Mono.Cecil.dll", "Mono.Cecil.Mdb.dll", "Mono.Cecil.Pdb.dll" };
string str = Path.Combine(base.InstallPath, "Unity");
string[] components = new string[] { str, "Tools", "SerializationWeaver" };
string path = Paths.Combine(components);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
foreach (string str3 in strArray)
{
string[] textArray3 = new string[] { base.PlayerPackage, "Tools", str3 };
string sourceFileName = Paths.Combine(textArray3);
string[] textArray4 = new string[] { base.InstallPath, "Unity", "Tools", str3 };
string destFileName = Paths.Combine(textArray4);
File.Copy(sourceFileName, destFileName, true);
File.SetAttributes(destFileName, FileAttributes.Normal);
}
}
public override void CreateCommandLineArgsPlaceholder()
{
string commandLineArgsFile = PlayerSettings.WSA.commandLineArgsFile;
if (!string.IsNullOrEmpty(commandLineArgsFile))
{
File.WriteAllText(Utility.CombinePath(base.StagingAreaData, commandLineArgsFile), string.Empty, Encoding.UTF8);
}
}
public override void CreateManifest()
{
ManifestWSA twsa = this.CreateManifestBuilder();
string path = Utility.CombinePath(base.StagingArea, "Package.appxmanifest");
twsa.Create(path, this._images);
}
protected abstract ManifestWSA CreateManifestBuilder();
public override void CreateTestCertificate()
{
string certificatePath = PlayerSettings.WSA.certificatePath;
if (string.IsNullOrEmpty(certificatePath) || !File.Exists(certificatePath))
{
if (string.IsNullOrEmpty(certificatePath))
{
certificatePath = Utility.CombinePath(Application.dataPath, "WSATestCertificate.pfx");
}
if (!File.Exists(certificatePath))
{
if (!EditorUtility.WSACreateTestCertificate(certificatePath, base.CompanyName, null, false))
{
throw new UnityException("Failed to create test certificate.");
}
AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
}
PlayerSettings.WSA.SetCertificate(certificatePath, null);
}
}
public override void CreateVisualStudioSolution()
{
string path = Utility.CombinePath(base.InstallPath, base.VisualStudioName + "v11.suo");
if (File.Exists(path))
{
File.Delete(path);
}
Dictionary<WSASDK, LibraryCollection> dictionary = this.TEMP_GetLibraryCollections();
MetroCSharpVisualStudioSolutionCreator creator = new MetroCSharpVisualStudioSolutionCreator(base.VisualStudioName, base.StagingArea, base.InstallPath, base.PlayerPackage) {
SourceBuild = base.SourceBuild,
DontOverwriteFiles = MetroVisualStudioSolutionHelper.GetDontOverwriteFilesCSharp(),
LibraryCollections = dictionary
};
if (base.AutoRunPlayer)
{
IEnumerator enumerator = Enum.GetValues(typeof(WSABuildType)).GetEnumerator();
try
{
while (enumerator.MoveNext())
{
object current = enumerator.Current;
creator.EnableDotNetNative[(WSABuildType) current] = false;
}
}
finally
{
IDisposable disposable = enumerator as IDisposable;
if (disposable != null)
{
disposable.Dispose();
}
}
}
else
{
IEnumerator enumerator2 = Enum.GetValues(typeof(WSABuildType)).GetEnumerator();
try
{
while (enumerator2.MoveNext())
{
object obj3 = enumerator2.Current;
creator.EnableDotNetNative[(WSABuildType) obj3] = EditorUserBuildSettings.GetWSADotNetNative((WSABuildType) obj3);
}
}
finally
{
IDisposable disposable2 = enumerator2 as IDisposable;
if (disposable2 != null)
{
disposable2.Dispose();
}
}
}
creator.CreateSolutionFileFrom();
MetroVisualStudioSolutionHelper.WriteUnityCommonProps(Path.Combine(base.InstallPath, "UnityCommon.props"), base.PlayerPackage, base.InstallPath, base.SourceBuild);
if (!base.SourceBuild)
{
this.CopyUnityTools();
}
}
protected override string GetAlternativeReferenceRewritterMappings() =>
"System.Xml.Serialization";
protected override IEnumerable<string> GetAssembliesIgnoredBySerializationWeaver()
{
IEnumerable<string> assembliesIgnoredBySerializationWeaver = base.GetAssembliesIgnoredBySerializationWeaver();
if (this._generateReferenceProjects)
{
string[] second = new string[] { Utility.AssemblyCSharpName + ".dll", Utility.AssemblyCSharpFirstPassName + ".dll" };
assembliesIgnoredBySerializationWeaver = assembliesIgnoredBySerializationWeaver.Union<string>(second);
}
return assembliesIgnoredBySerializationWeaver;
}
protected string GetDefaultSplashScreenImage()
{
string str;
IDictionary<PlayerSettings.SplashScreen.UnityLogoStyle, string> defaultSplashScreens = this.GetDefaultSplashScreens();
if ((defaultSplashScreens == null) || (defaultSplashScreens.Count == 0))
{
throw new Exception("No splash screens are available!");
}
if (!defaultSplashScreens.TryGetValue(PlayerSettings.SplashScreen.unityLogoStyle, out str))
{
Debug.LogWarning($"No splash screen for {PlayerSettings.SplashScreen.unityLogoStyle} available");
str = defaultSplashScreens.First<KeyValuePair<PlayerSettings.SplashScreen.UnityLogoStyle, string>>().Value;
}
return str;
}
protected virtual IDictionary<PlayerSettings.SplashScreen.UnityLogoStyle, string> GetDefaultSplashScreens()
{
if (_defaultSplashScreens == null)
{
_defaultSplashScreens = new Dictionary<PlayerSettings.SplashScreen.UnityLogoStyle, string>();
_defaultSplashScreens[PlayerSettings.SplashScreen.UnityLogoStyle.DarkOnLight] = "SplashScreen.png";
_defaultSplashScreens[PlayerSettings.SplashScreen.UnityLogoStyle.LightOnDark] = "LightSplashScreen.png";
}
return _defaultSplashScreens;
}
protected override string GetIgnoredReferenceRewriterTypes() =>
"System.IConvertible,mscorlib";
protected override IEnumerable<string> GetIgnoreOutputAssembliesForReferenceRewriter()
{
IEnumerable<string> ignoreOutputAssembliesForReferenceRewriter = base.GetIgnoreOutputAssembliesForReferenceRewriter();
if (base.ThisIsABuildMachine)
{
string[] second = new string[] { Utility.AssemblyCSharpName + ".dll", Utility.AssemblyCSharpFirstPassName + ".dll", Utility.AssemblyUnityScriptName + ".dll", Utility.AssemblyUnityScriptFirstPassName + ".dll" };
ignoreOutputAssembliesForReferenceRewriter = ignoreOutputAssembliesForReferenceRewriter.Union<string>(second);
}
return ignoreOutputAssembliesForReferenceRewriter;
}
protected override string GetPlatformAssemblyPath() =>
MicrosoftCSharpCompiler.GetPlatformAssemblyPath(base._sdk);
protected string GetPlayerFilesSourceDirectory(string path)
{
string[] paths = new string[] { base.PlayerPackage, "Players", path };
return Utility.CombinePath(paths);
}
protected string GetPlayerFilesTargetDirectory(string path)
{
string[] paths = new string[] { base.InstallPath, "Players", path };
return Utility.CombinePath(paths);
}
private static Version GetProjectFileToolsVersion(string path)
{
Version version;
try
{
XElement element = XDocument.Load(path).Element("{http://schemas.microsoft.com/developer/msbuild/2003}Project");
if (element == null)
{
return new Version(0, 0);
}
version = new Version(element.Attribute("ToolsVersion").Value);
}
catch (Exception exception)
{
throw new Exception($"Failed to extract ToolsVersion while reading '{path}'", exception);
}
return version;
}
protected static string GetReferenceAssembliesDirectory(WSASDK sdk) =>
PostProcessWinRT.GetReferenceAssembliesDirectory(MicrosoftCSharpCompiler.GetNETCoreFrameworkReferencesDirectory(sdk));
protected abstract string GetTemplateDirectorySource();
protected string GetTemplateDirectorySource(string directory)
{
string[] paths = new string[] { base.PlayerPackage, "Templates", directory, "CSharp" };
return Utility.CombinePath(paths);
}
protected virtual string GetTemplateDirectoryTarget() =>
base.StagingArea;
protected abstract Version GetToolsVersion();
public override void RunAssemblyConverter()
{
}
protected virtual Dictionary<WSASDK, LibraryCollection> TEMP_GetLibraryCollections() =>
new Dictionary<WSASDK, LibraryCollection>(1) { {
base._sdk,
base.Libraries
} };
}