Skip to content

Commit

Permalink
feat(UI): Use AssemblyWarning when AssemblyReference load faulted
Browse files Browse the repository at this point in the history
Allow you to easily and quickly see the reference libraries not found fixes icsharpcode#2932
  • Loading branch information
workgroupengineering committed Apr 10, 2024
1 parent 38e7ab4 commit 0cb79b3
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 9 deletions.
49 changes: 49 additions & 0 deletions ILSpy/Images/AssemblyLoading.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions ILSpy/Images/AssemblyLoading.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" ?>
<DrawingGroup xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<DrawingGroup.ClipGeometry>
<RectangleGeometry Rect="0.0,0.0,16.0,16.0"/>
</DrawingGroup.ClipGeometry>
<GeometryDrawing Brush="#fff6f6f6">
<GeometryDrawing.Geometry>
<PathGeometry Figures="M 16 3 v 9 H 8 V 9 H 6 v 2 H 0 V 4 h 6 v 2 h 2 V 3 h 8 z" FillRule="Nonzero"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing Brush="#ff424242">
<GeometryDrawing.Geometry>
<PathGeometry Figures="M 1 5 h 4 v 5 H 1 z M 9 4 h 6 v 7 H 9 z M 6 7 h 2 v 1 H 6 z" FillRule="Nonzero"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing Brush="#fff6f6f6">
<GeometryDrawing.Geometry>
<PathGeometry Figures="m 16 12 c 0 2.2055 -1.7945 4 -4 4 C 9.7945 16 8 14.2055 8 12 A 3.995 3.995 0 0 1 8.544 10 H 8 v -2 H 12 V 12 h -2 c 0 1.103 0.896999 2 2 2 c 1.103 0 2 -0.897 2 -2 c 0 -0.672 -0.3345 -1.295 -0.895 -1.667 l -0.4165 -0.277 l 1.1075 -1.666 l 0.4165 0.2765 A 3.996 3.996 0 0 1 16 12 Z" FillRule="Nonzero"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<DrawingGroup Transform="0.49999992,0.0,0.0,0.49999992,8.000001,8.000001">
<GeometryDrawing Brush="#ff00539c">
<GeometryDrawing.Geometry>
<PathGeometry Figures="m 15 8 c 0 3.859 -3.141 7 -7 7 C 4.14 15 1 11.859 1 8 A 7 7 0 0 1 3.12 3 H 1 V 1 H 7 V 7 H 5 V 4.002 A 5.01 5.01 0 0 0 3 8 c 0 2.757 2.243 5 5 5 c 2.757 0 5 -2.243 5 -5 A 4.993 4.993 0 0 0 10.764 3.833 L 11.871 2.167 A 6.989 6.989 0 0 1 15 8 Z" FillRule="Nonzero"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingGroup>
</DrawingGroup>
1 change: 1 addition & 0 deletions ILSpy/Images/Images.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static ImageSource Load(string icon)

public static readonly ImageSource Assembly = Load("Assembly");
public static readonly ImageSource AssemblyWarning = Load("AssemblyWarning");
public static readonly ImageSource AssemblyLoading = Load(nameof(AssemblyLoading));
public static readonly ImageSource FindAssembly = Load("FindAssembly");

public static readonly ImageSource Library = Load("Library");
Expand Down
47 changes: 38 additions & 9 deletions ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
Expand All @@ -30,9 +30,18 @@ namespace ICSharpCode.ILSpy.TreeNodes
/// </summary>
public sealed class AssemblyReferenceTreeNode : ILSpyTreeNode
{
private enum LoadState
{
Unloaded,
Loading,
Loadded,
Failed
}
readonly MetadataModule module;
readonly AssemblyReference r;
readonly AssemblyTreeNode parentAssembly;
MetadataFile referencedModule;
private LoadState state;

public AssemblyReferenceTreeNode(MetadataModule module, AssemblyReference r, AssemblyTreeNode parentAssembly)
{
Expand All @@ -48,7 +57,27 @@ public override object Text {
get { return Language.EscapeName(r.Name) + GetSuffixString(r.Handle); }
}

public override object Icon => Images.Assembly;
public override object Icon {
get {
if (state == LoadState.Unloaded)
{
state = LoadState.Loading;
Dispatcher.CurrentDispatcher.BeginInvoke(() => {
var resolver = parentAssembly.LoadedAssembly.GetAssemblyResolver(MainWindow.Instance.CurrentDecompilerSettings.AutoLoadAssemblyReferences);
referencedModule = resolver.Resolve(r);
state = referencedModule is null
? LoadState.Failed
: LoadState.Loadded;
RaisePropertyChanged(nameof(Icon));
}, DispatcherPriority.Background);
}
return state switch {
LoadState.Loadded => Images.Assembly,
LoadState.Failed => Images.AssemblyWarning,
_ => Images.AssemblyLoading,
};
}
}

public override bool ShowExpander {
get {
Expand All @@ -60,7 +89,7 @@ public override bool ShowExpander {
// while the list of references is updated causes problems with WPF's ListView rendering.
// Moving the assembly resolving out of the "add assembly reference"-loop by using the
// dispatcher fixes the issue.
Dispatcher.CurrentDispatcher.BeginInvoke((Action)EnsureLazyChildren, DispatcherPriority.Normal);
Dispatcher.CurrentDispatcher.BeginInvoke(EnsureLazyChildren, DispatcherPriority.Normal);
}
return base.ShowExpander;
}
Expand All @@ -79,10 +108,7 @@ public override void ActivateItem(System.Windows.RoutedEventArgs e)
protected override void LoadChildren()
{
this.Children.Add(new AssemblyReferenceReferencedTypesTreeNode(module, r));

var resolver = parentAssembly.LoadedAssembly.GetAssemblyResolver(MainWindow.Instance.CurrentDecompilerSettings.AutoLoadAssemblyReferences);
var referencedModule = resolver.Resolve(r);
if (referencedModule != null)
if (referencedModule is not null)
{
var module = (MetadataModule)referencedModule.GetTypeSystemWithCurrentOptionsOrNull().MainModule;
foreach (var childRef in referencedModule.AssemblyReferences)
Expand All @@ -106,7 +132,10 @@ public override void Decompile(Language language, ITextOutput output, Decompilat
output.Indent();
language.WriteCommentLine(output, "Assembly reference loading information:");
if (info.HasErrors)
{
language.WriteCommentLine(output, "There were some problems during assembly reference load, see below for more information!");
state = LoadState.Failed;
}
foreach (var item in info.Messages)
{
language.WriteCommentLine(output, $"{item.Item1}: {item.Item2}");
Expand Down

0 comments on commit 0cb79b3

Please sign in to comment.