Advertisement
Guest User

OnBeforeExpand with Dictionary

a guest
Aug 9th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 KB | None | 0 0
  1. protected async override void OnBeforeExpand(TreeViewCancelEventArgs e)
  2. {
  3.  
  4.     if (!_expandedCache.Contains(e.Node.FullPath))
  5.     {
  6.         TreeNodeCollection tnc = e.Node.Nodes;
  7.         _expandedCache.Add(e.Node.FullPath);
  8.         await Task.Run(() => {
  9.             Dictionary<ulong, ShellFileGetInfo.FolderIcons> icons = new Dictionary<ulong, ShellFileGetInfo.FolderIcons>();
  10.             ShellFileGetInfo.FolderIcons fi;
  11.             string curPath;
  12.             foreach (TreeNode n in tnc)
  13.             {
  14.                 curPath = Path.Combine((string)Tag, n.FullPath.Replace('/', Path.DirectorySeparatorChar));
  15.                 if (File.Exists(Path.Combine(curPath, "desktop.ini")) == true)
  16.                 {
  17.                     if (File.ReadAllText(Path.Combine(curPath, "desktop.ini")).Contains("IconFile"))
  18.                     {
  19.                         fi = ShellFileGetInfo.GetFolderIcon(curPath, false);
  20.                         if (fi.closed != null || fi.open != null)
  21.                         {
  22.                             icons.Add(((NtfsUsnJournal.UsnEntry)n.Tag).FileReferenceNumber, fi);
  23.                         }
  24.                     }
  25.                 }
  26.                 //EndUpdate();
  27.             }
  28.  
  29.             if (icons.Count > 0)
  30.             {
  31.                 Invoke((MethodInvoker)(() =>
  32.                 {
  33.  
  34.                     List<Image> images = new List<Image>();
  35.                     foreach (var icon in icons)
  36.                     {
  37.                         images.Add(icon.Value.closed.ToBitmap());
  38.                         images.Add(icon.Value.open.ToBitmap());
  39.                     }
  40.  
  41.                     BeginUpdate();
  42.  
  43.                     int imageIndexCount = ImageList.Images.Count;
  44.  
  45.                     ImageList.Images.AddRange(images.ToArray());
  46.                     foreach (var icon in icons)
  47.                     {
  48.                         e.Node.Nodes[icon.Key.ToString()].ImageIndex = imageIndexCount;
  49.                         imageIndexCount++;
  50.                         e.Node.Nodes[icon.Key.ToString()].SelectedImageIndex = imageIndexCount;
  51.                         imageIndexCount++;
  52.                     }
  53.  
  54.                     EndUpdate();
  55.                 }));
  56.             }
  57.         });
  58.  
  59.     }
  60.     base.OnBeforeExpand(e);
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement