Changed: threading and icons db

This commit is contained in:
Ray 2019-04-27 03:17:24 +01:00
parent 17e4e867eb
commit d232f7b5ec
3 changed files with 138 additions and 65 deletions

View File

@ -803,20 +803,12 @@ namespace bzit.bomg
readStream.Dispose(); readStream.Dispose();
readStream = null; readStream = null;
if (treeView1.InvokeRequired) treeView1.AddItem(rs);
{
treeView1.Invoke(new MethodInvoker(() => {
treeView1.AddItem(rs);
}));
}
else
{
treeView1.AddItem(rs);
}
if (this.InvokeRequired) if (this.InvokeRequired)
{ {
this.Invoke(new MethodInvoker(() => { this.Invoke(new MethodInvoker(() =>
{
this.ApplicationMode = AppMode.Open; this.ApplicationMode = AppMode.Open;
})); }));
} }
@ -825,7 +817,17 @@ namespace bzit.bomg
this.ApplicationMode = AppMode.Open; 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 = "") protected void loadBookmarkFile_ForRYZ(string filename, string password = "")
@ -953,23 +955,15 @@ namespace bzit.bomg
readStream.Dispose(); readStream.Dispose();
readStream = null; readStream = null;
if (treeView1.InvokeRequired) treeView1.AddItem(rs);
{
treeView1.Invoke(new MethodInvoker(() => {
treeView1.AddItem(rs);
}));
}
else
{
treeView1.AddItem(rs);
}
sessionFilename = sessionPassword = null; sessionFilename = sessionPassword = null;
usePassword = !string.IsNullOrWhiteSpace(password); usePassword = !string.IsNullOrWhiteSpace(password);
if (this.InvokeRequired) if (this.InvokeRequired)
{ {
this.Invoke(new MethodInvoker(() => { this.Invoke(new MethodInvoker(() =>
{
this.ApplicationMode = AppMode.New; this.ApplicationMode = AppMode.New;
})); }));
} }
@ -978,7 +972,17 @@ namespace bzit.bomg
this.ApplicationMode = AppMode.New; 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) protected void openBookmark(TreeNode node)
@ -1018,7 +1022,7 @@ namespace bzit.bomg
case 1: case 1:
saveBookmarkFile_ForJSNX(saveFileDialog.FileName); saveBookmarkFile_ForJSNX(saveFileDialog.FileName);
setAppTitle(Path.GetFileNameWithoutExtension(saveFileDialog.FileName)); this.Text = Path.GetFileNameWithoutExtension(saveFileDialog.FileName) + " - " + Properties.Resources.app_name;
sessionFilename = saveFileDialog.FileName; sessionFilename = saveFileDialog.FileName;
usePassword = false; usePassword = false;
@ -1031,7 +1035,7 @@ namespace bzit.bomg
saveBookmarkFile_ForJSNX(saveFileDialog.FileName, password ?? string.Empty); 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; sessionFilename = saveFileDialog.FileName;
sessionPassword = password; sessionPassword = password;
@ -1093,20 +1097,6 @@ namespace bzit.bomg
treeView1.HasChanged = false; 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) protected void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{ {
if (e.Button != MouseButtons.Right) if (e.Button != MouseButtons.Right)
@ -1243,27 +1233,11 @@ namespace bzit.bomg
{ {
if (loadFileType == LoadFileType.Jsnx) if (loadFileType == LoadFileType.Jsnx)
{ {
if (usePassword) loadBookmarkFile_ForJSNX(sessionFilename, sessionPassword ?? string.Empty);
{
loadBookmarkFile_ForJSNX(sessionFilename, sessionPassword);
}
else
{
loadBookmarkFile_ForJSNX(sessionFilename);
}
} }
else if (loadFileType == LoadFileType.Ryz) else if (loadFileType == LoadFileType.Ryz)
{ {
if (usePassword) loadBookmarkFile_ForRYZ(sessionFilename, sessionPassword ?? string.Empty);
{
loadBookmarkFile_ForRYZ(sessionFilename, sessionPassword);
}
else
{
loadBookmarkFile_ForRYZ(sessionFilename);
}
sessionFilename = sessionPassword = null;
} }
} }

View File

@ -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() protected string retrieveSourceCode()
{ {
if (webClient == null) if (webClient == null)

View File

@ -169,7 +169,17 @@ namespace RyzStudio.Windows.Forms
TreeNode tn2 = addFolderPath(viewModel.TreeviewPath); 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; this.HasChanged = true;
} }
@ -210,7 +220,17 @@ namespace RyzStudio.Windows.Forms
public void Clear() public void Clear()
{ {
this.Nodes.Clear(); if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(() =>
{
this.Nodes.Clear();
}));
}
else
{
this.Nodes.Clear();
}
this.HasChanged = true; this.HasChanged = true;
} }
@ -647,19 +667,42 @@ namespace RyzStudio.Windows.Forms
} }
else 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); return this.ImageList.Images.IndexOfKey(model.SiteAddress);
} }
} }
Bitmap bmp = model.RetrieveFavicon(); byte[] rawData;
Bitmap bmp = model.RetrieveFavicon(out rawData);
if (bmp == null) if (bmp == null)
{ {
return (int)IconSet.Default; 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); return this.ImageList.Images.IndexOfKey(model.SiteAddress);
} }
@ -697,7 +740,17 @@ namespace RyzStudio.Windows.Forms
{ {
if (!this.Nodes.ContainsKey(item)) 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]; tn = this.Nodes[item];
@ -706,7 +759,17 @@ namespace RyzStudio.Windows.Forms
{ {
if (!tn.Nodes.ContainsKey(item)) 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]; tn = tn.Nodes[item];