public IStreamTreeItem Extract(IStreamTreeItem node) { var supportedExtensions = new HashSet <String>(StringComparer.InvariantCultureIgnoreCase) { ".xml", ".mtl" }; if (supportedExtensions.Contains(Path.GetExtension(node.RelativePath))) { using (var dataStream = node.Stream) { dataStream.Seek(0, SeekOrigin.Begin); using (var br = new BinaryReader(dataStream)) { try { Debug.WriteLine($"Checking {node.Text}"); var peek = br.PeekChar(); // File is already XML if (peek == '<') { return(node); } String header = br.ReadFString(7); if (header == "CryXml" || header == "CryXmlB" || header == "CRY3SDK") { dataStream.Seek(0, SeekOrigin.Begin); var xml = unforge.CryXmlSerializer.ReadStream(dataStream); return(new CryXmlTreeItem(node, xml)); } } catch (Exception) { } } } } return(node); }
public DataForgeTreeItem(IStreamTreeItem node, unforge.DataForge dataForge) : base(node.Title, () => dataForge.GetStream(), node.LastModifiedUtc, dataForge.OuterXML.Length) { var sw = new Stopwatch { }; sw.Start(); var maxIndex = dataForge.Length - 1; var lastIndex = 0L; var oldProgress = ArchiveExplorer.RegisterProgress(async(ProgressBar barProgress) => { barProgress.Maximum = maxIndex; barProgress.Value = lastIndex; await ArchiveExplorer.UpdateStatus($"Deserializing file {lastIndex:#,##0}/{maxIndex:#,##0} from dataforge"); await Task.CompletedTask; }); foreach ((String FileName, XmlDocument XmlDocument)entry in dataForge) { this.AddStream( entry.FileName, () => entry.XmlDocument.GetStream(), node.LastModifiedUtc, entry.XmlDocument.OuterXml.Length); lastIndex++; } sw.Stop(); ArchiveExplorer.RegisterProgress(oldProgress); ArchiveExplorer.UpdateStatus($"Deserialized {this.Text} in {sw.ElapsedMilliseconds:#,000}ms").Wait(); }
public IStreamTreeItem Handle(IStreamTreeItem node) { if (Path.GetExtension(node.Title).Equals(".dcb", StringComparison.InvariantCultureIgnoreCase)) { using (var dataStream = node.Stream) { dataStream.Seek(0, SeekOrigin.Begin); using (var br = new BinaryReader(dataStream)) { try { var forge = new unforge.DataForge(br); return(new DataForgeTreeItem(node, forge)); } catch (Exception) { } } } } return(node); }
public IStreamTreeItem Handle(IStreamTreeItem node) { return(node); }
public IStreamTreeItem Extract(IStreamTreeItem node) { return(node); }
private async Task <Boolean> ExtractNodeAsync(IStreamTreeItem node, String outputRoot, ExtractModeEnum extractMode, String rootPath) { this._filesExtracted += 1; var forgeFactory = new DataForgeFormatFactory { }; var cryxmlFactory = new CryXmlFormatFactory { }; node = forgeFactory.Extract(node); node = cryxmlFactory.Extract(node); if (rootPath == null) { rootPath = Path.GetDirectoryName(node.RelativePath); outputRoot = Path.GetDirectoryName(outputRoot); } // Get file path relative to the passed root var relativePath = node.RelativePath.RelativeTo(rootPath); var absolutePath = Path.Combine(outputRoot, relativePath); if (!String.IsNullOrWhiteSpace(absolutePath)) { var target = new FileInfo(absolutePath); if (!target.Directory.Exists) { target.Directory.Create(); } if (target.Exists) { switch (extractMode) { case ExtractModeEnum.New: return(false); case ExtractModeEnum.NewOrLatest: if (target.LastWriteTimeUtc >= node.LastModifiedUtc) { return(false); } break; case ExtractModeEnum.Overwrite: break; } } #region Dump Raw File try { using (var dataStream = node.Stream) { dataStream.Seek(0, SeekOrigin.Begin); using (FileStream fs = File.Create(absolutePath)) { await dataStream.CopyToAsync(fs, 4096); } target.LastWriteTimeUtc = node.LastModifiedUtc; } } catch (ZStdException ex) { return(false); } #endregion } return(true); }
public CryXmlTreeItem(IStreamTreeItem node, XmlDocument xml) : base(node.Title, () => xml.GetStream(), node.LastModifiedUtc, xml.OuterXml.Length) { }