private async void btnLogin_Click(object sender, EventArgs e) { if (!validation()) { return; } btnLogin.Enabled = false; try { var vozClient = new NextVozClient(); if (string.IsNullOrEmpty(rbCookies.Text)) { await vozClient.Login(txtUserName.Text, txtPassword.Text); } else { await vozClient.Login(rbCookies.Text); } Setting.Instance.Cookies = vozClient.GetCookies(); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { btnLogin.Enabled = true; } }
private void init() { System.Net.ServicePointManager.MaxServicePoints = Int32.MaxValue; System.Net.ServicePointManager.DefaultConnectionLimit = Int32.MaxValue; System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; try { txtLink.Text = Setting.Instance.Link; txtSavePath.Text = Setting.Instance.SavePath; cbDownloadAllPage.Checked = Setting.Instance.AllPage; cbSubDirectory.Checked = Setting.Instance.SubDirectory; cbIgnoreSmallImage.Checked = Setting.Instance.IgnoreSmallImage; cbCreateDirByThreadName.Checked = Setting.Instance.CreateDirByThreadName; nrMaxImageInSubDirectory.Value = Setting.Instance.MaxImageInSubDirectory; nrNumberThreads.Value = Setting.Instance.NumberThreads; nrFormPage.Value = Setting.Instance.FromPage; nrToPage.Value = Setting.Instance.ToPage; } catch { } if (string.IsNullOrEmpty(txtSavePath.Text)) { txtSavePath.Text = Path.Combine(Application.StartupPath, "Images"); } if (!string.IsNullOrEmpty(Setting.Instance.Cookies)) { btnLogin.Enabled = false; btnLogin.Text = "Đang đăng nhập"; var vozClient = new NextVozClient(Setting.Instance.Cookies); Task.Run(async() => { try { await vozClient.Login(Setting.Instance.Cookies); this.Invoke((Action)(() => { btnLogin.Enabled = true; btnLogin.Text = "Đăng xuất"; })); } catch { this.Invoke((Action)(() => { btnLogin.Enabled = true; btnLogin.Text = "Đăng nhập"; })); } }); } btnLogin.Enabled = string.IsNullOrEmpty(Setting.Instance.Cookies); _downloader = new NextVozDownloadImage(); if (!string.IsNullOrEmpty(Setting.Instance.Link)) { linkChanged(); } SetDoubleBuffered(this.lvDownloadProcess); EXListView lv = new EXListView(); lv.Location = lvDownloadProcess.Location; lv.Width = lvDownloadProcess.Width; lv.Height = lvDownloadProcess.Height; lv.Anchor = lvDownloadProcess.Anchor; this.Controls.Remove(lvDownloadProcess); this.Controls.Add(lv); lv.Columns.Add("Link", 450); lv.Columns.Add("Process", 300); Status.Init(lbStatus, lbTotalDownloaded, lbTotalSize); DownloadProcess.Init(lv); }