public void Suspend()
        {
            var dir   = Get("Suspend");
            var args  = Preset.Extract.ToArguments().Concat(GetSource("SampleHeavy.7z"));
            var value = new ExtractSetting
            {
                SaveLocation  = SaveLocation.Preset,
                SaveDirectory = dir,
            };

            using (var vm = NewVM(args, value))
            {
                vm.Start();
                Assert.That(Wait.For(() => vm.State == TimerState.Run), $"1.{vm.State}");
                vm.SuspendOrResume();
                Assert.That(Wait.For(() => vm.State == TimerState.Suspend), $"2.{vm.State}");
                vm.SuspendOrResume();
                Assert.That(Wait.For(() => vm.State == TimerState.Run), $"3.{vm.State}");
                Task.Delay(1000).Wait();
            }

            var dest = Io.Combine(dir, "SampleHeavy");

            Assert.That(Io.Exists(dest), dest);
        }
        /* ----------------------------------------------------------------- */
        ///
        /// SevenZipLibrary
        ///
        /// <summary>
        /// Initializes a new instance of the SevenZipLibrary class.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        public SevenZipLibrary()
        {
            var dll = Io.Combine(GetType().Assembly.GetDirectoryName(), "7z.dll");

            _handle = Kernel32.NativeMethods.LoadLibrary(dll);
            if (_handle.IsInvalid)
            {
                throw new Win32Exception("LoadLibrary");
            }
        }
Ejemplo n.º 3
0
        /* ----------------------------------------------------------------- */
        ///
        /// GetEntity
        ///
        /// <summary>
        /// Invokes the conversion.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private Entity GetEntity()
        {
            var src  = Io.Get(_source);
            var tmp  = Io.Get(src.BaseName);
            var name = src.IsDirectory ? src.Name :
                       tmp.Extension.FuzzyEquals(".tar") ? tmp.BaseName :
                       tmp.Name;
            var dest = Io.Combine(src.DirectoryName, $"{name}{GetExtension()}");

            return(Io.Get(dest));
        }
Ejemplo n.º 4
0
        /* ----------------------------------------------------------------- */
        ///
        /// CreateDirectory
        ///
        /// <summary>
        /// Creates the directory.
        /// </summary>
        ///
        /// <param name="src">Information of the archived item.</param>
        /// <param name="root">Path of the root directory.</param>
        ///
        /* ----------------------------------------------------------------- */
        public static void CreateDirectory(this ArchiveEntity src, string root)
        {
            if (!src.IsDirectory)
            {
                return;
            }
            var path = Io.Combine(root, src.FullName);

            Io.CreateDirectory(path);
            SetAttributes(src, root);
        }
        /* ----------------------------------------------------------------- */
        ///
        /// SettingFolder
        ///
        /// <summary>
        /// Initializes a new instance of the SettingFolder with the
        /// specified parameters.
        /// </summary>
        ///
        /// <param name="assembly">Assembly information.</param>
        /// <param name="format">Serialized format.</param>
        /// <param name="location">Location for the settings.</param>
        ///
        /* ----------------------------------------------------------------- */
        public SettingFolder(Assembly assembly, DataContract.Format format, string location) :
            base(format, location, assembly.GetSoftwareVersion())
        {
            AutoSave = false;

            var exe = Io.Combine(assembly.GetDirectoryName(), "CubeChecker.exe");

            Startup = new("cubeice-checker") { Source = exe };
            Startup.Arguments.Add("cubeice");
            Startup.Arguments.Add("/subkey");
            Startup.Arguments.Add("CubeICE");
        }
Ejemplo n.º 6
0
        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>());
        }
Ejemplo n.º 7
0
        /* ----------------------------------------------------------------- */
        ///
        /// SetAttributes
        ///
        /// <summary>
        /// Sets attributes, creation time, last written time, and last
        /// accessed time to the extracted file or directory.
        /// </summary>
        ///
        /// <param name="src">Information of the archived item.</param>
        /// <param name="root">Path of the root directory.</param>
        ///
        /* ----------------------------------------------------------------- */
        public static void SetAttributes(this ArchiveEntity src, string root)
        {
            var path = Io.Combine(root, src.FullName);

            if (!Io.Exists(path))
            {
                return;
            }

            SetCreationTime(src, path);
            SetLastWriteTime(src, path);
            SetLastAccessTime(src, path);
            Io.SetAttributes(path, src.Attributes);
        }
Ejemplo n.º 8
0
        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 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));
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        public void CancelPassword()
        {
            var dir   = Get("CancelPassword");
            var src   = new[] { GetSource("Sample.txt") };
            var dest  = Io.Combine(dir, "Sample.zip");
            var args  = Preset.CompressZipPassword.ToArguments().Concat(src);
            var value = new CompressSetting
            {
                SaveLocation  = SaveLocation.Preset,
                SaveDirectory = dir,
                OpenMethod    = OpenMethod.None,
            };

            using var vm = NewVM(args, value);
            using (vm.SetDestination(dest)) vm.Test();
            Assert.That(Io.Exists(dest), Is.False, dest);
        }
Ejemplo n.º 12
0
        /* ----------------------------------------------------------------- */
        ///
        /// Move
        ///
        /// <summary>
        /// Moves from the temporary directory to the provided directory.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private void Move(Entity item)
        {
            if (!item.FullName.HasValue())
            {
                return;
            }

            var src = Io.Get(Io.Combine(Temp, item.FullName));

            if (!src.Exists)
            {
                return;
            }

            var dest = Io.Get(Io.Combine(Destination, item.FullName));

            src.Move(dest, Overwrite);
        }
        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);
        }
Ejemplo n.º 14
0
        public void WithFilter()
        {
            var src   = GetSource("SampleFilter.zip");
            var dest  = Get(nameof(WithFilter));
            var files = new[] { ".DS_Store", "Thumbs.db", "__MACOSX", "desktop.ini" };
            var opts  = new ArchiveOption {
                Filter = Filter.From(files)
            };

            using (var archive = new ArchiveReader(src, opts)) archive.Save(dest);

            Assert.That(Io.Exists(Io.Combine(dest, @"フィルタリング テスト用")), Is.True);
            Assert.That(Io.Exists(Io.Combine(dest, @"フィルタリング テスト用\.DS_Store")), Is.False);
            Assert.That(Io.Exists(Io.Combine(dest, @"フィルタリング テスト用\desktop.ini")), Is.False);
            Assert.That(Io.Exists(Io.Combine(dest, @"フィルタリング テスト用\DS_Store.txt")), Is.True);
            Assert.That(Io.Exists(Io.Combine(dest, @"フィルタリング テスト用\Thumbs.db")), Is.False);
            Assert.That(Io.Exists(Io.Combine(dest, @"フィルタリング テスト用\__MACOSX")), Is.False);
            Assert.That(Io.Exists(Io.Combine(dest, @"フィルタリング テスト用\フィルタリングされないファイル.txt")), 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);
        }
Ejemplo n.º 16
0
        /* ----------------------------------------------------------------- */
        ///
        /// 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);
            }
        }
Ejemplo n.º 17
0
        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();
                }
        }
        /* ----------------------------------------------------------------- */
        ///
        /// Invoke
        ///
        /// <summary>
        /// Invokes the file association.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        public static void Invoke(AssociateSetting src) => typeof(AssociateAction).LogWarn(() =>
        {
            if (!src.Changed)
            {
                return;
            }

            var dir = typeof(AssociateAction).Assembly.GetDirectoryName();
            var exe = Io.Combine(dir, Properties.Resources.FileAssociate);

            if (Io.Exists(exe))
            {
                System.Diagnostics.Process.Start(exe).WaitForExit();
            }
            else
            {
                typeof(AssociateAction).LogWarn($"{exe} not found");
            }

            src.Changed = false;
        });
Ejemplo n.º 19
0
        /* ----------------------------------------------------------------- */
        ///
        /// Select
        ///
        /// <summary>
        /// Gets the directory to save the compressed archive file.
        /// The method may query the user as needed.
        /// </summary>
        ///
        /// <param name="src">Source object.</param>
        /// <param name="settings">Runtime compress settings.</param>
        ///
        /// <returns>Path to save.</returns>
        ///
        /* ----------------------------------------------------------------- */
        public static string Select(this CompressFacade src, CompressRuntimeSetting settings)
        {
            if (settings.Destination.HasValue())
            {
                return(settings.Destination);
            }

            var ss  = src.Settings.Value.Compress;
            var cvt = new ArchiveName(src.Request.Sources.First(), src.Request.Format);
            var obj = new SaveQueryProxy(src.Select, cvt.Value.FullName, src.Request, ss)
            {
                Format = cvt.Format,
            };

            if (obj.Location == SaveLocation.Query)
            {
                return(obj.Value);
            }

            var dest = Io.Combine(obj.Value, cvt.Value.Name);

            return(Io.Exists(dest) && ss.OverwritePrompt ? obj.Invoke() : dest);
        }
 /* ----------------------------------------------------------------- */
 ///
 /// CompressRuntime
 ///
 /// <summary>
 /// Initializes a new instance of the CompressRuntime class with
 /// the specified arguments.
 /// </summary>
 ///
 /// <param name="format">Archive format.</param>
 ///
 /* ----------------------------------------------------------------- */
 public CompressRuntimeSetting(Format format)
 {
     Format = format;
     Sfx    = Io.Combine(GetType().Assembly.GetDirectoryName(), Formatter.SfxName);
 }
Ejemplo n.º 21
0
        /* ----------------------------------------------------------------- */
        ///
        /// GetPath
        ///
        /// <summary>
        /// Gets the absolute path of the specified filename.
        /// </summary>
        ///
        /// <param name="src">Source type.</param>
        /// <param name="filename">Filename or relative path.</param>
        ///
        /// <returns>Absolute path.</returns>
        ///
        /* ----------------------------------------------------------------- */
        public static string GetPath(this Type src, string filename)
        {
            var root = src.Assembly.GetDirectoryName();

            return(Io.Combine(root, "Results", src.FullName, filename));
        }
Ejemplo n.º 22
0
 /* ----------------------------------------------------------------- */
 ///
 /// GetValueToOpen
 ///
 /// <summary>
 /// Gets the directory path to open.
 /// </summary>
 ///
 /* ----------------------------------------------------------------- */
 private string GetValueToOpen(string src, IEnumerable <string> hints) =>
 hints.Take(2).Count() == 1 && hints.First() != WildCard?
 Io.Combine(src, hints.First()) :
     src;