Exemplo n.º 1
0
        private async void InitPluginCore(TabPage pluginScreenSpace, Label pluginStatusText)
        {
            pluginStatusText.Text = "Initializing CEF...";

            if (await CefInstaller.EnsureCef(GetCefPath()))
            {
                pluginMain.InitPlugin(pluginScreenSpace, pluginStatusText);
            }
        }
Exemplo n.º 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));
            }
        }
Exemplo n.º 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;
                }
            }
        }
Exemplo n.º 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));
     }
 }