Exemple #1
0
        /// <summary>
        /// Finalizes candidates find procedure.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">Completion arguments and results.</param>
        private void GttWrk_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            // Unlocking ListView...
            CM_FTable.EndUpdate();

            // Showing estimated of free space to be free after removing all found files...
            CM_Info.Text = String.Format(AppStrings.PS_FrFInfo, GuiHelpers.SclBytes(TotalSize));

            // Checking if candidates are found...
            if (CM_FTable.Items.Count == 0)
            {
                // Nothing found. Showing message and closing form...
                MessageBox.Show(AppStrings.PS_LoadErr, Properties.Resources.AppName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                CM_Clean.Enabled = false;
                Close();
            }
            else
            {
                // At least one candidate found. Enabling cleanup button...
                CM_Clean.Enabled = true;
            }
        }
Exemple #2
0
        /// <summary>
        /// Gets full list of files for deletion.
        /// </summary>
        /// <param name="CleanDirs">List of files and directories for cleanup.</param>
        /// <param name="Recursive">Enable recursive cleanup.</param>
        private void DetectFilesForCleanup(List <String> CleanDirs, bool Recursive)
        {
            foreach (string DirMs in CleanDirs)
            {
                // Extracting directory path and file mask from combined string...
                string CleanDir  = Path.GetDirectoryName(DirMs);
                string CleanMask = Path.GetFileName(DirMs);

                // Checking if directory exists...
                if (Directory.Exists(CleanDir))
                {
                    try
                    {
                        // Getting full contents of directory and adding them to result...
                        DirectoryInfo DInfo   = new DirectoryInfo(CleanDir);
                        FileInfo[]    DirList = DInfo.GetFiles(CleanMask);
                        foreach (FileInfo DItem in DirList)
                        {
                            ListViewItem LvItem = new ListViewItem(DItem.Name)
                            {
                                Checked     = !NoAutoCheck,
                                ToolTipText = Path.Combine(CleanDir, DItem.Name),
                                SubItems    =
                                {
                                    GuiHelpers.SclBytes(DItem.Length),
                                    DItem.LastWriteTime.ToString()
                                }
                            };

                            // Adding file to main list and incrementing counter...
                            Invoke((MethodInvoker) delegate() { CM_FTable.Items.Add(LvItem); });
                            TotalSize += DItem.Length;
                        }

                        if (Recursive)
                        {
                            try
                            {
                                // Getting subdirectories...
                                List <String> SubDirs = new List <string>();
                                foreach (DirectoryInfo Dir in DInfo.GetDirectories())
                                {
                                    SubDirs.Add(Path.Combine(Dir.FullName, CleanMask));
                                }

                                // If subdirectories exists, run this method recursively...
                                if (SubDirs.Count > 0)
                                {
                                    DetectFilesForCleanup(SubDirs, true);
                                }
                            }
                            catch (Exception Ex)
                            {
                                Logger.Warn(Ex);
                            }
                        }
                    }
                    catch (Exception Ex)
                    {
                        Logger.Warn(Ex);
                    }
                }
            }
        }