Ejemplo n.º 1
0
        public void SetDestination(string dest, Format format, CompressionMethod method)
        {
            var src = new CompressRuntimeSetting {
                Destination = dest
            };

            Assert.That(src.Format, Is.EqualTo(format));
            Assert.That(src.CompressionMethod, Is.EqualTo(method));
        }
        /* ----------------------------------------------------------------- */
        ///
        /// SetPassword
        ///
        /// <summary>
        /// Sets the password.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private void SetPassword(CompressRuntimeSetting src)
        {
            if (src.Password.HasValue() || !Request.Password)
            {
                return;
            }

            var e = Query.NewMessage(Destination);

            Password.Request(e);
            if (e.Cancel)
            {
                throw new OperationCanceledException();
            }
            src.Password = e.Value;
        }
Ejemplo n.º 3
0
        public void SetMethod(Format format, CompressionMethod method, string dest)
        {
            var src = new CompressRuntimeSetting {
                Destination = "Sample.txt"
            };

            Assert.That(src.Format, Is.EqualTo(Format.Zip));
            Assert.That(src.CompressionMethod, Is.EqualTo(CompressionMethod.Default));

            src.Format            = format;
            src.CompressionMethod = method;
            src.Format            = format;

            Assert.That(src.Format, Is.EqualTo(format));
            Assert.That(src.CompressionMethod, Is.EqualTo(method));
            Assert.That(src.Destination, Does.EndWith(dest));
        }
Ejemplo n.º 4
0
        public void ToOption()
        {
            var dest = new CompressRuntimeSetting()
            {
                CompressionLevel  = CompressionLevel.High,
                CompressionMethod = CompressionMethod.Ppmd,
                EncryptionMethod  = EncryptionMethod.Aes192,
                Format            = Format.GZip,
                Password          = "******",
                Destination       = "dummy",
                Sfx         = string.Empty,
                ThreadCount = 3,
            }.ToOption(new SettingFolder());

            Assert.That(dest.CompressionLevel, Is.EqualTo(CompressionLevel.High));
            Assert.That(dest.ThreadCount, Is.EqualTo(3));
        }
        /* ----------------------------------------------------------------- */
        ///
        /// 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);
            }
        }
Ejemplo n.º 6
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);
        }
 /* ----------------------------------------------------------------- */
 ///
 /// InvokePreProcess
 ///
 /// <summary>
 /// Invokes the pre-processes.
 /// </summary>
 ///
 /* ----------------------------------------------------------------- */
 private void InvokePreProcess(CompressRuntimeSetting src)
 {
     Destination = this.Select(src);
     SetTemp(Io.Get(Destination).DirectoryName);
     SetPassword(src);
 }