Example #1
0
        /// <summary>
        /// Метод, работающий в отдельном потоке при запуске механизма поиска и удаления.
        /// </summary>
        private void RW_Wrk_DoWork(object sender, DoWorkEventArgs e)
        {
            // Создаём список файлов для удаления...
            List <string> DeleteQueue = DetectFilesForCleanup(RemDirs);

            // Формируем счётчики...
            int TotalFiles = DeleteQueue.Count;
            int i = 1, j = 0;

            // Удаляем файлы из очереди очистки...
            foreach (string Fl in DeleteQueue)
            {
                try { j = (int)Math.Round(((double)i / (double)TotalFiles * (double)100.00), 0); i++; if ((j >= 0) && (j <= 100))
                      {
                          RW_Wrk.ReportProgress(j);
                      }
                } catch (Exception Ex) { CoreLib.WriteStringToLog(Ex.Message); }
                try { if (File.Exists(Fl))
                      {
                          File.SetAttributes(Fl, FileAttributes.Normal); File.Delete(Fl);
                      }
                } catch (Exception Ex) { CoreLib.WriteStringToLog(Ex.Message); }
            }

            // Удаляем пустые каталоги...
            foreach (string Dir in RemDirs)
            {
                FileManager.RemoveEmptyDirectories(Path.GetDirectoryName(Dir));
            }
        }
Example #2
0
 /// <summary>
 /// "Form create" event handler.
 /// </summary>
 /// <param name="sender">Sender object.</param>
 /// <param name="e">Event arguments.</param>
 private void FrmRmWrk_Load(object sender, EventArgs e)
 {
     // Starting async removal sequence...
     if (!RW_Wrk.IsBusy)
     {
         RW_Wrk.RunWorkerAsync(RemDirs);
     }
 }
Example #3
0
 /// <summary>
 /// Метод, срабатывающий при возникновении события "загрузка формы".
 /// </summary>
 private void FrmRmWrk_Load(object sender, EventArgs e)
 {
     // Запускаем удаление асинхронно...
     if (!RW_Wrk.IsBusy)
     {
         RW_Wrk.RunWorkerAsync();
     }
 }
Example #4
0
        /// <summary>
        /// Removes all files and directories recursively from specified directories.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">Additional arguments.</param>
        private void RW_Wrk_DoWork(object sender, DoWorkEventArgs e)
        {
            // Parsing arguments list...
            List <String> Arguments = e.Argument as List <String>;

            // Searching for candidates...
            List <string> DeleteQueue = DetectFilesForCleanup(Arguments);

            // Creating some counters...
            int TotalFiles = DeleteQueue.Count;
            int CurrentFile = 1, CurrentPercent;

            // Removing all files from list...
            foreach (string Fl in DeleteQueue)
            {
                try
                {
                    // Removing file if exists...
                    if (File.Exists(Fl))
                    {
                        File.SetAttributes(Fl, FileAttributes.Normal);
                        File.Delete(Fl);
                    }

                    // Reporting progress to form...
                    CurrentPercent = (int)Math.Round(CurrentFile / (double)TotalFiles * 100.00d, 0); CurrentFile++;
                    if ((CurrentPercent >= 0) && (CurrentPercent <= 100))
                    {
                        RW_Wrk.ReportProgress(CurrentPercent);
                    }
                }
                catch (Exception Ex)
                {
                    Logger.Warn(Ex);
                }
            }

            // Removing empty directories after files removal...
            foreach (string Dir in Arguments)
            {
                try
                {
                    FileManager.RemoveEmptyDirectories(Path.GetDirectoryName(Dir));
                }
                catch (Exception Ex)
                {
                    Logger.Error(Ex, DebugStrings.AppDbgExClnEmptyDirs);
                }
            }
        }