Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using FastClear.Models;
- using System;
- using System.CodeDom.Compiler;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.IO;
- using System.Threading;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Controls.Primitives;
- using System.Windows.Markup;
- namespace FastClearWPF
- {
- public class MainWindow : Window, IComponentConnector
- {
- internal ComboBox DriveComboBox;
- internal ProgressBar RefillDiskProgressBar;
- internal Button ClearButton;
- internal TextBlock LogsTextBlock;
- private bool _contentLoaded;
- public MainWindow()
- {
- this.InitializeComponent();
- new Thread(new ThreadStart(this.RefillDrivesList)).Start();
- }
- private void ClearButton_Click(object sender, RoutedEventArgs e)
- {
- if (this.DriveComboBox.SelectedItem != null)
- {
- this.LogsTextBlock.Dispatcher.BeginInvoke((Delegate) (() => this.LogsTextBlock.Text = "Начало..."));
- this.ClearButton.IsEnabled = false;
- Drive drive = this.DriveComboBox.SelectedItem as Drive;
- new Thread((ThreadStart) (() =>
- {
- foreach (string fileSystemEntry in Directory.GetFileSystemEntries(drive.DriveInfo.RootDirectory.ToString(), "*", SearchOption.AllDirectories))
- {
- string file = fileSystemEntry;
- if (file.LastIndexOf(".lnk") != -1 || file.LastIndexOf("autorun.") != -1)
- {
- File.Delete(file);
- this.LogsTextBlock.Dispatcher.BeginInvoke((Delegate) (() =>
- {
- TextBlock logsTextBlock = this.LogsTextBlock;
- logsTextBlock.Text = logsTextBlock.Text + "\nУдаление " + file + "..";
- }));
- }
- else if (file.IndexOf("System Volume Information") != -1)
- {
- if (!File.GetAttributes(file).HasFlag((Enum) FileAttributes.Hidden))
- {
- File.SetAttributes(file, FileAttributes.Hidden);
- this.LogsTextBlock.Dispatcher.BeginInvoke((Delegate) (() => this.LogsTextBlock.Text += "\nСкрытие System Volume Information..."));
- }
- }
- else if (File.GetAttributes(file).HasFlag((Enum) FileAttributes.Hidden))
- {
- File.SetAttributes(file, FileAttributes.Normal);
- this.LogsTextBlock.Dispatcher.BeginInvoke((Delegate) (() =>
- {
- TextBlock logsTextBlock = this.LogsTextBlock;
- logsTextBlock.Text = logsTextBlock.Text + "\nВосстановление аттрибутов для " + file + "..";
- }));
- }
- }
- this.ClearButton.Dispatcher.BeginInvoke((Delegate) (() => this.ClearButton.IsEnabled = true));
- this.LogsTextBlock.Dispatcher.BeginInvoke((Delegate) (() => this.LogsTextBlock.Text += "\nКонец!"));
- })).Start();
- }
- else
- {
- int num = (int) MessageBox.Show("Выберите диск который хотите очистить!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Hand);
- }
- }
- private void UpdateButton_Click(object sender, RoutedEventArgs e)
- {
- this.DriveComboBox.Items.Clear();
- new Thread(new ThreadStart(this.RefillDrivesList)).Start();
- }
- public void RefillDrivesList()
- {
- this.RefillDiskProgressBar.Dispatcher.BeginInvoke((Delegate) (() => this.RefillDiskProgressBar.Visibility = Visibility.Visible));
- foreach (DriveInfo drive1 in DriveInfo.GetDrives())
- {
- DriveInfo drive = drive1;
- if (drive.IsReady && drive.DriveType == DriveType.Removable)
- this.DriveComboBox.Dispatcher.BeginInvoke((Delegate) (() => this.DriveComboBox.Items.Add((object) new Drive(drive))));
- }
- this.RefillDiskProgressBar.Dispatcher.BeginInvoke((Delegate) (() => this.RefillDiskProgressBar.Visibility = Visibility.Collapsed));
- }
- [DebuggerNonUserCode]
- [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
- public void InitializeComponent()
- {
- if (this._contentLoaded)
- return;
- this._contentLoaded = true;
- Application.LoadComponent((object) this, new Uri("/FastClearWPF;component/mainwindow.xaml", UriKind.Relative));
- }
- [DebuggerNonUserCode]
- [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
- [EditorBrowsable(EditorBrowsableState.Never)]
- void IComponentConnector.Connect(int connectionId, object target)
- {
- switch (connectionId)
- {
- case 1:
- this.DriveComboBox = (ComboBox) target;
- break;
- case 2:
- this.RefillDiskProgressBar = (ProgressBar) target;
- break;
- case 3:
- this.ClearButton = (Button) target;
- this.ClearButton.Click += new
- messagebox.show
- MessageBox.Show
- RoutedEventHandler(this.ClearButton_Click);
- break;
- case 4:
- ((ButtonBase) target).Click += new RoutedEventHandler(this.UpdateButton_Click);
- break;
- case 5:
- this.LogsTextBlock = (TextBlock) target;
- break;
- default:
- this._contentLoaded = true;
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement