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,29 +803,31 @@ namespace bzit.bomg
readStream.Dispose(); readStream.Dispose();
readStream = null; readStream = null;
if (treeView1.InvokeRequired)
{
treeView1.Invoke(new MethodInvoker(() => {
treeView1.AddItem(rs); treeView1.AddItem(rs);
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(() =>
{
this.ApplicationMode = AppMode.Open;
})); }));
} }
else else
{ {
treeView1.AddItem(rs); this.ApplicationMode = AppMode.Open;
} }
if (this.InvokeRequired) if (this.InvokeRequired)
{ {
this.Invoke(new MethodInvoker(() => { this.Invoke(new MethodInvoker(() =>
this.ApplicationMode = AppMode.Open; {
this.Text = Path.GetFileNameWithoutExtension(filename) + " - " + Resources.app_name;
})); }));
} }
else else
{ {
this.ApplicationMode = AppMode.Open; this.Text = Path.GetFileNameWithoutExtension(filename) + " - " + Resources.app_name;
} }
setAppTitle(Path.GetFileNameWithoutExtension(filename));
} }
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.Invoke(new MethodInvoker(() => {
treeView1.AddItem(rs); 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);
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(() =>
{
tn2.Nodes.Add(tn); tn2.Nodes.Add(tn);
}));
}
else
{
tn2.Nodes.Add(tn);
}
this.HasChanged = true; this.HasChanged = true;
} }
@ -209,8 +219,18 @@ namespace RyzStudio.Windows.Forms
} }
public void Clear() public void Clear()
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(() =>
{ {
this.Nodes.Clear(); this.Nodes.Clear();
}));
}
else
{
this.Nodes.Clear();
}
this.HasChanged = true; this.HasChanged = true;
} }
@ -646,20 +666,43 @@ namespace RyzStudio.Windows.Forms
return (int)IconSet.Default; return (int)IconSet.Default;
} }
else else
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(() =>
{ {
this.ImageList.Images.Add(model.SiteAddress, rs); 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;
} }
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(() =>
{
this.ImageList.Images.Add(model.SiteAddress, bmp); 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);
} }
@ -696,8 +739,18 @@ namespace RyzStudio.Windows.Forms
if (i <= 0) if (i <= 0)
{ {
if (!this.Nodes.ContainsKey(item)) if (!this.Nodes.ContainsKey(item))
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(() =>
{ {
this.Nodes.Add(item, decodePath(item), (int)IconSet.Root, (int)IconSet.Root); 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];
@ -705,8 +758,18 @@ namespace RyzStudio.Windows.Forms
else else
{ {
if (!tn.Nodes.ContainsKey(item)) if (!tn.Nodes.ContainsKey(item))
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(() =>
{ {
tn.Nodes.Add(item, decodePath(item), (int)IconSet.Folder1, (int)IconSet.Folder2); 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];