diff --git a/ILSpy/LoadedPackage.cs b/ILSpy/LoadedPackage.cs
index 717e92255..5c889124f 100644
--- a/ILSpy/LoadedPackage.cs
+++ b/ILSpy/LoadedPackage.cs
@@ -49,6 +49,8 @@ namespace ICSharpCode.ILSpy
public PackageKind Kind { get; }
+ internal SingleFileBundle.Header BundleHeader { get; set; }
+
///
/// List of all entries, including those in sub-directories within the package.
///
@@ -115,6 +117,7 @@ namespace ICSharpCode.ILSpy
var manifest = SingleFileBundle.ReadManifest(view, bundleHeaderOffset);
var entries = manifest.Entries.Select(e => new BundleEntry(fileName, view, e)).ToList();
var result = new LoadedPackage(PackageKind.Bundle, entries);
+ result.BundleHeader = manifest;
view = null; // don't dispose the view, we're still using it in the bundle entries
return result;
}
@@ -210,7 +213,7 @@ namespace ICSharpCode.ILSpy
public abstract string FullName { get; }
}
- class PackageFolder : IAssemblyResolver
+ sealed class PackageFolder : IAssemblyResolver
{
///
/// Gets the short name of the folder.
diff --git a/ILSpy/TreeNodes/AssemblyTreeNode.cs b/ILSpy/TreeNodes/AssemblyTreeNode.cs
index 036879ca5..690880403 100644
--- a/ILSpy/TreeNodes/AssemblyTreeNode.cs
+++ b/ILSpy/TreeNodes/AssemblyTreeNode.cs
@@ -90,8 +90,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
var loadResult = LoadedAssembly.GetLoadResultAsync().Result;
if (loadResult.Package != null)
{
- return loadResult.Package.Kind switch
- {
+ return loadResult.Package.Kind switch {
LoadedPackage.PackageKind.Zip => Images.NuGet,
_ => Images.Library,
};
@@ -316,30 +315,57 @@ namespace ICSharpCode.ILSpy.TreeNodes
try
{
- LoadedAssembly.WaitUntilLoaded(); // necessary so that load errors are passed on to the caller
- }
- catch (AggregateException ex)
- {
- language.WriteCommentLine(output, LoadedAssembly.FileName);
- switch (ex.InnerException)
+ var loadResult = LoadedAssembly.GetLoadResultAsync().GetAwaiter().GetResult();
+ if (loadResult.PEFile != null)
+ {
+ language.DecompileAssembly(LoadedAssembly, output, options);
+ }
+ else if (loadResult.Package != null)
+ {
+ output.WriteLine("// " + LoadedAssembly.FileName);
+ DecompilePackage(loadResult.Package, output);
+ }
+ else
{
- case BadImageFormatException badImage:
- HandleException(badImage, "This file does not contain a managed assembly.");
- return;
- case FileNotFoundException fileNotFound:
- HandleException(fileNotFound, "The file was not found.");
- return;
- case DirectoryNotFoundException dirNotFound:
- HandleException(dirNotFound, "The directory was not found.");
- return;
- case PEFileNotSupportedException notSupported:
- HandleException(notSupported, notSupported.Message);
- return;
- default:
- throw;
+ LoadedAssembly.GetPEFileOrNullAsync().GetAwaiter().GetResult();
}
}
- language.DecompileAssembly(LoadedAssembly, output, options);
+ catch (BadImageFormatException badImage)
+ {
+ HandleException(badImage, "This file does not contain a managed assembly.");
+ }
+ catch (FileNotFoundException fileNotFound)
+ {
+ HandleException(fileNotFound, "The file was not found.");
+ }
+ catch (DirectoryNotFoundException dirNotFound)
+ {
+ HandleException(dirNotFound, "The directory was not found.");
+ }
+ catch (PEFileNotSupportedException notSupported)
+ {
+ HandleException(notSupported, notSupported.Message);
+ }
+ }
+
+ private void DecompilePackage(LoadedPackage package, ITextOutput output)
+ {
+ switch (package.Kind)
+ {
+ case LoadedPackage.PackageKind.Zip:
+ output.WriteLine("// File format: .zip file");
+ break;
+ case LoadedPackage.PackageKind.Bundle:
+ var header = package.BundleHeader;
+ output.WriteLine($"// File format: .NET bundle {header.MajorVersion}.{header.MinorVersion}");
+ break;
+ }
+ output.WriteLine();
+ output.WriteLine("Entries:");
+ foreach (var entry in package.Entries)
+ {
+ output.WriteLine(" " + entry.Name);
+ }
}
public override bool Save(TabPageModel tabPage)