コード例 #1
0
        private void create_zip_directory(QueryPanelInfoEventArgs e_current)
        {
            ZipDirectory zd = (ZipDirectory)e_current.ItemCollection;

            //prepare dialog
            CreateDirectoryDialog dialog = new CreateDirectoryDialog();

            dialog.Text = CommandMenu.Text;
            dialog.labelParentDir.Text              = zd.CurrentZipDirectory + "/";
            dialog.checkBoxUseTemplate.Checked      = false;
            dialog.checkBoxUseTemplate.Enabled      = false;
            dialog.textBoxTemplateDirectory.Enabled = false;

            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            if (dialog.textBoxDirectoryName.Text.Length == 0)
            {
                Messages.ShowMessage("directory name cannot be empty");
                return;
            }

            string new_directory_name = string.Empty;

            if (zd.CurrentZipDirectory == string.Empty)
            {
                new_directory_name = dialog.textBoxDirectoryName.Text;
            }
            else
            {
                new_directory_name = zd.CurrentZipDirectory + "/" + dialog.textBoxDirectoryName.Text;
            }
            if (!new_directory_name.EndsWith("/"))
            {
                new_directory_name = new_directory_name + "/";
            }

            try
            {
                ZipEntry dir_entry = zd.ZipFile.EntryFactory.MakeDirectoryEntry(new_directory_name);
                dir_entry.Size           = 0;
                dir_entry.CompressedSize = 0; //required, else exception throws
                zd.ZipFile.BeginUpdate();
                zd.ZipFile.Add(dir_entry);
                zd.ZipFile.CommitUpdate();
                zd.Refill();
            }
            catch (Exception ex)
            {
                Messages.ShowException(ex);
            }
        }
コード例 #2
0
        protected override void internal_command_proc()
        {
            QueryPanelInfoEventArgs e = new QueryPanelInfoEventArgs();

            OnQueryCurrentPanel(e);

            if (!(e.ItemCollection is ZipDirectory))
            {
                return;
            }

            ZipDirectory  zd = (ZipDirectory)e.ItemCollection;
            List <string> initial_sources = new List <string>();
            string        initial_zip_dir = zd.CurrentZipDirectory;

            if (initial_zip_dir.StartsWith("/"))
            {
                initial_zip_dir = initial_zip_dir.Substring(1);
            }
            if ((!initial_zip_dir.EndsWith("/")) && (initial_zip_dir != string.Empty))
            {
                initial_zip_dir = initial_zip_dir + "/";
            }
            if (e.SelectedIndices.Length == 0)
            {
                if (zd.GetItemDisplayName(e.FocusedIndex) == "..")
                {
                    return;
                }
                initial_sources.Add(initial_zip_dir + zd.GetItemDisplayName(e.FocusedIndex));
            }
            else
            {
                for (int i = 0; i < e.SelectedIndices.Length; i++)
                {
                    initial_sources.Add(initial_zip_dir + zd.GetItemDisplayName(e.SelectedIndices[i]));
                }
            }

            //show dialog
            DeleteFileDialog dialog = new DeleteFileDialog();

            dialog.Text = Options.GetLiteral(Options.LANG_DELETE);
            dialog.DeleteFileOptions               = DeleteFileOptions.DeleteEmptyDirectories | DeleteFileOptions.DeleteReadonly | DeleteFileOptions.RecursiveDeleteFiles;
            dialog.textBoxMask.Text                = "*";
            dialog.checkBoxForceReadonly.Enabled   = false;
            dialog.checkBoxRecursive.Enabled       = false;
            dialog.checkBoxRemoveEmptyDirs.Enabled = false;
            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            List <ZipEntry> del_list = new List <ZipEntry>();

            create_delete_list(del_list, initial_sources, dialog.textBoxMask.Text, zd.ZipFile);

            mainForm main_win = (mainForm)Program.MainWindow;

            try
            {
                zd.ZipFile.BeginUpdate();
                for (int i = 0; i < del_list.Count; i++)
                {
                    main_win.NotifyLongOperation
                        (string.Format
                            (Options.GetLiteral(Options.LANG_DELETE_NOW_0),
                            del_list[i].Name),
                        true);
                    zd.ZipFile.Delete(del_list[i]);
                }
                main_win.NotifyLongOperation(Options.GetLiteral(Options.LANG_COMMIT_ARCHIVE_UPDATES), true);
                zd.ZipFile.CommitUpdate();

                zd.Refill();
            }
            catch (Exception ex)
            {
                Messages.ShowException(ex);
            }
            finally
            {
                main_win.NotifyLongOperation("Done", false);
            }
        }
コード例 #3
0
        protected override void internal_command_proc()
        {
            QueryPanelInfoEventArgs e_current = new QueryPanelInfoEventArgs();
            QueryPanelInfoEventArgs e_other   = new QueryPanelInfoEventArgs();

            OnQueryCurrentPanel(e_current);
            OnQueryOtherPanel(e_other);

            //int buffer_size = 0x8000;

            if (!(e_other.ItemCollection is DirectoryList))
            {
                Messages.ShowMessage
                    (Options.GetLiteral(Options.LANG_WRONG_DESTINATION));
                return;
            }

            DirectoryList         dl              = (DirectoryList)e_other.ItemCollection;
            string                dest_dir        = dl.DirectoryPath;
            ZipDirectory          zd              = (ZipDirectory)e_current.ItemCollection;
            ZipFile               source_zip_file = zd.ZipFile;
            string                zip_current_dir = zd.CurrentZipDirectory;
            ArchiveExtractOptions opts            = Options.ArchiveExtractOptions;

            //show user dialog
            ExtractDialog dialog = new ExtractDialog();

            dialog.ArchiveExtractOptions  = opts;
            dialog.textBoxSourceMask.Text = "*";
            dialog.Text = Options.GetLiteral(Options.LANG_EXTRACT);
            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            //retrieve options
            opts = dialog.ArchiveExtractOptions;
            string dest_path   = Path.Combine(dest_dir, dialog.textBoxDestination.Text);
            string source_mask = dialog.textBoxSourceMask.Text;

            Options.ArchiveExtractOptions = opts;

            //retrieve source list
            List <string> source_list = new List <string>();

            if ((e_current.SelectedIndices.Length == 0) && (e_current.FocusedIndex != 0))
            {
                //focused index==0 always ref to parent entry, so skip it
                source_list.Add(zd.GetItemDisplayName(e_current.FocusedIndex));
            }
            else
            {
                for (int i = 0; i < e_current.SelectedIndices.Length; i++)
                {
                    if (e_current.SelectedIndices[i] == 0)
                    {
                        continue;
                    }

                    source_list.Add(zd.GetItemDisplayName(e_current.SelectedIndices[i]));
                }
            }

            //prepare progress dialog

            dialog_progress = new CopyFileProgressDialog();
            dialog_progress.labelError.Visible            = false;
            dialog_progress.labelSpeed.Text               = string.Empty;
            dialog_progress.labelStatus.Text              = string.Empty;
            dialog_progress.labelStatusTotal.Text         = string.Empty;
            dialog_progress.checkBoxCloseOnFinish.Checked = Options.CopyCloseProgress;

            dialog_progress.TopLevel = true;
            int x_center = Program.MainWindow.Left + Program.MainWindow.Width / 2;
            int y_center = Program.MainWindow.Top + Program.MainWindow.Height / 2;
            int x_dialog = x_center - dialog_progress.Width / 2;
            int y_dialog = y_center - dialog_progress.Height / 2;

            if (x_dialog < 0)
            {
                x_dialog = 0;
            }
            if (x_dialog < 0)
            {
                y_dialog = 0;
            }
            dialog_progress.Show();
            dialog_progress.Location = new System.Drawing.Point(x_dialog, y_dialog);

            ZipExtractEngine engine = new ZipExtractEngine
                                          (source_list,
                                          dest_path,
                                          opts,
                                          dialog_progress,
                                          dialog.textBoxSourceMask.Text,
                                          zd.ZipFile,
                                          zd.CurrentZipDirectory);

            engine.Done            += new EventHandler(engine_Done);
            engine.ExtractItemDone += new ItemEventHandler(engine_ExtractItemDone);

            zip_directory = zd;
            zd.LockSafe   = true;

            engine.Run();

            //ZipEntry source_entry = zd[e_current.FocusedIndex];
            //if (source_entry == null)
            //{
            //    return;
            //}

            //Stream out_stream = source_zip_file.GetInputStream(source_entry);
            //string target_file_name = Path.Combine(dest_dir, source_entry.Name);
            //FileStream writer = new FileStream(target_file_name, FileMode.CreateNew, FileAccess.Write, FileShare.Read);
            //byte[] buffer = new byte[buffer_size];
            //int bytes_readed = 0;
            //while ((bytes_readed = out_stream.Read(buffer, 0, buffer_size)) != 0)
            //{
            //    writer.Write(buffer, 0, bytes_readed);
            //}
            //writer.Flush();
            //writer.Close();
            //out_stream.Close();
        }
コード例 #4
0
        private void add_to_zip(QueryPanelInfoEventArgs e_current, QueryPanelInfoEventArgs e_other)
        {
            mainForm main_window = (mainForm)Program.MainWindow;

            try
            {
                //this is sync operation
                ZipDirectory  zd = (ZipDirectory)e_other.ItemCollection;
                DirectoryList dl = (DirectoryList)e_current.ItemCollection;

                //show add zip dialog
                ArchiveAddDialog dialog = new ArchiveAddDialog();
                dialog.Text = Options.GetLiteral(Options.LANG_ARCHIVE_ADD);
                dialog.textBoxSourceMask.Text = "*";
                dialog.ArchiveAddOptions      = Options.ArchiveAddOptions;
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                ArchiveAddOptions options = dialog.ArchiveAddOptions;
                Options.ArchiveAddOptions = options;

                //notify main window
                main_window.NotifyLongOperation(Options.GetLiteral(Options.LANG_CREATING_FILE_LIST_TO_ARCHIVE), true);

                //create file list to add (only files with path)
                string[]      one_file_list = new string[0];
                List <string> root_paths    = new List <string>();
                List <string> file_list     = new List <string>();
                if (e_current.SelectedIndices.Length == 0)
                {
                    if (dl[e_current.FocusedIndex].FileName == "..")
                    {
                        Messages.ShowMessage(Options.GetLiteral(Options.LANG_WRONG_SOURCE));
                        return;
                    }
                    root_paths.Add(dl[e_current.FocusedIndex].FullName);
                }
                else
                {
                    for (int i = 0; i < e_current.SelectedIndices.Length; i++)
                    {
                        root_paths.Add(dl[e_current.SelectedIndices[i]].FullName);
                    }
                }
                foreach (string one_path in root_paths)
                {
                    if ((Directory.Exists(one_path)) && ((options & ArchiveAddOptions.Recursive) == ArchiveAddOptions.Recursive))
                    {
                        one_file_list = Directory.GetFiles(one_path, dialog.textBoxSourceMask.Text, SearchOption.AllDirectories);
                    }
                    else if ((File.Exists(one_path)) && (Wildcard.Match(dialog.textBoxSourceMask.Text, one_path)))
                    {
                        one_file_list = new string[] { one_path };
                    }
                    else
                    {
                        one_file_list = new string[0];
                    }
                    file_list.AddRange(one_file_list);
                }

                //call ZipFile.BeginUpdate
                ZipFile zf = zd.ZipFile;


                //for each source list item:
                //create zip file name from real file path, trimmed from dl current directory
                //call ZipFile.Add
                //notify main window
                string current_dir = dl.DirectoryPath;
                string zip_path    = string.Empty;
                int    zip_index   = 0;
                foreach (string one_file in file_list)
                {
                    try
                    {
                        zip_path = one_file.Substring(current_dir.Length);
                        if (zd.CurrentZipDirectory != string.Empty)
                        {
                            zip_path = zd.CurrentZipDirectory + "/" + zip_path;
                        }
                        zip_path = ZipEntry.CleanName(zip_path);

                        //check for exist
                        zip_index = zf.FindEntry(zip_path, true);
                        if (zip_index != -1)
                        {
                            //entry with same name already exists
                            if ((options & ArchiveAddOptions.NeverRewrite) == ArchiveAddOptions.NeverRewrite)
                            {
                                //skip
                                continue;
                            }
                            if ((options & ArchiveAddOptions.RewriteIfSourceNewer) == ArchiveAddOptions.RewriteIfSourceNewer)
                            {
                                //check mod date
                                if (File.GetLastWriteTime(one_file) < zf[zip_index].DateTime)
                                {
                                    continue;
                                }
                                else
                                {
                                    //remove entry
                                    zf.BeginUpdate();
                                    zf.Delete(zf[zip_index]);
                                    zf.CommitUpdate();
                                }
                            }
                            if ((options & ArchiveAddOptions.RewriteAlways) == ArchiveAddOptions.RewriteAlways)
                            {
                                zf.BeginUpdate();
                                zf.Delete(zf[zip_index]);
                                zf.CommitUpdate();
                            }
                        }

                        //open source file
                        main_window.NotifyLongOperation
                            (string.Format
                                (Options.GetLiteral(Options.LANG_ARCHIVING_0_1),
                                one_file,
                                zip_path),
                            true);
                        InternalStreamSource static_source = null;
                        try
                        {
                            //TODO избавиться от флага SaveAttributes
                            //будем всегда сохранять - DONE
                            zf.BeginUpdate();
                            zf.Add(one_file, zip_path);
                            main_window.NotifyLongOperation(Options.GetLiteral(Options.LANG_COMMIT_ARCHIVE_UPDATES), true);
                            zf.CommitUpdate();
                        }
                        catch (Exception ex)
                        {
                            if ((options & ArchiveAddOptions.SupressErrors) != ArchiveAddOptions.SupressErrors)
                            {
                                string err_message = string.Format
                                                         (Options.GetLiteral(Options.LANG_FAILED_ARCHIVE_0),
                                                         zip_path);
                                if (Messages.ShowExceptionContinue(ex, err_message))
                                {
                                    continue;
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        finally
                        {
                            if (static_source != null)
                            {
                                static_source.Close();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if ((options & ArchiveAddOptions.SupressErrors) != ArchiveAddOptions.SupressErrors)
                        {
                            string err_message = string.Format
                                                     (Options.GetLiteral(Options.LANG_FAILED_ARCHIVE_0),
                                                     zip_path);
                            if (Messages.ShowExceptionContinue(ex, err_message))
                            {
                                continue;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }//end of foreach

                //Refill zd
                zd.Refill();

                //notify main window when done
            }
            catch (Exception ex)
            {
                Messages.ShowException(ex);
            }
            finally
            {
                main_window.NotifyLongOperation("Done", false);
            }
        }