Example #1
0
        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);
        }
Example #2
0
        private async Task <Boolean> ExtractNodeAsync(IBranchItem node, String outputRoot, ExtractModeEnum extractMode, String rootPath)
        {
            var result = true;

            if (rootPath == null)
            {
                rootPath = String.Empty;

                if (!String.IsNullOrWhiteSpace(node.RelativePath))
                {
                    rootPath = Path.GetDirectoryName(node.RelativePath);
                }
            }

            foreach (var child in node.Children.OfType <ITreeItem>())
            {
                result &= await this.ExtractNodeAsync(child, outputRoot, extractMode, rootPath);
            }

            return(result);
        }
Example #3
0
        private async Task <Boolean> ExtractNodeAsync(ITreeItem node, String outputRoot, ExtractModeEnum extractMode, String rootPath = null)
        {
            // Early exit if we don't match the filter
            if (!this.Filter(node))
            {
                return(true);
            }

            if (node is IStreamTreeItem leaf)
            {
                return(await this.ExtractNodeAsync(leaf, outputRoot, extractMode, rootPath));
            }

            if (node is IBranchItem branch)
            {
                return(await this.ExtractNodeAsync(branch, outputRoot, extractMode, rootPath));
            }

            return(false);

            // else
            // {
            //  throw new NotSupportedException($"Node type not supported. Node type: {node.GetType().Name}");
            // }
        }