-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
1196 lines (1050 loc) · 60.5 KB
/
Copy pathMainWindow.xaml.cs
File metadata and controls
1196 lines (1050 loc) · 60.5 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
// This file is part of BOINC.
// https://boinc.berkeley.edu
// Copyright (C) 2026 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.ComponentModel; // for CancelEventArgs
namespace boinc_buda_runner_wsl_installer
{
public partial class MainWindow : Window
{
public ObservableCollection<TableRow> TableItems { get; set; }
private bool _isInstalling = false; // track if installation is in progress
private bool _isUninstalling = false; // track if uninstallation is in progress
internal bool LastWindowsFeaturesRestartRequired { get; private set; } // quiet-mode detail
public MainWindow()
{
InitializeComponent();
// Enable debug logging by default
DebugLogger.IsEnabled = true;
TableItems = new ObservableCollection<TableRow>
{
new TableRow { Id = ID.ApplicationUpdate, Icon = "", Status = "Check installer update", IsVisible=false },
new TableRow { Id = ID.BoincProcessCheck, Icon = "", Status = "Check BOINC process", IsVisible=false },
new TableRow { Id = ID.WindowsVersion, Icon = "", Status = "Check Windows version", IsVisible=false },
new TableRow { Id = ID.WindowsFeatures, Icon = "", Status = "Check Windows features", IsVisible=false },
new TableRow { Id = ID.WslCheck, Icon = "", Status = "Check WSL installation", IsVisible=false },
new TableRow { Id = ID.BudaRunnerCheck, Icon = "", Status = "Check BOINC WSL Distro installation", IsVisible=false }
};
DataContext = this;
DebugLogger.LogInfo("MainWindow initialized", "MainWindow");
DebugLogger.LogConfiguration("Initial table items count", TableItems.Count, "MainWindow");
}
private void ResetInstallationSteps()
{
DebugLogger.LogInfo("Resetting installation steps (hiding rows and restoring initial text)", "MainWindow");
foreach (var row in TableItems)
{
row.IsVisible = false;
row.Icon = string.Empty;
switch (row.Id)
{
case ID.ApplicationUpdate:
row.Status = "Check installer update"; break;
case ID.WindowsVersion:
row.Status = "Check Windows version"; break;
case ID.WindowsFeatures:
row.Status = "Check Windows features"; break;
case ID.WslCheck:
row.Status = "Check WSL installation"; break;
case ID.BoincProcessCheck:
row.Status = "Check BOINC process"; break;
case ID.BudaRunnerCheck:
row.Status = "Check BOINC WSL Distro installation"; break;
}
}
}
protected override void OnClosing(CancelEventArgs e)
{
DebugLogger.LogMethodStart("OnClosing", component: "MainWindow");
if (_isInstalling || _isUninstalling)
{
var operationType = _isInstalling ? "Installation" : "Uninstallation";
var result = MessageBox.Show(
$"{operationType} is currently in progress. Are you sure you want to exit?",
"Confirm Exit",
MessageBoxButton.YesNo,
MessageBoxImage.Warning);
DebugLogger.LogInfo($"{operationType} in progress exit confirmation dialog result: {result}", "MainWindow");
if (result != MessageBoxResult.Yes)
{
e.Cancel = true;
DebugLogger.LogMethodEnd("OnClosing", "cancelled by user during installation", "MainWindow");
return;
}
}
DebugLogger.LogInfo("Application closing", "MainWindow");
DebugLogger.Flush();
DebugLogger.LogMethodEnd("OnClosing", component: "MainWindow");
base.OnClosing(e);
}
internal bool CheckWindowsVersionCompatibility()
{
DebugLogger.LogMethodStart("CheckWindowsVersionCompatibility", component: "MainWindow");
// Check Windows version compatibility first
var windowsInfo = WindowsVersionCheck.GetWindowsVersionInfo();
DebugLogger.LogInfo($"Windows version check result: Status={windowsInfo.Status}, Message={windowsInfo.StatusMessage}", "MainWindow");
DebugLogger.LogConfiguration("Windows Major Version", windowsInfo.MajorVersion, "MainWindow");
DebugLogger.LogConfiguration("Windows Minor Version", windowsInfo.MinorVersion, "MainWindow");
DebugLogger.LogConfiguration("Windows Build Number", windowsInfo.BuildNumber, "MainWindow");
DebugLogger.LogConfiguration("Windows Architecture", windowsInfo.Architecture, "MainWindow");
// Add version check result to the table
var versionIcon = windowsInfo.Status == WindowsVersionCheck.WindowsVersionStatus.Supported ? "GreenCheckboxIcon" : "RedCancelIcon";
var windowsVersion = windowsInfo.StatusMessage;
ChangeRowIconAndStatus(ID.WindowsVersion, versionIcon, "Windows version: " + windowsVersion);
var isSupported = windowsInfo.Status == WindowsVersionCheck.WindowsVersionStatus.Supported;
if (!isSupported && !App.IsQuiet)
{
MessageBox.Show(
"Your Windows version is not supported for this installation.",
"Unsupported Version",
MessageBoxButton.OK,
MessageBoxImage.Error);
}
DebugLogger.LogMethodEnd("CheckWindowsVersionCompatibility", isSupported.ToString(), "MainWindow");
return isSupported;
}
internal async Task<bool> CheckWindowsFeatures()
{
DebugLogger.LogMethodStart("CheckWindowsFeatures", component: "MainWindow");
LastWindowsFeaturesRestartRequired = false;
// Update UI to show we're checking features
ChangeRowIconAndStatus(ID.WindowsFeatures, "BlueInfoIcon", "Checking Windows features...");
// Allow UI to update
await Task.Delay(100);
try
{
// Check all required features
var checkResult = await WindowsFeaturesCheck.CheckRequiredFeaturesAsync();
DebugLogger.LogInfo($"Windows features check completed. All enabled: {checkResult.AllFeaturesEnabled}", "MainWindow");
foreach (var feature in checkResult.FeatureResults)
{
DebugLogger.LogConfiguration($"Feature {feature.FeatureName}", $"Status: {feature.Status}, Message: {feature.Message}", "MainWindow");
}
if (!checkResult.AllFeaturesEnabled)
{
DebugLogger.LogInfo("Some Windows features are disabled, attempting to enable them", "MainWindow");
// Update UI to show we're enabling features
ChangeRowIconAndStatus(ID.WindowsFeatures, "YellowExclamationIcon", "Enabling missing Windows features...");
// Allow UI to update
await Task.Delay(100);
// Enable missing features
var enableResult = await WindowsFeaturesCheck.EnableRequiredFeaturesAsync();
DebugLogger.LogInfo($"Windows features enable completed. Success: {enableResult.AllFeaturesEnabled}", "MainWindow");
// Check if restart is required
if (WindowsFeaturesCheck.IsRestartRequired(enableResult.FeatureResults))
{
LastWindowsFeaturesRestartRequired = true;
DebugLogger.LogWarning("Restart required after enabling Windows features", "MainWindow");
ChangeRowIconAndStatus(ID.WindowsFeatures, "YellowExclamationIcon", "Features enabled - restart required");
if (!App.IsQuiet)
{
MessageBox.Show(
"Windows features have been enabled but require a restart.\n\nPlease restart your computer and run this installation again.",
"Computer restart is required",
MessageBoxButton.OK,
MessageBoxImage.Warning);
}
DebugLogger.LogMethodEnd("CheckWindowsFeatures", "false (restart required)", "MainWindow");
return false;
}
// Features were enabled successfully
if (enableResult.AllFeaturesEnabled)
{
ChangeRowIconAndStatus(ID.WindowsFeatures, "GreenCheckboxIcon", "Windows features enabled successfully");
DebugLogger.LogMethodEnd("CheckWindowsFeatures", "true (features enabled)", "MainWindow");
return true;
}
else
{
// Some features failed to enable
ChangeRowIconAndStatus(ID.WindowsFeatures, "RedCancelIcon", "Failed to enable some Windows features");
DebugLogger.LogError("Failed to enable some required Windows features", "MainWindow");
var failedFeatures = string.Join(", ", enableResult.FeatureResults
.Where(f => f.Status != WindowsFeaturesCheck.WindowsFeatureStatus.Enabled)
.Select(f => f.FeatureName));
PromptOpenIssue("Windows features enable failed",
$"Failed to enable required Windows features: {failedFeatures}. " +
$"Error details: {string.Join("; ", enableResult.FeatureResults.Select(f => f.Message))}");
DebugLogger.LogMethodEnd("CheckWindowsFeatures", "false (enable failed)", "MainWindow");
return false;
}
}
// All features were already enabled
ChangeRowIconAndStatus(ID.WindowsFeatures, "GreenCheckboxIcon", "All Windows features are already enabled");
DebugLogger.LogMethodEnd("CheckWindowsFeatures", "true (all features already enabled)", "MainWindow");
return true;
}
catch (Exception ex)
{
DebugLogger.LogException(ex, "Error occurred while checking Windows features", "MainWindow");
ChangeRowIconAndStatus(ID.WindowsFeatures, "RedCancelIcon", "Error checking Windows features");
PromptOpenIssue("Windows features check exception", ex.ToString());
DebugLogger.LogMethodEnd("CheckWindowsFeatures", "false (exception)", "MainWindow");
return false;
}
}
internal async Task<bool> CheckWsl()
{
DebugLogger.LogMethodStart("CheckWsl", component: "MainWindow");
// Update UI to show we're checking WSL
ChangeRowIconAndStatus(ID.WslCheck, "BlueInfoIcon", "Checking WSL installation and configuration...");
// Allow UI to update
await Task.Delay(100);
try
{
// Perform comprehensive WSL check
var wslResult = await WslCheck.CheckWslAsync();
DebugLogger.LogInfo($"WSL check completed. Status: {wslResult.Status}, Message: {wslResult.Message}", "MainWindow");
switch (wslResult.Status)
{
case WslCheck.WslStatus.AllGood:
ChangeRowIconAndStatus(ID.WslCheck, "GreenCheckboxIcon", WslCheck.GetStatusDisplayMessage(wslResult));
DebugLogger.LogMethodEnd("CheckWsl", "true (WSL all good)", "MainWindow");
return true;
case WslCheck.WslStatus.NotInstalled:
DebugLogger.LogWarning("WSL is not installed, attempting installation", "MainWindow");
ChangeRowIconAndStatus(ID.WslCheck, "YellowExclamationIcon", "WSL is not installed on this system");
var installResult = await InstallWsl();
DebugLogger.LogMethodEnd("CheckWsl", $"{installResult} (WSL install attempted)", "MainWindow");
return installResult;
case WslCheck.WslStatus.OutdatedVersion:
case WslCheck.WslStatus.WrongDefaultVersion:
DebugLogger.LogWarning($"WSL needs fixing: {wslResult.Status}", "MainWindow");
ChangeRowIconAndStatus(ID.WslCheck, "YellowExclamationIcon", WslCheck.GetStatusDisplayMessage(wslResult));
var fixResult = await FixWslIssues(wslResult);
DebugLogger.LogMethodEnd("CheckWsl", $"{fixResult} (WSL fix attempted)", "MainWindow");
return fixResult;
case WslCheck.WslStatus.Error:
default:
DebugLogger.LogError($"WSL check failed with status: {wslResult.Status}", "MainWindow");
ChangeRowIconAndStatus(ID.WslCheck, "RedCancelIcon", WslCheck.GetStatusDisplayMessage(wslResult));
DebugLogger.LogMethodEnd("CheckWsl", "false (WSL error)", "MainWindow");
PromptOpenIssue("WSL check error",
$"WSL Status: {wslResult.Status}\n" +
$"Message: {wslResult.Message}\n" +
$"Version Info: {wslResult.VersionInfo?.WslVersion ?? "N/A"}\n" +
$"Default Version: {wslResult.StatusInfo?.DefaultVersion.ToString() ?? "N/A"}");
return false;
}
}
catch (System.Exception ex)
{
DebugLogger.LogException(ex, "Error occurred while checking WSL", "MainWindow");
ChangeRowIconAndStatus(ID.WslCheck, "RedCancelIcon", "Error occurred while checking WSL");
DebugLogger.LogMethodEnd("CheckWsl", "false (exception)", "MainWindow");
PromptOpenIssue("WSL check exception",
$"Exception Type: {ex.GetType().Name}\n" +
$"Message: {ex.Message}\n" +
$"Stack Trace:\n{ex.StackTrace}");
return false;
}
}
internal async Task<bool> CheckBoincProcess()
{
DebugLogger.LogMethodStart("CheckBoincProcess", component: "MainWindow");
// Update UI to show we're checking BOINC process
ChangeRowIconAndStatus(ID.BoincProcessCheck, "BlueInfoIcon", "Checking BOINC process...");
// Allow UI to update
await Task.Delay(100);
try
{
// Perform BOINC process check
var boincResult = await BoincProcessCheck.CheckBoincProcessAsync();
DebugLogger.LogInfo($"BOINC process check completed. Status: {boincResult.Status}, Process Count: {boincResult.ProcessCount}", "MainWindow");
switch (boincResult.Status)
{
case BoincProcessCheck.BoincProcessStatus.Running:
DebugLogger.LogWarning($"BOINC process is running: {boincResult.Message}", "MainWindow");
ChangeRowIconAndStatus(ID.BoincProcessCheck, "RedCancelIcon", boincResult.Message);
if (!App.IsQuiet)
{
// Show instruction to stop BOINC (do NOT offer to create an issue here)
MessageBox.Show(
$"BOINC client is currently running and may interfere with the installation.\n\nPlease stop the running BOINC client and retry the installation.",
$"{boincResult.Message}",
MessageBoxButton.OK,
MessageBoxImage.Warning);
}
DebugLogger.LogMethodEnd("CheckBoincProcess", "false (BOINC running)", "MainWindow");
return false;
case BoincProcessCheck.BoincProcessStatus.NotRunning:
DebugLogger.LogInfo("BOINC process is not running, ready for installation", "MainWindow");
ChangeRowIconAndStatus(ID.BoincProcessCheck, "GreenCheckboxIcon", "BOINC is not running - ready for installation");
DebugLogger.LogMethodEnd("CheckBoincProcess", "true (BOINC not running)", "MainWindow");
return true;
case BoincProcessCheck.BoincProcessStatus.Error:
default:
DebugLogger.LogWarning($"Unable to check BOINC status: {boincResult.ErrorMessage}", "MainWindow");
ChangeRowIconAndStatus(ID.BoincProcessCheck, "YellowExclamationIcon", $"Unable to check BOINC status: {boincResult.ErrorMessage}");
DebugLogger.LogMethodEnd("CheckBoincProcess", "true (error, continue anyway)", "MainWindow");
// Continue but offer to report if user wants
PromptOpenIssue("BOINC process check error", boincResult.ErrorMessage);
return true; // Continue despite error
}
}
catch (System.Exception ex)
{
DebugLogger.LogException(ex, "Error occurred while checking BOINC process", "MainWindow");
ChangeRowIconAndStatus(ID.BoincProcessCheck, "YellowExclamationIcon", "Error occurred while checking BOINC process");
DebugLogger.LogMethodEnd("CheckBoincProcess", "true (exception, continue anyway)", "MainWindow");
// Offer to report issue
PromptOpenIssue("BOINC process check exception", ex.ToString());
return true; // Continue despite error
}
}
internal async Task<bool> CheckBudaRunner()
{
DebugLogger.LogMethodStart("CheckBudaRunner", component: "MainWindow");
// Update UI to show we're checking BUDA Runner
ChangeRowIconAndStatus(ID.BudaRunnerCheck, "BlueInfoIcon", "Checking BOINC WSL Distro installation...");
// Allow UI to update
await Task.Delay(100);
try
{
// Perform comprehensive BUDA Runner check
var budaResult = await BudaRunnerCheck.CheckBudaRunnerAsync();
DebugLogger.LogInfo($"BUDA Runner check completed. Status: {budaResult.Status}", "MainWindow");
DebugLogger.LogConfiguration("BUDA Runner Installed", budaResult.VersionInfo.IsInstalled, "MainWindow");
DebugLogger.LogConfiguration("BUDA Runner Current Version", budaResult.VersionInfo.CurrentVersion ?? "N/A", "MainWindow");
DebugLogger.LogConfiguration("BUDA Runner Latest Version", budaResult.VersionInfo.LatestVersion ?? "N/A", "MainWindow");
DebugLogger.LogConfiguration("BUDA Runner Update Required", budaResult.UpdateRequired, "MainWindow");
switch (budaResult.Status)
{
case BudaRunnerCheck.BudaRunnerStatus.InstalledUpToDate:
DebugLogger.LogInfo("BUDA Runner is installed and up to date", "MainWindow");
ChangeRowIconAndStatus(ID.BudaRunnerCheck, "GreenCheckboxIcon", BudaRunnerCheck.GetStatusDisplayMessage(budaResult));
DebugLogger.LogMethodEnd("CheckBudaRunner", "true (up to date)", "MainWindow");
return true;
case BudaRunnerCheck.BudaRunnerStatus.NotInstalled:
DebugLogger.LogInfo("BUDA Runner is not installed, attempting installation", "MainWindow");
ChangeRowIconAndStatus(ID.BudaRunnerCheck, "YellowExclamationIcon", "BOINC WSL Distro is not installed");
var installResult = await InstallBudaRunner(budaResult);
DebugLogger.LogMethodEnd("CheckBudaRunner", $"{installResult} (install attempted)", "MainWindow");
return installResult;
case BudaRunnerCheck.BudaRunnerStatus.InstalledOutdated:
case BudaRunnerCheck.BudaRunnerStatus.InstalledNoVersion:
DebugLogger.LogInfo($"BUDA Runner needs update/reinstall: {budaResult.Status}", "MainWindow");
ChangeRowIconAndStatus(ID.BudaRunnerCheck, "YellowExclamationIcon", BudaRunnerCheck.GetStatusDisplayMessage(budaResult));
var updateResult = await InstallBudaRunner(budaResult);
DebugLogger.LogMethodEnd("CheckBudaRunner", $"{updateResult} (update attempted)", "MainWindow");
return updateResult;
case BudaRunnerCheck.BudaRunnerStatus.Error:
default:
DebugLogger.LogError($"BUDA Runner check failed: {budaResult.ErrorMessage}", "MainWindow");
ChangeRowIconAndStatus(ID.BudaRunnerCheck, "YellowExclamationIcon", BudaRunnerCheck.GetStatusDisplayMessage(budaResult));
DebugLogger.LogMethodEnd("CheckBudaRunner", "true (error, continue anyway)", "MainWindow");
// Offer to report issue
PromptOpenIssue("BUDA Runner check error",
$"Status: {budaResult.Status}\n" +
$"Error Message: {budaResult.ErrorMessage ?? "N/A"}\n" +
$"Is Installed: {budaResult.VersionInfo.IsInstalled}\n" +
$"Current Version: {budaResult.VersionInfo.CurrentVersion ?? "N/A"}\n" +
$"Latest Version: {budaResult.VersionInfo.LatestVersion ?? "N/A"}\n" +
$"Has Version File: {budaResult.VersionInfo.HasVersionFile}");
return true; // Continue despite error
}
}
catch (System.Exception ex)
{
DebugLogger.LogException(ex, "Error occurred while checking BUDA Runner", "MainWindow");
ChangeRowIconAndStatus(ID.BudaRunnerCheck, "YellowExclamationIcon", "Error occurred while checking BOINC WSL Distro");
DebugLogger.LogMethodEnd("CheckBudaRunner", "true (exception, continue anyway)", "MainWindow");
// Offer to report issue
PromptOpenIssue("BUDA Runner check exception",
$"Exception Type: {ex.GetType().Name}\n" +
$"Message: {ex.Message}\n" +
$"Stack Trace:\n{ex.StackTrace}");
return true; // Continue despite error
}
}
private async Task<bool> InstallBudaRunner(BudaRunnerCheck.BudaRunnerCheckResult budaResult)
{
DebugLogger.LogMethodStart("InstallBudaRunner", $"Status: {budaResult.Status}", "MainWindow");
try
{
// Create a progress reporter for UI updates
var progress = new System.Progress<string>(message =>
{
DebugLogger.LogInfo($"BUDA Runner install progress: {message}", "MainWindow");
ChangeRowIconAndStatus(ID.BudaRunnerCheck, "BlueInfoIcon", message);
});
// Install or update BUDA Runner
bool success = await BudaRunnerCheck.InstallOrUpdateBudaRunnerAsync(budaResult, progress);
if (success)
{
DebugLogger.LogInfo("BUDA Runner installation completed successfully", "MainWindow");
ChangeRowIconAndStatus(ID.BudaRunnerCheck, "GreenCheckboxIcon", "BOINC WSL Distro installed and configured successfully");
DebugLogger.LogMethodEnd("InstallBudaRunner", "true", "MainWindow");
return true;
}
else
{
DebugLogger.LogError("BUDA Runner installation failed", "MainWindow");
ChangeRowIconAndStatus(ID.BudaRunnerCheck, "RedCancelIcon", "Failed to install BOINC WSL Distro");
DebugLogger.LogMethodEnd("InstallBudaRunner", "false", "MainWindow");
// Offer to report issue with detailed context
PromptOpenIssue("BOINC WSL Distro installation failed",
$"Installation Status: Failed\n" +
$"Was Previously Installed: {budaResult.VersionInfo.IsInstalled}\n" +
$"Current Version: {budaResult.VersionInfo.CurrentVersion ?? "N/A"}\n" +
$"Target Version: {budaResult.VersionInfo.LatestVersion ?? "N/A"}\n" +
$"Download URL: {budaResult.DownloadUrl ?? "N/A"}\n" +
$"Update Required: {budaResult.UpdateRequired}\n" +
$"Check the log file for detailed error information.");
return false;
}
}
catch (System.Exception ex)
{
DebugLogger.LogException(ex, "BUDA Runner installation failed", "MainWindow");
ChangeRowIconAndStatus(ID.BudaRunnerCheck, "RedCancelIcon", $"BOINC WSL Distro installation failed: {ex.Message}");
DebugLogger.LogMethodEnd("InstallBudaRunner", "false (exception)", "MainWindow");
// Offer to report issue
PromptOpenIssue("BOINC WSL Distro installation exception",
$"Exception Type: {ex.GetType().Name}\n" +
$"Message: {ex.Message}\n" +
$"Was Previously Installed: {budaResult.VersionInfo.IsInstalled}\n" +
$"Target Version: {budaResult.VersionInfo.LatestVersion ?? "N/A"}\n" +
$"Stack Trace:\n{ex.StackTrace}");
return false;
}
}
private async Task<bool> InstallWsl()
{
DebugLogger.LogMethodStart("InstallWsl", component: "MainWindow");
ChangeRowIconAndStatus(ID.WslCheck, "BlueInfoIcon", "Installing WSL...");
try
{
// Create a progress reporter for UI updates
var progress = new System.Progress<string>(message =>
{
DebugLogger.LogInfo($"WSL install progress: {message}", "MainWindow");
ChangeRowIconAndStatus(ID.WslCheck, "BlueInfoIcon", message);
});
// Get the latest WSL download URL
var downloadInfo = await WslCheck.GetLatestWslDownloadInfoAsync();
var downloadUrl = downloadInfo?.DownloadUrl;
var downloadSha256 = downloadInfo?.Sha256;
DebugLogger.LogConfiguration("WSL Download URL", downloadUrl ?? "null", "MainWindow");
DebugLogger.LogConfiguration("WSL Download SHA256", downloadSha256 ?? "null", "MainWindow");
// Download and install WSL
bool success = await WslCheck.DownloadAndInstallLatestWslAsync(downloadUrl, downloadSha256, progress);
if (success)
{
DebugLogger.LogInfo("WSL installation completed successfully", "MainWindow");
ChangeRowIconAndStatus(ID.WslCheck, "GreenCheckboxIcon", "WSL installed successfully");
// Set default version to 2
DebugLogger.LogInfo("Setting WSL default version to 2", "MainWindow");
await Task.Delay(2000); // Give WSL time to initialize
await WslCheck.SetDefaultWslVersionTo2Async();
DebugLogger.LogMethodEnd("InstallWsl", "true", "MainWindow");
return true;
}
else
{
DebugLogger.LogError("WSL installation failed", "MainWindow");
ChangeRowIconAndStatus(ID.WslCheck, "RedCancelIcon", "Failed to install WSL");
DebugLogger.LogMethodEnd("InstallWsl", "false", "MainWindow");
// Offer to report issue
PromptOpenIssue("WSL installation failed",
$"Download URL: {downloadUrl}\n" +
$"Installation failed with no specific error. Check the log file for more details.");
return false;
}
}
catch (System.Exception ex)
{
DebugLogger.LogException(ex, "WSL installation failed", "MainWindow");
ChangeRowIconAndStatus(ID.WslCheck, "RedCancelIcon", "WSL installation failed");
DebugLogger.LogMethodEnd("InstallWsl", "false (exception)", "MainWindow");
// Offer to report issue
PromptOpenIssue("WSL installation exception",
$"Exception Type: {ex.GetType().Name}\n" +
$"Message: {ex.Message}\n" +
$"Stack Trace:\n{ex.StackTrace}");
return false;
}
}
private async Task<bool> FixWslIssues(WslCheck.WslCheckResult wslResult)
{
DebugLogger.LogMethodStart("FixWslIssues", $"Status: {wslResult.Status}", "MainWindow");
try
{
// Create a progress reporter for UI updates
var progress = new System.Progress<string>(message =>
{
DebugLogger.LogInfo($"WSL fix progress: {message}", "MainWindow");
ChangeRowIconAndStatus(ID.WslCheck, "BlueInfoIcon", message);
});
// Fix WSL issues automatically
bool success = await WslCheck.FixWslIssuesAsync(wslResult, progress);
if (success)
{
DebugLogger.LogInfo("WSL configuration updated successfully", "MainWindow");
ChangeRowIconAndStatus(ID.WslCheck, "GreenCheckboxIcon", "WSL configuration updated successfully");
DebugLogger.LogMethodEnd("FixWslIssues", "true", "MainWindow");
return true;
}
else
{
DebugLogger.LogWarning("Some WSL issues could not be fixed automatically", "MainWindow");
ChangeRowIconAndStatus(ID.WslCheck, "YellowExclamationIcon", "Some WSL issues could not be fixed automatically");
DebugLogger.LogMethodEnd("FixWslIssues", "false", "MainWindow");
// Offer to report issue
PromptOpenIssue("WSL fix issues could not be resolved",
$"WSL Status: {wslResult.Status}\n" +
$"Current Version: {wslResult.VersionInfo?.WslVersion ?? "N/A"}\n" +
$"Latest Version: {wslResult.LatestVersion ?? "N/A"}\n" +
$"Default Version: {wslResult.StatusInfo?.DefaultVersion.ToString() ?? "N/A"}\n" +
$"Update Required: {wslResult.UpdateRequired}\n" +
$"Version Change Required: {wslResult.VersionChangeRequired}\n" +
$"Message: {wslResult.Message}");
return false;
}
}
catch (System.Exception ex)
{
DebugLogger.LogException(ex, "Failed to fix WSL configuration", "MainWindow");
ChangeRowIconAndStatus(ID.WslCheck, "RedCancelIcon", "Failed to fix WSL configuration");
DebugLogger.LogMethodEnd("FixWslIssues", "false (exception)", "MainWindow");
// Offer to report issue
PromptOpenIssue("WSL fix exception",
$"Exception Type: {ex.GetType().Name}\n" +
$"Message: {ex.Message}\n" +
$"WSL Status: {wslResult.Status}\n" +
$"Stack Trace:\n{ex.StackTrace}");
return false;
}
}
// Button Event Handlers
private async void InstallButton_Click(object sender, RoutedEventArgs e)
{
DebugLogger.LogSeparator("Installation Process Started");
DebugLogger.LogMethodStart("InstallButton_Click", component: "MainWindow");
if (IntroTextBlock != null && IntroTextBlock.Visibility == Visibility.Visible)
{
IntroTextBlock.Visibility = Visibility.Collapsed; // hide intro once installation begins
}
var installButton = sender as Button;
if (installButton != null)
{
// If this is a retry (button content may be 'Retry') we hide existing steps
if (installButton.Content != null && installButton.Content.ToString().Equals("Retry", StringComparison.OrdinalIgnoreCase))
{
ResetInstallationSteps();
if (IntroTextBlock != null) IntroTextBlock.Visibility = Visibility.Collapsed; // ensure hidden on retry
}
installButton.IsEnabled = false;
DebugLogger.LogInfo("Install button disabled during execution", "MainWindow");
}
// Disable Uninstall button during installation
if (UninstallButton != null)
{
UninstallButton.IsEnabled = false;
DebugLogger.LogInfo("Uninstall button disabled during installation", "MainWindow");
}
bool success = false; // track overall result
_isInstalling = true; // mark installation started
try
{
try
{
ChangeRowIconAndStatus(ID.ApplicationUpdate, "BlueInfoIcon", "Checking for installer updates...");
await Task.Delay(50);
await CheckApplicationUpdateAsync();
}
catch (Exception ex)
{
ChangeRowIconAndStatus(ID.ApplicationUpdate, "YellowExclamationIcon", "Could not check for installer updates");
DebugLogger.LogException(ex, "Self-update check failed (continuing without update)", "MainWindow");
}
ChangeRowIconAndStatus(ID.WindowsVersion, "BlueInfoIcon", "Checking Windows version...");
await Task.Delay(100);
var res = CheckWindowsVersionCompatibility();
if (!res)
{
DebugLogger.LogError("Windows version is not supported", "MainWindow");
if (!App.IsQuiet)
{
MessageBox.Show(
"Your Windows version is not supported for this installation.",
"Unsupported Version",
MessageBoxButton.OK,
MessageBoxImage.Error);
}
return; // failure
}
res = await CheckBoincProcess();
if (!res)
{
DebugLogger.LogError("BOINC process check failed", "MainWindow");
return; // failure
}
res = await CheckWindowsFeatures();
if (!res)
{
DebugLogger.LogError("Windows features check/installation failed", "MainWindow");
return; // failure
}
res = await CheckWsl();
if (!res)
{
DebugLogger.LogError("WSL check/installation failed", "MainWindow");
return; // failure
}
res = await CheckBudaRunner();
if (!res)
{
DebugLogger.LogError("BOINC WSL Distro check/installation failed", "MainWindow");
return; // failure
}
await Task.Delay(100);
DebugLogger.LogInfo("Installation completed successfully", "MainWindow");
if (!App.IsQuiet)
{
MessageBox.Show(
"BOINC WSL Distro installation completed successfully!\n\nAll system requirements are met and BOINC WSL Distro is installed and ready to use.",
"Installation Complete",
MessageBoxButton.OK,
MessageBoxImage.Information);
}
success = true; // mark success
}
catch (System.Exception ex)
{
DebugLogger.LogException(ex, "Unexpected error during installation", "MainWindow");
}
finally
{
_isInstalling = false; // installation ended
if (installButton != null)
{
if (!success)
{
installButton.IsEnabled = true;
installButton.Content = "Retry"; // allow retry on failure
DebugLogger.LogInfo("Install button re-enabled for retry", "MainWindow");
}
else
{
installButton.IsEnabled = false; // keep disabled on success
DebugLogger.LogInfo("Install succeeded; button remains disabled", "MainWindow");
}
}
// Re-enable Uninstall button after installation
if (UninstallButton != null)
{
UninstallButton.IsEnabled = true;
DebugLogger.LogInfo("Uninstall button re-enabled after installation", "MainWindow");
}
DebugLogger.LogSeparator("Installation Process Completed");
}
DebugLogger.LogMethodEnd("InstallButton_Click", component: "MainWindow");
}
private void ExitButton_Click(object sender, RoutedEventArgs e)
{
DebugLogger.LogMethodStart("ExitButton_Click", component: "MainWindow");
// Delegate to window close to reuse confirmation logic
this.Close();
DebugLogger.LogMethodEnd("ExitButton_Click", component: "MainWindow");
}
private async void UninstallButton_Click(object sender, RoutedEventArgs e)
{
DebugLogger.LogSeparator("Uninstallation Process Started");
DebugLogger.LogMethodStart("UninstallButton_Click", component: "MainWindow");
if (IntroTextBlock != null && IntroTextBlock.Visibility == Visibility.Visible)
{
IntroTextBlock.Visibility = Visibility.Collapsed;
}
var uninstallButton = sender as Button;
if (uninstallButton != null)
{
uninstallButton.IsEnabled = false;
DebugLogger.LogInfo("Uninstall button disabled during execution", "MainWindow");
}
// Disable Install button during uninstallation
if (InstallButton != null)
{
InstallButton.IsEnabled = false;
DebugLogger.LogInfo("Install button disabled during uninstallation", "MainWindow");
}
_isUninstalling = true;
try
{
// Step 1: Check for running BOINC process
ChangeRowIconAndStatus(ID.BoincProcessCheck, "BlueInfoIcon", "Checking BOINC process...");
await Task.Delay(100);
var boincCheckResult = await BoincProcessCheck.CheckBoincProcessAsync();
if (boincCheckResult.Status == BoincProcessCheck.BoincProcessStatus.Running)
{
DebugLogger.LogWarning("BOINC process is running, cannot proceed with uninstallation", "MainWindow");
ChangeRowIconAndStatus(ID.BoincProcessCheck, "RedCancelIcon", $"{boincCheckResult.Message}");
MessageBox.Show(
"BOINC is currently running. Please close BOINC before uninstalling the BOINC WSL Distro.\n\n" +
"To close BOINC:\n" +
"1. Right-click the BOINC icon in the system tray\n" +
"2. Select 'Exit BOINC'\n" +
"3. Run this uninstaller again",
"BOINC is Running",
MessageBoxButton.OK,
MessageBoxImage.Warning);
return;
}
ChangeRowIconAndStatus(ID.BoincProcessCheck, "GreenCheckboxIcon", "BOINC is not running");
DebugLogger.LogInfo("BOINC process check passed, not running", "MainWindow");
// Step 2: Confirm with user
var confirmResult = MessageBox.Show(
"Are you sure you want to uninstall BOINC WSL Distro?\n\n" +
"⚠️ WARNING:\n" +
"• This will remove the BOINC WSL Distro from your system\n" +
"• Any Docker-based BOINC tasks will fail after removal\n" +
"• WSL itself will NOT be removed\n\n" +
"To remove WSL completely, please refer to next documentation:\n" +
"https://gist.github.com/4wk-/889b26043f519259ab60386ca13ba91b\n\n" +
"Do you want to continue with uninstallation?",
"Confirm Uninstallation",
MessageBoxButton.YesNo,
MessageBoxImage.Warning);
DebugLogger.LogInfo($"User confirmation result: {confirmResult}", "MainWindow");
if (confirmResult != MessageBoxResult.Yes)
{
DebugLogger.LogInfo("User cancelled uninstallation", "MainWindow");
ChangeRowIconAndStatus(ID.BudaRunnerCheck, "GreyMinusIcon", "Uninstallation cancelled");
return;
}
// Step 3: Check if BOINC WSL Distro is installed
ChangeRowIconAndStatus(ID.BudaRunnerCheck, "BlueInfoIcon", "Checking BOINC WSL Distro installation...");
await Task.Delay(100);
bool isInstalled = await BudaRunnerCheck.IsWslImageInstalledAsync(BudaRunnerCheck.BUDA_RUNNER_IMAGE_NAME);
if (!isInstalled)
{
DebugLogger.LogInfo("BOINC WSL Distro is not installed", "MainWindow");
ChangeRowIconAndStatus(ID.BudaRunnerCheck, "GreyMinusIcon", "BOINC WSL Distro is not installed");
MessageBox.Show(
"BOINC WSL Distro is not installed on this system.",
"Not Installed",
MessageBoxButton.OK,
MessageBoxImage.Information);
return;
}
ChangeRowIconAndStatus(ID.BudaRunnerCheck, "GreenCheckboxIcon", "BOINC WSL Distro found");
DebugLogger.LogInfo("BOINC WSL Distro is installed, proceeding with removal", "MainWindow");
// Step 4: Remove BOINC WSL Distro
ChangeRowIconAndStatus(ID.BudaRunnerCheck, "BlueInfoIcon", "Removing BOINC WSL Distro...");
await Task.Delay(100);
bool removed = await BudaRunnerCheck.RemoveWslImageAsync(BudaRunnerCheck.BUDA_RUNNER_IMAGE_NAME);
if (!removed)
{
DebugLogger.LogError("Failed to remove BOINC WSL Distro", "MainWindow");
ChangeRowIconAndStatus(ID.BudaRunnerCheck, "RedCancelIcon", "Failed to remove BOINC WSL Distro");
MessageBox.Show(
"Failed to remove BOINC WSL Distro.\n\nPlease check the log file for details.",
"Uninstallation Failed",
MessageBoxButton.OK,
MessageBoxImage.Error);
return;
}
ChangeRowIconAndStatus(ID.BudaRunnerCheck, "GreenCheckboxIcon", "BOINC WSL Distro removed successfully");
DebugLogger.LogInfo("BOINC WSL Distro removed successfully", "MainWindow");
await Task.Delay(100);
MessageBox.Show(
"BOINC WSL Distro has been successfully removed from your system.\n\n" +
"Note: WSL itself remains installed. To remove WSL completely, please refer to:\n" +
"https://gist.github.com/4wk-/889b26043f519259ab60386ca13ba91b",
"Uninstallation Complete",
MessageBoxButton.OK,
MessageBoxImage.Information);
}
catch (Exception ex)
{
DebugLogger.LogException(ex, "Unexpected error during uninstallation", "MainWindow");
MessageBox.Show(
$"An unexpected error occurred during uninstallation:\n\n{ex.Message}\n\nPlease check the log file for details.",
"Uninstallation Error",
MessageBoxButton.OK,
MessageBoxImage.Error);
}
finally
{
_isUninstalling = false;
if (uninstallButton != null)
{
uninstallButton.IsEnabled = true;
DebugLogger.LogInfo("Uninstall button re-enabled", "MainWindow");
}
// Re-enable Install button after uninstallation
if (InstallButton != null)
{
InstallButton.IsEnabled = true;
DebugLogger.LogInfo("Install button re-enabled after uninstallation", "MainWindow");
}
DebugLogger.LogSeparator("Uninstallation Process Completed");
}
DebugLogger.LogMethodEnd("UninstallButton_Click", component: "MainWindow");
}
internal void ChangeRowIconAndStatus(ID id, string newIcon, string status)
{
var row = TableItems.FirstOrDefault(item => item.Id == id);
if (row != null)
{
if (!row.IsVisible) row.IsVisible = true; // reveal step when first updated
row.Icon = newIcon;
row.Status = status;
DebugLogger.LogUIStatusChange(id.ToString(), newIcon, status);
}
else
{
DebugLogger.LogWarning($"Could not find table row with ID: {id}", "MainWindow");
}
}
private void PromptOpenIssue(string title, string details)
{
try
{
// Categorize the error to provide appropriate troubleshooting guidance
var errorCategory = TroubleshootingGuide.CategorizeError(title, details);
var advice = TroubleshootingGuide.GetAdvice(errorCategory, details);
if (!App.IsQuiet)
{
// Show troubleshooting dialog instead of simple message box
var dialog = new TroubleshootingDialog(advice, details)
{
Owner = this
};
dialog.ShowDialog();
}
else
{
// In quiet mode, log the troubleshooting information
var formattedAdvice = TroubleshootingGuide.FormatAdviceAsMessage(advice);
DebugLogger.LogInfo($"Troubleshooting guidance for '{title}':\n{formattedAdvice}", "MainWindow");
// Build a GitHub new issue URL with prefilled title/body for logging purposes
var repoNewIssueUrl = "https://github.com/BOINC/boinc-buda-runner-wsl-installer/issues/new";
var sb = new StringBuilder();
sb.AppendLine("Describe the problem and steps to reproduce here.\n");
sb.AppendLine("Error context:");
sb.AppendLine(details ?? "(no details)");
sb.AppendLine();
sb.AppendLine($"App version: {FileVersionInfo.GetVersionInfo(Process.GetCurrentProcess().MainModule.FileName).FileVersion}");
sb.AppendLine($"OS: {Environment.OSVersion}");
sb.AppendLine($"64-bit OS: {Environment.Is64BitOperatingSystem}, 64-bit Process: {Environment.Is64BitProcess}");
sb.AppendLine();
if (!string.IsNullOrEmpty(DebugLogger.LogFilePath))
{
sb.AppendLine($"Log file path (attach this file in the issue): {DebugLogger.LogFilePath}");
}
var url = repoNewIssueUrl + "?title=" + Uri.EscapeDataString(title ?? "Installer error")
+ "&body=" + Uri.EscapeDataString(sb.ToString());
DebugLogger.LogInfo($"Issue report URL (quiet mode): {url}", "MainWindow");
}
}
catch (Exception ex)
{
DebugLogger.LogException(ex, "Failed to show troubleshooting guidance", "MainWindow");
// Fallback to old behavior if troubleshooting dialog fails
if (!App.IsQuiet)
{
var ask = MessageBox.Show(
"An error occurred. Would you like to report it on GitHub? Your debug log file path will be included in the report so you can attach it.",
"Report Error",
MessageBoxButton.YesNo,
MessageBoxImage.Question);
if (ask == MessageBoxResult.Yes)