public static int CompareVersion(AssemblyUsagesResult a, AssemblyUsagesResult b) { return(Utility.CompareVersion(a.unityMeta.Version, b.unityMeta.Version)); }
public static AssemblyUsagesResult[] CheckCompatibilities(IEnumerable <string> assembliesPath, FilterText[] filterNamespaces, string[] targetNamespaces, IEnumerable <string> unityVersions) { if (targetNamespaces.Length == 0) { Debug.LogWarning("You must target at least one namespace."); return(null); } int hash = 0; hash += assembliesPath.GetHashCode(); for (int i = 0, max = filterNamespaces.Length; i < max; ++i) { FilterText filter = filterNamespaces[i]; if (filter.active == true) { hash += filter.text.GetHashCode() + filter.active.GetHashCode(); } } for (int i = 0, max = targetNamespaces.Length; i < max; ++i) { hash += targetNamespaces[i].GetHashCode(); } if (AssemblyUsages.usages == null || AssemblyUsages.lastUsagesHash != hash) { AssemblyUsages.lastUsagesHash = hash; using ((AssemblyUsages.debug & DebugItems.WatchTime) == 0 ? null : WatchTime.Get("Extracted usages from target assemblies")) { AssemblyUsages.usages = AssemblyUsages.InspectAssembly(assembliesPath, filterNamespaces, targetNamespaces); } } List <AssemblyUsagesResult> results = new List <AssemblyUsagesResult>(); int processorCount = Environment.ProcessorCount; Exception threadException = null; DatabaseMeta database = DatabaseMeta.GetDatabase(); using ((AssemblyUsages.debug & DebugItems.WatchTime) == 0 ? null : WatchTime.Get("Resolving all")) { foreach (string unityVersion in unityVersions) { try { UnityMeta unityMeta = database.Get(unityVersion); if (unityMeta != null) { AssemblyUsagesResult result = new AssemblyUsagesResult() { assemblyUsages = usages, unityMeta = unityMeta }; using ((AssemblyUsages.debug & DebugItems.WatchTime) == 0 ? null : WatchTime.Get("Resolved against " + unityMeta.Version)) { result.ResolveReferences(AssemblyUsages.usages.visibleTypes, AssemblyUsages.usages.visibleFields, AssemblyUsages.usages.visibleMethods); } lock (results) { results.Add(result); } } } catch (Exception ex) { Debug.LogException(ex); threadException = ex; } } } if (threadException != null) { throw threadException; } results.Sort(Utility.CompareVersion); return(results.ToArray()); }
protected virtual void OnGUI() { if (this.results == null) { return; } if (this.richFoldout == null) { this.richFoldout = new GUIStyle(EditorStyles.foldout); this.richFoldout.richText = true; } if (this.resultsAsLabel == null) { this.resultsAsLabel = new string[this.results.Length]; this.resultsAnomalyAsLabel = new string[this.results.Length]; for (int i = 0; i < this.results.Length; i++) { AssemblyUsagesResult result = this.results[i]; int missingRefsCount = result.missingTypes.Count + result.missingFields.Count + result.missingMethods.Count; int warningsCount = result.foundTypes.Count + result.foundFields.Count + result.foundMethods.Count; if (missingRefsCount + warningsCount == 0) { this.resultsAsLabel[i] = result.unityMeta.Version + " <color=green>(Fully compatible)</color>"; } else if (missingRefsCount + warningsCount == 1) { this.resultsAnomalyAsLabel[i] = (missingRefsCount + warningsCount) + " anomaly detected"; if (missingRefsCount > 0) { this.resultsAsLabel[i] = result.unityMeta.Version + " <color=red>(" + (missingRefsCount + warningsCount) + " anomaly)</color>"; } else { this.resultsAsLabel[i] = result.unityMeta.Version + " (" + (missingRefsCount + warningsCount) + " anomaly)"; } } else { this.resultsAnomalyAsLabel[i] = (missingRefsCount + warningsCount) + " anomalies detected"; if (missingRefsCount > 0) { this.resultsAsLabel[i] = result.unityMeta.Version + " <color=red>(" + (missingRefsCount + warningsCount) + " anomalies)</color>"; } else { this.resultsAsLabel[i] = result.unityMeta.Version + " (" + (missingRefsCount + warningsCount) + " anomalies)"; } } } } using (var scroll = new EditorGUILayout.ScrollViewScope(this.scrollPosition)) { this.scrollPosition = scroll.scrollPosition; for (int i = 0; i < this.results.Length; i++) { AssemblyUsagesResult result = this.results[i]; int missingRefsCount = result.missingTypes.Count + result.missingFields.Count + result.missingMethods.Count; int warningsCount = result.foundTypes.Count + result.foundFields.Count + result.foundMethods.Count; using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar)) { Rect r = GUILayoutUtility.GetRect(0F, Constants.SingleLineHeight, EditorStyles.label); r.width -= AssemblyUsagesResultWindow.ExportButtonWidth + AssemblyUsagesResultWindow.InspectMetaButtonWidth; this.resultsIsOpen[i] = EditorGUI.Foldout(r, this.resultsIsOpen[i], this.resultsAsLabel[i], true, this.richFoldout); r.x += r.width; r.y -= 2F; r.width = AssemblyUsagesResultWindow.ExportButtonWidth; if (GUI.Button(r, "Export", EditorStyles.toolbarButton) == true) { StringBuilder buffer = new StringBuilder(1024); result.Export(buffer); EditorGUIUtility.systemCopyBuffer = buffer.ToString(); this.ShowNotification(new GUIContent("Result exported to clipboard.")); } r.x += r.width; r.width = AssemblyUsagesResultWindow.InspectMetaButtonWidth; if (GUI.Button(r, "Inspect Meta", EditorStyles.toolbarButton) == true) { Utility.OpenWindow <AssemblyMetaWindow>(AssemblyMetaWindow.Title, true, w => w.meta = result.unityMeta.AssembliesMeta); } } if (this.resultsIsOpen[i] == true) { StringBuilder buffer = new StringBuilder(); for (int j = 0, max2 = result.assemblyUsages.Assemblies.Length; j < max2; ++j) { if (j > 0) { buffer.Append(", "); } buffer.Append(Path.GetFileNameWithoutExtension(result.assemblyUsages.Assemblies[j])); } EditorGUILayout.TextField("Inspected", buffer.ToString()); buffer.Length = 0; for (int j = 0, max2 = result.assemblyUsages.FilterNamespaces.Length; j < max2; ++j) { FilterText filter = result.assemblyUsages.FilterNamespaces[j]; if (j > 0) { buffer.Append(", "); } if (filter.type == Filter.Type.Inclusive) { buffer.Append('+'); } else { buffer.Append('-'); } buffer.Append(Path.GetFileNameWithoutExtension(filter.text)); } EditorGUILayout.TextField("Filtered in namespaces", buffer.ToString()); buffer.Length = 0; for (int j = 0, max2 = result.assemblyUsages.TargetNamespaces.Length; j < max2; ++j) { if (j > 0) { buffer.Append(", "); } buffer.Append(Path.GetFileNameWithoutExtension(result.assemblyUsages.TargetNamespaces[j])); } EditorGUILayout.TextField("Targeted namespaces", buffer.ToString()); if (missingRefsCount + warningsCount > 0) { GUILayout.Space(5F); using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar)) { GUILayout.Label(this.resultsAnomalyAsLabel[i]); } ++EditorGUI.indentLevel; if (result.missingTypes.Count > 0) { GUILayout.Space(5F); using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar)) { EditorGUILayout.LabelField("Missing Types (" + result.missingTypes.Count + ")"); } ++EditorGUI.indentLevel; for (int j = 0, max2 = result.missingTypes.Count; j < max2; ++j) { using (new EditorGUILayout.HorizontalScope()) { EditorGUILayout.TextField(result.missingTypes[j].ToString()); if (GUILayout.Button("See API Range", EditorStyles.miniButton, GUILayoutOptionPool.Width(100F)) == true) { Application.OpenURL("https://sabresaurus.com/unity-api-versioner/?api=" + result.missingTypes[j].ToString()); return; } } if (result.missingTypes[j].ErrorMessage != null) { ++EditorGUI.indentLevel; EditorGUILayout.TextField(result.missingTypes[j].ErrorMessage, EditorStyles.miniLabel); --EditorGUI.indentLevel; } } --EditorGUI.indentLevel; } if (result.missingFields.Count > 0) { GUILayout.Space(5F); using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar)) { EditorGUILayout.LabelField("Missing Fields (" + result.missingFields.Count + ")"); } ++EditorGUI.indentLevel; for (int j = 0, max2 = result.missingFields.Count; j < max2; ++j) { EditorGUILayout.TextField(result.missingFields[j].ToString()); if (result.missingFields[j].ErrorMessage != null) { ++EditorGUI.indentLevel; EditorGUILayout.TextField(result.foundFields[j].ErrorMessage, EditorStyles.miniLabel); --EditorGUI.indentLevel; } } --EditorGUI.indentLevel; } if (result.missingMethods.Count > 0) { GUILayout.Space(5F); using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar)) { EditorGUILayout.LabelField("Missing Methods (" + result.missingMethods.Count + ")"); } ++EditorGUI.indentLevel; for (int j = 0, max2 = result.missingMethods.Count; j < max2; ++j) { EditorGUILayout.TextField(result.missingMethods[j].ToString()); if (result.missingMethods[j].ErrorMessage != null) { ++EditorGUI.indentLevel; EditorGUILayout.TextField(result.missingMethods[j].ErrorMessage, EditorStyles.miniLabel); --EditorGUI.indentLevel; } } --EditorGUI.indentLevel; } if (result.foundTypes.Count > 0) { GUILayout.Space(5F); using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar)) { EditorGUILayout.LabelField("Found Types with error (" + result.foundTypes.Count + ")"); } for (int j = 0, max2 = result.foundTypes.Count; j < max2; ++j) { ++EditorGUI.indentLevel; EditorGUILayout.TextField(result.foundTypes[j].ToString()); ++EditorGUI.indentLevel; EditorGUILayout.TextField(result.foundTypes[j].ErrorMessage, EditorStyles.miniLabel); --EditorGUI.indentLevel; --EditorGUI.indentLevel; } } if (result.foundFields.Count > 0) { GUILayout.Space(5F); using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar)) { EditorGUILayout.LabelField("Found Fields with error (" + result.foundFields.Count + ")"); } for (int j = 0, max2 = result.foundFields.Count; j < max2; ++j) { ++EditorGUI.indentLevel; EditorGUILayout.TextField(result.foundFields[j].ToString()); ++EditorGUI.indentLevel; EditorGUILayout.TextField(result.foundFields[j].ErrorMessage, EditorStyles.miniLabel); --EditorGUI.indentLevel; --EditorGUI.indentLevel; } } if (result.foundMethods.Count > 0) { GUILayout.Space(5F); using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar)) { EditorGUILayout.LabelField("Found Methods with error (" + result.foundMethods.Count + ")"); } for (int j = 0, max2 = result.foundMethods.Count; j < max2; ++j) { ++EditorGUI.indentLevel; EditorGUILayout.TextField(result.foundMethods[j].ToString()); ++EditorGUI.indentLevel; EditorGUILayout.TextField(result.foundMethods[j].ErrorMessage, EditorStyles.miniLabel); --EditorGUI.indentLevel; --EditorGUI.indentLevel; } } --EditorGUI.indentLevel; } } } } }