示例#1
0
        public override void GetChildCollection(int index, ref FileCollectionBase new_collection, ref bool use_new, ref string preferred_focused_text)
        {
            if (!GetItemIsContainer(index))
            {
                use_new = false;
                return;
            }

            //returns DirectoryList of parent folder
            string target_dir = Path.GetDirectoryName(file_name_full);

            new_collection = new DirectoryList(0, false, target_dir);
            bool err = false;

            try
            {
                new_collection.Refill();
            }
            catch (Exception ex)
            {
                err = true;
                Messages.ShowException(ex);
            }

            if (err)
            {
                use_new = false;
            }
            else
            {
                use_new = true;
                preferred_focused_text = Path.GetFileName(file_name_full);
            }
        }
        protected override void internal_command_proc()
        {
            QueryPanelInfoEventArgs e_current = new QueryPanelInfoEventArgs();
            QueryPanelInfoEventArgs e_other   = new QueryPanelInfoEventArgs();

            OnQueryCurrentPanel(e_current);
            OnQueryOtherPanel(e_other);
            DirectoryList dl_current = (DirectoryList)e_current.ItemCollection;
            DirectoryList dl_other   = null;

            if (e_other.ItemCollection is DirectoryList)
            {
                dl_other = (DirectoryList)e_other.ItemCollection;
            }

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

            dialog.Text = "Create directory";
            dialog.labelParentDir.Text              = dl_current.DirectoryPath + Path.DirectorySeparatorChar;
            dialog.checkBoxUseTemplate.Checked      = false;
            dialog.textBoxTemplateDirectory.Enabled = false;
            if ((dl_other == null) || (e_other.FocusedIndex <= 0))
            {
                dialog.checkBoxUseTemplate.Checked      = false;
                dialog.textBoxTemplateDirectory.Enabled = false;
            }
            else
            {
                dialog.textBoxTemplateDirectory.Text = Path.Combine(dl_other.DirectoryPath, dl_other.GetItemDisplayNameLong(e_other.FocusedIndex));
            }

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

            if (dialog.textBoxDirectoryName.Text == string.Empty)
            {
                Messages.ShowMessage("Directory exists.");
                return;
            }

            string new_directory_name = Path.Combine(dl_current.DirectoryPath, dialog.textBoxDirectoryName.Text);
            string template_dir       = string.Empty;

            if (dialog.checkBoxUseTemplate.Checked)
            {
                template_dir = dialog.textBoxTemplateDirectory.Text;
            }

            try
            {
                Wrapper.CreateDirectoryTree(new_directory_name, template_dir);
            }
            catch (Exception ex)
            {
                Messages.ShowException(ex, string.Format("Failed to create directory '{0}'.", new_directory_name));
            }
        }
示例#3
0
        protected override void internal_command_proc()
        {
            QueryPanelInfoEventArgs e = new QueryPanelInfoEventArgs();

            OnQueryCurrentPanel(e);

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

            try
            {
                DirectoryList   dl   = (DirectoryList)e.ItemCollection;
                VolumeSpaceInfo info = WinAPiFSwrapper.GetVolumeSpaceInfo(dl.DirectoryPath);

                VolumeSpaceInfoDialog dialog = new VolumeSpaceInfoDialog();
                dialog.textBoxTotalSize.Text      = IOhelper.SizeToString(info.TotalNumberOfBytes);
                dialog.textBoxTotalAvailable.Text = IOhelper.SizeToString(info.FreeBytesAvailable);
                dialog.Text = dl.DirectoryPath;
                dialog.ShowDialog();
            }
            catch (Exception ex)
            {
                Messages.ShowException(ex);
            }
        }
示例#4
0
        public override void GetChildCollection(int index, ref FileCollectionBase new_collection, ref bool use_new, ref string preferred_focus)
        {
            internal_list.Keys[index].Update();

            if (!internal_list.Keys[index].DeviceReady)
            {
                Messages.ShowMessage(string.Format("Device {0} not ready.", internal_list.Keys[index].RootPathName));
                use_new = false;
                return;
            }


            preferred_focus = string.Empty;
            new_collection  = new DirectoryList(0, false, internal_list.Keys[index].RootPathName);
            try
            {
                new_collection.Refill();
                new_collection.MainWindow = this.MainWindow;
                use_new = true;
            }
            catch (Exception ex)
            {
                Messages.ShowException(ex);
            }
        }
示例#5
0
        private void create_fs_directory(QueryPanelInfoEventArgs e_current, QueryPanelInfoEventArgs e_other)
        {
            var           dl_current = (DirectoryList)e_current.ItemCollection;
            DirectoryList dl_other   = null;

            if (e_other.ItemCollection is DirectoryList)
            {
                dl_other = (DirectoryList)e_other.ItemCollection;
            }

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

            dialog.Text = CommandMenu.Text;
            dialog.labelParentDir.Text              = dl_current.DirectoryPath + Path.DirectorySeparatorChar;
            dialog.checkBoxUseTemplate.Checked      = false;
            dialog.textBoxTemplateDirectory.Enabled = false;
            if ((dl_other == null) || (e_other.FocusedIndex <= 0))
            {
                dialog.checkBoxUseTemplate.Checked      = false;
                dialog.textBoxTemplateDirectory.Enabled = false;
            }
            else
            {
                dialog.textBoxTemplateDirectory.Text = Path.Combine(dl_other.DirectoryPath, dl_other.GetItemDisplayNameLong(e_other.FocusedIndex));
            }

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

            if (dialog.textBoxDirectoryName.Text == string.Empty)
            {
                Messages.ShowMessage(Options.GetLiteral(Options.LANG_DIRECTORY_EXISTS));
                return;
            }

            var new_directory_name = Path.Combine(dl_current.DirectoryPath, dialog.textBoxDirectoryName.Text);
            var template_dir       = string.Empty;

            if (dialog.checkBoxUseTemplate.Checked)
            {
                template_dir = dialog.textBoxTemplateDirectory.Text;
            }

            try
            {
                WinAPiFSwrapper.CreateDirectoryTree(new_directory_name, template_dir);
            }
            catch (Exception ex)
            {
                Messages.ShowException
                    (ex,
                    string.Format
                        (Options.GetLiteral(Options.LANG_CANNOT_CREATE_DIRECTORY_0),
                        new_directory_name));
            }
        }
示例#6
0
        private void jump_to(mFilePanel target_panel)
        {
            var dial = new JumpToDialog();

            dial.Text = Options.GetLiteral(Options.LANG_WHERE_TO_JUMP);

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

            var path = dial.textBoxPath.Text;
            FileCollectionBase new_source = null;

            try
            {
                //parse path
                if (path.StartsWith(@"\\"))
                {
                    //assume smb path

                    var target_res = WinApiWNETwrapper.GetResourceInfo(path);
                    if (target_res.dwDisplayType == netCommander.WNet.ResourceDisplayType.SHARE)
                    {
                        //it is network share - show directory list
                        new_source = new DirectoryList(0, false, path);
                    }
                    else if ((target_res.dwUsage & ResourceUsage.CONTAINER) != ResourceUsage.CONTAINER)
                    {
                        //target_res is not container - try show parent
                        target_res = WinApiWNETwrapper.GetParentResource(target_res);
                        new_source = new WnetResourceList(0, false, target_res);
                    }
                    else
                    {
                        //show target_resource
                        new_source = new WnetResourceList(0, false, target_res);
                    }
                }//end of stratsWith("\\") brunch
                else
                {
                    new_source = new DirectoryList(0, false, path);
                }

                //now refill source
                new_source.MainWindow = this;
                new_source.Refill();
                target_panel.Source = new_source;
                target_panel.Refresh();
            }
            catch (Exception ex)
            {
                Messages.ShowException(ex, string.Format(Options.GetLiteral(Options.LANG_CANNOT_SHOW_0), path));
            }
        }
示例#7
0
        protected override void internal_command_proc()
        {
            QueryPanelInfoEventArgs e = new QueryPanelInfoEventArgs();

            OnQueryCurrentPanel(e);

            if (e.FocusedIndex < 0)
            {
                return;
            }

            DirectoryList dl_list = (DirectoryList)e.ItemCollection;

            if (dl_list.GetItemDisplayNameLong(e.FocusedIndex) == "..")
            {
                return;
            }

            //check volume caps
            string     root_path = Path.GetPathRoot(dl_list.DirectoryPath);
            VolumeInfo vi        = new VolumeInfo(root_path);

            if ((vi.FileSystemFlags & VolumeCaps.NamedStreams) != VolumeCaps.NamedStreams)
            {
                Messages.ShowMessage
                    (string.Format
                        ("File system on drive {0} not support named streams",
                        root_path));
                return;
            }

            StreamList new_source = new StreamList
                                        (Path.Combine(dl_list.DirectoryPath, dl_list.GetItemDisplayNameLong(e.FocusedIndex)),
                                        false,
                                        0,
                                        false);

            try
            {
                new_source.Refill();
            }
            catch (Exception ex)
            {
                Messages.ShowException(ex);
                return;
            }

            SetNewSourceEventArgs e_new_source = new SetNewSourceEventArgs
                                                     (new_source,
                                                     false,
                                                     string.Empty);

            OnSetNewSource(e_new_source);
        }
示例#8
0
        private void show_directory(mFilePanel target_panel, string dir_path)
        {
            try
            {
                DirectoryList old_dl = null;

                if ((target_panel.Source != null) && (target_panel.Source is DirectoryList))
                {
                    old_dl = (DirectoryList)target_panel.Source;
                }

                DirectoryList dl = null;

                if (old_dl == null)
                {
                    dl = new DirectoryList
                             (0,
                             false,
                             dir_path);
                }
                else
                {
                    dl = new DirectoryList
                             (old_dl.SortCriteria,
                             old_dl.SortReverse,
                             dir_path);
                }

                dl.MainWindow       = this;
                target_panel.Source = dl;
                try
                {
                    dl.Refill();
                }
                catch (Exception ex_inner)
                {
                    if (old_dl != null)
                    {
                        target_panel.Source = old_dl;
                    }
                    throw ex_inner;
                }
            }
            catch (Exception ex)
            {
                Messages.ShowException(ex);
            }
        }
示例#9
0
        private void find_files(mFilePanel target_panel)
        {
            if (target_panel == null)
            {
                target_panel = doublePanel1.PanelActive;
            }

            DirectoryListFilterDialog filter_dialog = null;
            var filter = new DirectoryListFilter();

            filter.Load();

            if (doublePanel1.PanelActive.Source is DirectoryList)
            {
                filter.InCurrentDirectory            = true;
                filter.InCurrentDirectoryWithSubdirs = true;
                filter.CurrentDirectory = ((DirectoryList)doublePanel1.PanelActive.Source).DirectoryPath;
                filter.CurrentDrive     = Path.GetPathRoot(filter.CurrentDirectory);
            }

            filter_dialog      = new DirectoryListFilterDialog(true, filter);
            filter_dialog.Text = Options.GetLiteral(Options.LANG_FIND);
            if (filter_dialog.ShowDialog() == DialogResult.OK)
            {
                var result_dialog = new DirectorySearchResultDialog(filter_dialog.DirectoryListFilter);
                //result_dialog.BeginSearch(filter_dialog.DirectoryListFilter);
                if (result_dialog.ShowDialog() == DialogResult.OK)
                {
                    //go to...
                    var sel_file_name = result_dialog.SelectedResult;
                    if (string.IsNullOrEmpty(sel_file_name))
                    {
                        return;
                    }
                    var sel_dir  = Path.GetDirectoryName(sel_file_name);
                    var sel_file = Path.GetFileName(sel_file_name);
                    var dl       = new DirectoryList(target_panel.Source.SortCriteria, target_panel.Source.SortReverse, sel_dir);
                    target_panel.Source = dl;
                    dl.Refill();
                    var foc_index = dl.FindIndexOfName(sel_file);
                    if (foc_index != -1)
                    {
                        doublePanel1.PanelActive.FocusedIndex = foc_index;
                    }
                }
            }
        }
示例#10
0
        private void button1_Click(object sender, EventArgs e)
        {
            //DriveList dl = new DriveList(1, false);


            //mFilePanel1.Source = dl;
            //dl.Refill();

            //DirectoryList dirL = new DirectoryList(4, false, @"c:\temp");
            //dirL.Refill();

            DirectoryList dirL = new DirectoryList(0, false, @"d:\temp");

            mFilePanel1.Source = dirL;
            dirL.Refill();

            //DirectoryListFilterDialog f = new DirectoryListFilterDialog();
            //f.ShowDialog();
        }
示例#11
0
        public override void GetChildCollection(int index, ref FileCollectionBase new_collection, ref bool use_new, ref string preferred_focused_text)
        {
            if (index == 0)
            {
                //return container from wnet
                try
                {
                    NETRESOURCE      container = WinApiWNETwrapper.GetParentResource(server_ref);
                    WnetResourceList wnet_list = new WnetResourceList(SortCriteria, SortReverse, container);
                    preferred_focused_text = server_ref.lpRemoteName;
                    wnet_list.Refill();
                    use_new        = true;
                    new_collection = wnet_list;
                }
                catch (Exception ex)
                {
                    Messages.ShowException(ex);
                }
                return;
            }

            //else return DirectoryList
            try
            {
                string target_dir = string.Format
                                        ("{0}\\{1}",
                                        server_ref.lpRemoteName,
                                        internal_list.Keys[index - 1].shi1_netname);
                DirectoryList dir_list = new DirectoryList(SortCriteria, SortReverse, target_dir);
                dir_list.Refill();
                use_new        = true;
                new_collection = dir_list;
            }
            catch (Exception ex)
            {
                Messages.ShowException(ex);
            }
            return;
        }
示例#12
0
        protected override void internal_command_proc()
        {
            QueryPanelInfoEventArgs e = new QueryPanelInfoEventArgs();

            OnQueryCurrentPanel(e);

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

            if (e.ItemCollection == null)
            {
                return;
            }

            DirectoryList dl          = (DirectoryList)e.ItemCollection;
            string        target_file = Path.Combine(dl.DirectoryPath, dl.GetItemDisplayNameLong(e.FocusedIndex));

            AFSdialog dialog = new AFSdialog(target_file);

            dialog.ShowDialog();
        }
        protected override void internal_command_proc()
        {
            QueryPanelInfoEventArgs e = new QueryPanelInfoEventArgs();

            OnQueryCurrentPanel(e);



            DirectoryList dl = (DirectoryList)e.ItemCollection;

            if (dl.GetItemDisplayNameLong(e.FocusedIndex) == "..")
            {
                return;
            }

            string file_name = Path.Combine(dl.DirectoryPath, dl.GetItemDisplayNameLong(e.FocusedIndex));

            FileInformationDialog dialog = new FileInformationDialog();

            try
            {
                if (dl.MainWindow != null)
                {
                    dl.MainWindow.NotifyLongOperation(Options.GetLiteral(Options.LANG_QUERY_PROPERTIES), true);
                }

                dialog.FillContents(file_name);
            }
            finally
            {
                if (dl.MainWindow != null)
                {
                    dl.MainWindow.NotifyLongOperation(string.Empty, false);
                }
            }
            dialog.ShowDialog();
        }
        protected override void internal_command_proc()
        {
            try
            {
                QueryPanelInfoEventArgs e = new QueryPanelInfoEventArgs();
                OnQueryCurrentPanel(e);

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

                DirectoryList dl        = (DirectoryList)e.ItemCollection;
                string        file_name = dl[e.FocusedIndex].FullName;

                FileViewEditDialog dialog = new FileViewEditDialog();
                dialog.OpenView(file_name);
                dialog.Show();
            }
            catch (Exception ex)
            {
                Messages.ShowException(ex);
            }
        }
        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(Options.GetLiteral(Options.LANG_WRONG_DESTINATION));
                return;
            }

            FtpDirectoryList ftp_list = (FtpDirectoryList)e_current.ItemCollection;
            DirectoryList    dir_list = (DirectoryList)e_other.ItemCollection;

            List <FtpEntryInfo> sel_source = new List <FtpEntryInfo>();

            if (e_current.SelectedIndices.Length == 0)
            {
                sel_source.Add(ftp_list[e_current.FocusedIndex]);
            }
            else
            {
                for (int i = 0; i < e_current.SelectedIndices.Length; i++)
                {
                    sel_source.Add(ftp_list[e_current.SelectedIndices[i]]);
                }
            }

            string destination = dir_list.DirectoryPath;

            //prepare and show user dialog
            FtpTransferOptions ftp_trans_opts = Options.FtpDownloadOptions;
            FtpTransferDialog  dialog         = new FtpTransferDialog();

            dialog.FtpTransferOptions      = ftp_trans_opts;
            dialog.textBoxDestination.Text = destination;

            if (sel_source.Count == 1)
            {
                dialog.labelSourceFile.Text =
                    ftp_list.Connection.Options.ServerName + FtpPath.Combine(sel_source[0].DirectoryPath, sel_source[0].EntryName);
            }
            else
            {
                dialog.labelSourceFile.Text =
                    string.Format
                        ("{0} items from {1}",
                        sel_source.Count,
                        ftp_list.Connection.Options.ServerName);
            }

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

            //retrieve user selection
            ftp_trans_opts = dialog.FtpTransferOptions;
            destination    = dialog.textBoxDestination.Text;

            //save user selection
            Options.FtpDownloadOptions = ftp_trans_opts;

            //prepare progress window
            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 doanload engine
            FtpDownloadEngine engine = new FtpDownloadEngine
                                           (sel_source.ToArray(),
                                           destination,
                                           ftp_list.Connection,
                                           ftp_trans_opts,
                                           dialog_progress);

            engine.Done             += new EventHandler(engine_Done);
            engine.DownloadItemDone += new ItemEventHandler(engine_DownloadItemDone);

            engine.Run();
        }
示例#16
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);
            }
        }
示例#17
0
        private void upload_to_ftp(QueryPanelInfoEventArgs e_current, QueryPanelInfoEventArgs e_other)
        {
            DirectoryList    source_directory = (DirectoryList)e_current.ItemCollection;
            FtpDirectoryList destination_ftp  = (FtpDirectoryList)e_other.ItemCollection;

            List <string> source_list = new List <string>();

            if (e_current.SelectedIndices.Length == 0)
            {
                if (source_directory.GetItemDisplayNameLong(e_current.FocusedIndex) == "..")
                {
                    return;
                }

                source_list.Add
                    (Path.Combine
                        (source_directory.DirectoryPath,
                        source_directory.GetItemDisplayNameLong(e_current.FocusedIndex)));
            }
            else
            {
                for (int i = 0; i < e_current.SelectedIndices.Length; i++)
                {
                    source_list.Add
                        (Path.Combine
                            (source_directory.DirectoryPath,
                            source_directory.GetItemDisplayNameLong(e_current.SelectedIndices[i])));
                }
            }

            string        dest_path = destination_ftp.DirectoryPath;
            FtpConnection ftp_conn  = destination_ftp.Connection;

            //show upload dialog
            FtpTransferOptions ftp_trans_opts = Options.FtpUploadOptions;
            FtpTransferDialog  dialog         = new FtpTransferDialog();

            dialog.FtpTransferOptions      = ftp_trans_opts;
            dialog.textBoxDestination.Text = dest_path;
            dialog.Text = Options.GetLiteral(Options.LANG_UPLOAD);
            if (source_list.Count == 1)
            {
                dialog.labelSourceFile.Text =
                    source_list[0];
            }
            else
            {
                dialog.labelSourceFile.Text =
                    string.Format
                        ("{0} " + Options.GetLiteral(Options.LANG_ENTRIES),
                        source_list.Count);
            }

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

            //retrieve user selection
            ftp_trans_opts = dialog.FtpTransferOptions;
            dest_path      = dialog.textBoxDestination.Text;

            //save user selection
            Options.FtpUploadOptions = ftp_trans_opts;


            //prepare progress window
            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 upload engine
            FtpUploadEngine upload_engine = new FtpUploadEngine
                                                (source_list.ToArray(),
                                                dest_path,
                                                ftp_conn,
                                                ftp_trans_opts,
                                                dialog_progress);

            upload_engine.Done           += new EventHandler(upload_engine_Done);
            upload_engine.UploadItemDone += new ItemEventHandler(upload_engine_UploadItemDone);

            upload_engine.Run();

            //ftp_conn.ClearCache(dest_path);
        }
        protected override void internal_command_proc()
        {
            abort = false;
            QueryPanelInfoEventArgs e = new QueryPanelInfoEventArgs();

            OnQueryCurrentPanel(e);

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

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

            DirectoryList dl = (DirectoryList)e.ItemCollection;

            main_window = dl.MainWindow;
            int[] sel_indices = e.SelectedIndices;
            //we must cache selection
            //becouse indexes will be change while deleting
            List <FileInfoEx> sel_files = new List <FileInfoEx>();

            if (sel_indices.Length > 0)
            {
                for (int i = 0; i < sel_indices.Length; i++)
                {
                    sel_files.Add(dl[sel_indices[i]]);
                }
            }
            else
            {
                if (dl[e.FocusedIndex].FileName == "..")
                {
                    Messages.ShowMessage(Options.GetLiteral(Options.LANG_WRONG_DESTINATION));
                    return;
                }
                sel_files.Add(dl[e.FocusedIndex]);
            }

            //now we have list for delete

            opts = Options.DeleteFileOptions;

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

            dialog.Text = CommandMenu.Text;
            dialog.DeleteFileOptions = opts;
            dialog.textBoxMask.Text  = "*";

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

            opts = dialog.DeleteFileOptions;
            Options.DeleteFileOptions = opts;
            delete_mask = dialog.textBoxMask.Text;

            if (sel_files.Count == 1)
            {
                delete_entry(sel_files[0]);
            }
            else
            {
                foreach (FileInfoEx info in sel_files)
                {
                    if (abort)
                    {
                        break;
                    }
                    delete_entry(info);
                }
            }
            if (main_window != null)
            {
                main_window.NotifyLongOperation(string.Empty, false);
            }
        }
示例#19
0
        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(Options.GetLiteral(Options.LANG_WRONG_DESTINATION));
                return;
            }

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

            int[] sel_indices = e_current.SelectedIndices;
            if (sel_indices.Length == 0)
            {
                if (dl_source.GetItemDisplayNameLong(e_current.FocusedIndex) == "..")
                {
                    return;
                }

                source_list.Add(dl_source[e_current.FocusedIndex]);
            }
            else
            {
                for (int i = 0; i < sel_indices.Length; i++)
                {
                    source_list.Add(dl_source[sel_indices[i]]);
                }
            }

            //prepare move dialog
            MoveFileDialog dialog = new MoveFileDialog();

            dialog.MoveEngineOptions = Options.MoveEngineOptions;
            dialog.Text                    = Options.GetLiteral(Options.LANG_MOVE_RENAME);
            dialog.textBoxMask.Text        = "*";
            dialog.textBoxDestination.Text = string.Empty;

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

            MoveEngineOptions move_opts = dialog.MoveEngineOptions;

            Options.MoveEngineOptions = move_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;

            //calc location - it is not modal!
            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;
            }

            //show progress
            dialog_progress.Show();
            dialog_progress.Location = new System.Drawing.Point(x_dialog, y_dialog);

            //prepare move engine
            MoveFileEngine move_engine = new MoveFileEngine
                                             (source_list,
                                             dialog.textBoxDestination.Text == string.Empty ? dl_target.DirectoryPath : Path.Combine(dl_target.DirectoryPath, dialog.textBoxDestination.Text),
                                             dialog.textBoxMask.Text,
                                             move_opts,
                                             dialog_progress);

            move_engine.Done += new EventHandler(move_engine_Done);

            //and run
            move_engine.Do();
        }
示例#20
0
        private void execute(UserMenuEntry entry)
        {
            string command_expanded = entry.CommandText;

            try
            {
                QueryPanelInfoEventArgs e_current = new QueryPanelInfoEventArgs();
                QueryPanelInfoEventArgs e_other   = new QueryPanelInfoEventArgs();
                OnQueryCurrentPanel(e_current);
                OnQueryOtherPanel(e_other);
                string repl_text = string.Empty;

                //process %1
                if (command_expanded.Contains("%1"))
                {
                    repl_text = e_current.ItemCollection.GetCommandlineTextShort(e_current.FocusedIndex);
                    if (repl_text.Contains(" "))
                    {
                        repl_text = '"' + repl_text + '"';
                    }
                    command_expanded = command_expanded.Replace("%1", repl_text);
                }

                //process %2
                if (command_expanded.Contains("%2"))
                {
                    repl_text = e_current.ItemCollection.GetCommandlineTextLong(e_current.FocusedIndex);
                    if (repl_text.Contains(" "))
                    {
                        repl_text = '"' + repl_text + '"';
                    }
                    command_expanded = command_expanded.Replace("%2", repl_text);
                }

                //process %3
                if (command_expanded.Contains("%3"))
                {
                    DirectoryList dl = (DirectoryList)e_other.ItemCollection;
                    repl_text = dl.DirectoryPath;
                    if (repl_text.Contains(" "))
                    {
                        repl_text = '"' + repl_text + '"';
                    }
                    command_expanded = command_expanded.Replace("%3", repl_text);
                }

                string reg_pattern = Options.REGEX_PARSE_COMMAND;
                Regex  rex         = new Regex(reg_pattern);

                string[] splitted = rex.Split(command_expanded, 2);
                if (splitted.Length < 2)
                {
                    throw new ApplicationException(Options.GetLiteral(Options.LANG_CANNOT_PARSE_COMMAND_LINE));
                }

                string command_name = splitted[1];
                string command_args = splitted.Length > 2 ? splitted[2] : string.Empty;

                ProcessStartInfo psi = new ProcessStartInfo();
                psi.Arguments        = command_args;
                psi.CreateNoWindow   = (entry.Options & ProcessStartFlags.NoWindow) == ProcessStartFlags.NoWindow;
                psi.ErrorDialog      = false;
                psi.FileName         = command_name;
                psi.UseShellExecute  = (entry.Options & ProcessStartFlags.UseShellexecute) == ProcessStartFlags.UseShellexecute;
                psi.WorkingDirectory = Directory.GetCurrentDirectory();

                Process p = new Process();
                p.StartInfo = psi;
                p.Start();
            }
            catch (Exception ex)
            {
                Messages.ShowException
                    (ex,
                    string.Format
                        (Options.GetLiteral(Options.LANG_CANNOT_EXECUTE_0),
                        command_expanded));
            }
        }
        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();
        }
        protected override void internal_command_proc()
        {
            try
            {
                QueryPanelInfoEventArgs e = new QueryPanelInfoEventArgs();
                OnQueryCurrentPanel(e);
                if (e.FocusedIndex == -1)
                {
                    return;
                }

                string        target_file = string.Empty;
                DirectoryList dl          = (DirectoryList)e.ItemCollection;
                int[]         sel_indices = e.SelectedIndices;
                bool          group_mode  = (sel_indices.Length > 1);
                //we need cache list of selected files
                //becouse e.ItemCollection can change while processing (sort!)
                List <string> sel_names = new List <string>();
                for (int i = 0; i < sel_indices.Length; i++)
                {
                    sel_names.Add(e.ItemCollection.GetItemDisplayNameLong(sel_indices[i]));
                }


                if (!group_mode)
                {
                    if (sel_indices.Length == 1)
                    {
                        target_file = Path.Combine(dl.DirectoryPath, dl.GetItemDisplayNameLong(sel_indices[0]));
                    }
                    else
                    {
                        target_file = Path.Combine(dl.DirectoryPath, dl.GetItemDisplayNameLong(e.FocusedIndex));
                    }
                }
                if (target_file.EndsWith(".."))
                {
                    target_file = dl.DirectoryPath + Path.DirectorySeparatorChar;
                }

                FileSystemInfo target_fsi = null;
                if (!group_mode)
                {
                    target_fsi = IOhelper.GetFileSystemInfo(target_file);
                }

                TouchFileDialog dialog = new TouchFileDialog();

                dialog.Text = Options.GetLiteral(Options.LANG_TOUCH);

                if (!group_mode)
                {
                    dialog.textBoxFileName.Text             = target_file;
                    dialog.dateTimePickerAccess.Value       = target_fsi.LastAccessTime;
                    dialog.dateTimePickerCreation.Value     = target_fsi.CreationTime;
                    dialog.dateTimePickerModification.Value = target_fsi.LastWriteTime;
                }
                else
                {
                    dialog.textBoxFileName.Text    = string.Format("{0} " + Options.GetLiteral(Options.LANG_ENTRIES), sel_indices.Length);
                    dialog.textBoxFileName.Enabled = false;
                }

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

                if (!group_mode)
                {
                    if (dialog.textBoxFileName.Text != target_file)
                    {
                        //try create new file
                        netCommander.FileSystemEx.WinAPiFSwrapper.CreateNewEmptyFile(dialog.textBoxFileName.Text);
                        //if success
                        target_fsi = new FileInfo(dialog.textBoxFileName.Text);
                    }
                }

                //set times
                if (group_mode)
                {
                    foreach (string one_name in sel_names)
                    {
                        try
                        {
                            target_file = Path.Combine(dl.DirectoryPath, one_name);
                            target_fsi  = IOhelper.GetFileSystemInfo(target_file);
                            if (dialog.dateTimePickerAccess.Checked)
                            {
                                target_fsi.LastAccessTime = dialog.dateTimePickerAccess.Value;
                            }
                            if (dialog.dateTimePickerCreation.Checked)
                            {
                                target_fsi.CreationTime = dialog.dateTimePickerCreation.Value;
                            }
                            if (dialog.dateTimePickerModification.Checked)
                            {
                                target_fsi.LastWriteTime = dialog.dateTimePickerModification.Value;
                            }
                            OnItemProcessDone(new ItemEventArs(one_name));
                        }
                        catch (Exception ex)
                        {
                            Messages.ShowException(ex);
                        }
                    }
                }
                else
                {
                    try
                    {
                        if (dialog.dateTimePickerAccess.Checked)
                        {
                            target_fsi.LastAccessTime = dialog.dateTimePickerAccess.Value;
                        }
                        if (dialog.dateTimePickerCreation.Checked)
                        {
                            target_fsi.CreationTime = dialog.dateTimePickerCreation.Value;
                        }
                        if (dialog.dateTimePickerModification.Checked)
                        {
                            target_fsi.LastWriteTime = dialog.dateTimePickerModification.Value;
                        }
                    }
                    catch (Exception ex)
                    {
                        Messages.ShowException(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                Messages.ShowException(ex);
            }
        } // end of proc
示例#23
0
        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 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
            List <FileInfoEx> source_list = new List <FileInfoEx>();
            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(dl_source[e_current.FocusedIndex]);
            }
            else
            {
                //get source from selection
                for (int i = 0; i < sel_indices.Length; i++)
                {
                    source_list.Add(dl_source[sel_indices[i]]);
                }
            }

            string dest_path = dl_target.DirectoryPath;

            //prepare copy dialog
            CopyFileDialog 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
            CopyEngineOptions 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
            bool dest_remote = true;

            try
            {
                FileInfoEx dest_info = new FileInfoEx();
                FileInfoEx.TryGet(dest_path, ref dest_info);
                NT_FS_DEVICE_CHARACTERISTICS 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);
            CopyFileEngine 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();
        }
示例#24
0
        protected override void internal_command_proc()
        {
            QueryPanelInfoEventArgs e = new QueryPanelInfoEventArgs();

            OnQueryCurrentPanel(e);

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

            DirectoryList dl = (DirectoryList)e.ItemCollection;

            int[] sel_indices = e.SelectedIndices;
            //we must cache selection
            //becouse indexes will be change while deleting
            List <string> sel_names = new List <string>();

            if (sel_indices.Length > 0)
            {
                for (int i = 0; i < sel_indices.Length; i++)
                {
                    sel_names.Add(Path.Combine(dl.DirectoryPath, dl.GetItemDisplayNameLong(sel_indices[i])));
                }
            }
            else
            {
                sel_names.Add(Path.Combine(dl.DirectoryPath, dl.GetItemDisplayNameLong(e.FocusedIndex)));
            }

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

            dialog.Text = "Delete files";
            if (sel_names.Count == 1)
            {
                if (IOhelper.IsDirectory(sel_names[0]))
                {
                    dialog.labelQuestion.Text = string.Format("Do you REALLY want to delete '{0}'? This directory and all its contents it will be destroyed for ever.", sel_names[0]);
                }
                else
                {
                    dialog.labelQuestion.Text = string.Format("Do you REALLY want to delete '{0}'? The file will be destroyed for ever.", sel_names[0]);
                }
            }
            else
            {
                dialog.labelQuestion.Text = string.Format("Do you REALLY want to delete {0} entries? All selected files and directories with the contents will be destroyed for ever.", sel_names.Count);
            }
            dialog.checkBoxForceReadonly.Checked     = Options.DeleteReadonly;
            dialog.checkBoxSupressExceptions.Checked = Options.DeleteSupressExceptions;

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

            //save user selection
            Options.DeleteReadonly          = dialog.checkBoxForceReadonly.Checked;
            Options.DeleteSupressExceptions = dialog.checkBoxSupressExceptions.Checked;
            force_readonly     = dialog.checkBoxForceReadonly.Checked;
            supress_exceptions = dialog.checkBoxSupressExceptions.Checked;

            //and enum entries in sel_names and recursively delete each
            foreach (string one_name in sel_names)
            {
                delete_file_recurs(one_name);
            }
        }
示例#25
0
        public override void GetChildCollection
            (int index,
            ref FileCollectionBase new_collection,
            ref bool use_new,
            ref string preferred_focused_text)
        {
            if (!GetItemIsContainer(index))
            {
                use_new = false;
                return;
            }

            NETRESOURCE target_container = new NETRESOURCE();

            if (index == 0)
            {
                //go up to container of resourse_root

                //cache valid?
                if (parent_cache != null)
                {
                    //fill from cache
                    internal_list.Clear();
                    foreach (NETRESOURCE res in parent_cache.ResourceList)
                    {
                        internal_list.Add(res, null);
                    }
                    preferred_focused_text = resource_root.lpRemoteName;
                    resource_root          = parent_cache.ResourceRoot;
                    parent_cache           = parent_cache.ParentCache;
                    OnAfterRefill();
                    use_new = false;
                    return;
                }

                //workaround.
                //Wnet throws exception while getting parent of resource like 'Microsoft Windows Network'
                if ((resource_root.lpRemoteName == null) ||
                    (resource_root.dwDisplayType == ResourceDisplayType.NETWORK))
                {
                    target_container = WinApiWNETwrapper.RootNetresource;
                }
                else
                {
                    target_container = WinApiWNETwrapper.GetParentResource(resource_root);
                }

                preferred_focused_text = resource_root.lpRemoteName;

                //set new resource_root
                resource_root = target_container;

                //and fill
                Refill();

                //and return
                use_new = false;
                return;
            }//end of UP brunch

            //else go to down
            target_container = internal_list.Keys[index - 1];

            //case disk share - switch to DirectoryList
            if (target_container.dwType == ResourceType.DISK)
            {
                //switch to DirectoryList
                DirectoryList new_source = new DirectoryList
                                               (SortCriteria, SortReverse, target_container.lpRemoteName);
                new_source.MainWindow = MainWindow;

                try
                {
                    new_source.Refill();
                    use_new        = true;
                    new_collection = new_source;
                }
                catch (Win32Exception win5_ex)
                {
                    if (win5_ex.NativeErrorCode == 5) //access denied
                    {
                        //try to establish connection with creds
                        if (establish_connection(target_container))
                        {
                            try
                            {
                                //and retry
                                new_source.Refill();
                                use_new        = true;
                                new_collection = new_source;
                            }
                            catch (Exception ex)
                            {
                                Messages.ShowException(ex);
                            }
                        }
                    }
                    else
                    {
                        Messages.ShowException(win5_ex);
                    }
                }
                catch (Exception ex)
                {
                    Messages.ShowException(ex);
                }
                return;
            }

            //prepare parent cache
            InternalCache new_cache = new InternalCache(target_container);

            new_cache.ParentCache = parent_cache;
            new_cache.ResourceList.AddRange(internal_list.Keys);
            new_cache.ResourceRoot = resource_root;

            try
            {
                resource_root = target_container;
                use_new       = false;
                Refill();
                parent_cache = new_cache;
            }
            catch (Exception ex)
            {
                Messages.ShowException(ex);
            }
            return;
        }
        protected override void internal_command_proc()
        {
            QueryPanelInfoEventArgs e = new QueryPanelInfoEventArgs();

            OnQueryCurrentPanel(e);

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

            DirectoryList dl = (DirectoryList)e.ItemCollection;

            if (dl.GetItemDisplayNameLong(e.FocusedIndex) == "..")
            {
                return;
            }

            //show dialog
            ProcessStartInfo psi       = new ProcessStartInfo();
            string           file_name = dl[e.FocusedIndex].FullName;

            psi.FileName = file_name;
            RunExeOptions opts   = Options.RunExeOptions;
            RunexeDialog  dialog = new RunexeDialog();

            dialog.Text                         = Options.GetLiteral(Options.LANG_EXECUTE);
            dialog.RunExeOptions                = opts;
            dialog.textBoxArguments.Text        = string.Empty;
            dialog.textBoxFilename.Text         = dl[e.FocusedIndex].FileName;
            dialog.textBoxWorkingDirectory.Text = dl.DirectoryPath;
            if (psi.Verbs != null)
            {
                foreach (string verb in psi.Verbs)
                {
                    dialog.comboBoxVerb.Items.Add(verb);
                }
            }

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

            opts = dialog.RunExeOptions;
            Options.RunExeOptions = opts;

            psi.LoadUserProfile = (opts & RunExeOptions.LoadEnvironment) == RunExeOptions.LoadEnvironment;
            if ((opts & RunExeOptions.RunInConsole) == RunExeOptions.RunInConsole)
            {
                if (file_name.Contains(" "))
                {
                    file_name = '"' + file_name + '"';
                }
                psi.FileName  = "cmd";
                psi.Arguments = "/K " + file_name;
            }
            else
            {
                psi.FileName = file_name;
            }

            if ((opts & RunExeOptions.UseRunas) == RunExeOptions.UseRunas)
            {
                string user = string.Empty;
                string pass = string.Empty;

                if (Messages.AskCredentials(Options.GetLiteral(Options.LANG_ACCOUNT), Options.GetLiteral(Options.LANG_EXECUTE) + " '" + file_name + "'", ref user, ref pass) == DialogResult.OK)
                {
                    psi.UserName = user;
                    System.Security.SecureString sec = new System.Security.SecureString();
                    foreach (char c in pass)
                    {
                        sec.AppendChar(c);
                    }
                    psi.Password = sec;
                }
            }

            psi.UseShellExecute = (opts & RunExeOptions.UseShellExecute) == RunExeOptions.UseShellExecute;

            psi.WorkingDirectory = dialog.textBoxWorkingDirectory.Text;
            psi.Verb             = dialog.comboBoxVerb.Text;
            psi.Arguments        = psi.Arguments + " " + dialog.textBoxArguments.Text;

            try
            {
                Process.Start(psi);
            }
            catch (Exception ex)
            {
                Messages.ShowException
                    (ex,
                    string.Format(Options.GetLiteral(Options.LANG_CANNOT_EXCUTE_0_1), psi.FileName, psi.Arguments));
            }
        }
        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();
        }
示例#28
0
        public override void GetChildCollection
            (int index,
            ref FileCollectionBase new_collection,
            ref bool use_new,
            ref string preferred_focused_text)
        {
            if (LockSafe)
            {
                Messages.ShowMessage("Cannot change directory now.");
                return;
            }

            if (!GetItemIsContainer(index))
            {
                use_new = false;
                return;
            }

            //directory to go to..
            var target_dir   = internal_list.Keys[index];
            var old_virt_dir = string.Empty;

            if (target_dir == "..")
            {
                //up
                if (zip_virtual_dir == string.Empty)
                {
                    //go to directory list
                    try
                    {
                        new_collection         = new DirectoryList(0, false, Path.GetDirectoryName(zip_file_name));
                        preferred_focused_text = Path.GetFileName(zip_file_name);
                        use_new = true;
                        new_collection.MainWindow = (mainForm)Program.MainWindow;
                        new_collection.Refill();
                    }
                    catch (Exception ex)
                    {
                        Messages.ShowException(ex);
                    }
                    return;
                }
                else
                {
                    //up

                    old_virt_dir           = zip_virtual_dir;
                    zip_virtual_dir        = FtpPath.GetDirectory(zip_virtual_dir);
                    preferred_focused_text = old_virt_dir;
                    try
                    {
                        Refill();
                    }
                    catch (Exception ex)
                    {
                        zip_virtual_dir = old_virt_dir;
                        Messages.ShowException(ex);
                    }
                    return;
                }
            }
            else
            {
                //go to down

                old_virt_dir = zip_virtual_dir;

                //down
                zip_virtual_dir = target_dir;

                try
                {
                    Refill();
                }
                catch (Exception ex)
                {
                    zip_virtual_dir = old_virt_dir;
                    Messages.ShowException(ex);
                }
                return;
            }
        }
示例#29
0
        protected override void internal_command_proc()
        {
            QueryPanelInfoEventArgs e = new QueryPanelInfoEventArgs();

            OnQueryCurrentPanel(e);

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

            bool group_mode = false;

            int[] sel_indices = e.SelectedIndices;
            //we not need cache selection
            //becouse e.ItemsCollection must not change (DirectoryList not sort on attributes)
            group_mode = (sel_indices.Length > 1);
            DirectoryList   dl     = (DirectoryList)e.ItemCollection;
            WIN32_FIND_DATA f_data = new WIN32_FIND_DATA();

            string target_file = string.Empty;

            if (!group_mode)
            {
                if (sel_indices.Length == 0)
                {
                    target_file = Path.Combine(dl.DirectoryPath, dl.GetItemDisplayNameLong(e.FocusedIndex));
                }
                else
                {
                    target_file = Path.Combine(dl.DirectoryPath, dl.GetItemDisplayNameLong(sel_indices[0]));
                }
                if (target_file.EndsWith(".."))
                {
                    target_file = dl.DirectoryPath;
                }
                if (!WinAPiFSwrapper.GetFileInfo(target_file, ref f_data))
                {
                    return;
                }
            }



            FileAttributesEditDialog dialog = new FileAttributesEditDialog();

            if (!group_mode)
            {
                dialog.buttonClear.Enabled = false;
                set_attributes_to_dialog(dialog, f_data.dwFileAttributes);
                dialog.Text = String.Format
                                  (Options.GetLiteral(Options.LANG_FILE_ATTRIBUTES) + " [{0}]", target_file);
            }
            else
            {
                dialog.buttonClear.Enabled = true;
                dialog.buttonOK.Text       = Options.GetLiteral(Options.LANG_ADD);
                dialog.Text = string.Format
                                  (Options.GetLiteral(Options.LANG_FILE_ATTRIBUTES) + " [{0} " + Options.GetLiteral(Options.LANG_ENTRIES) + "]", sel_indices.Length);
            }
            set_readonly_attributes(dialog);

            DialogResult d_res = dialog.ShowDialog();

            switch (d_res)
            {
            case DialogResult.OK:
                //group mode = add attributes
                //single mode = set attributes
                if (!group_mode)
                {
                    try
                    {
                        set_attributes_file(target_file, get_attributes_from_dialog(dialog));
                    }
                    catch (Exception ex)
                    {
                        Messages.ShowException(ex);
                    }
                }
                else
                {
                    //group mode
                    FileAttributes add_fa = get_attributes_from_dialog(dialog);
                    foreach (int one_index in sel_indices)
                    {
                        target_file = Path.Combine(dl.DirectoryPath, dl.GetItemDisplayNameLong(one_index));
                        try
                        {
                            add_attributes_file(target_file, add_fa);
                            OnItemProcessDone(new ItemEventArs(one_index));
                        }
                        catch (Exception ex)
                        {
                            Messages.ShowException(ex);
                        }
                    }
                }
                break;

            case DialogResult.Yes:
                //group mode only = clear attributes
                FileAttributes clear_fa = get_attributes_from_dialog(dialog);
                foreach (int one_index in sel_indices)
                {
                    target_file = Path.Combine(dl.DirectoryPath, dl.GetItemDisplayNameLong(one_index));
                    try
                    {
                        clear_attributes_file(target_file, clear_fa);
                        OnItemProcessDone(new ItemEventArs(one_index));
                    }
                    catch (Exception ex)
                    {
                        Messages.ShowException(ex);
                    }
                }
                break;
            }
        }
        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.ItemCollection is DirectoryList))
            {
                return;
            }

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

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

            DirectoryList dl_current = (DirectoryList)e_current.ItemCollection;
            DirectoryList dl_other   = (DirectoryList)e_other.ItemCollection;
            bool          group_mode = e_current.SelectedIndices.Length > 1;
            NTFSlinkType  link_type  = Options.LinkType;

            List <FileInfoEx> sels = new List <FileInfoEx>();

            if (e_current.SelectedIndices.Length > 0)
            {
                for (int i = 0; i < e_current.SelectedIndices.Length; i++)
                {
                    sels.Add(dl_current[e_current.SelectedIndices[i]]);
                }
            }
            else
            {
                sels.Add(dl_current[e_current.FocusedIndex]);
            }

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

            dialog.Text                 = Options.GetLiteral(Options.LANG_LINK_CREATE);
            dialog.LinkType             = link_type;
            dialog.textBoxLinkname.Text = string.Empty;
            if (group_mode)
            {
                dialog.textBoxLinkname.ReadOnly = true;
                dialog.textBoxLinktarget.Text   = string.Format
                                                      ("{0} " + Options.GetLiteral(Options.LANG_ENTRIES),
                                                      sels.Count);
            }
            else
            {
                dialog.textBoxLinktarget.Text = sels[0].FileName;
            }

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

            link_type        = dialog.LinkType;
            Options.LinkType = link_type;

            foreach (FileInfoEx entry in sels)
            {
                IntPtr link_handle = IntPtr.Zero;
                //combine link name
                string link_name = string.Empty;
                if (dialog.textBoxLinkname.Text == string.Empty)
                {
                    //use target file name
                    link_name = Path.Combine(dl_other.DirectoryPath, entry.FileName);
                }
                else
                {
                    link_name = Path.Combine(dl_other.DirectoryPath, dialog.textBoxLinkname.Text);
                }

                try
                {
                    if ((entry.Directory) && (link_type == NTFSlinkType.Hard))
                    {
                        Messages.ShowMessage
                            (string.Format
                                (Options.GetLiteral(Options.LANG_CANNOT_CREATE_HARD_LINK_DIR_0),
                                entry.FullName));
                        continue;
                    }

                    if (link_type == NTFSlinkType.Hard)
                    {
                        int res = WinApiFS.CreateHardLink
                                      (link_name,
                                      entry.FullName,
                                      IntPtr.Zero);
                        if (res == 0)
                        {
                            Messages.ShowException
                                (new Win32Exception(Marshal.GetLastWin32Error()),
                                string.Format
                                    (Options.GetLiteral(Options.LANG_CANNOT_CREATE_LINK_0_ARROW_1),
                                    entry.FullName,
                                    link_name));
                        }
                        else
                        {
                            OnItemProcessDone(new ItemEventArs(entry.FileName));
                        }
                        continue;
                    }

                    if (link_type == NTFSlinkType.Symbolic)
                    {
                        try
                        {
                            WinAPiFSwrapper.CreateSymbolicLink(link_name, entry.FullName, entry.Directory);
                            OnItemProcessDone(new ItemEventArs(entry.FileName));
                        }
                        catch (Exception)
                        {
                            Messages.ShowException
                                (new Win32Exception(Marshal.GetLastWin32Error()),
                                string.Format
                                    (Options.GetLiteral(Options.LANG_CANNOT_CREATE_LINK_0_ARROW_1),
                                    entry.FullName,
                                    link_name));
                        }
                        continue;
                    }

                    //link type is junction

                    WIN32_FIND_DATA link_data  = new WIN32_FIND_DATA();
                    bool            link_exist = WinAPiFSwrapper.GetFileInfo(link_name, ref link_data);

                    if (link_exist)
                    {
                        Messages.ShowMessage(string.Format(Options.GetLiteral(Options.LANG_DESTINATION_0_EXIST_OVERWRITING_PROHIBITED), link_name));
                        continue;
                    }

                    //jumction target must be directory, create directory
                    Directory.CreateDirectory(link_name);
                    //and retrieve handle
                    link_handle = WinApiFS.CreateFile_intptr
                                      (link_name,
                                      Win32FileAccess.WRITE_ATTRIBUTES | Win32FileAccess.WRITE_EA,
                                      FileShare.ReadWrite,
                                      IntPtr.Zero,
                                      FileMode.Open,
                                      CreateFileOptions.OPEN_REPARSE_POINT | CreateFileOptions.BACKUP_SEMANTICS,
                                      IntPtr.Zero);
                    if (link_handle.ToInt32() == WinApiFS.INVALID_HANDLE_VALUE)
                    {
                        Win32Exception win_ex = new Win32Exception(Marshal.GetLastWin32Error());
                        Messages.ShowException
                            (win_ex,
                            string.Format
                                (Options.GetLiteral(Options.LANG_CANNOT_CREATE_LINK_0_ARROW_1),
                                link_name,
                                entry.FullName));
                        if (Directory.Exists(link_name))
                        {
                            Directory.Delete(link_name);
                        }
                        continue;
                    }
                    //now handle to link open
                    WinAPiFSwrapper.SetMountpoint(link_handle, entry.FullName, entry.FullName);

                    OnItemProcessDone(new ItemEventArs(entry.FileName));
                }//end try
                catch (Exception ex)
                {
                    Messages.ShowException
                        (ex,
                        string.Format
                            (Options.GetLiteral(Options.LANG_CANNOT_CREATE_LINK_0_ARROW_1),
                            entry.FullName,
                            link_name));
                }
                finally
                {
                    //close handle
                    if ((link_handle.ToInt32() != WinApiFS.INVALID_HANDLE_VALUE) && (link_handle != IntPtr.Zero))
                    {
                        WinApiFS.CloseHandle(link_handle);
                    }
                }
            }//end foreach
        }