public static bool PrepareRuntime()
        {
            if (!System.IO.Directory.Exists(CommonRuntimeDir))
            {
                System.IO.Directory.CreateDirectory(CommonRuntimeDir);
            }

            if (IsLocalRuntimeExisits() == false)
            {
                if (IsRuntimeExists() == false)
                {
                    var downloadForm = new RuntimeDownloadForm(CommonRuntimeDir, CURRENT_CEF_VERSION, FrameworkDownloadUrl, PlatformArch, EnableFlashSupport);

                    if (downloadForm.ShowDialog() != DialogResult.OK || !IsRuntimeExists())
                    {
                        return(false);
                    }
                }
            }
            CfxRuntime.LibCefDirPath = FrameworkDir;


            Application.ApplicationExit += (sender, args) =>
            {
                foreach (var handle in SchemeHandlerGCHandles)
                {
                    handle.Free();
                }

                CfxRuntime.Shutdown();
            };

            return(true);
        }
Exemple #2
0
        public static bool InitializeChromium(Action <OnBeforeCfxInitializeEventArgs> BeforeChromiumInitialize = null, Action <CfxOnBeforeCommandLineProcessingEventArgs> BeforeCommandLineProcessing = null)
        {
            if (!System.IO.Directory.Exists(RuntimeDir))
            {
                System.IO.Directory.CreateDirectory(RuntimeDir);
            }

            if (IsRuntimeExists() == false)
            {
                var downloadForm = new RuntimeDownloadForm(RuntimeDir, FrameworkDownloadUrl, PlatformArch, EnableFlashSupport);

                if (downloadForm.ShowDialog() != DialogResult.OK || !IsRuntimeExists())
                {
                    return(false);
                }
            }

            CfxRuntime.LibCefDirPath = FrameworkDir;

            Application.ApplicationExit += (sender, args) =>
            {
                foreach (var handle in SchemeHandlerGCHandles)
                {
                    handle.Free();
                }

                CfxRuntime.Shutdown();
            };


            OnBeforeCfxInitialize += (args) =>
            {
                var cachePath = System.IO.Path.Combine(RuntimeDir, Application.ProductName, "Cache");
                if (!System.IO.Directory.Exists(cachePath))
                {
                    System.IO.Directory.CreateDirectory(cachePath);
                }

                args.Settings.LocalesDirPath   = LocalesDir;
                args.Settings.ResourcesDirPath = 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 (EnableFlashSupport)
                {
                    SetFlashSupport(args);
                }

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



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

            try
            {
                Initialize();

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



            return(false);
        }