private static void Application_ApplicationExit(object sender, EventArgs e)
        {
            //to kill subprocess in windows . because on windows when application exited,will left a subprocess can not auto shutdown.

            if (CfxRuntime.PlatformOS == CfxPlatformOS.Windows)
            {
                var current = Process.GetCurrentProcess();

                var processName = current.ProcessName;

                var sublist = Process.GetProcessesByName(processName);

                var realSublist = sublist.Where(p => p.Id != current.Id).ToList();

                foreach (var process in realSublist)
                {
                    try
                    {
                        process.Kill();
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
            else
            {
                CfxRuntime.QuitMessageLoop();
            }

            CfxRuntime.Shutdown();
        }
        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);
        }
        public static void Main()
        {
            var assemblyDir = System.IO.Path.GetDirectoryName(new System.Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath);

            Environment.CurrentDirectory = System.IO.Path.Combine(assemblyDir, @"..\..\");

            if (CfxRuntime.PlatformArch == CfxPlatformArch.x64)
            {
                CfxRuntime.LibCefDirPath = @"cef\Release64";
            }
            else
            {
                CfxRuntime.LibCefDirPath = @"cef\Release";
            }

            Chromium.WebBrowser.ChromiumWebBrowser.OnBeforeCfxInitialize += ChromiumWebBrowser_OnBeforeCfxInitialize;
            ChromiumWebBrowser.OnBeforeCommandLineProcessing             += ChromiumWebBrowser_OnBeforeCommandLineProcessing;
            Chromium.WebBrowser.ChromiumWebBrowser.Initialize();

            //Walkthrough01.Main();
            //return;

            Application.EnableVisualStyles();
            var f = new BrowserForm();

            f.Show();
            Application.Run(f);

            CfxRuntime.Shutdown();
        }
Beispiel #4
0
 private static void OnApplicationExit(object sender, EventArgs e)
 {
     foreach (var handle in SchemeHandlerGCHandles)
     {
         handle.Free();
     }
     CfxRuntime.Shutdown();
 }
Beispiel #5
0
        static void Main()
        {
            string nowDir = AppDomain.CurrentDomain.BaseDirectory;

            if (!System.IO.File.Exists(System.IO.Path.Combine(nowDir, "libcfx.dll")))
            {
                if (MessageBox.Show("并没有在软件目录下找到基本运行库\n您应该在获得这款软件的时候同时获得关于本软件依赖库的信息\n如果没有,您可以到本软件的Github Wiki获得帮助\n是否现在前往?",
                                    "未能找到依赖库", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    System.Diagnostics.Process.Start("https://github.com/huix-oldcat/ArkDesktop/wiki");
                }
                return;
            }
            CfxRuntime.LibCefDirPath = System.IO.Path.Combine(nowDir, "cef");
            CfxRuntime.LibCfxDirPath = nowDir;
            int exitCode = CfxRuntime.ExecuteProcess(null);

            if (exitCode >= 0)
            {
                Environment.Exit(exitCode);
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            using (var settings = new CfxSettings())
            {
                settings.MultiThreadedMessageLoop   = true;
                settings.WindowlessRenderingEnabled = true;
                settings.NoSandbox        = true;
                settings.ResourcesDirPath = System.IO.Path.Combine(nowDir, "cef", "Resources");
                settings.LocalesDirPath   = System.IO.Path.Combine(nowDir, "cef", "Resources", "locales");

                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);
                }
            }

            Manager.layeredWindow = new LayeredWindow();
            Manager.control       = new ArkDesktopBrowserControl();
            Manager.Init();

            Application.Run(Manager.layeredWindow);

            // CfxRuntime.QuitMessageLoop();
            CfxRuntime.Shutdown();
        }
Beispiel #6
0
        static void Main()
        {
            ChromiumWebBrowser.Initialize();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MyDemo());

            CfxRuntime.Shutdown();
        }
        private void Init()
        {
            if (_Runing)
            {
                return;
            }

            _Runing = true;
            _WpfThread.Dispatcher.Invoke(Initialize);
            _WpfThread.OnThreadEnded += (o, e) => CfxRuntime.Shutdown();
        }
Beispiel #8
0
        public static void Main()
        {
            ChromiumWebBrowser.OnBeforeCfxInitialize         += ChromiumWebBrowser_OnBeforeCfxInitialize;
            ChromiumWebBrowser.OnBeforeCommandLineProcessing += ChromiumWebBrowser_OnBeforeCommandLineProcessing;
            ChromiumWebBrowser.Initialize();

            Application.EnableVisualStyles();
            var winform = new BrowserForm();

            winform.Show();
            Application.Run(winform);

            CfxRuntime.Shutdown();
        }
Beispiel #9
0
        static void Main()
        {
            string nowDir = Environment.CurrentDirectory;

            CfxRuntime.LibCefDirPath = System.IO.Path.Combine(nowDir, "cef");
            CfxRuntime.LibCfxDirPath = nowDir;
            int exitCode = CfxRuntime.ExecuteProcess(null);

            if (exitCode >= 0)
            {
                Environment.Exit(exitCode);
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            using (var settings = new CfxSettings())
            {
                settings.MultiThreadedMessageLoop   = true;
                settings.WindowlessRenderingEnabled = true;
                settings.NoSandbox        = true;
                settings.ResourcesDirPath = System.IO.Path.Combine(nowDir, "cef", "Resources");
                settings.LocalesDirPath   = System.IO.Path.Combine(nowDir, "cef", "Resources", "locales");

                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);
                }
            }

            Manager.layeredWindow = new LayeredWindow();
            Manager.control       = new ArkDesktopBrowserControl();
            Manager.Init();

            Application.Run(Manager.layeredWindow);

            // CfxRuntime.QuitMessageLoop();
            CfxRuntime.Shutdown();
        }
Beispiel #10
0
        public static void Main()
        {
            //CfxRuntime.LoadLibraries(@"C:\path\to\cef\directory");
            //ChromiumWebBrowser.OnBeforeCfxInitialize += ChromiumWebBrowser_OnBeforeCfxInitialize;
            //ChromiumWebBrowser.Initialize();

            Form f = new Form();

            f.Size = new Size(800, 600);

            ChromiumWebBrowser wb = new ChromiumWebBrowser();

            wb.Dock = DockStyle.Fill;

            wb.Parent = f;

            wb.GlobalObject.AddFunction("HelloApp").Execute    += HelloApp_Execute;
            wb.GlobalObject.AddFunction("DoSomething").Execute += DoSomething_Execute;


            //wb.ExecuteJavascript("var x = HelloApp();");

            var html = " <button onclick='var x = HelloApp(12345); document.getElementById(\"demo\").innerHTML =x;'>";

            html += "Trigger HelloApp(12345) callback function.</button><br><br><img src='http://localresource/image'>";
            html += "<br><p>Callback returned: <span id='demo'></span></p>";
            html += "<br><br><button onclick='DoSomething();'>Do something</button>";

            var bm = new System.Drawing.Bitmap(100, 100);

            using (var g = System.Drawing.Graphics.FromImage(bm)) {
                g.DrawLine(System.Drawing.Pens.Black, 0, 0, 100, 100);
            }

            wb.SetWebResource("http://localresource/text.html", new Chromium.WebBrowser.WebResource(html));
            wb.SetWebResource("http://localresource/image", new Chromium.WebBrowser.WebResource(bm));


            f.Show();
            wb.LoadUrl("http://localresource/text.html");
            Application.Run(f);

            CfxRuntime.Shutdown();
        }
        public static bool PrepareRuntime()
        {
            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;
                //	}

                //}

                MessageBox.Show($"CEF Runtime is not found.\r\nCEF Runtime should be in\r\n\"{System.IO.Path.Combine(Application.StartupPath, "fx\\")}\"", "CEF Runtime initialize faild", MessageBoxButtons.OK, MessageBoxIcon.Error);


                return(false);
            }


            CfxRuntime.LibCefDirPath = FrameworkDir;


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

                CfxRuntime.Shutdown();
            };

            return(true);
        }
Beispiel #12
0
        static void Main(string[] args)
        {
            Environment.CurrentDirectory = FileHelper.AppPath;

            CfxRuntime.LibCefDirPath = Path.GetFullPath($@"{_basePath}\{CfxRuntime.PlatformArch.ToString()}");
            CfxRuntime.LibCfxDirPath = Path.GetFullPath($"{_basePath}");

            if (!Directory.Exists(CfxRuntime.LibCefDirPath))
            {
                throw new DirectoryNotFoundException("Sorry! The CEF configuration directory was not found. Please confirm and try again.");
            }

            ChromiumWebBrowser.OnBeforeCfxInitialize         += new OnBeforeCfxInitializeEventHandler(ChromiumWebBrowser_OnBeforeCfxInitialize);
            ChromiumWebBrowser.OnBeforeCommandLineProcessing += new OnBeforeCommandLineProcessingEventHandler(ChromiumWebBrowser_OnBeforeCommandLineProcessing);
            ChromiumWebBrowser.Initialize();

            Application.EnableVisualStyles();
            var f = new BrowserForm();

            f.Show();
            Application.Run(f);

            CfxRuntime.Shutdown();
        }
Beispiel #13
0
 public override void Unload()
 {
     // bug: tell the user that terraria will get restarted
     CfxRuntime.Shutdown();
 }
 /// <summary>
 /// This function should be called on the main application thread to shut down
 /// the CEF browser process before the application exits.
 /// </summary>
 public static void Shutdown()
 {
     CfxRuntime.Shutdown();
 }
 void IStartable.Shutdown()
 {
     CfxRuntime.Shutdown();
 }
Beispiel #16
0
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    //Console.WriteLine("args[{0}] == {1}", i, args[i]);

                    if (args[i].Contains("--port="))
                    {
                        port       = Int32.Parse(args[i].Replace("--port=", ""));
                        arguments += "port=" + port.ToString() + " ";
                    }

                    if (args[i].Contains("--proxy="))
                    {
                        string   proxy_ = args[i].Replace("--proxy=", "");
                        string[] ss     = proxy_.Split('@');
                        proxy      = "http://" + ss[0];
                        arguments += "proxy=" + proxy;
                    }
                }
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var assemblyDir = Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath);

            Environment.CurrentDirectory = Path.Combine(assemblyDir, @"..\..\..\..\");

            if (CfxRuntime.PlatformArch == CfxPlatformArch.x64)
            {
                CfxRuntime.LibCefDirPath = @"cef\Release64";
            }
            else
            {
                CfxRuntime.LibCefDirPath = @"cef\Release";
            }

            ChromiumWebBrowser.OnBeforeCfxInitialize         += ChromiumWebBrowser_OnBeforeCfxInitialize;
            ChromiumWebBrowser.OnBeforeCommandLineProcessing += ChromiumWebBrowser_OnBeforeCommandLineProcessing;

            ChromiumWebBrowser.Initialize();

            ChromiumWebBrowser wb = new ChromiumWebBrowser();

            wb.RequestHandler.CanSetCookie += (s, e) =>
            {
                e.SetReturnValue(true);
            };

            wb.RequestHandler.CanGetCookies += (s, e) =>
            {
                e.SetReturnValue(true);
            };

            Form1 f = new Form1();

            f.wb              = wb;
            f.txt             = arguments;
            f.FormBorderStyle = FormBorderStyle.None;
            f.Size            = new System.Drawing.Size(900, 600);


            wb.Dock   = DockStyle.Fill;
            wb.Parent = f;
            wb.LoadUrl("http://mybot.su/ip.php");
            //wb.LoadUrl("http://mybot.su");
            //wb.LoadUrl("http://youtube.com");
            Application.Run(f);

            CfxRuntime.Shutdown();
        }
Beispiel #17
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     CfxRuntime.Shutdown();
 }
        static void Main()
        {
            var assemblyDir = System.IO.Path.GetDirectoryName(new System.Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath);

            var projectRoot = assemblyDir;

            while (!System.IO.File.Exists(System.IO.Path.Combine(projectRoot, "Readme.md")))
            {
                projectRoot = System.IO.Path.GetDirectoryName(projectRoot);
            }

            CfxRuntime.LibCefDirPath = System.IO.Path.Combine(projectRoot, "cef", "Release64");
            CfxRuntime.LibCfxDirPath = System.IO.Path.Combine(projectRoot, "Build", "Release");

            var LD_LIBRARY_PATH = Environment.GetEnvironmentVariable("LD_LIBRARY_PATH");

            Debug.Print(LD_LIBRARY_PATH);

            var exitCode = CfxRuntime.ExecuteProcess(null);

            if (exitCode >= 0)
            {
                Environment.Exit(exitCode);
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var settings = new CfxSettings();

            settings.WindowlessRenderingEnabled = true;
            settings.NoSandbox = true;

            //settings.SingleProcess = true;
            settings.BrowserSubprocessPath = System.IO.Path.Combine(assemblyDir, "windowless");

            //settings.LogSeverity = CfxLogSeverity.Disable;

            settings.ResourcesDirPath = System.IO.Path.Combine(projectRoot, "cef", "Resources");
            settings.LocalesDirPath   = System.IO.Path.Combine(projectRoot, "cef", "Resources", "locales");

            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);
            }


            var f = new Form();

            f.Width  = 900;
            f.Height = 600;

            var c = new BrowserControl();

            c.Dock   = DockStyle.Fill;
            c.Parent = f;

            Application.Idle += Application_Idle;
            Application.Run(f);

            CfxRuntime.Shutdown();
        }
Beispiel #19
0
 private static void Application_ThreadExit(object sender, EventArgs e)
 {
     CfxRuntime.Shutdown();
 }
Beispiel #20
0
        static void Main()
        {
            Config = JsonConvert.DeserializeObject <Config>(File.ReadAllText("Config.json"));

            if (CfxRuntime.PlatformArch == CfxPlatformArch.x64)
            {
                CfxRuntime.LibCefDirPath = Path.GetFullPath(@"..\..\..\libcef\x64");
            }
            else
            {
                CfxRuntime.LibCefDirPath = System.IO.Path.GetFullPath(@"..\..\..\libcef\x86");
            }

            CfxRuntime.LibCfxDirPath = CfxRuntime.LibCefDirPath;

            string assemblyDir = System.IO.Path.GetDirectoryName(
                new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath
                );

            //CfxRuntime.EnableHighDpiSupport();

            int exitCode = CfxRuntime.ExecuteProcess(null);

            if (exitCode >= 0)
            {
                Environment.Exit(exitCode);
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var settings = new CfxSettings();

            settings.WindowlessRenderingEnabled = true;
            settings.NoSandbox = true;

            //settings.SingleProcess = true;
            settings.BrowserSubprocessPath = Path.Combine(assemblyDir, "xRemote");

            //settings.LogSeverity = CfxLogSeverity.Disable;

            settings.ResourcesDirPath = Path.GetFullPath(@"..\..\..\libcef\Resources");
            settings.LocalesDirPath   = Path.GetFullPath(@"..\..\..\libcef\Resources\locales");

            var app = new CfxApp();

            app.OnBeforeCommandLineProcessing += (s, e) =>
            {
                e.CommandLine.AppendSwitch("disable-web-security");
                e.CommandLine.AppendSwitch("enable-system-flash");

                // 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);
            }

            Common.GlobalObjectPool.InitializePool();

            // 监听连接请求
            ProxyListener.Initialize();

            var f = new MainForm();

            f.Show();
            Application.Idle += (s, e) => CfxRuntime.DoMessageLoopWork();
            Application.Run(f);

            Common.GlobalObjectPool.DestroyPool();

            CfxRuntime.Shutdown();
        }
Beispiel #21
0
        static void Main()
        {
            string nowDir = Environment.CurrentDirectory;

            CfxRuntime.LibCefDirPath = System.IO.Path.Combine(nowDir, "cef");
            CfxRuntime.LibCfxDirPath = nowDir;
            int exitCode = CfxRuntime.ExecuteProcess(null);

            if (exitCode >= 0)
            {
                Environment.Exit(exitCode);
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            using (var settings = new CfxSettings())
            {
                settings.MultiThreadedMessageLoop   = true;
                settings.WindowlessRenderingEnabled = true;
                settings.NoSandbox        = true;
                settings.ResourcesDirPath = System.IO.Path.Combine(nowDir, "cef", "Resources");
                settings.LocalesDirPath   = System.IO.Path.Combine(nowDir, "cef", "Resources", "locales");

                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);
                }
            }


            Manager.mainForm = new Form1
            {
                //FormBorderStyle = System.Windows.Forms.FormBorderStyle.None,
                BackColor         = Color.White,
                Height            = 300,
                Width             = 300,
                TransparencyKey   = Color.White,
                AllowTransparency = true
            };

            ArkDesktopBrowserControl control = new ArkDesktopBrowserControl
            {
                Dock   = DockStyle.Fill,
                Parent = Manager.mainForm
            };

            Manager.mainForm.Controls.Add(control);

            Manager.Init();

            Application.Run(Manager.mainForm);

            // CfxRuntime.QuitMessageLoop();
            CfxRuntime.Shutdown();
        }
Beispiel #22
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);
        }
Beispiel #23
0
 /// <summary>
 /// 停止
 /// </summary>
 internal void Stop()
 {
     IsStarted = false;
     CfxRuntime.Shutdown();
 }
 public void Dispose()
 {
     CfxRuntime.Shutdown();
 }