Beispiel #1
0
 public SizeNode(string displayName, string iconName, ScanState state, FolderSize size, Icon icon, string path)
 {
     this.displayName = displayName;
     this.iconName = iconName;
     this.state = state;
     this.size = size;
     this.icon = icon;
     this.path = path;
     if (icon == null) throw new ArgumentNullException();
 }
Beispiel #2
0
 private void AddFileSize(ref FolderSize sum, string path)
 {
     sum.fileCount++;
     sum.logicalSize += (ulong)new FileInfo(path).Length;
     try
     {
         ulong ps = ExtendedFileInfo.GetPhysicalFileSize(path);
         sum.physicalSize += ps;
         uint clusterSize = ExtendedFileInfo.GetClusterSize(path);
         if (clusterSizeOverride != 0)
         {
             clusterSize = clusterSizeOverride;
         }
         ulong ds = ((ps + clusterSize - 1) / clusterSize) * clusterSize;
         sum.diskSize += ds;
     }
     catch (Win32Exception ex)
     {
         throw new UnauthorizedAccessException("Cannot get file size: ", ex);
     }
 }
Beispiel #3
0
 public void Update()
 {
     if (folderInfo == null) return;
     this.size = folderInfo.Size;
     this.state = folderInfo.State;
     if (fileSummaries.Count == 0 && (folderInfo.State == ScanState.SCANNING || folderInfo.State == ScanState.DONE))
     {
         FillInFiles();
         // If there are no files or directories below, load "them" immediately
         // to remove the dummy node.
         if (folderInfo.Children.Count == 0 && folderInfo.AllFilesSize.fileCount == 0)
         {
             LoadChildren();
         }
     }
 }
Beispiel #4
0
        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();
            }
        }
Beispiel #5
0
 private void AddFileSize(ref FolderSize sum, string path)
 {
     sum.fileCount++;
     sum.logicalSize += (ulong)new FileInfo(path).Length;
     try
     {
         ulong ps = ExtendedFileInfo.GetPhysicalFileSize(path);
         sum.physicalSize += ps;
         uint clusterSize = ExtendedFileInfo.GetClusterSize(path);
         if (clusterSizeOverride != 0) clusterSize = clusterSizeOverride;
         ulong ds = ((ps + clusterSize - 1) / clusterSize) * clusterSize;
         sum.diskSize += ds;
     }
     catch (Win32Exception ex)
     {
         throw new UnauthorizedAccessException("Cannot get file size: ", ex);
     }
 }
Beispiel #6
0
 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();
 }
Beispiel #7
0
 private ulong displayValue(FolderSize folderSize)
 {
     switch (sizeValue)
     {
         case SizeValue.PHYSICAL:
             return folderSize.physicalSize;
         case SizeValue.LOGICAL:
             return folderSize.logicalSize;
         case SizeValue.ALLOCATED:
             return folderSize.diskSize;
         case SizeValue.WASTED:
             return folderSize.diskSize - folderSize.physicalSize;
         case SizeValue.FILECOUNT:
             return (ulong)folderSize.fileCount;
         case SizeValue.FOLDERCOUNT:
             return (ulong)folderSize.folderCount;
         case SizeValue.ALLCOUNT:
             return (ulong)(folderSize.fileCount + folderSize.folderCount);
         default: throw new Exception();
     }
 }