Advertisement
tima18

Untitled

Jan 12th, 2020
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.41 KB | None | 0 0
  1. using FastClear.Models;
  2. using System;
  3. using System.CodeDom.Compiler;
  4. using System.ComponentModel;
  5. using System.Diagnostics;
  6. using System.IO;
  7. using System.Threading;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Controls.Primitives;
  11. using System.Windows.Markup;
  12.  
  13. namespace FastClearWPF
  14. {
  15. public class MainWindow : Window, IComponentConnector
  16. {
  17. internal ComboBox DriveComboBox;
  18. internal ProgressBar RefillDiskProgressBar;
  19. internal Button ClearButton;
  20. internal TextBlock LogsTextBlock;
  21. private bool _contentLoaded;
  22.  
  23. public MainWindow()
  24. {
  25. this.InitializeComponent();
  26. new Thread(new ThreadStart(this.RefillDrivesList)).Start();
  27. }
  28.  
  29. private void ClearButton_Click(object sender, RoutedEventArgs e)
  30. {
  31. if (this.DriveComboBox.SelectedItem != null)
  32. {
  33. this.LogsTextBlock.Dispatcher.BeginInvoke((Delegate) (() => this.LogsTextBlock.Text = "Начало..."));
  34. this.ClearButton.IsEnabled = false;
  35. Drive drive = this.DriveComboBox.SelectedItem as Drive;
  36. new Thread((ThreadStart) (() =>
  37. {
  38. foreach (string fileSystemEntry in Directory.GetFileSystemEntries(drive.DriveInfo.RootDirectory.ToString(), "*", SearchOption.AllDirectories))
  39. {
  40. string file = fileSystemEntry;
  41. if (file.LastIndexOf(".lnk") != -1 || file.LastIndexOf("autorun.") != -1)
  42. {
  43. File.Delete(file);
  44. this.LogsTextBlock.Dispatcher.BeginInvoke((Delegate) (() =>
  45. {
  46. TextBlock logsTextBlock = this.LogsTextBlock;
  47. logsTextBlock.Text = logsTextBlock.Text + "\nУдаление " + file + "..";
  48. }));
  49. }
  50. else if (file.IndexOf("System Volume Information") != -1)
  51. {
  52. if (!File.GetAttributes(file).HasFlag((Enum) FileAttributes.Hidden))
  53. {
  54. File.SetAttributes(file, FileAttributes.Hidden);
  55. this.LogsTextBlock.Dispatcher.BeginInvoke((Delegate) (() => this.LogsTextBlock.Text += "\nСкрытие System Volume Information..."));
  56. }
  57. }
  58. else if (File.GetAttributes(file).HasFlag((Enum) FileAttributes.Hidden))
  59. {
  60. File.SetAttributes(file, FileAttributes.Normal);
  61. this.LogsTextBlock.Dispatcher.BeginInvoke((Delegate) (() =>
  62. {
  63. TextBlock logsTextBlock = this.LogsTextBlock;
  64. logsTextBlock.Text = logsTextBlock.Text + "\nВосстановление аттрибутов для " + file + "..";
  65. }));
  66. }
  67. }
  68. this.ClearButton.Dispatcher.BeginInvoke((Delegate) (() => this.ClearButton.IsEnabled = true));
  69. this.LogsTextBlock.Dispatcher.BeginInvoke((Delegate) (() => this.LogsTextBlock.Text += "\nКонец!"));
  70. })).Start();
  71. }
  72. else
  73. {
  74. int num = (int) MessageBox.Show("Выберите диск который хотите очистить!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Hand);
  75. }
  76. }
  77.  
  78. private void UpdateButton_Click(object sender, RoutedEventArgs e)
  79. {
  80. this.DriveComboBox.Items.Clear();
  81. new Thread(new ThreadStart(this.RefillDrivesList)).Start();
  82. }
  83.  
  84. public void RefillDrivesList()
  85. {
  86. this.RefillDiskProgressBar.Dispatcher.BeginInvoke((Delegate) (() => this.RefillDiskProgressBar.Visibility = Visibility.Visible));
  87. foreach (DriveInfo drive1 in DriveInfo.GetDrives())
  88. {
  89. DriveInfo drive = drive1;
  90. if (drive.IsReady && drive.DriveType == DriveType.Removable)
  91. this.DriveComboBox.Dispatcher.BeginInvoke((Delegate) (() => this.DriveComboBox.Items.Add((object) new Drive(drive))));
  92. }
  93. this.RefillDiskProgressBar.Dispatcher.BeginInvoke((Delegate) (() => this.RefillDiskProgressBar.Visibility = Visibility.Collapsed));
  94. }
  95.  
  96. [DebuggerNonUserCode]
  97. [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  98. public void InitializeComponent()
  99. {
  100. if (this._contentLoaded)
  101. return;
  102. this._contentLoaded = true;
  103. Application.LoadComponent((object) this, new Uri("/FastClearWPF;component/mainwindow.xaml", UriKind.Relative));
  104. }
  105.  
  106. [DebuggerNonUserCode]
  107. [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  108. [EditorBrowsable(EditorBrowsableState.Never)]
  109. void IComponentConnector.Connect(int connectionId, object target)
  110. {
  111. switch (connectionId)
  112. {
  113. case 1:
  114. this.DriveComboBox = (ComboBox) target;
  115. break;
  116. case 2:
  117. this.RefillDiskProgressBar = (ProgressBar) target;
  118. break;
  119. case 3:
  120. this.ClearButton = (Button) target;
  121. this.ClearButton.Click += new
  122. messagebox.show
  123. MessageBox.Show
  124. RoutedEventHandler(this.ClearButton_Click);
  125. break;
  126. case 4:
  127. ((ButtonBase) target).Click += new RoutedEventHandler(this.UpdateButton_Click);
  128. break;
  129. case 5:
  130. this.LogsTextBlock = (TextBlock) target;
  131. break;
  132. default:
  133. this._contentLoaded = true;
  134. break;
  135. }
  136. }
  137. }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement