Globals.cs
author Thomas
Fri, 05 Aug 2016 18:27:05 +0200
changeset 1110 dcc5e1d58b16
parent 1108 47880211c601
child 1114 b5b466814076
permissions -rw-r--r--
OUT-55: Completed fix for missing sent messages
Dean@1076
     1
using pEp.UI;
Dean@1076
     2
using System;
Dean@1081
     3
using System.Collections.Generic;
Dean@911
     4
using System.IO;
Dean@660
     5
using System.Reflection;
Dean@660
     6
using System.Runtime.InteropServices;
Dean@660
     7
using System.Text;
Dean@660
     8
using System.Threading;
Dean@1074
     9
using System.Windows;
Dean@660
    10
using System.Windows.Forms;
Dean@660
    11
using Office = Microsoft.Office.Core;
Dean@606
    12
Dean@606
    13
namespace pEp
Dean@606
    14
{
Dean@606
    15
    /// <summary>
Dean@660
    16
    /// Class to store all global/shared data and methods.
Dean@860
    17
    /// This class is a shared partial class with the internally generated code.
Dean@606
    18
    /// </summary>
Dean@860
    19
    internal sealed partial class Globals
Dean@606
    20
    {
Thomas@1110
    21
        public const string CUSTOM_SENT_FOLDER_NAME    = "Sent";
Dean@1090
    22
        public const string LOG_FILE_NAME              = "log.txt";
Dean@1084
    23
        public const string PEP_COPYRIGHT              = "Copyright © 2014-2016 p≡p Security SA, Luxembourg";
Dean@1023
    24
        public const string PEP_NAME                   = "p≡p for Outlook";               // Display name to the user
Dean@1023
    25
#if DEBUG
Dean@1023
    26
        public const string PEP_NAME_ADDIN_DESC        = "pEp";                           // Description of the add-in within Outlook itself (shared with reader)
Dean@1023
    27
#else
Dean@1023
    28
        public const string PEP_NAME_ADDIN_DESC        = "pEp for Outlook";               // Description of the add-in within Outlook itself (shared with reader)
Dean@1023
    29
#endif
Dean@1023
    30
        public const string PEP_NAME_INSTALL           = "pEp for Outlook";               // Name for Windows installer, must sync with installation code (shared with reader)
Dean@1023
    31
        public const string PEP_READER_NAME            = "p≡p for Outlook Reader";        // Display name to the user
Dean@1023
    32
        public const string PEP_WEBSITE_LINK           = "https://prettyeasyprivacy.com";
Dean@1023
    33
        public const string PEP_WEBSITE_UPGRADE_LINK   = "https://prettyeasyprivacy.com";
Dean@859
    34
Dean@859
    35
#if READER_RELEASE_MODE
Dean@859
    36
        public const ReleaseMode RELEASE_MODE = ReleaseMode.Reader;
Dean@859
    37
#else
Dean@859
    38
        public const ReleaseMode RELEASE_MODE = ReleaseMode.Standard;
Dean@859
    39
#endif
Dean@859
    40
Dean@882
    41
        // Engine translations
Dean@882
    42
        public const int PHRASE_ID_TRUSTWORDS_LANGUAGE = 1000;
Dean@882
    43
Dean@607
    44
        /// <summary>
Dean@859
    45
        /// Enumeration to define the supported release modes.
Dean@859
    46
        /// </summary>
Dean@859
    47
        public enum ReleaseMode
Dean@859
    48
        {
Dean@859
    49
            Standard,
Dean@859
    50
            Reader
Dean@859
    51
        }
Dean@859
    52
Dean@859
    53
        /// <summary>
Dean@910
    54
        /// Enumeration to define the return status of methods.
Dean@910
    55
        /// </summary>
Dean@910
    56
        public enum ReturnStatus
Dean@910
    57
        {
Dean@910
    58
            /// <summary>
Dean@910
    59
            /// An unspecified failure occured.
Dean@910
    60
            /// </summary>
Dean@910
    61
            Failure,
Dean@910
    62
Dean@910
    63
            /// <summary>
Dean@910
    64
            /// A failure occured because there is no internet or Exchange connection.
Dean@910
    65
            /// </summary>
Dean@910
    66
            FailureNoConnection,
Dean@910
    67
Dean@910
    68
            /// <summary>
Dean@910
    69
            /// Successfully completed with no unexpected failures.
Dean@910
    70
            /// </summary>
Dean@910
    71
            Success
Dean@910
    72
        }
Dean@910
    73
Dean@1074
    74
        private static bool               eventsAreConnected = false;
Dean@1074
    75
        private static StreamWriter       logWriter          = null;
Dean@1074
    76
        private static object             mutexLogFile       = new object();
Dean@1075
    77
        private static ResourceDictionary _ResourceDict      = null;
Dean@1074
    78
Dean@1074
    79
        /**************************************************************
Dean@1074
    80
         * 
Dean@1074
    81
         * Property Accessors
Dean@1074
    82
         * 
Dean@1074
    83
         *************************************************************/
Dean@1074
    84
Dean@1074
    85
        /// <summary>
Dean@1074
    86
        /// Gets the shared XAML resource dictionary.
Dean@1074
    87
        /// </summary>
Dean@1074
    88
        public static ResourceDictionary ResourceDict
Dean@1074
    89
        {
Dean@1074
    90
            get
Dean@1074
    91
            {
Dean@1075
    92
                if (_ResourceDict == null)
Dean@1074
    93
                {
Dean@1074
    94
                    // Load resource dictionary
Dean@1075
    95
                    _ResourceDict = new ResourceDictionary();
Dean@1075
    96
                    _ResourceDict.Source = new Uri("pack://application:,,,/pEp;component/Resources/Dictionary.xaml", UriKind.RelativeOrAbsolute);
Dean@1074
    97
Dean@1075
    98
                    return (_ResourceDict);
Dean@1074
    99
                }
Dean@1074
   100
                else
Dean@1074
   101
                {
Dean@1075
   102
                    return (_ResourceDict);
Dean@1074
   103
                }
Dean@1074
   104
            }
Dean@1074
   105
        }
Dean@660
   106
Dean@660
   107
        /**************************************************************
Dean@660
   108
         * 
Dean@660
   109
         * Methods
Dean@660
   110
         * 
Dean@660
   111
         *************************************************************/
Dean@660
   112
Dean@660
   113
        /// <summary>
Dean@660
   114
        /// Builds a crash report and displays it to the user before sending. 
Dean@660
   115
        /// </summary>
Dean@660
   116
        /// <param name="exception">The exception to build the report with.</param>
Dean@660
   117
        /// <param name="summaryMessage">The message summarizing where the error occured or what it is.</param>
Dean@660
   118
        /// <param name="allowRestart">True to allow the add-in to attempt to restart itself.</param>
Dean@660
   119
        /// <param name="isEngineCrash">True if the engine generated the error. This will not attempt to get
Dean@660
   120
        /// an engine log as the engine itself is not working (avoids infinite loop).</param>
Dean@660
   121
        public static void StopAndSendCrashReport(Exception exception = null,
Dean@660
   122
                                                  string summaryMessage = null,
Dean@660
   123
                                                  bool allowRestart = true,
Dean@660
   124
                                                  bool isEngineCrash = false)
Dean@660
   125
        {
Dean@660
   126
            bool continueSend = true;
Dean@660
   127
            string engineLog = "";
Dean@960
   128
            string log = "";
Dean@660
   129
            FormCrashReport form;
Dean@1076
   130
            FormControlCrashReport.State stateIn = null;
Dean@660
   131
            DialogResult result;
Dean@660
   132
            Office.COMAddIns comAddIns = null;
Dean@660
   133
            Office.COMAddIn addIn = null;
Dean@660
   134
            PEPMessage newMessage;
Dean@660
   135
            PEPAttachment attachment = null;
Dean@660
   136
Dean@660
   137
            // Show the report before sending
Dean@660
   138
            if (continueSend)
Dean@660
   139
            {
Dean@1076
   140
                stateIn = new FormControlCrashReport.State();
Dean@1090
   141
                stateIn.AddressTo = Globals.ThisAddIn.Settings.CrashReportSendAddress;
Dean@660
   142
                stateIn.AddressFrom = null; // A message can be sent without a "from" address
Dean@660
   143
Dean@960
   144
                // Get log
Dean@960
   145
                try
Dean@960
   146
                {
Dean@960
   147
                    log = string.Join(Environment.NewLine, Globals.ReadLogFile());
Dean@960
   148
                }
Dean@960
   149
                catch
Dean@960
   150
                {
Dean@960
   151
                    log = "";
Dean@960
   152
                }
Dean@960
   153
Dean@660
   154
                // Get engine log
Dean@660
   155
                if (isEngineCrash == false)
Dean@660
   156
                {
Dean@660
   157
                    try
Dean@660
   158
                    {
Dean@660
   159
                        engineLog = ThisAddIn.pEp.get_crashdump_log();
Dean@660
   160
                    }
Dean@660
   161
                    catch (COMException ex)
Dean@660
   162
                    {
Dean@660
   163
                        engineLog = ex.ToString();
Dean@660
   164
                    }
Dean@660
   165
                    catch (Exception ex)
Dean@660
   166
                    {
Dean@660
   167
                        engineLog = ex.ToString();
Dean@660
   168
                    }
Dean@660
   169
                }
Dean@660
   170
Dean@960
   171
                // Double check for null log files
Dean@960
   172
                if (log == null) { log = ""; }
Dean@960
   173
                if (engineLog == null) { engineLog = ""; }
Dean@960
   174
Dean@660
   175
                // Build report header
Dean@660
   176
                stateIn.ReportText = string.Join(Environment.NewLine, new string[]
Dean@660
   177
                    {
Dean@660
   178
                        "Summary---------------------------------------------------",
Dean@660
   179
                        "",
Dean@660
   180
                        "Date: " + System.DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss K"),
Dean@860
   181
                        Globals.GetSystemInfo(),
Dean@660
   182
                        "",
Dean@660
   183
                        (string.IsNullOrWhiteSpace(summaryMessage) ? "no message" : summaryMessage),
Dean@660
   184
                        "",
Dean@660
   185
                        "Exception Details-----------------------------------------",
Dean@660
   186
                        "",
Dean@660
   187
                        (exception == null ? "no exception" : exception.ToString()),
Dean@660
   188
                        "",
Dean@660
   189
                        "p≡p for Outlook Log---------------------------------------",
Dean@660
   190
                        "",
Dean@960
   191
                        log,
Dean@660
   192
                        "",
Dean@660
   193
                        "p≡p Engine Log--------------------------------------------",
Dean@660
   194
                        "",
Dean@660
   195
                        engineLog,
Dean@660
   196
                        "",
Dean@660
   197
                        "END OF REPORT"
Dean@660
   198
                    });
Dean@660
   199
Dean@1090
   200
                if (Globals.ThisAddIn.Settings.IsCrashReportVisible)
Dean@660
   201
                {
Dean@660
   202
                    form = new FormCrashReport();
Dean@1082
   203
                    form.StartPosition = FormStartPosition.CenterParent;
Dean@1076
   204
                    form.FormControl.DisplayState = stateIn;
Dean@1076
   205
                    result = form.ShowDialog();
Dean@660
   206
Dean@660
   207
                    if (result != DialogResult.OK)
Dean@660
   208
                    {
Dean@660
   209
                        continueSend = false;
Dean@660
   210
                    }
Dean@660
   211
                }
Dean@660
   212
            }
Dean@660
   213
Dean@660
   214
            // Build and send message
Dean@660
   215
            if (continueSend)
Dean@660
   216
            {
Dean@660
   217
                newMessage = new PEPMessage();
Dean@660
   218
                newMessage.ShortMsg = "Crash Report";
Dean@660
   219
                newMessage.To.Add(new PEPIdentity(stateIn.AddressTo));
Dean@660
   220
                newMessage.LongMsg = stateIn.ReportText;
Dean@660
   221
                newMessage.Direction = pEpCOMServerAdapterLib._pEp_msg_direction.pEp_dir_outgoing;
Dean@660
   222
Dean@960
   223
                // Add logs as attachments
Dean@960
   224
                if (string.IsNullOrEmpty(log) == false)
Dean@660
   225
                {
Dean@960
   226
                    attachment = new PEPAttachment();
Dean@960
   227
                    attachment.Data = Encoding.UTF8.GetBytes(log);
Dean@960
   228
                    attachment.FileName = "pEp Log.txt";
Dean@960
   229
                    newMessage.Attachments.Add(attachment);
Dean@960
   230
                }
Dean@960
   231
Dean@960
   232
                if (string.IsNullOrEmpty(engineLog) == false)
Dean@960
   233
                {
Dean@960
   234
                    attachment = new PEPAttachment();
Dean@960
   235
                    attachment.Data = Encoding.UTF8.GetBytes(engineLog);
Dean@960
   236
                    attachment.FileName = "pEp Engine Log.txt";
Dean@660
   237
                    newMessage.Attachments.Add(attachment);
Dean@660
   238
                }
Dean@660
   239
Dean@660
   240
                Globals.ThisAddIn.SendWithoutProcessing(newMessage, true);
Dean@660
   241
            }
Dean@660
   242
Dean@1053
   243
            // Stop logging
Dean@1053
   244
            Globals.CloseLogFile();
Dean@1053
   245
Dean@660
   246
            // Locate the Outlook add-in
Dean@660
   247
            comAddIns = Globals.ThisAddIn.Application.COMAddIns;
Dean@660
   248
            foreach (Office.COMAddIn addin in comAddIns)
Dean@660
   249
            {
Dean@1023
   250
                if (string.Equals(addin.Description, Globals.PEP_NAME_ADDIN_DESC, StringComparison.OrdinalIgnoreCase))
Dean@660
   251
                {
Dean@660
   252
                    addIn = addin;
Dean@660
   253
                    break;
Dean@660
   254
                }
Dean@660
   255
            }
Dean@660
   256
Dean@660
   257
            // Shutdown add-in
Dean@660
   258
            if (addIn != null)
Dean@660
   259
            {
Dean@660
   260
                addIn.Connect = false;
Dean@660
   261
            }
Dean@660
   262
Dean@660
   263
            return;
Dean@660
   264
        }
Dean@660
   265
Dean@660
   266
        /// <summary>
Dean@660
   267
        /// Connects or disconnects all global error handling events.
Dean@660
   268
        /// </summary>
Dean@660
   269
        /// <param name="connect">True to connect events, false to disconnect.</param>
Dean@660
   270
        public static void ConnectEvents(bool connect)
Dean@660
   271
        {
Dean@660
   272
            // Connect events only if not already connected
Dean@660
   273
            if ((connect == true) &&
Dean@660
   274
                (eventsAreConnected == false))
Dean@660
   275
            {
Dean@1074
   276
                System.Windows.Forms.Application.ThreadException += Application_UnhandledException;
Dean@660
   277
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
Dean@660
   278
Dean@660
   279
                eventsAreConnected = true;
Dean@660
   280
            }
Dean@660
   281
            // Always attempt to disconnect
Dean@660
   282
            else if (connect == false)
Dean@660
   283
            {
Dean@1074
   284
                System.Windows.Forms.Application.ThreadException -= Application_UnhandledException;
Dean@660
   285
                AppDomain.CurrentDomain.UnhandledException -= CurrentDomain_UnhandledException;
Dean@660
   286
Dean@660
   287
                eventsAreConnected = false;
Dean@660
   288
            }
Dean@660
   289
Dean@660
   290
            return;
Dean@660
   291
        }
Dean@660
   292
Dean@660
   293
        /// <summary>
Dean@660
   294
        /// Adds the given text to the pEp for Outlook log.
Dean@660
   295
        /// </summary>
Dean@660
   296
        /// <param name="text">The text to add to the log.</param>
Dean@759
   297
        public static void Log(string text)
Dean@660
   298
        {
Dean@911
   299
            Globals.WriteToLogFile(text);
Dean@732
   300
            return;
Dean@732
   301
        }
Dean@732
   302
Dean@732
   303
        /// <summary>
Dean@732
   304
        /// Adds the given verbose text to the pEp for Outlook log only
Dean@732
   305
        /// when verbose logging is enabled.
Dean@732
   306
        /// </summary>
Dean@732
   307
        /// <param name="text">The verbose text to add to the lob.</param>
Dean@759
   308
        public static void LogVerbose(string text)
Dean@732
   309
        {
Dean@1090
   310
            if (Globals.ThisAddIn.Settings.IsVerboseLoggingEnabled)
Dean@732
   311
            {
Dean@911
   312
                Globals.WriteToLogFile(System.DateTime.Now.ToString("HH:mm:ss.fff") + " | " + text);
Dean@660
   313
            }
Dean@660
   314
            return;
Dean@660
   315
        }
Dean@660
   316
Dean@660
   317
        /// <summary>
Dean@660
   318
        /// Gets the current system information string.
Dean@660
   319
        /// </summary>
Dean@660
   320
        /// <returns>The system information as a string.</returns>
Dean@660
   321
        public static string GetSystemInfo()
Dean@660
   322
        {
Dean@1081
   323
            string result = "";
Dean@1081
   324
            List<KVPair<string, string>> systemInfo;
Dean@1081
   325
            List<string> list = new List<string>();
Dean@660
   326
Dean@660
   327
            try
Dean@660
   328
            {
Dean@1081
   329
                systemInfo = Globals.GetSystemInfoList();
Dean@1081
   330
Dean@1081
   331
                for (int i = 0; i < systemInfo.Count; i++)
Dean@660
   332
                {
Dean@1081
   333
                    list.Add(systemInfo[i].Key + " " + systemInfo[i].Value);
Dean@1081
   334
                }
Dean@1081
   335
Dean@1081
   336
                result = string.Join(Environment.NewLine, list);
Dean@660
   337
            }
Dean@660
   338
            catch { }
Dean@660
   339
Dean@1081
   340
            return (result);
Dean@1081
   341
        }
Dean@1081
   342
Dean@1081
   343
        /// <summary>
Dean@1081
   344
        /// Gets the current system information as a list of Key-Value pairs.
Dean@1081
   345
        /// </summary>
Dean@1081
   346
        /// <returns>The system information as a list.</returns>
Dean@1081
   347
        public static List<KVPair<string, string>> GetSystemInfoList()
Dean@1081
   348
        {
Dean@1081
   349
            string serial;
Dean@1081
   350
            List<KVPair<string, string>> systemInfo = new List<KVPair<string, string>>();
Dean@1081
   351
            Office.LanguageSettings lang = null;
Dean@1081
   352
Dean@1081
   353
            try
Dean@1081
   354
            {
Dean@1081
   355
                lang = Globals.ThisAddIn.Application.LanguageSettings;
Dean@1081
   356
Dean@1081
   357
                // Use only the first 10-digits which is the serial itself
Dean@1081
   358
                serial = Properties.Settings.Default.Serial;
Dean@1081
   359
                serial = (serial.Length > 10) ? serial.Substring(0, 10) : serial;
Dean@1081
   360
Dean@1081
   361
                systemInfo.Add(new KVPair<string, string>("Serial:", (Globals.RELEASE_MODE == Globals.ReleaseMode.Reader ? "Reader" : serial)));
Dean@1081
   362
                systemInfo.Add(new KVPair<string, string>("Assembly Version:", Assembly.GetExecutingAssembly().GetName().Version.ToString()));
Dean@1081
   363
                systemInfo.Add(new KVPair<string, string>("Outlook Version:", Globals.ThisAddIn.Application.Version));
Dean@1081
   364
                systemInfo.Add(new KVPair<string, string>("OS Version:", Environment.OSVersion.VersionString));
Dean@1081
   365
                systemInfo.Add(new KVPair<string, string>("Language Install:", ((Office.MsoLanguageID)lang.LanguageID[Office.MsoAppLanguageID.msoLanguageIDInstall]).ToString()));
Dean@1081
   366
                systemInfo.Add(new KVPair<string, string>("Language UI:", ((Office.MsoLanguageID)lang.LanguageID[Office.MsoAppLanguageID.msoLanguageIDUI]).ToString()));
Dean@1081
   367
            }
Dean@1081
   368
            catch (Exception ex)
Dean@1081
   369
            {
Dean@1081
   370
                systemInfo.Add(new KVPair<string, string>("Exception:", ex.ToString()));
Dean@1081
   371
            }
Dean@1081
   372
            finally
Dean@1081
   373
            {
Dean@1081
   374
                if (lang != null)
Dean@1081
   375
                {
Dean@1081
   376
                    Marshal.ReleaseComObject(lang);
Dean@1081
   377
                    lang = null;
Dean@1081
   378
                }
Dean@1081
   379
            }
Dean@1081
   380
Dean@660
   381
            return (systemInfo);
Dean@660
   382
        }
Dean@660
   383
Dean@660
   384
        /// <summary>
Dean@911
   385
        /// Writes the given text to the log file.
Dean@660
   386
        /// </summary>
Dean@911
   387
        /// <param name="text">The text to write to the log file.</param>
Dean@911
   388
        private static void WriteToLogFile(string text)
Dean@660
   389
        {
Dean@911
   390
            try
Dean@911
   391
            {
Dean@911
   392
                if (text != null)
Dean@911
   393
                {
Dean@923
   394
                    lock (mutexLogFile)
Dean@911
   395
                    {
Dean@923
   396
                        if (Globals.logWriter == null)
Dean@923
   397
                        {
Dean@923
   398
                            // Open the file
Dean@926
   399
                            Globals.logWriter = File.AppendText(Globals.GetLogFilePath());
Dean@923
   400
                        }
Dean@923
   401
Dean@923
   402
                        Globals.logWriter.WriteLine(text);
Dean@911
   403
                    }
Dean@911
   404
                }
Dean@911
   405
            }
Dean@911
   406
            catch { }
Dean@911
   407
Dean@911
   408
            return;
Dean@911
   409
        }
Dean@911
   410
Dean@911
   411
        /// <summary>
Dean@911
   412
        /// Reads all lines of text from the log file.
Dean@911
   413
        /// This will never return null.
Dean@911
   414
        /// </summary>
Dean@911
   415
        /// <returns>The lines of text in the log file.</returns>
Dean@911
   416
        public static string ReadLogFile()
Dean@911
   417
        {
Dean@911
   418
            string log = "";
Dean@911
   419
            string path;
Dean@911
   420
            StreamReader logReader;
Dean@911
   421
Dean@911
   422
            try
Dean@660
   423
            {
Dean@911
   424
                Globals.CloseLogFile();
Dean@911
   425
Dean@923
   426
                lock (mutexLogFile)
Dean@911
   427
                {
Dean@926
   428
                    path = Globals.GetLogFilePath();
Dean@923
   429
                    if (File.Exists(path))
Dean@923
   430
                    {
Dean@923
   431
                        logReader = new StreamReader(path);
Dean@923
   432
                        log = logReader.ReadToEnd();
Dean@911
   433
Dean@923
   434
                        logReader.Close();
Dean@923
   435
                        logReader.Dispose();
Dean@923
   436
                    }
Dean@911
   437
                }
Dean@911
   438
Dean@911
   439
                // Never allow null
Dean@911
   440
                if (log == null)
Dean@911
   441
                {
Dean@911
   442
                    log = "";
Dean@911
   443
                }
Dean@660
   444
            }
Dean@911
   445
            catch { }
Dean@660
   446
Dean@911
   447
            return (log);
Dean@911
   448
        }
Dean@911
   449
Dean@911
   450
        /// <summary>
Dean@911
   451
        /// Closes and releases any open log file writer.
Dean@911
   452
        /// </summary>
Dean@911
   453
        public static void CloseLogFile()
Dean@911
   454
        {
Dean@911
   455
            try
Dean@911
   456
            {
Dean@923
   457
                lock (mutexLogFile)
Dean@911
   458
                {
Dean@923
   459
                    if (Globals.logWriter != null)
Dean@923
   460
                    {
Dean@923
   461
                        Globals.logWriter.Flush();
Dean@923
   462
                        Globals.logWriter.Close();
Dean@923
   463
                        Globals.logWriter.Dispose();
Dean@923
   464
                        Globals.logWriter = null;
Dean@923
   465
                    }
Dean@911
   466
                }
Dean@911
   467
            }
Dean@911
   468
            catch { }
Dean@911
   469
Dean@911
   470
            return;
Dean@911
   471
        }
Dean@911
   472
Dean@911
   473
        /// <summary>
Dean@911
   474
        /// Clears all logged text by deleting the file.
Dean@911
   475
        /// </summary>
Dean@911
   476
        public static void ClearLogFile()
Dean@911
   477
        {
Dean@911
   478
            string path;
Dean@911
   479
Dean@911
   480
            try
Dean@911
   481
            {
Dean@911
   482
                Globals.CloseLogFile();
Dean@911
   483
Dean@923
   484
                lock (mutexLogFile)
Dean@911
   485
                {
Dean@926
   486
                    path = Globals.GetLogFilePath();
Dean@923
   487
                    if (File.Exists(path))
Dean@923
   488
                    {
Dean@923
   489
                        File.Delete(path);
Dean@923
   490
                    }
Dean@911
   491
                }
Dean@911
   492
            }
Dean@911
   493
            catch { }
Dean@911
   494
Dean@911
   495
            return;
Dean@660
   496
        }
Dean@660
   497
Dean@926
   498
        /// <summary>
Dean@926
   499
        /// Gets the path of the log file.
Dean@926
   500
        /// </summary>
Dean@926
   501
        /// <returns>The path of the log file.</returns>
Dean@926
   502
        private static string GetLogFilePath()
Dean@926
   503
        {
Dean@926
   504
            return (Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "pEp", LOG_FILE_NAME));
Dean@926
   505
        }
Dean@926
   506
Dean@660
   507
        /**************************************************************
Dean@660
   508
         * 
Dean@660
   509
         * Event Handling
Dean@660
   510
         * 
Dean@660
   511
         *************************************************************/
Dean@660
   512
Dean@660
   513
        /// <summary>
Dean@660
   514
        /// Event handler for when an unhandled error occurs within the current application.
Dean@660
   515
        /// </summary>
Dean@660
   516
        private static void Application_UnhandledException(object sender, ThreadExceptionEventArgs e)
Dean@660
   517
        {
Dean@860
   518
            Globals.StopAndSendCrashReport(e.Exception);
Dean@660
   519
            return;
Dean@660
   520
        }
Dean@660
   521
Dean@660
   522
        /// <summary>
Dean@660
   523
        /// Event handler for when an unhandled error occurs within the current domain.
Dean@660
   524
        /// </summary>
Dean@660
   525
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
Dean@660
   526
        {
Dean@860
   527
            Globals.StopAndSendCrashReport();
Dean@660
   528
            return;
Dean@660
   529
        }
Dean@660
   530
Dean@606
   531
    }
Dean@606
   532
}