Пример #1
0
        static void Main(string[] args)
        {
            // Make sure that settings aren't corrupted, and fix them.
            try {
                string uiLanguage = Settings.Default.UILanguage;
            }
            catch (ConfigurationErrorsException ex) { //(requires System.Configuration)
                // Once the configuration system is corrupt, there doesn't appear a way to
                // fix it (Settings.Default.Reload() doesn't work, even though you would
                // think it would. So restarting the application appears to be the best way.
                // We inform the user in case deleting doesn't work they can try to delete the file
                // themselves. This is so rare it isn't worth localizing the message.

                string filename = ((ConfigurationErrorsException)ex.InnerException).Filename;
                MessageBox.Show(string.Format("The configuration file '{0}' is corrupted. Purple Pen will delete this file and restart.", filename),
                                "Corrupt Configuration File",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                File.Delete(filename);
                System.Diagnostics.Process.Start(Application.ExecutablePath); // start new instance of application
                return;                                                       // exit current instance of application.
            }

            // Enable crash reporting.
            Application.ThreadException += (sender, e) => SendCrashReport(e.Exception);
            AppDomain.CurrentDomain.UnhandledException += (sender, e) => {
                SendCrashReport((Exception)e.ExceptionObject);
                Environment.Exit(0);
            };

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);


            InitUILanguage();
            InitClientId();
            FontDesc.InitializeFonts();

            if (args.Length > 0 && LoadCommandLineFile(args[0]))
            {
                // We successfully loaded a file from the command line.
                // Nothing more to do here.
            }
            else
            {
                // No command line args. Show initial screen to load/create an event.
                new InitialScreen().Show();
            }

            Application.Run();
        }