Example #1
0
        private void DeleteFiles(bool silent)
        {
            System.Collections.Specialized.StringCollection files = new System.Collections.Specialized.StringCollection();
            IEnumerable <IBrowserItem> itemset = getComponent <IBrowser>().CurSelItems;

            foreach (IBrowserItem item in itemset)
            {
                files.Add(item.FullPath);
            }

            ShellLib.ShellFileOperation fo = new ShellLib.ShellFileOperation();

            string[] filearray = new string[files.Count];
            files.CopyTo(filearray, 0);
            fo.Operation   = ShellLib.ShellFileOperation.FileOperations.FO_DELETE;
            fo.OwnerWindow = m_windowhandle;
            fo.SourceFiles = filearray;

            fo.OperationFlags = ShellLib.ShellFileOperation.ShellFileOperationFlags.FOF_NO_CONNECTED_ELEMENTS
                                | ShellLib.ShellFileOperation.ShellFileOperationFlags.FOF_WANTNUKEWARNING;

            if (silent)
            {
                fo.OperationFlags = fo.OperationFlags | ShellLib.ShellFileOperation.ShellFileOperationFlags.FOF_NOCONFIRMATION;
            }

            bool retVal = fo.DoOperation();

            getComponent <IBrowser>().Refresh();

            if (retVal == false)
            {
                throw new Exception("Shell File Operation Failed");
            }
        }
Example #2
0
        public static bool DeleteToRecycleBin(string path, bool sillent)
        {
            System.IO.FileInfo fi = new System.IO.FileInfo(path);

            ShellLib.ShellFileOperation fo = new ShellLib.ShellFileOperation();

            String[] source = new String[1];
            source[0] = fi.FullName;

            HwndSource hs     = (HwndSource)HwndSource.FromVisual(App.Current.MainWindow);
            IntPtr     handle = hs.Handle;

            fo.Silent      = true;
            fo.Operation   = ShellLib.ShellFileOperation.FileOperations.FO_DELETE;
            fo.OwnerWindow = handle;
            fo.SourceFiles = source;

            return(fo.DoOperation());
        }
Example #3
0
        void DoPaste()
        {
            ShellLib.ShellFileOperation fo = new ShellLib.ShellFileOperation();

            String[] source = new String[3];
            String[] dest   = new String[3];

            source[0] = Environment.SystemDirectory + @"\winmine.exe";
            source[1] = Environment.SystemDirectory + @"\freecell.exe";
            source[2] = Environment.SystemDirectory + @"\mshearts.exe";
            dest[0]   = Environment.SystemDirectory.Substring(0, 2) + @"\winmine.exe";
            dest[1]   = Environment.SystemDirectory.Substring(0, 2) + @"\freecell.exe";
            dest[2]   = Environment.SystemDirectory.Substring(0, 2) + @"\mshearts.exe";

            fo.Operation   = ShellLib.ShellFileOperation.FileOperations.FO_COPY;
            fo.OwnerWindow = this.Handle;
            fo.SourceFiles = source;
            fo.DestFiles   = dest;

            bool RetVal = fo.DoOperation();
        }
Example #4
0
        void Paste()
        {
            IDataObject obj = Clipboard.GetDataObject();

            int dropeffect = 0;
            MemoryStream stream = (System.IO.MemoryStream)obj.GetData("Preferred DropEffect");
            if (stream != null)
            {
                BinaryReader reader = new BinaryReader(stream);
                dropeffect = reader.ReadInt32();
            }

            System.Collections.Specialized.StringCollection files = Clipboard.GetFileDropList();
            ShellLib.ShellFileOperation fo = new ShellLib.ShellFileOperation();

            string[] filearray = new string[files.Count];
            files.CopyTo(filearray, 0);

            if ((DragDropEffects.Move & (DragDropEffects)dropeffect) == DragDropEffects.Move)
            {
                fo.Operation = ShellLib.ShellFileOperation.FileOperations.FO_MOVE;
            }
            else
            {
                fo.Operation = ShellLib.ShellFileOperation.FileOperations.FO_COPY;
            }

            fo.OwnerWindow = Program.form.Handle;
            fo.SourceFiles = filearray;
            /*            if (filearray.Length == 0)
            {
                string[] destarray = new string[files.Count];
                for (int i = 0; i < files.Count; i++)
                {
                    string filename = files[i].Substring(files[i].LastIndexOf('\\'));
                    destarray[i] = Browser.CurrentDir.FullName + filename;
                }
                fo.DestFiles = destarray;
            }
            else*/
            {
                fo.OperationFlags = ShellLib.ShellFileOperation.ShellFileOperationFlags.FOF_ALLOWUNDO
                    | ShellLib.ShellFileOperation.ShellFileOperationFlags.FOF_RENAMEONCOLLISION
                    | ShellLib.ShellFileOperation.ShellFileOperationFlags.FOF_NO_CONNECTED_ELEMENTS
                    | ShellLib.ShellFileOperation.ShellFileOperationFlags.FOF_WANTNUKEWARNING;

                fo.DestFiles = new string[] { Browser.CurrentDir.FullName };
            }

            try
            {
                bool retVal = fo.DoOperation();
                if (retVal == false)
                {
                    MessageBox.Show("Error Occurs");
                }
            }
            catch (Exception EE)
            {
                MessageBox.Show(EE.Message);
            }
        }
Example #5
0
        private void DeleteFiles()
        {
            System.Collections.Specialized.StringCollection files = new System.Collections.Specialized.StringCollection();
            IEnumerable<IBrowserItem> itemset = Browser.CurSelItems;

            foreach (IBrowserItem item in itemset)
            {
                files.Add(item.FullPath);
            }

            ShellLib.ShellFileOperation fo = new ShellLib.ShellFileOperation();

            string[] filearray = new string[files.Count];
            files.CopyTo(filearray, 0);
            fo.Operation = ShellLib.ShellFileOperation.FileOperations.FO_DELETE;
            fo.OwnerWindow = Program.form.Handle;
            fo.SourceFiles = filearray;

            fo.OperationFlags = ShellLib.ShellFileOperation.ShellFileOperationFlags.FOF_NO_CONNECTED_ELEMENTS
                | ShellLib.ShellFileOperation.ShellFileOperationFlags.FOF_WANTNUKEWARNING;

            bool retVal = fo.DoOperation();

            Browser.Refresh();

            if (retVal == false)
            {
                throw new Exception("Shell File Operation Failed");
            }
        }
Example #6
0
File: Misc.cs Project: tmbx/kwm
        /// <summary>
        /// Copy one file using the Shell API. The progress dialog displayed is not modal.
        /// </summary>
        /// <param name="Sources">Source paths of the files to copy.</param>
        /// <param name="Destinations">Destination paths of the files to copy.</param>
        /// <param name="DisplayErrors">No user interface will be displayed if an error occurs.</param>
        /// <param name="SilentOverwrite">Do not prompt the user before overwritting the destination file. </param>
        /// <param name="RenameDestOnCollision">Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists.</param>
        /// <param name="SimpleProgress">Displays a progress dialog box but does not show the file names.</param>
        /// <param name="Silent">Does not display a progress dialog box. </param>
        /// <param name="LockUI">Set to true if you want the entire application to be disabled during the operation.</param>
        /// <returns>True if the operation completed with success, false if the user aborted or if an error occured.</returns>
        public static bool CopyFiles(List<String> Sources, List<String> Destinations, bool DisplayErrors, bool SilentOverwrite, bool RenameDestOnCollision, bool SimpleProgress, bool Silent, bool LockUI)
        {
            // Prepare the Shell.
            ShellLib.ShellFileOperation FileOp = new ShellLib.ShellFileOperation();
            FileOp.Operation = ShellLib.ShellFileOperation.FileOperations.FO_COPY;

            if (DisplayErrors)
                FileOp.OperationFlags |= ShellLib.ShellFileOperation.ShellFileOperationFlags.FOF_NOERRORUI;

            if (RenameDestOnCollision)
                FileOp.OperationFlags |= ShellLib.ShellFileOperation.ShellFileOperationFlags.FOF_RENAMEONCOLLISION;

            if (SilentOverwrite)
                FileOp.OperationFlags |= ShellLib.ShellFileOperation.ShellFileOperationFlags.FOF_NOCONFIRMATION;

            if (SimpleProgress)
                FileOp.OperationFlags |= ShellLib.ShellFileOperation.ShellFileOperationFlags.FOF_SIMPLEPROGRESS;

            FileOp.OwnerWindow = Misc.MainForm.Handle;
            FileOp.SourceFiles = Sources.ToArray();
            FileOp.DestFiles = Destinations.ToArray();

            // Disable the entire application while the copy is being done.
            // Necessary since we can't make the progress dialog modal.
            try
            {
                if (LockUI)
                    Misc.MainForm.Enabled = false;
                return FileOp.DoOperation();
            }

            finally
            {
                if (LockUI)
                    Misc.MainForm.Enabled = true;
            }
        }
Example #7
0
        /// <summary>
        /// Called when the user selects the Move menu item.
        /// </summary>
        void MoveMenuItemClick(object sender, System.EventArgs e)
        {
            int nCount = listView.CheckedItems.Count;

            if (nCount > 0)
            {
                folderBrowserDialog.Description = "Select the target directory";

                DialogResult result = folderBrowserDialog.ShowDialog();
                if (result == DialogResult.OK)
                {
                    ShellLib.ShellFileOperation fo = new ShellLib.ShellFileOperation();

                    string[] source = new string[nCount];
                    string[] dest = new string[nCount];

                    for (int i = 0; i < nCount; i++)
                    {
                        string path = listView.CheckedItems[i].SubItems[(int)ColumnIndex.Path].Text;
                        string filename = listView.CheckedItems[i].SubItems[(int)ColumnIndex.Name].Text;
                        source[i] = Path.Combine(path, filename);

                        dest[i] = Path.GetPathRoot(source[i]);
                        dest[i] = source[i].Remove(0, dest[i].Length);
                        dest[i] = Path.Combine(folderBrowserDialog.SelectedPath, dest[i]);
                    }

                    fo.Operation = ShellLib.ShellApi.FileOperations.FO_MOVE;
                    fo.OwnerWindow = this.Handle;
                    fo.ProgressTitle = "Moving Checked Files";
                    fo.SourceFiles = source;
                    fo.DestFiles = dest;

                    bool RetVal = fo.DoOperation();

                    foreach (ListViewItem lvi in listView.CheckedItems)
                        listView.Items.Remove(lvi);

                }

            }
        }
Example #8
0
        /// <summary>
        /// Called when the user selects the Delete menu item.
        /// </summary>
        void DeleteMenuItemClick(object sender, System.EventArgs e)
        {
            int nCount = listView.CheckedItems.Count;

            if (nCount > 0)
            {
                ShellLib.ShellFileOperation fo = new ShellLib.ShellFileOperation();

                string[] source = new string[nCount];

                for (int i = 0; i < nCount; i++)
                {
                    string path = listView.CheckedItems[i].SubItems[(int)ColumnIndex.Path].Text;
                    string filename = listView.CheckedItems[i].SubItems[(int)ColumnIndex.Name].Text;
                    source[i] = Path.Combine(path, filename);
                }

                fo.Operation = ShellLib.ShellApi.FileOperations.FO_DELETE;
                fo.OwnerWindow = this.Handle;
                fo.ProgressTitle = "Deleting Checked Files";
                fo.SourceFiles = source;

                bool RetVal = fo.DoOperation();

                foreach (ListViewItem lvi in listView.CheckedItems)
                    listView.Items.Remove(lvi);
            }
        }
Example #9
0
        void Paste()
        {
            IDataObject obj = Clipboard.GetDataObject();

            int          dropeffect = 0;
            MemoryStream stream     = (System.IO.MemoryStream)obj.GetData("Preferred DropEffect");

            if (stream != null)
            {
                BinaryReader reader = new BinaryReader(stream);
                dropeffect = reader.ReadInt32();
            }

            System.Collections.Specialized.StringCollection files = Clipboard.GetFileDropList();
            ShellLib.ShellFileOperation fo = new ShellLib.ShellFileOperation();

            string[] filearray = new string[files.Count];
            files.CopyTo(filearray, 0);

            if ((DragDropEffects.Move & (DragDropEffects)dropeffect) == DragDropEffects.Move)
            {
                fo.Operation = ShellLib.ShellFileOperation.FileOperations.FO_MOVE;
            }
            else
            {
                fo.Operation = ShellLib.ShellFileOperation.FileOperations.FO_COPY;
            }

            fo.OwnerWindow = m_windowhandle;
            fo.SourceFiles = filearray;

            /*            if (filearray.Length == 0)
             *          {
             *              string[] destarray = new string[files.Count];
             *              for (int i = 0; i < files.Count; i++)
             *              {
             *                  string filename = files[i].Substring(files[i].LastIndexOf('\\'));
             *                  destarray[i] = Browser.CurrentDir.FullName + filename;
             *              }
             *              fo.DestFiles = destarray;
             *          }
             *          else*/
            {
                fo.OperationFlags = ShellLib.ShellFileOperation.ShellFileOperationFlags.FOF_ALLOWUNDO
                                    | ShellLib.ShellFileOperation.ShellFileOperationFlags.FOF_RENAMEONCOLLISION
                                    | ShellLib.ShellFileOperation.ShellFileOperationFlags.FOF_NO_CONNECTED_ELEMENTS
                                    | ShellLib.ShellFileOperation.ShellFileOperationFlags.FOF_WANTNUKEWARNING;

                fo.DestFiles = new string[] { getComponent <IBrowser>().CurrentDir.FullName };
            }

            try
            {
                bool retVal = fo.DoOperation();
                if (retVal == false)
                {
                    MessageBox.Show("Error Occurs");
                }
            }
            catch (Exception EE)
            {
                MessageBox.Show(EE.Message);
            }
        }