Esempio n. 1
0
 /// <summary>
 /// Gets a <see cref="IResourceDataProvider"/> if <paramref name="node"/> is a resource node, else returns null
 /// </summary>
 /// <param name="node">Node</param>
 /// <returns></returns>
 public static IResourceDataProvider?GetResourceDataProvider(DocumentTreeNodeData node)
 {
     if (node is IResourceDataProvider provider)
     {
         return(provider);
     }
     if (ResourceNode.GetResource(node) is Resource resource)
     {
         return(new ResourceNode_ResourceDataProvider(node, resource));
     }
     if (ResourceElementNode.GetResourceElement(node) is ResourceElement resourceElement)
     {
         return(new ResourceElementNode_ResourceDataProvider(node, resourceElement));
     }
     return(null);
 }
		public override DocumentTreeNodeFilterResult GetResult(ResourceElementNode node) {
			bool isMatch = (flags & VisibleMembersFlags.ResourceElement) != 0;
			if (!isMatch)
				return new DocumentTreeNodeFilterResult(FilterType.Hide, isMatch);
			return new DocumentTreeNodeFilterResult(FilterType.Visible, isMatch);
		}
Esempio n. 3
0
 ModuleDefMD?GetModuleOffset(out FileOffset fileOffset) =>
 ResourceElementNode.GetModuleOffset(node, resourceElement, out fileOffset);
Esempio n. 4
0
 public IEnumerable <ResourceData> GetResourceData(ResourceDataType type) =>
 ResourceElementNode.GetSerializedData(resourceElement);
Esempio n. 5
0
		DeleteResourceElementCommand(ResourceElementNode[] rsrcNodes) {
			nodes = new DeletableNodes<ResourceElementNode>(rsrcNodes);
		}
		public virtual DocumentTreeNodeFilterResult GetResult(ResourceElementNode node) => new DocumentTreeNodeFilterResult(FilterType.Hide, false);
Esempio n. 7
0
		ImageResourceElementSettingsCommand(ResourceElementNode rsrcElNode, ResourceElementOptions options)
			: base(rsrcElNode, options) {
		}
Esempio n. 8
0
		protected CreateResourceElementCommandBase(ResourceElementSetNode rsrcSetNode, ResourceElementNode[] nodes) {
			module = rsrcSetNode.GetModule();
			Debug.Assert(module != null);
			this.rsrcSetNode = rsrcSetNode;
			this.nodes = nodes;
			resource = rsrcSetNode.Resource;
			resourceIndex = module.Resources.IndexOf(resource);
			Debug.Assert(resourceIndex >= 0);
			if (resourceIndex < 0)
				throw new InvalidOperationException();
		}
Esempio n. 9
0
		CreateResourceElementCommand(ResourceElementSetNode rsrcSetNode, ResourceElementNode node)
			: base(rsrcSetNode, new[] { node }) {
		}
Esempio n. 10
0
		protected ResourceElementSettingsBaseCommand(ResourceElementNode rsrcElNode, ResourceElementOptions options) {
			rsrcSetNode = (ResourceElementSetNode)rsrcElNode.TreeNode.Parent.Data;
			this.rsrcElNode = rsrcElNode;
			newOptions = options.Create();
			origOptions = rsrcElNode.ResourceElement;

			module = rsrcSetNode.GetModule();
			Debug.Assert(module != null);
			resource = rsrcSetNode.Resource;
			resourceIndex = module.Resources.IndexOf(resource);
			Debug.Assert(resourceIndex >= 0);
			if (resourceIndex < 0)
				throw new InvalidOperationException();

			origParentChildIndex = rsrcSetNode.TreeNode.Children.IndexOf(rsrcElNode.TreeNode);
			Debug.Assert(origParentChildIndex >= 0);
			if (origParentChildIndex < 0)
				throw new InvalidOperationException();

			nameChanged = origOptions.Name != newOptions.Name;
		}
Esempio n. 11
0
		CreateStreamResourceElementCommand(ResourceElementSetNode rsrcSetNode, ResourceElementNode[] nodes)
			: base(rsrcSetNode, nodes) {
		}
Esempio n. 12
0
		CreateByteArrayResourceElementCommand(ResourceElementSetNode rsrcSetNode, ResourceElementNode[] nodes)
			: base(rsrcSetNode, nodes) {
		}
Esempio n. 13
0
		internal static void Execute(Lazy<IUndoCommandService> undoCommandService, IAppService appService, IResourceNodeFactory resourceNodeFactory, DocumentTreeNodeData[] nodes, ResourceTypeCode typeCode, Func<ResourceElementSetNode, ResourceElementNode[], IUndoCommand> createCommand) {
			var rsrcSetNode = nodes[0] as ResourceElementSetNode;
			if (rsrcSetNode == null)
				rsrcSetNode = nodes[0].TreeNode.Parent.Data as ResourceElementSetNode;
			Debug.Assert(rsrcSetNode != null);

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

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

			var newNodes = new ResourceElementNode[fnames.Length];
			var treeView = appService.DocumentTreeView.TreeView;
			var treeNodeGroup = appService.DocumentTreeView.DocumentTreeNodeGroups.GetGroup(DocumentTreeNodeGroupType.ResourceElementTreeNodeGroup);
			for (int i = 0; i < fnames.Length; i++) {
				var fn = fnames[i];
				try {
					var rsrcElem = new ResourceElement {
						Name = Path.GetFileName(fn),
						ResourceData = new BuiltInResourceData(typeCode, File.ReadAllBytes(fn)),
					};
					newNodes[i] = (ResourceElementNode)treeView.Create(resourceNodeFactory.Create(module, rsrcElem, treeNodeGroup)).Data;
				}
				catch (Exception ex) {
					MsgBox.Instance.Show(string.Format(dnSpy_AsmEditor_Resources.Error_ReadingFiles, ex.Message));
					return;
				}
			}

			undoCommandService.Value.Add(createCommand(rsrcSetNode, newNodes.ToArray()));
			appService.DocumentTabService.FollowReference(newNodes[0]);
		}
Esempio n. 14
0
		void SearchResourceElementTreeNode(IDsDocument module, ResourceNode resTreeNode, ResourceElementNode resElNode) {
			var res = options.Filter.GetResult(resElNode);
			if (res.FilterType == FilterType.Hide)
				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(ToString(resElNode), null);
				if (m) {
					options.OnMatch(new SearchResult {
						Context = options.Context,
						Object = resElNode,
						NameObject = resElNode,
						ObjectImageReference = resElNode.Icon,
						LocationObject = resTreeNode,
						LocationImageReference = resTreeNode.Icon,
						Document = module,
					});
				}
			}
		}
Esempio n. 15
0
		SerializedImageListStreamerResourceElementSettingsCommand(ResourceElementNode rsrcElNode, ResourceElementOptions options)
			: base(rsrcElNode, options) {
		}
		public virtual DocumentTreeNodeFilterResult GetResult(ResourceElementNode node) => new DocumentTreeNodeFilterResult();
Esempio n. 17
0
		void Decompile(ResourceElementNode node) =>
			node.WriteShort(output, decompiler, decompiler.Settings.GetBoolean(DecompilerOptionConstants.ShowTokenAndRvaComments_GUID));