Skip to content

Commit 711912d

Browse files
committed
Add Open Assembly menu, drag-drop support, and empty startup state
Open without arguments now shows an empty form instead of a usage dialog. Users can load assemblies via Options > Open Assembly (Ctrl+O) or by dropping a .dll/.exe onto the form. Reloading replaces the current view in-place.
1 parent fc79c28 commit 711912d

3 files changed

Lines changed: 112 additions & 22 deletions

File tree

AssemblyInformation/FormMain.Designer.cs

Lines changed: 25 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AssemblyInformation/FormMain.cs

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ public partial class FormMain : Form
1414
{
1515
private const string Loading = "Loading";
1616

17-
private readonly string _assemblyPath;
17+
private string _assemblyPath;
1818

1919
private static readonly Dictionary<string, Form> AssemblyFormMap = new Dictionary<string, Form>();
2020

21-
private readonly AssemblyInformationLoader assemblyInformation;
21+
private AssemblyInformationLoader assemblyInformation;
2222

2323
private List<Binary> recursiveDependencies;
2424

@@ -27,15 +27,43 @@ public partial class FormMain : Form
2727
public FormMain(string assemblyPath)
2828
{
2929
InitializeComponent();
30+
FormClosing += FormMainFormClosing;
31+
if (assemblyPath != null)
32+
LoadAssembly(assemblyPath);
33+
}
34+
35+
private void LoadAssembly(string assemblyPath)
36+
{
37+
// Clean up previous state
38+
if (_assemblyPath != null)
39+
AssemblyFormMap.Remove(_assemblyPath);
40+
directDependencies = null;
41+
recursiveDependencies = null;
42+
dependencyTreeView.Nodes.Clear();
43+
referenceListListBox.Items.Clear();
44+
referringAssembliesListtBox.Items.Clear();
45+
3046
_assemblyPath = assemblyPath;
3147
assemblyInformation = new AssemblyInformationLoader(assemblyPath);
3248
referringAssemblyFolderTextBox.Text = Path.GetDirectoryName(assemblyPath);
3349
AssemblyFormMap[assemblyPath] = this;
34-
FormClosing += FormMainFormClosing;
50+
Text = $"Assembly Information - {Path.GetFileName(assemblyPath)}";
51+
panel1.Visible = true;
52+
53+
// Re-run the load logic
54+
FormMainLoad(this, EventArgs.Empty);
3555
}
3656

3757
private void FormMainLoad(object sender, EventArgs e)
3858
{
59+
// If no assembly loaded, show empty state
60+
if (assemblyInformation == null)
61+
{
62+
panel1.Visible = false;
63+
Text = "Assembly Information";
64+
return;
65+
}
66+
3967
string debuggableFlagsToolTipText;
4068

4169
// Prevent read-only display fields from receiving focus
@@ -144,7 +172,8 @@ private void FormMainLoad(object sender, EventArgs e)
144172

145173
private void FormMainFormClosing(object sender, FormClosingEventArgs e)
146174
{
147-
AssemblyFormMap.Remove(_assemblyPath);
175+
if (_assemblyPath != null)
176+
AssemblyFormMap.Remove(_assemblyPath);
148177
}
149178

150179
private void FillAssemblyReferences(IEnumerable<Binary> dependencies, TreeNode treeNode = null)
@@ -279,7 +308,7 @@ private void DependencyTreeViewBeforeExpand(object sender, TreeViewCancelEventAr
279308

280309
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
281310
{
282-
if (!assemblyInformation.IsManaged) return;
311+
if (assemblyInformation == null || !assemblyInformation.IsManaged) return;
283312

284313
if (tabControl1.SelectedIndex == 1 && referenceListListBox.Items.Count == 0)
285314
{
@@ -411,6 +440,48 @@ private void RefreshDependencyDisplay()
411440
if (recursiveDependencies != null)
412441
FillRecursiveDependency();
413442
}
443+
444+
private void OpenAssemblyToolStripMenuItem_Click(object sender, EventArgs e)
445+
{
446+
using var dlg = new OpenFileDialog
447+
{
448+
Title = "Open Assembly",
449+
Filter = "Assemblies (*.dll;*.exe)|*.dll;*.exe|All files (*.*)|*.*",
450+
FilterIndex = 1
451+
};
452+
if (_assemblyPath != null)
453+
dlg.InitialDirectory = Path.GetDirectoryName(_assemblyPath);
454+
if (dlg.ShowDialog() == DialogResult.OK)
455+
LoadAssembly(dlg.FileName);
456+
}
457+
458+
private void FormMain_DragEnter(object sender, DragEventArgs e)
459+
{
460+
if (e.Data.GetDataPresent(DataFormats.FileDrop))
461+
{
462+
var files = (string[])e.Data.GetData(DataFormats.FileDrop);
463+
if (files.Length == 1)
464+
{
465+
var ext = Path.GetExtension(files[0]).ToLowerInvariant();
466+
if (ext == ".dll" || ext == ".exe")
467+
{
468+
e.Effect = DragDropEffects.Copy;
469+
return;
470+
}
471+
}
472+
}
473+
e.Effect = DragDropEffects.None;
474+
}
475+
476+
private void FormMain_DragDrop(object sender, DragEventArgs e)
477+
{
478+
if (e.Data.GetDataPresent(DataFormats.FileDrop))
479+
{
480+
var files = (string[])e.Data.GetData(DataFormats.FileDrop);
481+
if (files.Length == 1)
482+
LoadAssembly(files[0]);
483+
}
484+
}
414485
}
415486

416487
internal class AssemblyNameComparer : IComparer<AssemblyName>

AssemblyInformation/Program.cs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,30 @@ public class Program
1010
[STAThread]
1111
public static void Main(string[] args)
1212
{
13+
Application.EnableVisualStyles();
14+
Application.SetCompatibleTextRenderingDefault(false);
1315
Application.ThreadException += ApplicationThreadException;
1416

17+
string assemblyFullPath = null;
18+
1519
if (args.Length == 1)
1620
{
17-
string filePath = args[0];
18-
string assemblyFullPath = Path.GetFullPath(filePath);
21+
assemblyFullPath = Path.GetFullPath(args[0]);
1922

2023
if (!File.Exists(assemblyFullPath))
2124
{
2225
MessageBox.Show(string.Format(Resource.FailedToLocateFile, assemblyFullPath), Resource.AppName, MessageBoxButtons.OK, MessageBoxIcon.Error);
2326
return;
2427
}
28+
}
2529

26-
try
27-
{
28-
Application.EnableVisualStyles();
29-
Application.SetCompatibleTextRenderingDefault(false);
30-
Application.Run(new FormMain(assemblyFullPath));
31-
}
32-
catch (Exception ex)
33-
{
34-
MessageBox.Show(string.Format(Resource.LoadError, ex.Message), Resource.AppName, MessageBoxButtons.OK, MessageBoxIcon.Error);
35-
}
30+
try
31+
{
32+
Application.Run(new FormMain(assemblyFullPath));
3633
}
37-
else
34+
catch (Exception ex)
3835
{
39-
MessageBox.Show(Resource.UsageString, Resource.AppName, MessageBoxButtons.OK, MessageBoxIcon.Information);
36+
MessageBox.Show(string.Format(Resource.LoadError, ex.Message), Resource.AppName, MessageBoxButtons.OK, MessageBoxIcon.Error);
4037
}
4138
}
4239

0 commit comments

Comments
 (0)