-
Notifications
You must be signed in to change notification settings - Fork 2
/
APIUpdaterHelper.cs
224 lines (208 loc) · 9.33 KB
/
APIUpdaterHelper.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
211
212
213
214
215
216
217
218
219
220
221
222
223
namespace UnityEditor.Scripting
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using Unity.DataContract;
using UnityEditor;
using UnityEditor.Modules;
using UnityEditor.Scripting.Compilers;
using UnityEditor.Utils;
using UnityEngine;
internal class APIUpdaterHelper
{
[CompilerGenerated]
private static Func<Assembly, IEnumerable<System.Type>> <>f__am$cache0;
[CompilerGenerated]
private static Func<string, Exception, string> <>f__am$cache1;
[CompilerGenerated]
private static Func<KeyValuePair<string, PackageFileData>, bool> <>f__am$cache2;
[CompilerGenerated]
private static Func<KeyValuePair<string, PackageFileData>, string> <>f__am$cache3;
private static string APIVersionArgument()
{
return (" --api-version " + Application.unityVersion + " ");
}
private static string AssemblySearchPathArgument()
{
return (" -e " + CommandLineFormatter.PrepareFileName(GetUnityEditorManagedPath()) + " -p " + CommandLineFormatter.PrepareFileName(Application.dataPath));
}
private static string ConfigurationProviderAssembliesPathArgument()
{
StringBuilder builder = new StringBuilder();
IEnumerator<Unity.DataContract.PackageInfo> enumerator = ModuleManager.packageManager.unityExtensions.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
Unity.DataContract.PackageInfo current = enumerator.Current;
if (<>f__am$cache2 == null)
{
<>f__am$cache2 = f => f.Value.type == PackageFileType.Dll;
}
if (<>f__am$cache3 == null)
{
<>f__am$cache3 = pi => pi.Key;
}
IEnumerator<string> enumerator2 = current.files.Where<KeyValuePair<string, PackageFileData>>(<>f__am$cache2).Select<KeyValuePair<string, PackageFileData>, string>(<>f__am$cache3).GetEnumerator();
try
{
while (enumerator2.MoveNext())
{
string str = enumerator2.Current;
builder.AppendFormat(" {0}", CommandLineFormatter.PrepareFileName(Path.Combine(current.basePath, str)));
}
continue;
}
finally
{
if (enumerator2 == null)
{
}
enumerator2.Dispose();
}
}
}
finally
{
if (enumerator == null)
{
}
enumerator.Dispose();
}
string unityEditorManagedPath = GetUnityEditorManagedPath();
builder.AppendFormat(" {0}", CommandLineFormatter.PrepareFileName(Path.Combine(unityEditorManagedPath, "UnityEngine.dll")));
builder.AppendFormat(" {0}", CommandLineFormatter.PrepareFileName(Path.Combine(unityEditorManagedPath, "UnityEditor.dll")));
return builder.ToString();
}
public static bool DoesAssemblyRequireUpgrade(string assetFullPath)
{
if (File.Exists(assetFullPath))
{
string str;
string str2;
if (!AssemblyHelper.IsManagedAssembly(assetFullPath))
{
return false;
}
int num = RunUpdatingProgram("AssemblyUpdater.exe", TimeStampArgument() + APIVersionArgument() + "--check-update-required -a " + CommandLineFormatter.PrepareFileName(assetFullPath) + AssemblySearchPathArgument() + ConfigurationProviderAssembliesPathArgument(), out str, out str2);
Console.WriteLine("{0}{1}", str, str2);
switch (num)
{
case 0:
case 1:
return false;
case 2:
return true;
}
UnityEngine.Debug.LogError(str + Environment.NewLine + str2);
}
return false;
}
private static string GetUnityEditorManagedPath()
{
return Path.Combine(MonoInstallationFinder.GetFrameWorksFolder(), "Managed");
}
public static bool IsReferenceToMissingObsoleteMember(string namespaceName, string className)
{
bool flag;
<IsReferenceToMissingObsoleteMember>c__AnonStorey9D storeyd = new <IsReferenceToMissingObsoleteMember>c__AnonStorey9D {
className = className,
namespaceName = namespaceName
};
try
{
if (<>f__am$cache0 == null)
{
<>f__am$cache0 = (Func<Assembly, IEnumerable<System.Type>>) (a => a.GetTypes());
}
flag = AppDomain.CurrentDomain.GetAssemblies().SelectMany<Assembly, System.Type>(<>f__am$cache0).FirstOrDefault<System.Type>(new Func<System.Type, bool>(storeyd.<>m__1CC)) != null;
}
catch (ReflectionTypeLoadException exception)
{
if (<>f__am$cache1 == null)
{
<>f__am$cache1 = (acc, curr) => acc + "\r\n\t" + curr.Message;
}
throw new Exception(exception.Message + exception.LoaderExceptions.Aggregate<Exception, string>(string.Empty, <>f__am$cache1));
}
return flag;
}
private static bool IsUpdateable(System.Type type)
{
object[] customAttributes = type.GetCustomAttributes(typeof(ObsoleteAttribute), false);
if (customAttributes.Length != 1)
{
return false;
}
ObsoleteAttribute attribute = (ObsoleteAttribute) customAttributes[0];
return attribute.Message.Contains("UnityUpgradable");
}
private static string ResolveAssemblyPath(string assemblyPath)
{
return CommandLineFormatter.PrepareFileName(assemblyPath);
}
public static void Run(string commaSeparatedListOfAssemblies)
{
char[] separator = new char[] { ',' };
string[] source = commaSeparatedListOfAssemblies.Split(separator, StringSplitOptions.RemoveEmptyEntries);
object[] args = new object[] { source.Count<string>() };
APIUpdaterLogger.WriteToFile("Started to update {0} assemblie(s)", args);
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
foreach (string str in source)
{
if (AssemblyHelper.IsManagedAssembly(str))
{
string str2;
string str3;
string str4 = ResolveAssemblyPath(str);
int num2 = RunUpdatingProgram("AssemblyUpdater.exe", "-u -a " + str4 + APIVersionArgument() + AssemblySearchPathArgument() + ConfigurationProviderAssembliesPathArgument(), out str2, out str3);
if (str2.Length > 0)
{
object[] objArray2 = new object[] { str4, str2 };
APIUpdaterLogger.WriteToFile("Assembly update output ({0})\r\n{1}", objArray2);
}
if (num2 < 0)
{
object[] objArray3 = new object[] { num2, str3 };
APIUpdaterLogger.WriteErrorToConsole("Error {0} running AssemblyUpdater. Its output is: `{1}`", objArray3);
}
}
}
object[] objArray4 = new object[] { stopwatch.Elapsed.TotalSeconds };
APIUpdaterLogger.WriteToFile("Update finished in {0}s", objArray4);
}
private static int RunUpdatingProgram(string executable, string arguments, out string stdOut, out string stdErr)
{
string str = EditorApplication.applicationContentsPath + "/Tools/ScriptUpdater/" + executable;
ManagedProgram program = new ManagedProgram(MonoInstallationFinder.GetMonoInstallation("MonoBleedingEdge"), "4.0", str, arguments);
program.LogProcessStartInfo();
program.Start();
program.WaitForExit();
stdOut = program.GetStandardOutputAsString();
stdErr = string.Join("\r\n", program.GetErrorOutput());
return program.ExitCode;
}
private static string TimeStampArgument()
{
return (" --timestamp " + DateTime.Now.Ticks + " ");
}
[CompilerGenerated]
private sealed class <IsReferenceToMissingObsoleteMember>c__AnonStorey9D
{
internal string className;
internal string namespaceName;
internal bool <>m__1CC(System.Type t)
{
return (((t.Name == this.className) && (t.Namespace == this.namespaceName)) && UnityEditor.Scripting.APIUpdaterHelper.IsUpdateable(t));
}
}
}
}