Ejemplo n.º 1
0
        protected override void internal_command_proc()
        {
            var e_current = new QueryPanelInfoEventArgs();
            var e_other   = new QueryPanelInfoEventArgs();

            OnQueryCurrentPanel(e_current);
            OnQueryOtherPanel(e_other);

            if (e_current.FocusedIndex == -1)
            {
                return;
            }

            if (e_other.ItemCollection is FtpDirectoryList)
            {
                //do ftp download
                upload_to_ftp(e_current, e_other);
                return;
            }
            else if (e_other.ItemCollection is ZipDirectory)
            {
                add_to_zip(e_current, e_other);
                return;
            }
            else if (!(e_other.ItemCollection is DirectoryList))
            {
                Messages.ShowMessage(Options.GetLiteral(Options.LANG_WRONG_DESTINATION));
                return;
            }

            //see source
            var source_list = new List <FileInfoEx>();
            var dl_source   = (DirectoryList)e_current.ItemCollection;
            var dl_target   = (DirectoryList)e_other.ItemCollection;
            var sel_indices = e_current.SelectedIndices;

            if (sel_indices.Length == 0)
            {
                if (dl_source.GetItemDisplayNameLong(e_current.FocusedIndex) == "..")
                {
                    return;
                }
                //get focused entry
                source_list.Add(dl_source[e_current.FocusedIndex]);
            }
            else
            {
                //get source from selection
                for (var i = 0; i < sel_indices.Length; i++)
                {
                    source_list.Add(dl_source[sel_indices[i]]);
                }
            }

            var dest_path = dl_target.DirectoryPath;

            //prepare copy dialog
            var dialog = new CopyFileDialog();

            dialog.CopyEngineOptions = Options.CopyEngineOptions;
            dialog.Text = Options.GetLiteral(Options.LANG_COPY);

            dialog.textBoxSourceMask.Text = "*";

            dialog.textBoxDestination.Text = string.Empty;

            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            //save user selection
            var engine_opts = dialog.CopyEngineOptions;

            Options.CopyEngineOptions = engine_opts;

            //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;
            var x_center = Program.MainWindow.Left + Program.MainWindow.Width / 2;
            var y_center = Program.MainWindow.Top + Program.MainWindow.Height / 2;
            var x_dialog = x_center - dialog_progress.Width / 2;
            var 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);

            //prepare copy engine
            var dest_remote = true;

            try
            {
                var dest_info = new FileInfoEx();
                FileInfoEx.TryGet(dest_path, ref dest_info);
                var chars = dest_info.GetDeviceInfo().Characteristics;
                if (((chars & NT_FS_DEVICE_CHARACTERISTICS.Remote) == NT_FS_DEVICE_CHARACTERISTICS.Remote) ||
                    ((chars & NT_FS_DEVICE_CHARACTERISTICS.Removable) == NT_FS_DEVICE_CHARACTERISTICS.Removable) ||
                    ((chars & NT_FS_DEVICE_CHARACTERISTICS.WebDAV) == NT_FS_DEVICE_CHARACTERISTICS.WebDAV))
                {
                    dest_remote = true;
                }
                else
                {
                    dest_remote = false;
                }
            }
            catch (Exception) { }

            dest_path = dialog.textBoxDestination.Text == string.Empty ? dest_path : Path.Combine(dest_path, dialog.textBoxDestination.Text);
            var copy_engine = new CopyFileEngine
                                  (source_list, dest_path, engine_opts, dialog_progress, dialog.textBoxSourceMask.Text, dest_remote);

            copy_engine.Done         += new EventHandler(copy_engine_Done);
            copy_engine.CopyItemDone += new ItemEventHandler(copy_engine_CopyItemDone);

            //and do job
            copy_engine.Do();
        }
        protected override void internal_command_proc()
        {
            QueryPanelInfoEventArgs e_current = new QueryPanelInfoEventArgs();
            QueryPanelInfoEventArgs e_other   = new QueryPanelInfoEventArgs();

            OnQueryCurrentPanel(e_current);
            OnQueryOtherPanel(e_other);

            if (e_current.FocusedIndex == -1)
            {
                return;
            }
            if (!(e_other.ItemCollection is DirectoryList))
            {
                Messages.ShowMessage("Cannot copy to current destination.");
                return;
            }

            //see source
            source_list = new List <string>();
            DirectoryList dl_source = (DirectoryList)e_current.ItemCollection;
            DirectoryList dl_target = (DirectoryList)e_other.ItemCollection;

            int[] sel_indices = e_current.SelectedIndices;
            if (sel_indices.Length == 0)
            {
                if (dl_source.GetItemDisplayNameLong(e_current.FocusedIndex) == "..")
                {
                    return;
                }
                //get focused entry
                source_list.Add(Path.Combine(dl_source.DirectoryPath, dl_source.GetItemDisplayNameLong(e_current.FocusedIndex)));
            }
            else
            {
                //get source from selection
                for (int i = 0; i < sel_indices.Length; i++)
                {
                    source_list.Add(Path.Combine(dl_source.DirectoryPath, dl_source.GetItemDisplayNameLong(sel_indices[i])));
                }
            }

            string dest_path = dl_target.DirectoryPath;

            //prepare copy dialog
            CopyFileDialog dialog = new CopyFileDialog();

            dialog.CopyEngineOptions = engine_opts;
            dialog.Text = "Copy";
            if (source_list.Count == 1)
            {
                dialog.labelSourceFile.Text = source_list[0];
            }
            else
            {
                dialog.labelSourceFile.Text = string.Format("{0} entries", source_list.Count);
            }
            dialog.textBoxDestination.Text = dest_path;

            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            //save user selection
            engine_opts = dialog.CopyEngineOptions;
            Options.CopyEngineOptions = engine_opts;

            //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);

            //prepare copy engine
            CopyFileEngine copy_engine = new CopyFileEngine
                                             (source_list.ToArray(), dialog.textBoxDestination.Text, engine_opts, dialog_progress);

            copy_engine.Done         += new EventHandler(copy_engine_Done);
            copy_engine.CopyItemDone += new ItemEventHandler(copy_engine_CopyItemDone);

            //and do job
            copy_engine.Do();
        }