Пример #1
0
        private void KickoffZipup(string outfile)
        {
            if (File.Exists(outfile))
            {
                if ((MessageBox.Show(string.Format("The file you have specified ({0}) already exists.  Do you want to overwrite this file?", outfile), "Zipper - Zip Files", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes))
                {
                    return;
                }
                else
                {
                    File.Delete(outfile);
                }
            }
            this._saveCanceled             = false;
            this._nFilesCompleted          = 0;
            this._totalBytesAfterCompress  = 0;
            this._totalBytesBeforeCompress = 0;
            this.btnZipUp.Invoke(new ButtonClick(delegate(object sender, EventArgs e) {
                btnZipUp.Enabled       = false; this.btnZipUp.Text = "Zipping...";
                this.btnCancel.Enabled = true;
                this.lblStatus.Text    = "Loading...";
            }), new object[] { null, EventArgs.Empty });
            //this.btnZipUp.Enabled = false;
            //this.btnZipUp.Text = "Zipping...";
            //this.btnCancel.Enabled = true;
            //this.lblStatus.Text = "Loading...";
            Classes.WorkerOptions options = new Classes.WorkerOptions();
            options.ZipName = outfile;

            //_backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
            //_backgroundWorker1.WorkerSupportsCancellation = false;
            //_backgroundWorker1.WorkerReportsProgress = false;
            //this._backgroundWorker1.DoWork += new DoWorkEventHandler(this.DoSave);
            //_backgroundWorker1.RunWorkerAsync(new object[] {options, outfile});
            DoSave(null, new DoWorkEventArgs(options));
        }
Пример #2
0
        private void KickoffZipup(string outfile)
        {
            if (File.Exists(outfile))
            {
                if ((MessageBox.Show(string.Format("The file you have specified ({0}) already exists.  Do you want to overwrite this file?", outfile), "Zipper - Zip Files", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)) {
                    return;
                }
                else
                {
                    File.Delete(outfile);
                }
            }
            this._saveCanceled = false;
            this._nFilesCompleted = 0;
            this._totalBytesAfterCompress = 0;
            this._totalBytesBeforeCompress = 0;
            this.btnZipUp.Invoke(new ButtonClick(delegate (object sender, EventArgs e) {
                                                     btnZipUp.Enabled = false; this.btnZipUp.Text = "Zipping...";
                                                     this.btnCancel.Enabled = true;
                                                     this.lblStatus.Text = "Loading...";
                                                 }), new object[] {null, EventArgs.Empty});
            //this.btnZipUp.Enabled = false;
            //this.btnZipUp.Text = "Zipping...";
            //this.btnCancel.Enabled = true;
            //this.lblStatus.Text = "Loading...";
               Classes.WorkerOptions options = new Classes.WorkerOptions();
            options.ZipName = outfile;

            //_backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
            //_backgroundWorker1.WorkerSupportsCancellation = false;
            //_backgroundWorker1.WorkerReportsProgress = false;
            //this._backgroundWorker1.DoWork += new DoWorkEventHandler(this.DoSave);
            //_backgroundWorker1.RunWorkerAsync(new object[] {options, outfile});
            DoSave(null, new DoWorkEventArgs(options));
        }
Пример #3
0
        private void DoSave(object sender, DoWorkEventArgs e)
        {
            Classes.WorkerOptions options = e.Argument as Classes.WorkerOptions;
            try {
                using (ZipFile zip1 = new ZipFile()) {
                    if (MahEncType != EncryptionAlgorithm.None)
                    {
                        zip1.Encryption = MahEncType;
                        zip1.Password   = Password;
                    }
                    Taskbar.SetProgressValue(0, iTunes.LibraryPlaylist.Tracks.Count);
                    int i = 0;
                    this.btnZipUp.Invoke(new ButtonClick(delegate(object sender2, EventArgs e2) {
                        lblStatus.Text       = "Processing files...";
                        ProgressBar1.Value   = 0;
                        ProgressBar1.Maximum = iTunes.LibraryPlaylist.Tracks.Count;
                    }), new object[] { null, EventArgs.Empty });
                    #region ' Adding files to Archive '
                    if (fullBackupRadioButton.Checked)
                    {
                        foreach (IITFileOrCDTrack track in iTunes.LibraryPlaylist.Tracks)
                        {
                            if (this._saveCanceled)
                            {
                                break;
                            }
                            this.btnZipUp.Invoke(new ButtonClick(delegate(object sender2, EventArgs e2) {
                                ProgressBar1.Value++;
                            }), new object[] { null, EventArgs.Empty });

                            Taskbar.SetProgressValue(++i, iTunes.LibraryPlaylist.Tracks.Count);
                            if (!string.IsNullOrEmpty(track.Location))
                            {
                                this.btnZipUp.Invoke(new ButtonClick(delegate(object sender2, EventArgs e2) {
                                    lblStatus.Text = "Processing files... " + track.Location;
                                }), new object[] { null, EventArgs.Empty });
                                try {
                                    zip1.AddFile(track.Location, (string.IsNullOrEmpty(track.Artist) ? "Unknown Artist" : Clean(track.Artist)) + "\\" + (string.IsNullOrEmpty(track.Album) ? "Unknown Album" : Clean(track.Album)) + "\\");
                                } catch (Exception ex) {
                                    this.btnZipUp.Invoke(new ButtonClick(delegate(object sender2, EventArgs e2) {
                                        errorListBox.Items.Add("Error adding a file: " + track.Location + " " + ex.Message);
                                    }), new object[] { null, EventArgs.Empty });
                                }
                            }
                            else
                            {
                                this.btnZipUp.Invoke(new ButtonClick(delegate(object sender2, EventArgs e2) {
                                    lblStatus.Text = "Processing files... " + "found dead track!";
                                }), new object[] { null, EventArgs.Empty });
                            }
                        }
                    }
                    else
                    {
                        foreach (IITFileOrCDTrack track in iTunes.LibraryPlaylist.Tracks)
                        {
                            if (this._saveCanceled)
                            {
                                break;
                            }
                            this.btnZipUp.Invoke(new ButtonClick(delegate(object sender2, EventArgs e2) {
                                ProgressBar1.Value++;
                            }), new object[] { null, EventArgs.Empty });

                            Taskbar.SetProgressValue(++i, iTunes.LibraryPlaylist.Tracks.Count);
                            if (!string.IsNullOrEmpty(track.Location))
                            {
                                this.btnZipUp.Invoke(new ButtonClick(delegate(object sender2, EventArgs e2) {
                                    lblStatus.Text = "Processing files... " + track.Location;
                                }), new object[] { null, EventArgs.Empty });
                                try {
                                    if ((!track.Podcast) && (track.Location.EndsWith(".wav") || track.Location.EndsWith(".m4a") || track.Location.EndsWith(".mp3")))
                                    {
                                        this.btnZipUp.Invoke(new ButtonClick(delegate(object sender2, EventArgs e2) {
                                            lblStatus.Text = "Processing files... " + track.Location;
                                        }), new object[] { null, EventArgs.Empty });
                                        zip1.AddFile(track.Location, (string.IsNullOrEmpty(track.Artist) ? "Unknown Artist" : Clean(track.Artist)) + "\\" + (string.IsNullOrEmpty(track.Album) ? "Unknown Album" : Clean(track.Album)) + "\\");
                                    }
                                    else
                                    {
                                        this.btnZipUp.Invoke(new ButtonClick(delegate(object sender2, EventArgs e2) {
                                            lblStatus.Text = "Processing files... " + "skipping non-music file!";
                                        }), new object[] { null, EventArgs.Empty });
                                    }
                                } catch (Exception ex) {
                                    this.btnZipUp.Invoke(new ButtonClick(delegate(object sender2, EventArgs e2) {
                                        errorListBox.Items.Add("Error adding a file: " + track.Location + " " + ex.Message);
                                    }), new object[] { null, EventArgs.Empty });
                                }
                            }
                            else
                            {
                                this.btnZipUp.Invoke(new ButtonClick(delegate(object sender2, EventArgs e2) {
                                    lblStatus.Text = "Processing files... " + "found dead track!";
                                }), new object[] { null, EventArgs.Empty });
                            }
                        }
                    }
                    #endregion
                    Taskbar.SetProgressValue(0, zip1.EntryFileNames.Count);
                    this._entriesToZip = zip1.EntryFileNames.Count;
                    this.SetProgressBars();
                    zip1.CompressionLevel   = CompressionLevel.BestCompression;
                    zip1.SaveProgress      += new EventHandler <SaveProgressEventArgs>(this.zip1_SaveProgress);
                    zip1.UseZip64WhenSaving = Zip64Option.Always;
                    zip1.Save(options.ZipName);
                }
            }
            catch (Exception exc1)
            {
                MessageBox.Show(string.Format("Error: {0}", exc1.Message));
                this.BtnCancel_Click(null, null);
            }
        }