-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMainWindow.xaml.cs
275 lines (252 loc) · 11.2 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
using System;
using System.Windows;
using System.Windows.Controls;
using System.Threading;
using System.Collections.Generic;
using static KMS_Activator.Shared;
using static KMS_Activator.Office_Configurator;
using static KMS_Activator.Animations_Related;
namespace KMS_Activator
{
/// <summary>
/// <para>Interaction logic for MainWindow.xaml</para>
/// <para>将不会为该类的所有函数编写XML文档</para>
/// <para>XML documents will not be written for all functions of this class</para>
/// </summary>
public partial class MainWindow : Window
{
// 该字典存储了激活过程中打勾的Label
// This dictionary stores the Label with a check mark during the activation process
private readonly Dictionary<int, Label> stepLabels;
// 该字典存储了激活过程中表示转圈的LoadingCircle
// This dictionary stores the LoadingCircle during the activation process
private readonly Dictionary<int, HandyControl.Controls.LoadingCircle> loadingCircles;
/// <summary>
/// 主窗口类构造函数
/// </summary>
public MainWindow()
{
InitializeComponent();
stepLabels = new Dictionary<int, Label>()
{
{1, stepDone1 },
{2, stepDone2 },
{3, stepDone3 },
{4, stepDone4 }
};
loadingCircles = new Dictionary<int, HandyControl.Controls.LoadingCircle>()
{
{1, loadingCircle1 },
{2, loadingCircle2 },
{3, loadingCircle3 },
{4, loadingCircle4 }
};
}
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
// 设置几个Label
// Set the content of Labels in MainWindow
mainWindow = (MainWindow)Application.Current.MainWindow;
winVersion_Label.Content = WIN_VERSION;
officeVersion_Label.Content = officeProduct;
EnableConfigToUI();
// 新增:加载完主窗口后选择是否检查更新
if (Current_Config.isAutoUpdate)
{
await AutoCheckUpdate();
}
}
// 当“+”号Label按钮按下的时候
// When the "+" Label button is pressed
/* private void addServerName_Button_Click(object sender, RoutedEventArgs e)
{
if (addServerName_TextBox.Visibility == Visibility.Hidden)
{
addServerName_TextBox.Visibility = Visibility.Visible;
addServerName_Button.Content = "√";
deleteServerName_Button.Visibility = Visibility.Hidden;
}
else
{
if (addServerName_TextBox.Text.Trim(' ') != string.Empty && !addServerName_TextBox.Text.Contains("Anawaert KMS 服务器"))
{
ComboBoxItem newItem = new ComboBoxItem
{
Content = addServerName_TextBox.Text,
IsSelected = true,
};
selectServer_ComboBox.Items.Add(newItem);
}
addServerName_TextBox.Text = string.Empty;
addServerName_TextBox.Visibility = Visibility.Hidden;
deleteServerName_Button.Visibility = Visibility.Visible;
addServerName_Button.Content = "+";
}
}
// 当“-”号Label按钮按下的时候
// When the "-" Label button is pressed
private void deleteServerName_Button_Click(object sender, RoutedEventArgs e)
{
selectServer_ComboBox.Items.Remove
(
(string)((ComboBoxItem)selectServer_ComboBox.SelectedItem).Content == "Anawaert KMS 服务器" ?
null :
selectServer_ComboBox.SelectedItem
);
} */
private void RemoveLoadingAndNoticeLabels()
{
for (int i = 1; i < 5; i++)
{
loadingCircles[i].Visibility = Visibility.Collapsed;
stepLabels[i].Visibility = Visibility.Collapsed;
}
}
// 当“激活”Label按钮按下的时候
// When the “激活” Label button is pressed
private void activate_Button_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
RemoveLoadingAndNoticeLabels();
// 执行动画
// Begin the animation
MainW_Slide(new List<Grid> { mainInterfaceGrid });
// awaiting_ProgressBar.IsEnabled = true;
// 当awaiting_ProgressBar被选中时
// When awaiting_ProgressBar was selected
if (actWin_RadioButton.IsChecked == true)
{
// 使用另一个线程
// Use another thread to run the functions for activating
Thread subThread = new Thread
(
() =>
{
// Thread.Sleep(500);
string selectedContent = AW_KMS_SERVER_ADDR;
bool isAutoRenewChecked = true;
// 通过UI线程拿到KMS服务器的选择
// Get the KMS server selection through the UI thread
this.Dispatcher.Invoke
(
() =>
{
selectedContent = (string)((ComboBoxItem)selectServer_ComboBox.SelectedItem).Content == "Anawaert 服务器" ?
AW_KMS_SERVER_ADDR :
(string)((ComboBoxItem)selectServer_ComboBox.SelectedItem).Content;
isAutoRenewChecked = autoRenew_CheckBox.IsChecked == true;
}
);
if (IsWinActivated())
{
UI_Thread_Operations.ShiftAwaitingAnimationEffectsTalker(1);
MessageBox.Show
(
"您的 Windows 已激活,无需再次激活",
"提示",
MessageBoxButton.OK,
MessageBoxImage.Information
);
}
else
{
Win_Activator activator = new Win_Activator();
activator.ActWin(selectedContent);
// 若“自动续签”被选中,那么就设定一下计划任务;否则,就取消自动续签
// If Auto-renew is selected, set the scheduled tasks; Otherwise, the auto-renewal is canceled
if (Current_Config.isAutoRenew)
{
CancelAutoRenew("WINDOWS");
AutoRenewSign("WINDOWS");
}
else
{
CancelAutoRenew("WINDOWS");
}
}
// 执行完后再返回UI线程执行剩下的动画
//When you're done, return to the UI thread to execute the rest of the animation
this.Dispatcher.Invoke
(
() =>
{
MainW_SlideBack(new List<Grid> { mainInterfaceGrid });
// awaiting_ProgressBar.IsEnabled = false;
}
);
}
);
subThread.Start();
}
// 同理上述
// Same thing as above
else if (actOffice_RadioButton.IsChecked == true)
{
Thread subThread = new Thread
(
() =>
{
// Thread.Sleep(500);
string selectedContent = AW_KMS_SERVER_ADDR;
bool isAutoRenewChecked = true;
this.Dispatcher.Invoke
(
() =>
{
selectedContent = (string)((ComboBoxItem)selectServer_ComboBox.SelectedItem).Content == "Anawaert 服务器" ?
AW_KMS_SERVER_ADDR :
(string)((ComboBoxItem)selectServer_ComboBox.SelectedItem).Content;
isAutoRenewChecked = autoRenew_CheckBox.IsChecked == true;
}
);
Office_Activator activator = new Office_Activator();
activator.ActOffice(selectedContent);
if (Current_Config.isAutoRenew)
{
CancelAutoRenew("OFFICE");
AutoRenewSign("OFFICE");
}
else
{
CancelAutoRenew("OFFICE");
}
this.Dispatcher.Invoke
(
() =>
{
MainW_SlideBack(new List<Grid> { mainInterfaceGrid });
// awaiting_ProgressBar.IsEnabled = false;
// officeVersion_Label.Content = officeProduct;
}
);
}
);
subThread.Start();
}
}
private void autoRenew_CheckBox_Click(object sender, RoutedEventArgs e)
{
RefreshConfigInit();
RefreshConfigFile(JSON_CFG_PATH);
}
private void autoUpdate_CheckBox_Click(object sender, RoutedEventArgs e)
{
RefreshConfigInit();
RefreshConfigFile(JSON_CFG_PATH);
}
// 用来表示激活过程中的动画效果,实现方法很蠢,但是暂时没有更好的办法
// Used to represent the animation effects during the activation process, the implementation method is very stupid, but there is no better way for the time being
internal void ShiftAwaitingAnimationEffects(int currentIndex)
{
int minIndex = 1;
if (currentIndex < 5)
{
loadingCircles[currentIndex].Visibility = Visibility.Visible;
}
for (int i = minIndex; i <= currentIndex - 1; i++)
{
loadingCircles[i].Visibility = Visibility.Collapsed;
stepLabels[i].Visibility = Visibility.Visible;
}
}
}
}