forked from AdderlyMark/MakuTweakerAnniversary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm7.cs
387 lines (351 loc) · 15 KB
/
Form7.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
using Microsoft.Win32;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics.Eventing.Reader;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection.Emit;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static MakuTweaker.Form1;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button;
namespace MakuTweaker
{
public partial class Form7 : Form
{
private UserPreferenceChangedEventHandler UserPreferenceChanged;
public static Dictionary<string, string> LoadLocalization(string language, int category)
{
var jsonFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "localization", $"{language}.json");
if (!File.Exists(jsonFile))
{
throw new FileNotFoundException($"Файл локализации {jsonFile} не найден.");
}
var jsonContent = File.ReadAllText(jsonFile);
var localizationData = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, Dictionary<string, string>>>>(jsonContent);
if (localizationData.ContainsKey("categories") && localizationData["categories"].ContainsKey(category.ToString()))
{
return localizationData["categories"][category.ToString()];
}
else
{
throw new KeyNotFoundException($"Категория {category} не найдена в файле {jsonFile}.");
}
}
public static class Localization
{
public static Dictionary<string, string> LoadLocalization(string language, int category)
{
var localizationFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Localization");
var jsonFile = Path.Combine(localizationFolder, $"{language}.json");
if (!File.Exists(jsonFile))
{
throw new FileNotFoundException($"Файл локализации {jsonFile} не найден.");
}
var jsonContent = File.ReadAllText(jsonFile);
var localizationData = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, Dictionary<string, string>>>>(jsonContent);
if (localizationData.ContainsKey("categories") && localizationData["categories"].ContainsKey(category.ToString()))
{
return localizationData["categories"][category.ToString()];
}
else
{
throw new KeyNotFoundException($"Категория {category} не найдена в файле {jsonFile}.");
}
}
}
public Form7()
{
InitializeComponent();
LoadTheme();
LoadLocalizedText(11);
Color savedColor = Properties.Settings.Default.SavedColor;
this.BackColor = savedColor;
UserPreferenceChanged = new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
SystemEvents.UserPreferenceChanged += UserPreferenceChanged;
this.Disposed += new EventHandler(Form_Disposed);
this.Deactivate += new EventHandler(Form1_Deactivate);
this.Activated += new EventHandler(Form1_Activated);
}
void Form1_Deactivate(object sender, EventArgs e)
{
statusStrip1.BackColor = Color.White;
}
void Form1_Activated(object sender, EventArgs e)
{
SystemEvents.UserPreferenceChanged -= UserPreferenceChanged;
LoadTheme();
}
public class WinTheme
{
[DllImport("uxtheme.dll", EntryPoint = "#95")]
private static extern uint GetImmersiveColorFromColorSetEx(uint dwImmersiveColorSet, uint dwImmersiveColorType,
bool bIgnoreHighContrast, uint dwHighContrastCacheMode);
[DllImport("uxtheme.dll", EntryPoint = "#96")]
private static extern uint GetImmersiveColorTypeFromName(IntPtr pName);
[DllImport("uxtheme.dll", EntryPoint = "#98")]
private static extern int GetImmersiveUserColorSetPreference(bool bForceCheckRegistry, bool bSkipCheckOnFail);
public static Color GetAccentColor()
{
var userColorSet = GetImmersiveUserColorSetPreference(false, false);
var colorType = GetImmersiveColorTypeFromName(Marshal.StringToHGlobalUni("ImmersiveStartSelectionBackground"));
var colorSetEx = GetImmersiveColorFromColorSetEx((uint)userColorSet, colorType, false, 0);
return ConvertDWordColorToRGB(colorSetEx);
}
private static Color ConvertDWordColorToRGB(uint colorSetEx)
{
byte redColor = (byte)((0x000000FF & colorSetEx) >> 0);
byte greenColor = (byte)((0x0000FF00 & colorSetEx) >> 8);
byte blueColor = (byte)((0x00FF0000 & colorSetEx) >> 16);
return Color.FromArgb(redColor, greenColor, blueColor);
}
}
private void LoadTheme()
{
var themeColor = WinTheme.GetAccentColor();
var lightColor = ControlPaint.Light(themeColor);
var darkColor = ControlPaint.Dark(themeColor);
statusStrip1.BackColor = themeColor;
statusStrip1.ForeColor = lightColor;
}
private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
{
if (e.Category == UserPreferenceCategory.General || e.Category == UserPreferenceCategory.VisualStyle)
{
LoadTheme();
}
}
private void Form_Disposed(object sender, EventArgs e)
{
SystemEvents.UserPreferenceChanged -= UserPreferenceChanged;
}
private void LoadLocalizedText(int category)
{
var languageCode = Properties.Settings.Default.languageCode ?? "en";
var localization = Localization.LoadLocalization(languageCode, category);
this.Text = localization["title"];
checkBox1.Text = localization["checkBox1"];
checkBox2.Text = localization["checkBox2"];
checkBox4.Text = localization["checkBox4"];
checkBox5.Text = localization["checkBox5"];
label1.Text = localization["label1"];
button12.Text = localization["button12"];
themeToolStripMenuItem.Text = localization["themeToolStripMenuItem"];
aboutToolStripMenuItem.Text = localization["aboutToolStripMenuItem"];
moveToCenterToolStripMenuItem.Text = localization["moveToCenterToolStripMenuItem"];
chooseAColorToolStripMenuItem.Text = localization["chooseAColorToolStripMenuItem"];
label1.Text = localization["label1"];
}
private void Form7_Load(object sender, EventArgs e)
{
checkBox1.Checked = Properties.Settings.Default.sleep;
checkBox2.Checked = Properties.Settings.Default.disablead;
checkBox4.Checked = Properties.Settings.Default.uwpdis;
checkBox5.Checked = Properties.Settings.Default.explorernewt;
if (Properties.Settings.Default.language == false)
{
string systemLanguage = CultureInfo.CurrentCulture.Name;
switch (systemLanguage)
{
case "uk-UA":
Properties.Settings.Default.languageCode = "ua";
comboBox1.SelectedIndex = 2;
break;
case "ru-RU":
Properties.Settings.Default.languageCode = "ru";
comboBox1.SelectedIndex = 0;
break;
case "en-US":
Properties.Settings.Default.languageCode = "en";
comboBox1.SelectedIndex = 1;
break;
default:
Properties.Settings.Default.languageCode = "en";
comboBox1.SelectedIndex = 1;
break;
}
}
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if(checkBox1.Checked == true)
{
Properties.Settings.Default.sleep = true;
}
else
{
Properties.Settings.Default.sleep = false;
}
Properties.Settings.Default.Save();
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
if (checkBox2.Checked == true)
{
Properties.Settings.Default.disablead = true;
}
else
{
Properties.Settings.Default.disablead = false;
}
Properties.Settings.Default.Save();
}
private void button12_Click(object sender, EventArgs e)
{
Properties.Settings.Default.form1pos = this.Location;
Properties.Settings.Default.Save();
Form1 f1 = new Form1();
f1.StartPosition = FormStartPosition.Manual;
f1.Location = this.Location;
f1.Show();
this.Hide();
}
private void Form7_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
Properties.Settings.Default.form1pos = this.Location;
Properties.Settings.Default.Save();
Form1 f1 = new Form1();
f1.StartPosition = FormStartPosition.Manual;
f1.Location = this.Location;
f1.Show();
this.Hide();
}
}
private void Form7_FormClosed(object sender, FormClosedEventArgs e)
{
Properties.Settings.Default.form1pos = this.Location;
Properties.Settings.Default.Save();
System.Windows.Forms.Application.Exit();
}
private void moveToCenterToolStripMenuItem_Click(object sender, EventArgs e)
{
this.StartPosition = FormStartPosition.CenterScreen;
this.CenterToScreen();
Properties.Settings.Default.form1pos = this.Location;
Properties.Settings.Default.Save();
}
private void button12_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
Properties.Settings.Default.form1pos = this.Location;
Properties.Settings.Default.Save();
Form1 f1 = new Form1();
f1.StartPosition = FormStartPosition.Manual;
f1.Location = this.Location;
f1.Show();
this.Hide();
}
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
Form8 f8 = new Form8();
f8.StartPosition = FormStartPosition.Manual;
f8.Location = this.Location;
f8.Show();
this.Hide();
}
private void radioButton2_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
Properties.Settings.Default.form1pos = this.Location;
Properties.Settings.Default.Save();
Form1 f1 = new Form1();
f1.StartPosition = FormStartPosition.Manual;
f1.Location = this.Location;
f1.Show();
this.Hide();
}
}
private void checkBox5_CheckedChanged(object sender, EventArgs e)
{
if(checkBox5.Checked == true)
{
Properties.Settings.Default.explorernewt = true;
}
else
{
Properties.Settings.Default.explorernewt = false;
}
Properties.Settings.Default.Save();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Properties.Settings.Default.language = true;
switch (comboBox1.SelectedIndex)
{
case 0:
Properties.Settings.Default.languageCode = "ru";
break;
case 1:
Properties.Settings.Default.languageCode = "en";
break;
case 2:
Properties.Settings.Default.languageCode = "ua";
break;
case 3:
Properties.Settings.Default.languageCode = "kz";
break;
case 4:
Properties.Settings.Default.languageCode = "bl";
break;
default:
Properties.Settings.Default.languageCode = "en";
break;
}
Properties.Settings.Default.custlang = comboBox1.SelectedIndex;
string languageCode = Properties.Settings.Default.languageCode;
Properties.Settings.Default.Save();
LoadLocalizedText(11);
}
private void checkBox4_CheckedChanged(object sender, EventArgs e)
{
if (checkBox4.Checked == true)
{
Properties.Settings.Default.uwpdis = true;
}
else
{
Properties.Settings.Default.uwpdis = false;
}
Properties.Settings.Default.Save();
}
private void button1_Click(object sender, EventArgs e)
{
comboBox1.SelectedIndex = 0;
}
private void button2_Click(object sender, EventArgs e)
{
comboBox1.SelectedIndex = 1;
}
private void button3_Click(object sender, EventArgs e)
{
comboBox1.SelectedIndex = 2;
}
private void chooseAColorToolStripMenuItem_Click(object sender, EventArgs e)
{
using (ColorDialog colorDialog = new ColorDialog())
{
colorDialog.FullOpen = true;
colorDialog.Color = Color.FromArgb(7, 0, 31);
if (colorDialog.ShowDialog() == DialogResult.OK)
{
Color selectedColor = colorDialog.Color;
this.BackColor = selectedColor;
Properties.Settings.Default.SavedColor = selectedColor;
Properties.Settings.Default.Save();
}
}
}
}
}