Skip to content

Commit a973b2e

Browse files
committed
Replace WinForms FolderBrowserDialog with WPF OpenFolderDialog.
1 parent 5625db2 commit a973b2e

File tree

1 file changed

+67
-73
lines changed

1 file changed

+67
-73
lines changed

ILSpy/Commands/GeneratePdbContextMenuEntry.cs

Lines changed: 67 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -153,66 +153,27 @@ internal static void GeneratePdbForAssemblies(IEnumerable<LoadedAssembly> assemb
153153
}
154154

155155
// Ask for target folder
156-
using (var dlg = new System.Windows.Forms.FolderBrowserDialog())
157-
{
158-
dlg.Description = Resources.SelectPDBOutputFolder;
159-
dlg.RootFolder = Environment.SpecialFolder.MyComputer;
160-
dlg.ShowNewFolderButton = true;
161-
// Show dialog on UI thread
162-
System.Windows.Forms.DialogResult result = dlg.ShowDialog();
163-
if (result != System.Windows.Forms.DialogResult.OK || string.IsNullOrWhiteSpace(dlg.SelectedPath))
164-
return;
156+
var dlg = new OpenFolderDialog();
157+
dlg.Title = Resources.SelectPDBOutputFolder;
158+
if (dlg.ShowDialog() != true || string.IsNullOrWhiteSpace(dlg.FolderName))
159+
return;
165160

166-
string targetFolder = dlg.SelectedPath;
167-
DecompilationOptions options = dockWorkspace.ActiveTabPage.CreateDecompilationOptions();
161+
string targetFolder = dlg.FolderName;
162+
DecompilationOptions options = dockWorkspace.ActiveTabPage.CreateDecompilationOptions();
168163

169-
dockWorkspace.RunWithCancellation(ct => Task<AvalonEditTextOutput>.Factory.StartNew(() => {
170-
AvalonEditTextOutput output = new AvalonEditTextOutput();
171-
Stopwatch totalWatch = Stopwatch.StartNew();
172-
options.CancellationToken = ct;
164+
dockWorkspace.RunWithCancellation(ct => Task<AvalonEditTextOutput>.Factory.StartNew(() => {
165+
AvalonEditTextOutput output = new AvalonEditTextOutput();
166+
Stopwatch totalWatch = Stopwatch.StartNew();
167+
options.CancellationToken = ct;
173168

174-
int total = assemblyArray.Length;
175-
int processed = 0;
176-
foreach (var assembly in assemblyArray)
169+
int total = assemblyArray.Length;
170+
int processed = 0;
171+
foreach (var assembly in assemblyArray)
172+
{
173+
// only process supported assemblies
174+
if (!supported.TryGetValue(assembly, out var file))
177175
{
178-
// only process supported assemblies
179-
if (!supported.TryGetValue(assembly, out var file))
180-
{
181-
output.WriteLine(string.Format(Resources.CannotCreatePDBFile, Path.GetFileName(assembly.FileName)));
182-
processed++;
183-
if (options.Progress != null)
184-
{
185-
options.Progress.Report(new DecompilationProgress {
186-
Title = Resources.GeneratingPortablePDB,
187-
TotalUnits = total,
188-
UnitsCompleted = processed
189-
});
190-
}
191-
continue;
192-
}
193-
194-
string fileName = Path.Combine(targetFolder, WholeProjectDecompiler.CleanUpFileName(assembly.ShortName, ".pdb"));
195-
196-
try
197-
{
198-
using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
199-
{
200-
var decompiler = new CSharpDecompiler(file, assembly.GetAssemblyResolver(options.DecompilerSettings.AutoLoadAssemblyReferences), options.DecompilerSettings);
201-
decompiler.CancellationToken = ct;
202-
PortablePdbWriter.WritePdb(file, decompiler, options.DecompilerSettings, stream, progress: options.Progress, currentProgressTitle: Resources.GeneratingPortablePDB);
203-
}
204-
output.WriteLine(string.Format(Resources.GeneratedPDBFile, fileName));
205-
}
206-
catch (OperationCanceledException)
207-
{
208-
output.WriteLine();
209-
output.WriteLine(Resources.GenerationWasCancelled);
210-
throw;
211-
}
212-
catch (Exception ex)
213-
{
214-
output.WriteLine(string.Format(Resources.GenerationFailedForAssembly, assembly.FileName, ex.Message));
215-
}
176+
output.WriteLine(string.Format(Resources.CannotCreatePDBFile, Path.GetFileName(assembly.FileName)));
216177
processed++;
217178
if (options.Progress != null)
218179
{
@@ -222,29 +183,62 @@ internal static void GeneratePdbForAssemblies(IEnumerable<LoadedAssembly> assemb
222183
UnitsCompleted = processed
223184
});
224185
}
186+
continue;
225187
}
226188

227-
totalWatch.Stop();
228-
output.WriteLine();
229-
output.WriteLine(Resources.GenerationCompleteInSeconds, totalWatch.Elapsed.TotalSeconds.ToString("F1"));
230-
output.WriteLine();
231-
// Select all generated pdb files in explorer
232-
var generatedFiles = assemblyArray
233-
.Select(a => Path.Combine(targetFolder, WholeProjectDecompiler.CleanUpFileName(a.ShortName, ".pdb")))
234-
.Where(File.Exists)
235-
.ToList();
236-
if (generatedFiles.Any())
189+
string fileName = Path.Combine(targetFolder, WholeProjectDecompiler.CleanUpFileName(assembly.ShortName, ".pdb"));
190+
191+
try
237192
{
238-
output.AddButton(null, Resources.OpenExplorer, delegate { ShellHelper.OpenFolderAndSelectItems(generatedFiles); });
193+
using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
194+
{
195+
var decompiler = new CSharpDecompiler(file, assembly.GetAssemblyResolver(options.DecompilerSettings.AutoLoadAssemblyReferences), options.DecompilerSettings);
196+
decompiler.CancellationToken = ct;
197+
PortablePdbWriter.WritePdb(file, decompiler, options.DecompilerSettings, stream, progress: options.Progress, currentProgressTitle: Resources.GeneratingPortablePDB);
198+
}
199+
output.WriteLine(string.Format(Resources.GeneratedPDBFile, fileName));
239200
}
240-
else
201+
catch (OperationCanceledException)
241202
{
242-
output.AddButton(null, Resources.OpenExplorer, delegate { ShellHelper.OpenFolder(targetFolder); });
203+
output.WriteLine();
204+
output.WriteLine(Resources.GenerationWasCancelled);
205+
throw;
243206
}
244-
output.WriteLine();
245-
return output;
246-
}, ct)).Then(dockWorkspace.ShowText).HandleExceptions();
247-
}
207+
catch (Exception ex)
208+
{
209+
output.WriteLine(string.Format(Resources.GenerationFailedForAssembly, assembly.FileName, ex.Message));
210+
}
211+
processed++;
212+
if (options.Progress != null)
213+
{
214+
options.Progress.Report(new DecompilationProgress {
215+
Title = Resources.GeneratingPortablePDB,
216+
TotalUnits = total,
217+
UnitsCompleted = processed
218+
});
219+
}
220+
}
221+
222+
totalWatch.Stop();
223+
output.WriteLine();
224+
output.WriteLine(Resources.GenerationCompleteInSeconds, totalWatch.Elapsed.TotalSeconds.ToString("F1"));
225+
output.WriteLine();
226+
// Select all generated pdb files in explorer
227+
var generatedFiles = assemblyArray
228+
.Select(a => Path.Combine(targetFolder, WholeProjectDecompiler.CleanUpFileName(a.ShortName, ".pdb")))
229+
.Where(File.Exists)
230+
.ToList();
231+
if (generatedFiles.Any())
232+
{
233+
output.AddButton(null, Resources.OpenExplorer, delegate { ShellHelper.OpenFolderAndSelectItems(generatedFiles); });
234+
}
235+
else
236+
{
237+
output.AddButton(null, Resources.OpenExplorer, delegate { ShellHelper.OpenFolder(targetFolder); });
238+
}
239+
output.WriteLine();
240+
return output;
241+
}, ct)).Then(dockWorkspace.ShowText).HandleExceptions();
248242
}
249243
}
250244

0 commit comments

Comments
 (0)