示例#1
0
        private static int Main(string[] args)
        {
            try
            {
                CefRuntime.Load();
            }
            catch (DllNotFoundException ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(1);
            }
            catch (CefRuntimeException ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(2);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(3);
            }

            var mainArgs = new CefMainArgs(args);
            var app      = new DemoApp();

            var exitCode = CefRuntime.ExecuteProcess(mainArgs, app);

            if (exitCode != -1)
            {
                return(exitCode);
            }

            var codeBase           = Assembly.GetExecutingAssembly().CodeBase;
            var localFolder        = Path.GetDirectoryName(new Uri(codeBase).LocalPath);
            var browserProcessPath = CombinePaths(localFolder, "..", "..", "..",
                                                  "CefGlue.Demo.WinForms", "bin", "Release", "Xilium.CefGlue.Demo.WinForms.exe");

            var settings = new CefSettings
            {
                BrowserSubprocessPath    = browserProcessPath,
                MultiThreadedMessageLoop = true,
                LogSeverity = CefLogSeverity.Disable,
                LogFile     = "CefGlue.log",
            };

            CefRuntime.Initialize(mainArgs, settings, app);

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

            if (!settings.MultiThreadedMessageLoop)
            {
                Application.Idle += (sender, e) => { CefRuntime.DoMessageLoopWork(); };
            }

            Application.Run(new MainForm());

            CefRuntime.Shutdown();
            return(0);
        }
示例#2
0
        private static int Main(string[] args)
        {
            try
            {
                CefRuntime.Load();
            }
            catch (DllNotFoundException ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(1);
            }
            catch (CefRuntimeException ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(2);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(3);
            }

            var mainArgs = new CefMainArgs(args);
            var app      = new DemoApp();

            var exitCode = CefRuntime.ExecuteProcess(mainArgs, app);

            if (exitCode != -1)
            {
                return(exitCode);
            }

            var settings = new CefSettings
            {
                // BrowserSubprocessPath = @"D:\fddima\Projects\Xilium\Xilium.CefGlue\CefGlue.Demo\bin\Release\Xilium.CefGlue.Demo.exe",
                SingleProcess            = false,
                MultiThreadedMessageLoop = true,
                LogSeverity         = CefLogSeverity.Disable,
                LogFile             = "CefGlue.log",
                RemoteDebuggingPort = 7777,
            };

            CefRuntime.Initialize(mainArgs, settings, app);
            CefRuntime.RegisterSchemeHandlerFactory("http", "server", new MySchemeHandlerFactory());

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

            if (!settings.MultiThreadedMessageLoop)
            {
                Application.Idle += (sender, e) => { CefRuntime.DoMessageLoopWork(); };
            }

            Application.Run(new MainForm());

            CefRuntime.Shutdown();
            return(0);
        }
示例#3
0
文件: Program.cs 项目: rajsite/lvcef
        private static int Main(string[] args)
        {
            try
            {
                CefRuntime.Load();
            }
            catch (DllNotFoundException ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return 1;
            }
            catch (CefRuntimeException ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return 2;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return 3;
            }

            var mainArgs = new CefMainArgs(args);
            var app = new DemoApp();

            var exitCode = CefRuntime.ExecuteProcess(mainArgs, app);
            if (exitCode != -1)
                return exitCode;

            var settings = new CefSettings
                {
                    // BrowserSubprocessPath = @"D:\fddima\Projects\Xilium\Xilium.CefGlue\CefGlue.Demo\bin\Release\Xilium.CefGlue.Demo.exe",
                    SingleProcess = false,
                    MultiThreadedMessageLoop = true,
                    LogSeverity = CefLogSeverity.Disable,
                    LogFile = "CefGlue.log",
                };

            CefRuntime.Initialize(mainArgs, settings, app);

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

            if (!settings.MultiThreadedMessageLoop)
            {
                Application.Idle += (sender, e) => { CefRuntime.DoMessageLoopWork(); };
            }

            Application.Run(new MainForm());

            CefRuntime.Shutdown();
            return 0;
        }
示例#4
0
        private static int Main(string[] args1)
        {
            //自定义初始化系统配置
            InitAllinOne();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            MainForm.taskRunner   = GlobalUI.taskRunner;
            GlobalVar.AccountList = HaoziHelper.importAccounts();
            //导入账号信息

            //每个账号建立一个cache
            string zfbEmail = "";

            zfbEmail = GlobalVar.AccountList.Count == 0 ? "downloadAccount" : GlobalVar.AccountList[0].zfbEmail;
            string MyCachePath = Application.StartupPath + "\\cache\\{0}\\".With(zfbEmail);

            if (!Directory.Exists(MyCachePath))
            {
                Directory.CreateDirectory(MyCachePath);
            }

            //每个账号建立一个个性化信息配置文件
            string zfbEmailConfig = MyCachePath + zfbEmail + ".txt";
            string httpHeadAgent  = FileHelper.RandomReadOneLine("Resources//httpHead.txt").ReplaceNum();

            if (!File.Exists(zfbEmailConfig))
            {
                //  File.Create(zfbEmailConfig); //Directory.CreateDirectory(MyCachePath);
                File.WriteAllText(zfbEmailConfig, httpHeadAgent);
            }
            else
            {
                httpHeadAgent = File.ReadAllLines(zfbEmailConfig)[0];
            }
            GlobalCefGlue.UserAgent = httpHeadAgent;
            LogManager.WriteLog(httpHeadAgent + " " + MyCachePath);

            //
            string[] args = { "" };
            int      main;

            if (cefruntimeLoad(out main))
            {
                return(main);
            }
            var mainArgs = new CefMainArgs(args);
            var app      = new DemoApp();

            var exitCode = CefRuntime.ExecuteProcess(mainArgs, app);

            if (exitCode != -1)
            {
                return(exitCode);
            }

            var settings = new CefSettings {
                // BrowserSubprocessPath = @"D:\fddima\Projects\Xilium\Xilium.CefGlue\CefGlue.Demo\bin\Release\Xilium.CefGlue.Demo.exe",
                SingleProcess = false,
                LogSeverity   = CefLogSeverity.Disable,
                LogFile       = "CefGlue.log",
                //设置缓存地址
                CachePath           = MyCachePath,// Application.StartupPath + "\\cache\\{0}\\".With(zfbEmail),
                RemoteDebuggingPort = 20480,
                //  UserAgent = httpHeadAgent//FileHelper.RandomReadOneLine("Resources//httpHead.txt").ReplaceNum()
            };

            if (ConfigHelper.GetBoolValue("UseUserAgent"))
            {
                settings.UserAgent = httpHeadAgent;
            }
            settings.UserAgent = httpHeadAgent;

            //   settings.MultiThreadedMessageLoop = CefRuntime.Platform == CefRuntimePlatform.Windows;
            settings.MultiThreadedMessageLoop = bool.Parse(ConfigHelper.GetValue("MultiThreadedMessageLoop"));
            ;

            CefRuntime.Initialize(mainArgs, settings, app);
            //注册  register custom scheme handler
            //
            CefRuntime.RegisterSchemeHandlerFactory("http", GlobalVar.Js2CsharpRequestDomain, new Js2CsharpSchemeHandlerFactory());
            CefRuntime.AddCrossOriginWhitelistEntry(
                "http://trade.taobao.com", "http", "https://tbapi.alipay.com", true);
            CefRuntime.AddCrossOriginWhitelistEntry(
                "http://trade.taobao.com", "https", "https://tbapi.alipay.com", true);

            if (!settings.MultiThreadedMessageLoop)
            {
                Application.Idle += (sender, e) => { CefRuntime.DoMessageLoopWork(); };
            }

            MainForm mainform;

            //通过配置觉得是否自运行
            if (GlobalVar.autoRun)
            {
                mainform = new MainForm(true);
            }
            else
            {
                mainform = new MainForm();
            }

            Application.Run(mainform);

            CefRuntime.Shutdown();


            return(0);
        }