Skip to content

Commit 7668d92

Browse files
author
Darin Higgins
committed
Added built in simple help.
Added control for turning LOGGING on. Added menu for turning REPORT on. Beefed up error handling during sequence processing. Improved performance by only evaluating the target app control tree once and caching Regexs.
1 parent 7e19f1b commit 7668d92

File tree

7 files changed

+165862
-29
lines changed

7 files changed

+165862
-29
lines changed

Disambiguator/Disambiguator.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@
8686
</Reference>
8787
</ItemGroup>
8888
<ItemGroup>
89+
<Compile Include="DisambiguatorHelp.cs">
90+
<SubType>Form</SubType>
91+
</Compile>
92+
<Compile Include="DisambiguatorHelp.Designer.cs">
93+
<DependentUpon>DisambiguatorHelp.cs</DependentUpon>
94+
</Compile>
8995
<Compile Include="Properties\Resources.Designer.cs">
9096
<AutoGen>True</AutoGen>
9197
<DesignTime>True</DesignTime>
@@ -98,6 +104,9 @@
98104
</Compile>
99105
</ItemGroup>
100106
<ItemGroup>
107+
<EmbeddedResource Include="DisambiguatorHelp.resx">
108+
<DependentUpon>DisambiguatorHelp.cs</DependentUpon>
109+
</EmbeddedResource>
101110
<EmbeddedResource Include="Properties\Resources.resx">
102111
<Generator>ResXFileCodeGenerator</Generator>
103112
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
@@ -107,6 +116,7 @@
107116
</EmbeddedResource>
108117
</ItemGroup>
109118
<ItemGroup>
119+
<EmbeddedResource Include="DisambiguatorHelp.rtf" />
110120
<None Include="KeePass.exe">
111121
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
112122
</None>

Disambiguator/DisambiguatorExt.cs

Lines changed: 100 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public sealed class DisambiguatorExt : Plugin
4242
/// </summary>
4343
private bool _reportOn = false;
4444

45+
/// <summary>
46+
/// used to turn logging on or off dynamically
47+
/// </summary>
48+
private static bool _loggingOn = false;
49+
4550
/// <summary>
4651
/// is reporting on for this invocation
4752
/// </summary>
@@ -98,6 +103,22 @@ public override ToolStripMenuItem GetMenuItem(PluginMenuType t)
98103
};
99104
subMenu.Click += this.OnSetReportClicked;
100105
menuItem.DropDownItems.Add(subMenu);
106+
107+
subMenu = new ToolStripMenuItem()
108+
{
109+
Text = "Logging",
110+
CheckOnClick = true,
111+
Checked = false,
112+
};
113+
subMenu.Click += this.OnSetLoggingClicked;
114+
menuItem.DropDownItems.Add(subMenu);
115+
116+
subMenu = new ToolStripMenuItem()
117+
{
118+
Text = "Help",
119+
};
120+
subMenu.Click += this.OnHelpClicked;
121+
menuItem.DropDownItems.Add(subMenu);
101122
break;
102123

103124
//case PluginMenuType.Group:
@@ -124,6 +145,27 @@ public override ToolStripMenuItem GetMenuItem(PluginMenuType t)
124145
return menuItem;
125146
}
126147

148+
private void OnSetLoggingClicked(object sender, EventArgs e)
149+
{
150+
var menuItem = sender as ToolStripMenuItem;
151+
_loggingOn = menuItem.Checked;
152+
153+
if (_loggingOn)
154+
{
155+
MessageBox.Show("Disambiguator Logging is now enabled\r\n\r\n" +
156+
"With logging on, a Disambiguator.log file will be written to\r\n" +
157+
"the current user's Desktop.\r\n\r\n" +
158+
"It is recommended to only turn on logging when asked to by\r\n" +
159+
"The Disambiguator development team."
160+
, "The Disambiguator", MessageBoxButtons.OK, MessageBoxIcon.Information);
161+
}
162+
}
163+
164+
private void OnHelpClicked(object sender, EventArgs e)
165+
{
166+
new DisambiguatorHelp().ShowDialog();
167+
}
168+
127169

128170
private void OnSetReportClicked(object sender, EventArgs e)
129171
{
@@ -137,13 +179,13 @@ private void OnSetReportClicked(object sender, EventArgs e)
137179
"evaluate the target application and display a report of the\r\n" +
138180
"executable name and various control details you can use\r\n" +
139181
"to pinpoint the specific autotype sequence to use."
140-
, "The Disambiguator");
182+
, "The Disambiguator", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
141183
}
142184
else
143185
{
144186
MessageBox.Show("Disambiguator Reporting is now disabled\r\n\r\n" +
145187
"Standard autotype functionality will now resume."
146-
, "The Disambiguator");
188+
, "The Disambiguator", MessageBoxButtons.OK, MessageBoxIcon.Information);
147189
}
148190
}
149191

@@ -179,19 +221,26 @@ private void OnMainOptionsClicked(object sender, EventArgs e)
179221
/// <param name="e"></param>
180222
private void AutoType_SequenceQueriesBegin(object sender, SequenceQueriesEventArgs e)
181223
{
182-
Debug("Sequence Queries Begin");
224+
try
225+
{
226+
Debug("Sequence Queries Begin");
183227

184-
_exePath = getExecutableFromHwnd(e.TargetWindowHandle).ToLower();
185-
_exeFile = Path.GetFileName(_exePath);
186-
_report = _reportOn;
187-
_matchCount = 0;
228+
_exePath = getExecutableFromHwnd(e.TargetWindowHandle).ToLower();
229+
_exeFile = Path.GetFileName(_exePath);
230+
_report = _reportOn;
231+
_matchCount = 0;
188232

189-
//traverse the control tree for the target window to collect
190-
//a list of UIelements that we can use to disambiguate
191-
_currentUIElements = TraverseControlTree(e.TargetWindowHandle);
233+
//traverse the control tree for the target window to collect
234+
//a list of UIelements that we can use to disambiguate
235+
_currentUIElements = TraverseControlTree(e.TargetWindowHandle);
192236

193-
//once the target app is analyzed, show any report window (if applicable)
194-
TestOutput.ShowOnTop();
237+
//once the target app is analyzed, show any report window (if applicable)
238+
TestOutput.ShowOnTop();
239+
}
240+
catch (Exception ex)
241+
{
242+
Debug("Error In AutoType_SequenceQueriesBegin: " + ex.ToString());
243+
}
195244
}
196245

197246

@@ -274,28 +323,49 @@ private void AutoType_SequenceQueriesEnd(object sender, SequenceQueriesEventArgs
274323
/// <param name="e"></param>
275324
private void AutoType_SequenceQuery(object sender, SequenceQueryEventArgs e)
276325
{
277-
//if reporting is on, we don't actually try to match anything
278-
if (_report) return;
326+
try
327+
{
328+
//if reporting is on, we don't actually try to match anything
329+
if (_report) return;
330+
331+
//main win title and AutoType sequence for this entry
332+
//we have to check this separately from the custom associations
333+
var autoTypeSequenceTitle = e.Entry.Strings.ReadSafe("Title");
334+
string entryAutoTypeSequence = e.Entry.GetAutoTypeSequence();
279335

280-
//main win title and AutoType sequence for this entry
281-
//we have to check this separately from the custom associations
282-
var autoTypeSequenceTitle = e.Entry.Strings.ReadSafe("Title");
283-
string entryAutoTypeSequence = e.Entry.GetAutoTypeSequence();
336+
try
337+
{
338+
Debug("ResolveSequence for AutoType Sequence Title");
339+
ResolveSequence(autoTypeSequenceTitle, entryAutoTypeSequence, e);
340+
}
341+
catch (Exception ex)
342+
{
343+
Debug("Error In AutoType_SequenceQuery.Resolving Title: " + ex.ToString());
344+
}
284345

285-
Debug("ResolveSequence for AutoType Sequence Title");
286-
ResolveSequence(autoTypeSequenceTitle, entryAutoTypeSequence, e);
346+
//run through the target window associations looking for match elements
347+
foreach (AutoTypeAssociation association in e.Entry.AutoType.Associations)
348+
{
349+
//get the window name (this would usually contain the TITLE of the window
350+
//that would match
351+
try
352+
{
353+
var winName = association.WindowName;
354+
Debug("ResolveSequence for AutoType Association Name");
355+
ResolveSequence(winName, association.Sequence, e);
356+
}
357+
catch (Exception ex)
358+
{
359+
Debug("Error In AutoType_SequenceQuery.Resolving AutoType Associations: " + ex.ToString());
360+
}
361+
}
287362

288-
//run through the target window associations looking for match elements
289-
foreach (AutoTypeAssociation association in e.Entry.AutoType.Associations)
363+
Debug("Finished AutoType_SequenceQuery");
364+
}
365+
catch (Exception ex)
290366
{
291-
//get the window name (this would usually contain the TITLE of the window
292-
//that would match
293-
var winName = association.WindowName;
294-
Debug("ResolveSequence for AutoType Association Name");
295-
ResolveSequence(winName, association.Sequence, e);
367+
Debug("Error In AutoType_SequenceQuery: " + ex.ToString());
296368
}
297-
298-
Debug("Finished AutoType_SequenceQuery");
299369
}
300370

301371

@@ -581,6 +651,7 @@ private static string LogFile
581651

582652
internal static void Debug(string template, params object[] args)
583653
{
654+
if (!_loggingOn) return;
584655
try
585656
{
586657
var buf = string.Format(template, args);

Disambiguator/DisambiguatorHelp.Designer.cs

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

Disambiguator/DisambiguatorHelp.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Data;
5+
using System.Drawing;
6+
using System.IO;
7+
using System.Linq;
8+
using System.Reflection;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
using System.Windows.Forms;
12+
13+
14+
namespace Disambiguator
15+
{
16+
public partial class DisambiguatorHelp : Form
17+
{
18+
public DisambiguatorHelp()
19+
{
20+
InitializeComponent();
21+
}
22+
23+
24+
private void btnClose_Click(object sender, EventArgs e)
25+
{
26+
this.Close();
27+
}
28+
29+
30+
private void DisambiguatorHelp_Load(object sender, EventArgs e)
31+
{
32+
Assembly asm = Assembly.GetExecutingAssembly();
33+
Stream stream = asm.GetManifestResourceStream("Disambiguator.DisambiguatorHelp.rtf");
34+
35+
this.rtfHelp.LoadFile(stream, RichTextBoxStreamType.RichText);
36+
this.rtfHelp.ReadOnly = true;
37+
this.rtfHelp.LinkClicked += RtfHelp_LinkClicked;
38+
}
39+
40+
41+
private void RtfHelp_LinkClicked(object sender, LinkClickedEventArgs e)
42+
{
43+
try
44+
{
45+
System.Diagnostics.Process.Start(e.LinkText);
46+
}
47+
catch { }
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)