/// <summary>
 /// Method to wrap all execution exceptions
 /// </summary>
 /// <param name="environment">Environment to execute</param>
 private static RuntimeErrorCode RunEnvironment(IRunMode environment)
 {
     try
     {
         return(environment.Run());
     }
     catch (Exception ex)
     {
         CrashHandler.HandleCrash(null, new UnhandledExceptionEventArgs(ex, true));
         return(RuntimeErrorCode.Error);
     }
 }
示例#2
0
        public static void Main(string[] args)
        {
            Application app = new Application(Eto.Platforms.Wpf);

            ChapterManager    chapterManager    = null;
            string            startChapter      = null;
            KanjiInputManager kanjiInputManager = null;
            TranslatorThread  translatorThread  = null;
            MiharuMainWindow  mainWindow        = null;

            try {
                Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory.ToString());

                if (Init.CheckForTesseract())
                {
                    if (Init.CheckForGecko())
                    {
                        translatorThread = TranslatorThread.StartThread();
                    }

                    startChapter = Init.CheckCrash();
                    if (startChapter == null && args.Length > 0 && File.Exists(args [0]))
                    {
                        startChapter = args[0];
                    }

                    kanjiInputManager = new KanjiInputManager();

                    chapterManager = new ChapterManager(kanjiInputManager, translatorThread);

                    mainWindow = new MiharuMainWindow(chapterManager, startChapter);

                    app.Run(mainWindow);
                }
            }
            catch (Exception e) {
                CrashHandler.HandleCrash(chapterManager, e);
                FileInfo crashFileInfo = new FileInfo(Logger.CurrentCrashLog);

                MessageBox.Show("There was a fatal error. Details can be found in the generated crash log:" + Environment.NewLine +
                                crashFileInfo.FullName,
                                "Fatal Error",
                                MessageBoxButtons.OK,
                                MessageBoxType.Error,
                                MessageBoxDefaultButton.OK);
            }
            finally {
                mainWindow?.Close();
                translatorThread?.FinalizeThread();
            }
        }
        /// <summary>
        /// Selects and loads the environment by arguments of the heart of gold
        /// </summary>
        private EnvironmentLoadResult LoadEnvironment(out IRunMode runMode)
        {
            var runModes   = _container.ResolveAll <IRunMode>();
            var runModeMap = (from existing in runModes
                              let runModeAttr = existing.GetType().GetCustomAttribute <RunModeAttribute>()
                                                where runModeAttr != null
                                                select new EnvironmentInfo
            {
                RunMode = existing,
                OptionType = runModeAttr.OptionType
            }).ToArray();

            var optionTypes = runModeMap.Select(r => r.OptionType).ToArray();

            EnvironmentInfo env        = null;
            var             loadResult = EnvironmentLoadResult.Error;

            try
            {
                Parser.Default.ParseArguments(_args, optionTypes)
                .WithParsed(delegate(object parsed)
                {
                    // Select run mode
                    env         = runModeMap.First(m => m.OptionType == parsed.GetType());
                    env.Options = (RuntimeOptions)parsed;
                    loadResult  = EnvironmentLoadResult.Success;
                })
                .WithNotParsed(errors => loadResult = EvaluateParserErrors(errors));

                if (loadResult == EnvironmentLoadResult.Success)
                {
                    SetupEnvironment(env);
                }
            }
            catch (Exception ex)
            {
                loadResult = EnvironmentLoadResult.Error;
                CrashHandler.HandleCrash(null, new UnhandledExceptionEventArgs(ex, true));
            }
            finally
            {
                runMode = env?.RunMode;
            }

            return(loadResult);
        }
示例#4
0
 /// <inheritdoc />
 public void HandleDispatcherException(object sender, DispatcherUnhandledExceptionEventArgs args)
 {
     Logger.LogException(LogLevel.Error, args.Exception, "There is an error on the UI thread! Check it!");
     CrashHandler.HandleCrash(sender, new UnhandledExceptionEventArgs(args.Exception, false));
 }
示例#5
0
        public static void Main(string [] args)
        {
            ChapterManager    chapterManager    = null;
            KanjiInputManager kanjiInputManager = null;
            TranslatorThread  translatorThread  = null;
            MiharuMainWindow  mainWindow        = null;

            try {
                App application = new App();


                /*MainWindow mw = new MainWindow();
                 * application.Run(mw);*/


                //Initialize stuff
                Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory.ToString());
                if (CheckForTesseract())
                {
                    translatorThread = TranslatorThread.StartThread();

                    string startChapter = null;
                    startChapter = CheckCrash();
                    if (startChapter == null && args.Length > 0 && File.Exists(args [0]))
                    {
                        startChapter = args[0];
                    }

                    /*Logger.Log("Start Chapter: " + startChapter);
                     * Logger.Log("Args Length: " + args.Length);
                     * for (int i = 0; i < args.Length; i++)
                     *      Logger.Log("\t" + args[i]);*/

                    kanjiInputManager = new KanjiInputManager();

                    chapterManager = new ChapterManager(kanjiInputManager, translatorThread);

                    mainWindow = new MiharuMainWindow(chapterManager, startChapter);

                    PageControl pageControl = new PageControl(chapterManager.PageManager);
                    mainWindow.PageControlArea.Child = pageControl;

                    TextEntryView textEntryView = new TextEntryView(chapterManager.PageManager.TextEntryManager, kanjiInputManager);
                    mainWindow.TextEntryArea.Child = textEntryView;

                    application.Run(mainWindow);
                }
            }
            catch (Exception e) {
                CrashHandler.HandleCrash(chapterManager, e);
                FileInfo crashFileInfo = new FileInfo(Logger.CurrentCrashLog);

                TaskDialog dialog = new TaskDialog();
                dialog.WindowTitle     = "Fatal Error";
                dialog.MainIcon        = TaskDialogIcon.Error;
                dialog.MainInstruction = "There was a fatal error. Details can be found in the generated crash log:";
                dialog.Content         = crashFileInfo.FullName;

                TaskDialogButton okButton = new TaskDialogButton("Ok");
                okButton.ButtonType = ButtonType.Ok;
                dialog.Buttons.Add(okButton);
                TaskDialogButton button = dialog.ShowDialog();
            }
            finally {
                mainWindow?.Close();
                translatorThread?.FinalizeThread();
            }
        }