protected async Task <HttpWebRequest> CreateWebRequest(string uri) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.UserAgent = HttpUserAgent; request.Accept = HttpAccept; request.CookieContainer = new CookieContainer(); await CefHelper.CollectCookies(); //request.CookieContainer.Add(CookieStorageHelper.CurrentCookies); foreach (Cookie cookie in CookieStorageHelper.CurrentCookies) { try { request.CookieContainer.Add(cookie); } catch (CookieException) { // Ignore } } return(request); }
private void ClientContainer_Load(object sender, EventArgs e) { Cef.Initialize(new CefSettings() { Locale = "es-AR" }); string start = string.Format("{0}\\App\\dist\\index.html", Application.StartupPath); if (!File.Exists(start)) { MessageBox.Show("Error The html file doesn't exists : " + start); } browser = new ChromiumWebBrowser(start); helper = new CefHelper(browser); browser.RegisterJsObject("CefHelper", helper); browser.RegisterJsObject("PrintHelper", new PrintHelper(Application.StartupPath + "\\PrintConfig.json", CreatePrintModes())); browser.RegisterJsObject("ClientConfig", new ClientConfig { Host = ConfigurationManager.AppSettings["ApiHost"] }); this.Controls.Add(browser); browser.Dock = DockStyle.Fill; //browser.IsBrowserInitializedChanged += ShowDevTools; // Allow the use of local resources in the browser BrowserSettings browserSettings = new BrowserSettings(); browserSettings.FileAccessFromFileUrls = CefState.Enabled; browserSettings.UniversalAccessFromFileUrls = CefState.Enabled; browser.BrowserSettings = browserSettings; browser.Focus(); }
private void OnClosing(object sender, CancelEventArgs e) { StorageHelper.SaveData(MallowSource.CurrentSource); ConfigHelper.SaveConfig(Config.Current); WebPush.Current.Stop(); CefHelper.Shutdown(); UpdateHelper.Current.Dispose(); }
private void Application_Startup(object sender, StartupEventArgs e) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; CefHelper.LoadCefDllsAndInit(); MainWindow = new MainWindow(); MainWindow.Show(); ShutdownMode = ShutdownMode.OnMainWindowClose; }
private static void Main() { XmlConfigurator.Configure(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.ThreadException += Application_ThreadException; Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); CefHelper.Init(true, true); Application.Run(new FormMain()); Cef.Shutdown(); }
public App() { // Exception Handler DispatcherUnhandledException += (sender, args) => { args.Handled = true; MessageBox.Show( args.Exception.Message, "灾难性故障", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); }; AppDomain.CurrentDomain.UnhandledException += (sender, args) => { MessageBox.Show( ((Exception)args.ExceptionObject)?.Message ?? "Exception", "灾难性故障", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); }; // SquirrelAware using (UpdateManager mgr = new UpdateManager(Config.Current.UpdateServer)) { SquirrelAwareApp.HandleEvents( onInitialInstall: v => { mgr.CreateShortcutForThisExe(); Current.Shutdown(0); }, onAppUpdate: v => { mgr.CreateShortcutForThisExe(); Current.Shutdown(0); }, onAppUninstall: v => { mgr.RemoveShortcutForThisExe(); Current.Shutdown(0); }); } SimpleBox.Properties.Resources.Culture = CultureInfo.CurrentUICulture; // Initialize UpdateHelper string updateMode = UpdateHelper.Current.UpdateMode; // Initialize CookieManager System.Net.CookieCollection cookieCollection = CookieStorageHelper.CurrentCookies; // Initialize WebPush WebPush.Current = new WebPush(); WebPush.Current.Start(); if (!WebPush.Current.IsListening) { MessageBox.Show( "信息推送服务无法启动。请检查端口占用。程序即将退出。", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); Current.Shutdown(1); } // Initialize CEFSharp CefHelper.Initialize(); // Force Dark Theme ResourceDictionaryEx.GlobalTheme = ElementTheme.Dark; // Create MainWindow MainWindow ??= new MainWindow(); // Show MainWindow MainWindow.Show(); }
private async void Btn_Star_Click(object sender, RoutedEventArgs e) { if (_second) { return; } _second = true; if (await GetCheck(GlobalData.VM_MA.IsStarted ? GlobalLanguage.Msg_SecondConf : GlobalLanguage.Msg_StartConf)) { if (GlobalData.CheckResult == false) { _second = false; return; } } if (!GlobalData.VM_MA.IsStarted) { ShowLoading(true); if (await Begin()) { _tempArt = new ArtistInfo() { Id = GlobalData.VM_MA.Artist.Id, AName = GlobalData.VM_MA.Artist.AName, PayLow = GlobalData.VM_MA.Artist.PayLow, PayHigh = GlobalData.VM_MA.Artist.PayHigh, PostUrl = GlobalData.VM_MA.Artist.PostUrl, }; _tempSite = GlobalData.VM_MA.Site; _tempCookies = GlobalData.VM_MA.Cookies; _tempProxy = GlobalData.VM_MA.Proxy; _tempDate = GlobalData.VM_MA.Date; _tempSP = GlobalData.VM_MA.SavePath; _tempUP = GlobalData.VM_MA.UseProxy; _tempUD = GlobalData.VM_MA.UseDate; ShowLoading(false); GlobalData.VM_MA.IsStarted = true; } } else { ShowLoading(true); if (_tempSite != GlobalData.VM_MA.Site || _tempArt.PostUrl != GlobalData.VM_MA.Artist.PostUrl) { if (GlobalData.VM_DL.IsDownloading) { await GetCheck(GlobalLanguage.Msg_IsDownload); ShowLoading(false); _second = false; return; } if (await Begin()) { _tempArt = new ArtistInfo() { Id = GlobalData.VM_MA.Artist.Id, AName = GlobalData.VM_MA.Artist.AName, PayLow = GlobalData.VM_MA.Artist.PayLow, PayHigh = GlobalData.VM_MA.Artist.PayHigh, PostUrl = GlobalData.VM_MA.Artist.PostUrl, }; _tempSite = GlobalData.VM_MA.Site; _tempCookies = GlobalData.VM_MA.Cookies; _tempProxy = GlobalData.VM_MA.Proxy; _tempDate = GlobalData.VM_MA.Date; _tempSP = GlobalData.VM_MA.SavePath; } ShowLoading(false); _second = false; return; } if (_tempArt.PayLow != GlobalData.VM_MA.Artist.PayLow || _tempArt.PayHigh != GlobalData.VM_MA.Artist.PayHigh) { if (GlobalData.VM_MA.Site == SiteType.Fanbox) { await Task.Run(() => { foreach (var bi in _tempBis) { bi.Skip = GlobalMethord.OverPayment(int.Parse(bi.Fee)); } }); GlobalData.VM_MA.ItemList = _tempBis.Where(x => !x.Skip).ToList(); _tempArt.PayLow = GlobalData.VM_MA.Artist.PayLow; _tempArt.PayHigh = GlobalData.VM_MA.Artist.PayHigh; } } if (_tempSP != GlobalData.VM_MA.SavePath) { await GetCheck(GlobalLanguage.Msg_ChangeSP); _tempSP = GlobalData.VM_MA.SavePath; } if (_tempProxy != GlobalData.VM_MA.Proxy) { GlobalData.VM_DL.DLClients.ForEach(x => { GlobalData.VM_DL.ReStartCommand.Execute(x); }); if (null != GlobalData.VM_MA.PatreonCefBrowser) { await CefHelper.SetProxy((CefSharp.Wpf.ChromiumWebBrowser) GlobalData.VM_MA.PatreonCefBrowser, GlobalData.VM_MA.Proxy); } _tempProxy = GlobalData.VM_MA.Proxy; } if (_tempUP != GlobalData.VM_MA.UseProxy) { GlobalData.VM_DL.DLClients.ForEach(x => { GlobalData.VM_DL.ReStartCommand.Execute(x); }); if (GlobalData.VM_MA.UseProxy && null != GlobalData.VM_MA.PatreonCefBrowser) { await CefHelper.SetProxy((CefSharp.Wpf.ChromiumWebBrowser) GlobalData.VM_MA.PatreonCefBrowser, GlobalData.VM_MA.Proxy); } _tempUP = GlobalData.VM_MA.UseProxy; } if (_tempCookies != GlobalData.VM_MA.Cookies) { GlobalData.VM_DL.DLClients.ForEach(x => { GlobalData.VM_DL.ReStartCommand.Execute(x); }); _tempCookies = GlobalData.VM_MA.Cookies; } if (_tempDate != GlobalData.VM_MA.Date || _tempUD != GlobalData.VM_MA.UseDate) { if (GlobalData.VM_MA.Site == SiteType.Fanbox || CompareDate(GlobalData.VM_MA.Date, _tempDate)) { await Task.Run(() => { foreach (var bi in _tempBis) { bi.Skip = GlobalMethord.OverTime(bi.UpdateDate); } }); GlobalData.VM_MA.ItemList = _tempBis.Where(x => !x.Skip).ToList(); _tempDate = GlobalData.VM_MA.Date; _tempUD = GlobalData.VM_MA.UseDate; } else { if (GlobalData.VM_DL.IsDownloading) { await GetCheck(GlobalLanguage.Msg_IsDownload); ShowLoading(false); _second = false; return; } if (await Begin()) { _tempArt = new ArtistInfo() { Id = GlobalData.VM_MA.Artist.Id, AName = GlobalData.VM_MA.Artist.AName, PayLow = GlobalData.VM_MA.Artist.PayLow, PayHigh = GlobalData.VM_MA.Artist.PayHigh, PostUrl = GlobalData.VM_MA.Artist.PostUrl, }; _tempSite = GlobalData.VM_MA.Site; _tempCookies = GlobalData.VM_MA.Cookies; _tempProxy = GlobalData.VM_MA.Proxy; _tempDate = GlobalData.VM_MA.Date; _tempSP = GlobalData.VM_MA.SavePath; } ShowLoading(false); _second = false; return; } } ShowLoading(false); GlobalCommand.BackCommand.Execute(BackType.Pop); } _second = false; }