/* Copyright (C) 2014-2019 de4dot@gmail.com This file is part of dnSpy dnSpy is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. dnSpy is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with dnSpy. If not, see . */ using System; using System.Collections.Generic; using dnlib.DotNet; namespace dnSpy.Contracts.Documents { /// /// Manages all loaded documents (which are shown in the treeview) /// public interface IDsDocumentService { /// /// Call this to disable loading assemblies in the document list until the return value's /// method has been called. /// /// IDisposable DisableAssemblyLoad(); /// /// Notified when the collection gets changed /// event EventHandler? CollectionChanged; /// /// Gets all documents. Doesn't include any children. /// /// IDsDocument[] GetDocuments(); /// /// Adds a new instance if it hasn't already been added. Returns /// the input or the existing instance. /// /// Document /// IDsDocument GetOrAdd(IDsDocument document); /// /// Adds to the list, even if another instance has already been /// inserted. Returns the input. /// /// Document /// true to delay load /// Data passed to listeners /// IDsDocument ForceAdd(IDsDocument document, bool delayLoad, object? data); /// /// Creates a new instance or returns an existing one. null is /// returned if it couldn't be created. /// /// Document info /// New value of if the /// document gets created. /// IDsDocument? TryGetOrCreate(DsDocumentInfo info, bool isAutoLoaded = false); /// /// Tries to create a new without adding it to the list. null is /// returned if it couldn't be created. /// /// Document info /// IDsDocument? TryCreateOnly(DsDocumentInfo info); /// /// Resolves an assembly. Returns null if it couldn't be resolved. /// /// Assembly /// The module that needs to resolve an assembly or null /// IDsDocument? Resolve(IAssembly asm, ModuleDef? sourceModule); /// /// Returns an assembly or null if it's not in the list /// /// Assembly /// IDsDocument? FindAssembly(IAssembly assembly); /// /// Returns an assembly or null if it's not in the list /// /// Assembly /// Options /// IDsDocument? FindAssembly(IAssembly assembly, FindAssemblyOptions options); /// /// Returns an inserted instance or null /// /// Key /// IDsDocument? Find(IDsDocumentNameKey key); /// /// Removes a document /// /// Key of document to remove. See void Remove(IDsDocumentNameKey key); /// /// Removes documents /// /// Documents void Remove(IEnumerable documents); /// /// Clears all documents /// void Clear(); /// /// Can be called once to set a delegate instance that will execute code in a certain /// thread. can be called on any thread unless this method /// gets called. /// /// Action void SetDispatcher(Action action); /// /// Creates a /// /// Document info /// Filename /// true if it's a module, false if it's an assembly /// IDsDocument CreateDocument(DsDocumentInfo documentInfo, string filename, bool isModule = false); /// /// Creates a /// /// Document info /// File data /// Filename or null/empty string if it's unknown /// true if it's file layout, false if it's memory layout /// true if it's a module, false if it's an assembly /// IDsDocument CreateDocument(DsDocumentInfo documentInfo, byte[] fileData, string? filename, bool isFileLayout, bool isModule = false); /// /// The assembly resolver it uses /// IAssemblyResolver AssemblyResolver { get; } } /// /// Find assembly options /// public enum FindAssemblyOptions { /// /// No option is enabled /// None = 0, /// /// Compare assembly simple name /// Name = 0x00000001, /// /// Compare assembly version /// Version = 0x00000002, /// /// Compare assembly public key token /// PublicKeyToken = 0x00000004, /// /// Compare assembly culture /// Culture = 0x00000008, /// /// Compare content type /// ContentType = 0x00000010, /// /// Compare assembly simple name, version, public key token, locale and content type /// All = Name | Version | PublicKeyToken | Culture | ContentType, } }