using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; using BookmarkManager.Services; using bzit.bomg.Models; using RyzStudio.Windows.Forms; using RyzStudio.Windows.ThemedForms; using RyzStudio.Windows.ThemedForms.PickerBox; namespace FizzyLauncher { public class UpdateIconsForm : TDialog { private System.Windows.Forms.Label label1; private ThButton button1; private RyzStudio.Windows.Forms.THorizontalSeparator tHorizontalSeparator1; private RyzStudio.Windows.Forms.THorizontalSeparator tHorizontalSeparator2; private Label label2; private PictureBox pictureBox2; private ThYesNoPickerBox pickerBox1; private ThButton button2; private RyzStudio.Windows.ThemedForms.ThProgressBar progressBar1; private readonly WebProvider _webProvider; private BookmarkTreeView _treeView; private bool _isBusy = false; private Label label4; private THorizontalSeparator tHorizontalSeparator3; private ThButton button3; private bool _requestCancel = false; public UpdateIconsForm(BookmarkTreeView treeView) { InitializeComponent(); this.OkButton = button1; _webProvider = new WebProvider(); _webProvider.IgnoreSSL = true; _treeView = treeView; } private void InitializeComponent() { label1 = new Label(); button1 = new ThButton(); tHorizontalSeparator1 = new THorizontalSeparator(); tHorizontalSeparator2 = new THorizontalSeparator(); label2 = new Label(); pictureBox2 = new PictureBox(); pickerBox1 = new ThYesNoPickerBox(); button2 = new ThButton(); progressBar1 = new ThProgressBar(); label4 = new Label(); tHorizontalSeparator3 = new THorizontalSeparator(); button3 = new ThButton(); ((ISupportInitialize)pictureBox2).BeginInit(); SuspendLayout(); // // label1 // label1.AutoSize = true; label1.BackColor = System.Drawing.Color.Transparent; label1.ForeColor = System.Drawing.SystemColors.ControlText; label1.Location = new System.Drawing.Point(10, 21); label1.Margin = new Padding(0); label1.Name = "label1"; label1.Padding = new Padding(0, 8, 0, 0); label1.Size = new System.Drawing.Size(156, 23); label1.TabIndex = 153; label1.Text = "Update Missing Icons (Only)"; label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // button1 // button1.AcceptButton = null; button1.ActiveImage = null; button1.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; button1.BackColor = System.Drawing.Color.Transparent; button1.EnableMenuOnClick = false; button1.EnableReactiveVisual = true; button1.HoverImage = null; button1.IdleImage = null; button1.LabelText = "&Close"; button1.Location = new System.Drawing.Point(301, 469); button1.Margin = new Padding(10, 10, 10, 0); button1.Name = "button1"; button1.Padding = new Padding(4, 4, 3, 3); button1.Size = new System.Drawing.Size(128, 32); button1.TabIndex = 2; button1.TabStop = false; // // tHorizontalSeparator1 // tHorizontalSeparator1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; tHorizontalSeparator1.AutoScrollMargin = new System.Drawing.Size(0, 0); tHorizontalSeparator1.AutoScrollMinSize = new System.Drawing.Size(0, 0); tHorizontalSeparator1.BackColor = System.Drawing.Color.Transparent; tHorizontalSeparator1.Location = new System.Drawing.Point(10, 437); tHorizontalSeparator1.Margin = new Padding(0, 10, 0, 0); tHorizontalSeparator1.MaximumSize = new System.Drawing.Size(4920, 2); tHorizontalSeparator1.MinimumSize = new System.Drawing.Size(0, 22); tHorizontalSeparator1.Name = "tHorizontalSeparator1"; tHorizontalSeparator1.Size = new System.Drawing.Size(424, 22); tHorizontalSeparator1.TabIndex = 188; tHorizontalSeparator1.TabStop = false; // // tHorizontalSeparator2 // tHorizontalSeparator2.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; tHorizontalSeparator2.AutoScrollMargin = new System.Drawing.Size(0, 0); tHorizontalSeparator2.AutoScrollMinSize = new System.Drawing.Size(0, 0); tHorizontalSeparator2.BackColor = System.Drawing.Color.Transparent; tHorizontalSeparator2.Location = new System.Drawing.Point(10, 65); tHorizontalSeparator2.Margin = new Padding(0, 10, 0, 0); tHorizontalSeparator2.MaximumSize = new System.Drawing.Size(4920, 2); tHorizontalSeparator2.MinimumSize = new System.Drawing.Size(0, 22); tHorizontalSeparator2.Name = "tHorizontalSeparator2"; tHorizontalSeparator2.Size = new System.Drawing.Size(424, 22); tHorizontalSeparator2.TabIndex = 190; tHorizontalSeparator2.TabStop = false; // // label2 // label2.AutoSize = true; label2.BackColor = System.Drawing.Color.Transparent; label2.ForeColor = System.Drawing.SystemColors.ControlText; label2.Location = new System.Drawing.Point(10, 98); label2.Margin = new Padding(0); label2.Name = "label2"; label2.Padding = new Padding(0, 8, 0, 0); label2.Size = new System.Drawing.Size(231, 23); label2.TabIndex = 195; label2.Text = "Retrieve supported icons from bookmarks."; label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // pictureBox2 // pictureBox2.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; pictureBox2.BackColor = System.Drawing.Color.Transparent; pictureBox2.ErrorImage = null; pictureBox2.InitialImage = null; pictureBox2.Location = new System.Drawing.Point(261, 171); pictureBox2.Name = "pictureBox2"; pictureBox2.Size = new System.Drawing.Size(32, 32); pictureBox2.SizeMode = PictureBoxSizeMode.CenterImage; pictureBox2.TabIndex = 202; pictureBox2.TabStop = false; // // pickerBox1 // pickerBox1.AcceptButton = null; pickerBox1.Anchor = AnchorStyles.Top | AnchorStyles.Right; pickerBox1.BackColor = System.Drawing.Color.Transparent; pickerBox1.EnableReactiveVisual = true; pickerBox1.Font = new System.Drawing.Font("Segoe UI", 9F); pickerBox1.Location = new System.Drawing.Point(350, 21); pickerBox1.Margin = new Padding(10, 10, 10, 0); pickerBox1.Name = "pickerBox1"; pickerBox1.Padding = new Padding(4, 4, 3, 3); pickerBox1.SelectedIndex = 1; pickerBox1.Size = new System.Drawing.Size(84, 35); pickerBox1.TabIndex = 0; pickerBox1.TabStop = false; pickerBox1.Value = true; // // button2 // button2.AcceptButton = null; button2.ActiveImage = null; button2.Anchor = AnchorStyles.Top | AnchorStyles.Right; button2.BackColor = System.Drawing.Color.Transparent; button2.EnableMenuOnClick = false; button2.EnableReactiveVisual = true; button2.HoverImage = null; button2.IdleImage = null; button2.LabelText = "&Run"; button2.Location = new System.Drawing.Point(306, 171); button2.Margin = new Padding(10, 10, 10, 0); button2.Name = "button2"; button2.Padding = new Padding(4, 4, 3, 3); button2.Size = new System.Drawing.Size(128, 32); button2.TabIndex = 1; button2.TabStop = false; button2.MouseClick += button2_MouseClick; // // progressBar1 // progressBar1.AcceptButton = null; progressBar1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; progressBar1.BackColor = System.Drawing.Color.Transparent; progressBar1.BarColour = System.Drawing.Color.FromArgb(86, 81, 157); progressBar1.BarTextColour = System.Drawing.Color.Black; progressBar1.EnableReactiveVisual = false; progressBar1.Font = new System.Drawing.Font("Segoe UI", 9F); progressBar1.Location = new System.Drawing.Point(10, 141); progressBar1.Margin = new Padding(10, 10, 10, 0); progressBar1.Maximum = 100; progressBar1.Minimum = 0; progressBar1.Name = "progressBar1"; progressBar1.Padding = new Padding(4, 4, 3, 3); progressBar1.ProgressText = "50/100"; progressBar1.ShowProgressText = true; progressBar1.Size = new System.Drawing.Size(424, 20); progressBar1.TabIndex = 206; progressBar1.TabStop = false; progressBar1.Value = 50; // // label4 // label4.AutoSize = true; label4.BackColor = System.Drawing.Color.Transparent; label4.ForeColor = System.Drawing.SystemColors.ControlText; label4.Location = new System.Drawing.Point(10, 245); label4.Margin = new Padding(0); label4.Name = "label4"; label4.Padding = new Padding(0, 8, 0, 0); label4.Size = new System.Drawing.Size(83, 23); label4.TabIndex = 208; label4.Text = "Clear all icons."; label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // tHorizontalSeparator3 // tHorizontalSeparator3.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; tHorizontalSeparator3.AutoScrollMargin = new System.Drawing.Size(0, 0); tHorizontalSeparator3.AutoScrollMinSize = new System.Drawing.Size(0, 0); tHorizontalSeparator3.BackColor = System.Drawing.Color.Transparent; tHorizontalSeparator3.Location = new System.Drawing.Point(10, 212); tHorizontalSeparator3.Margin = new Padding(0, 10, 0, 0); tHorizontalSeparator3.MaximumSize = new System.Drawing.Size(4920, 2); tHorizontalSeparator3.MinimumSize = new System.Drawing.Size(0, 22); tHorizontalSeparator3.Name = "tHorizontalSeparator3"; tHorizontalSeparator3.Size = new System.Drawing.Size(424, 22); tHorizontalSeparator3.TabIndex = 207; tHorizontalSeparator3.TabStop = false; // // button3 // button3.AcceptButton = null; button3.ActiveImage = null; button3.BackColor = System.Drawing.Color.Transparent; button3.EnableMenuOnClick = false; button3.EnableReactiveVisual = true; button3.HoverImage = null; button3.IdleImage = null; button3.LabelText = "Clear &All"; button3.Location = new System.Drawing.Point(10, 288); button3.Margin = new Padding(10, 10, 10, 0); button3.Name = "button3"; button3.Padding = new Padding(4, 4, 3, 3); button3.Size = new System.Drawing.Size(128, 32); button3.TabIndex = 209; button3.TabStop = false; button3.MouseClick += button3_MouseClick; // // UpdateIconsForm // AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new System.Drawing.Size(444, 521); Controls.Add(button3); Controls.Add(label4); Controls.Add(tHorizontalSeparator3); Controls.Add(progressBar1); Controls.Add(button2); Controls.Add(pickerBox1); Controls.Add(pictureBox2); Controls.Add(label2); Controls.Add(tHorizontalSeparator2); Controls.Add(tHorizontalSeparator1); Controls.Add(button1); Controls.Add(label1); KeyPreview = true; MinimumSize = new System.Drawing.Size(460, 560); Name = "UpdateIconsForm"; Text = "Update Icons"; ((ISupportInitialize)pictureBox2).EndInit(); ResumeLayout(false); PerformLayout(); } protected override void OnLoad(EventArgs e) { base.OnLoad(e); var model = _treeView.ToNodeList(); if (pickerBox1.Value) { model = model.Where(x => x.Value.Icon == null)?.ToList() ?? new List>(); } progressBar1.Minimum = 0; progressBar1.Value = 0; progressBar1.Maximum = model.Count; pickerBox1.Focus(); } protected override void OnClosing(CancelEventArgs e) { base.OnClosing(e); if (this.IsBusy) { e.Cancel = true; } } protected bool IsBusy { get => _isBusy; set { _isBusy = value; UIControl.SetEnable(pickerBox1, !this.IsBusy); UIControl.Invoke(button2, (x) => { button2.LabelText = (this.IsBusy ? "&Stop" : "&Run"); }); UIControl.SetValue(pictureBox2, (this.IsBusy ? RyzStudio.Windows.ThemedForms.Resource2.loading_block : null)); UIControl.SetEnable(button3, !this.IsBusy); UIControl.SetEnable(button1, !this.IsBusy); } } private async void button2_MouseClick(object sender, MouseEventArgs e) { await Task.Run(async () => { if (this.IsBusy) { _requestCancel = true; return; } this.IsBusy = true; var model = _treeView.ToNodeList(); if (pickerBox1.Value) { model = model.Where(x => x.Value.Icon == null)?.ToList() ?? new List>(); } progressBar1.Minimum = 0; progressBar1.Value = 0; progressBar1.Maximum = model.Count; foreach (var item in model) { progressBar1.Value++; if (string.IsNullOrWhiteSpace(item.Value.Address)) { continue; } if (_requestCancel) { break; } var document = await _webProvider.RetrieveHtmlDocument(item.Value.Address); if (document == null) { continue; } if (_requestCancel) { break; } var image = await _webProvider.RetrieveImage(document); if (image == null) { continue; } var newModel = item.Value; newModel.Icon = image; _treeView.UpdateNode(item.Key, newModel); } _requestCancel = false; this.IsBusy = false; }); } private async void button3_MouseClick(object sender, MouseEventArgs e) { await Task.Run(() => { if (this.IsBusy) { return; } this.IsBusy = true; var model = _treeView.ToNodeList(); foreach (var item in model) { progressBar1.Value++; if (item.Value.Icon == null) { continue; } var newModel = item.Value; newModel.Icon = null; _treeView.UpdateNode(item.Key, newModel); } _requestCancel = false; this.IsBusy = false; }); } } }