diff --git a/MainForm.cs b/MainForm.cs index 76db302..19a5619 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -803,20 +803,12 @@ namespace bzit.bomg readStream.Dispose(); readStream = null; - if (treeView1.InvokeRequired) - { - treeView1.Invoke(new MethodInvoker(() => { - treeView1.AddItem(rs); - })); - } - else - { - treeView1.AddItem(rs); - } + treeView1.AddItem(rs); if (this.InvokeRequired) { - this.Invoke(new MethodInvoker(() => { + this.Invoke(new MethodInvoker(() => + { this.ApplicationMode = AppMode.Open; })); } @@ -825,7 +817,17 @@ namespace bzit.bomg this.ApplicationMode = AppMode.Open; } - setAppTitle(Path.GetFileNameWithoutExtension(filename)); + if (this.InvokeRequired) + { + this.Invoke(new MethodInvoker(() => + { + this.Text = Path.GetFileNameWithoutExtension(filename) + " - " + Resources.app_name; + })); + } + else + { + this.Text = Path.GetFileNameWithoutExtension(filename) + " - " + Resources.app_name; + } } protected void loadBookmarkFile_ForRYZ(string filename, string password = "") @@ -953,23 +955,15 @@ namespace bzit.bomg readStream.Dispose(); readStream = null; - if (treeView1.InvokeRequired) - { - treeView1.Invoke(new MethodInvoker(() => { - treeView1.AddItem(rs); - })); - } - else - { - treeView1.AddItem(rs); - } + treeView1.AddItem(rs); sessionFilename = sessionPassword = null; usePassword = !string.IsNullOrWhiteSpace(password); if (this.InvokeRequired) { - this.Invoke(new MethodInvoker(() => { + this.Invoke(new MethodInvoker(() => + { this.ApplicationMode = AppMode.New; })); } @@ -978,7 +972,17 @@ namespace bzit.bomg this.ApplicationMode = AppMode.New; } - setAppTitle(Path.GetFileNameWithoutExtension(filename)); + if (this.InvokeRequired) + { + this.Invoke(new MethodInvoker(() => + { + this.Text = Path.GetFileNameWithoutExtension(filename) + " - " + Resources.app_name; + })); + } + else + { + this.Text = Path.GetFileNameWithoutExtension(filename) + " - " + Resources.app_name; + } } protected void openBookmark(TreeNode node) @@ -1018,7 +1022,7 @@ namespace bzit.bomg case 1: saveBookmarkFile_ForJSNX(saveFileDialog.FileName); - setAppTitle(Path.GetFileNameWithoutExtension(saveFileDialog.FileName)); + this.Text = Path.GetFileNameWithoutExtension(saveFileDialog.FileName) + " - " + Properties.Resources.app_name; sessionFilename = saveFileDialog.FileName; usePassword = false; @@ -1031,7 +1035,7 @@ namespace bzit.bomg saveBookmarkFile_ForJSNX(saveFileDialog.FileName, password ?? string.Empty); - setAppTitle(Path.GetFileNameWithoutExtension(saveFileDialog.FileName)); + this.Text = Path.GetFileNameWithoutExtension(saveFileDialog.FileName) + " - " + Properties.Resources.app_name; sessionFilename = saveFileDialog.FileName; sessionPassword = password; @@ -1093,20 +1097,6 @@ namespace bzit.bomg treeView1.HasChanged = false; } - protected void setAppTitle(string title) - { - if (this.InvokeRequired) - { - this.Invoke(new MethodInvoker(() => { - this.Text = title + " - " + Properties.Resources.app_name; - })); - } - else - { - this.Text = title + " - " + Properties.Resources.app_name; - } - } - protected void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { if (e.Button != MouseButtons.Right) @@ -1243,27 +1233,11 @@ namespace bzit.bomg { if (loadFileType == LoadFileType.Jsnx) { - if (usePassword) - { - loadBookmarkFile_ForJSNX(sessionFilename, sessionPassword); - } - else - { - loadBookmarkFile_ForJSNX(sessionFilename); - } + loadBookmarkFile_ForJSNX(sessionFilename, sessionPassword ?? string.Empty); } else if (loadFileType == LoadFileType.Ryz) { - if (usePassword) - { - loadBookmarkFile_ForRYZ(sessionFilename, sessionPassword); - } - else - { - loadBookmarkFile_ForRYZ(sessionFilename); - } - - sessionFilename = sessionPassword = null; + loadBookmarkFile_ForRYZ(sessionFilename, sessionPassword ?? string.Empty); } } diff --git a/Models/BookmarkItemModel.cs b/Models/BookmarkItemModel.cs index fe98ab6..8e78b6c 100644 --- a/Models/BookmarkItemModel.cs +++ b/Models/BookmarkItemModel.cs @@ -148,6 +148,42 @@ namespace bzit.bomg } } + public Bitmap RetrieveFavicon(out byte[] rawData) + { + rawData = null; + + if (string.IsNullOrWhiteSpace(this.FaviconAddress)) + { + return null; + } + + byte[] iconData = null; + WebClient webClient = new WebClient(); + webClient.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore); + + try + { + iconData = webClient.DownloadData(this.FaviconAddress); + + if (!RyzStudio.IO.FileType.IsImage(iconData)) + { + throw new Exception("Not a supported image"); + } + + rawData = iconData; + + Image img = Image.FromStream(new MemoryStream(iconData)); + return new Bitmap(img, 16, 16); + } + catch + { + iconData = null; + this.FaviconAddress = null; + + return null; + } + } + protected string retrieveSourceCode() { if (webClient == null) diff --git a/Windows/Forms/BookmarkTreeView.cs b/Windows/Forms/BookmarkTreeView.cs index 9f22e4f..66e4499 100644 --- a/Windows/Forms/BookmarkTreeView.cs +++ b/Windows/Forms/BookmarkTreeView.cs @@ -169,7 +169,17 @@ namespace RyzStudio.Windows.Forms TreeNode tn2 = addFolderPath(viewModel.TreeviewPath); - tn2.Nodes.Add(tn); + if (this.InvokeRequired) + { + this.Invoke(new MethodInvoker(() => + { + tn2.Nodes.Add(tn); + })); + } + else + { + tn2.Nodes.Add(tn); + } this.HasChanged = true; } @@ -210,7 +220,17 @@ namespace RyzStudio.Windows.Forms public void Clear() { - this.Nodes.Clear(); + if (this.InvokeRequired) + { + this.Invoke(new MethodInvoker(() => + { + this.Nodes.Clear(); + })); + } + else + { + this.Nodes.Clear(); + } this.HasChanged = true; } @@ -647,19 +667,42 @@ namespace RyzStudio.Windows.Forms } else { - this.ImageList.Images.Add(model.SiteAddress, rs); + if (this.InvokeRequired) + { + this.Invoke(new MethodInvoker(() => + { + this.ImageList.Images.Add(model.SiteAddress, rs); + })); + } + else + { + this.ImageList.Images.Add(model.SiteAddress, rs); + } return this.ImageList.Images.IndexOfKey(model.SiteAddress); } } - Bitmap bmp = model.RetrieveFavicon(); + byte[] rawData; + Bitmap bmp = model.RetrieveFavicon(out rawData); if (bmp == null) { return (int)IconSet.Default; } - this.ImageList.Images.Add(model.SiteAddress, bmp); + if (this.InvokeRequired) + { + this.Invoke(new MethodInvoker(() => + { + this.ImageList.Images.Add(model.SiteAddress, bmp); + })); + } + else + { + this.ImageList.Images.Add(model.SiteAddress, bmp); + } + + iconDatabase.AddIcon(model.SiteAddress, rawData); return this.ImageList.Images.IndexOfKey(model.SiteAddress); } @@ -697,7 +740,17 @@ namespace RyzStudio.Windows.Forms { if (!this.Nodes.ContainsKey(item)) { - this.Nodes.Add(item, decodePath(item), (int)IconSet.Root, (int)IconSet.Root); + if (this.InvokeRequired) + { + this.Invoke(new MethodInvoker(() => + { + this.Nodes.Add(item, decodePath(item), (int)IconSet.Root, (int)IconSet.Root); + })); + } + else + { + this.Nodes.Add(item, decodePath(item), (int)IconSet.Root, (int)IconSet.Root); + } } tn = this.Nodes[item]; @@ -706,7 +759,17 @@ namespace RyzStudio.Windows.Forms { if (!tn.Nodes.ContainsKey(item)) { - tn.Nodes.Add(item, decodePath(item), (int)IconSet.Folder1, (int)IconSet.Folder2); + if (this.InvokeRequired) + { + this.Invoke(new MethodInvoker(() => + { + tn.Nodes.Add(item, decodePath(item), (int)IconSet.Folder1, (int)IconSet.Folder2); + })); + } + else + { + tn.Nodes.Add(item, decodePath(item), (int)IconSet.Folder1, (int)IconSet.Folder2); + } } tn = tn.Nodes[item];