@@ -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 ) ;
0 commit comments