diff --git a/BookmarkForm.cs b/BookmarkForm.cs index fbac468..360f01d 100644 --- a/BookmarkForm.cs +++ b/BookmarkForm.cs @@ -389,41 +389,12 @@ namespace FizzyLauncher } else { - ThreadControl.SetValue(pictureBox1, RetrieveImage(rs.IconURL)); + ThreadControl.SetValue(pictureBox1, webParser.RetrieveImage(rs.IconURL)); } IsBusy = false; }); } - private Bitmap RetrieveImage(string url) - { - if (string.IsNullOrWhiteSpace(url)) - { - return null; - } - - if (webClient == null) webClient = new WebClient(); - webClient.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore); - - try - { - byte[] byteData = webClient.DownloadData(url); - - if (!RyzStudio.IO.FileType.IsImage(byteData)) - { - throw new Exception("Not a supported image"); - } - - Image img = Image.FromStream(new MemoryStream(byteData)); - - return new Bitmap(img, 16, 16); - } - catch (Exception) - { - return null; - } - } - } } \ No newline at end of file diff --git a/BookmarkManager.csproj b/BookmarkManager.csproj index c091635..cb25ea3 100644 --- a/BookmarkManager.csproj +++ b/BookmarkManager.csproj @@ -12,9 +12,9 @@ Hi, I'm Ray Bookmark Manager Ray Lam - 0.4.0.061 - 0.4.0.061 - 0.4.0.061 + 0.4.0.129 + 0.4.0.129 + 0.4.0.129 bookmarkmanager @@ -107,6 +107,12 @@ True AppResource.resx + + UserControl + + + Form + Form diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index 7056adb..87e5076 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -84,6 +84,8 @@ this.toolStripMenuItem8 = new System.Windows.Forms.ToolStripSeparator(); this.moveUpToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.moveDownToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem9 = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); this.menuStrip1.SuspendLayout(); this.rootContextMenu.SuspendLayout(); this.folderContextMenu.SuspendLayout(); @@ -130,7 +132,7 @@ this.newToolStripMenuItem.Image = global::BookmarkManager.UIResource.file2; this.newToolStripMenuItem.Name = "newToolStripMenuItem"; this.newToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.N))); - this.newToolStripMenuItem.Size = new System.Drawing.Size(146, 22); + this.newToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.newToolStripMenuItem.Text = "&New"; this.newToolStripMenuItem.Click += new System.EventHandler(this.newToolStripMenuItem_Click); // @@ -139,52 +141,52 @@ this.openToolStripMenuItem.Image = global::BookmarkManager.UIResource.folder2; this.openToolStripMenuItem.Name = "openToolStripMenuItem"; this.openToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O))); - this.openToolStripMenuItem.Size = new System.Drawing.Size(146, 22); + this.openToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.openToolStripMenuItem.Text = "&Open"; this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click); // // toolStripMenuItem13 // this.toolStripMenuItem13.Name = "toolStripMenuItem13"; - this.toolStripMenuItem13.Size = new System.Drawing.Size(143, 6); + this.toolStripMenuItem13.Size = new System.Drawing.Size(177, 6); // // closeToolStripMenuItem // this.closeToolStripMenuItem.Name = "closeToolStripMenuItem"; - this.closeToolStripMenuItem.Size = new System.Drawing.Size(146, 22); + this.closeToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.closeToolStripMenuItem.Text = "&Close"; this.closeToolStripMenuItem.Click += new System.EventHandler(this.closeToolStripMenuItem_Click); // // toolStripMenuItem14 // this.toolStripMenuItem14.Name = "toolStripMenuItem14"; - this.toolStripMenuItem14.Size = new System.Drawing.Size(143, 6); + this.toolStripMenuItem14.Size = new System.Drawing.Size(177, 6); // // saveToolStripMenuItem // this.saveToolStripMenuItem.Image = global::BookmarkManager.UIResource.disk2; this.saveToolStripMenuItem.Name = "saveToolStripMenuItem"; this.saveToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S))); - this.saveToolStripMenuItem.Size = new System.Drawing.Size(146, 22); + this.saveToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.saveToolStripMenuItem.Text = "&Save"; this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click); // // saveAsToolStripMenuItem // this.saveAsToolStripMenuItem.Name = "saveAsToolStripMenuItem"; - this.saveAsToolStripMenuItem.Size = new System.Drawing.Size(146, 22); + this.saveAsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.saveAsToolStripMenuItem.Text = "Save &As..."; this.saveAsToolStripMenuItem.Click += new System.EventHandler(this.saveAsToolStripMenuItem_Click); // // toolStripMenuItem15 // this.toolStripMenuItem15.Name = "toolStripMenuItem15"; - this.toolStripMenuItem15.Size = new System.Drawing.Size(143, 6); + this.toolStripMenuItem15.Size = new System.Drawing.Size(177, 6); // // exitToolStripMenuItem2 // this.exitToolStripMenuItem2.Name = "exitToolStripMenuItem2"; - this.exitToolStripMenuItem2.Size = new System.Drawing.Size(146, 22); + this.exitToolStripMenuItem2.Size = new System.Drawing.Size(180, 22); this.exitToolStripMenuItem2.Text = "E&xit"; this.exitToolStripMenuItem2.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); // @@ -201,7 +203,7 @@ this.findToolStripMenuItem.Image = global::BookmarkManager.UIResource.search2; this.findToolStripMenuItem.Name = "findToolStripMenuItem"; this.findToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.F))); - this.findToolStripMenuItem.Size = new System.Drawing.Size(137, 22); + this.findToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.findToolStripMenuItem.Text = "&Find"; this.findToolStripMenuItem.Click += new System.EventHandler(this.findToolStripMenuItem_Click); // @@ -245,6 +247,8 @@ // toolsToolStripMenuItem // this.toolsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripMenuItem9, + this.toolStripSeparator2, this.optionsToolStripMenuItem}); this.toolsToolStripMenuItem.Name = "toolsToolStripMenuItem"; this.toolsToolStripMenuItem.Size = new System.Drawing.Size(46, 20); @@ -255,7 +259,7 @@ this.optionsToolStripMenuItem.Image = global::BookmarkManager.UIResource.cog2; this.optionsToolStripMenuItem.Name = "optionsToolStripMenuItem"; this.optionsToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.F12))); - this.optionsToolStripMenuItem.Size = new System.Drawing.Size(168, 22); + this.optionsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.optionsToolStripMenuItem.Text = "&Options"; this.optionsToolStripMenuItem.Click += new System.EventHandler(this.optionsToolStripMenuItem_Click); // @@ -510,6 +514,18 @@ this.moveDownToolStripMenuItem1.Text = "Move &Down"; this.moveDownToolStripMenuItem1.Click += new System.EventHandler(this.moveDownToolStripMenuItem1_Click); // + // toolStripMenuItem9 + // + this.toolStripMenuItem9.Name = "toolStripMenuItem9"; + this.toolStripMenuItem9.Size = new System.Drawing.Size(180, 22); + this.toolStripMenuItem9.Text = "Update &Icons"; + this.toolStripMenuItem9.Click += new System.EventHandler(this.toolStripMenuItem9_Click); + // + // toolStripSeparator2 + // + this.toolStripSeparator2.Name = "toolStripSeparator2"; + this.toolStripSeparator2.Size = new System.Drawing.Size(177, 6); + // // MainForm // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; @@ -591,6 +607,8 @@ private System.Windows.Forms.ToolStripSeparator toolStripMenuItem8; private System.Windows.Forms.ToolStripMenuItem moveUpToolStripMenuItem1; private System.Windows.Forms.ToolStripMenuItem moveDownToolStripMenuItem1; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem9; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator2; } } diff --git a/MainForm.cs b/MainForm.cs index 9ac27ad..b459cf8 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -27,6 +27,7 @@ namespace FizzyLauncher protected IconDatabase iconDatabase = null; + protected UpdateIconsForm updateIconsForm = null; protected OptionsForm optionsForm = null; protected FindForm findForm = null; @@ -163,6 +164,8 @@ namespace FizzyLauncher ThreadControl.SetEnable(findToolStripMenuItem, false); + ThreadControl.SetEnable(toolStripMenuItem9, false); + ThreadControl.SetEnable(expandAllToolStripMenuItem, false); ThreadControl.SetEnable(collapseAllToolStripMenuItem, false); @@ -175,6 +178,8 @@ namespace FizzyLauncher ThreadControl.SetEnable(findToolStripMenuItem, true); + ThreadControl.SetEnable(toolStripMenuItem9, true); + ThreadControl.SetEnable(expandAllToolStripMenuItem, true); ThreadControl.SetEnable(collapseAllToolStripMenuItem, true); @@ -189,6 +194,8 @@ namespace FizzyLauncher ThreadControl.SetEnable(findToolStripMenuItem, true); + ThreadControl.SetEnable(toolStripMenuItem9, true); + ThreadControl.SetEnable(expandAllToolStripMenuItem, true); ThreadControl.SetEnable(collapseAllToolStripMenuItem, true); @@ -468,6 +475,22 @@ namespace FizzyLauncher } + /// + /// Update icons + /// + /// + /// + private void toolStripMenuItem9_Click(object sender, EventArgs e) + { + if (this.IsBusy) + { + return; + } + + if (updateIconsForm == null) updateIconsForm = new UpdateIconsForm(treeView1, iconDatabase); + updateIconsForm.ShowDialog(); + } + /// /// Options /// @@ -1176,7 +1199,7 @@ namespace FizzyLauncher // retrieve icon from DB if (!string.IsNullOrWhiteSpace(model.SiteAddress)) { - string iconID = Crypto.GetSHA256Hash(model?.SiteAddress); + string iconID = model?.ToHash(); icon = iconDatabase.FindIcon(iconID); } @@ -1184,7 +1207,7 @@ namespace FizzyLauncher BookmarkForm bookmarkForm = new BookmarkForm(model, icon); if (bookmarkForm.ShowDialog() == DialogResult.OK) { - string iconID = Crypto.GetSHA256Hash(bookmarkForm.Model.Item?.SiteAddress); + string iconID = bookmarkForm.Model.Item?.ToHash(); if (!string.IsNullOrWhiteSpace(iconID)) { iconDatabase.AddIcon(iconID, bookmarkForm.Model.Icon); diff --git a/Models/BookmarkItem.cs b/Models/BookmarkItem.cs index 5bc0a3a..7778f78 100644 --- a/Models/BookmarkItem.cs +++ b/Models/BookmarkItem.cs @@ -1,4 +1,5 @@ -using System; +using BookmarkManager; +using System; using System.Text; namespace bzit.bomg.Models @@ -47,5 +48,7 @@ namespace bzit.bomg.Models return sb.ToString(); } + public string ToHash() => Crypto.GetSHA256Hash(this.SiteAddress); + } } \ No newline at end of file diff --git a/Classes/WebParser.cs b/Net/WebParser.cs similarity index 89% rename from Classes/WebParser.cs rename to Net/WebParser.cs index 5c170b5..7f8ec85 100644 --- a/Classes/WebParser.cs +++ b/Net/WebParser.cs @@ -2,6 +2,8 @@ using HtmlAgilityPack; using RyzStudio.Net; using System; +using System.Drawing; +using System.IO; using System.Net; namespace BookmarkManager @@ -9,6 +11,7 @@ namespace BookmarkManager public class WebParser { protected HttpWeb webClient = null; + protected WebClient webClient2 = null; public BookmarkResult RetrieveDetails(string url) @@ -44,6 +47,35 @@ namespace BookmarkManager return rs; } + public Bitmap RetrieveImage(string url) + { + if (string.IsNullOrWhiteSpace(url)) + { + return null; + } + + if (webClient2 == null) webClient2 = new WebClient(); + webClient2.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore); + + try + { + byte[] byteData = webClient2.DownloadData(url); + + if (!RyzStudio.IO.FileType.IsImage(byteData)) + { + throw new Exception("Not a supported image"); + } + + Image img = Image.FromStream(new MemoryStream(byteData)); + + return new Bitmap(img, 16, 16); + } + catch (Exception) + { + return null; + } + } + protected string retrieveSourceCode(string url) { diff --git a/RyzStudio/Windows/Forms/TCustomProgressBar.Designer.cs b/RyzStudio/Windows/Forms/TCustomProgressBar.Designer.cs new file mode 100644 index 0000000..73c344f --- /dev/null +++ b/RyzStudio/Windows/Forms/TCustomProgressBar.Designer.cs @@ -0,0 +1,63 @@ +namespace RyzStudio.Windows.Forms +{ + partial class TCustomProgressBar + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label3 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // label3 + // + this.label3.BackColor = System.Drawing.Color.Transparent; + this.label3.Dock = System.Windows.Forms.DockStyle.Fill; + this.label3.Font = new System.Drawing.Font("Segoe UI", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label3.Location = new System.Drawing.Point(4, 4); + this.label3.Margin = new System.Windows.Forms.Padding(0); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(803, 47); + this.label3.TabIndex = 144; + this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // ProgressBarInner + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.label3); + this.Margin = new System.Windows.Forms.Padding(0); + this.Name = "ProgressBarInner"; + this.Padding = new System.Windows.Forms.Padding(4, 4, 3, 3); + this.Size = new System.Drawing.Size(810, 54); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Label label3; + } +} diff --git a/RyzStudio/Windows/Forms/TCustomProgressBar.cs b/RyzStudio/Windows/Forms/TCustomProgressBar.cs new file mode 100644 index 0000000..1a8493e --- /dev/null +++ b/RyzStudio/Windows/Forms/TCustomProgressBar.cs @@ -0,0 +1,158 @@ +using System; +using System.ComponentModel; +using System.Drawing; +using System.Windows.Forms; + +namespace RyzStudio.Windows.Forms +{ + public partial class TCustomProgressBar : TUserControl + { + protected int minimum = 0; + protected int maximum = 100; + protected int value = 50; + + + public TCustomProgressBar() : base() + { + InitializeComponent(); + + this.Padding = new Padding(0); + } + + + [Category("Data"), Browsable(true)] + public int Minimum + { + get => minimum; + set + { + if (this.InvokeRequired) + { + this.Invoke(new MethodInvoker(() => { + SetMinimum(value); + })); + } + else + { + SetMinimum(value); + } + } + } + + [Category("Data"), Browsable(true)] + public int Maximum + { + get => maximum; + set + { + if (this.InvokeRequired) + { + this.Invoke(new MethodInvoker(() => { + SetMaximum(value); + })); + } + else + { + SetMaximum(value); + } + } + } + + [Category("Data"), Browsable(true)] + public int Value + { + get => value; + set + { + if (this.InvokeRequired) + { + this.Invoke(new MethodInvoker(() => { + SetValue(value); + })); + } + else + { + SetValue(value); + } + } + } + + [Category("Appearance"), Browsable(true)] + public Color BarColour { get; set; } = Color.FromArgb(158, 225, 249); + + [Category("Appearance"), Browsable(true)] + public Color BarTextColour { get => label3.ForeColor; set => label3.ForeColor = value; } + + + protected override void OnPaint(PaintEventArgs e) + { + base.OnPaint(e); + + Rectangle canvas = this.DisplayRectangle; + Graphics g = e.Graphics; + + if (this.Value > 0) + { + decimal result = decimal.Divide(canvas.Width, this.Maximum) * this.Value; + + canvas.Width = (int)Math.Round(result); + + g.FillRectangle(new SolidBrush(this.BarColour), canvas); + } + } + + + public void Reset(int value) + { + this.Minimum = 0; + this.Value = 0; + this.Maximum = value; + } + + protected void UpdateText() => RyzStudio.Windows.Forms.ThreadControl.SetText(label3, string.Format("{0}/{1}", this.Value.ToString(), this.Maximum.ToString())); + + protected void SetMinimum(int value) + { + int m = value; + if (m < 0) m = 0; + if (m > this.Maximum) m = this.Maximum; + if (this.Value < m) this.Value = m; + if (this.value > this.Maximum) this.value = this.Maximum; + + minimum = m; + + UpdateText(); + + this.Invalidate(); + } + + protected void SetMaximum(int value) + { + int m = value; + if (m < 0) m = 0; + if (m < this.Minimum) m = this.Minimum; + if (this.Value > m) this.Value = m; + if (this.value < this.Minimum) this.value = this.Minimum; + + maximum = m; + + UpdateText(); + + this.Invalidate(); + } + + protected void SetValue(int value) + { + int m = value; + if (m < this.Minimum) m = this.Minimum; + if (m > this.Maximum) m = this.Maximum; + + this.value = m; + + UpdateText(); + + this.Invalidate(); + } + + } +} diff --git a/RyzStudio/Windows/Forms/TCustomProgressBar.resx b/RyzStudio/Windows/Forms/TCustomProgressBar.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/RyzStudio/Windows/Forms/TCustomProgressBar.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/RyzStudio/Windows/Forms/ThreadControl.cs b/RyzStudio/Windows/Forms/ThreadControl.cs index ea45b40..dd33b3e 100644 --- a/RyzStudio/Windows/Forms/ThreadControl.cs +++ b/RyzStudio/Windows/Forms/ThreadControl.cs @@ -626,6 +626,20 @@ namespace RyzStudio.Windows.Forms } } + public static void SetValue(ComboBox control, int value) + { + if (control.InvokeRequired) + { + control.Invoke(new MethodInvoker(() => { + control.SelectedIndex = value; + })); + } + else + { + control.SelectedIndex = value; + } + } + public static void SetValue(PictureBox control, Image value) { if (control.InvokeRequired) @@ -641,6 +655,42 @@ namespace RyzStudio.Windows.Forms } } + public static string GetValue(ListBox sender) + { + string rv = string.Empty; + + if (sender.InvokeRequired) + { + sender.Invoke(new MethodInvoker(() => { + rv = (sender.SelectedItem == null) ? string.Empty : sender.SelectedItem.ToString(); + })); + } + else + { + rv = (sender.SelectedItem == null) ? string.Empty : sender.SelectedItem.ToString(); + } + + return rv; + } + + public static int GetValue(ComboBox sender) + { + int rv = -1; + + if (sender.InvokeRequired) + { + sender.Invoke(new MethodInvoker(() => { + rv = sender.SelectedIndex; + })); + } + else + { + rv = sender.SelectedIndex; + } + + return rv; + } + public static void SetVisible(Control control, bool value) { if (control.InvokeRequired) diff --git a/RyzStudio/Windows/ThemedForms/PickerBox/TYesNoPickerBox.cs b/RyzStudio/Windows/ThemedForms/PickerBox/TYesNoPickerBox.cs index 89225ee..e9b0557 100644 --- a/RyzStudio/Windows/ThemedForms/PickerBox/TYesNoPickerBox.cs +++ b/RyzStudio/Windows/ThemedForms/PickerBox/TYesNoPickerBox.cs @@ -1,4 +1,7 @@ -namespace RyzStudio.Windows.ThemedForms +using RyzStudio.Windows.Forms; +using System.Windows.Forms; + +namespace RyzStudio.Windows.ThemedForms { public class TYesNoPickerBox : TPickerBox { @@ -11,7 +14,14 @@ if (this.ComboBox.Items.Count > 0) this.ComboBox.SelectedIndex = 0; } - public bool Value { get => (this.ComboBox.SelectedIndex == 1); set =>this.ComboBox.SelectedIndex = (value ? 1 : 0); } + + public ComboBox InnerControl { get => this.ComboBox; } + + public bool Value + { + get => (ThreadControl.GetValue(this.ComboBox) == 1); + set => ThreadControl.SetValue(this.ComboBox, (value ? 1 : 0)); + } } } diff --git a/RyzStudio/Windows/ThemedForms/TButton.cs b/RyzStudio/Windows/ThemedForms/TButton.cs index e2ce5f0..e3da499 100644 --- a/RyzStudio/Windows/ThemedForms/TButton.cs +++ b/RyzStudio/Windows/ThemedForms/TButton.cs @@ -1,5 +1,6 @@ namespace RyzStudio.Windows.ThemedForms { + using RyzStudio.Windows.Forms; using System; using System.ComponentModel; using System.Drawing; @@ -136,7 +137,7 @@ [Browsable(true)] [Category("Appearance")] - public string LabelText { get => label1.Text; set => label1.Text = value; } + public string LabelText { get => ThreadControl.GetText(label1); set => ThreadControl.SetText(label1, value); } [Browsable(true)] [Category("Appearance")] diff --git a/RyzStudio/Windows/ThemedForms/TProgressBar.cs b/RyzStudio/Windows/ThemedForms/TProgressBar.cs new file mode 100644 index 0000000..d30a566 --- /dev/null +++ b/RyzStudio/Windows/ThemedForms/TProgressBar.cs @@ -0,0 +1,50 @@ +using RyzStudio.Drawing; +using System; +using System.ComponentModel; +using System.Drawing; +using System.Windows.Forms; + +namespace RyzStudio.Windows.ThemedForms +{ + public partial class TProgressBar : RyzStudio.Windows.ThemedForms.TUserControl + { + protected readonly Padding textboxPadding = new Padding(2, 2, 2, 2); + + + public TProgressBar() : base() + { + InitializeComponent(); + + this.Margin = new Padding(10, 6, 10, 6); + this.Font = new Font(this.Font, FontStyle.Regular); + + customProgressBar1.Font = this.Font; + } + + protected override void OnResize(EventArgs e) + { + base.OnResize(e); + + this.Invalidate(); + } + + [Browsable(true), EditorBrowsable(EditorBrowsableState.Advanced)] + [Category("Appearance")] + public RyzStudio.Windows.Forms.TCustomProgressBar InnerControl { get => customProgressBar1; set => customProgressBar1 = value; } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public new Padding Margin { get => base.Margin; set => base.Margin = value; } + + protected override void updateBackground(Graphics g, ThemeStyle style) + { + int b = (styleActive.BorderWidth + 1) + styleActive.BorderPadding; + + this.Padding = new Padding((b + textboxPadding.Left), (b + textboxPadding.Top), ((b - 1) + textboxPadding.Right), ((b - 1) + textboxPadding.Bottom)); + + Rectangoid area = new Rectangoid(this.ClientRectangle, style.BorderRadius, style.BorderWidth); + g.FillPath(new SolidBrush(style.BackColour), area.ToGraphicsPath()); + g.DrawPath(new Pen(new SolidBrush(style.BorderColour), style.BorderWidth), area.ToGraphicsPath()); + } + + } +} \ No newline at end of file diff --git a/RyzStudio/Windows/ThemedForms/TProgressBar.designer.cs b/RyzStudio/Windows/ThemedForms/TProgressBar.designer.cs new file mode 100644 index 0000000..a1bc39f --- /dev/null +++ b/RyzStudio/Windows/ThemedForms/TProgressBar.designer.cs @@ -0,0 +1,65 @@ +namespace RyzStudio.Windows.ThemedForms +{ + partial class TProgressBar + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.customProgressBar1 = new RyzStudio.Windows.Forms.TCustomProgressBar(); + this.SuspendLayout(); + // + // customProgressBar1 + // + this.customProgressBar1.AutoScrollMargin = new System.Drawing.Size(0, 0); + this.customProgressBar1.AutoScrollMinSize = new System.Drawing.Size(0, 0); + this.customProgressBar1.BarColour = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(225)))), ((int)(((byte)(249))))); + this.customProgressBar1.BarTextColour = System.Drawing.SystemColors.ControlText; + this.customProgressBar1.Dock = System.Windows.Forms.DockStyle.Fill; + this.customProgressBar1.Location = new System.Drawing.Point(4, 4); + this.customProgressBar1.Margin = new System.Windows.Forms.Padding(0); + this.customProgressBar1.Maximum = 100; + this.customProgressBar1.Minimum = 0; + this.customProgressBar1.Name = "customProgressBar1"; + this.customProgressBar1.Size = new System.Drawing.Size(121, 25); + this.customProgressBar1.TabIndex = 0; + this.customProgressBar1.Value = 50; + // + // TProgressBar + // + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; + this.Controls.Add(this.customProgressBar1); + this.Name = "TProgressBar"; + this.Padding = new System.Windows.Forms.Padding(4, 4, 3, 3); + this.Size = new System.Drawing.Size(128, 32); + this.ResumeLayout(false); + + } + + #endregion + + private Forms.TCustomProgressBar customProgressBar1; + } +} diff --git a/RyzStudio/Windows/ThemedForms/TProgressBar.resx b/RyzStudio/Windows/ThemedForms/TProgressBar.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/RyzStudio/Windows/ThemedForms/TProgressBar.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/UpdateIconsForm.cs b/UpdateIconsForm.cs new file mode 100644 index 0000000..ebf6c5e --- /dev/null +++ b/UpdateIconsForm.cs @@ -0,0 +1,380 @@ +using BookmarkManager; +using bzit.bomg.Models; +using RyzStudio.Windows.Forms; +using RyzStudio.Windows.ThemedForms; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Net; +using System.Threading.Tasks; +using System.Windows.Forms; +using TProgressBar = RyzStudio.Windows.Forms.TCustomProgressBar; + +namespace FizzyLauncher +{ + public class UpdateIconsForm : TDialogForm + { + private System.Windows.Forms.Label label1; + private TButton button1; + private RyzStudio.Windows.Forms.THorizontalSeparator tHorizontalSeparator1; + private RyzStudio.Windows.Forms.THorizontalSeparator tHorizontalSeparator2; + private Label label2; + private PictureBox pictureBox2; + + private ToolTip toolTip1; + private System.ComponentModel.IContainer components; + + protected BookmarkTreeView bookmarkTreeView = null; + protected IconDatabase iconDatabase = null; + + protected WebParser webParser = null; + protected WebClient webClient = null; + private TYesNoPickerBox pickerBox1; + private TButton button2; + + + protected bool isBusy = false; + private RyzStudio.Windows.ThemedForms.TProgressBar progressBar1; + protected bool requestCancellation = false; + + + public UpdateIconsForm(BookmarkTreeView treeView, IconDatabase database) + { + InitializeComponent(); + + bookmarkTreeView = treeView; + iconDatabase = database; + + pickerBox1.InnerControl.SelectedIndexChanged += comboBox1_SelectedIndexChanged; + + } + + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.label1 = new System.Windows.Forms.Label(); + this.button1 = new RyzStudio.Windows.ThemedForms.TButton(); + this.tHorizontalSeparator1 = new RyzStudio.Windows.Forms.THorizontalSeparator(); + this.tHorizontalSeparator2 = new RyzStudio.Windows.Forms.THorizontalSeparator(); + this.label2 = new System.Windows.Forms.Label(); + this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); + this.pictureBox2 = new System.Windows.Forms.PictureBox(); + this.pickerBox1 = new RyzStudio.Windows.ThemedForms.TYesNoPickerBox(); + this.button2 = new RyzStudio.Windows.ThemedForms.TButton(); + this.progressBar1 = new RyzStudio.Windows.ThemedForms.TProgressBar(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.BackColor = System.Drawing.Color.Transparent; + this.label1.ForeColor = System.Drawing.SystemColors.ControlText; + this.label1.Location = new System.Drawing.Point(10, 21); + this.label1.Margin = new System.Windows.Forms.Padding(0); + this.label1.Name = "label1"; + this.label1.Padding = new System.Windows.Forms.Padding(0, 9, 0, 10); + this.label1.Size = new System.Drawing.Size(154, 34); + this.label1.TabIndex = 153; + this.label1.Text = "Find outstanding icons only"; + this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // button1 + // + this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.button1.BackColor = System.Drawing.Color.Transparent; + this.button1.DefaultImage = null; + this.button1.DownImage = null; + this.button1.IsSelected = false; + this.button1.LabelText = "&Close"; + this.button1.Location = new System.Drawing.Point(241, 469); + this.button1.Margin = new System.Windows.Forms.Padding(10); + this.button1.Name = "button1"; + this.button1.OverImage = null; + this.button1.Padding = new System.Windows.Forms.Padding(4, 4, 3, 3); + this.button1.Size = new System.Drawing.Size(128, 32); + this.button1.TabIndex = 173; + this.button1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.button1_MouseClick); + // + // tHorizontalSeparator1 + // + this.tHorizontalSeparator1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tHorizontalSeparator1.AutoScrollMargin = new System.Drawing.Size(0, 0); + this.tHorizontalSeparator1.AutoScrollMinSize = new System.Drawing.Size(0, 0); + this.tHorizontalSeparator1.BackColor = System.Drawing.Color.Transparent; + this.tHorizontalSeparator1.Location = new System.Drawing.Point(10, 437); + this.tHorizontalSeparator1.Margin = new System.Windows.Forms.Padding(10, 0, 10, 0); + this.tHorizontalSeparator1.MaximumSize = new System.Drawing.Size(4920, 2); + this.tHorizontalSeparator1.MinimumSize = new System.Drawing.Size(0, 22); + this.tHorizontalSeparator1.Name = "tHorizontalSeparator1"; + this.tHorizontalSeparator1.Padding = new System.Windows.Forms.Padding(0, 10, 0, 10); + this.tHorizontalSeparator1.Size = new System.Drawing.Size(364, 22); + this.tHorizontalSeparator1.TabIndex = 188; + // + // tHorizontalSeparator2 + // + this.tHorizontalSeparator2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tHorizontalSeparator2.AutoScrollMargin = new System.Drawing.Size(0, 0); + this.tHorizontalSeparator2.AutoScrollMinSize = new System.Drawing.Size(0, 0); + this.tHorizontalSeparator2.BackColor = System.Drawing.Color.Transparent; + this.tHorizontalSeparator2.Location = new System.Drawing.Point(10, 59); + this.tHorizontalSeparator2.Margin = new System.Windows.Forms.Padding(10, 0, 10, 0); + this.tHorizontalSeparator2.MaximumSize = new System.Drawing.Size(4920, 2); + this.tHorizontalSeparator2.MinimumSize = new System.Drawing.Size(0, 22); + this.tHorizontalSeparator2.Name = "tHorizontalSeparator2"; + this.tHorizontalSeparator2.Padding = new System.Windows.Forms.Padding(0, 10, 0, 10); + this.tHorizontalSeparator2.Size = new System.Drawing.Size(364, 22); + this.tHorizontalSeparator2.TabIndex = 190; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.BackColor = System.Drawing.Color.Transparent; + this.label2.ForeColor = System.Drawing.SystemColors.ControlText; + this.label2.Location = new System.Drawing.Point(10, 85); + this.label2.Margin = new System.Windows.Forms.Padding(0); + this.label2.Name = "label2"; + this.label2.Padding = new System.Windows.Forms.Padding(0, 9, 0, 10); + this.label2.Size = new System.Drawing.Size(52, 34); + this.label2.TabIndex = 195; + this.label2.Text = "Progress"; + this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // pictureBox2 + // + this.pictureBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.pictureBox2.BackColor = System.Drawing.Color.Transparent; + this.pictureBox2.ErrorImage = null; + this.pictureBox2.InitialImage = null; + this.pictureBox2.Location = new System.Drawing.Point(196, 469); + this.pictureBox2.Name = "pictureBox2"; + this.pictureBox2.Size = new System.Drawing.Size(32, 32); + this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; + this.pictureBox2.TabIndex = 202; + this.pictureBox2.TabStop = false; + // + // pickerBox1 + // + this.pickerBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.pickerBox1.BackColor = System.Drawing.Color.Transparent; + this.pickerBox1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.pickerBox1.Location = new System.Drawing.Point(285, 21); + this.pickerBox1.Margin = new System.Windows.Forms.Padding(10, 4, 10, 4); + this.pickerBox1.Name = "pickerBox1"; + this.pickerBox1.Padding = new System.Windows.Forms.Padding(10, 6, 7, 5); + this.pickerBox1.Size = new System.Drawing.Size(84, 34); + this.pickerBox1.SubmitButton = null; + this.pickerBox1.TabIndex = 203; + this.pickerBox1.Value = true; + // + // button2 + // + this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.button2.BackColor = System.Drawing.Color.Transparent; + this.button2.DefaultImage = null; + this.button2.DownImage = null; + this.button2.IsSelected = false; + this.button2.LabelText = "&Run"; + this.button2.Location = new System.Drawing.Point(241, 168); + this.button2.Margin = new System.Windows.Forms.Padding(10); + this.button2.Name = "button2"; + this.button2.OverImage = null; + this.button2.Padding = new System.Windows.Forms.Padding(4, 4, 3, 3); + this.button2.Size = new System.Drawing.Size(128, 32); + this.button2.TabIndex = 205; + this.button2.MouseClick += new System.Windows.Forms.MouseEventHandler(this.button2_MouseClick); + // + // progressBar1 + // + this.progressBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.progressBar1.BackColor = System.Drawing.Color.Transparent; + this.progressBar1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.progressBar1.Location = new System.Drawing.Point(10, 119); + this.progressBar1.Margin = new System.Windows.Forms.Padding(10, 6, 10, 6); + this.progressBar1.Name = "progressBar1"; + this.progressBar1.Padding = new System.Windows.Forms.Padding(6, 6, 5, 5); + this.progressBar1.Size = new System.Drawing.Size(359, 33); + this.progressBar1.TabIndex = 206; + // + // UpdateIconsForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(384, 521); + this.Controls.Add(this.progressBar1); + this.Controls.Add(this.button2); + this.Controls.Add(this.pickerBox1); + this.Controls.Add(this.pictureBox2); + this.Controls.Add(this.label2); + this.Controls.Add(this.tHorizontalSeparator2); + this.Controls.Add(this.tHorizontalSeparator1); + this.Controls.Add(this.button1); + this.Controls.Add(this.label1); + this.KeyPreview = true; + this.MinimumSize = new System.Drawing.Size(400, 560); + this.Name = "UpdateIconsForm"; + this.Text = "Update Icons"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + + comboBox1_SelectedIndexChanged(null, null); + } + + protected override void OnShown(EventArgs e) + { + base.OnShown(e); + + this.DialogResult = DialogResult.None; + } + + protected override void OnClosing(CancelEventArgs e) + { + base.OnClosing(e); + + if (IsBusy) + { + e.Cancel = true; + } + } + + protected override void OnKeyDown(KeyEventArgs e) + { + if (e.KeyCode == Keys.Escape) + { + if (!IsBusy) + { + this.Close(); + } + } + + base.OnKeyDown(e); + } + + + protected bool IsBusy + { + get => isBusy; + set + { + isBusy = value; + + ThreadControl.SetValue(pictureBox2, (isBusy ? AppResource.loading_block : null)); + + ThreadControl.SetEnable(pickerBox1, !isBusy); + button2.LabelText = (isBusy ? "&Stop" : "&Run"); + } + } + + + private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) + { + if (IsBusy) + { + return; + } + + List bookmarkList = GetBookmarkFilteredList(); + + progressBar1.InnerControl.Reset(bookmarkList.Count); + } + + private async void button2_MouseClick(object sender, MouseEventArgs e) + { + await Task.Run(() => + { + if (IsBusy) + { + requestCancellation = true; + return; + } + + IsBusy = true; + + WebParser webParser = new WebParser(); + List bookmarkList = GetBookmarkFilteredList(); + + progressBar1.InnerControl.Reset(bookmarkList.Count); + + for (int i=0; i GetBookmarkFilteredList() + { + List rs = bookmarkTreeView.GetBookmarkList(); + + // remove empty + for (int i = 0; i < rs.Count; i++) + { + if (string.IsNullOrWhiteSpace(rs[i].SiteAddress)) + { + rs.Remove(rs[i]); + } + } + + if (pickerBox1.Value) + { + for (int i = 0; i < rs.Count; i++) + { + if (iconDatabase.HasIcon(rs[i].ToHash())) + { + rs.Remove(rs[i]); + } + } + } + + return rs; + } + + + } +} \ No newline at end of file diff --git a/UpdateIconsForm.resx b/UpdateIconsForm.resx new file mode 100644 index 0000000..57523cc --- /dev/null +++ b/UpdateIconsForm.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Windows/Forms/BookmarkTreeView.cs b/Windows/Forms/BookmarkTreeView.cs index 238f714..2cab676 100644 --- a/Windows/Forms/BookmarkTreeView.cs +++ b/Windows/Forms/BookmarkTreeView.cs @@ -880,7 +880,7 @@ namespace RyzStudio.Windows.Forms if (item == null) return (int)IconSet.Default; if (string.IsNullOrWhiteSpace(item.SiteAddress)) return (int)IconSet.Default; - string iconID = Crypto.GetSHA256Hash(item?.SiteAddress); + string iconID = item?.ToHash(); Image image = this.IconDatabase.FindIcon(iconID); if (image == null) @@ -888,10 +888,7 @@ namespace RyzStudio.Windows.Forms return (int)IconSet.Default; } - if (this.ImageList.Images.ContainsKey(iconID)) - { - this.ImageList.Images.RemoveByKey(iconID); - } + if (this.ImageList.Images.ContainsKey(iconID)) this.ImageList.Images.RemoveByKey(iconID); ThreadControl.Add(this, this.ImageList, iconID, image);