Skip to content

Commit 557dad9

Browse files
author
RandomCrocodile
committed
feature: add Copy Report button to GUI protect tab (#65)
The protect tab now wraps the logger and progress reporter with a DiagnosticCollector during each run. A 'Copy Report' button (enabled once a run completes, success or failure) copies the markdown diagnostic report to the clipboard for pasting into a bug report. Clipboard failures are swallowed so a transient lock cannot crash the app.
1 parent 04b544e commit 557dad9

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

ConfuserEx/ViewModel/UI/ProtectTabVM.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Windows.Media;
88
using CommunityToolkit.Mvvm.Input;
99
using Confuser.Core;
10+
using Confuser.Core.Diagnostics;
1011
using Confuser.Core.Project;
1112
using Microsoft.Extensions.Logging;
1213
using Serilog;
@@ -15,6 +16,7 @@ namespace ConfuserEx.ViewModel {
1516
internal class ProtectTabVM : TabViewModel, IProgressReporter {
1617
readonly Paragraph documentContent;
1718
CancellationTokenSource cancelSrc;
19+
DiagnosticCollector collector;
1820
double? progress = 0;
1921
bool? result;
2022

@@ -33,6 +35,10 @@ public ICommand CancelCmd {
3335
get { return new RelayCommand(DoCancel, () => App.NavigationDisabled); }
3436
}
3537

38+
public ICommand CopyReportCmd {
39+
get { return new RelayCommand(DoCopyReport, () => Result != null && collector != null); }
40+
}
41+
3642
public double? Progress {
3743
get { return progress; }
3844
set { SetProperty(ref progress, value, "Progress"); }
@@ -65,8 +71,12 @@ void DoProtect() {
6571
builder.AddSerilog(serilogLogger, dispose: true));
6672
var melLogger = loggerFactory.CreateLogger("ConfuserEx");
6773

68-
parameters.Logger = melLogger;
69-
parameters.ProgressReporter = this;
74+
// The collector wraps the logger and this progress reporter so a diagnostic report —
75+
// covering both successful and failed runs — can be copied afterwards. It captures the
76+
// full transcript regardless of the display level and forwards everything through.
77+
collector = new DiagnosticCollector(melLogger, this) { Project = parameters.Project };
78+
parameters.Logger = collector;
79+
parameters.ProgressReporter = collector;
7080

7181
cancelSrc = new CancellationTokenSource();
7282
Result = null;
@@ -89,6 +99,19 @@ void DoCancel() {
8999
cancelSrc.Cancel();
90100
}
91101

102+
void DoCopyReport() {
103+
if (collector == null)
104+
return;
105+
106+
try {
107+
Clipboard.SetText(collector.GenerateReport());
108+
}
109+
catch {
110+
// The clipboard can be transiently locked by another process; a failed copy
111+
// should never crash the app. The user can simply retry.
112+
}
113+
}
114+
92115
#region IProgressReporter
93116

94117
DateTime begin;

ConfuserEx/Views/ProtectTabView.xaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@
1010
</Grid.RowDefinitions>
1111
<Grid.ColumnDefinitions>
1212
<ColumnDefinition Width="*" />
13+
<ColumnDefinition Width="110px" />
1314
<ColumnDefinition Width="100px" />
1415
<ColumnDefinition Width="100px" />
1516
</Grid.ColumnDefinitions>
1617

1718
<ProgressBar x:Name="progress" Grid.Row="0" Grid.Column="0" Margin="5"
1819
Value="{Binding Progress}" Minimum="0" Maximum="1" />
19-
<Button Grid.Row="0" Grid.Column="1" Margin="5" Content="Protect!" Command="{Binding ProtectCmd}" />
20-
<Button Grid.Row="0" Grid.Column="2" Margin="5" Content="Cancel" Command="{Binding CancelCmd}" />
21-
<RichTextBox x:Name="log" Grid.Row="1" Grid.ColumnSpan="3" Margin="5" FontFamily="Consolas"
20+
<Button Grid.Row="0" Grid.Column="1" Margin="5" Content="Copy Report"
21+
ToolTip="Copy a diagnostic report (system, configuration and log) to the clipboard for bug reports."
22+
Command="{Binding CopyReportCmd}" />
23+
<Button Grid.Row="0" Grid.Column="2" Margin="5" Content="Protect!" Command="{Binding ProtectCmd}" />
24+
<Button Grid.Row="0" Grid.Column="3" Margin="5" Content="Cancel" Command="{Binding CancelCmd}" />
25+
<RichTextBox x:Name="log" Grid.Row="1" Grid.ColumnSpan="4" Margin="5" FontFamily="Consolas"
2226
IsReadOnly="True" IsReadOnlyCaretVisible="True" local:Skin.RTBDocument="{Binding LogDocument}"
2327
VerticalScrollBarVisibility="Visible" />
2428
</Grid>

0 commit comments

Comments
 (0)