Beispiel #1
0
 protected override void LoadChildren()
 {
     foreach (Resource r in module.Resources.OrderBy(m => m.Name))
     {
         this.Children.Add(ResourceTreeNode.Create(r));
     }
 }
Beispiel #2
0
 protected override void LoadChildren()
 {
     foreach (Resource r in module.Resources.OrderBy(m => m.Name, NaturalStringComparer.Instance))
     {
         this.Children.Add(ResourceTreeNode.Create(r));
     }
 }
Beispiel #3
0
 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, entry));
             }
             else
             {
                 yield return(ResourceTreeNode.Create(entry));
             }
         }
         else
         {
             yield return(ResourceTreeNode.Create(entry));
         }
     }
 }
Beispiel #4
0
 CreateAssemblyLinkedResourceCommand(ResourceListTreeNode rsrcListNode, ResourceTreeNode resTreeNode)
     : base(rsrcListNode, resTreeNode)
 {
 }
Beispiel #5
0
        static void Execute(ILSpyTreeNode[] nodes)
        {
            if (!CanExecute(nodes))
                return;

            var rsrcListNode = Utils.GetResourceListTreeNode(nodes);

            var module = ILSpyTreeNode.GetModule(nodes[0]);
            Debug.Assert(module != null);
            if (module == null)
                throw new InvalidOperationException();

            var dlg = new WF.OpenFileDialog {
                RestoreDirectory = true,
                Multiselect = true,
            };
            if (dlg.ShowDialog() != WF.DialogResult.OK)
                return;
            var fnames = dlg.FileNames;
            if (fnames.Length == 0)
                return;

            var newNodes = new ResourceTreeNode[fnames.Length];
            for (int i = 0; i < fnames.Length; i++) {
                var fn = fnames[i];
                try {
                    var rsrc = new EmbeddedResource(Path.GetFileName(fn), File.ReadAllBytes(fn), ManifestResourceAttributes.Public);
                    newNodes[i] = ResourceFactory.Create(module, rsrc);
                }
                catch (Exception ex) {
                    MainWindow.Instance.ShowMessageBox(string.Format("Error reading files: {0}", ex.Message));
                    return;
                }
            }

            UndoCommandManager.Instance.Add(new CreateFileResourceCommand(rsrcListNode, newNodes));
        }
Beispiel #6
0
 CreateFileResourceCommand(ResourceListTreeNode rsrcListNode, ResourceTreeNode[] nodes)
 {
     this.module = ILSpyTreeNode.GetModule(rsrcListNode);
     Debug.Assert(this.module != null);
     this.rsrcListNode = rsrcListNode;
     this.nodes = nodes;
 }
Beispiel #7
0
        ResourceSettingsCommand(ResourceTreeNode rsrcNode, ResourceOptions options)
        {
            this.rsrcNode = rsrcNode;
            this.newOptions = options;
            this.origOptions = new ResourceOptions(rsrcNode.Resource);

            this.origParentNode = (ILSpyTreeNode)rsrcNode.Parent;
            this.origParentChildIndex = this.origParentNode.Children.IndexOf(rsrcNode);
            Debug.Assert(this.origParentChildIndex >= 0);
            if (this.origParentChildIndex < 0)
                throw new InvalidOperationException();

            this.nameChanged = origOptions.Name != newOptions.Name;
        }
Beispiel #8
0
 public ModuleInfo(ResourceTreeNode node)
 {
     if (node == null)
         throw new InvalidOperationException();
     this.Node = node;
     var module = ILSpyTreeNode.GetModule(node);
     Debug.Assert(module != null);
     if (module == null)
         throw new InvalidOperationException();
     this.Module = module;
     this.Index = module.Resources.IndexOf(node.Resource);
     Debug.Assert(this.Index >= 0);
     if (this.Index < 0)
         throw new InvalidOperationException();
     this.Resource = node.Resource;
 }
Beispiel #9
0
            public void Restore(ResourceTreeNode[] nodes)
            {
                Debug.Assert(infos != null);
                if (infos == null)
                    throw new InvalidOperationException();
                Debug.Assert(infos.Length == nodes.Length);
                if (infos.Length != nodes.Length)
                    throw new InvalidOperationException();

                for (int i = infos.Length - 1; i >= 0; i--) {
                    var node = nodes[i];
                    var info = infos[i];
                    info.OwnerModule.Resources.Insert(info.Index, node.Resource);
                }

                infos = null;
            }
Beispiel #10
0
		void SearchResourceTreeNodes(DnSpyFile module, ResourceTreeNode resTreeNode) {
			var res = filter.GetFilterResult(resTreeNode);
			if (res.FilterResult == FilterResult.Hidden)
				return;

			if (res.IsMatch && (IsMatch(resTreeNode.Name, resTreeNode) || IsMatch(resTreeNode.GetStringContents(), null))) {
				onMatch(new SearchResult {
					Language = language,
					Object = resTreeNode,
					NameObject = resTreeNode,
					TypeImageInfo = GetImage(resTreeNode.IconName),
					LocationObject = module.ModuleDef,
					LocationImageInfo = GetImage("AssemblyModule"),
					DnSpyFile = module,
				});
			}

			res = filter.GetFilterResult((ResourceElementTreeNode)null);
			if (res.FilterResult == FilterResult.Hidden)
				return;

			var resNodes = new List<ResourceElementTreeNode>();
			App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => {
				resTreeNode.EnsureChildrenFiltered();
				resNodes.AddRange(resTreeNode.Children.Cast<ResourceElementTreeNode>());
			}));

			foreach (var resElNode in resNodes)
				SearchResourceElementTreeNode(module, resTreeNode, resElNode);
		}
		public virtual TreeViewNodeFilterResult GetFilterResult(ResourceTreeNode node) {
			return new TreeViewNodeFilterResult(FilterResult.Hidden, false);
		}
Beispiel #12
0
 protected CreateResourceTreeNodeCommand(ResourceListTreeNode rsrcListNode, ResourceTreeNode resTreeNode)
 {
     this.module = ILSpyTreeNode.GetModule(rsrcListNode);
     Debug.Assert(this.module != null);
     this.rsrcListNode = rsrcListNode;
     this.resTreeNode = resTreeNode;
 }
 public override TreeViewNodeFilterResult GetFilterResult(ResourceTreeNode node)
 {
     if (showPublicApi() && !ResourceTreeNode.IsPublicAPIInternal(node.Resource))
         return new TreeViewNodeFilterResult(FilterResult.Hidden, false);
     return base.GetFilterResult(node);
 }
Beispiel #14
0
		public virtual TreeViewNodeFilterResult GetFilterResult(ResourceTreeNode node) {
			return new TreeViewNodeFilterResult();
		}
Beispiel #15
0
		void SearchResourceElementTreeNode(DnSpyFile module, ResourceTreeNode resTreeNode, ResourceElementTreeNode resElNode) {
			var res = filter.GetFilterResult(resElNode);
			if (res.FilterResult == FilterResult.Hidden)
				return;

			if (res.IsMatch) {
				bool m = IsMatch(resElNode.Name, resElNode);
				if (!m) {
					var builtin = resElNode.ResourceElement.ResourceData as BuiltInResourceData;
					if (builtin != null) {
						var val = builtin.Data;
						if (builtin.Code == ResourceTypeCode.TimeSpan)
							val = ((TimeSpan)val).Ticks;
						m = IsMatch(val as string, val);
					}
				}
				if (!m)
					m = IsMatch(resElNode.GetStringContents(), null);
				if (m) {
					onMatch(new SearchResult {
						Language = language,
						Object = resElNode,
						NameObject = resElNode,
						TypeImageInfo = GetImage(resElNode.IconName),
						LocationObject = resTreeNode,
						LocationImageInfo = GetImage(resTreeNode.IconName),
						DnSpyFile = module,
					});
				}
			}
		}
Beispiel #16
0
 CreateMultiFileResourceCommand(ResourceListTreeNode rsrcListNode, ResourceTreeNode resTreeNode)
     : base(rsrcListNode, resTreeNode)
 {
 }
Beispiel #17
0
            public void Delete(ResourceTreeNode[] nodes, ILSpyTreeNode[] parents)
            {
                Debug.Assert(infos == null);
                if (infos != null)
                    throw new InvalidOperationException();

                infos = new ModelInfo[nodes.Length];

                for (int i = 0; i < infos.Length; i++) {
                    var node = nodes[i];

                    var module = ILSpyTreeNode.GetModule(parents[i]);
                    Debug.Assert(module != null);
                    if (module == null)
                        throw new InvalidOperationException();
                    var info = new ModelInfo(module, node.Resource);
                    infos[i] = info;
                    info.OwnerModule.Resources.RemoveAt(info.Index);
                }
            }
Beispiel #18
0
 DeleteResourceCommand(ResourceTreeNode[] rsrcNodes)
 {
     this.nodes = new DeletableNodes<ResourceTreeNode>(rsrcNodes);
 }
		public override TreeViewNodeFilterResult GetFilterResult(ResourceTreeNode node) {
			var visibleFlags = VisibleMembersFlags.Resource | VisibleMembersFlags.ResourceElement;
			bool isMatch = (flags & VisibleMembersFlags.Resource) != 0;
			if ((flags & visibleFlags) == 0)
				return new TreeViewNodeFilterResult(FilterResult.Hidden, isMatch);
			if (isMatch)
				return new TreeViewNodeFilterResult(FilterResult.Match, isMatch);
			return new TreeViewNodeFilterResult(FilterResult.Recurse, isMatch);
		}