Skip to content

Commit 90d5284

Browse files
authored
Merge pull request #7 from BOINC/vko_improve_debug_log
Add possibility to report errors dirctly to GitHub
2 parents 6d06418 + a09508f commit 90d5284

3 files changed

Lines changed: 87 additions & 42 deletions

File tree

DebugLogger.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ namespace boinc_buda_runner_wsl_installer
2727
internal static class DebugLogger
2828
{
2929
private static string _logFilePath;
30-
private static bool _isEnabled = false;
30+
private static bool _isEnabled = true; // Always enabled
3131
private static readonly object _lockObject = new object();
32+
private static bool _initialized = false;
3233

3334
/// <summary>
3435
/// Gets or sets whether debug logging is enabled
@@ -43,10 +44,6 @@ public static bool IsEnabled
4344
{
4445
InitializeLogFile();
4546
}
46-
else if (!_isEnabled && !string.IsNullOrEmpty(_logFilePath))
47-
{
48-
LogInfo("Debug logging disabled by user", "DebugLogger");
49-
}
5047
}
5148
}
5249

@@ -56,16 +53,19 @@ public static bool IsEnabled
5653
public static string LogFilePath => _logFilePath;
5754

5855
/// <summary>
59-
/// Initializes the log file with a timestamped filename
56+
/// Initializes the log file with a timestamped filename in the temp directory
6057
/// </summary>
6158
private static void InitializeLogFile()
6259
{
60+
if (_initialized) return;
61+
_initialized = true;
62+
6363
try
6464
{
6565
var timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
6666
var fileName = $"boinc_buda_installer_debug_{timestamp}.log";
67-
var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
68-
_logFilePath = Path.Combine(documentsPath, fileName);
67+
var tempPath = Path.GetTempPath();
68+
_logFilePath = Path.Combine(tempPath, fileName);
6969

7070
// Create the initial log entry
7171
LogInfo($"Debug logging started at {DateTime.Now:yyyy-MM-dd HH:mm:ss}", "DebugLogger");
@@ -80,15 +80,10 @@ private static void InitializeLogFile()
8080
LogInfo($"User Name: {Environment.UserName}", "DebugLogger");
8181
LogInfo("=" + new string('=', 70), "DebugLogger");
8282
}
83-
catch (Exception ex)
83+
catch
8484
{
85-
// If we can't create the log file, disable logging
85+
// If we can't create the log file, disable logging silently
8686
_isEnabled = false;
87-
System.Windows.MessageBox.Show(
88-
$"Failed to create debug log file: {ex.Message}\n\nDebug logging has been disabled.",
89-
"Debug Logging Error",
90-
System.Windows.MessageBoxButton.OK,
91-
System.Windows.MessageBoxImage.Warning);
9287
}
9388
}
9489

@@ -191,9 +186,15 @@ public static void LogConfiguration(string name, object value, string component
191186
/// </summary>
192187
private static void Log(string level, string message, string component)
193188
{
194-
if (!_isEnabled || string.IsNullOrEmpty(_logFilePath))
189+
if (!_isEnabled)
195190
return;
196191

192+
if (string.IsNullOrEmpty(_logFilePath))
193+
{
194+
InitializeLogFile();
195+
if (string.IsNullOrEmpty(_logFilePath)) return;
196+
}
197+
197198
try
198199
{
199200
lock (_lockObject)

MainWindow.xaml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,13 @@ along with BOINC. If not, see <http://www.gnu.org/licenses/>.
7575
</ItemsControl.ItemTemplate>
7676
</ItemsControl>
7777

78-
<!-- Bottom panel with debug checkbox on left and buttons on right -->
78+
<!-- Bottom panel with buttons on right -->
7979
<Grid Grid.Row="1" Margin="10">
8080
<Grid.ColumnDefinitions>
8181
<ColumnDefinition Width="*"/>
8282
<ColumnDefinition Width="Auto"/>
8383
</Grid.ColumnDefinitions>
8484

85-
<!-- Debug checkbox on the left -->
86-
<CheckBox Name="DebugLogCheckBox"
87-
Grid.Column="0"
88-
Content="Write debug log to a file"
89-
HorizontalAlignment="Left"
90-
VerticalAlignment="Center"
91-
IsChecked="False"
92-
Checked="DebugLogCheckBox_Checked"
93-
Unchecked="DebugLogCheckBox_Unchecked"/>
94-
9585
<!-- Buttons on the right -->
9686
<StackPanel Grid.Column="1" Orientation="Horizontal">
9787
<Button Name="InstallButton" Content="Install" Width="80" Height="30" Margin="5" Click="InstallButton_Click"/>

MainWindow.xaml.cs

Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public partial class MainWindow : Window
3737
public MainWindow()
3838
{
3939
InitializeComponent();
40+
41+
// Enable debug logging by default
42+
DebugLogger.IsEnabled = true;
43+
4044
TableItems = new ObservableCollection<TableRow>
4145
{
4246
new TableRow { Id = ID.ApplicationUpdate, Icon = "", Status = "Check installer update" },
@@ -52,19 +56,6 @@ public MainWindow()
5256
DebugLogger.LogConfiguration("Initial table items count", TableItems.Count, "MainWindow");
5357
}
5458

55-
// Debug checkbox event handlers
56-
private void DebugLogCheckBox_Checked(object sender, RoutedEventArgs e)
57-
{
58-
DebugLogger.IsEnabled = true;
59-
DebugLogger.LogInfo("Debug logging enabled by user", "MainWindow");
60-
}
61-
62-
private void DebugLogCheckBox_Unchecked(object sender, RoutedEventArgs e)
63-
{
64-
DebugLogger.LogInfo("Debug logging being disabled by user", "MainWindow");
65-
DebugLogger.IsEnabled = false;
66-
}
67-
6859
private bool CheckWindowsVersionCompatibility()
6960
{
7061
DebugLogger.LogMethodStart("CheckWindowsVersionCompatibility", component: "MainWindow");
@@ -191,6 +182,7 @@ private async Task<bool> CheckWsl()
191182
DebugLogger.LogError($"WSL check failed with status: {wslResult.Status}", "MainWindow");
192183
ChangeRowIconAndStatus(ID.WslCheck, "RedCancelIcon", WslCheck.GetStatusDisplayMessage(wslResult));
193184
DebugLogger.LogMethodEnd("CheckWsl", "false (WSL error)", "MainWindow");
185+
PromptOpenIssue("WSL check error", WslCheck.GetStatusDisplayMessage(wslResult));
194186
return false;
195187
}
196188
}
@@ -199,6 +191,7 @@ private async Task<bool> CheckWsl()
199191
DebugLogger.LogException(ex, "Error occurred while checking WSL", "MainWindow");
200192
ChangeRowIconAndStatus(ID.WslCheck, "RedCancelIcon", "Error occurred while checking WSL");
201193
DebugLogger.LogMethodEnd("CheckWsl", "false (exception)", "MainWindow");
194+
PromptOpenIssue("WSL check exception", ex.ToString());
202195
return false;
203196
}
204197
}
@@ -225,8 +218,8 @@ private async Task<bool> CheckBoincProcess()
225218
DebugLogger.LogWarning($"BOINC process is running: {boincResult.Message}", "MainWindow");
226219
ChangeRowIconAndStatus(ID.BoincProcessCheck, "RedCancelIcon", boincResult.Message);
227220

228-
// Ask user if they want to stop BOINC
229-
var result = MessageBox.Show(
221+
// Show instruction to stop BOINC (do NOT offer to create an issue here)
222+
MessageBox.Show(
230223
$"BOINC client is currently running and may interfere with the installation.\n\nPlease stop the running BOINC client and retry the installation.",
231224
$"{boincResult.Message}",
232225
MessageBoxButton.OK,
@@ -245,6 +238,8 @@ private async Task<bool> CheckBoincProcess()
245238
DebugLogger.LogWarning($"Unable to check BOINC status: {boincResult.ErrorMessage}", "MainWindow");
246239
ChangeRowIconAndStatus(ID.BoincProcessCheck, "YellowExclamationIcon", $"Unable to check BOINC status: {boincResult.ErrorMessage}");
247240
DebugLogger.LogMethodEnd("CheckBoincProcess", "true (error, continue anyway)", "MainWindow");
241+
// Continue but offer to report if user wants
242+
PromptOpenIssue("BOINC process check error", boincResult.ErrorMessage);
248243
return true; // Continue despite error
249244
}
250245
}
@@ -253,6 +248,8 @@ private async Task<bool> CheckBoincProcess()
253248
DebugLogger.LogException(ex, "Error occurred while checking BOINC process", "MainWindow");
254249
ChangeRowIconAndStatus(ID.BoincProcessCheck, "YellowExclamationIcon", "Error occurred while checking BOINC process");
255250
DebugLogger.LogMethodEnd("CheckBoincProcess", "true (exception, continue anyway)", "MainWindow");
251+
// Offer to report issue
252+
PromptOpenIssue("BOINC process check exception", ex.ToString());
256253
return true; // Continue despite error
257254
}
258255
}
@@ -305,6 +302,8 @@ private async Task<bool> CheckBudaRunner()
305302
DebugLogger.LogError($"BUDA Runner check failed: {budaResult.ErrorMessage}", "MainWindow");
306303
ChangeRowIconAndStatus(ID.BudaRunnerCheck, "YellowExclamationIcon", BudaRunnerCheck.GetStatusDisplayMessage(budaResult));
307304
DebugLogger.LogMethodEnd("CheckBudaRunner", "true (error, continue anyway)", "MainWindow");
305+
// Offer to report issue
306+
PromptOpenIssue("BUDA Runner check error", budaResult.ErrorMessage);
308307
return true; // Continue despite error
309308
}
310309
}
@@ -313,6 +312,8 @@ private async Task<bool> CheckBudaRunner()
313312
DebugLogger.LogException(ex, "Error occurred while checking BUDA Runner", "MainWindow");
314313
ChangeRowIconAndStatus(ID.BudaRunnerCheck, "YellowExclamationIcon", "Error occurred while checking BUDA Runner");
315314
DebugLogger.LogMethodEnd("CheckBudaRunner", "true (exception, continue anyway)", "MainWindow");
315+
// Offer to report issue
316+
PromptOpenIssue("BUDA Runner check exception", ex.ToString());
316317
return true; // Continue despite error
317318
}
318319
}
@@ -345,6 +346,8 @@ private async Task<bool> InstallBudaRunner(BudaRunnerCheck.BudaRunnerCheckResult
345346
DebugLogger.LogError("BUDA Runner installation failed", "MainWindow");
346347
ChangeRowIconAndStatus(ID.BudaRunnerCheck, "RedCancelIcon", "Failed to install BUDA Runner");
347348
DebugLogger.LogMethodEnd("InstallBudaRunner", "false", "MainWindow");
349+
// Offer to report issue
350+
PromptOpenIssue("BUDA Runner installation failed", "Failed to install BUDA Runner");
348351
return false;
349352
}
350353
}
@@ -353,6 +356,8 @@ private async Task<bool> InstallBudaRunner(BudaRunnerCheck.BudaRunnerCheckResult
353356
DebugLogger.LogException(ex, "BUDA Runner installation failed", "MainWindow");
354357
ChangeRowIconAndStatus(ID.BudaRunnerCheck, "RedCancelIcon", $"BUDA Runner installation failed: {ex.Message}");
355358
DebugLogger.LogMethodEnd("InstallBudaRunner", "false (exception)", "MainWindow");
359+
// Offer to report issue
360+
PromptOpenIssue("BUDA Runner installation exception", ex.ToString());
356361
return false;
357362
}
358363
}
@@ -397,6 +402,8 @@ private async Task<bool> InstallWsl()
397402
DebugLogger.LogError("WSL installation failed", "MainWindow");
398403
ChangeRowIconAndStatus(ID.WslCheck, "RedCancelIcon", "Failed to install WSL");
399404
DebugLogger.LogMethodEnd("InstallWsl", "false", "MainWindow");
405+
// Offer to report issue
406+
PromptOpenIssue("WSL installation failed", "Failed to install WSL");
400407
return false;
401408
}
402409
}
@@ -405,6 +412,8 @@ private async Task<bool> InstallWsl()
405412
DebugLogger.LogException(ex, "WSL installation failed", "MainWindow");
406413
ChangeRowIconAndStatus(ID.WslCheck, "RedCancelIcon", "WSL installation failed");
407414
DebugLogger.LogMethodEnd("InstallWsl", "false (exception)", "MainWindow");
415+
// Offer to report issue
416+
PromptOpenIssue("WSL installation exception", ex.ToString());
408417
return false;
409418
}
410419
}
@@ -437,6 +446,8 @@ private async Task<bool> FixWslIssues(WslCheck.WslCheckResult wslResult)
437446
DebugLogger.LogWarning("Some WSL issues could not be fixed automatically", "MainWindow");
438447
ChangeRowIconAndStatus(ID.WslCheck, "YellowExclamationIcon", "Some WSL issues could not be fixed automatically");
439448
DebugLogger.LogMethodEnd("FixWslIssues", "false", "MainWindow");
449+
// Offer to report issue
450+
PromptOpenIssue("WSL fix issues could not be resolved", WslCheck.GetStatusDisplayMessage(wslResult));
440451
return false;
441452
}
442453
}
@@ -445,6 +456,8 @@ private async Task<bool> FixWslIssues(WslCheck.WslCheckResult wslResult)
445456
DebugLogger.LogException(ex, "Failed to fix WSL configuration", "MainWindow");
446457
ChangeRowIconAndStatus(ID.WslCheck, "RedCancelIcon", "Failed to fix WSL configuration");
447458
DebugLogger.LogMethodEnd("FixWslIssues", "false (exception)", "MainWindow");
459+
// Offer to report issue
460+
PromptOpenIssue("WSL fix exception", ex.ToString());
448461
return false;
449462
}
450463
}
@@ -619,6 +632,47 @@ private void ChangeRowIconAndStatus(ID id, string newIcon, string status)
619632
}
620633
}
621634

635+
private void PromptOpenIssue(string title, string details)
636+
{
637+
try
638+
{
639+
// Build a GitHub new issue URL with prefilled title/body.
640+
var repoNewIssueUrl = "https://github.com/BOINC/boinc-buda-runner-wsl-installer/issues/new";
641+
642+
var sb = new StringBuilder();
643+
sb.AppendLine("Describe the problem and steps to reproduce here.\n");
644+
sb.AppendLine("Error context:");
645+
sb.AppendLine(details ?? "(no details)");
646+
sb.AppendLine();
647+
sb.AppendLine($"App version: {FileVersionInfo.GetVersionInfo(Process.GetCurrentProcess().MainModule.FileName).FileVersion}");
648+
sb.AppendLine($"OS: {Environment.OSVersion}");
649+
sb.AppendLine($"64-bit OS: {Environment.Is64BitOperatingSystem}, 64-bit Process: {Environment.Is64BitProcess}");
650+
sb.AppendLine();
651+
if (!string.IsNullOrEmpty(DebugLogger.LogFilePath))
652+
{
653+
sb.AppendLine($"Log file path (attach this file in the issue): {DebugLogger.LogFilePath}");
654+
}
655+
656+
var url = repoNewIssueUrl + "?title=" + Uri.EscapeDataString(title ?? "Installer error")
657+
+ "&body=" + Uri.EscapeDataString(sb.ToString());
658+
659+
var ask = MessageBox.Show(
660+
"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.",
661+
"Report Error",
662+
MessageBoxButton.YesNo,
663+
MessageBoxImage.Question);
664+
665+
if (ask == MessageBoxResult.Yes)
666+
{
667+
Process.Start(url);
668+
}
669+
}
670+
catch (Exception ex)
671+
{
672+
DebugLogger.LogException(ex, "Failed to create/open GitHub issue link", "MainWindow");
673+
}
674+
}
675+
622676
// --- Self-update logic (lightweight JSON parsing) ---
623677
private static string ExtractJsonString(string json, string propertyName)
624678
{

0 commit comments

Comments
 (0)