Пример #1
0
        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);
        }
Пример #2
0
        private void UpdateFolder()
        {
            List <FileItem> folder = new List <FileItem>();

            try
            {
                if (_SelectedFolder == null)
                {
                    return;
                }

                string path = _SelectedFolder.Path ?? string.Empty;
                if (!string.IsNullOrEmpty(path))
                {
                    if (IsDirectoryChooser)
                    {
                        string[] directories = Directory.GetDirectories(path);

                        foreach (string directory in directories)
                        {
                            DirectoryInfo di = new DirectoryInfo(directory);

                            FileItem item = new FileItem();
                            item.Path  = directory;
                            item.Name  = Path.GetFileName(directory);
                            item.Date  = di.LastWriteTime.ToString(DateFormat, CultureInfo.InvariantCulture);
                            item.Image = FileInfoHelper.GetSmallImage(directory, true);
                            folder.Add(item);
                        }
                    }
                    else
                    {
                        string[] files = Directory.GetFiles(path);

                        foreach (string file in files)
                        {
                            if (!string.IsNullOrEmpty(SelectedFileFilterExtension))
                            {
                                if (Path.GetExtension(file) != SelectedFileFilterExtension)
                                {
                                    continue;
                                }
                            }

                            FileInfo fi = new FileInfo(file);

                            FileItem item = new FileItem();
                            item.Path  = file;
                            item.Name  = Path.GetFileName(file);
                            item.Date  = fi.LastWriteTime.ToString(DateFormat, CultureInfo.InvariantCulture);
                            item.Size  = string.Format("{0}", fi.Length / 1024);
                            item.Type  = FileInfoHelper.GetFileType(file);
                            item.Image = FileInfoHelper.GetSmallImage(file, true);
                            folder.Add(item);
                        }
                    }
                }
            }
            catch (UnauthorizedAccessException)
            {
            }

            Folder = new ReadOnlyCollection <FileItem>(folder);
        }