From aecc5ac0431f5c323319e8d47c6f3d6383eb11ab Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 7 Apr 2019 18:29:33 +0100 Subject: [PATCH] Changed: improved source code parsing for title, description and favicon --- BookmarkEditForm.Designer.cs | 346 ++++++++++----------- BookmarkEditForm.cs | 16 +- BookmarkItem.cs | 508 ++++++++++++++++++++----------- BookmarkTreeView.cs | 24 +- MainForm.cs | 12 +- Properties/AssemblyInfo.cs | 2 +- Properties/Resources.Designer.cs | 2 +- Properties/Resources.resx | 2 +- SessionFileFormat.cs | 4 +- app.config | 3 - bomg.csproj | 2 - bomg.sln | 31 ++ 12 files changed, 558 insertions(+), 394 deletions(-) delete mode 100644 app.config create mode 100644 bomg.sln diff --git a/BookmarkEditForm.Designer.cs b/BookmarkEditForm.Designer.cs index fe91676..8ad9413 100644 --- a/BookmarkEditForm.Designer.cs +++ b/BookmarkEditForm.Designer.cs @@ -28,182 +28,182 @@ namespace bzit.bomg /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(BookmarkEditForm)); - this.label1 = new System.Windows.Forms.Label(); - this.tbxAddress = new System.Windows.Forms.TextBox(); - this.tbxName = new System.Windows.Forms.TextBox(); - this.label2 = new System.Windows.Forms.Label(); - this.tbxDescription = new System.Windows.Forms.TextBox(); - this.oToolTip = new System.Windows.Forms.ToolTip(this.components); - this.label3 = new System.Windows.Forms.Label(); - this.pbxIcon = new System.Windows.Forms.PictureBox(); - this.pictureBox1 = new System.Windows.Forms.PictureBox(); - this.button1 = new RyzStudio.Windows.Forms.BigButton(); - this.btnSave = new RyzStudio.Windows.Forms.BigButton(); - ((System.ComponentModel.ISupportInitialize)(this.pbxIcon)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); - this.SuspendLayout(); - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(12, 12); - this.label1.Margin = new System.Windows.Forms.Padding(3); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(39, 13); - this.label1.TabIndex = 0; - this.label1.Text = "Name:"; - // - // tbxAddress - // - this.tbxAddress.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + this.components = new System.ComponentModel.Container(); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(BookmarkEditForm)); + this.label1 = new System.Windows.Forms.Label(); + this.tbxAddress = new System.Windows.Forms.TextBox(); + this.tbxName = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.tbxDescription = new System.Windows.Forms.TextBox(); + this.oToolTip = new System.Windows.Forms.ToolTip(this.components); + this.label3 = new System.Windows.Forms.Label(); + this.pbxIcon = new System.Windows.Forms.PictureBox(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.button1 = new RyzStudio.Windows.Forms.BigButton(); + this.btnSave = new RyzStudio.Windows.Forms.BigButton(); + ((System.ComponentModel.ISupportInitialize)(this.pbxIcon)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 12); + this.label1.Margin = new System.Windows.Forms.Padding(3); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(39, 13); + this.label1.TabIndex = 0; + this.label1.Text = "Name:"; + // + // tbxAddress + // + this.tbxAddress.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.tbxAddress.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(51)))), ((int)(((byte)(51))))); - this.tbxAddress.Location = new System.Drawing.Point(12, 78); - this.tbxAddress.MaxLength = 4096; - this.tbxAddress.Name = "tbxAddress"; - this.tbxAddress.Size = new System.Drawing.Size(240, 22); - this.tbxAddress.TabIndex = 0; - this.tbxAddress.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.textBox_PreviewKeyDown); - // - // tbxName - // - this.tbxName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + this.tbxAddress.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(51)))), ((int)(((byte)(51))))); + this.tbxAddress.Location = new System.Drawing.Point(12, 78); + this.tbxAddress.MaxLength = 4096; + this.tbxAddress.Name = "tbxAddress"; + this.tbxAddress.Size = new System.Drawing.Size(240, 22); + this.tbxAddress.TabIndex = 1; + this.tbxAddress.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.textBox_PreviewKeyDown); + // + // tbxName + // + this.tbxName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.tbxName.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(51)))), ((int)(((byte)(51))))); - this.tbxName.Location = new System.Drawing.Point(12, 31); - this.tbxName.MaxLength = 4096; - this.tbxName.Name = "tbxName"; - this.tbxName.Size = new System.Drawing.Size(212, 22); - this.tbxName.TabIndex = 1; - this.tbxName.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.textBox_PreviewKeyDown); - // - // label2 - // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(12, 59); - this.label2.Margin = new System.Windows.Forms.Padding(3); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(51, 13); - this.label2.TabIndex = 4; - this.label2.Text = "Address:"; - // - // tbxDescription - // - this.tbxDescription.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + this.tbxName.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(51)))), ((int)(((byte)(51))))); + this.tbxName.Location = new System.Drawing.Point(12, 31); + this.tbxName.MaxLength = 4096; + this.tbxName.Name = "tbxName"; + this.tbxName.Size = new System.Drawing.Size(212, 22); + this.tbxName.TabIndex = 0; + this.tbxName.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.textBox_PreviewKeyDown); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 59); + this.label2.Margin = new System.Windows.Forms.Padding(3); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(51, 13); + this.label2.TabIndex = 4; + this.label2.Text = "Address:"; + // + // tbxDescription + // + this.tbxDescription.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.tbxDescription.BackColor = System.Drawing.SystemColors.Window; - this.tbxDescription.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(51)))), ((int)(((byte)(51))))); - this.tbxDescription.Location = new System.Drawing.Point(12, 125); - this.tbxDescription.MaxLength = 4096; - this.tbxDescription.Multiline = true; - this.tbxDescription.Name = "tbxDescription"; - this.tbxDescription.Size = new System.Drawing.Size(240, 84); - this.tbxDescription.TabIndex = 2; - this.tbxDescription.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.textBox_PreviewKeyDown); - // - // oToolTip - // - this.oToolTip.Active = false; - this.oToolTip.BackColor = System.Drawing.Color.IndianRed; - // - // label3 - // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(12, 106); - this.label3.Margin = new System.Windows.Forms.Padding(3); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(69, 13); - this.label3.TabIndex = 55; - this.label3.Text = "Description:"; - // - // pbxIcon - // - this.pbxIcon.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.pbxIcon.BackColor = System.Drawing.SystemColors.Window; - this.pbxIcon.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; - this.pbxIcon.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.pbxIcon.ErrorImage = null; - this.pbxIcon.InitialImage = null; - this.pbxIcon.Location = new System.Drawing.Point(230, 31); - this.pbxIcon.Name = "pbxIcon"; - this.pbxIcon.Size = new System.Drawing.Size(22, 22); - this.pbxIcon.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; - this.pbxIcon.TabIndex = 57; - this.pbxIcon.TabStop = false; - // - // pictureBox1 - // - this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.pictureBox1.BackColor = System.Drawing.Color.Transparent; - this.pictureBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; - this.pictureBox1.ErrorImage = null; - this.pictureBox1.InitialImage = null; - this.pictureBox1.Location = new System.Drawing.Point(12, 227); - this.pictureBox1.Name = "pictureBox1"; - this.pictureBox1.Size = new System.Drawing.Size(32, 32); - this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; - this.pictureBox1.TabIndex = 60; - this.pictureBox1.TabStop = false; - // - // button1 - // - this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.button1.BackColor = System.Drawing.Color.WhiteSmoke; - this.button1.Location = new System.Drawing.Point(118, 227); - this.button1.MaximumSize = new System.Drawing.Size(120, 32); - this.button1.MinimumSize = new System.Drawing.Size(32, 32); - this.button1.Name = "button1"; - this.button1.Padding = new System.Windows.Forms.Padding(4); - this.button1.Size = new System.Drawing.Size(32, 32); - this.button1.TabIndex = 4; - this.button1.Value = ""; - this.button1.Click += new System.EventHandler(this.btnRetrievePage_Click); - // - // btnSave - // - this.btnSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.btnSave.BackColor = System.Drawing.Color.WhiteSmoke; - this.btnSave.Location = new System.Drawing.Point(156, 227); - this.btnSave.MaximumSize = new System.Drawing.Size(120, 32); - this.btnSave.MinimumSize = new System.Drawing.Size(32, 32); - this.btnSave.Name = "btnSave"; - this.btnSave.Padding = new System.Windows.Forms.Padding(4); - this.btnSave.Size = new System.Drawing.Size(96, 32); - this.btnSave.TabIndex = 3; - this.btnSave.Value = "&OK"; - this.btnSave.Click += new System.EventHandler(this.btnSave_Click); - // - // BookmarkEditForm - // - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; - this.BackColor = System.Drawing.Color.White; - this.ClientSize = new System.Drawing.Size(264, 271); - this.Controls.Add(this.button1); - this.Controls.Add(this.pictureBox1); - this.Controls.Add(this.pbxIcon); - this.Controls.Add(this.tbxDescription); - this.Controls.Add(this.label3); - this.Controls.Add(this.tbxName); - this.Controls.Add(this.label1); - this.Controls.Add(this.tbxAddress); - this.Controls.Add(this.btnSave); - this.Controls.Add(this.label2); - this.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; - this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "BookmarkEditForm"; - this.ShowInTaskbar = false; - this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "Edit Bookmark"; - ((System.ComponentModel.ISupportInitialize)(this.pbxIcon)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); + this.tbxDescription.BackColor = System.Drawing.SystemColors.Window; + this.tbxDescription.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(51)))), ((int)(((byte)(51))))); + this.tbxDescription.Location = new System.Drawing.Point(12, 125); + this.tbxDescription.MaxLength = 4096; + this.tbxDescription.Multiline = true; + this.tbxDescription.Name = "tbxDescription"; + this.tbxDescription.Size = new System.Drawing.Size(240, 84); + this.tbxDescription.TabIndex = 2; + this.tbxDescription.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.textBox_PreviewKeyDown); + // + // oToolTip + // + this.oToolTip.Active = false; + this.oToolTip.BackColor = System.Drawing.Color.IndianRed; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(12, 106); + this.label3.Margin = new System.Windows.Forms.Padding(3); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(69, 13); + this.label3.TabIndex = 55; + this.label3.Text = "Description:"; + // + // pbxIcon + // + this.pbxIcon.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.pbxIcon.BackColor = System.Drawing.SystemColors.Window; + this.pbxIcon.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; + this.pbxIcon.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.pbxIcon.ErrorImage = null; + this.pbxIcon.InitialImage = null; + this.pbxIcon.Location = new System.Drawing.Point(230, 31); + this.pbxIcon.Name = "pbxIcon"; + this.pbxIcon.Size = new System.Drawing.Size(22, 22); + this.pbxIcon.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; + this.pbxIcon.TabIndex = 57; + this.pbxIcon.TabStop = false; + // + // pictureBox1 + // + this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.pictureBox1.BackColor = System.Drawing.Color.Transparent; + this.pictureBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; + this.pictureBox1.ErrorImage = null; + this.pictureBox1.InitialImage = null; + this.pictureBox1.Location = new System.Drawing.Point(12, 227); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(32, 32); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; + this.pictureBox1.TabIndex = 60; + this.pictureBox1.TabStop = false; + // + // button1 + // + this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.button1.BackColor = System.Drawing.Color.WhiteSmoke; + this.button1.Location = new System.Drawing.Point(118, 227); + this.button1.MaximumSize = new System.Drawing.Size(120, 32); + this.button1.MinimumSize = new System.Drawing.Size(32, 32); + this.button1.Name = "button1"; + this.button1.Padding = new System.Windows.Forms.Padding(4); + this.button1.Size = new System.Drawing.Size(32, 32); + this.button1.TabIndex = 3; + this.button1.Value = ""; + this.button1.Click += new System.EventHandler(this.btnRetrievePage_Click); + // + // btnSave + // + this.btnSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnSave.BackColor = System.Drawing.Color.WhiteSmoke; + this.btnSave.Location = new System.Drawing.Point(156, 227); + this.btnSave.MaximumSize = new System.Drawing.Size(120, 32); + this.btnSave.MinimumSize = new System.Drawing.Size(32, 32); + this.btnSave.Name = "btnSave"; + this.btnSave.Padding = new System.Windows.Forms.Padding(4); + this.btnSave.Size = new System.Drawing.Size(96, 32); + this.btnSave.TabIndex = 4; + this.btnSave.Value = "&OK"; + this.btnSave.Click += new System.EventHandler(this.btnSave_Click); + // + // BookmarkEditForm + // + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; + this.BackColor = System.Drawing.Color.White; + this.ClientSize = new System.Drawing.Size(264, 271); + this.Controls.Add(this.button1); + this.Controls.Add(this.pictureBox1); + this.Controls.Add(this.pbxIcon); + this.Controls.Add(this.tbxDescription); + this.Controls.Add(this.label3); + this.Controls.Add(this.tbxName); + this.Controls.Add(this.label1); + this.Controls.Add(this.tbxAddress); + this.Controls.Add(this.btnSave); + this.Controls.Add(this.label2); + this.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "BookmarkEditForm"; + this.ShowInTaskbar = false; + this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Edit Bookmark"; + ((System.ComponentModel.ISupportInitialize)(this.pbxIcon)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); } diff --git a/BookmarkEditForm.cs b/BookmarkEditForm.cs index 25f3c02..a707cd9 100644 --- a/BookmarkEditForm.cs +++ b/BookmarkEditForm.cs @@ -36,7 +36,7 @@ namespace bzit.bomg { bookmarkItem = (BookmarkItem)parentNode.Tag; tbxName.Text = bookmarkItem.GetName(); - tbxAddress.Text = bookmarkItem.Address; + tbxAddress.Text = bookmarkItem.SiteAddress; tbxDescription.Text = bookmarkItem.Description; if (parentNode.TreeView.ImageList != null) @@ -125,12 +125,12 @@ namespace bzit.bomg } bookmarkItem.ChangeName(tbxName.Text.Trim()); - bookmarkItem.Address = tbxAddress.Text.Trim(); + bookmarkItem.SiteAddress = tbxAddress.Text.Trim(); bookmarkItem.Description = tbxDescription.Text.Trim(); parentNode.Text = tbxName.Text.Trim(); //// parentNode.ImageIndex = parentNode.SelectedImageIndex = 3; - parentNode.ToolTipText = string.Concat(bookmarkItem.Address, Environment.NewLine, bookmarkItem.Description).Trim(); + parentNode.ToolTipText = string.Concat(bookmarkItem.SiteAddress, Environment.NewLine, bookmarkItem.Description).Trim(); parentNode.Tag = bookmarkItem; BookmarkTreeView bookmarkTreeView = (BookmarkTreeView)parentNode.TreeView; @@ -144,13 +144,13 @@ namespace bzit.bomg protected void bookmarkItem_OnRetrieveCompleted(BookmarkItem sender, bool hasError, string message) { - if (string.IsNullOrEmpty(sender.TempName)) + if (string.IsNullOrEmpty(sender.SiteName)) { if (MessageBox.Show("The page could not be retrieved or the title is blank. Do you want to keep your original title?", "Keep original?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { - bookmarkItem.TempName = sender.TempName; + bookmarkItem.SiteName = sender.SiteName; - tbxName.Text = bookmarkItem.TempName; + tbxName.Text = bookmarkItem.SiteName; // don't replace with blank if (!string.IsNullOrEmpty(sender.Description)) @@ -161,9 +161,9 @@ namespace bzit.bomg } else { - bookmarkItem.TempName = sender.TempName; + bookmarkItem.SiteName = sender.SiteName; - tbxName.Text = bookmarkItem.TempName; + tbxName.Text = bookmarkItem.SiteName; // don't replace with blank if (!string.IsNullOrEmpty(sender.Description)) diff --git a/BookmarkItem.cs b/BookmarkItem.cs index 444cb2b..2892057 100644 --- a/BookmarkItem.cs +++ b/BookmarkItem.cs @@ -1,9 +1,11 @@ -using System; +using HtmlAgilityPack; +using System; using System.ComponentModel; using System.Drawing; using System.IO; using System.Net; using System.Windows.Forms; +using HtmlDocument = HtmlAgilityPack.HtmlDocument; namespace bzit.bomg { @@ -11,9 +13,22 @@ namespace bzit.bomg { public delegate void RetrieveCompleted(BookmarkItem sender, bool hasError, string message); - protected const char pathSeparator = '|'; + public RetrieveCompleted OnRetrieveCompleted { get; set; } = null; - protected TreeNode treeNode = null; + public TreeNode TreeViewNode { get; protected set; } + + public byte[] IconData { get; set; } = null; + + public string SiteName { get; set; } = null; + public string SiteAddress { get; set; } + public string Description { get; set; } + public string IconAddress { get; protected set; } + public string Fullpath { get; set; } + public string Created { get; set; } + + protected const char pathSeparator = '|'; + + //protected TreeNode treeNode = null; protected BackgroundWorker mainThread = null; protected bool hasRetrieveError = false; @@ -28,7 +43,7 @@ namespace bzit.bomg { string rv = ""; rv += "Name=" + this.Fullpath + Environment.NewLine; - rv += "Address=" + this.Address + Environment.NewLine; + rv += "Address=" + this.SiteAddress + Environment.NewLine; rv += "Description=" + this.Description + Environment.NewLine; rv += "Created=" + this.Created?.Trim(); @@ -37,18 +52,18 @@ namespace bzit.bomg #region public properties - public TreeNode TreeViewNode - { - get - { - return this.treeNode; - } + + //{ + // get + // { + // return this.treeNode; + // } - set - { - this.treeNode = value; - } - } + // set + // { + // this.treeNode = value; + // } + //} public Bitmap Icon { @@ -71,20 +86,7 @@ namespace bzit.bomg } } - [DefaultValue(null)] - public byte[] IconData { get; set; } - public string Created { get; set; } - - public string TempName { get; set; } - - public string Fullpath { get; set; } - - public string IconAddress { get; set; } - - public string Address { get; set; } - - public string Description { get; set; } #endregion @@ -93,7 +95,7 @@ namespace bzit.bomg public void Clear() { this.Fullpath = string.Empty; - this.Address = string.Empty; + this.SiteAddress = string.Empty; this.Description = string.Empty; this.Created = string.Empty; @@ -110,17 +112,17 @@ namespace bzit.bomg { if (this.Fullpath.Contains(pathSeparator.ToString())) { - return PathDecode(this.Fullpath.Substring(this.Fullpath.LastIndexOf(pathSeparator) + 1)).Trim(); + return decodePath(this.Fullpath.Substring(this.Fullpath.LastIndexOf(pathSeparator) + 1)).Trim(); } - return PathDecode(this.Fullpath).Trim(); + return decodePath(this.Fullpath).Trim(); } public void ChangeName(string newName) { string prefix = (this.Fullpath.Contains(pathSeparator.ToString()) ? this.Fullpath.Substring(0, this.Fullpath.IndexOf(pathSeparator)).Trim() : string.Empty); - this.Fullpath = string.Concat(prefix, pathSeparator, PathEncode(newName.Trim())); + this.Fullpath = string.Concat(prefix, pathSeparator, encodePath(newName.Trim())); } public void GetFaviconAddress() @@ -137,7 +139,7 @@ namespace bzit.bomg try { - sourceCode = webClient.DownloadString(this.Address); + sourceCode = webClient.DownloadString(this.SiteAddress); } catch (Exception exc) { @@ -149,67 +151,98 @@ namespace bzit.bomg HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument(); document.LoadHtml(sourceCode); - // parse icon - HtmlAgilityPack.HtmlNodeCollection hnc = document.DocumentNode.SelectNodes("//link"); - if (hnc != null) - { - foreach (HtmlAgilityPack.HtmlNode node in hnc) - { - if (node.Attributes["rel"] == null) - { - continue; - } + // favicon + this.IconAddress = parseSiteIcon(document); + if (!string.IsNullOrWhiteSpace(this.IconAddress)) + { + Uri iconAddressURI; + bool rv = Uri.TryCreate(new Uri(this.SiteAddress), this.IconAddress, out iconAddressURI); + if (rv) + { + this.IconAddress = iconAddressURI.ToString(); + } + } - string nodeAttr = node.Attributes["rel"].Value.Trim(); - if (nodeAttr.ToLower().Contains("icon")) - { - if (!string.IsNullOrEmpty(this.IconAddress)) - { - continue; - } + // load favicon image + if (!string.IsNullOrEmpty(this.IconAddress)) + { + try + { + this.IconData = webClient.DownloadData(this.IconAddress); - if (node.Attributes["href"] != null) - { - Uri iconPath; - bool rv = Uri.TryCreate(new Uri(this.Address), WebUtility.HtmlDecode(node.Attributes["href"].Value).Trim(), out iconPath); - if (rv) - { - this.IconAddress = iconPath.ToString(); - } + if (!RyzStudio.IO.FileType.IsImage(this.IconData)) + { + this.IconData = null; + } + } + catch + { + this.IconData = null; + this.IconAddress = null; + } + } - break; - } - } - } - } + //// parse icon + //HtmlAgilityPack.HtmlNodeCollection hnc = document.DocumentNode.SelectNodes("//link"); + // if (hnc != null) + // { + // foreach (HtmlAgilityPack.HtmlNode node in hnc) + // { + // if (node.Attributes["rel"] == null) + // { + // continue; + // } - // default favicon - if (string.IsNullOrEmpty(this.IconAddress)) - { - Uri iconPath; - if (Uri.TryCreate(new Uri(this.Address), "/favicon.ico", out iconPath)) - { - this.IconAddress = iconPath.ToString(); - } - } + // string nodeAttr = node.Attributes["rel"].Value.Trim(); + // if (nodeAttr.ToLower().Contains("icon")) + // { + // if (!string.IsNullOrEmpty(this.IconAddress)) + // { + // continue; + // } - // load icon image - if (!string.IsNullOrEmpty(this.IconAddress)) - { - try - { - this.IconData = webClient.DownloadData(this.IconAddress); + // if (node.Attributes["href"] != null) + // { + // Uri iconPath; + // bool rv = Uri.TryCreate(new Uri(this.SiteAddress), WebUtility.HtmlDecode(node.Attributes["href"].Value).Trim(), out iconPath); + // if (rv) + // { + // this.IconAddress = iconPath.ToString(); + // } - if (!RyzStudio.IO.FileType.IsImage(this.IconData)) - { - this.IconData = null; - } - } - catch - { - // do nothing - } - } + // break; + // } + // } + // } + // } + + // // default favicon + // if (string.IsNullOrEmpty(this.IconAddress)) + // { + // Uri iconPath; + // if (Uri.TryCreate(new Uri(this.SiteAddress), "/favicon.ico", out iconPath)) + // { + // this.IconAddress = iconPath.ToString(); + // } + // } + + // // load icon image + // if (!string.IsNullOrEmpty(this.IconAddress)) + // { + // try + // { + // this.IconData = webClient.DownloadData(this.IconAddress); + + // if (!RyzStudio.IO.FileType.IsImage(this.IconData)) + // { + // this.IconData = null; + // } + // } + // catch + // { + // // do nothing + // } + // } } public void RetrieveAsync() @@ -229,17 +262,12 @@ namespace bzit.bomg return; } - this.Address = address; + this.SiteAddress = address; this.mainThread.RunWorkerAsync(); } #endregion - #region events & delegate - - public RetrieveCompleted OnRetrieveCompleted = null; - - #endregion protected void retrieveWorker_DoWork(object sender, DoWorkEventArgs e) { @@ -254,11 +282,11 @@ namespace bzit.bomg WebClient webClient = new WebClient(); webClient.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore); - string sourceCode = string.Empty; + string sourceCode = string.Empty; try { - sourceCode = webClient.DownloadString(this.Address); + sourceCode = webClient.DownloadString(this.SiteAddress); } catch (Exception exc) { @@ -267,92 +295,28 @@ namespace bzit.bomg return; } - HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument(); + HtmlDocument document = new HtmlDocument(); document.LoadHtml(sourceCode); - // parse title - HtmlAgilityPack.HtmlNodeCollection hnc = document.DocumentNode.SelectNodes("//title"); - if (hnc != null) - { - if (hnc.Count > 0) - { - this.TempName = WebUtility.HtmlDecode(hnc[0].InnerHtml).Trim(); - } - } + // title + this.SiteName = parseSiteTitle(document); - // parse description - hnc = document.DocumentNode.SelectNodes("//meta"); - if (hnc != null) - { - foreach (HtmlAgilityPack.HtmlNode node in hnc) - { - if (node.Attributes["name"] == null) - { - continue; - } + // description + this.Description = parseSiteDescription(document); - string nodeAttr = node.Attributes["name"].Value.Trim(); - if (nodeAttr.Equals("description", StringComparison.CurrentCultureIgnoreCase)) - { - if (!string.IsNullOrEmpty(this.Description)) - { - continue; - } + // favicon + this.IconAddress = parseSiteIcon(document); + if (!string.IsNullOrWhiteSpace(this.IconAddress)) + { + Uri iconAddressURI; + bool rv = Uri.TryCreate(new Uri(this.SiteAddress), this.IconAddress, out iconAddressURI); + if (rv) + { + this.IconAddress = iconAddressURI.ToString(); + } + } - if (node.Attributes["content"] != null) - { - this.Description = WebUtility.HtmlDecode(node.Attributes["content"].Value).Trim(); - break; - } - } - } - } - - // parse icon - hnc = document.DocumentNode.SelectNodes("//link"); - if (hnc != null) - { - foreach (HtmlAgilityPack.HtmlNode node in hnc) - { - if (node.Attributes["rel"] == null) - { - continue; - } - - string nodeAttr = node.Attributes["rel"].Value.Trim(); - if (nodeAttr.ToLower().Contains("icon")) - { - if (!string.IsNullOrEmpty(this.IconAddress)) - { - continue; - } - - if (node.Attributes["href"] != null) - { - Uri iconPath; - bool rv = Uri.TryCreate(new Uri(this.Address), WebUtility.HtmlDecode(node.Attributes["href"].Value).Trim(), out iconPath); - if (rv) - { - this.IconAddress = iconPath.ToString(); - } - - break; - } - } - } - } - - // default favicon - if (string.IsNullOrEmpty(this.IconAddress)) - { - Uri iconPath; - if (Uri.TryCreate(new Uri(this.Address), "/favicon.ico", out iconPath)) - { - this.IconAddress = iconPath.ToString(); - } - } - - // load icon image + // load favicon image if (!string.IsNullOrEmpty(this.IconAddress)) { try @@ -366,8 +330,9 @@ namespace bzit.bomg } catch { - // do nothing - } + this.IconData = null; + this.IconAddress = null; + } } } @@ -376,11 +341,184 @@ namespace bzit.bomg this.OnRetrieveCompleted?.Invoke(this, hasRetrieveError, retrieveErrorMessage); } -// protected string CustomDecode(string text) { return WebUtility.HtmlDecode(text); } + protected string encodePath(string text) => System.Web.HttpUtility.UrlEncode(text); - ////protected string PathEncode(string text) { return RyzStudio.String.EncodeTo64(text); } - ////protected string PathDecode(string text) { return RyzStudio.String.DecodeFrom64(text); } - protected string PathEncode(string text) { return System.Web.HttpUtility.UrlEncodeUnicode(text); } - protected string PathDecode(string text) { return System.Web.HttpUtility.UrlDecode(text); } - } + protected string decodePath(string text) => System.Web.HttpUtility.UrlDecode(text); + + protected string parseTagValue(HtmlDocument doc, string xpath, string defaultValue = "") + { + HtmlNodeCollection hnc = doc.DocumentNode.SelectNodes(xpath); + if (hnc == null) + { + return defaultValue; + } + + if (hnc.Count <= 0) + { + return defaultValue; + } + + foreach (HtmlNode hn in hnc) + { + if (string.IsNullOrWhiteSpace(hn.InnerHtml)) + { + continue; + } + + string rs = WebUtility.HtmlDecode(hn.InnerHtml)?.Replace("\r", "")?.Replace("\n", " ")?.Trim(); + if (string.IsNullOrWhiteSpace(rs)) + { + continue; + } + + return rs; + } + + return defaultValue; + } + + protected string parseTagValue_Attr(HtmlDocument doc, string xpath, string attr, string defaultValue = "") + { + HtmlNodeCollection hnc = doc.DocumentNode.SelectNodes(xpath); + if (hnc == null) + { + return defaultValue; + } + + if (hnc.Count <= 0) + { + return defaultValue; + } + + foreach (HtmlNode hn in hnc) + { + if (hn.Attributes[attr] == null) + { + continue; + } + + if (string.IsNullOrWhiteSpace(hn.Attributes[attr].Value)) + { + continue; + } + + return System.Web.HttpUtility.HtmlDecode(hn.Attributes[attr].Value?.Trim()); + } + + return defaultValue; + } + + protected string parseSiteTitle(HtmlDocument doc) + { + string rs = null; + + if (string.IsNullOrWhiteSpace(rs)) + { + rs = parseTagValue(doc, "//title", string.Empty); + } + + if (string.IsNullOrWhiteSpace(rs)) + { + rs = parseTagValue_Attr(doc, "//meta[@property='og:title']", "content", string.Empty); + } + + if (string.IsNullOrWhiteSpace(rs)) + { + rs = parseTagValue_Attr(doc, "//meta[@name='twitter:title']", "content", string.Empty); + } + + if (string.IsNullOrWhiteSpace(rs)) + { + rs = parseTagValue_Attr(doc, "//meta[@property='og:site_name']", "content", string.Empty); + } + + if (string.IsNullOrWhiteSpace(rs)) + { + rs = parseTagValue_Attr(doc, "//meta[@itemprop='name']", "content", string.Empty); + } + + return rs; + } + + protected string parseSiteDescription(HtmlDocument doc) + { + string rs = null; + + if (string.IsNullOrWhiteSpace(rs)) + { + rs = parseTagValue_Attr(doc, "//meta[@name='description']", "content", string.Empty); + } + + if (string.IsNullOrWhiteSpace(rs)) + { + rs = parseTagValue_Attr(doc, "//meta[@property='og:description']", "content", string.Empty); + } + + if (string.IsNullOrWhiteSpace(rs)) + { + rs = parseTagValue_Attr(doc, "//meta[@name='twitter:description']", "content", string.Empty); + } + + if (string.IsNullOrWhiteSpace(rs)) + { + rs = parseTagValue_Attr(doc, "//meta[@property='og:description']", "content", string.Empty); + } + + if (string.IsNullOrWhiteSpace(rs)) + { + rs = parseTagValue_Attr(doc, "//meta[@itemprop='description']", "content", string.Empty); + } + + return rs; + } + + protected string parseSiteIcon(HtmlDocument doc) + { + string rs = null; + + if (string.IsNullOrWhiteSpace(rs)) + { + rs = parseTagValue_Attr(doc, "//link[@rel='shortcut icon']", "href", string.Empty); + } + + if (string.IsNullOrWhiteSpace(rs)) + { + rs = parseTagValue_Attr(doc, "//link[@rel='icon']", "href", string.Empty); + } + + if (string.IsNullOrWhiteSpace(rs)) + { + rs = parseTagValue_Attr(doc, "//link[@rel='apple-touch-icon']", "href", string.Empty); + } + + if (string.IsNullOrWhiteSpace(rs)) + { + rs = parseTagValue_Attr(doc, "//link[@rel='apple-touch-icon-precomposed']", "href", string.Empty); + } + + if (string.IsNullOrWhiteSpace(rs)) + { + rs = parseTagValue_Attr(doc, "//meta[@property='og:image']", "content", string.Empty); + } + + if (string.IsNullOrWhiteSpace(rs)) + { + rs = parseTagValue_Attr(doc, "//meta[@name='twitter:image']", "content", string.Empty); + } + + if (string.IsNullOrWhiteSpace(rs)) + { + rs = parseTagValue_Attr(doc, "//meta[@property='og:image']", "content", string.Empty); + } + + if (string.IsNullOrWhiteSpace(rs)) + { + rs = parseTagValue_Attr(doc, "//meta[@itemprop='image']", "content", string.Empty); + } + + return rs; + } + + + } } \ No newline at end of file diff --git a/BookmarkTreeView.cs b/BookmarkTreeView.cs index 9b4c5d3..6847b7d 100644 --- a/BookmarkTreeView.cs +++ b/BookmarkTreeView.cs @@ -67,18 +67,18 @@ namespace bzit.bomg TreeNode tn = AddBookmarkPageFullPath(name.Trim(), 3); tn.Tag = tag; - tn.ToolTipText = tag.Address + Environment.NewLine + tag.Description; + tn.ToolTipText = tag.SiteAddress + Environment.NewLine + tag.Description; // load icon - if (this.IconDatabase.HasIcon(tag.Address)) + if (this.IconDatabase.HasIcon(tag.SiteAddress)) { try { - Image icon = this.IconDatabase.GetIcon(tag.Address); + Image icon = this.IconDatabase.GetIcon(tag.SiteAddress); if (icon != null) { - tn.TreeView.ImageList.Images.Add(tag.Address, icon); - tn.ImageKey = tn.SelectedImageKey = tag.Address; + tn.TreeView.ImageList.Images.Add(tag.SiteAddress, icon); + tn.ImageKey = tn.SelectedImageKey = tag.SiteAddress; } } catch @@ -91,13 +91,13 @@ namespace bzit.bomg public int AddToIconList(BookmarkItem sender) { Image rs = null; - if (this.IconDatabase.HasIcon(sender.Address)) + if (this.IconDatabase.HasIcon(sender.SiteAddress)) { - rs = this.IconDatabase.GetIcon(sender.Address); + rs = this.IconDatabase.GetIcon(sender.SiteAddress); } else { - if (this.IconDatabase.AddIcon(sender.Address, sender.IconData)) + if (this.IconDatabase.AddIcon(sender.SiteAddress, sender.IconData)) { rs = sender.Icon; } @@ -105,8 +105,8 @@ namespace bzit.bomg if (rs != null) { - this.ImageList.Images.Add(sender.Address, rs); - return this.ImageList.Images.IndexOfKey(sender.Address); + this.ImageList.Images.Add(sender.SiteAddress, rs); + return this.ImageList.Images.IndexOfKey(sender.SiteAddress); } return 3; @@ -114,12 +114,12 @@ namespace bzit.bomg public void AddIcon(BookmarkItem sender) { - if (this.IconDatabase.HasIcon(sender.Address)) + if (this.IconDatabase.HasIcon(sender.SiteAddress)) { return; } - this.IconDatabase.AddIcon(sender.Address, sender.IconData); + this.IconDatabase.AddIcon(sender.SiteAddress, sender.IconData); } } } \ No newline at end of file diff --git a/MainForm.cs b/MainForm.cs index 63c61a7..ff3764e 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -743,14 +743,14 @@ namespace bzit.bomg return; } - if (string.IsNullOrEmpty(bookmarkItem.Address)) + if (string.IsNullOrEmpty(bookmarkItem.SiteAddress)) { return; } try { - Clipboard.SetText(bookmarkItem.Address.Trim()); + Clipboard.SetText(bookmarkItem.SiteAddress.Trim()); } catch { @@ -788,7 +788,7 @@ namespace bzit.bomg return; } - if (string.IsNullOrEmpty(item.Address)) + if (string.IsNullOrEmpty(item.SiteAddress)) { return; } @@ -810,8 +810,8 @@ namespace bzit.bomg return; } - bookmarkCustom1 = bookmarkCustom1.Replace("%1", item.Address); - bookmarkCustom2 = bookmarkCustom2.Replace("%1", item.Address); + bookmarkCustom1 = bookmarkCustom1.Replace("%1", item.SiteAddress); + bookmarkCustom2 = bookmarkCustom2.Replace("%1", item.SiteAddress); try { @@ -826,7 +826,7 @@ namespace bzit.bomg default: try { - System.Diagnostics.Process.Start(item.Address); + System.Diagnostics.Process.Start(item.SiteAddress); } catch { diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index a72bcfb..8bbc9a6 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.2.0.083")] +[assembly: AssemblyVersion("0.2.1.001")] [assembly: AssemblyFileVersion("0.1.0.0")] diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index 72717ac..fe32468 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -89,7 +89,7 @@ namespace bzit.bomg.Properties { } /// - /// Looks up a localized string similar to 0.2.0.083 beta. + /// Looks up a localized string similar to 0.2.1.001 beta. /// internal static string app_version { get { diff --git a/Properties/Resources.resx b/Properties/Resources.resx index 5ca70ff..8637a55 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -128,7 +128,7 @@ Bookmark Manager - 0.2.0.083 beta + 0.2.1.001 beta ..\Resources\cog.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a diff --git a/SessionFileFormat.cs b/SessionFileFormat.cs index 39f92f8..d9d8fb0 100644 --- a/SessionFileFormat.cs +++ b/SessionFileFormat.cs @@ -40,7 +40,7 @@ namespace bzit.bomg bi.Fullpath = xn2.InnerText?.Trim(); break; case "address": - bi.Address = xn2.InnerText?.Trim(); + bi.SiteAddress = xn2.InnerText?.Trim(); break; case "description": bi.Description = xn2.InnerText?.Trim(); @@ -78,7 +78,7 @@ namespace bzit.bomg writer.WriteStartElement("m"); writer.WriteElementString("name", parentForm.treeView1.GetNodeFullPath(tn)); - writer.WriteElementString("address", bi.Address); + writer.WriteElementString("address", bi.SiteAddress); writer.WriteElementString("description", bi.Description); writer.WriteElementString("created", bi.Created.ToString()); writer.WriteEndElement(); diff --git a/app.config b/app.config deleted file mode 100644 index 2a0024f..0000000 --- a/app.config +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/bomg.csproj b/bomg.csproj index 1bc6c83..4368e87 100644 --- a/bomg.csproj +++ b/bomg.csproj @@ -206,7 +206,6 @@ BigButton.cs - SettingsSingleFileGenerator @@ -219,7 +218,6 @@ - diff --git a/bomg.sln b/bomg.sln new file mode 100644 index 0000000..06ba052 --- /dev/null +++ b/bomg.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.168 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bomg", "bomg.csproj", "{594B03D6-3F17-4AE9-911D-C338EBD99FDF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {594B03D6-3F17-4AE9-911D-C338EBD99FDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {594B03D6-3F17-4AE9-911D-C338EBD99FDF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {594B03D6-3F17-4AE9-911D-C338EBD99FDF}.Debug|x86.ActiveCfg = Debug|x86 + {594B03D6-3F17-4AE9-911D-C338EBD99FDF}.Debug|x86.Build.0 = Debug|x86 + {594B03D6-3F17-4AE9-911D-C338EBD99FDF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {594B03D6-3F17-4AE9-911D-C338EBD99FDF}.Release|Any CPU.Build.0 = Release|Any CPU + {594B03D6-3F17-4AE9-911D-C338EBD99FDF}.Release|x86.ActiveCfg = Release|x86 + {594B03D6-3F17-4AE9-911D-C338EBD99FDF}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3FF38EC6-A04F-4999-AA1C-771FA6DAC156} + EndGlobalSection +EndGlobal