public Format Detect(string filename) { var dest = Get(Guid.NewGuid().ToString("N")); Io.Copy(GetSource(filename), dest, true); return(Formatter.FromFile(dest)); }
public void Error_Permission() { var dest = Get(nameof(Error_Permission)); var locked = Io.Combine(dest, @"Sample\Foo.txt"); Io.Copy(GetSource("Sample.txt"), locked, true); using var ss = Io.Open(locked); using var archive = new ArchiveReader(GetSource("Sample.zip"), ""); Assert.That(() => archive.Save(dest), Throws.TypeOf <System.IO.IOException>()); }
public void Error_MultiVolume() { var dest = Get(nameof(Error_MultiVolume)); for (var i = 1; i < 4; ++i) { var name = $"SampleVolume.rar.{i:000}"; Io.Copy(GetSource(name), Io.Combine(dest, name), true); } var src = Io.Combine(dest, "SampleVolume.rar.001"); using var archive = new ArchiveReader(src); Assert.That(() => archive.Save(dest), Throws.TypeOf <System.IO.IOException>()); }
public void Overwrite() { var dir = Get("Overwrite"); var src = new[] { GetSource("Sample.txt") }; var dest = Io.Combine(dir, "Sample.zip"); var args = Preset.Compress.ToArguments().Concat(src); var value = new CompressSetting { SaveLocation = SaveLocation.Query, OpenMethod = OpenMethod.None, }; Io.Copy(GetSource("Single.1.0.0.zip"), dest, true); using var vm = NewVM(args, value); using (vm.SetDestination(dest)) vm.Test(); Assert.That(Io.Exists(dest), Is.True, dest); }
public void CancelOverwrite() { var dummy = GetSource("Sample.txt"); var size = Io.Get(dummy).Length; var dest = Get("CancelOverwrite"); var args = Preset.Extract.ToArguments().Concat(GetSource("Complex.1.0.0.zip")); var value = new ExtractSetting { SaveLocation = SaveLocation.Preset, SaveDirectory = dest, }; Io.Copy(dummy, Io.Combine(dest, "Foo.txt"), true); using var vm = NewVM(args, value); using (vm.SetOverwrite(OverwriteMethod.Cancel)) vm.Test(); Assert.That(Io.Get(Io.Combine(dest, "Foo.txt")).Length, Is.EqualTo(size)); }
public void WithCjk(CodePage cp) { var zip = Format.Zip; var src = Get("日本語のファイル名.txt"); var dest = Get($"{nameof(WithCjk)}{zip}{cp}.zip"); Io.Copy(GetSource("Sample.txt"), src, true); Assert.That(Io.Exists(src), Is.True); using (var obj = new ArchiveWriter(zip, new() { CodePage = cp })) { obj.Add(src); obj.Save(dest); } using var ss = Io.Open(dest); Assert.That(Formatter.FromStream(ss), Is.EqualTo(zip)); }
public void DeleteSource() { var src = Get("Complex.zip"); var dest = Get("DeleteSource"); var args = Preset.Extract.ToArguments().Concat(src); var value = new ExtractSetting { SaveLocation = SaveLocation.Preset, SaveDirectory = dest, DeleteSource = true, }; Io.Copy(GetSource("Complex.1.0.0.zip"), src, true); Assert.That(Io.Exists(src), Is.True); using var vm = NewVM(args, value); vm.Test(); Assert.That(Io.Exists(src), Is.False); Assert.That(Io.Exists(Io.Combine(dest, "Complex")), Is.True); }
public void Rename() { var dummy = GetSource("Sample.txt"); var dest = Get(@"Rename"); var args = Preset.Extract.ToArguments().Concat(GetSource("Complex.1.0.0.zip")); var value = new ExtractSetting { SaveLocation = SaveLocation.Preset, SaveDirectory = dest, }; Io.Copy(dummy, Io.Combine(dest, @"Complex.1.0.0\Foo.txt"), true); Io.Copy(dummy, Io.Combine(dest, @"Complex.1.0.0\Directory\Empty.txt"), true); using var vm = NewVM(args, value); using (vm.SetOverwrite(OverwriteMethod.Rename)) vm.Test(); Assert.That(Io.Exists(Io.Combine(dest, @"Complex.1.0.0\Foo(1).txt")), Is.True); Assert.That(Io.Exists(Io.Combine(dest, @"Complex.1.0.0\Directory\Empty(1).txt")), Is.True); }
public void MoveFailed() { var dir = Get("MoveFailed"); var src = new[] { GetSource("Sample.txt") }; var dest = Io.Combine(dir, "Sample.zip"); var args = Preset.CompressZip.ToArguments().Concat(new[] { "/o:runtime" }).Concat(src); var value = new CompressSetting { SaveLocation = SaveLocation.Preset, SaveDirectory = dir, OpenMethod = OpenMethod.None, }; Io.Copy(GetSource("Single.1.0.0.zip"), dest, true); using var vm = NewVM(args, value); using (Io.Open(dest)) using (vm.SetDestination(dest)) { vm.Test(); } }