mirror of https://github.com/icsharpcode/ILSpy.git
44 changed files with 1007 additions and 850 deletions
@ -0,0 +1,160 @@
@@ -0,0 +1,160 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using System; |
||||
using System.Collections.Immutable; |
||||
using System.IO; |
||||
using System.IO.MemoryMappedFiles; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.Decompiler |
||||
{ |
||||
/// <summary>
|
||||
/// Class for dealing with .NET 5 single-file bundles.
|
||||
///
|
||||
/// Based on code from Microsoft.NET.HostModel.
|
||||
/// </summary>
|
||||
public static class SingleFileBundle |
||||
{ |
||||
/// <summary>
|
||||
/// Check if the memory-mapped data is a single-file bundle
|
||||
/// </summary>
|
||||
public static unsafe bool IsBundle(MemoryMappedViewAccessor view, out long bundleHeaderOffset) |
||||
{ |
||||
var buffer = view.SafeMemoryMappedViewHandle; |
||||
byte* ptr = null; |
||||
buffer.AcquirePointer(ref ptr); |
||||
try |
||||
{ |
||||
return IsBundle(ptr, checked((long)buffer.ByteLength), out bundleHeaderOffset); |
||||
} |
||||
finally |
||||
{ |
||||
buffer.ReleasePointer(); |
||||
} |
||||
} |
||||
|
||||
public static unsafe bool IsBundle(byte* data, long size, out long bundleHeaderOffset) |
||||
{ |
||||
ReadOnlySpan<byte> bundleSignature = new byte[] { |
||||
// 32 bytes represent the bundle signature: SHA-256 for ".net core bundle"
|
||||
0x8b, 0x12, 0x02, 0xb9, 0x6a, 0x61, 0x20, 0x38, |
||||
0x72, 0x7b, 0x93, 0x02, 0x14, 0xd7, 0xa0, 0x32, |
||||
0x13, 0xf5, 0xb9, 0xe6, 0xef, 0xae, 0x33, 0x18, |
||||
0xee, 0x3b, 0x2d, 0xce, 0x24, 0xb3, 0x6a, 0xae |
||||
}; |
||||
|
||||
byte* end = data + (size - bundleSignature.Length); |
||||
for (byte* ptr = data; ptr < end; ptr++) |
||||
{ |
||||
if (*ptr == 0x8b && bundleSignature.SequenceEqual(new ReadOnlySpan<byte>(ptr, bundleSignature.Length))) |
||||
{ |
||||
bundleHeaderOffset = *(long*)(ptr - sizeof(long)); |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
bundleHeaderOffset = 0; |
||||
return false; |
||||
} |
||||
|
||||
public struct Header |
||||
{ |
||||
public uint MajorVersion; |
||||
public uint MinorVersion; |
||||
public int FileCount; |
||||
public string BundleID; |
||||
|
||||
// Fields introduced with v2:
|
||||
public long DepsJsonOffset; |
||||
public long DepsJsonSize; |
||||
public long RuntimeConfigJsonOffset; |
||||
public long RuntimeConfigJsonSize; |
||||
public ulong Flags; |
||||
|
||||
public ImmutableArray<Entry> Entries; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// FileType: Identifies the type of file embedded into the bundle.
|
||||
///
|
||||
/// The bundler differentiates a few kinds of files via the manifest,
|
||||
/// with respect to the way in which they'll be used by the runtime.
|
||||
/// </summary>
|
||||
public enum FileType : byte |
||||
{ |
||||
Unknown, // Type not determined.
|
||||
Assembly, // IL and R2R Assemblies
|
||||
NativeBinary, // NativeBinaries
|
||||
DepsJson, // .deps.json configuration file
|
||||
RuntimeConfigJson, // .runtimeconfig.json configuration file
|
||||
Symbols // PDB Files
|
||||
}; |
||||
|
||||
public struct Entry |
||||
{ |
||||
public long Offset; |
||||
public long Size; |
||||
public FileType Type; |
||||
public string RelativePath; // Path of an embedded file, relative to the Bundle source-directory.
|
||||
} |
||||
|
||||
static UnmanagedMemoryStream AsStream(MemoryMappedViewAccessor view) |
||||
{ |
||||
long size = checked((long)view.SafeMemoryMappedViewHandle.ByteLength); |
||||
return new UnmanagedMemoryStream(view.SafeMemoryMappedViewHandle, 0, size); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Reads the manifest header from the memory mapping.
|
||||
/// </summary>
|
||||
public static Header ReadManifest(MemoryMappedViewAccessor view, long bundleHeaderOffset) |
||||
{ |
||||
using var stream = AsStream(view); |
||||
stream.Seek(bundleHeaderOffset, SeekOrigin.Begin); |
||||
return ReadManifest(stream); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Reads the manifest header from the stream.
|
||||
/// </summary>
|
||||
public static Header ReadManifest(Stream stream) |
||||
{ |
||||
var header = new Header(); |
||||
using var reader = new BinaryReader(stream, Encoding.UTF8, leaveOpen: true); |
||||
header.MajorVersion = reader.ReadUInt32(); |
||||
header.MinorVersion = reader.ReadUInt32(); |
||||
if (header.MajorVersion < 1 || header.MajorVersion > 2) |
||||
{ |
||||
throw new InvalidDataException($"Unsupported manifest version: {header.MajorVersion}.{header.MinorVersion}"); |
||||
} |
||||
header.FileCount = reader.ReadInt32(); |
||||
header.BundleID = reader.ReadString(); |
||||
if (header.MajorVersion >= 2) |
||||
{ |
||||
header.DepsJsonOffset = reader.ReadInt64(); |
||||
header.DepsJsonSize = reader.ReadInt64(); |
||||
header.RuntimeConfigJsonOffset = reader.ReadInt64(); |
||||
header.RuntimeConfigJsonSize = reader.ReadInt64(); |
||||
header.Flags = reader.ReadUInt64(); |
||||
} |
||||
var entries = ImmutableArray.CreateBuilder<Entry>(header.FileCount); |
||||
for (int i = 0; i < header.FileCount; i++) |
||||
{ |
||||
entries.Add(ReadEntry(reader)); |
||||
} |
||||
header.Entries = entries.MoveToImmutable(); |
||||
return header; |
||||
} |
||||
|
||||
private static Entry ReadEntry(BinaryReader reader) |
||||
{ |
||||
Entry entry; |
||||
entry.Offset = reader.ReadInt64(); |
||||
entry.Size = reader.ReadInt64(); |
||||
entry.Type = (FileType)reader.ReadByte(); |
||||
entry.RelativePath = reader.ReadString(); |
||||
return entry; |
||||
} |
||||
} |
||||
} |
After Width: | Height: | Size: 13 KiB |
@ -1,121 +0,0 @@
@@ -1,121 +0,0 @@
|
||||
// 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
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.ComponentModel; |
||||
using System.IO; |
||||
using System.IO.Compression; |
||||
using System.Linq; |
||||
using System.Runtime.CompilerServices; |
||||
using System.Text; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace ICSharpCode.ILSpy |
||||
{ |
||||
public class LoadedNugetPackage : INotifyPropertyChanged |
||||
{ |
||||
public List<Entry> Entries { get; } = new List<Entry>(); |
||||
public List<Entry> SelectedEntries { get; } = new List<Entry>(); |
||||
|
||||
public LoadedNugetPackage(string file) |
||||
{ |
||||
using (var archive = ZipFile.OpenRead(file)) |
||||
{ |
||||
foreach (var entry in archive.Entries) |
||||
{ |
||||
switch (Path.GetExtension(entry.FullName)) |
||||
{ |
||||
case ".dll": |
||||
case ".exe": |
||||
var memory = new MemoryStream(); |
||||
entry.Open().CopyTo(memory); |
||||
memory.Position = 0; |
||||
var e = new Entry(Uri.UnescapeDataString(entry.FullName), memory); |
||||
e.PropertyChanged += EntryPropertyChanged; |
||||
Entries.Add(e); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
void EntryPropertyChanged(object sender, PropertyChangedEventArgs e) |
||||
{ |
||||
if (e.PropertyName == nameof(Entry.IsSelected)) |
||||
{ |
||||
var entry = (Entry)sender; |
||||
if (entry.IsSelected) |
||||
SelectedEntries.Add(entry); |
||||
else |
||||
SelectedEntries.Remove(entry); |
||||
OnPropertyChanged(nameof(SelectedEntries)); |
||||
} |
||||
} |
||||
|
||||
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) |
||||
{ |
||||
PropertyChanged?.Invoke(this, e); |
||||
} |
||||
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) |
||||
{ |
||||
OnPropertyChanged(new PropertyChangedEventArgs(propertyName)); |
||||
} |
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged; |
||||
} |
||||
|
||||
public class Entry : INotifyPropertyChanged |
||||
{ |
||||
public string Name { get; } |
||||
|
||||
public bool IsSelected { |
||||
get { return isSelected; } |
||||
set { |
||||
if (isSelected != value) |
||||
{ |
||||
isSelected = value; |
||||
OnPropertyChanged(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) |
||||
{ |
||||
PropertyChanged?.Invoke(this, e); |
||||
} |
||||
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) |
||||
{ |
||||
OnPropertyChanged(new PropertyChangedEventArgs(propertyName)); |
||||
} |
||||
|
||||
public Stream Stream { get; } |
||||
|
||||
bool isSelected; |
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged; |
||||
|
||||
public Entry(string name, Stream stream) |
||||
{ |
||||
this.Name = name; |
||||
this.Stream = stream; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,281 @@
@@ -0,0 +1,281 @@
|
||||
// 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
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.IO; |
||||
using System.IO.Compression; |
||||
using System.IO.MemoryMappedFiles; |
||||
using System.Linq; |
||||
using System.Reflection; |
||||
using System.Threading.Tasks; |
||||
|
||||
using ICSharpCode.Decompiler; |
||||
using ICSharpCode.Decompiler.Metadata; |
||||
|
||||
namespace ICSharpCode.ILSpy |
||||
{ |
||||
/// <summary>
|
||||
/// NuGet package or .NET bundle:
|
||||
/// </summary>
|
||||
public class LoadedPackage |
||||
{ |
||||
public enum PackageKind |
||||
{ |
||||
Zip, |
||||
Bundle, |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the LoadedAssembly instance representing this bundle.
|
||||
/// </summary>
|
||||
internal LoadedAssembly LoadedAssembly { get; set; } |
||||
|
||||
public PackageKind Kind { get; } |
||||
|
||||
/// <summary>
|
||||
/// List of all entries, including those in sub-directories within the package.
|
||||
/// </summary>
|
||||
public IReadOnlyList<PackageEntry> Entries { get; } |
||||
|
||||
internal PackageFolder RootFolder { get; } |
||||
|
||||
public LoadedPackage(PackageKind kind, IEnumerable<PackageEntry> entries) |
||||
{ |
||||
this.Kind = kind; |
||||
this.Entries = entries.ToArray(); |
||||
var topLevelEntries = new List<PackageEntry>(); |
||||
var folders = new Dictionary<string, PackageFolder>(); |
||||
var rootFolder = new PackageFolder(this, null, ""); |
||||
folders.Add("", rootFolder); |
||||
foreach (var entry in this.Entries) |
||||
{ |
||||
var (dirname, filename) = SplitName(entry.Name); |
||||
GetFolder(dirname).Entries.Add(new FolderEntry(filename, entry)); |
||||
} |
||||
this.RootFolder = rootFolder; |
||||
|
||||
static (string, string) SplitName(string filename) |
||||
{ |
||||
int pos = filename.LastIndexOfAny(new char[] { '/', '\\' }); |
||||
if (pos == -1) |
||||
return ("", filename); // file in root
|
||||
else |
||||
return (filename.Substring(0, pos), filename.Substring(pos + 1)); |
||||
} |
||||
|
||||
PackageFolder GetFolder(string name) |
||||
{ |
||||
if (folders.TryGetValue(name, out var result)) |
||||
return result; |
||||
var (dirname, basename) = SplitName(name); |
||||
PackageFolder parent = GetFolder(dirname); |
||||
result = new PackageFolder(this, parent, basename); |
||||
parent.Folders.Add(result); |
||||
folders.Add(name, result); |
||||
return result; |
||||
} |
||||
} |
||||
|
||||
public static LoadedPackage FromZipFile(string file) |
||||
{ |
||||
Debug.WriteLine($"LoadedPackage.FromZipFile({file})"); |
||||
using var archive = ZipFile.OpenRead(file); |
||||
return new LoadedPackage(PackageKind.Zip, |
||||
archive.Entries.Select(entry => new ZipFileEntry(file, entry))); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Load a .NET single-file bundle.
|
||||
/// </summary>
|
||||
public static LoadedPackage FromBundle(string fileName) |
||||
{ |
||||
using var memoryMappedFile = MemoryMappedFile.CreateFromFile(fileName, FileMode.Open, null, 0, MemoryMappedFileAccess.Read); |
||||
var view = memoryMappedFile.CreateViewAccessor(0, 0, MemoryMappedFileAccess.Read); |
||||
try |
||||
{ |
||||
if (!SingleFileBundle.IsBundle(view, out long bundleHeaderOffset)) |
||||
return null; |
||||
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); |
||||
view = null; // don't dispose the view, we're still using it in the bundle entries
|
||||
return result; |
||||
} |
||||
finally |
||||
{ |
||||
view?.Dispose(); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Entry inside a package folder. Effectively renames the entry.
|
||||
/// </summary>
|
||||
sealed class FolderEntry : PackageEntry |
||||
{ |
||||
readonly PackageEntry originalEntry; |
||||
public override string Name { get; } |
||||
|
||||
public FolderEntry(string name, PackageEntry originalEntry) |
||||
{ |
||||
this.Name = name; |
||||
this.originalEntry = originalEntry; |
||||
} |
||||
|
||||
public override ManifestResourceAttributes Attributes => originalEntry.Attributes; |
||||
public override string FullName => originalEntry.FullName; |
||||
public override ResourceType ResourceType => originalEntry.ResourceType; |
||||
public override Stream TryOpenStream() => originalEntry.TryOpenStream(); |
||||
} |
||||
|
||||
sealed class ZipFileEntry : PackageEntry |
||||
{ |
||||
readonly string zipFile; |
||||
public override string Name { get; } |
||||
public override string FullName => $"zip://{zipFile};{Name}"; |
||||
|
||||
public ZipFileEntry(string zipFile, ZipArchiveEntry entry) |
||||
{ |
||||
this.zipFile = zipFile; |
||||
this.Name = entry.FullName; |
||||
} |
||||
|
||||
public override Stream TryOpenStream() |
||||
{ |
||||
Debug.WriteLine("Decompress " + Name); |
||||
using var archive = ZipFile.OpenRead(zipFile); |
||||
var entry = archive.GetEntry(Name); |
||||
if (entry == null) |
||||
return null; |
||||
var memoryStream = new MemoryStream(); |
||||
using (var s = entry.Open()) |
||||
{ |
||||
s.CopyTo(memoryStream); |
||||
} |
||||
memoryStream.Position = 0; |
||||
return memoryStream; |
||||
} |
||||
} |
||||
|
||||
sealed class BundleEntry : PackageEntry |
||||
{ |
||||
readonly string bundleFile; |
||||
readonly MemoryMappedViewAccessor view; |
||||
readonly SingleFileBundle.Entry entry; |
||||
|
||||
public BundleEntry(string bundleFile, MemoryMappedViewAccessor view, SingleFileBundle.Entry entry) |
||||
{ |
||||
this.bundleFile = bundleFile; |
||||
this.view = view; |
||||
this.entry = entry; |
||||
} |
||||
|
||||
public override string Name => entry.RelativePath; |
||||
public override string FullName => $"bundle://{bundleFile};{Name}"; |
||||
|
||||
public override Stream TryOpenStream() |
||||
{ |
||||
Debug.WriteLine("Open bundle member " + Name); |
||||
return new UnmanagedMemoryStream(view.SafeMemoryMappedViewHandle, entry.Offset, entry.Size); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public abstract class PackageEntry : Resource |
||||
{ |
||||
/// <summary>
|
||||
/// Gets the file name of the entry (may include path components, relative to the package root).
|
||||
/// </summary>
|
||||
public abstract override string Name { get; } |
||||
|
||||
/// <summary>
|
||||
/// Gets the full file name for the entry.
|
||||
/// </summary>
|
||||
public abstract string FullName { get; } |
||||
} |
||||
|
||||
class PackageFolder : IAssemblyResolver |
||||
{ |
||||
/// <summary>
|
||||
/// Gets the short name of the folder.
|
||||
/// </summary>
|
||||
public string Name { get; } |
||||
|
||||
readonly LoadedPackage package; |
||||
readonly PackageFolder parent; |
||||
|
||||
internal PackageFolder(LoadedPackage package, PackageFolder parent, string name) |
||||
{ |
||||
this.package = package; |
||||
this.parent = parent; |
||||
this.Name = name; |
||||
} |
||||
|
||||
public List<PackageFolder> Folders { get; } = new List<PackageFolder>(); |
||||
public List<PackageEntry> Entries { get; } = new List<PackageEntry>(); |
||||
|
||||
public PEFile Resolve(IAssemblyReference reference) |
||||
{ |
||||
var asm = ResolveFileName(reference.Name + ".dll"); |
||||
if (asm != null) |
||||
{ |
||||
return asm.GetPEFileOrNull(); |
||||
} |
||||
return parent?.Resolve(reference); |
||||
} |
||||
|
||||
public PEFile ResolveModule(PEFile mainModule, string moduleName) |
||||
{ |
||||
var asm = ResolveFileName(moduleName + ".dll"); |
||||
if (asm != null) |
||||
{ |
||||
return asm.GetPEFileOrNull(); |
||||
} |
||||
return parent?.ResolveModule(mainModule, moduleName); |
||||
} |
||||
|
||||
readonly Dictionary<string, LoadedAssembly> assemblies = new Dictionary<string, LoadedAssembly>(StringComparer.OrdinalIgnoreCase); |
||||
|
||||
internal LoadedAssembly ResolveFileName(string name) |
||||
{ |
||||
if (package.LoadedAssembly == null) |
||||
return null; |
||||
lock (assemblies) |
||||
{ |
||||
if (assemblies.TryGetValue(name, out var asm)) |
||||
return asm; |
||||
var entry = Entries.FirstOrDefault(e => string.Equals(name, e.Name, StringComparison.OrdinalIgnoreCase)); |
||||
if (entry != null) |
||||
{ |
||||
asm = new LoadedAssembly( |
||||
package.LoadedAssembly, entry.Name, |
||||
assemblyResolver: this, |
||||
stream: Task.Run(entry.TryOpenStream) |
||||
); |
||||
} |
||||
else |
||||
{ |
||||
asm = null; |
||||
} |
||||
assemblies.Add(name, asm); |
||||
return asm; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,92 @@
@@ -0,0 +1,92 @@
|
||||
// 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
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
using ICSharpCode.Decompiler; |
||||
using ICSharpCode.TreeView; |
||||
|
||||
namespace ICSharpCode.ILSpy.TreeNodes |
||||
{ |
||||
/// <summary>
|
||||
/// Lists the embedded resources in an assembly.
|
||||
/// </summary>
|
||||
sealed class PackageFolderTreeNode : ILSpyTreeNode |
||||
{ |
||||
readonly PackageFolder folder; |
||||
|
||||
public PackageFolderTreeNode(PackageFolder folder, string text = null) |
||||
{ |
||||
this.folder = folder; |
||||
this.Text = text ?? folder.Name; |
||||
this.LazyLoading = true; |
||||
} |
||||
|
||||
public override object Text { get; } |
||||
|
||||
public override object Icon => Images.FolderClosed; |
||||
|
||||
public override object ExpandedIcon => Images.FolderOpen; |
||||
|
||||
protected override void LoadChildren() |
||||
{ |
||||
this.Children.AddRange(LoadChildrenForFolder(folder)); |
||||
} |
||||
|
||||
internal static IEnumerable<SharpTreeNode> LoadChildrenForFolder(PackageFolder root) |
||||
{ |
||||
foreach (var folder in root.Folders.OrderBy(f => f.Name)) |
||||
{ |
||||
string newName = folder.Name; |
||||
var subfolder = folder; |
||||
while (subfolder.Folders.Count == 1 && subfolder.Entries.Count == 0) |
||||
{ |
||||
// special case: a folder that only contains a single sub-folder
|
||||
subfolder = subfolder.Folders[0]; |
||||
newName = $"{newName}/{subfolder.Name}"; |
||||
} |
||||
yield return new PackageFolderTreeNode(subfolder, newName); |
||||
} |
||||
foreach (var entry in root.Entries.OrderBy(e => e.Name)) |
||||
{ |
||||
if (entry.Name.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) |
||||
{ |
||||
var asm = root.ResolveFileName(entry.Name); |
||||
if (asm != null) |
||||
{ |
||||
yield return new AssemblyTreeNode(asm); |
||||
} |
||||
else |
||||
{ |
||||
yield return ResourceTreeNode.Create(entry); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
yield return ResourceTreeNode.Create(entry); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) |
||||
{ |
||||
} |
||||
} |
||||
} |
@ -1,99 +0,0 @@
@@ -1,99 +0,0 @@
|
||||
// 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
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.ComponentModel.Composition; |
||||
using System.IO; |
||||
using System.Threading.Tasks; |
||||
|
||||
using ICSharpCode.AvalonEdit.Highlighting; |
||||
using ICSharpCode.Decompiler.Metadata; |
||||
using ICSharpCode.ILSpy.TextView; |
||||
using ICSharpCode.ILSpy.TreeNodes; |
||||
using ICSharpCode.ILSpy.ViewModels; |
||||
|
||||
namespace ICSharpCode.ILSpy.TreeNodes |
||||
{ |
||||
[Export(typeof(IResourceNodeFactory))] |
||||
sealed class JsonResourceNodeFactory : IResourceNodeFactory |
||||
{ |
||||
private readonly static string[] jsonFileExtensions = { ".json" }; |
||||
|
||||
public ILSpyTreeNode CreateNode(Resource resource) |
||||
{ |
||||
Stream stream = resource.TryOpenStream(); |
||||
if (stream == null) |
||||
return null; |
||||
return CreateNode(resource.Name, stream); |
||||
} |
||||
|
||||
public ILSpyTreeNode CreateNode(string key, object data) |
||||
{ |
||||
if (!(data is Stream)) |
||||
return null; |
||||
foreach (string fileExt in jsonFileExtensions) |
||||
{ |
||||
if (key.EndsWith(fileExt, StringComparison.OrdinalIgnoreCase)) |
||||
return new JsonResourceEntryNode(key, (Stream)data); |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
sealed class JsonResourceEntryNode : ResourceEntryNode |
||||
{ |
||||
string json; |
||||
|
||||
public JsonResourceEntryNode(string key, Stream data) |
||||
: base(key, data) |
||||
{ |
||||
} |
||||
|
||||
// TODO : add Json Icon
|
||||
public override object Icon => Images.Resource; |
||||
|
||||
public override bool View(TabPageModel tabPage) |
||||
{ |
||||
AvalonEditTextOutput output = new AvalonEditTextOutput(); |
||||
IHighlightingDefinition highlighting = null; |
||||
|
||||
tabPage.ShowTextView(textView => textView.RunWithCancellation( |
||||
token => Task.Factory.StartNew( |
||||
() => { |
||||
try { |
||||
// cache read XAML because stream will be closed after first read
|
||||
if (json == null) { |
||||
using (var reader = new StreamReader(Data)) { |
||||
json = reader.ReadToEnd(); |
||||
} |
||||
} |
||||
output.Write(json); |
||||
highlighting = HighlightingManager.Instance.GetDefinitionByExtension(".json"); |
||||
} |
||||
catch (Exception ex) { |
||||
output.Write(ex.ToString()); |
||||
} |
||||
return output; |
||||
}, token) |
||||
).Then(t => textView.ShowNode(t, this, highlighting)) |
||||
.HandleExceptions()); |
||||
tabPage.SupportsLanguageSwitching = false; |
||||
return true; |
||||
} |
||||
} |
||||
} |
@ -1,98 +0,0 @@
@@ -1,98 +0,0 @@
|
||||
// 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
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.ComponentModel.Composition; |
||||
using System.IO; |
||||
using System.Threading.Tasks; |
||||
|
||||
using ICSharpCode.AvalonEdit.Highlighting; |
||||
using ICSharpCode.Decompiler.Metadata; |
||||
using ICSharpCode.ILSpy.TextView; |
||||
using ICSharpCode.ILSpy.TreeNodes; |
||||
using ICSharpCode.ILSpy.ViewModels; |
||||
|
||||
namespace ICSharpCode.ILSpy.TreeNodes |
||||
{ |
||||
[Export(typeof(IResourceNodeFactory))] |
||||
sealed class TextResourceNodeFactory : IResourceNodeFactory |
||||
{ |
||||
private readonly static string[] txtFileExtensions = { ".txt", ".md" }; |
||||
|
||||
public ILSpyTreeNode CreateNode(Resource resource) |
||||
{ |
||||
Stream stream = resource.TryOpenStream(); |
||||
if (stream == null) |
||||
return null; |
||||
return CreateNode(resource.Name, stream); |
||||
} |
||||
|
||||
public ILSpyTreeNode CreateNode(string key, object data) |
||||
{ |
||||
if (!(data is Stream)) |
||||
return null; |
||||
foreach (string fileExt in txtFileExtensions) |
||||
{ |
||||
if (key.EndsWith(fileExt, StringComparison.OrdinalIgnoreCase)) |
||||
return new TextResourceEntryNode(key, (Stream)data); |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
sealed class TextResourceEntryNode : ResourceEntryNode |
||||
{ |
||||
string text; |
||||
|
||||
public TextResourceEntryNode(string key, Stream data) |
||||
: base(key, data) |
||||
{ |
||||
} |
||||
|
||||
public override object Icon => Images.Resource; |
||||
|
||||
public override bool View(TabPageModel tabPage) |
||||
{ |
||||
AvalonEditTextOutput output = new AvalonEditTextOutput(); |
||||
IHighlightingDefinition highlighting = null; |
||||
|
||||
tabPage.ShowTextView(textView => textView.RunWithCancellation( |
||||
token => Task.Factory.StartNew( |
||||
() => { |
||||
try { |
||||
// cache read text because stream will be closed after first read
|
||||
if (text == null) { |
||||
using (var reader = new StreamReader(Data)) { |
||||
text = reader.ReadToEnd(); |
||||
} |
||||
} |
||||
output.Write(text); |
||||
highlighting = null; |
||||
} |
||||
catch (Exception ex) { |
||||
output.Write(ex.ToString()); |
||||
} |
||||
return output; |
||||
}, token) |
||||
).Then(t => textView.ShowNode(t, this, highlighting)) |
||||
.HandleExceptions()); |
||||
tabPage.SupportsLanguageSwitching = false; |
||||
return true; |
||||
} |
||||
} |
||||
} |
@ -1,40 +0,0 @@
@@ -1,40 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Window |
||||
x:Class="ICSharpCode.ILSpy.NugetPackageBrowserDialog" |
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:controls="clr-namespace:ICSharpCode.ILSpy.Controls" |
||||
xmlns:properties="clr-namespace:ICSharpCode.ILSpy.Properties" |
||||
xmlns:treeview="http://icsharpcode.net/sharpdevelop/treeview" |
||||
Title="{x:Static properties:Resources.NugetPackageBrowser}" |
||||
Style="{DynamicResource DialogWindow}" |
||||
WindowStartupLocation="CenterOwner" |
||||
ResizeMode="CanResizeWithGrip" |
||||
MinWidth="200" |
||||
MinHeight="150" |
||||
Height="350" |
||||
Width="750"> |
||||
<Grid |
||||
Margin="12,8"> |
||||
<Grid.RowDefinitions> |
||||
<RowDefinition |
||||
Height="Auto" /> |
||||
<RowDefinition |
||||
Height="1*" /> |
||||
<RowDefinition |
||||
Height="Auto" /> |
||||
</Grid.RowDefinitions> |
||||
<TextBlock Text="{x:Static properties:Resources.SelectAssembliesOpen}" Margin="5" /> |
||||
<ListBox ItemsSource="{Binding Package.Entries}" Grid.Row="1"> |
||||
<ListBox.ItemTemplate> |
||||
<DataTemplate> |
||||
<CheckBox Content="{Binding Name}" IsChecked="{Binding IsSelected}" /> |
||||
</DataTemplate> |
||||
</ListBox.ItemTemplate> |
||||
</ListBox> |
||||
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right"> |
||||
<Button IsDefault="True" Margin="2,0" IsEnabled="{Binding HasSelection}" Name="okButton" Click="OKButton_Click" Content="{x:Static properties:Resources.Open}"/> |
||||
<Button IsCancel="True" Margin="2,0" Content="{x:Static properties:Resources.Cancel}"/> |
||||
</StackPanel> |
||||
</Grid> |
||||
</Window> |
@ -1,86 +0,0 @@
@@ -1,86 +0,0 @@
|
||||
// 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
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Collections.ObjectModel; |
||||
using System.ComponentModel; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Threading; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Threading; |
||||
|
||||
using ICSharpCode.ILSpy.Controls; |
||||
|
||||
namespace ICSharpCode.ILSpy |
||||
{ |
||||
/// <summary>
|
||||
/// Interaction logic for NugetPackageBrowserDialog.xaml
|
||||
/// </summary>
|
||||
public partial class NugetPackageBrowserDialog : Window, INotifyPropertyChanged |
||||
{ |
||||
public LoadedNugetPackage Package { get; } |
||||
|
||||
public NugetPackageBrowserDialog() |
||||
{ |
||||
InitializeComponent(); |
||||
} |
||||
|
||||
public NugetPackageBrowserDialog(LoadedNugetPackage package) |
||||
{ |
||||
InitializeComponent(); |
||||
this.Package = package; |
||||
this.Package.PropertyChanged += Package_PropertyChanged; |
||||
DataContext = this; |
||||
} |
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged; |
||||
|
||||
void Package_PropertyChanged(object sender, PropertyChangedEventArgs e) |
||||
{ |
||||
if (e.PropertyName == nameof(Package.SelectedEntries)) |
||||
{ |
||||
OnPropertyChanged(new PropertyChangedEventArgs("HasSelection")); |
||||
} |
||||
} |
||||
|
||||
void OKButton_Click(object sender, RoutedEventArgs e) |
||||
{ |
||||
this.DialogResult = true; |
||||
Close(); |
||||
} |
||||
|
||||
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) |
||||
{ |
||||
PropertyChanged?.Invoke(this, e); |
||||
} |
||||
|
||||
public Entry[] SelectedItems { |
||||
get { |
||||
return Package.SelectedEntries.ToArray(); |
||||
} |
||||
} |
||||
|
||||
public bool HasSelection { |
||||
get { return SelectedItems.Length > 0; } |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue