public OpenFolderRoot GetComputer()
        {
            OpenFolderRoot root = new OpenFolderRoot();

            root.Name  = "Computer";
            root.Image = FileInfoHelper.GetComputerImage(false);

            List <OpenFolderItem> items = new List <OpenFolderItem>();

            DriveInfo[] drives = DriveInfo.GetDrives();
            foreach (var drive in drives)
            {
                if (drive.IsReady)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append(drive.DriveType);
                    sb.Append(" (");
                    sb.Append(drive.Name, 0, drive.Name.Length - 1);
                    sb.Append(") ");
                    sb.Append(drive.VolumeLabel);

                    OpenFolderItem item = new OpenFolderItem(drive.Name);
                    item.Name  = sb.ToString();
                    item.Image = FileInfoHelper.GetSmallImage(item.Path, false);
                    items.Add(item);
                }
            }

            root.Children = items;

            return(root);
        }
Exemple #2
0
        public OpenFolderRoot GetFavorites()
        {
            OpenFolderRoot root = new OpenFolderRoot();

            root.Name  = "Favorites";
            root.Image = FileInfoHelper.GetFavoritesImage(false);
            root.Path  = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Links");

            if (Directory.Exists(root.Path))
            {
                List <OpenFolderItem> items = new List <OpenFolderItem>();
                foreach (string file in Directory.GetFiles(root.Path))
                {
                    if (ShortcutHelper.IsShortcut(file))
                    {
                        OpenFolderItem item     = new OpenFolderItem();
                        string         resolved = ShortcutHelper.ResolveShortcut(file);
                        item.Path  = resolved;
                        item.Name  = Path.GetFileNameWithoutExtension(file);
                        item.Image = FileInfoHelper.GetImage(file, false);
                        items.Add(item);
                    }
                }
                root.Children = items;
            }
            return(root);
        }
Exemple #3
0
        private ICollection <OpenFolderItem> LoadChildren()
        {
            List <OpenFolderItem> items = new List <OpenFolderItem>();

            try
            {
                foreach (string directory in Directory.GetDirectories(Path))
                {
                    OpenFolderItem item = new OpenFolderItem(directory);
                    item.Name  = System.IO.Path.GetFileName(directory);
                    item.Image = FileInfoHelper.GetFolderImage(false);
                    items.Add(item);
                }
            }
            catch (UnauthorizedAccessException) { }
            catch (ArgumentException) { }
            catch (DirectoryNotFoundException) { }

            return(new ReadOnlyCollection <OpenFolderItem>(items));
        }