//Parser commands must initialize the node before returning. public static ResourceNode FromFile(ResourceNode parent, string path) { ResourceNode node = null; FileMap map = FileMap.FromFile(path, FileMapProtect.Read); try { if (Path.GetExtension(path).ToUpper().ToString() == ".MRG") { node = new MRGNode(); node.Initialize(parent, map); } else if (Path.GetExtension(path).ToUpper().ToString() == ".REL") { node = new RELNode(); node.Initialize(parent, map); } else if (Path.GetExtension(path).ToUpper().ToString() == ".DOL") { node = new DOLNode(); node.Initialize(parent, map); } else { node = FromSource(parent, new DataSource(map)); } } finally { if (node == null) { map.Dispose(); } } return(node); }
public void ExportAsMRG(string path) { MRGNode node = new MRGNode(); node._children = Children; node._changed = true; node.Export(path); }
//Parser commands must initialize the node before returning. public unsafe static ResourceNode FromFile(ResourceNode parent, string path) { ResourceNode node = null; FileMap map = FileMap.FromFile(path, FileMapProtect.Read); try { DataSource source = new DataSource(map); if (String.Equals(Path.GetExtension(path), ".mrg", StringComparison.OrdinalIgnoreCase) || String.Equals(Path.GetExtension(path), ".mrgc", StringComparison.OrdinalIgnoreCase)) { node = new MRGNode(); if (Compressor.IsDataCompressed(source.Address, source.Length)) { CompressionHeader *cmpr = (CompressionHeader *)source.Address; source.Compression = cmpr->Algorithm; if (Compressor.Supports(cmpr->Algorithm)) { try { //Expand the whole resource and initialize FileMap uncompMap = FileMap.FromTempFile(cmpr->ExpandedSize); Compressor.Expand(cmpr, uncompMap.Address, uncompMap.Length); node.Initialize(parent, source, new DataSource(uncompMap)); } catch (InvalidCompressionException e) { MessageBox.Show(e.ToString()); } } else { node.Initialize(parent, source); } } else { node.Initialize(parent, source); } } else if (String.Equals(Path.GetExtension(path), ".rel", StringComparison.OrdinalIgnoreCase)) { node = new RELNode(); node.Initialize(parent, map); } else if (String.Equals(Path.GetExtension(path), ".dol", StringComparison.OrdinalIgnoreCase)) { node = new DOLNode(); node.Initialize(parent, map); } else if ((node = FromSource(parent, source)) == null) { //if (Compressor.IsDataCompressed(source.Address, source.Length)) //{ // CompressionHeader* cmpr = (CompressionHeader*)source.Address; // if (!Compressor.Supports(cmpr->Algorithm)) // MessageBox.Show("File uses unsupported " + cmpr->Algorithm.ToString() + " compression."); //} } } finally { if (node == null) { map.Dispose(); } } return(node); }
public MRGNode NewMRG() { MRGNode node = new MRGNode() { Name = _resource.FindName("NewMRG") }; _resource.AddChild(node); BaseWrapper w = this.FindResource(node, false); w.EnsureVisible(); w.TreeView.SelectedNode = w; return node; }