/* ----------------------------------------------------------------- */ /// /// Archive /// /// <summary> /// 圧縮処理を実行します。 /// </summary> /// /* ----------------------------------------------------------------- */ private void Archive() { var fmt = GetFormat(); var dest = GetTmp(); var query = RtSettings.Password.HasValue() || Request.Password ? new Query <string>(e => RaisePasswordRequested(e)) : null; System.Diagnostics.Debug.Assert(RtSettings != null); this.LogDebug(string.Format("Format:{0}\tMethod:{1}", fmt, RtSettings.CompressionMethod)); using (var writer = new ArchiveWriter(fmt, IO)) { writer.Option = RtSettings.ToOption(Settings); if (Settings.Value.Archive.Filtering) { writer.Filters = Settings.Value.GetFilters(); } foreach (var item in Request.Sources) { writer.Add(item); } ProgressStart(); writer.Save(dest, query, CreateInnerProgress(x => Report = x)); } // Move if (!IO.Exists(Tmp)) { return; } IO.Move(Tmp, Destination, true); }
public void Archive_Skip() { var dir = GetResultsWith("Ignore"); var ignore = IO.Combine(dir, "Sample.txt"); var io = new IO(); io.Failed += (s, e) => e.Cancel = true; io.Copy(GetExamplesWith("Sample.txt"), ignore); var dest = io.Combine(dir, "Sample.zip"); using (var _ = OpenExclude(ignore)) using (var writer = new ArchiveWriter(Format.Zip, io)) { writer.Add(ignore); writer.Add(GetExamplesWith("Sample 00..01")); writer.Save(dest); } using (var reader = new ArchiveReader(dest)) { Assert.That(reader.Items.Count, Is.EqualTo(8)); Assert.That(reader.Items.Any(x => x.FullName == "Sample.txt"), Is.False); } }
public void Archive_PasswordCancel() => Assert.That(() => { using (var writer = new ArchiveWriter(Format.Zip)) { var dest = GetResultsWith("PasswordCancel.zip"); var query = new Query <string>(e => e.Cancel = true); writer.Add(GetExamplesWith("Sample.txt")); writer.Save(dest, query, null); } }, Throws.TypeOf <OperationCanceledException>());
public void Archive_SfxNotFound() => Assert.That(() => { using (var writer = new ArchiveWriter(Format.Sfx)) { var dest = GetResultsWith("SfxNotFound.exe"); writer.Option = new SfxOption { Module = "dummy.sfx" }; writer.Add(GetExamplesWith("Sample.txt")); writer.Save(dest); } }, Throws.TypeOf <System.IO.FileNotFoundException>());
public void Archive_PermissionError() => Assert.That(() => { var dir = GetResultsWith("PermissionError"); var src = IO.Combine(dir, "Sample.txt"); IO.Copy(GetExamplesWith("Sample.txt"), src); using (var _ = OpenExclude(src)) using (var writer = new ArchiveWriter(Format.Zip)) { writer.Add(src); writer.Save(IO.Combine(dir, "Sample.zip")); } }, Throws.TypeOf <System.IO.IOException>());
public Format Archive(Format format, string filename, string password, string[] items, ArchiveOption option) { var dest = GetResultsWith(filename); using (var writer = new ArchiveWriter(format)) { writer.Option = option; foreach (var item in items) { writer.Add(GetExamplesWith(item)); } writer.Save(dest, password); writer.Clear(); } using (var ss = IO.OpenRead(dest)) return(Formats.FromStream(ss)); }
/* ----------------------------------------------------------------- */ /// /// Invoke /// /// <summary> /// Invokes the compression and saves the archive. /// </summary> /// /* ----------------------------------------------------------------- */ private void Invoke(CompressRuntimeSetting src) { GetType().LogDebug($"Format:{src.Format}", $"Method:{src.CompressionMethod}"); using (var writer = new ArchiveWriter(src.Format, src.ToOption(Settings))) { foreach (var e in Request.Sources) { writer.Add(e); } writer.Save(Temp, GetProgress()); } if (Io.Exists(Temp)) { Io.Move(Temp, Destination, true); } }
public int Archive_Filter(bool filter) { var names = new[] { "Filter.txt", "FilterDirectory" }; var s = filter ? "True" : "False"; var dest = GetResultsWith($"Filter{s}.zip"); using (var writer = new ArchiveWriter(Format.Zip)) { if (filter) { writer.Filters = names; } writer.Add(GetExamplesWith("Sample.txt")); writer.Add(GetExamplesWith("Sample 00..01")); writer.Save(dest); } using (var reader = new ArchiveReader(dest)) return(reader.Items.Count); }
public void Archive_Japanese(bool utf8) { var fmt = Format.Zip; var src = GetResultsWith("日本語のファイル名.txt"); var code = utf8 ? "UTF8" : "SJis"; var dest = GetResultsWith($"ZipJapanese{code}.zip"); IO.Copy(GetExamplesWith("Sample.txt"), src, true); Assert.That(IO.Exists(src), Is.True); using (var writer = new ArchiveWriter(fmt)) { writer.Option = new ZipOption { CodePage = utf8 ? CodePage.Utf8 : CodePage.Japanese }; writer.Add(src); writer.Save(dest); } using (var stream = System.IO.File.OpenRead(dest)) { Assert.That(Formats.FromStream(stream), Is.EqualTo(fmt)); } }