using System; using System.IO; using System.Windows.Forms; using SharpCompress.Archive; using SharpCompress.Common; namespace Custom_Installer { class Extract { public String FilePath { get; set; } public String ExtractPath { get; set; } public ProgressBar Progress { get; set; } public Label Information { get; set; } public Boolean IsFinished; public void StartExtract() { try { using (var CurrentArchive = ArchiveFactory.Open(FilePath)) { Int32 Completed = 0; Int32 Total = 0; foreach (var CurrentEntry in CurrentArchive.Entries) { if (!CurrentEntry.IsDirectory) { Total++; } } foreach (var CurrentEntry in CurrentArchive.Entries) { Double CompletedDouble = (Double)Completed; Double TotalDouble = (Double)Total; Double ProgressDouble = (CompletedDouble / TotalDouble); Int32 ProgressPercentage = (Int32)(ProgressDouble * 100); if (!CurrentEntry.IsDirectory) { if (Progress != null) { Progress.BeginInvoke((Action)(() => { Progress.Value = ProgressPercentage; })); } if (Information != null) { Information.BeginInvoke((Action)(() => { Information.Text = String.Format("Extracting: ({0}%) [{1}/{2}]", ProgressPercentage, Completed, Total); })); } CurrentEntry.WriteToDirectory(ExtractPath, ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite); } else { Directory.CreateDirectory(CurrentEntry.FilePath); } Completed++; } } if (Progress != null) { Progress.BeginInvoke((Action)(() => { Progress.Value = 100; })); } if (Information != null) { Information.BeginInvoke((Action)(() => { Information.Text = String.Format("Extracted Successfully"); })); } IsFinished = true; } catch(Exception Error) { Program.Message(Error.Message); Program.Shutdown(); } } } }