Пример #1
0
        private void Clean_Worker(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker             = sender as BackgroundWorker;
            ArrayList        selectedItems      = e.Argument as ArrayList;
            string           workspaceDirectory = MOG_ControllerProject.GetWorkspaceDirectory() + "\\";

            for (int i = 0; i < selectedItems.Count && !worker.CancellationPending; i++)
            {
                string file         = selectedItems[i] as string;
                string relativeFile = file;
                if (file.StartsWith(workspaceDirectory, StringComparison.CurrentCultureIgnoreCase))
                {
                    relativeFile = file.Substring(workspaceDirectory.Length);
                }

                string message = "Deleting:\n" +
                                 "     " + Path.GetDirectoryName(relativeFile) + "\n" +
                                 "     " + Path.GetFileName(relativeFile);
                worker.ReportProgress(i * 100 / selectedItems.Count, message);

                // Check if this file really exists?
                if (DosUtils.FileExistFast(file))
                {
                    if (!DosUtils.Recycle(file))
                    {
                        // Error
                        MOG_Prompt.PromptMessage("Delete File", "Could not delete:\n" + file);
                    }
                    else
                    {
                        if (!DosUtils.DirectoryDeleteEmptyParentsFast(Path.GetDirectoryName(file), true))
                        {
                            if (DosUtils.GetLastError() != null && DosUtils.GetLastError().Length > 0)
                            {
                                // Error
                                MOG_Prompt.PromptMessage("Delete directory", "Could not delete directory:\n" + Path.GetDirectoryName(file));
                            }
                        }
                    }
                }
            }
        }