示例#1
0
        public static bool InitializeChromium(Action <OnBeforeCfxInitializeEventArgs> BeforeChromiumInitialize = null, Action <CfxOnBeforeCommandLineProcessingEventArgs> BeforeCommandLineProcessing = null)
        {
            if (ChromiumStartupSettings.PrepareRuntime())
            {
                OnBeforeCfxInitialize += (args) =>
                {
                    var cachePath = System.IO.Path.Combine(ChromiumStartupSettings.ApplicationDataDir, Application.ProductName, "Cache");
                    if (!System.IO.Directory.Exists(cachePath))
                    {
                        System.IO.Directory.CreateDirectory(cachePath);
                    }

                    args.Settings.LocalesDirPath   = ChromiumStartupSettings.LocalesDir;
                    args.Settings.ResourcesDirPath = ChromiumStartupSettings.ResourcesDir;
                    args.Settings.Locale           = "zh-CN";
                    args.Settings.CachePath        = cachePath;
                    args.Settings.LogSeverity      = CfxLogSeverity.Disable;


                    BeforeChromiumInitialize?.Invoke(args);
                };

                OnBeforeCommandLineProcessing += (args) =>
                {
                    Console.WriteLine("处理命令行参数。。。");


                    BeforeCommandLineProcessing?.Invoke(args);



                    if (ChromiumStartupSettings.EnableFlashSupport)
                    {
                        SetFlashSupport(args);
                    }

                    Console.WriteLine(args.CommandLine.CommandLineString);
                };



                OnRegisterCustomSchemes += args =>
                {
                    args.Registrar.AddCustomScheme("embedded", false, false, false);
                };


                try
                {
                    Initialize();


                    RegisterLocalScheme();
                    return(true);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);

                    Console.WriteLine(ex.InnerException);
                    MessageBox.Show(string.Format("初始化系统失败。\r\n{0}", ex.Message), "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            return(false);
        }
示例#2
0
        public static bool InitializeChromium()
        {
            if (ChromiumStartupSettings.PrepareRuntime())
            {
                var exitCode = CfxRuntime.ExecuteProcess(null);
                if (exitCode >= 0)
                {
                    Environment.Exit(exitCode);
                }

                var settings = new CfxSettings();
                settings.WindowlessRenderingEnabled = true;
                settings.NoSandbox = true;

                var cachePath = System.IO.Path.Combine(ChromiumStartupSettings.ApplicationDataDir, Application.ProductName, "Cache");
                if (!System.IO.Directory.Exists(cachePath))
                {
                    System.IO.Directory.CreateDirectory(cachePath);
                }

                settings.LocalesDirPath   = ChromiumStartupSettings.LocalesDir;
                settings.ResourcesDirPath = ChromiumStartupSettings.ResourcesDir;
                settings.Locale           = "zh-CN";
                settings.CachePath        = cachePath;
                settings.LogSeverity      = CfxLogSeverity.Disable;



                OnRegisterCustomSchemes += args =>
                {
                    args.Registrar.AddCustomScheme("embedded", false, false, false);
                };



                try
                {
                    var app = new CfxApp();
                    app.OnBeforeCommandLineProcessing += (s, e) =>
                    {
                        // optimizations following recommendations from issue #84
                        e.CommandLine.AppendSwitch("disable-gpu");
                        e.CommandLine.AppendSwitch("disable-gpu-compositing");
                        e.CommandLine.AppendSwitch("disable-gpu-vsync");
                    };

                    if (!CfxRuntime.Initialize(settings, app))
                    {
                        //Environment.Exit(-1);
                        return(false);
                    }

                    Application.Idle += (sender, e) =>
                    {
                        CfxRuntime.DoMessageLoopWork();
                    };



                    return(true);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);

                    Console.WriteLine(ex.InnerException);
                    MessageBox.Show(string.Format("初始化系统失败。\r\n{0}", ex.Message), "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            return(false);
        }