public static void WriteOffsetComment(this ITextOutput output, IResourceNode node) { if (!DecompilerSettingsPanel.CurrentDecompilerSettings.ShowTokenAndRvaComments) return; ulong fo = node.FileOffset; if (fo == 0) return; var mod = ILSpyTreeNode.GetModule((SharpTreeNode)node); var filename = mod == null ? null : mod.Location; output.WriteReference(string.Format("0x{0:X8}", fo), new AddressReference(filename, false, fo, node.Length), TextTokenType.Comment); output.Write(": ", TextTokenType.Comment); }
private GridResourceNode(IResourceNode node) { if (node == null) throw new ArgumentNullException("node"); this.Source = node; this.Offense = node.Offense; this.Defense = node.Defense; this.Exchange = node.Exchange; Id = new UniqueIdentifier(IdentityType.ResourceNode, new[] { this.Offense, this.Defense, this.Exchange }); this.RenewableResources = new List<Resource>(); this.RenewableResources.AddRange(node.RenewableResources); this.Reservoir = new List<Resource>(); this.RefreshReservoir(); }
public static void Save(IResourceNode[] nodes, bool useSubDirs, ResourceDataType resourceDataType) { if (nodes == null) return; var files = GetFiles(GetResourceData(nodes, resourceDataType), useSubDirs).ToArray(); if (files.Length == 0) return; var data = new ProgressVM(MainWindow.Instance.Dispatcher, new ResourceSaver(files)); var win = new ProgressDlg(); win.DataContext = data; win.Owner = MainWindow.Instance; win.Title = files.Length == 1 ? "Save Resource" : "Save Resources"; var res = win.ShowDialog(); if (res != true) return; if (!data.WasError) return; MainWindow.Instance.ShowMessageBox(string.Format("An error occurred:\n\n{0}", data.ErrorMessage)); }
public static void Save(IResourceNode[] nodes, bool useSubDirs, ResourceDataType resourceDataType) { if (nodes == null) return; var infos = GetResourceData(nodes, resourceDataType); if (infos.Length == 1) { var info = infos[0]; var name = ResourceUtils.FixFileNamePart(ResourceUtils.GetFileName(info.Name)); var dlg = new WF.SaveFileDialog { RestoreDirectory = true, ValidateNames = true, FileName = name, }; var ext = Path.GetExtension(name); dlg.DefaultExt = string.IsNullOrEmpty(ext) ? string.Empty : ext.Substring(1); if (dlg.ShowDialog() != WF.DialogResult.OK) return; var ex = ResourceUtils.SaveFile(dlg.FileName, info.GetStream()); if (ex != null) MainWindow.Instance.ShowMessageBox(string.Format("Could not save '{0}'\nERROR: {1}", dlg.FileName, ex.Message)); } else { var dlg = new WF.FolderBrowserDialog(); if (dlg.ShowDialog() != WF.DialogResult.OK) return; string baseDir = dlg.SelectedPath; foreach (var info in infos) { var name = ResourceUtils.GetCleanedPath(info.Name, useSubDirs); var pathName = Path.Combine(baseDir, name); var ex = ResourceUtils.SaveFile(pathName, info.GetStream()); if (ex != null) { MainWindow.Instance.ShowMessageBox(string.Format("Could not save '{0}'\nERROR: {1}", pathName, ex.Message)); break; } } } }
protected ResourceData[] GetResourceData(IResourceNode[] nodes) { return SaveResources.GetResourceData(nodes, resourceDataType); }
protected CreateResourceTreeNodeCommand(IResourcesFolderNode rsrcListNode, IResourceNode resTreeNode) { this.module = rsrcListNode.GetModule(); Debug.Assert(this.module != null); this.rsrcListNode = rsrcListNode; this.resTreeNode = resTreeNode; }
static void Execute(Lazy<IUndoCommandManager> undoCommandManager, IAppWindow appWindow, IResourceNodeFactory resourceNodeFactory, IFileTreeNodeData[] nodes) { if (!CanExecute(nodes)) return; var rsrcListNode = ResUtils.GetResourceListTreeNode(nodes); var module = nodes[0].GetModule(); 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 IResourceNode[fnames.Length]; var treeView = appWindow.FileTreeView.TreeView; var treeNodeGroup = appWindow.FileTreeView.FileTreeNodeGroups.GetGroup(FileTreeNodeGroupType.ResourceTreeNodeGroup); 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] = (IResourceNode)treeView.Create(resourceNodeFactory.Create(module, rsrc, treeNodeGroup)).Data; } catch (Exception ex) { Shared.App.MsgBox.Instance.Show(string.Format(dnSpy_AsmEditor_Resources.Error_ReadingFiles, ex.Message)); return; } } undoCommandManager.Value.Add(new CreateFileResourceCommand(rsrcListNode, newNodes)); appWindow.FileTabManager.FollowReference(newNodes[0]); }
public void Restore(IResourceNode[] 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; }
ResourceSettingsCommand(IResourceNode rsrcNode, ResourceOptions options) { this.rsrcNode = rsrcNode; this.newOptions = options; this.origOptions = new ResourceOptions(rsrcNode.Resource); this.origParentNode = (IFileTreeNodeData)rsrcNode.TreeNode.Parent.Data; this.origParentChildIndex = this.origParentNode.TreeNode.Children.IndexOf(rsrcNode.TreeNode); Debug.Assert(this.origParentChildIndex >= 0); if (this.origParentChildIndex < 0) throw new InvalidOperationException(); this.nameChanged = origOptions.Name != newOptions.Name; }
public virtual FileTreeNodeFilterResult GetResult(IResourceNode node) { return new FileTreeNodeFilterResult(); }
private ColorViewModel GetColorResource(IResourceNode node, string key) { return(((Color)node.FindResource(key)).FromColor()); }
/// <summary> /// 确认修改 /// </summary> /// <param name="_rModelNode"></param> /// <param name="_rImgNode"></param> /// <param name="_strTag"></param> /// <param name="_strShowName"></param> public void OnAffirm(IResourceNode _rModelNode, IResourceNode _rImgNode, string _strTag, string _strShowName) { m_bNeedUpdate = true; string strData = m_infoJson.ReadString("data", JsonUtils.EmptyJsonArray.ToJson()); JsonData jdData = JsonMapper.ToObject(strData); JsonData dataJD = jdData; JsonData jdNewData = JsonUtils.EmptyJsonArray; if (dataJD.Count < 1) { JsonData jd = JsonUtils.EmptyJsonObject; dataJD.Add(jd); } JsonData jdFbx = dataJD[0]; if (_rImgNode != null) { m_infoJson["picName"] = _rImgNode.GetName(); m_infoJson["picCrc"] = _rImgNode.GetCrc(); m_strImg = _rImgNode.GetName(); m_strImgCrc = _rImgNode.GetCrc(); m_rNewImg = _rImgNode; } if (_rModelNode != null) { jdFbx["fileName"] = _rModelNode.GetName(); jdFbx["fileCrc"] = _rModelNode.GetCrc(); jdFbx["type"] = _rModelNode.GetResType().ToString(); m_strModelCrc = _rModelNode.GetCrc(); m_strModelName = _rModelNode.GetName(); m_strModelType = _rModelNode.GetResType().ToString(); m_rNewModel = _rModelNode; if (m_bIsNew) { m_strCode = Utils.GetFilePrefix(m_strModelName); m_infoJson["code"] = m_strCode; m_infoJson["wallLength"] = "0"; } } if (!_strShowName.Equals(m_strShowName)) { m_infoJson["name"] = _strShowName; m_strShowName = _strShowName; } if (!_strTag.Equals(m_strTag)) { m_infoJson["tag"] = _strTag; m_strTag = _strTag; } jdFbx["children"] = JsonUtils.EmptyJsonArray; jdNewData.Add(jdFbx); m_infoJson["data"] = jdNewData.ToJson(); Debug.LogWarning("NewComp:" + m_infoJson.ToJson()); }
public virtual DocumentTreeNodeFilterResult GetResult(IResourceNode node) => new DocumentTreeNodeFilterResult(FilterType.Hide, false);
public virtual FileTreeNodeFilterResult GetResult(IResourceNode node) { return this.filter.GetResult(node); }
/// <summary> /// Create the first layer after the root layer (based on the root node) /// </summary> /// <returns>The next layer.</returns> /// <param name="rootNode">Root node.</param> public NodeLayer CreateNextLayer(IResourceNode rootNode) { return(CreateNextLayer(new[] { rootNode })); }
void SearchResourceElementTreeNode(IDnSpyFile module, IResourceNode resTreeNode, IResourceElementNode 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, DnSpyFile = module, }); } } }
private ThicknessViewModel GetThicknessResource(IResourceNode node, string key) { return(((Thickness)node.FindResource(key)).FromThickness()); }
public ResourceObservable(IResourceNode target, object key) { _target = target; _key = key; }
private double GetDoubleResource(IResourceNode node, string key) { return((double)node.FindResource(key)); }
public static ResourceData[] GetResourceData(IResourceNode[] nodes, ResourceDataType resourceDataType) { return nodes.SelectMany(a => a.GetResourceData(resourceDataType)).ToArray(); }
public virtual DocumentTreeNodeFilterResult GetResult(IResourceNode node) => new DocumentTreeNodeFilterResult();
CreateFileLinkedResourceCommand(IResourcesFolderNode rsrcListNode, IResourceNode resTreeNode) : base(rsrcListNode, resTreeNode) { }
public void addResourceNode(IResourceNode newNode, Vector2Int pos) { this.resourceMap.addNode(newNode, pos); }
public void Delete(IResourceNode[] nodes, IFileTreeNodeData[] 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 = parents[i].GetModule(); 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); } }
public Styles(IResourceNode parent) : this() { _parent = parent; }
DeleteResourceCommand(IResourceNode[] rsrcNodes) { this.nodes = new DeletableNodes<IResourceNode>(rsrcNodes); }
private void CreateChildren(GraphNode graphNode, object constraints) { string graphNodeKeyStr = PrintRKTag(graphNode.OriginalKey, graphNode.ExtensionTag); int i, j, k, count, foundIndex; GraphNode childNode; GraphConnectionRef childConnection; IResourceConnection child; IResourceKey childKey; List <IResourceConnection> children = graphNode.Core.SlurpConnections(constraints); count = (children == null) ? 0 : children.Count; Diagnostics.Log("Resolving " + count + " RK Refs from " + graphNodeKeyStr); for (i = 0; i < count; i++) { child = children[i]; childKey = child.OriginalChildKey; childConnection = new GraphConnectionRef(this, graphNode, child); childNode = null; // Try to find an already existing child node in the lookup table. foundIndex = -1; for (j = 0; j < this.nodeLookupTable.Count && foundIndex < 0; j++) { if (this.nodeLookupTable[j].OriginalKey.Equals(childKey)) { foundIndex = j; } } if (foundIndex >= 0 && !child.AlwaysCreateChild) { childNode = this.nodeLookupTable[foundIndex]; } else { RFileType fileType = RFileType.Game; SpecificResource sr = null; IResourceNode childCore = null; if (child.ChildDataActions < ResourceDataActions.Find) { childCore = child.CreateChild(null, constraints); } else { List <PathPackageTuple> searchList;// = child.IsChildDDS ? FileTable.DDSImages : //child.IsChildThum ? FileTable.Thumbnails : FileTable.GameContent; if (child.IsChildDDS) { fileType = RFileType.DDS; searchList = FileTable.DDSImages; } else if (child.IsChildThum) { fileType = RFileType.Thum; searchList = FileTable.Thumbnails; } else { fileType = RFileType.Game; searchList = FileTable.GameContent; } sr = new SpecificResource(searchList, child.OriginalChildKey); if (sr.ResourceIndexEntry == null || sr.Resource == null) { Diagnostics.Log("Unresolved RK Ref:" + PrintRKRef(childKey, child.AbsolutePath) + ((sr.Exception == null) ? "" : string.Concat(" Error:\r\n", sr.Exception.ToString()))); } else { childCore = child.CreateChild(sr.Resource, constraints); } } if (childCore == null) { Diagnostics.Log("CreateChild Failed:" + PrintRKRef(childKey, child.AbsolutePath)); } else { childNode = new GraphNode(this, childKey, childCore, sr == null ? null : sr.PathPackage, child.ChildDataActions, fileType); if (child.AlwaysCreateChild && foundIndex >= 0) { Diagnostics.Log("Dup Ref Node Added:" + PrintRKRef(childKey, child.AbsolutePath)); this.nodeDuplicates.Add(childNode); } else { Diagnostics.Log("New Ref Node Added:" + PrintRKRef(childKey, child.AbsolutePath)); this.nodeLookupTable.Add(childNode); } CreateChildren(childNode, constraints); } } if (childNode != null) { graphNode.ChildConnections.Add(childConnection); childConnection.Child = childNode; childNode.ParentConnections.Add(childConnection); } } IResourceIndexEntry kinKey; GraphConnectionKin kinConnection; IResourceKinHelper kinHelper; List <SpecificResource> kin; List <IResourceKinHelper> kinHelpers = graphNode.Core.CreateKinHelpers(constraints); count = (kinHelpers == null) ? 0 : kinHelpers.Count; Diagnostics.Log("Resolving " + count + " RK Kin types for " + graphNodeKeyStr); for (i = 0; i < kinHelpers.Count; i++) { kinHelper = kinHelpers[i]; Diagnostics.Log("Slurping " + kinHelper.KinName + " Kin of " + graphNodeKeyStr); if (kinHelper is IResourceKinFinder) { kin = (kinHelper as IResourceKinFinder).FindKindredResources(graphNode.OriginalKey); } else { kin = SlurpKindredResources(graphNode.OriginalKey, kinHelper); } for (j = 0; j < kin.Count; j++) { kinKey = kin[j].ResourceIndexEntry; if (kinKey == null) { continue; } kinConnection = new GraphConnectionKin(this, graphNode, kinHelper); childNode = null; // Try to find an already existing kindred node in the lookup table. foundIndex = -1; for (k = 0; k < this.nodeLookupTable.Count && foundIndex < 0; k++) { if (this.nodeLookupTable[k].OriginalKey.Equals(kinKey)) { foundIndex = k; } } if (foundIndex >= 0) { childNode = this.nodeLookupTable[foundIndex]; if (!childNode.IsKindred) { Diagnostics.Log("Non-Kindred Node " + PrintRKTag(kinKey, childNode.ExtensionTag) + " is " + kinHelper.KinName + " Kin of " + graphNodeKeyStr); } else { Diagnostics.Log("Existing Kindred Node " + PrintRKTag(kinKey, childNode.ExtensionTag) + " is " + kinHelper.KinName + " Kin of " + graphNodeKeyStr); } } else { IResource kinResource = kin[j].Resource; if (kinResource == null) { Diagnostics.Log("Unresolved RK Kin:" + PrintRK(kinKey) + ((kin[j].Exception == null) ? "" : string.Concat(" Error:\r\n", kin[j].Exception.ToString()))); } else { IResourceNode kinCore = kinHelper.CreateKin(kinResource, kinKey, constraints); if (kinCore == null) { Diagnostics.Log("CreateKin Failed:" + PrintRK(kinKey)); } else { childNode = new GraphNode(this, kinKey, kinCore, kin[j].PathPackage, ResourceDataActions.FindWrite); this.nodeLookupTable.Add(childNode); Diagnostics.Log("New Kin Node Added:" + PrintRKTag(kinKey, childNode.ExtensionTag)); CreateChildren(childNode, constraints); } } } if (childNode != null) { graphNode.KindredConnections.Add(kinConnection); kinConnection.Child = childNode; childNode.KinOwnerConnections.Add(kinConnection); } } } }
CreateFileResourceCommand(IResourcesFolderNode rsrcListNode, IResourceNode[] nodes) { this.module = rsrcListNode.GetModule(); Debug.Assert(this.module != null); this.rsrcListNode = rsrcListNode; this.nodes = nodes; }
public virtual FileTreeNodeFilterResult GetResult(IResourceNode node) { return new FileTreeNodeFilterResult(FilterType.Hide, false); }
CreateMultiFileResourceCommand(IResourcesFolderNode rsrcListNode, IResourceNode resTreeNode) : base(rsrcListNode, resTreeNode) { }
public virtual FileTreeNodeFilterResult GetResult(IResourceNode node) { return(new FileTreeNodeFilterResult(FilterType.Hide, false)); }
void Decompile(IResourceNode node) { if (node is IResourceElementSetNode) Decompile((IResourceElementSetNode)node); else node.WriteShort(output, language, language.Settings.GetBoolean(DecompilerOptionConstants.ShowTokenAndRvaComments_GUID)); }
public override FileTreeNodeFilterResult GetResult(IResourceNode node) { var visibleFlags = VisibleMembersFlags.Resource | VisibleMembersFlags.ResourceElement | VisibleMembersFlags.Attributes; bool isMatch = (flags & VisibleMembersFlags.Resource) != 0; if ((flags & visibleFlags) == 0) return new FileTreeNodeFilterResult(FilterType.Hide, isMatch); if (isMatch) return new FileTreeNodeFilterResult(FilterType.Visible, isMatch); return new FileTreeNodeFilterResult(FilterType.CheckChildren, isMatch); }
void SearchResourceTreeNodes(IDnSpyFile module, IResourceNode resTreeNode) { var res = options.Filter.GetResult(resTreeNode); if (res.FilterType == FilterType.Hide) return; if (res.IsMatch && (IsMatch(resTreeNode.Name, resTreeNode) || IsMatch(ToString(resTreeNode), null))) { options.OnMatch(new SearchResult { Context = options.Context, Object = resTreeNode, NameObject = resTreeNode, ObjectImageReference = resTreeNode.Icon, LocationObject = module.ModuleDef, LocationImageReference = options.DotNetImageManager.GetImageReference(module.ModuleDef), DnSpyFile = module, }); } res = options.Filter.GetResult((IResourceElementNode)null); if (res.FilterType == FilterType.Hide) return; var resNodes = new List<IResourceElementNode>(); options.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { resTreeNode.TreeNode.EnsureChildrenLoaded(); resNodes.AddRange(resTreeNode.TreeNode.DataChildren.OfType<IResourceElementNode>()); })); foreach (var resElNode in resNodes) SearchResourceElementTreeNode(module, resTreeNode, resElNode); }
public static IObservable <object> GetResourceObservable(this IResourceNode target, object key) { return(new ResourceObservable(target, key)); }