Ejemplo n.º 1
0
        public static int GetIndexForFile(string file)
        {
            string key;

            // icon files and exe files can have their custom icons
            if (Path.GetExtension(file).Equals(".ico", StringComparison.OrdinalIgnoreCase) ||
                Path.GetExtension(file).Equals(".exe", StringComparison.OrdinalIgnoreCase))
            {
                key = file;
            }
            else
            {
                key = Path.GetExtension(file).ToLower();
            }

            // clear the icon cache
            if (icons.Images.Count > 100)
            {
                icons.Images.Clear();
                iconIndecies.Clear();
            }

            if (iconIndecies.Contains(key))
            {
                return((int)iconIndecies[key]);
            }
            else
            {
                icons.Images.Add(DriveObject.GetImageForFile(file));
                int index = icons.Images.Count - 1;
                iconIndecies.Add(key, index);
                return(index);
            }
        }
Ejemplo n.º 2
0
        public ShellTree()
        {
            Sorted = true;
            TreeNode rootNode = Nodes.Add(Path.GetFileName(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)));

            rootNode.ImageIndex         = 6;
            rootNode.SelectedImageIndex = 6;
            rootNode.Tag = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

            TreeNode myFilesNode = rootNode.Nodes.Add(ResourceService.GetString("MainWindow.Windows.FileScout.MyDocuments"));

            myFilesNode.ImageIndex         = 7;
            myFilesNode.SelectedImageIndex = 7;
            try
            {
                myFilesNode.Tag = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            }
            catch (Exception)
            {
                myFilesNode.Tag = "C:\\";
            }

            myFilesNode.Nodes.Add("");

            TreeNode computerNode = rootNode.Nodes.Add(ResourceService.GetString("MainWindow.Windows.FileScout.MyComputer"));

            computerNode.ImageIndex         = 8;
            computerNode.SelectedImageIndex = 8;
            try
            {
                computerNode.Tag = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            }
            catch (Exception)
            {
                computerNode.Tag = "C:\\";
            }

            foreach (DriveInfo info in DriveInfo.GetDrives())
            {
                DriveObject drive = new DriveObject(info);

                TreeNode node = new TreeNode(drive.ToString());
                node.Nodes.Add(new TreeNode(""));
                node.Tag = drive.Drive.Substring(0, 2);
                computerNode.Nodes.Add(node);

                switch (info.DriveType)
                {
                case DriveType.Removable:
                    node.ImageIndex = node.SelectedImageIndex = 2;
                    break;

                case DriveType.Fixed:
                    node.ImageIndex = node.SelectedImageIndex = 3;
                    break;

                case DriveType.CDRom:
                    node.ImageIndex = node.SelectedImageIndex = 4;
                    break;

                case DriveType.Network:
                    node.ImageIndex = node.SelectedImageIndex = 5;
                    break;

                default:
                    node.ImageIndex = node.SelectedImageIndex = 3;
                    break;
                }
            }

            foreach (string directory in Directory.GetDirectories(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)))
            {
                TreeNode node = rootNode.Nodes.Add(Path.GetFileName(directory));
                node.Tag        = directory;
                node.ImageIndex = node.SelectedImageIndex = 0;
                node.Nodes.Add(new TreeNode(""));
            }

            rootNode.Expand();
            computerNode.Expand();

            InitializeComponent();
        }