forked from JamesCJ60/Universal-x86-Tuning-Utility
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
639 lines (545 loc) · 23.8 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
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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Management;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using AATUV3.Pages;
using UXTU.Properties;
using AATUV3.Scripts;
using RyzenSmu;
using RyzenSMUBackend;
using System.IO;
using AATUV3.Scripts.SMU_Backend_Scripts;
using Forms = System.Windows.Forms;
using UXTU.Scripts;
namespace AATUV3
{
public partial class MainWindow : Window
{
//check if program has admin rights
public static bool IsAdministrator()
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
public static string menu = "";
public static string AppName = "";
public static string mbo = "";
public static Timer reApply;
[DllImport("inpoutx64.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetPhysLong(UIntPtr memAddress, ref uint DData);
[DllImport("inpoutx64.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsInpOutDriverOpen();
[DllImport("inpoutx64.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetPhysLong(UIntPtr memAddress, uint DData);
public MainWindow()
{
if (!MainWindow.IsAdministrator())
{
// Restart and run as admin
var exeName = Process.GetCurrentProcess().MainModule.FileName;
ProcessStartInfo startInfo = new ProcessStartInfo(exeName);
startInfo.Verb = "runas";
startInfo.Arguments = "restart";
Process.Start(startInfo);
this.Close();
}
InitializeComponent();
//load main menu on load
PagesNavigation.Navigate(new System.Uri("Pages/HomeMenu.xaml", UriKind.RelativeOrAbsolute));
//Set menu lable to menu name
string menu = (string)rdHome.Content;
lblMenu.Content = menu.ToUpper();
//Get current directory
if (Settings.Default["Path"].ToString() == "" || Settings.Default["Path"].ToString() == null || Settings.Default["Path"].ToString().Contains("System32"))
{
//Get current path
var path = new Uri(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase)).LocalPath;
//Save APU Name
Settings.Default["APUName"] = System.Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER");
//Save CPUID
ManagementClass managClass = new ManagementClass("win32_processor");
ManagementObjectCollection managCollec = managClass.GetInstances();
foreach (ManagementObject managObj in managCollec)
{
Settings.Default["APUID"] = managObj.Properties["processorID"].Value.ToString();
break;
}
//Save path
Settings.Default["Path"] = path;
Settings.Default.Save();
// Debug path MessageBox.Show(path);
}
//Detect if an AYA Neo is being used
ManagementObjectSearcher baseboardSearcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_BaseBoard");
foreach (ManagementObject queryObj in baseboardSearcher.Get())
{
mbo = queryObj["Manufacturer"].ToString();
mbo = mbo.ToLower();
}
if (mbo.Contains("aya") && this.WindowState == System.Windows.WindowState.Normal)
{
//Get screen working bounds
this.MaxHeight = SystemParameters.WorkArea.Height;
this.MaxWidth = SystemParameters.WorkArea.Width;
this.WindowState = System.Windows.WindowState.Maximized;
}
string CPUName = "";
//Get CPU name
ManagementObjectSearcher myProcessorObject = new ManagementObjectSearcher("select * from Win32_Processor");
foreach (ManagementObject obj in myProcessorObject.Get())
{
CPUName = obj["Name"].ToString();
}
if (CPUName.Contains("AMD") || CPUName.Contains("Ryzen") || CPUName.Contains("Athlon") || CPUName.Contains("Radeon") || CPUName.Contains("AMD Custom APU 0405"))
{
if ((bool)Settings.Default["firstBoot"] == true)
{
BasicExeBackend.ApplySettings("\\InstallDriver.exe", "", false);
Settings.Default["firstBoot"] = false;
Settings.Default.Save();
}
Families.SetFam();
//Remove everything before Ryzen/Althon
if (CPUName.Contains("R"))
{
CPUName = CPUName.Substring(CPUName.IndexOf("R"));
}
else
{
CPUName = CPUName.Substring(CPUName.IndexOf("A"));
}
//Remove everything after the model identifier
if (CPUName.Contains("HX"))
{
CPUName = CPUName.Substring(0, CPUName.IndexOf("X") + 1);
}
else if (CPUName.Contains("HS"))
{
CPUName = CPUName.Substring(0, CPUName.IndexOf("S") + 1);
}
else if (CPUName.Contains("H"))
{
CPUName = CPUName.Substring(0, CPUName.IndexOf("H") + 1);
}
else if (CPUName.Contains("U"))
{
CPUName = CPUName.Substring(0, CPUName.IndexOf("U") + 1);
}
else if (CPUName.Contains("X"))
{
CPUName = CPUName.Substring(0, CPUName.IndexOf("X") + 1);
}
else if (CPUName.Contains("V"))
{
CPUName = CPUName.Substring(0, CPUName.IndexOf("V") + 1);
}
else if (CPUName.Contains("X"))
{
CPUName = CPUName.Substring(0, CPUName.IndexOf("Z") + 1);
}
else if (CPUName.Contains("E"))
{
CPUName = CPUName.Substring(0, CPUName.IndexOf("E") + 1);
}
else if (CPUName.Contains("e"))
{
CPUName = CPUName.Substring(0, CPUName.IndexOf("e") + 1);
}
var startColour = (SolidColorBrush)new BrushConverter().ConvertFrom("#f10046");
var endColour = (SolidColorBrush)new BrushConverter().ConvertFrom("#be0037");
Application.Current.Resources["PrimaryBlueColor"] = new LinearGradientBrush(startColour.Color, endColour.Color, new Point(0, 1), new Point(1, 0));
startColour = (SolidColorBrush)new BrushConverter().ConvertFrom("#eb0045");
endColour = (SolidColorBrush)new BrushConverter().ConvertFrom("#b80036");
Application.Current.Resources["PrimaryBlueColorHover"] = new LinearGradientBrush(startColour.Color, endColour.Color, new Point(0, 0), new Point(1, 1));
startColour = (SolidColorBrush)new BrushConverter().ConvertFrom("#a80132");
endColour = (SolidColorBrush)new BrushConverter().ConvertFrom("#750123");
Application.Current.Resources["PrimaryBlueColorDown"] = new LinearGradientBrush(startColour.Color, endColour.Color, new Point(0, 0), new Point(1, 1));
//RAVEN - 0
//PICASSO - 1
//DALI - 2
//RENOIR/LUCIENNE - 3
//MATISSE - 4
//VANGOGH - 5
//VERMEER - 6
//CEZANNE/BARCELO - 7
//REMBRANDT - 8
//PHEONIX - 9
//RAPHAEL/DRAGON RANGE - 10
switch (Families.FAMID)
{
case 4:
case 6:
case 10:
AppName = "AMD CPU Tuning Utility";
break;
case 0:
case 1:
case 2:
case 3:
case 5:
case 7:
case 8:
case 9:
AppName = "AMD APU Tuning Utility";
break;
default:
AppName = "AMD APU Tuning Utility";
break;
}
}
else if (CPUName.Contains("Intel"))
{
AppName = "Intel CPU Tuning Utility";
var startColour = (SolidColorBrush)new BrushConverter().ConvertFrom("#1e90ff");
var endColour = (SolidColorBrush)new BrushConverter().ConvertFrom("#1ec8ff");
Application.Current.Resources["PrimaryBlueColor"] = new LinearGradientBrush(startColour.Color, endColour.Color, new Point(0, 1), new Point(1, 0));
startColour = (SolidColorBrush)new BrushConverter().ConvertFrom("#5160ff");
endColour = (SolidColorBrush)new BrushConverter().ConvertFrom("#51a9ff");
Application.Current.Resources["PrimaryBlueColorHover"] = new LinearGradientBrush(startColour.Color, endColour.Color, new Point(0, 0), new Point(1, 1));
startColour = (SolidColorBrush)new BrushConverter().ConvertFrom("#0059d1");
endColour = (SolidColorBrush)new BrushConverter().ConvertFrom("#008dd1");
Application.Current.Resources["PrimaryBlueColorDown"] = new LinearGradientBrush(startColour.Color, endColour.Color, new Point(0, 0), new Point(1, 1));
//Application.Current.Resources["PrimaryBlueColorHover"] = IntelBlueHover;
//Application.Current.Resources["PrimaryBlueColorDown"] = IntelBlueDown;
rdClock.Visibility = Visibility.Collapsed;
rdSnow.Visibility = Visibility.Collapsed;
}
//Change window title
this.Title = $"{AppName} - {menu}";
//Garbage collection
DispatcherTimer Garbage = new DispatcherTimer();
Garbage.Interval = TimeSpan.FromSeconds(8);
Garbage.Tick += GarbageCollect_Tick;
Garbage.Start();
OverlayWindow overlay = new OverlayWindow();
overlay.Show();
if (Settings.Default.isMagpie == true)
{
int i = 0;
foreach (var process in Process.GetProcessesByName("magpie")) i++;
foreach (var process in Process.GetProcessesByName("Magpie")) i++;
if (i <= 0) GlobalVariables.UpdateMagpie();
}
if ((bool)Settings.Default["SensorOverlay"] == true)
{
try
{
SensorWindow sensorWindow = new SensorWindow();
sensorWindow.Show();
}
catch (Exception ex)
{
}
}
Settings.Default["APUName"] = CPUName;
Settings.Default.Save();
Tray();
if (Convert.ToBoolean(Settings.Default["StartMinimised"]) == true)
{
this.WindowState = WindowState.Minimized;
_trayIcon.Visible = true;
this.Hide();
}
}
private void btnClose_Click(object sender, RoutedEventArgs e)
{
//Close application
System.Windows.Application.Current.Shutdown();
}
private Forms.NotifyIcon _trayIcon;
private void Tray()
{
_trayIcon = new Forms.NotifyIcon();
_trayIcon.Icon = new System.Drawing.Icon(Settings.Default.Path + "\\favicon.ico");
_trayIcon.Text = $"UXTU";
_trayIcon.Click += trayIcon_Click;
}
private void trayIcon_Click(object sender, EventArgs e)
{
this.Show();
WindowState = WindowState.Normal;
_trayIcon.Visible = false;
}
private void btnRestore_Click(object sender, RoutedEventArgs e)
{
//Get screen working bounds
this.MaxHeight = SystemParameters.WorkArea.Height;
this.MaxWidth = SystemParameters.WorkArea.Width;
//Maximise window if Window is in normal view else set normal window view
if (WindowState == WindowState.Normal)
WindowState = WindowState.Maximized;
else
WindowState = WindowState.Normal;
}
private void btnMinimize_Click(object sender, RoutedEventArgs e)
{
//Minimise window
_trayIcon.Visible = true;
WindowState = WindowState.Minimized;
this.Hide();
}
private void rdHome_Click(object sender, RoutedEventArgs e)
{
if (AppName.Contains("AMD APU"))
{
//Load menu
PagesNavigation.Navigate(new System.Uri("Pages/HomeMenu.xaml", UriKind.RelativeOrAbsolute));
//Set menu lable to menu name
menu = (string)rdHome.Content;
lblMenu.Content = menu.ToUpper();
}
if (AppName.Contains("AMD CPU"))
{
//Load menu
PagesNavigation.Navigate(new System.Uri("Pages/HomeMenu.xaml", UriKind.RelativeOrAbsolute));
//Set menu lable to menu name
menu = (string)rdHome.Content;
lblMenu.Content = menu.ToUpper();
}
if (AppName.Contains("Intel CPU"))
{
//Load menu
PagesNavigation.Navigate(new System.Uri("Pages/HomeMenu.xaml", UriKind.RelativeOrAbsolute));
//Set menu lable to menu name
menu = (string)rdHome.Content;
lblMenu.Content = menu.ToUpper();
}
//Change window title
this.Title = $"{AppName} - {menu}";
}
private void rdAC_Click(object sender, RoutedEventArgs e)
{
//Load menu
PagesNavigation.Navigate(new System.Uri("Pages/ASUSAC.xaml", UriKind.RelativeOrAbsolute));
//Set menu lable to menu name
menu = (string)rdAC.Content;
lblMenu.Content = menu.ToUpper();
//Change window title
this.Title = $"{AppName} - {menu}";
}
private void rdSnow_Click(object sender, RoutedEventArgs e)
{
if (AppName.Contains("AMD APU"))
{
//Load menu
PagesNavigation.Navigate(new System.Uri("Pages/ProjectSnowdrop.xaml", UriKind.RelativeOrAbsolute));
//Set menu lable to menu name
menu = (string)rdSnow.Content;
lblMenu.Content = menu.ToUpper();
}
if (AppName.Contains("AMD CPU"))
{
//Load menu
PagesNavigation.Navigate(new System.Uri("Pages/ComingSoon.xaml", UriKind.RelativeOrAbsolute));
//Set menu lable to menu name
menu = (string)rdSnow.Content;
lblMenu.Content = menu.ToUpper();
}
if (AppName.Contains("Intel CPU"))
{
//Load menu
PagesNavigation.Navigate(new System.Uri("Pages/ComingSoon.xaml", UriKind.RelativeOrAbsolute));
//Set menu lable to menu name
menu = (string)rdSnow.Content;
lblMenu.Content = menu.ToUpper();
}
//Change window title
this.Title = $"{AppName} - {menu}";
}
private void rdCustom_Click(object sender, RoutedEventArgs e)
{
if (AppName.Contains("AMD APU"))
{
//Load menu
PagesNavigation.Navigate(new System.Uri("Pages/CustomPresets.xaml", UriKind.RelativeOrAbsolute));
//Set menu lable to menu name
menu = (string)rdCustom.Content;
lblMenu.Content = menu.ToUpper();
}
if (AppName.Contains("AMD CPU"))
{
//Load menu
PagesNavigation.Navigate(new System.Uri("Pages/AMDCPU/AMDCustomPresets.xaml", UriKind.RelativeOrAbsolute));
//Set menu lable to menu name
menu = (string)rdCustom.Content;
lblMenu.Content = menu.ToUpper();
}
if (AppName.Contains("Intel CPU"))
{
//Load menu
PagesNavigation.Navigate(new System.Uri("Pages/Intel/IntelCustomPresets.xaml", UriKind.RelativeOrAbsolute));
//Set menu lable to menu name
menu = (string)rdCustom.Content;
lblMenu.Content = menu.ToUpper();
}
//Change window title
this.Title = $"{AppName} - {menu}";
}
private void rdAdaptive_Click(object sender, RoutedEventArgs e)
{
if (AppName.Contains("AMD APU"))
{
//Load menu
PagesNavigation.Navigate(new System.Uri("Pages/ComingSoon.xaml", UriKind.RelativeOrAbsolute));
//Set menu lable to menu name
menu = (string)rdAdaptive.Content;
lblMenu.Content = menu.ToUpper();
}
if (AppName.Contains("AMD CPU"))
{
//Load menu
PagesNavigation.Navigate(new System.Uri("Pages/ComingSoon.xaml", UriKind.RelativeOrAbsolute));
//Set menu lable to menu name
menu = (string)rdAdaptive.Content;
lblMenu.Content = menu.ToUpper();
}
if (AppName.Contains("Intel CPU"))
{
//Load menu
PagesNavigation.Navigate(new System.Uri("Pages/ComingSoon.xaml", UriKind.RelativeOrAbsolute));
//Set menu lable to menu name
menu = (string)rdAdaptive.Content;
lblMenu.Content = menu.ToUpper();
}
//Change window title
this.Title = $"{AppName} - {menu}";
}
private void rdClock_Click(object sender, RoutedEventArgs e)
{
if (AppName.Contains("AMD APU") || AppName.Contains("AMD CPU"))
{
//Load menu
PagesNavigation.Navigate(new System.Uri("Pages/ClockControl.xaml", UriKind.RelativeOrAbsolute));
//Set menu lable to menu name
menu = (string)rdClock.Content;
lblMenu.Content = menu.ToUpper();
}
if (AppName.Contains("Intel CPU"))
{
//Load menu
PagesNavigation.Navigate(new System.Uri("Pages/ComingSoon.xaml", UriKind.RelativeOrAbsolute));
//Set menu lable to menu name
menu = (string)rdClock.Content;
lblMenu.Content = menu.ToUpper();
}
//Change window title
this.Title = $"{AppName} - {menu}";
}
//private void rdAC_Click(object sender, RoutedEventArgs e)
//{
// //Load menu
// PagesNavigation.Navigate(new System.Uri("Pages/ComingSoon.xaml", UriKind.RelativeOrAbsolute));
// //Set menu lable to menu name
// string menu = (string)rdAC.Content;
// lblMenu.Content = menu.ToUpper();
// //Change window title
// this.Title = $"AMD APU Tuning Utility - {menu}";
//}
private void rdInfo_Click(object sender, RoutedEventArgs e)
{
if (AppName.Contains("AMD"))
{
if (pmtables.PMT_Sensors.Length == 0 || pmtables.PMT_Sensors == null)
{
if (File.Exists(Settings.Default["Path"].ToString() + $"\\bin\\pmtables\\0x00{string.Format("{0:x}", Addresses.PMTableVersion)}-sensors.txt"))
{
pmtables.PMT_Sensors = File.ReadAllLines(Settings.Default["Path"].ToString() + $"\\bin\\pmtables\\0x00{string.Format("{0:x}", Addresses.PMTableVersion)}-sensors.txt");
}
}
}
if (File.Exists(Settings.Default["Path"].ToString() + $"\\bin\\pmtables\\0x00{string.Format("{0:x}", Addresses.PMTableVersion)}-sensors.txt"))
{
PagesNavigation.Navigate(new System.Uri("Pages/BasicSensor.xaml", UriKind.RelativeOrAbsolute));
}
else
{
PagesNavigation.Navigate(new System.Uri("Pages/ComingSoon.xaml", UriKind.RelativeOrAbsolute));
}
if (AppName.Contains("Intel CPU"))
{
//Load menu
PagesNavigation.Navigate(new System.Uri("Pages/ComingSoon.xaml", UriKind.RelativeOrAbsolute));
//Set menu lable to menu name
}
menu = (string)rdInfo.Content;
lblMenu.Content = menu.ToUpper();
//Change window title
this.Title = $"{AppName} - {menu}";
}
private void rdSettings_Click(object sender, RoutedEventArgs e)
{
if (AppName.Contains("AMD APU"))
{
//Load menu
PagesNavigation.Navigate(new System.Uri("Pages/Settings.xaml", UriKind.RelativeOrAbsolute));
//Set menu lable to menu name
menu = (string)rdSettings.Content;
lblMenu.Content = menu.ToUpper();
}
if (AppName.Contains("AMD CPU"))
{
//Load menu
PagesNavigation.Navigate(new System.Uri("Pages/Settings.xaml", UriKind.RelativeOrAbsolute));
//Set menu lable to menu name
menu = (string)rdSettings.Content;
lblMenu.Content = menu.ToUpper();
}
if (AppName.Contains("Intel CPU"))
{
//Load menu
PagesNavigation.Navigate(new System.Uri("Pages/Settings.xaml", UriKind.RelativeOrAbsolute));
//Set menu lable to menu name
menu = (string)rdSettings.Content;
lblMenu.Content = menu.ToUpper();
}
//Change window title
this.Title = $"{AppName} - {menu}";
}
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
//Make window follow cursor when button is down on top bar
if (e.ChangedButton == MouseButton.Left)
this.DragMove();
}
async void GarbageCollect_Tick(object sender, EventArgs e)
{
//Free resources back to system
await BasicExeBackend.Garbage_Collect();
}
private void home_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
//Close application
//System.Windows.Application.Current.Shutdown();
Environment.Exit(0);
}
private void rdFSR_Click(object sender, RoutedEventArgs e)
{
//Load menu
PagesNavigation.Navigate(new System.Uri("Pages/FSR.xaml", UriKind.RelativeOrAbsolute));
//Set menu lable to menu name
menu = (string)rdFSR.Content;
lblMenu.Content = menu.ToUpper();
}
}
}