private void Populate(TreeNode node) { string path = node.FullPath; if (path.Length == 2) { path += "\\"; } if (node.Nodes.Count > 0) { return; //already populated } if (!this.hashtable.ContainsKey(path)) { return; //not found in hashtable } DirEnrty entry = (DirEnrty)this.hashtable[path]; for (int i = 0; i < entry.subdir.Length; i++) { TreeNode subnode = node.Nodes.Add(entry.subdir[i].name); if (hashtable.ContainsKey(entry.subdir[i].fullname)) { DirEnrty sub = (DirEnrty)hashtable[entry.subdir[i].fullname]; foreach (DirEnrty o in sub.subdir) { subnode.Nodes.Add(o.name); } } } }
private Tuple <ulong, DirEnrty[], FileEnrty[]> ScanDirectory(DirectoryInfo dir) { ulong size = 0; DirectoryInfo[] dirInfo = dir.GetDirectories(); DirEnrty[] dirs = new DirEnrty[dirInfo.Length]; for (long i = 0; i < dirInfo.Length; i++) { Tuple <ulong, DirEnrty[], FileEnrty[]> nested = null; try { nested = ScanDirectory(dirInfo[i]); } catch { } dirs[i] = new DirEnrty() { name = dirInfo[i].Name, fullname = dirInfo[i].FullName, cre_date = dirInfo[i].CreationTime.Ticks, mod_date = dirInfo[i].LastWriteTime.Ticks, size = nested?.Item1 ?? 0, subdir = nested?.Item2 ?? new DirEnrty[] { }, files = nested?.Item3 ?? new FileEnrty[] { } }; size += nested?.Item1 ?? 0; } FileEnrty[] files = null; try { FileInfo[] fileInfo = dir.GetFiles(); files = new FileEnrty[fileInfo.Length]; for (long i = 0; i < fileInfo.Length; i++) { files[i] = new FileEnrty() { name = fileInfo[i].Name, fullname = fileInfo[i].FullName, cre_date = fileInfo[i].CreationTime.Ticks, mod_date = fileInfo[i].LastWriteTime.Ticks, size = fileInfo[i].Length }; size += (ulong)fileInfo[i].Length; } } catch { } DirEnrty entry = new DirEnrty() { name = dir.Name, fullname = dir.FullName, cre_date = dir.CreationTime.Ticks, mod_date = dir.LastWriteTime.Ticks, size = size, subdir = dirs ?? new DirEnrty[] { }, files = files ?? new FileEnrty[] { } }; hashtable.Add(dir.FullName, entry); return(Tuple.Create(size, dirs, files)); }
private void DrawMapLoop(Graphics g, Rectangle r, string path) { DirEnrty entry = (DirEnrty)this.hashtable[path]; ulong size = entry.size; //TODO: for (int i = 0; i < entry.subdir.Length; i++) { } for (int i = 0; i < entry.files.Length; i++) { } }
private void LstTree_AfterSelect(object sender, TreeViewEventArgs e) { txtPath.Text = e.Node.FullPath; lstFiles.Items.Clear(); string path = e.Node.FullPath; if (path.Length == 2) { path += "\\"; } if (!this.hashtable.ContainsKey(path)) { return; } DirEnrty entry = (DirEnrty)this.hashtable[path]; for (int i = 0; i < entry.subdir.Length; i++) { ListViewItem item = new ListViewItem( new string[] { $"{entry.subdir[i].name}\\", entry.subdir[i].size.ToString(), entry.subdir[i].cre_date.ToString(), entry.subdir[i].mod_date.ToString() }); item.ImageIndex = 1; lstFiles.Items.Add(item); } for (int i = 0; i < entry.files.Length; i++) { ListViewItem item = new ListViewItem( new string[] { entry.files[i].name, entry.files[i].size.ToString(), entry.files[i].cre_date.ToString(), entry.files[i].mod_date.ToString() }); item.ImageIndex = 0; lstFiles.Items.Add(item); } }