/* ----------------------------------------------------------------- */ /// /// Invoke /// /// <summary> /// Invokes the main process. /// </summary> /// /* ----------------------------------------------------------------- */ protected override void Invoke() { foreach (var src in Request.Sources) { Source = src; var dir = new ExtractDirectory(this.Select(), Settings); InvokePreProcess(dir); var list = Settings.Value.GetFilters(Settings.Value.Extract.Filtering); var opts = new ArchiveOption { Filter = Filter.From(list) }; using (var e = new ArchiveReader(src, Password, opts)) { if (e.Items.Count == 1) { Invoke(e, 0, dir); } else { Invoke(e, dir); } } InvokePostProcess(dir); } }
/* ----------------------------------------------------------------- */ /// /// SetDestination /// /// <summary> /// Sets the destination path. /// </summary> /// /* ----------------------------------------------------------------- */ private void SetDestination(ArchiveReader src, ExtractDirectory dir) { var basename = Io.Get(src.Source).GetBaseName(src.Format); dir.Resolve(basename, src.Items); Destination = dir.Value; }
/* ----------------------------------------------------------------- */ /// /// InvokePostProcess /// /// <summary> /// Invokes the post-process. /// </summary> /// /* ----------------------------------------------------------------- */ private void InvokePostProcess(ExtractDirectory dir) { var ss = Settings.Value.Extract; var app = Settings.Value.Explorer; Io.Get(dir.ValueToOpen).Open(ss.OpenMethod, app); if (ss.DeleteSource) { GetType().LogWarn(() => Io.Delete(Source)); } }
/* ----------------------------------------------------------------- */ /// /// Invoke /// /// <summary> /// Extracts the specified archive. /// </summary> /// /* ----------------------------------------------------------------- */ private void Invoke(ArchiveReader src, ExtractDirectory dir) { GetType().LogDebug($"Format:{src.Format}", $"Source:{src.Source}"); SetDestination(src, dir); var progress = GetProgress(e => { e.CopyTo(Report); if (Report.Status == ReportStatus.End) { Move(e.Current); } }); Retry(() => src.Save(Temp, progress)); }
/* ----------------------------------------------------------------- */ /// /// Invoke /// /// <summary> /// Extracts an archive item of the specified index. /// </summary> /// /* ----------------------------------------------------------------- */ private void Invoke(ArchiveReader src, int index, ExtractDirectory dir) { GetType().LogDebug($"Format:{src.Format}", $"Source:{src.Source}"); SetDestination(src, dir); var item = src.Items[index]; Retry(() => src.Save(Temp, item, GetProgress())); var dest = Io.Combine(Temp, item.FullName); if (Formatter.FromFile(dest) != Format.Tar) { Move(item); } else { using var e = new ArchiveReader(dest, Password, src.Options); Invoke(e, dir); } }
/* ----------------------------------------------------------------- */ /// /// InvokePreProcess /// /// <summary> /// Invokes the pre-process. /// </summary> /// /* ----------------------------------------------------------------- */ private void InvokePreProcess(ExtractDirectory dir) => SetTemp(dir.Source);