Пример #1
0
        private async void InitPluginCore(TabPage pluginScreenSpace, Label pluginStatusText)
        {
            pluginStatusText.Text = "Initializing CEF...";

            if (await CefInstaller.EnsureCef(GetCefPath()))
            {
                pluginMain.InitPlugin(pluginScreenSpace, pluginStatusText);
            }
        }
Пример #2
0
        public async Task FinishInit(TinyIoCContainer container)
        {
            if (await CefInstaller.EnsureCef(GetCefPath()))
            {
                // Finally, load the html renderer. We load it here since HtmlRenderer depends on CEF which we can't load these before
                // the CefInstaller is done.
                if (SanityChecker.LoadSaneAssembly("HtmlRenderer"))
                {
                    // Since this is an async method, we could have switched threds. Make sure InitPlugin() runs on the ACT main thread.
                    ActGlobals.oFormActMain.Invoke((Action)(() =>
                    {
                        try {
                            pluginMain.InitPlugin(pluginScreenSpace, pluginStatusText);
                            initFailed = false;
                        }
                        catch (Exception ex)
                        {
                            if (ex is TypeLoadException)
                            {
                                if (ex.Message.Contains("CefSharp"))
                                {
                                    //Cef load failed, try to repair cef
                                    Task.Run(() => CefInstaller.InstallCef(GetCefPath())).Wait();
                                    try
                                    {
                                        pluginMain.InitPlugin(pluginScreenSpace, pluginStatusText);
                                    }
                                    catch (Exception ex2)
                                    {
                                        //Still failed, showing message to users
                                        ex = ex2;
                                    }
                                }
                            }
                            // TODO: Add a log box to CefMissingTab and while CEF missing is the most likely
                            // cause for an exception here, it is not necessarily the case.
                            // logger.Log(LogLevel.Error, "Failed to init plugin: " + ex.ToString());

                            initFailed = true;

                            MessageBox.Show("加载ngld悬浮窗插件失败: " + ex.ToString(), "ngld悬浮窗插件错误");
                            pluginScreenSpace.Controls.Add(new CefMissingTab(GetCefPath(), this, container));
                        }
                    }));
                }
                else
                {
                    pluginStatusText.Text = Resources.CoreOrHtmlRendererInsane;
                }
            }
            else
            {
                pluginScreenSpace.Controls.Add(new CefMissingTab(GetCefPath(), this, container));
            }
        }
Пример #3
0
        private async void Initialize(TabPage pluginScreenSpace, Label pluginStatusText)
        {
            pluginStatusText.Text = Resources.InitRuntime;

            Registry.Init();
            logger = new Logger();
            asmResolver.ExceptionOccured += (o, e) => logger.Log(LogLevel.Error, Resources.AssemblyResolverError, e.Exception);
            asmResolver.AssemblyLoaded   += (o, e) => logger.Log(LogLevel.Debug, Resources.AssemblyResolverLoaded, e.LoadedAssembly.FullName);
            pluginMain = new PluginMain(pluginDirectory, logger);

            pluginStatusText.Text = Resources.InitCef;

            try
            {
                CurlWrapper.Init(pluginDirectory);
            } catch (Exception ex)
            {
                logger.Log(LogLevel.Error, ex.ToString());
            }

            if (await CefInstaller.EnsureCef(GetCefPath()))
            {
                // Finally, load the html renderer. We load it here since HtmlRenderer depends on CEF which we can't load these before
                // the CefInstaller is done.
                if (SanityChecker.LoadSaneAssembly("HtmlRenderer"))
                {
                    // Since this is an async method, we could have switched threds. Make sure InitPlugin() runs on the ACT main thread.
                    ActGlobals.oFormActMain.Invoke((Action)(() =>
                    {
                        pluginMain.InitPlugin(pluginScreenSpace, pluginStatusText);
                    }));
                }
                else
                {
                    pluginStatusText.Text = Resources.CoreOrHtmlRendererInsane;
                }
            }
        }
Пример #4
0
 public async Task FinishInit()
 {
     if (await CefInstaller.EnsureCef(GetCefPath()))
     {
         // Finally, load the html renderer. We load it here since HtmlRenderer depends on CEF which we can't load these before
         // the CefInstaller is done.
         if (SanityChecker.LoadSaneAssembly("HtmlRenderer"))
         {
             // Since this is an async method, we could have switched threds. Make sure InitPlugin() runs on the ACT main thread.
             ActGlobals.oFormActMain.Invoke((Action)(() =>
             {
                 pluginMain.InitPlugin(pluginScreenSpace, pluginStatusText);
             }));
         }
         else
         {
             pluginStatusText.Text = Resources.CoreOrHtmlRendererInsane;
         }
     }
     else
     {
         pluginScreenSpace.Controls.Add(new CefMissingTab(GetCefPath(), this));
     }
 }
Пример #5
0
        public void Initialize(ApplicationStartupHandler handler, IDIContext container)
        {
            var uiSynchronizer = container.Resolve <IUISynchronizer>();
            ProgressDisplayForm progressDisplay = null;

            var cefFolder     = Path.Combine(GobchatContext.ApplicationLocation, "libs", "cef");
            var patcherFolder = Path.Combine(GobchatContext.ApplicationLocation, "patch");
            var installer     = new CefInstaller(cefFolder, patcherFolder);

            if (installer.IsCefAvailable())
            {
                return;
            }

            //TODO message dialog
            {
                logger.Info("CEF missing");
                var dialogResult = MessageBox.Show(
                    Resources.Module_Cef_Dialog_CefMissing_Text,
                    "Gobchat",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Warning
                    );

                if (dialogResult != DialogResult.Yes)
                {
                    handler.StopStartup = true;
                    return;
                }
            }

            try
            {
                uiSynchronizer.RunSync(() =>
                {
                    progressDisplay = new ProgressDisplayForm();
                    progressDisplay.Show();
                });

                using (var progressMonitor = new ProgressMonitorAdapter(progressDisplay))
                {
                    try
                    {
                        installer.DownloadCef(progressMonitor);
                    }
                    catch (Exception e)
                    {
                        logger.Log(LogLevel.Fatal, e, () => "CEF download failed");
                        throw;
                    }
                    try
                    {
                        installer.ExtractCef(progressMonitor);
                    }
                    catch (Exception e)
                    {
                        logger.Log(LogLevel.Fatal, e, () => "CEF extraction failed");
                        throw;
                    }
                }
            }
            catch (Exception e)
            {
                logger.Fatal("CEF installation failed");
                logger.Fatal(e);

                MessageBox.Show(
                    StringFormat.Format(Resources.Module_Cef_Dialog_InstallFailed_Text, e.Message),
                    Resources.Module_Cef_Dialog_InstallFailed_Title,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );

                handler.StopStartup = true;
            }
            finally
            {
                uiSynchronizer.RunSync(() => progressDisplay.Dispose());
            }
        }