Ejemplo n.º 1
0
        IDsDocument?TryRuntimeAssemblyResolvers(IAssembly assembly, ModuleDef?sourceModule)
        {
            foreach (var lz in runtimeAsmResolvers)
            {
                var result = lz.Value.Resolve(assembly, sourceModule);
                if (!result.IsDefault)
                {
                    if (!string2.IsNullOrEmpty(result.Filename))
                    {
                        var file = documentService.Find(FilenameKey.CreateFullPath(result.Filename), checkTempCache: true);
                        if (file is not null)
                        {
                            return(file);
                        }
                    }

                    if (result.GetFileData is not null)
                    {
                        return(documentService.TryGetOrCreateInternal(DsDocumentInfo.CreateInMemory(result.GetFileData, result.Filename), true, true));
                    }
                    if (!string2.IsNullOrEmpty(result.Filename))
                    {
                        return(documentService.TryGetOrCreateInternal(DsDocumentInfo.CreateDocument(result.Filename), true, true));
                    }

                    Debug.Fail("Shouldn't be reached");
                    return(null);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
		public void OnNewArgs(IAppCommandLineArgs args) {
			if (!SelectMember(args)) {
				var mod = GetLoadedFiles(args).FirstOrDefault();
				if (mod != null)
					fileTabManager.FollowReference((object)mod.Assembly ?? mod);
				else {
					foreach (var filename in args.Filenames) {
						var key = new FilenameKey(filename);
						var file = fileTabManager.FileTreeView.FileManager.GetFiles().FirstOrDefault(a => a.Key.Equals(key));
						if (file != null) {
							fileTabManager.FollowReference(file);
							break;
						}
					}
				}
			}
		}
Ejemplo n.º 3
0
		public void OnNewArgs(IAppCommandLineArgs args) {
			if (!SelectMember(args)) {
				var mod = GetLoadedFiles(args).FirstOrDefault();
				if (mod != null)
					documentTabService.FollowReference((object)mod.Assembly ?? mod);
				else {
					foreach (var filename in args.Filenames) {
						var key = new FilenameKey(filename);
						var document = documentTabService.DocumentTreeView.DocumentService.GetDocuments().FirstOrDefault(a => a.Key.Equals(key));
						if (document != null) {
							documentTabService.FollowReference(document);
							break;
						}
					}
				}
			}
		}
Ejemplo n.º 4
0
        void OnDropFiles(int index, string[] filenames)
        {
            if (!context.CanDragAndDrop)
            {
                return;
            }

            var origFilenames = filenames;
            var existingFiles = new HashSet <string>(FileManager.GetFiles().Select(a => a.Filename ?? string.Empty), StringComparer.OrdinalIgnoreCase);

            filenames = filenames.Where(a => File.Exists(a) && !existingFiles.Contains(a)).Distinct(StringComparer.OrdinalIgnoreCase).ToArray();
            ITreeNodeData newSelectedNode = null;

            for (int i = 0, j = 0; i < filenames.Length; i++)
            {
                var file = FileManager.TryCreateOnly(DnSpyFileInfo.CreateFile(filenames[i]));
                if (file == null)
                {
                    continue;
                }
                var node = CreateNode(null, file);
                FileManager.ForceAdd(file, false, new AddFileInfo(node, index + j++));
                if (newSelectedNode == null)
                {
                    newSelectedNode = node;
                }
            }
            if (newSelectedNode == null)
            {
                var filename = origFilenames.FirstOrDefault(a => File.Exists(a));
                if (filename != null)
                {
                    var key  = new FilenameKey(filename);
                    var file = FileManager.GetFiles().FirstOrDefault(a => key.Equals(a.Key));
                    newSelectedNode = FindNode(file);
                }
            }
            if (newSelectedNode != null)
            {
                TreeView.SelectItems(new[] { newSelectedNode });
            }
        }
Ejemplo n.º 5
0
        void OnDropFiles(int index, string[] filenames)
        {
            if (!context.CanDragAndDrop)
            {
                return;
            }

            var origFilenames = filenames;
            var existingFiles = new HashSet <string>(DocumentService.GetDocuments().Select(a => a.Filename ?? string.Empty), StringComparer.OrdinalIgnoreCase);

            filenames = filenames.Where(a => File.Exists(a) && !existingFiles.Contains(a)).Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(a => Path.GetFileNameWithoutExtension(a), StringComparer.CurrentCultureIgnoreCase).ToArray();
            ITreeNodeData newSelectedNode = null;

            for (int i = 0, j = 0; i < filenames.Length; i++)
            {
                var document = DocumentService.TryCreateOnly(DsDocumentInfo.CreateDocument(filenames[i]));
                if (document == null)
                {
                    continue;
                }
                var node = CreateNode(null, document);
                DocumentService.ForceAdd(document, false, new AddDocumentInfo(node, index + j++));
                if (newSelectedNode == null)
                {
                    newSelectedNode = node;
                }
            }
            if (newSelectedNode == null)
            {
                var filename = origFilenames.FirstOrDefault(a => File.Exists(a));
                if (filename != null)
                {
                    var key      = new FilenameKey(filename);
                    var document = DocumentService.GetDocuments().FirstOrDefault(a => key.Equals(a.Key));
                    newSelectedNode = FindNode(document);
                }
            }
            if (newSelectedNode != null)
            {
                TreeView.SelectItems(new[] { newSelectedNode });
            }
        }
Ejemplo n.º 6
0
 IEnumerable <ModuleDef> GetLoadedFiles(IAppCommandLineArgs args)
 {
     foreach (var filename in args.Filenames)
     {
         var key  = new FilenameKey(filename);
         var file = fileTabManager.FileTreeView.FileManager.GetFiles().FirstOrDefault(a => key.Equals(a.Key));
         if (file == null || file.ModuleDef == null)
         {
             continue;
         }
         if (file.AssemblyDef != null)
         {
             foreach (var mod in file.AssemblyDef.Modules)
             {
                 yield return(mod);
             }
         }
         else
         {
             yield return(file.ModuleDef);
         }
     }
 }
Ejemplo n.º 7
0
 IEnumerable <ModuleDef> GetLoadedFiles(IAppCommandLineArgs args)
 {
     foreach (var filename in args.Filenames)
     {
         var key      = new FilenameKey(filename);
         var document = documentTabService.DocumentTreeView.DocumentService.GetDocuments().FirstOrDefault(a => key.Equals(a.Key));
         if (document?.ModuleDef == null)
         {
             continue;
         }
         if (document.AssemblyDef != null)
         {
             foreach (var mod in document.AssemblyDef.Modules)
             {
                 yield return(mod);
             }
         }
         else
         {
             yield return(document.ModuleDef);
         }
     }
 }
Ejemplo n.º 8
0
 public void OnNewArgs(IAppCommandLineArgs args)
 {
     if (!SelectMember(args))
     {
         var mod = GetLoadedFiles(args).FirstOrDefault();
         if (mod != null)
         {
             fileTabManager.FollowReference((object)mod.Assembly ?? mod);
         }
         else
         {
             foreach (var filename in args.Filenames)
             {
                 var key  = new FilenameKey(filename);
                 var file = fileTabManager.FileTreeView.FileManager.GetFiles().FirstOrDefault(a => a.Key.Equals(key));
                 if (file != null)
                 {
                     fileTabManager.FollowReference(file);
                     break;
                 }
             }
         }
     }
 }
Ejemplo n.º 9
0
 public void OnNewArgs(IAppCommandLineArgs args)
 {
     if (!SelectMember(args))
     {
         var mod = GetLoadedFiles(args).FirstOrDefault();
         if (mod != null)
         {
             documentTabService.FollowReference((object)mod.Assembly ?? mod);
         }
         else
         {
             foreach (var filename in args.Filenames)
             {
                 var key      = new FilenameKey(filename);
                 var document = documentTabService.DocumentTreeView.DocumentService.GetDocuments().FirstOrDefault(a => a.Key.Equals(key));
                 if (document != null)
                 {
                     documentTabService.FollowReference(document);
                     break;
                 }
             }
         }
     }
 }
Ejemplo n.º 10
0
 IDsDocument TryFindFromDir2(string filename) => documentService.Find(FilenameKey.CreateFullPath(filename), checkTempCache: true);
Ejemplo n.º 11
0
		internal DnSpyFile GetOrCreate(string file, bool canAdd, bool isAutoLoaded, bool delayLoad) {
			var key = new FilenameKey(file);

			lock (lockObj) {
				var existingFile = FindByKey_NoLock(key);
				if (existingFile != null)
					return existingFile;

				var newFile = CreateDnSpyFile(file, options.UseMemoryMappedIO, options.UseDebugSymbols);
				newFile.IsAutoLoaded = isAutoLoaded;
				return ForceAddFileToList_NoLock(newFile, canAdd, delayLoad, -1, true);
			}
		}
Ejemplo n.º 12
0
 IEnumerable<ModuleDef> GetLoadedFiles(IAppCommandLineArgs args)
 {
     foreach (var filename in args.Filenames) {
         var key = new FilenameKey(filename);
         var file = fileTabManager.FileTreeView.FileManager.GetFiles().FirstOrDefault(a => key.Equals(a.Key));
         if (file == null || file.ModuleDef == null)
             continue;
         if (file.AssemblyDef != null) {
             foreach (var mod in file.AssemblyDef.Modules)
                 yield return mod;
         }
         else
             yield return file.ModuleDef;
     }
 }
Ejemplo n.º 13
0
        void OnDropFiles(int index, string[] filenames)
        {
            if (!context.CanDragAndDrop)
            {
                return;
            }

            var origFilenames = filenames;
            var existingFiles = new HashSet <string>(DocumentService.GetDocuments().Select(a => a.Filename ?? string.Empty), StringComparer.OrdinalIgnoreCase);

            filenames = filenames.Where(a => File.Exists(a) && !existingFiles.Contains(a)).Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(a => Path.GetFileNameWithoutExtension(a), StringComparer.CurrentCultureIgnoreCase).ToArray();
            TreeNodeData newSelectedNode = null;

            for (int i = 0, j = 0; i < filenames.Length; i++)
            {
                var document = DocumentService.TryCreateOnly(DsDocumentInfo.CreateDocument(filenames[i]));
                if (document == null)
                {
                    continue;
                }

                if (filenames.Length > 1)
                {
                    switch (documentTreeViewSettings.FilterDraggedItems)
                    {
                    case DocumentFilterType.All:
                        break;

                    case DocumentFilterType.DotNetOnly:
                        if (!(document is IDsDotNetDocument))
                        {
                            continue;
                        }
                        break;

                    case DocumentFilterType.AllSupported:
                        if (document is DsUnknownDocument)
                        {
                            continue;
                        }
                        break;

                    default:
                        Debug.Fail("Shouldn't be here");
                        break;
                    }
                }

                var node = CreateNode(null, document);
                DocumentService.ForceAdd(document, false, new AddDocumentInfo(node, index + j++));
                if (newSelectedNode == null)
                {
                    newSelectedNode = node;
                }

                existingFiles.Add(document.Filename);
            }

            if (filenames.Any() && !filenames.Any(f => existingFiles.Contains(f)))
            {
                MsgBox.Instance.Show(dnSpy_Resources.AssemblyExplorer_AllFilesFilteredOut);
            }

            if (newSelectedNode == null)
            {
                var filename = origFilenames.FirstOrDefault(a => File.Exists(a));
                if (filename != null)
                {
                    var key      = new FilenameKey(filename);
                    var document = DocumentService.GetDocuments().FirstOrDefault(a => key.Equals(a.Key));
                    newSelectedNode = FindNode(document);
                }
            }
            if (newSelectedNode != null)
            {
                TreeView.SelectItems(new[] { newSelectedNode });
            }
        }
Ejemplo n.º 14
0
		IEnumerable<ModuleDef> GetLoadedFiles(IAppCommandLineArgs args) {
			foreach (var filename in args.Filenames) {
				var key = new FilenameKey(filename);
				var document = documentTabService.DocumentTreeView.DocumentService.GetDocuments().FirstOrDefault(a => key.Equals(a.Key));
				if (document?.ModuleDef == null)
					continue;
				if (document.AssemblyDef != null) {
					foreach (var mod in document.AssemblyDef.Modules)
						yield return mod;
				}
				else
					yield return document.ModuleDef;
			}
		}