示例#1
0
        public AFSdialog(string file_name)
        {
            InitializeComponent();

            internal_file_name = file_name;

            if (!check_volume(file_name))
            {
                Messages.ShowMessage("File system not support named streams.");
                return;
            }

            Text = string.Format("File streams [{0}]", file_name);

            fill_listview(file_name);
        }
示例#2
0
        private void SettingsDeserialize(byte[] settings)
        {
            if (settings.Length == 0)
            {
                fill_defaults();
                return;
            }

            MemoryStream ms = null;

            try
            {
                ms = new MemoryStream(settings);

                //mask
                var int_bytes = new byte[4];
                ms.Read(int_bytes, 0, 4);
                var mask_len   = BitConverter.ToInt64(int_bytes, 0);
                var mask_bytes = new byte[mask_len];
                ms.Read(mask_bytes, 0, (int)mask_len);
                var mask_string = Encoding.Unicode.GetString(mask_bytes);
                var masks       = mask_string.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                Masks = masks;

                //ignore attr
                var bool_bytes = new byte[1];
                ms.Read(bool_bytes, 0, 1);
                IgnoreFileAttributes = BitConverter.ToBoolean(bool_bytes, 0);

                //attributes
                ms.Read(int_bytes, 0, 4);
                var attr_int = BitConverter.ToInt64(int_bytes, 0);
                var fa       = (FileAttributes)attr_int;
                FileAttributes = fa;

                //ignore size
                ms.Read(bool_bytes, 0, 1);
                IgnoreSize = BitConverter.ToBoolean(bool_bytes, 0);

                //size criteria
                ms.Read(int_bytes, 0, 4);
                FilterSizeCriteria = (FilterSizeCriteria)BitConverter.ToInt64(int_bytes, 0);

                //size min
                var long_bytes = new byte[8];
                ms.Read(long_bytes, 0, 8);
                SizeMinimum = BitConverter.ToInt64(long_bytes, 0);

                //size max
                ms.Read(long_bytes, 0, 8);
                SizeMaximum = BitConverter.ToInt64(long_bytes, 0);

                //ignore create
                ms.Read(bool_bytes, 0, 1);
                IgnoreTimeCreate = BitConverter.ToBoolean(bool_bytes, 0);

                //create begin
                ms.Read(long_bytes, 0, 8);
                CreateBegin = DateTime.FromFileTime(BitConverter.ToInt64(long_bytes, 0));

                //create end
                ms.Read(long_bytes, 0, 8);
                CreateEnd = DateTime.FromFileTime(BitConverter.ToInt64(long_bytes, 0));

                //ignore modif
                ms.Read(bool_bytes, 0, 1);
                IgnoreTimeModification = BitConverter.ToBoolean(bool_bytes, 0);

                //modif begin
                ms.Read(long_bytes, 0, 8);
                ModificationBegin = DateTime.FromFileTime(BitConverter.ToInt64(long_bytes, 0));

                //modif end
                ms.Read(long_bytes, 0, 8);
                ModificationEnd = DateTime.FromFileTime(BitConverter.ToInt64(long_bytes, 0));

                //ignore access
                ms.Read(bool_bytes, 0, 1);
                IgnoreTimeAccess = BitConverter.ToBoolean(bool_bytes, 0);

                //access begin
                ms.Read(long_bytes, 0, 8);
                AccessBegin = DateTime.FromFileTime(BitConverter.ToInt64(long_bytes, 0));

                //access end
                ms.Read(long_bytes, 0, 8);
                AccessEnd = DateTime.FromFileTime(BitConverter.ToInt64(long_bytes, 0));

                //current directory only
                ms.Read(bool_bytes, 0, 1);
                InCurrentDirectory = BitConverter.ToBoolean(bool_bytes, 0);

                //include subdirs
                ms.Read(bool_bytes, 0, 1);
                InCurrentDirectoryWithSubdirs = BitConverter.ToBoolean(bool_bytes, 0);

                //current drive
                ms.Read(bool_bytes, 0, 1);
                InCurrentDrive = BitConverter.ToBoolean(bool_bytes, 0);

                //all drives
                ms.Read(bool_bytes, 0, 1);
                //this. = BitConverter.ToBoolean(bool_bytes, 0);

                //fixed drives
                ms.Read(bool_bytes, 0, 1);
                InFixedDrives = BitConverter.ToBoolean(bool_bytes, 0);

                //removable drives
                ms.Read(bool_bytes, 0, 1);
                InRemovableDrives = BitConverter.ToBoolean(bool_bytes, 0);

                //network drives
                ms.Read(bool_bytes, 0, 1);
                InNetworkDrives = BitConverter.ToBoolean(bool_bytes, 0);
            }
            catch (Exception ex)
            {
                Messages.ShowMessage(ex.Message + " Failed to read settings. Load defaults.");
                fill_defaults();
            }
            finally
            {
                if (ms != null)
                {
                    ms.Close();
                }
            }
        }
        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);
            }
        }
示例#4
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();
        }
        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();
        }
示例#6
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;
            }
        }
示例#7
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();
        }
示例#8
0
        private void add_to_zip(QueryPanelInfoEventArgs e_current, QueryPanelInfoEventArgs e_other)
        {
            var main_window = (mainForm)Program.MainWindow;

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

                //show add zip dialog
                var dialog = new ArchiveAddDialog();
                dialog.Text = Options.GetLiteral(Options.LANG_ARCHIVE_ADD);
                dialog.textBoxSourceMask.Text = "*";
                dialog.ArchiveAddOptions      = Options.ArchiveAddOptions;
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                var 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)
                var one_file_list = new string[0];
                var root_paths    = new List <string>();
                var 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 (var i = 0; i < e_current.SelectedIndices.Length; i++)
                    {
                        root_paths.Add(dl[e_current.SelectedIndices[i]].FullName);
                    }
                }
                foreach (var 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
                var 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
                var current_dir = dl.DirectoryPath;
                var zip_path    = string.Empty;
                var zip_index   = 0;
                foreach (var 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)
                            {
                                var 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)
                        {
                            var 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);
            }
        }
        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();
        }
示例#10
0
        private void delete_file_recurs(string current_file)
        {
            bool readonly_changed = false;
            int  res    = 0;
            int  winErr = 0;

            try
            {
                Wrapper.GetFileInfo(current_file, ref fs_data);
            }
            catch (Exception ex)
            {
                process_exceptions(ex);
            }
            if ((fs_data.dwFileAttributes & FileAttributes.Directory) == FileAttributes.Directory)
            {
                try
                {
                    //this is deirectory
                    //current_file is directory
                    //enum entries and call recurs for each
                    string search_path = current_file;
                    search_path = search_path.TrimEnd(new char[] { Path.DirectorySeparatorChar });
                    search_path = search_path + Path.DirectorySeparatorChar + "*";
                    Wrapper.WIN32_FIND_DATA_enumerable fs_enum = new Wrapper.WIN32_FIND_DATA_enumerable(search_path);
                    foreach (WIN32_FIND_DATA data in fs_enum)
                    {
                        //skip refs to current and up dirs
                        if (data.cFileName == ".")
                        {
                            continue;
                        }
                        if (data.cFileName == "..")
                        {
                            continue;
                        }
                        delete_file_recurs(Path.Combine(current_file, data.cFileName));
                    }
                    //now directory current_file must be empty
                    //check attr
                    try
                    {
                        if ((fs_data.dwFileAttributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                        {
                            if (force_readonly)
                            {
                                clear_readonly(current_file);
                                readonly_changed = true;
                            }
                            else
                            {
                                if (!supress_exceptions)
                                {
                                    Messages.ShowMessage(string.Format("Cannot delete '{0}'. Directory have readonly attribute.", current_file));
                                    return;
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        process_exceptions(ex);
                    }
                    //and delete
                    try
                    {
                        ///////////////////////////////////////////////////////////////////////////////////////
                        /* DEBUG */
                        //if (current_file.EndsWith("netcommander", StringComparison.CurrentCultureIgnoreCase))
                        //{
                        //    int j = 0;
                        //    j++;
                        //}
                        ///////////////////////////////////////////////////////////////////////////////////////
                        res = Native.RemoveDirectory(current_file);
                        if (res == 0)
                        {
                            //restore attr
                            if (readonly_changed)
                            {
                                set_readonly(current_file);
                            }
                            if (!supress_exceptions)
                            {
                                //throw exception
                                winErr = Marshal.GetLastWin32Error();
                                throw new Win32Exception(winErr);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        process_exceptions(ex);
                    }
                }
                catch (Exception ex)
                {
                    process_exceptions(ex);
                }
            }
            else
            {
                //current_file is FILE
                //check attributes
                try
                {
                    if ((fs_data.dwFileAttributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                    {
                        if (force_readonly)
                        {
                            clear_readonly(current_file);
                            readonly_changed = true;
                        }
                        else
                        {
                            if (!supress_exceptions)
                            {
                                Messages.ShowMessage(string.Format("Cannot delete '{0}'. File have readonly attribute.", current_file));
                                return;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    process_exceptions(ex);
                }
                //now try delete file
                try
                {
                    res = Native.DeleteFile(current_file);
                    if (res == 0)
                    {
                        //restore attr
                        if (readonly_changed)
                        {
                            set_readonly(current_file);
                        }
                        if (!supress_exceptions)
                        {
                            winErr = Marshal.GetLastWin32Error();
                            throw new Win32Exception(winErr);
                        }
                    }
                }
                catch (Exception ex)
                {
                    process_exceptions(ex);
                }
            }
        }
示例#11
0
        protected override void internal_command_proc()
        {
            var e_current = new QueryPanelInfoEventArgs();

            OnQueryCurrentPanel(e_current);

            var pl = (ProcessList)e_current.ItemCollection;
            var p  = pl[e_current.FocusedIndex];

            //prepare dialog
            var opts   = Options.TerminateProcessOptions;
            var dialog = new TerminateProcessDialog();

            dialog.Text = Options.GetLiteral(Options.LANG_TERMINATE);
            dialog.labelTerminateProcessMessage.Text = string.Format
                                                           (Options.GetLiteral(Options.LANG_TERMINATE_PROCESS_ID_NAME),
                                                           p.ProcessName,
                                                           p.Id);
            dialog.Options = opts;

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

            opts = dialog.Options;
            Options.TerminateProcessOptions = opts;
            var res = false;

            try
            {
                if ((opts & TerminateProcessOptions.DebugMode) == TerminateProcessOptions.DebugMode)
                {
                    Process.EnterDebugMode();
                }

                if ((opts & TerminateProcessOptions.CloseMainWindow) == TerminateProcessOptions.CloseMainWindow)
                {
                    res = p.CloseMainWindow();

                    if (!res)
                    {
                        Messages.ShowMessage(Options.GetLiteral(Options.LANG_TERMINATE_NO_MAIN_WINDOW));
                    }
                    else
                    {
                        res = p.WaitForExit(30000);
                    }
                }
                else if ((opts & TerminateProcessOptions.Kill) == TerminateProcessOptions.Kill)
                {
                    p.Kill();
                    res = p.WaitForExit(30000);
                }

                if (!res)
                {
                    Messages.ShowMessage(Options.GetLiteral(Options.LANG_TERMINATE_FAIL));
                }
            }
            catch (Exception ex)
            {
                Messages.ShowException(ex);
            }
            finally
            {
                if ((opts & TerminateProcessOptions.DebugMode) == TerminateProcessOptions.DebugMode)
                {
                    try
                    {
                        Process.LeaveDebugMode();
                    }
                    catch (Exception) { }
                }
            }
        }
示例#12
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 DirectoryList))
            {
                Messages.ShowMessage(Options.GetLiteral(Options.LANG_WRONG_DESTINATION));
                return;
            }

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

            var sel_source = new List <FtpEntryInfo>();

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

            var destination = dir_list.DirectoryPath;

            //prepare and show user dialog
            var ftp_trans_opts = Options.FtpDownloadOptions;
            var 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;
            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 doanload engine
            var 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();
        }
示例#13
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.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;
            }

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

            var sels = new List <FileInfoEx>();

            if (e_current.SelectedIndices.Length > 0)
            {
                for (var 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
            var 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 (var entry in sels)
            {
                var link_handle = IntPtr.Zero;
                //combine link name
                var 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)
                    {
                        var 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

                    var link_data  = new WIN32_FIND_DATA();
                    var 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.ToInt64() == WinApiFS.INVALID_HANDLE_VALUE)
                    {
                        var 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.ToInt64() != WinApiFS.INVALID_HANDLE_VALUE) && (link_handle != IntPtr.Zero))
                    {
                        WinApiFS.CloseHandle(link_handle);
                    }
                }
            }//end foreach
        }