private void UpdateSum() { lock (this) { if (state != ScanState.SCANNING) { return; } size.Zero(); size.Add(allFilesSize); size.folderCount += children.Count; foreach (FolderInfo fi in children) { if (fi.size.childrenDenied) { size.childrenDenied = true; } else if (fi.State != ScanState.DONE) { return; // not ready yet! } size.Add(fi.Size); } state = ScanState.DONE; stateChanged = true; } if (parent != null) { parent.UpdateSum(); } }
internal void DoScan() { bool updateSum = false; lock (this) { if (state != ScanState.QUEUED) { throw new Exception(); } state = ScanState.SCANNING; stateChanged = true; allFilesSize.Zero(); filesSizeByExtension.Clear(); try { foreach (string dir in Directory.GetDirectories(fullPath)) { children.Add(new FolderInfo(this, dir, Path.GetFileName(dir), clusterSizeOverride)); } children.Sort(new Comparison <FolderInfo>(delegate(FolderInfo fi1, FolderInfo fi2) { return(fi1.DisplayName.CompareTo(fi2.DisplayName)); })); string[] files = Directory.GetFiles(fullPath); foreach (string file in files) { string extension; string fn = Path.GetFileName(file); if (fn.IndexOf(".") != -1) { extension = fn.Substring(fn.LastIndexOf(".") + 1); } else { extension = ""; } FolderSize ext; if (!filesSizeByExtension.ContainsKey(extension)) { ext = new FolderSize(true); } else { ext = filesSizeByExtension[extension]; } AddFileSize(ref ext, file); filesSizeByExtension[extension] = ext; AddFileSize(ref allFilesSize, file); } if (children.Count == 0) { // we are a leaf, so update the counts updateSum = true; } } catch (Exception) { allFilesSize.Zero(); filesSizeByExtension.Clear(); updateSum = true; children.Clear(); stateChanged = true; size.childrenDenied = true; } } if (updateSum) { UpdateSum(); } }