public void Bind(ArchiveWriter.Stats stats) { onTick = delegate { this.Text = stats.Title; progressBar1.Value = Math.Max(0, Math.Min(100, (int)(stats.Progress * 100))); textStatus.Text = stats.Status; long total = stats.Compressed + stats.SavedByCompression + stats.SavedByInternalDelta + stats.SavedByExternalDelta; TimeSpan time = (stats.EndTime ?? DateTime.Now) - stats.StartTime; labelL1.Text = "Total processed:"; textL1.Text = FormatSize(total); labelL2.Text = "Elapsed time:"; textL2.Text = string.Format("{0}:{1:D2}:{2:D2}", time.Hours, time.Minutes, time.Seconds); labelL3.Text = "Block size:"; textL3.Text = FormatSize(Settings.BlockSize); labelL4.Text = ""; textL4.Text = ""; labelR1.Text = "Compressed size:"; textR1.Text = FormatSize(stats.Compressed, total); labelR2.Text = "Saved by compression:"; textR2.Text = FormatSize(stats.SavedByCompression, total); labelR3.Text = "Saved by internal delta:"; textR3.Text = FormatSize(stats.SavedByInternalDelta, total); labelR4.Text = "Saved by external delta:"; textR4.Text = FormatSize(stats.SavedByExternalDelta, total); buttonCancel.Enabled = (stats.EndTime == null); }; onCancel = delegate { stats.Canceled = true; stats.EndTime = DateTime.Now; }; }
static void Create_Worker(ProgressBar bar, ArchiveWriter.Stats stats) { string src = Settings.Src; string dst = Settings.Dst; string refFile = Settings.Ref; if (string.IsNullOrEmpty(src)) throw new Exception("You have to specify Src"); if (string.IsNullOrEmpty(dst)) throw new Exception("You have to specify Dst"); // The destination is directory if (!Settings.CreateMulti && !dst.ToLowerInvariant().EndsWith(Settings.ArchiveExtension.ToLowerInvariant())) { dst = Path.Combine(dst, Path.GetFileName(src) + Settings.ArchiveExtension); } if (Settings.RefRecent) { string dir = Path.GetDirectoryName(dst); if (Directory.Exists(dir)) { refFile = GetMostRecentArchive(dir); } } Reference reference = null; if (!string.IsNullOrEmpty(refFile)) { stats.Status = "Opening " + Path.GetFileName(refFile); reference = new Reference(refFile); } List<string> verifycationList = new List<string>(); if (Settings.CreateMulti) { // Multiple archives string dstBase = dst; foreach (string subDir in Directory.GetDirectories(src)) { dst = Path.Combine(dstBase, Path.GetFileName(subDir)) + Settings.ArchiveExtension; stats.Title = Path.GetFileName(dst); string tmpName = dst + Settings.TmpExtension + new Random().Next(); ArchiveWriter archive = new ArchiveWriter(tmpName, stats); archive.AddDir(subDir, reference); reference = archive.Finish(Path.GetFileName(dst)); if (stats.Canceled) { IOFile.Delete(tmpName); break; } else { if (IOFile.Exists(dst)) { IOFile.Delete(dst); } IOFile.Move(tmpName, dst); verifycationList.Add(dst); } } } else { stats.Title = Path.GetFileName(dst); string tmpName = dst + Settings.TmpExtension + new Random().Next(); Directory.CreateDirectory(Path.GetDirectoryName(tmpName)); ArchiveWriter archive = new ArchiveWriter(tmpName, stats); archive.AddDir(src, reference); archive.Finish(dst); if (stats.Canceled) { IOFile.Delete(tmpName); } else { if (IOFile.Exists(dst)) { int suffix = 0; string newDst; do { newDst = Path.Combine(Path.GetDirectoryName(dst), Path.GetFileNameWithoutExtension(dst) + (suffix == 0 ? string.Empty : ("-" + suffix.ToString())) + Path.GetExtension(dst)); suffix++; } while (IOFile.Exists(newDst)); dst = newDst; } IOFile.Move(tmpName, dst); verifycationList.Add(dst); } } stats.EndTime = DateTime.Now; // Free memory reference = null; bool allOk = true; if (!stats.Canceled && Settings.Verify) { ArchiveReader.Stats verficationStats = new ArchiveReader.Stats(); bar.Bind(verficationStats); foreach (string filename in verifycationList) { allOk = allOk && ArchiveReader.Extract(filename, null, verficationStats); } } if (Settings.AutoQuit && allOk) bar.Close(); }