Ejemplo n.º 1
0
        /// <summary>
        ///   Send file to recycle bin
        /// </summary>
        /// <param name = "path">Location of directory or file to recycle</param>
        /// <param name = "flags">FileOperationFlags to add in addition to FOF_ALLOWUNDO</param>
        public static bool Send(string path, FileOperationFlags flags)
        {
            try
            {
                var fs = new SHFileOpStruct
                {
                    wFunc  = FileOperationType.Delete,
                    pFrom  = path + '\0' + '\0',
                    fFlags = FileOperationFlags.AllowUndo | flags
                };

                // important to double-terminate the string.
                SHFileOperation(ref fs);
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public static bool Send(IEnumerable <string> paths)
        {
            string pathsMerged = string.Join('\0', paths);

            try
            {
                var fs = new SHFileOpStruct
                {
                    wFunc  = FileOperationType.FO_DELETE,
                    pFrom  = pathsMerged + "\0\0",
                    fFlags = FileOperationFlags.FOF_ALLOWUNDO | FileOperationFlags.FOF_NOCONFIRMATION | FileOperationFlags.FOF_WANTNUKEWARNING
                };

                SHFileOperation(ref fs);
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            StartupPath = System.Windows.Forms.Application.StartupPath + '\\';

            DockIcon.Register(StartupPath + "Container-Empty.png", null, false);
            if (!DockIcon.IsRegistered)
            {
                Shutdown();
                return;
            }

            DockIcon.KeepInDock = true;
            DockIcon.Exposable = false;
            DockIcon.Activatable = true;

            Settings.Initialize(DockIcon.SettingsPath + "settings.xml");

            #region Get Previous Icon

            var iconName = DockIcon.IconName;
            if (string.IsNullOrEmpty(iconName))
            {
                iconName = StartupPath + "Container-Empty.png";
            }
            if (string.IsNullOrEmpty(Settings.Icon) || ((iconName != StartupPath + "Container-Empty.png") && (iconName != StartupPath + "Container-Opened.png")))
            {
                Settings.Icon = iconName;
                Settings.Save();
            }

            #endregion

            #region Init Path

            Path = Settings.Path;
            if (!Directory.Exists(Path))
            {
                Path = StartupPath;
            }
            if (Path.LastIndexOf('\\') < Path.Length - 1)
            {
                Path += '\\';
            }

            #endregion

            #region Start With View Mode

            if ((e.Args.Length >= 3) && (e.Args[0] == "-viewMode"))
            {
                Path = e.Args[2];
                if (Path.LastIndexOf('\\') < Path.Length - 1)
                {
                    Path += '\\';
                }
                if (!((e.Args.Length == 4) && (e.Args[3] == "-notSetPath")))
                {
                    Settings.Path = Path;
                }

                Directories = Directory.GetDirectories(Path);
                Files = Directory.GetFiles(Path);

                DockIcon.Title = null;
                DockIcon.AddFolderWatcher(1, DockIcon.FolderWatcherActions.FileAdded | DockIcon.FolderWatcherActions.FileModified | DockIcon.FolderWatcherActions.FolderAdded, Path);

                switch (e.Args[1])
                {
                    case "fan":
                        ViewMode = ViewModeEnum.Fan;
                        MainWindow = new ContainerPublic.FanView();
                        break;

                    case "list":
                        ViewMode = ViewModeEnum.List;
                        Shutdown();
                        return;
                    //break;

                    default:
                        ViewMode = ViewModeEnum.Grid;
                        MainWindow = new ContainerPublic.GridView();
                        break;
                }

                MainWindow.Show();
                return;
            }

            #endregion

            #region Dropped files & directories into the stack

            if ((e.Args.Length > 0) && !((e.Args.Length == 1) && Directory.Exists(e.Args[0])))
            {
                var droppedFiles = true;
                foreach (var file in e.Args)
                {
                    if (!File.Exists(file) && !Directory.Exists(file))
                    {
                        droppedFiles = false;
                        break;
                    }
                }
                if (droppedFiles)
                {
                    var fileOperation = new SHFileOpStruct();
                    fileOperation.hwnd = IntPtr.Zero;

                    fileOperation.wFunc = FO_Func.FO_MOVE;
                    if ((System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.Control) == System.Windows.Forms.Keys.Control)
                    {
                        fileOperation.wFunc = FO_Func.FO_COPY;
                    }

                    fileOperation.pFrom = StringArrayToMultiString(e.Args);
                    fileOperation.pTo = StringArrayToMultiString(new string[] { Path });
                    fileOperation.hNameMappings = IntPtr.Zero;
                    fileOperation.fAnyOperationsAborted = 0;
                    fileOperation.fFlags = 0;
                    fileOperation.lpszProgressTitle = null;

                    SHFileOperation(ref fileOperation);

                    Shutdown();
                    return;
                }
            }

            #endregion

            #region Start With Directory

            if ((e.Args.Length > 0) && Directory.Exists(e.Args[0]))
            {
                Path = e.Args[0];
                if (Path.LastIndexOf('\\') < Path.Length - 1)
                {
                    Path += '\\';
                }
                if (!((e.Args.Length == 2) && (e.Args[1] == "-notSetPath")))
                {
                    Settings.Path = Path;
                }
            }

            #endregion

            #region Default

            Directories = Directory.GetDirectories(Path);
            Files = Directory.GetFiles(Path);

            if (Directories.Length + Files.Length <= FanView.MaxItems)
            {
                ViewMode = ViewModeEnum.Fan;
            }
            else if (Directories.Length + Files.Length <= GridView.MaxItems)
            {
                ViewMode = ViewModeEnum.Grid;
            }
            else
            {
                //ViewMode = ViewModeEnum.List;
                ViewMode = ViewModeEnum.Grid;
            }

            DockIcon.Title = null;
            DockIcon.AddFolderWatcher(1, DockIcon.FolderWatcherActions.FileAdded | DockIcon.FolderWatcherActions.FileModified | DockIcon.FolderWatcherActions.FolderAdded, Path);

            switch (ViewMode)
            {
                case ViewModeEnum.Fan:
                    MainWindow = new ContainerPublic.FanView();
                    break;

                case ViewModeEnum.List:
                    Shutdown();
                    return;
                    //break;

                default:
                    MainWindow = new ContainerPublic.GridView();
                    break;
            }

            MainWindow.Show();

            #endregion
        }
Ejemplo n.º 4
0
 private static extern int SHFileOperation(ref SHFileOpStruct lpFileOp);
Ejemplo n.º 5
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            StartupPath = System.Windows.Forms.Application.StartupPath + '\\';

            DockIcon.Register(StartupPath + "Container-Empty.png", null, false);
            if (!DockIcon.IsRegistered)
            {
                Shutdown();
                return;
            }

            DockIcon.KeepInDock  = true;
            DockIcon.Exposable   = false;
            DockIcon.Activatable = true;

            Settings.Initialize(DockIcon.SettingsPath + "settings.xml");

            #region Get Previous Icon

            var iconName = DockIcon.IconName;
            if (string.IsNullOrEmpty(iconName))
            {
                iconName = StartupPath + "Container-Empty.png";
            }
            if (string.IsNullOrEmpty(Settings.Icon) || ((iconName != StartupPath + "Container-Empty.png") && (iconName != StartupPath + "Container-Opened.png")))
            {
                Settings.Icon = iconName;
                Settings.Save();
            }

            #endregion

            #region Init Path

            Path = Settings.Path;
            if (!Directory.Exists(Path))
            {
                Path = StartupPath;
            }
            if (Path.LastIndexOf('\\') < Path.Length - 1)
            {
                Path += '\\';
            }

            #endregion

            #region Start With View Mode

            if ((e.Args.Length >= 3) && (e.Args[0] == "-viewMode"))
            {
                Path = e.Args[2];
                if (Path.LastIndexOf('\\') < Path.Length - 1)
                {
                    Path += '\\';
                }
                if (!((e.Args.Length == 4) && (e.Args[3] == "-notSetPath")))
                {
                    Settings.Path = Path;
                }

                Directories = Directory.GetDirectories(Path);
                Files       = Directory.GetFiles(Path);

                DockIcon.Title = null;
                DockIcon.AddFolderWatcher(1, DockIcon.FolderWatcherActions.FileAdded | DockIcon.FolderWatcherActions.FileModified | DockIcon.FolderWatcherActions.FolderAdded, Path);

                switch (e.Args[1])
                {
                case "fan":
                    ViewMode   = ViewModeEnum.Fan;
                    MainWindow = new ContainerPublic.FanView();
                    break;

                case "list":
                    ViewMode = ViewModeEnum.List;
                    Shutdown();
                    return;

                //break;

                default:
                    ViewMode   = ViewModeEnum.Grid;
                    MainWindow = new ContainerPublic.GridView();
                    break;
                }

                MainWindow.Show();
                return;
            }

            #endregion

            #region Dropped files & directories into the stack

            if ((e.Args.Length > 0) && !((e.Args.Length == 1) && Directory.Exists(e.Args[0])))
            {
                var droppedFiles = true;
                foreach (var file in e.Args)
                {
                    if (!File.Exists(file) && !Directory.Exists(file))
                    {
                        droppedFiles = false;
                        break;
                    }
                }
                if (droppedFiles)
                {
                    var fileOperation = new SHFileOpStruct();
                    fileOperation.hwnd = IntPtr.Zero;

                    fileOperation.wFunc = FO_Func.FO_MOVE;
                    if ((System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.Control) == System.Windows.Forms.Keys.Control)
                    {
                        fileOperation.wFunc = FO_Func.FO_COPY;
                    }

                    fileOperation.pFrom                 = StringArrayToMultiString(e.Args);
                    fileOperation.pTo                   = StringArrayToMultiString(new string[] { Path });
                    fileOperation.hNameMappings         = IntPtr.Zero;
                    fileOperation.fAnyOperationsAborted = 0;
                    fileOperation.fFlags                = 0;
                    fileOperation.lpszProgressTitle     = null;

                    SHFileOperation(ref fileOperation);

                    Shutdown();
                    return;
                }
            }

            #endregion

            #region Start With Directory

            if ((e.Args.Length > 0) && Directory.Exists(e.Args[0]))
            {
                Path = e.Args[0];
                if (Path.LastIndexOf('\\') < Path.Length - 1)
                {
                    Path += '\\';
                }
                if (!((e.Args.Length == 2) && (e.Args[1] == "-notSetPath")))
                {
                    Settings.Path = Path;
                }
            }

            #endregion

            #region Default

            Directories = Directory.GetDirectories(Path);
            Files       = Directory.GetFiles(Path);

            if (Directories.Length + Files.Length <= FanView.MaxItems)
            {
                ViewMode = ViewModeEnum.Fan;
            }
            else if (Directories.Length + Files.Length <= GridView.MaxItems)
            {
                ViewMode = ViewModeEnum.Grid;
            }
            else
            {
                //ViewMode = ViewModeEnum.List;
                ViewMode = ViewModeEnum.Grid;
            }

            DockIcon.Title = null;
            DockIcon.AddFolderWatcher(1, DockIcon.FolderWatcherActions.FileAdded | DockIcon.FolderWatcherActions.FileModified | DockIcon.FolderWatcherActions.FolderAdded, Path);

            switch (ViewMode)
            {
            case ViewModeEnum.Fan:
                MainWindow = new ContainerPublic.FanView();
                break;

            case ViewModeEnum.List:
                Shutdown();
                return;

            //break;

            default:
                MainWindow = new ContainerPublic.GridView();
                break;
            }

            MainWindow.Show();

            #endregion
        }
Ejemplo n.º 6
0
 private static extern int SHFileOperation(ref SHFileOpStruct lpFileOp);