8
8
using System ;
9
9
using System . Collections . Generic ;
10
10
using System . Diagnostics ;
11
- using System . Globalization ;
12
11
using System . IO ;
13
12
using System . Linq ;
14
13
using System . Net ;
@@ -194,7 +193,7 @@ public static void SetGlobalRibbon(CustomRibbon ribbon)
194
193
195
194
private void C4WAddIn_Startup ( object sender , EventArgs e )
196
195
{
197
- string module = $ "{ MethodBase . GetCurrentMethod ( ) . Name } ()";
196
+ string module = $ "{ _product } . { _class } . { MethodBase . GetCurrentMethod ( ) . Name } ()";
198
197
try
199
198
{
200
199
// Deliberate crash to test Error Reporting
@@ -215,10 +214,18 @@ private void C4WAddIn_Startup(object sender, EventArgs e)
215
214
PerformStartUpActions ( ) ;
216
215
217
216
sw . Stop ( ) ;
218
- message = $ "{ module } took { sw . ElapsedMilliseconds . ToString ( "#,000" , CultureInfo . InvariantCulture ) } ms";
217
+ message = $ "{ module } took { SafeDouble . AsString ( sw . ElapsedMilliseconds ) } ms";
219
218
StartUpTimings . Add ( message ) ;
220
219
Debug . WriteLine ( message ) ;
221
220
}
221
+ else
222
+ {
223
+ if ( Ribbon == null )
224
+ {
225
+ RegistryHelper . StoreMessage ( module , "Ribbon is null" ) ;
226
+ }
227
+ RegistryHelper . StoreMessage ( module , $ "Command line { cmd } ") ;
228
+ }
222
229
}
223
230
catch ( Exception exception )
224
231
{
@@ -275,13 +282,13 @@ private void SlowOperations()
275
282
Telemetry = new TelemetryWriter ( true , Helper ) ;
276
283
277
284
sw . Stop ( ) ;
278
- message = $ "{ module } took { sw . ElapsedMilliseconds . ToString ( "#,000" , CultureInfo . InvariantCulture ) } ms";
285
+ message = $ "{ module } took { SafeDouble . AsString ( sw . ElapsedMilliseconds ) } ms";
279
286
Debug . WriteLine ( message ) ;
280
287
StartUpTimings . Add ( message ) ;
281
288
}
282
- catch ( ThreadAbortException )
289
+ catch ( ThreadAbortException threadAbortException )
283
290
{
284
- // Do Nothing
291
+ RegistryHelper . StoreException ( module , threadAbortException ) ;
285
292
}
286
293
catch ( Exception exception )
287
294
{
@@ -297,15 +304,15 @@ private void PerformStartUpActions()
297
304
{
298
305
AddInInfo = new C4wAddInInfo ( ) ;
299
306
307
+ UpdateHelper . ReadSavedValues ( ) ;
308
+ UpdateHelper . ReadThisVersion ( Assembly . GetExecutingAssembly ( ) ) ;
309
+ ShowOrHideUpdateShield ( ) ;
310
+
300
311
// Handle slower startup stuff on thread
301
312
Thread thread = new Thread ( SlowOperations ) ;
302
313
thread . SetApartmentState ( ApartmentState . STA ) ;
303
314
thread . Start ( ) ;
304
315
305
- UpdateHelper . ReadSavedValues ( ) ;
306
- UpdateHelper . ReadThisVersion ( Assembly . GetExecutingAssembly ( ) ) ;
307
- ShowOrHideUpdateShield ( ) ;
308
-
309
316
if ( VersionsBehind < Constants . MaximumVersionsBehind )
310
317
{
311
318
Word . Application app = Application ;
@@ -349,18 +356,20 @@ private void PerformStartUpActions()
349
356
}
350
357
else
351
358
{
359
+ SetButtonStates ( ButtonState . Disabled ) ;
352
360
StartUpTimings . Add (
353
361
$ "{ module } chemistry operations disabled because Chem4Word is { VersionsBehind } versions behind!") ;
362
+ RegistryHelper . StoreMessage ( module , $ "Chem4Word is disabled because it is { VersionsBehind } versions behind!") ;
354
363
}
355
364
356
365
// Deliberate crash to test Error Reporting
357
366
//int ii = 2;
358
367
//int dd = 0;
359
368
//int bang = ii / dd;
360
369
}
361
- catch ( ThreadAbortException )
370
+ catch ( ThreadAbortException threadAbortException )
362
371
{
363
- // Do Nothing
372
+ RegistryHelper . StoreException ( module , threadAbortException ) ;
364
373
}
365
374
catch ( Exception exception )
366
375
{
@@ -407,99 +416,98 @@ public void LoadOptions()
407
416
// Initialise Telemetry with send permission
408
417
Telemetry = new TelemetryWriter ( true , Helper ) ;
409
418
410
- // Read in options file
411
- if ( string . IsNullOrEmpty ( AddInInfo . ProductAppDataPath ) )
412
- {
413
- Debugger . Break ( ) ;
414
- }
415
- SystemOptions = new Chem4WordOptions ( AddInInfo . ProductAppDataPath ) ;
416
- if ( SystemOptions . Errors . Any ( ) )
417
- {
418
- Telemetry . Write ( module , "Exception" , string . Join ( Environment . NewLine , SystemOptions . Errors ) ) ;
419
- SystemOptions . Errors = new List < string > ( ) ;
420
- }
421
-
422
- bool isBeta = true ;
423
- try
419
+ if ( AddInInfo != null )
424
420
{
425
- if ( ThisVersion != null )
421
+ // Read in options file
422
+ SystemOptions = new Chem4WordOptions ( AddInInfo . ProductAppDataPath ) ;
423
+ if ( SystemOptions . Errors . Any ( ) )
426
424
{
427
- string betaValue = ThisVersion . Root ? . Element ( "IsBeta" ) ? . Value ;
428
- isBeta = betaValue != null && bool . Parse ( betaValue ) ;
425
+ Telemetry . Write ( module , "Exception" , string . Join ( Environment . NewLine , SystemOptions . Errors ) ) ;
426
+ SystemOptions . Errors = new List < string > ( ) ;
429
427
}
430
- }
431
- catch
432
- {
433
- // Assume isBeta
434
- }
435
428
436
- // Belt and braces ...
437
- if ( SystemOptions == null )
438
- {
439
- SystemOptions = new Chem4WordOptions
429
+ bool isBeta = true ;
430
+ try
440
431
{
441
- SettingsPath = AddInInfo . ProductAppDataPath
442
- } ;
443
- }
444
-
445
- // ... as we are seeing some errors here ?
446
- // Re-Initialise Telemetry with granted permissions
447
- Telemetry = new TelemetryWriter ( isBeta || SystemOptions . TelemetryEnabled , Helper ) ;
448
-
449
- try
450
- {
451
- bool settingsChanged = false ;
432
+ if ( ThisVersion != null )
433
+ {
434
+ string betaValue = ThisVersion . Root ? . Element ( "IsBeta" ) ? . Value ;
435
+ isBeta = betaValue != null && bool . Parse ( betaValue ) ;
436
+ }
437
+ }
438
+ catch
439
+ {
440
+ // Assume isBeta
441
+ }
452
442
453
- if ( string . IsNullOrEmpty ( SystemOptions . SelectedEditorPlugIn ) )
443
+ // Belt and braces ...
444
+ if ( SystemOptions == null )
454
445
{
455
- SystemOptions . SelectedEditorPlugIn = Constants . DefaultEditorPlugIn ;
446
+ SystemOptions = new Chem4WordOptions
447
+ {
448
+ SettingsPath = AddInInfo . ProductAppDataPath
449
+ } ;
456
450
}
457
- else
451
+
452
+ // ... as we are seeing some errors here ?
453
+ // Re-Initialise Telemetry with granted permissions
454
+ Telemetry = new TelemetryWriter ( isBeta || SystemOptions . TelemetryEnabled , Helper ) ;
455
+
456
+ try
458
457
{
459
- if ( Editors . Count > 0 )
458
+ bool settingsChanged = false ;
459
+
460
+ if ( string . IsNullOrEmpty ( SystemOptions . SelectedEditorPlugIn ) )
461
+ {
462
+ SystemOptions . SelectedEditorPlugIn = Constants . DefaultEditorPlugIn ;
463
+ }
464
+ else
460
465
{
461
- var editor = GetEditorPlugIn ( SystemOptions . SelectedEditorPlugIn ) ;
462
- if ( editor == null )
466
+ if ( Editors . Count > 0 )
463
467
{
464
- SystemOptions . SelectedEditorPlugIn = Constants . DefaultEditorPlugIn ;
465
- Telemetry . Write ( module , "Information" , $ "Setting editor to { SystemOptions . SelectedEditorPlugIn } ") ;
466
- settingsChanged = true ;
468
+ var editor = GetEditorPlugIn ( SystemOptions . SelectedEditorPlugIn ) ;
469
+ if ( editor == null )
470
+ {
471
+ SystemOptions . SelectedEditorPlugIn = Constants . DefaultEditorPlugIn ;
472
+ Telemetry . Write ( module , "Information" , $ "Setting editor to { SystemOptions . SelectedEditorPlugIn } ") ;
473
+ settingsChanged = true ;
474
+ }
467
475
}
468
476
}
469
- }
470
477
471
- if ( string . IsNullOrEmpty ( SystemOptions . SelectedRendererPlugIn ) )
472
- {
473
- SystemOptions . SelectedRendererPlugIn = Constants . DefaultRendererPlugIn ;
474
- }
475
- else
476
- {
477
- if ( Renderers . Count > 0 )
478
+ if ( string . IsNullOrEmpty ( SystemOptions . SelectedRendererPlugIn ) )
479
+ {
480
+ SystemOptions . SelectedRendererPlugIn = Constants . DefaultRendererPlugIn ;
481
+ }
482
+ else
478
483
{
479
- var renderer = GetRendererPlugIn ( SystemOptions . SelectedRendererPlugIn ) ;
480
- if ( renderer == null )
484
+ if ( Renderers . Count > 0 )
481
485
{
482
- SystemOptions . SelectedRendererPlugIn = Constants . DefaultRendererPlugIn ;
483
- Telemetry . Write ( module , "Information" , $ "Setting renderer to { SystemOptions . SelectedRendererPlugIn } ") ;
484
- settingsChanged = true ;
486
+ var renderer = GetRendererPlugIn ( SystemOptions . SelectedRendererPlugIn ) ;
487
+ if ( renderer == null )
488
+ {
489
+ SystemOptions . SelectedRendererPlugIn = Constants . DefaultRendererPlugIn ;
490
+ Telemetry . Write ( module , "Information" , $ "Setting renderer to { SystemOptions . SelectedRendererPlugIn } ") ;
491
+ settingsChanged = true ;
492
+ }
485
493
}
486
494
}
487
- }
488
495
489
- if ( settingsChanged )
490
- {
491
- Telemetry . Write ( module , "Information" , "Saving revised settings" ) ;
492
- SystemOptions . Save ( ) ;
493
- if ( SystemOptions . Errors . Any ( ) )
496
+ if ( settingsChanged )
494
497
{
495
- Telemetry . Write ( module , "Exception" , string . Join ( Environment . NewLine , SystemOptions . Errors ) ) ;
496
- SystemOptions . Errors = new List < string > ( ) ;
498
+ Telemetry . Write ( module , "Information" , "Saving revised settings" ) ;
499
+ SystemOptions . Save ( ) ;
500
+ if ( SystemOptions . Errors . Any ( ) )
501
+ {
502
+ Telemetry . Write ( module , "Exception" , string . Join ( Environment . NewLine , SystemOptions . Errors ) ) ;
503
+ SystemOptions . Errors = new List < string > ( ) ;
504
+ }
497
505
}
498
506
}
499
- }
500
- catch
501
- {
502
- //
507
+ catch
508
+ {
509
+ //
510
+ }
503
511
}
504
512
}
505
513
catch ( Exception exception )
@@ -800,7 +808,7 @@ private void LoadPlugIns(bool mustBeSigned)
800
808
801
809
sw . Stop ( ) ;
802
810
803
- message = $ "{ module } examining { filesFound } files took { sw . ElapsedMilliseconds . ToString ( "#,000" , CultureInfo . InvariantCulture ) } ms";
811
+ message = $ "{ module } examining { filesFound } files took { SafeDouble . AsString ( sw . ElapsedMilliseconds ) } ms";
804
812
Debug . WriteLine ( message ) ;
805
813
StartUpTimings . Add ( message ) ;
806
814
}
@@ -1133,13 +1141,16 @@ public void ShowOrHideUpdateShield()
1133
1141
Ribbon . Update . Image = Properties . Resources . Shield_Danger ;
1134
1142
Ribbon . Update . Label = "Update to use Chem4Word again" ;
1135
1143
Ribbon . Update . ScreenTip = "You must update to continue using Chem4Word" ;
1136
- Ribbon . Update . SuperTip = $ "You are { VersionsBehind } versions behind and Chem4Word has been disabled because it is too many versions old.";
1144
+ Ribbon . Update . SuperTip = $ "You are { VersionsBehind } versions behind therefore Chem4Word has been disabled as it is too many versions old.";
1137
1145
SetButtonStates ( ButtonState . Disabled ) ;
1138
1146
ChemistryProhibitedReason = Constants . Chem4WordTooOld ;
1139
1147
break ;
1140
1148
}
1141
1149
1142
- if ( VersionsBehind > 0 && ! VersionAvailableIsBeta )
1150
+ string betaValue = Globals . Chem4WordV3 . ThisVersion . Root ? . Element ( "IsBeta" ) ? . Value ;
1151
+ bool isBeta = betaValue != null && bool . Parse ( betaValue ) ;
1152
+
1153
+ if ( isBeta && VersionsBehind > 0 && ! VersionAvailableIsBeta )
1143
1154
{
1144
1155
Ribbon . Update . Visible = true ;
1145
1156
Ribbon . Update . Enabled = true ;
0 commit comments