//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); }
//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); }