Пример #1
0
        private void core_OnDeleteError(object sender, DeletionErrorEventArgs e)
        {
            var errorDialog = new DeletionError();

            errorDialog.SetPath(e.Path);
            errorDialog.SetErrorMessage(e.ErrorMessage);

            var dialogResult = errorDialog.ShowDialog();

            errorDialog.Dispose();

            if (dialogResult == DialogResult.Abort)
            {
                this.core.AbortDeletion();
            }
            else
            {
                // Hack: retry means -> ignore all errors
                if (dialogResult == DialogResult.Retry)
                {
                    this.Data.IgnoreAllErrors = true;
                }

                this.core.ContinueDeleteProcess();
            }
        }
        private void core_OnDeleteError(object sender, DeletionErrorEventArgs e)
        {
            var errorDialog = new DeletionError();

            errorDialog.SetPath(e.Path);
            errorDialog.SetErrorMessage(e.ErrorMessage);

            var dialogResult = errorDialog.ShowDialog();

            errorDialog.Dispose();

            if (dialogResult == DialogResult.Abort)
            {
                this.core.AbortDeletion();
            }
            else
            {
                // Hack: retry means -> ignore all errors
                if (dialogResult == DialogResult.Retry)
                    this.Data.IgnoreAllErrors = true;

                this.core.ContinueDeleteProcess();
            }
        }
        protected override void OnDoWork(DoWorkEventArgs e)
        {
            // This method will run on a thread other than the UI thread.
            // Be sure not to manipulate any Windows Forms controls created
            // on the UI thread from this method.

            if (CancellationPending)
            {
                e.Cancel = true;
                return;
            }

            bool   stopNow      = false;
            string errorMessage = "";

            this.ErrorInfo = null;

            int count = this.Data.EmptyFolderList.Count;

            while (this.ListPos < this.Data.EmptyFolderList.Count)
            {
                if (CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                var folder = this.Data.EmptyFolderList[this.ListPos];
                var status = DirectoryDeletionStatusTypes.Ignored;

                // Do not delete one time protected folders
                if (!this.Data.ProtectedFolderList.ContainsKey(folder))
                {
                    try
                    {
                        // Try to delete the directory
                        this.secureDelete(folder);

                        this.Data.AddLogMessage(String.Format("Successfully deleted dir \"{0}\"", folder));

                        status = DirectoryDeletionStatusTypes.Deleted;
                        this.DeletedCount++;
                    }
                    catch (REDPermissionDeniedException ex)
                    {
                        errorMessage = ex.Message;

                        this.Data.AddLogMessage(String.Format("Directory is protected by the system \"{0}\" - Message: \"{1}\"", folder, errorMessage));

                        status = DirectoryDeletionStatusTypes.Protected;
                        this.ProtectedCount++;
                    }
                    catch (Exception ex)
                    {
                        errorMessage = ex.Message;
                        stopNow      = (!this.Data.IgnoreAllErrors);

                        this.Data.AddLogMessage(String.Format("Failed to delete dir \"{0}\" - Error message: \"{1}\"", folder, errorMessage));

                        status = DirectoryDeletionStatusTypes.Warning;
                        this.FailedCount++;
                    }

                    if (!stopNow && this.Data.PauseTime > 0)
                    {
                        Thread.Sleep(TimeSpan.FromMilliseconds(this.Data.PauseTime));
                    }
                }
                else
                {
                    status = DirectoryDeletionStatusTypes.Protected;
                }

                this.ReportProgress(1, new DeleteProcessUpdateEventArgs(this.ListPos, folder, status, count));

                this.ListPos++;

                if (stopNow)
                {
                    // stop here for now
                    if (errorMessage == "")
                    {
                        errorMessage = "Unknown error";
                    }

                    e.Cancel       = true;
                    this.ErrorInfo = new DeletionErrorEventArgs(folder, errorMessage);
                    return;
                }
            }

            e.Result = count;
        }
        protected override void OnDoWork(DoWorkEventArgs e)
        {
            // This method will run on a thread other than the UI thread.
            // Be sure not to manipulate any Windows Forms controls created
            // on the UI thread from this method.

            if (CancellationPending)
            {
                e.Cancel = true;
                return;
            }

            bool stopNow = false;
            string errorMessage = "";
            this.ErrorInfo = null;

            int count = this.Data.EmptyFolderList.Count;

            while (this.ListPos < this.Data.EmptyFolderList.Count)
            {
                if (CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                var folder = this.Data.EmptyFolderList[this.ListPos];
                var status = DirectoryDeletionStatusTypes.Ignored;

                // Do not delete one time protected folders
                if (!this.Data.ProtectedFolderList.ContainsKey(folder))
                {
                    try
                    {
                        // Try to delete the directory
                        this.secureDelete(folder);

                        this.Data.AddLogMessage(String.Format("Successfully deleted dir \"{0}\"", folder));

                        status = DirectoryDeletionStatusTypes.Deleted;
                        this.DeletedCount++;
                    }
                    catch (REDPermissionDeniedException ex)
                    {
                        errorMessage = ex.Message;

                        this.Data.AddLogMessage(String.Format("Directory is protected by the system \"{0}\" - Message: \"{1}\"", folder, errorMessage));

                        status = DirectoryDeletionStatusTypes.Protected;
                        this.ProtectedCount++;
                    }
                    catch (Exception ex)
                    {
                        errorMessage = ex.Message;
                        stopNow = (!this.Data.IgnoreAllErrors);

                        this.Data.AddLogMessage(String.Format("Failed to delete dir \"{0}\" - Error message: \"{1}\"", folder, errorMessage));

                        status = DirectoryDeletionStatusTypes.Warning;
                        this.FailedCount++;
                    }

                    if (!stopNow && this.Data.PauseTime > 0)
                        Thread.Sleep(TimeSpan.FromMilliseconds(this.Data.PauseTime));
                }
                else
                    status = DirectoryDeletionStatusTypes.Protected;

                this.ReportProgress(1, new DeleteProcessUpdateEventArgs(this.ListPos, folder, status, count));

                this.ListPos++;

                if (stopNow)
                {
                    // stop here for now
                    if (errorMessage == "") errorMessage = "Unknown error";

                    e.Cancel = true;
                    this.ErrorInfo = new DeletionErrorEventArgs(folder, errorMessage);
                    return;
                }
            }

            e.Result = count;
        }