From 25bd87aa3a40bd1c238f33ccf075a0a2d8cef2fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20St=C3=B6rmer?= Date: Fri, 24 Nov 2017 14:02:55 +0100 Subject: [PATCH] Added support for dropping nupkg files. --- ILSpy/TreeNodes/AssemblyListTreeNode.cs | 40 +++++++++++++++++++------ 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/ILSpy/TreeNodes/AssemblyListTreeNode.cs b/ILSpy/TreeNodes/AssemblyListTreeNode.cs index d63ec273c..a8fb51dd4 100644 --- a/ILSpy/TreeNodes/AssemblyListTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyListTreeNode.cs @@ -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 @@ -17,8 +17,10 @@ // DEALINGS IN THE SOFTWARE. using System; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; +using System.IO; using System.Linq; using System.Windows; using ICSharpCode.Decompiler; @@ -98,11 +100,12 @@ namespace ICSharpCode.ILSpy.TreeNodes files = e.Data.GetData(DataFormats.FileDrop) as string[]; if (files != null) { lock (assemblyList.assemblies) { - var assemblies = (from file in files - where file != null - select assemblyList.OpenAssembly(file) into node - where node != null - select node).Distinct().ToList(); + var assemblies = files + .Where(file => file != null) + .SelectMany(file => OpenAssembly(assemblyList, file)) + .Where(asm => asm != null) + .Distinct() + .ToArray(); foreach (LoadedAssembly asm in assemblies) { int nodeIndex = assemblyList.assemblies.IndexOf(asm); if (nodeIndex < index) @@ -117,6 +120,25 @@ namespace ICSharpCode.ILSpy.TreeNodes } } + private IEnumerable OpenAssembly(AssemblyList assemblyList, string file) + { + if (file.EndsWith(".nupkg")) { + LoadedNugetPackage package = new LoadedNugetPackage(file); + var selectionDialog = new NugetPackageBrowserDialog(package); + selectionDialog.Owner = Application.Current.MainWindow; + if (selectionDialog.ShowDialog() != true) + yield break; + foreach (var entry in selectionDialog.SelectedItems) { + var nugetAsm = assemblyList.OpenAssembly("nupkg://" + file + ";" + entry.Name, entry.Stream, true); + if (nugetAsm != null) { + yield return nugetAsm; + } + } + yield break; + } + yield return assemblyList.OpenAssembly(file); + } + public Action Select = delegate { }; public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) @@ -168,7 +190,7 @@ namespace ICSharpCode.ILSpy.TreeNodes } return null; } - + public AssemblyTreeNode FindAssemblyNode(AssemblyDefinition asm) { if (asm == null)