forked from HearthSim/Hearthstone-Deck-Tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
149 lines (130 loc) · 3.36 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#region
using System;
using System.ComponentModel;
using System.IO;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Media;
using Microsoft.Win32;
#endregion
namespace HDTUninstaller
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : INotifyPropertyChanged
{
public MainWindow()
{
InitializeComponent();
}
private string LogConfigPath
{
get { return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Blizzard\Hearthstone\log.config"; }
}
private string HDTDirectory
{
get { return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "HearthstoneDeckTracker"); }
}
private bool LoggingEnabled
{
get { return File.Exists(LogConfigPath); }
}
private bool DataExists
{
get { return Directory.Exists(HDTDirectory); }
}
private bool AutostartEnabled
{
get
{
var regKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if(regKey != null)
return regKey.GetValue("Hearthstone Deck Tracker") != null;
return false;
}
}
public string TextLogging
{
get { return LoggingEnabled ? "REMOVE" : "REMOVED"; }
}
public string TextData
{
get { return DataExists ? "REMOVE" : "REMOVED"; }
}
public string TextAutostart
{
get { return AutostartEnabled ? "REMOVE" : "REMOVED"; }
}
public SolidColorBrush BackgroundLogging
{
get { return new SolidColorBrush(LoggingEnabled ? Colors.Red : Colors.Green); }
}
public SolidColorBrush BackgroundData
{
get { return new SolidColorBrush(DataExists ? Colors.Red : Colors.Green); }
}
public SolidColorBrush BackgroundAutostart
{
get { return new SolidColorBrush(AutostartEnabled ? Colors.Red : Colors.Green); }
}
private void ButtonAutostart_Click(object sender, RoutedEventArgs e)
{
if(!AutostartEnabled)
return;
try
{
var regKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if(regKey != null)
regKey.DeleteValue("Hearthstone Deck Tracker", false);
OnPropertyChanged("TextAutostart");
OnPropertyChanged("BackgroundAutostart");
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void ButtonLogging_Click(object sender, RoutedEventArgs e)
{
if(!LoggingEnabled)
return;
try
{
File.Delete(LogConfigPath);
OnPropertyChanged("TextLogging");
OnPropertyChanged("BackgroundLogging");
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void ButtonData_Click(object sender, RoutedEventArgs e)
{
if(!DataExists)
return;
try
{
var result = MessageBox.Show("Are you sure? This can not be undone!", "Delete HDT Data", MessageBoxButton.OKCancel);
if(result == MessageBoxResult.OK)
{
Directory.Delete(HDTDirectory, true);
OnPropertyChanged("TextData");
OnPropertyChanged("BackgroundData");
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
var handler = PropertyChanged;
if(handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}