public override void Extract(string root, BaseEntity entity, Func <BaseEntity, string> entityToDir, DirectoryCache cache, IProgress <int> progress)
        {
            PackageEntity package = entity as PackageEntity;

            using (ZipArchive arch = ZipFile.OpenRead(Path.Combine(root, entity.RelativePath)))
            {
                foreach (var entry in arch.Entries)
                {
                    BaseEntity ent = package.GetEntityFromRelativePath(entry.FullName, false);
                    if (ent is null)
                    {
                        throw new InvalidOperationException("Couldn't find entity in structure: " + entry.FullName + " of package: " + entity.RelativePath);
                    }
                    if (ent is FileEntity)
                    {
                        string dir = entityToDir(ent);
                        if (!cache.CacheDirectory(dir))
                        {
                            entry.ExtractToFile(Path.Combine(dir, ent.Name), false);
                        }
                        progress?.Report(1);
                    }
                }
            }
        }
Exemple #2
0
        private static void ParsePackage(FileInfo package, DirectoryEntity parent, HashProvider hashProvider, IProgress <int> progress)
        {
            PackageEntity root = new PackageEntity(package.Name);

            parent.Add(root);
            bool computeHash = hashProvider != null;

            using (ZipArchive archive = ZipFile.OpenRead(package.FullName))
            {
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    // Directory
                    if (entry.Length == 0)
                    {
                        continue;
                    }

                    string     relativePath = entry.FullName.Substring(0, entry.FullName.Length - entry.Name.Length);
                    FileEntity file         = computeHash ? new FileEntity(entry.Name, hashProvider.FromStream(entry.Open()) + entry.FullName.GetHashCode(), entry.Length) : new FileEntity(entry.Name, entry.Length);
                    (root.GetEntityFromRelativePath(relativePath, true) as DirectoryEntity).Add(file);
                    progress?.Report(1);
                }
            }
        }