Exemplo n.º 1
0
        public static void Merge(PathCollection archivesFiles, string destinationArchiveFileName, CompressionFlavor flavor, IProgress <string> progress)
        {
            var files = new SortedDictionary <string, FileEntry>();

            foreach (var archiveFullPath in archivesFiles.Keys)
            {
                using (var archive = new HpiArchive(File.OpenRead(archiveFullPath)))
                    foreach (var shortFileName in archivesFiles[archiveFullPath])
                    {
                        var entry  = archive.Entries[shortFileName];
                        var buffer = archive.Extract(entry);

                        if (files.ContainsKey(shortFileName))
                        {
                            files[shortFileName] = new FileEntry(buffer, flavor, shortFileName, progress);
                        }
                        else
                        {
                            files.Add(shortFileName, new FileEntry(buffer, flavor, shortFileName, progress));
                        }
                    }
            }
            WriteToFile(destinationArchiveFileName, files);
        }
Exemplo n.º 2
0
        public static void DoExtraction(PathCollection archivesFiles, string destinationPath, IProgress <string> progress)
        {
            foreach (var archiveFullPath in archivesFiles.Keys)
            {
                using (var archive = new HpiArchive(File.OpenRead(archiveFullPath)))
                {
                    //int progressLimiter = (fileList.Count - 1) / 100 + 1; //Reduce progress calls

                    foreach (var shortFileName in archivesFiles[archiveFullPath])
                    {
                        string fullName = destinationPath + "\\" + shortFileName;
                        Directory.CreateDirectory(Path.GetDirectoryName(fullName));
                        var entry = archive.Entries[shortFileName];
                        File.WriteAllBytes(fullName, archive.Extract(entry));

                        //Report progress
                        if (progress != null) //&& i % progressLimiter == 0)
                        {
                            progress.Report(shortFileName);
                        }
                    }
                }
            }
        }