-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
1362 lines (1195 loc) · 53.1 KB
/
MainWindow.xaml.cs
File metadata and controls
1362 lines (1195 loc) · 53.1 KB
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
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System.Management;
using System.IO;
using System.Text;
using System.Windows;
using System.Windows.Input;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Collections.ObjectModel;
using System.Linq;
using ModernOptimizer.Helpers;
using ModernOptimizer.Models;
using System.Threading.Tasks;
namespace ModernOptimizer;
public partial class MainWindow : Window
{
private int _logEventCount = 0;
private Settings _settings;
private ObservableCollection<StartupItem> _startupItems = new();
private SystemCleaner.CleanupResult? _scanResult;
private Border? _notificationBorder;
public MainWindow()
{
InitializeComponent();
// Enable hardware acceleration for better performance
RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.Default;
_settings = Settings.Load();
LoadSettings();
// Initialize audio system
AudioHelper.Initialize();
// Generate click sound if it doesn't exist
var soundPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Assets", "click.wav");
if (!File.Exists(soundPath))
{
SoundGenerator.GenerateClickSound(soundPath);
}
LoadSystemInformation();
LogActivity("SYSTEM", "Vera Optimizer initialized", LogLevel.Success);
LogActivity("INFO", "Administrator privileges verified", LogLevel.Info);
LogActivity("SETTINGS", $"Settings loaded from: {Settings.GetSettingsPath()}", LogLevel.Success);
CreateNotificationOverlay();
MainTabControl.SelectionChanged += TabControl_SelectionChanged;
// Smooth window fade-in animation on startup (optimized)
Opacity = 0;
Loaded += (s, e) =>
{
var fadeIn = new DoubleAnimation
{
From = 0,
To = 1,
Duration = TimeSpan.FromMilliseconds(300), // Faster for better responsiveness
EasingFunction = new CubicEase { EasingMode = EasingMode.EaseOut }
};
BeginAnimation(OpacityProperty, fadeIn);
// Load scripts dynamically
LoadAdvancedScripts();
};
Closed += (s, e) => AudioHelper.Cleanup();
}
private void LoadAdvancedScripts()
{
try
{
ScriptsContainer.Children.Clear();
var scriptsBase = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Scripts");
if (!Directory.Exists(scriptsBase))
{
var errorText = new TextBlock
{
Text = "Scripts folder not found",
FontSize = 14,
Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF5555")),
HorizontalAlignment = HorizontalAlignment.Center,
Margin = new Thickness(0, 50, 0, 50)
};
ScriptsContainer.Children.Add(errorText);
return;
}
var categories = new[]
{
new { Name = "1 Check", Icon = "🔍", Title = "System Diagnostics", Color = "#4FACFE" },
new { Name = "2 Refresh", Icon = "🔄", Title = "System Refresh", Color = "#00F260" },
new { Name = "3 Setup", Icon = "⚙️", Title = "Initial Setup", Color = "#FF6B9D" },
new { Name = "4 Installers", Icon = "📦", Title = "Setup & Apps", Color = "#FFA07A" },
new { Name = "5 Graphics", Icon = "🎮", Title = "Graphics & Gaming", Color = "#C471F5" },
new { Name = "6 Windows", Icon = "🪟", Title = "Windows Tweaks", Color = "#00D9FF" },
new { Name = "7 Hardware", Icon = "🖱️", Title = "Hardware Tweaks", Color = "#FFD700" },
new { Name = "8 Advanced", Icon = "⚡", Title = "Advanced Tweaks", Color = "#FF4757" }
};
foreach (var category in categories)
{
var categoryPath = Path.Combine(scriptsBase, category.Name);
if (!Directory.Exists(categoryPath)) continue;
var scripts = Directory.GetFiles(categoryPath, "*.ps1").OrderBy(f => f).ToList();
if (scripts.Count == 0) continue;
// Category Header
var headerText = new TextBlock
{
Text = $"{category.Icon} {category.Title}",
FontSize = 18,
FontWeight = FontWeights.Bold,
Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(category.Color)),
Margin = new Thickness(0, 20, 0, 15)
};
ScriptsContainer.Children.Add(headerText);
// Scripts in this category
foreach (var scriptPath in scripts)
{
var scriptName = Path.GetFileNameWithoutExtension(scriptPath);
var scriptCard = new Border
{
Background = new SolidColorBrush(Color.FromArgb(20, 255, 255, 255)),
BorderBrush = new SolidColorBrush(Color.FromArgb(40, 255, 255, 255)),
BorderThickness = new Thickness(1),
CornerRadius = new CornerRadius(8),
Padding = new Thickness(15, 12, 15, 12),
Margin = new Thickness(0, 0, 0, 8)
};
var grid = new Grid();
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
var nameText = new TextBlock
{
Text = scriptName,
FontSize = 13,
Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#EAEAEA")),
VerticalAlignment = VerticalAlignment.Center
};
Grid.SetColumn(nameText, 0);
grid.Children.Add(nameText);
var runButton = new Button
{
Content = "▶️ Run Script",
Padding = new Thickness(15, 6, 15, 6),
Tag = scriptPath,
Background = new SolidColorBrush(Color.FromArgb(30, 0, 255, 240)),
BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#00FFF0")),
BorderThickness = new Thickness(1),
Foreground = new SolidColorBrush(Colors.White),
FontSize = 12,
FontWeight = FontWeights.Medium,
Cursor = Cursors.Hand
};
runButton.Click += RunScript_Click;
Grid.SetColumn(runButton, 1);
grid.Children.Add(runButton);
scriptCard.Child = grid;
ScriptsContainer.Children.Add(scriptCard);
}
}
LogActivity("SCRIPTS", "Loaded advanced scripts interface", LogLevel.Success);
}
catch (Exception ex)
{
LogActivity("ERROR", $"Failed to load scripts: {ex.Message}", LogLevel.Error);
}
}
#region Settings Management
private void LoadSettings()
{
PerformanceToggle.IsChecked = _settings.PerformanceTweaksEnabled;
NetworkThrottlingToggle.IsChecked = _settings.NetworkThrottlingDisabled;
HibernationToggle.IsChecked = _settings.HibernationDisabled;
WindowsTelemetryToggle.IsChecked = _settings.WindowsTelemetryDisabled;
CoPilotToggle.IsChecked = _settings.CoPilotDisabled;
}
private void SaveSettings()
{
_settings.PerformanceTweaksEnabled = PerformanceToggle.IsChecked ?? false;
_settings.NetworkThrottlingDisabled = NetworkThrottlingToggle.IsChecked ?? false;
_settings.HibernationDisabled = HibernationToggle.IsChecked ?? false;
_settings.WindowsTelemetryDisabled = WindowsTelemetryToggle.IsChecked ?? false;
_settings.CoPilotDisabled = CoPilotToggle.IsChecked ?? false;
_settings.Save();
LogActivity("SETTINGS", "User preferences saved to AppData", LogLevel.Success);
}
#endregion
#region Activity Log System
private enum LogLevel
{
Info,
Success,
Warning,
Error
}
private void LogActivity(string category, string message, LogLevel level = LogLevel.Info)
{
_logEventCount++;
var timestamp = DateTime.Now.ToString("HH:mm:ss");
var levelColor = level switch
{
LogLevel.Success => "#27C93F",
LogLevel.Warning => "#FFBD2E",
LogLevel.Error => "#FF5F56",
_ => "#4FACFE"
};
var levelText = level switch
{
LogLevel.Success => "[OK]",
LogLevel.Warning => "[WARN]",
LogLevel.Error => "[ERR]",
_ => "[>>]"
};
Dispatcher.Invoke(() =>
{
var currentLog = ActivityLog.Text;
var newEntry = $"\n[{timestamp}] {levelText} [{category}] {message}";
ActivityLog.Text = currentLog + newEntry;
LogCount.Text = $"{_logEventCount} events";
// Update status indicator
StatusIndicator.Fill = new System.Windows.Media.SolidColorBrush(
(System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(levelColor)
);
StatusText.Text = level switch
{
LogLevel.Success => "Success",
LogLevel.Warning => "Warning",
LogLevel.Error => "Error",
_ => "Active"
};
// Auto-scroll to bottom
LogScrollViewer.ScrollToEnd();
});
}
private void ClearLog_Click(object sender, RoutedEventArgs e)
{
ActivityLog.Text = "[SYSTEM] Activity log cleared";
_logEventCount = 0;
LogCount.Text = "0 events";
StatusIndicator.Fill = new System.Windows.Media.SolidColorBrush(
(System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#27C93F")
);
StatusText.Text = "Ready";
}
#endregion
#region Window Controls
private void TitleBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.ClickCount == 2)
{
MaximizeButton_Click(sender, e);
}
else
{
DragMove();
}
}
private void MinimizeButton_Click(object sender, RoutedEventArgs e)
{
WindowState = WindowState.Minimized;
LogActivity("WINDOW", "Window minimized", LogLevel.Info);
}
private void MaximizeButton_Click(object sender, RoutedEventArgs e)
{
// Professional smooth animation for maximize/restore
if (WindowState == WindowState.Normal)
{
WindowState = WindowState.Maximized;
LogActivity("WINDOW", "Window maximized", LogLevel.Info);
}
else
{
WindowState = WindowState.Normal;
LogActivity("WINDOW", "Window restored", LogLevel.Info);
}
}
private void CloseButton_Click(object sender, RoutedEventArgs e)
{
Close();
}
#endregion
#region Navigation
private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// No animations - instant tab switching for maximum responsiveness
}
private void AnimateTabTransition(TabItem tab)
{
// Removed for instant performance
}
private void NavigateToDashboard(object sender, RoutedEventArgs e)
{
AudioHelper.PlayClickSound();
MainTabControl.SelectedIndex = 0;
LogActivity("NAV", "Navigated to Dashboard", LogLevel.Info);
}
private void NavigateToOptimizations(object sender, RoutedEventArgs e)
{
AudioHelper.PlayClickSound();
MainTabControl.SelectedIndex = 1;
LogActivity("NAV", "Navigated to Optimizations", LogLevel.Info);
}
private void NavigateToPrivacy(object sender, RoutedEventArgs e)
{
AudioHelper.PlayClickSound();
MainTabControl.SelectedIndex = 2;
LogActivity("NAV", "Navigated to Privacy & Security", LogLevel.Info);
}
private void NavigateToStats(object sender, RoutedEventArgs e)
{
AudioHelper.PlayClickSound();
MainTabControl.SelectedIndex = 3;
LogActivity("NAV", "Navigated to Optimization Stats", LogLevel.Info);
UpdateOptimizationScore();
}
private void NavigateToStartup(object sender, RoutedEventArgs e)
{
AudioHelper.PlayClickSound();
MainTabControl.SelectedIndex = 5; // Updated: Stats is now index 3, System Info is 4
LogActivity("NAV", "Navigated to Startup Manager", LogLevel.Info);
LoadStartupItems();
}
private void NavigateToCleaner(object sender, RoutedEventArgs e)
{
AudioHelper.PlayClickSound();
MainTabControl.SelectedIndex = 6; // Updated
LogActivity("NAV", "Navigated to System Cleaner", LogLevel.Info);
}
private void NavigateToSystemInfo(object sender, RoutedEventArgs e)
{
AudioHelper.PlayClickSound();
MainTabControl.SelectedIndex = 4; // Updated: System Info is now index 4
LogActivity("NAV", "Navigated to System Information", LogLevel.Info);
}
private void NavigateToActivityLog(object sender, RoutedEventArgs e)
{
AudioHelper.PlayClickSound();
MainTabControl.SelectedIndex = 7; // Updated
LogActivity("NAV", "Viewing Activity Log", LogLevel.Info);
}
private void NavigateToAdvancedScripts(object sender, RoutedEventArgs e)
{
AudioHelper.PlayClickSound();
MainTabControl.SelectedIndex = 8; // Advanced Scripts tab
LogActivity("NAV", "Navigated to Advanced Scripts", LogLevel.Info);
}
private void NavigateToAbout(object sender, RoutedEventArgs e)
{
AudioHelper.PlayClickSound();
MainTabControl.SelectedIndex = 9; // About tab
LogActivity("NAV", "Viewing About", LogLevel.Info);
}
private void OpenScriptFolder_Click(object sender, RoutedEventArgs e)
{
try
{
AudioHelper.PlayClickSound();
if (sender is Button button && button.Tag is string folderName)
{
var scriptsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Scripts", folderName);
if (Directory.Exists(scriptsPath))
{
System.Diagnostics.Process.Start("explorer.exe", scriptsPath);
LogActivity("SCRIPTS", $"Opened folder: {folderName}", LogLevel.Success);
ShowToast($"Opened {folderName} scripts folder");
}
else
{
LogActivity("ERROR", $"Scripts folder not found: {folderName}", LogLevel.Error);
ShowToast($"Scripts folder not found: {folderName}", true);
}
}
}
catch (Exception ex)
{
LogActivity("ERROR", $"Failed to open scripts folder: {ex.Message}", LogLevel.Error);
ShowToast($"Error: {ex.Message}", true);
}
}
private async void RunScript_Click(object sender, RoutedEventArgs e)
{
try
{
AudioHelper.PlayClickSound();
if (sender is Button button && button.Tag is string scriptPath)
{
if (!File.Exists(scriptPath))
{
LogActivity("ERROR", $"Script not found: {Path.GetFileName(scriptPath)}", LogLevel.Error);
ShowToast("Script file not found", true);
return;
}
var scriptName = Path.GetFileName(scriptPath);
LogActivity("SCRIPT", $"Running: {scriptName}", LogLevel.Info);
ShowToast($"Running {scriptName}...");
// Disable button during execution
button.IsEnabled = false;
button.Content = "⏳ Running...";
// Run script silently in background
await Task.Run(() =>
{
try
{
var process = new System.Diagnostics.Process
{
StartInfo = new System.Diagnostics.ProcessStartInfo
{
FileName = "powershell.exe",
Arguments = $"-NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File \"{scriptPath}\"",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
Verb = "runas" // Run as admin
}
};
var output = new System.Text.StringBuilder();
var error = new System.Text.StringBuilder();
process.OutputDataReceived += (s, args) =>
{
if (!string.IsNullOrEmpty(args.Data))
{
output.AppendLine(args.Data);
Dispatcher.Invoke(() => LogActivity("OUTPUT", args.Data, LogLevel.Info));
}
};
process.ErrorDataReceived += (s, args) =>
{
if (!string.IsNullOrEmpty(args.Data))
{
error.AppendLine(args.Data);
Dispatcher.Invoke(() => LogActivity("ERROR", args.Data, LogLevel.Warning));
}
};
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
var exitCode = process.ExitCode;
Dispatcher.Invoke(() =>
{
if (exitCode == 0)
{
LogActivity("SCRIPT", $"✅ Completed: {scriptName}", LogLevel.Success);
ShowToast($"✅ {scriptName} completed successfully");
}
else
{
LogActivity("SCRIPT", $"⚠️ Completed with code {exitCode}: {scriptName}", LogLevel.Warning);
ShowToast($"Script finished with code {exitCode}", true);
}
});
}
catch (System.ComponentModel.Win32Exception)
{
// User cancelled UAC or no admin rights
Dispatcher.Invoke(() =>
{
LogActivity("SCRIPT", $"❌ Admin rights required for: {scriptName}", LogLevel.Error);
ShowToast("Administrator rights required", true);
});
}
catch (Exception ex)
{
Dispatcher.Invoke(() =>
{
LogActivity("ERROR", $"Script failed: {ex.Message}", LogLevel.Error);
ShowToast($"Error: {ex.Message}", true);
});
}
});
// Re-enable button
button.IsEnabled = true;
button.Content = "▶️ Run Script";
}
}
catch (Exception ex)
{
LogActivity("ERROR", $"Failed to execute script: {ex.Message}", LogLevel.Error);
ShowToast($"Error: {ex.Message}", true);
}
}
private void OpenGitHubRepo_Click(object sender, RoutedEventArgs e)
{
try
{
AudioHelper.PlayClickSound();
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
{
FileName = "https://github.com/FR33THYFR33THY/Ultimate-Windows-Optimization-Guide",
UseShellExecute = true
});
LogActivity("INFO", "Opened Ultimate Windows Optimization Guide repository", LogLevel.Info);
}
catch (Exception ex)
{
LogActivity("ERROR", $"Failed to open GitHub repository: {ex.Message}", LogLevel.Error);
}
}
#endregion
#region Startup Manager
private void LoadStartupItems()
{
Task.Run(() =>
{
var items = StartupManager.GetStartupItems();
Dispatcher.Invoke(() =>
{
_startupItems.Clear();
foreach (var item in items)
{
_startupItems.Add(item);
}
StartupItemsControl.ItemsSource = _startupItems;
if (_startupItems.Count == 0)
{
NoStartupItemsText.Visibility = Visibility.Visible;
}
else
{
NoStartupItemsText.Visibility = Visibility.Collapsed;
}
LogActivity("STARTUP", $"Loaded {_startupItems.Count} startup programs", LogLevel.Success);
ShowToast($"Found {_startupItems.Count} startup programs");
});
});
}
private void RefreshStartup_Click(object sender, RoutedEventArgs e)
{
LogActivity("STARTUP", "Refreshing startup items list...", LogLevel.Info);
LoadStartupItems();
}
private void StartupItem_Changed(object sender, RoutedEventArgs e)
{
if (sender is CheckBox checkBox && checkBox.Tag is StartupItem item)
{
try
{
if (checkBox.IsChecked == false)
{
LogActivity("STARTUP", $"Disabling startup item: {item.Name}", LogLevel.Info);
if (StartupManager.DisableStartupItem(item))
{
LogActivity("STARTUP", $"Successfully disabled: {item.Name}", LogLevel.Success);
ShowToast($"Disabled: {item.Name}");
}
else
{
LogActivity("STARTUP", $"Failed to disable: {item.Name}", LogLevel.Error);
ShowToast($"Failed to disable: {item.Name}", true);
checkBox.IsChecked = true;
}
}
else
{
LogActivity("STARTUP", $"Enabling startup item: {item.Name}", LogLevel.Info);
if (StartupManager.EnableStartupItem(item))
{
LogActivity("STARTUP", $"Successfully enabled: {item.Name}", LogLevel.Success);
ShowToast($"Enabled: {item.Name}");
}
else
{
LogActivity("STARTUP", $"Failed to enable: {item.Name}", LogLevel.Error);
ShowToast($"Failed to enable: {item.Name}", true);
checkBox.IsChecked = false;
}
}
}
catch (Exception ex)
{
LogActivity("ERROR", $"Startup modification error: {ex.Message}", LogLevel.Error);
ShowToast($"Error: {ex.Message}", true);
}
}
}
#endregion
#region System Cleaner
private void ScanSystem_Click(object sender, RoutedEventArgs e)
{
ScanButton.IsEnabled = false;
CleanButton.IsEnabled = false;
CleanerStatusText.Text = "Scanning system...";
Task.Run(() =>
{
LogActivity("CLEANER", "Starting system scan...", LogLevel.Info);
_scanResult = SystemCleaner.ScanSystem();
Dispatcher.Invoke(() =>
{
var totalSize = SystemCleaner.FormatBytes(_scanResult.TotalSize);
CleanerStatusText.Text = $"Scan complete - Found cleanable files";
CleanerSizeText.Text = totalSize;
CleanerSizeText.Visibility = Visibility.Visible;
CleanButton.IsEnabled = true;
ScanButton.IsEnabled = true;
LogActivity("CLEANER", $"Scan complete - {totalSize} of cleanable files found", LogLevel.Success);
ShowToast($"Found {totalSize} of cleanable files");
});
});
}
private void CleanSystem_Click(object sender, RoutedEventArgs e)
{
var result = MessageBox.Show(
"This will permanently delete temporary files and cached data. Continue?",
"Confirm Cleanup",
MessageBoxButton.YesNo,
MessageBoxImage.Question
);
if (result != MessageBoxResult.Yes)
return;
CleanButton.IsEnabled = false;
ScanButton.IsEnabled = false;
CleanerStatusText.Text = "Cleaning system...";
// Capture checkbox states on UI thread
var cleanTemp = TempFilesCheck.IsChecked == true;
var cleanBrowser = BrowserCacheCheck.IsChecked == true;
var cleanUpdate = UpdateCacheCheck.IsChecked == true;
var cleanRecycle = RecycleBinCheck.IsChecked == true;
var cleanPrefetch = PrefetchCheck.IsChecked == true;
var cleanThumbnail = ThumbnailCheck.IsChecked == true;
Task.Run(() =>
{
try
{
LogActivity("CLEANER", "Starting system cleanup...", LogLevel.Info);
// All cleanup happens on background thread to prevent freezing
if (cleanTemp)
{
LogActivity("CLEANER", "Cleaning temporary files...", LogLevel.Info);
SystemCleaner.CleanTempFiles();
LogActivity("CLEANER", "Temporary files cleaned successfully", LogLevel.Success);
}
if (cleanBrowser)
{
LogActivity("CLEANER", "Cleaning browser cache...", LogLevel.Info);
SystemCleaner.CleanBrowserCache();
LogActivity("CLEANER", "Browser cache cleaned successfully", LogLevel.Success);
}
if (cleanUpdate)
{
LogActivity("CLEANER", "Cleaning Windows Update cache...", LogLevel.Info);
SystemCleaner.CleanUpdateCache();
LogActivity("CLEANER", "Update cache cleaned successfully", LogLevel.Success);
}
if (cleanRecycle)
{
LogActivity("CLEANER", "Emptying Recycle Bin...", LogLevel.Info);
SystemCleaner.CleanRecycleBin();
LogActivity("CLEANER", "Recycle Bin emptied successfully", LogLevel.Success);
}
if (cleanPrefetch)
{
LogActivity("CLEANER", "Cleaning prefetch data...", LogLevel.Info);
SystemCleaner.CleanPrefetch();
LogActivity("CLEANER", "Prefetch data cleaned successfully", LogLevel.Success);
}
if (cleanThumbnail)
{
LogActivity("CLEANER", "Cleaning thumbnail cache...", LogLevel.Info);
SystemCleaner.CleanThumbnailCache();
LogActivity("CLEANER", "Thumbnail cache cleaned successfully", LogLevel.Success);
}
// Update UI on completion
Dispatcher.Invoke(() =>
{
var freedSize = _scanResult != null ? SystemCleaner.FormatBytes(_scanResult.TotalSize) : "Unknown";
CleanerStatusText.Text = "Cleanup complete!";
CleanerSizeText.Visibility = Visibility.Collapsed;
CleanButton.IsEnabled = false;
ScanButton.IsEnabled = true;
LogActivity("CLEANER", $"System cleanup complete - approximately {freedSize} freed", LogLevel.Success);
ShowToast($"Cleanup complete! ~{freedSize} freed");
});
}
catch (Exception ex)
{
Dispatcher.Invoke(() =>
{
LogActivity("ERROR", $"Cleanup error: {ex.Message}", LogLevel.Error);
ShowToast($"Cleanup error: {ex.Message}", true);
CleanButton.IsEnabled = true;
ScanButton.IsEnabled = true;
CleanerStatusText.Text = "Error during cleanup";
});
}
});
}
#endregion
#region Professional Toast Notifications
private void CreateNotificationOverlay()
{
// Create notification container that sits at top-center of window
// Content is now a Grid containing everything
var rootGrid = (Grid)Content;
_notificationBorder = new Border
{
Background = new SolidColorBrush(Color.FromArgb(240, 20, 25, 40)),
CornerRadius = new CornerRadius(12),
Padding = new Thickness(20, 12, 20, 12),
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Top,
Margin = new Thickness(0, 80, 0, 0),
Visibility = Visibility.Collapsed,
Effect = new System.Windows.Media.Effects.DropShadowEffect
{
Color = Colors.Black,
BlurRadius = 20,
Opacity = 0.5,
ShadowDepth = 3
}
};
var stackPanel = new StackPanel
{
Orientation = Orientation.Horizontal
};
var iconText = new TextBlock
{
Text = "✓",
FontSize = 16,
FontWeight = FontWeights.Bold,
Foreground = new SolidColorBrush(Color.FromRgb(39, 201, 63)),
Margin = new Thickness(0, 0, 10, 0),
VerticalAlignment = VerticalAlignment.Center
};
iconText.SetValue(System.Windows.Controls.Panel.ZIndexProperty, 1000);
var messageText = new TextBlock
{
FontSize = 13,
FontWeight = FontWeights.Medium,
Foreground = Brushes.White,
VerticalAlignment = VerticalAlignment.Center
};
messageText.SetValue(System.Windows.Controls.Panel.ZIndexProperty, 1000);
stackPanel.Children.Add(iconText);
stackPanel.Children.Add(messageText);
_notificationBorder.Child = stackPanel;
_notificationBorder.SetValue(System.Windows.Controls.Panel.ZIndexProperty, 10000);
rootGrid.Children.Add(_notificationBorder);
}
private void ShowToast(string message, bool isError = false)
{
if (_notificationBorder == null) return;
Dispatcher.Invoke(() =>
{
var stackPanel = (StackPanel)_notificationBorder.Child;
var iconText = (TextBlock)stackPanel.Children[0];
var messageText = (TextBlock)stackPanel.Children[1];
if (isError)
{
iconText.Text = "✕";
iconText.Foreground = new SolidColorBrush(Color.FromRgb(255, 95, 86));
_notificationBorder.BorderBrush = new SolidColorBrush(Color.FromRgb(255, 95, 86));
_notificationBorder.BorderThickness = new Thickness(2);
}
else
{
iconText.Text = "✓";
iconText.Foreground = new SolidColorBrush(Color.FromRgb(39, 201, 63));
_notificationBorder.BorderBrush = new SolidColorBrush(Color.FromRgb(39, 201, 63));
_notificationBorder.BorderThickness = new Thickness(2);
}
messageText.Text = message;
_notificationBorder.Visibility = Visibility.Visible;
// Professional slide-in animation
var slideIn = new ThicknessAnimation
{
From = new Thickness(0, -50, 0, 0),
To = new Thickness(0, 80, 0, 0),
Duration = TimeSpan.FromMilliseconds(300),
EasingFunction = new CubicEase { EasingMode = EasingMode.EaseOut }
};
var fadeIn = new DoubleAnimation
{
From = 0,
To = 1,
Duration = TimeSpan.FromMilliseconds(300)
};
_notificationBorder.BeginAnimation(Border.MarginProperty, slideIn);
_notificationBorder.BeginAnimation(UIElement.OpacityProperty, fadeIn);
// Auto-hide after 3 seconds
Task.Delay(3000).ContinueWith(_ =>
{
Dispatcher.Invoke(() =>
{
var slideOut = new ThicknessAnimation
{
From = new Thickness(0, 80, 0, 0),
To = new Thickness(0, -50, 0, 0),
Duration = TimeSpan.FromMilliseconds(300),
EasingFunction = new CubicEase { EasingMode = EasingMode.EaseIn }
};
var fadeOut = new DoubleAnimation
{
From = 1,
To = 0,
Duration = TimeSpan.FromMilliseconds(300)
};
slideOut.Completed += (s, e) =>
{
_notificationBorder.Visibility = Visibility.Collapsed;
};
_notificationBorder.BeginAnimation(Border.MarginProperty, slideOut);
_notificationBorder.BeginAnimation(UIElement.OpacityProperty, fadeOut);
});
});
});
}
#endregion
#region Optimization Event Handlers
private void PerformanceToggle_Changed(object sender, RoutedEventArgs e)
{
try
{
if (PerformanceToggle.IsChecked == true)
{
LogActivity("OPTIMIZE", "Applying performance tweaks...", LogLevel.Info);
OptimizationHelper.EnablePerformanceTweaks();
LogActivity("OPTIMIZE", "Performance tweaks enabled successfully", LogLevel.Success);
ShowToast("Performance tweaks enabled successfully!");
}
else
{
LogActivity("OPTIMIZE", "Performance tweaks disabled", LogLevel.Info);
ShowToast("Performance tweaks disabled");
}
SaveSettings();
}
catch (Exception ex)
{
LogActivity("ERROR", $"Failed to apply performance tweaks: {ex.Message}", LogLevel.Error);
ShowToast($"Failed to apply performance tweaks: {ex.Message}", true);
PerformanceToggle.IsChecked = !PerformanceToggle.IsChecked;
}
}
private void NetworkThrottlingToggle_Changed(object sender, RoutedEventArgs e)
{
try
{
if (NetworkThrottlingToggle.IsChecked == true)
{
LogActivity("NETWORK", "Disabling network throttling...", LogLevel.Info);
OptimizationHelper.DisableNetworkThrottling();
LogActivity("NETWORK", "Network throttling disabled - restart may be required", LogLevel.Success);
ShowToast("Network throttling disabled - restart required");
}
else
{
LogActivity("NETWORK", "Network throttling settings reverted", LogLevel.Info);
ShowToast("Network throttling re-enabled");
}
SaveSettings();
}
catch (Exception ex)
{
LogActivity("ERROR", $"Network throttling modification failed: {ex.Message}", LogLevel.Error);
ShowToast($"Failed to modify network throttling: {ex.Message}", true);
NetworkThrottlingToggle.IsChecked = !NetworkThrottlingToggle.IsChecked;
}
}
private void HibernationToggle_Changed(object sender, RoutedEventArgs e)
{
try
{
if (HibernationToggle.IsChecked == true)
{
LogActivity("POWER", "Disabling hibernation...", LogLevel.Info);
OptimizationHelper.DisableHibernation();
LogActivity("POWER", "Hibernation disabled - disk space freed", LogLevel.Success);
ShowToast("Hibernation disabled successfully!");
}
else
{
LogActivity("POWER", "Enabling hibernation...", LogLevel.Info);
OptimizationHelper.EnableHibernation();
LogActivity("POWER", "Hibernation enabled", LogLevel.Success);
ShowToast("Hibernation enabled successfully!");
}
SaveSettings();
}
catch (Exception ex)
{
LogActivity("ERROR", $"Hibernation modification failed: {ex.Message}", LogLevel.Error);
ShowToast($"Failed to modify hibernation: {ex.Message}", true);
HibernationToggle.IsChecked = !HibernationToggle.IsChecked;
}
}
private void WindowsTelemetryToggle_Changed(object sender, RoutedEventArgs e)