Ejemplo n.º 1
0
        private void btCreateArchive_Click(object sender, EventArgs e)
        {
            string arc_path = System.IO.Path.GetFullPath(this.tbArchivePath.Text);

            if (arc_path != null)
            {
                ArchiveCreatorParams myparams = new ArchiveCreatorParams(
                    arc_path, this.ArchiveEntries, this.GetArchiveType(), this.GetCompressMethod());
                this.bwArchiveCreate.RunWorkerAsync(myparams);
                this.my_tmr_params = myparams;
                this.gboxArchiveCreateSettings.Enabled = false;
                this.gboxProgress.Enabled      = true;
                this.btCreateArchive.Enabled   = false;
                this.tmrUpdateProgress.Enabled = true;
                this.Text = "Creating archive....";
            }
            else
            {
                MessageBox.Show("Invalid archive path.", "Path Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 2
0
        private void bwArchiveCreate_DoWork(object sender, DoWorkEventArgs e)
        {
            ArchiveCreatorParams my_params = e.Argument as ArchiveCreatorParams;

            if (my_params != null)
            {
                #region Convert my Settings to Lib Settings
                CompressionType  c_type = CompressionType.Deflate;
                CompressionLevel c_lvl  = CompressionLevel.None;
                switch (my_params.ArchiveType)
                {
                case ArchiveTypes.Rar:
                    c_type = CompressionType.Rar;
                    break;

                case ArchiveTypes.Zip:
                    c_type = CompressionType.LZMA;
                    break;

                case ArchiveTypes.Tar:
                    c_type = CompressionType.GZip;
                    break;

                case ArchiveTypes.SevenZip:
                    c_type = CompressionType.LZMA;
                    break;

                case ArchiveTypes.GZip:
                    c_type = CompressionType.GZip;
                    break;
                }
                switch (my_params.CompressMethod)
                {
                case CompressionMethods.Store:
                    c_lvl = CompressionLevel.None;
                    break;

                case CompressionMethods.Normal:
                    c_lvl = CompressionLevel.Level4;
                    break;

                case CompressionMethods.Good:
                    c_lvl = CompressionLevel.Level6;
                    break;

                case CompressionMethods.Best:
                    c_lvl = CompressionLevel.BestCompression;
                    break;
                }


                CompressionInfo compress_info = new CompressionInfo()
                {
                    Type = c_type,
                    DeflateCompressionLevel = c_lvl,
                };
                #endregion



                using (var arc_stream = System.IO.File.Create(my_params.ArchiveFullPath))
                    using (var writer = WriterFactory.Open(arc_stream, my_params.ArchiveType, compress_info))
                    {
                        foreach (var entry in my_params.ArchiveEntries)
                        {
                            if (entry.IsValid)
                            {
                                if (entry.File != null)
                                {
                                    writer.Write(entry.File.Name, entry.File);
                                }
                                else if (entry.Directory != null)
                                {
                                    foreach (var file in entry.Directory.GetFiles("*.*", System.IO.SearchOption.AllDirectories))
                                    {
                                        string filepathindir = entry.Directory.Name + file.FullName.Substring(entry.Directory.FullName.Length);
                                        writer.Write(filepathindir, file.FullName);
                                    }
                                }
                            }
                        }
                        e.Result = my_params.ArchiveFullPath;
                    }
            }
        }