Skip to content

Commit c263d7b

Browse files
Merge pull request #3013 from workgroupengineering/feature/ReferenceAssemblyOverly
feat(UI): Use AssemblyWarning when AssemblyReference load faulted
2 parents 612c5bc + c832348 commit c263d7b

File tree

4 files changed

+114
-7
lines changed

4 files changed

+114
-7
lines changed

ILSpy/Images/AssemblyLoading.svg

Lines changed: 49 additions & 0 deletions
Loading

ILSpy/Images/AssemblyLoading.xaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" ?>
2+
<DrawingGroup xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
3+
<DrawingGroup.ClipGeometry>
4+
<RectangleGeometry Rect="0.0,0.0,16.0,16.0"/>
5+
</DrawingGroup.ClipGeometry>
6+
<GeometryDrawing Brush="#fff6f6f6">
7+
<GeometryDrawing.Geometry>
8+
<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"/>
9+
</GeometryDrawing.Geometry>
10+
</GeometryDrawing>
11+
<GeometryDrawing Brush="#ff424242">
12+
<GeometryDrawing.Geometry>
13+
<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"/>
14+
</GeometryDrawing.Geometry>
15+
</GeometryDrawing>
16+
<GeometryDrawing Brush="#fff6f6f6">
17+
<GeometryDrawing.Geometry>
18+
<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"/>
19+
</GeometryDrawing.Geometry>
20+
</GeometryDrawing>
21+
<DrawingGroup Transform="0.49999992,0.0,0.0,0.49999992,8.000001,8.000001">
22+
<GeometryDrawing Brush="#ff00539c">
23+
<GeometryDrawing.Geometry>
24+
<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"/>
25+
</GeometryDrawing.Geometry>
26+
</GeometryDrawing>
27+
</DrawingGroup>
28+
</DrawingGroup>

ILSpy/Images/Images.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ static ImageSource Load(string icon)
5353

5454
public static readonly ImageSource Assembly = Load("Assembly");
5555
public static readonly ImageSource AssemblyWarning = Load("AssemblyWarning");
56+
public static readonly ImageSource AssemblyLoading = Load(nameof(AssemblyLoading));
5657
public static readonly ImageSource FindAssembly = Load("FindAssembly");
5758

5859
public static readonly ImageSource Library = Load("Library");

ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
2-
//
2+
//
33
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
44
// software and associated documentation files (the "Software"), to deal in the Software
55
// without restriction, including without limitation the rights to use, copy, modify, merge,
66
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
77
// to whom the Software is furnished to do so, subject to the following conditions:
8-
//
8+
//
99
// The above copyright notice and this permission notice shall be included in all copies or
1010
// substantial portions of the Software.
11-
//
11+
//
1212
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
1313
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
1414
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
@@ -35,9 +35,19 @@ namespace ICSharpCode.ILSpy.TreeNodes
3535
/// </summary>
3636
public sealed class AssemblyReferenceTreeNode : ILSpyTreeNode
3737
{
38+
private enum LoadState
39+
{
40+
Unloaded,
41+
Loading,
42+
Loadded,
43+
Failed
44+
}
45+
3846
readonly MetadataModule module;
3947
readonly AssemblyReference r;
4048
readonly AssemblyTreeNode parentAssembly;
49+
MetadataFile referencedModule;
50+
LoadState state;
4151

4252
public AssemblyReferenceTreeNode(MetadataModule module, AssemblyReference r, AssemblyTreeNode parentAssembly)
4353
{
@@ -55,7 +65,27 @@ public override object Text {
5565

5666
public override object NavigationText => $"{Text} ({Properties.Resources.References})";
5767

58-
public override object Icon => ImagesProvider.Assembly;
68+
public override object Icon {
69+
get {
70+
if (state == LoadState.Unloaded)
71+
{
72+
state = LoadState.Loading;
73+
Dispatcher.CurrentDispatcher.BeginInvoke(() => {
74+
var resolver = parentAssembly.LoadedAssembly.GetAssemblyResolver(SettingsService.DecompilerSettings.AutoLoadAssemblyReferences);
75+
referencedModule = resolver.Resolve(r);
76+
state = referencedModule is null
77+
? LoadState.Failed
78+
: LoadState.Loadded;
79+
RaisePropertyChanged(nameof(Icon));
80+
}, DispatcherPriority.Background);
81+
}
82+
return state switch {
83+
LoadState.Loadded => Images.Assembly,
84+
LoadState.Failed => Images.AssemblyWarning,
85+
_ => Images.AssemblyLoading,
86+
};
87+
}
88+
}
5989

6090
public override bool ShowExpander {
6191
get {
@@ -67,7 +97,7 @@ public override bool ShowExpander {
6797
// while the list of references is updated causes problems with WPF's ListView rendering.
6898
// Moving the assembly resolving out of the "add assembly reference"-loop by using the
6999
// dispatcher fixes the issue.
70-
Dispatcher.CurrentDispatcher.BeginInvoke((Action)EnsureLazyChildren, DispatcherPriority.Normal);
100+
Dispatcher.CurrentDispatcher.BeginInvoke(EnsureLazyChildren, DispatcherPriority.Normal);
71101
}
72102
return base.ShowExpander;
73103
}
@@ -87,8 +117,6 @@ protected override void LoadChildren()
87117
{
88118
this.Children.Add(new AssemblyReferenceReferencedTypesTreeNode(module, r));
89119

90-
var resolver = parentAssembly.LoadedAssembly.GetAssemblyResolver(SettingsService.DecompilerSettings.AutoLoadAssemblyReferences);
91-
var referencedModule = resolver.Resolve(r);
92120
if (referencedModule != null)
93121
{
94122
var module = (MetadataModule)referencedModule.GetTypeSystemWithCurrentOptionsOrNull(SettingsService, AssemblyTreeModel.CurrentLanguageVersion)?.MainModule;
@@ -115,6 +143,7 @@ public override void Decompile(Language language, ITextOutput output, Decompilat
115143
if (info.HasErrors)
116144
{
117145
output.WriteLine("There were some problems during assembly reference load, see below for more information!");
146+
state = LoadState.Failed;
118147
}
119148
PrintAssemblyLoadLogMessages(output, info);
120149
output.Unindent();

0 commit comments

Comments
 (0)