Esempio n. 1
0
        private static void SetLabel(DirectoryInfoEx directory, SpecialDirectoryEntry directoryEntry)
        {
            if (directory.Name != directory.Label)
            {
                directoryEntry.Label = directory.Label;
            }

            if (directory.TryGetKnownFolderType(out var knownFolder))
            {
                var definition = knownFolder.Definition;
                if (!string.IsNullOrEmpty(definition.LocalizedName))
                {
                    var parts = definition.LocalizedName.TrimStart('@').Split(',');
                    if (parts.Length == 2 && int.TryParse(parts[1], out var id))
                    {
                        directoryEntry.LabelPath = parts[0];
                        directoryEntry.LabelId   = id;
                        return;
                    }
                }
            }

            //http://archives.miloush.net/michkap/archive/2007/01/18/1487464.html
            var sb  = new StringBuilder(500);
            var len = (uint)sb.Capacity;

            if (NativeMethods.SHGetLocalizedName(directory.FullName, sb, ref len, out var pidsRes) == IntPtr.Zero)
            {
                directoryEntry.LabelPath = sb.ToString();
                directoryEntry.LabelId   = pidsRes;
            }
        }
Esempio n. 2
0
        private static bool SetSpecialFolderAttributes(DirectoryInfoEx directory, SpecialDirectoryEntry specialDirectory)
        {
            SetLabel(directory, specialDirectory);
            specialDirectory.IconId = GetFolderIcon(directory);

            return(specialDirectory.IconId != 0 || specialDirectory.Label != null || specialDirectory.LabelId != 0 ||
                   specialDirectory.LabelPath != null);
        }
Esempio n. 3
0
        private DirectoryEntry CreateSpecializedDirectory(DirectoryInfoEx directory)
        {
            if (directory.DirectoryType == DirectoryInfoEx.DirectoryTypeEnum.dtDrive)
            {
                var drive = _drives.Value.FirstOrDefault(x => x.RootDirectory.FullName == directory.FullName);
                if (drive != null)
                {
                    DriveDirectoryEntry driveDirectory;
                    if (drive.IsReady)
                    {
                        driveDirectory = new DriveDirectoryEntry
                        {
                            TotalSize = drive.TotalSize,
                            UsedSpace = drive.TotalSize - drive.TotalFreeSpace,
                            DriveType = drive.DriveType
                        }
                    }
                    ;
                    else
                    {
                        driveDirectory =
                            new DriveDirectoryEntry {
                            TotalSize = 0, UsedSpace = 0, DriveType = drive.DriveType
                        }
                    };

                    SetSpecialFolderAttributes(directory, driveDirectory);
                    return(driveDirectory);
                }
            }

            var specialDirectory = new SpecialDirectoryEntry();

            if (SetSpecialFolderAttributes(directory, specialDirectory))
            {
                return(specialDirectory);
            }

            return(new DirectoryEntry());
        }
Esempio n. 4
0
 public BitmapImage GetFolderImage(SpecialDirectoryEntry directoryEntry)
 {
     return(GetFolderImage(directoryEntry.Name, Math.Abs(directoryEntry.IconId)));
 }