public RootDirectoryViewModel(NativeDirectoryInfo nativeDirectoryInfo, IDirectoryViewModel parent)
     : base(nativeDirectoryInfo, parent)
 {
     NativeSystemInfo = nativeDirectoryInfo;
     var directoryUnfo = new DirectoryInfo(nativeDirectoryInfo.Path);
     var subDirectoryProvider = new SubDirectoriesProvider(directoryUnfo, this);
     var filesProvider = new FilesProvider(directoryUnfo,this);
     DisplayName = nativeDirectoryInfo.DisplayName;
     Path = nativeDirectoryInfo.Path;
     VisualPath = Parent.VisualPath + "\\" + DisplayName;
     //is drive?
     DriveInfo driveInfo =  Drives.FirstOrDefault(info => PathHelper.NormalizePath(info.Name) == PathHelper.NormalizePath(Path));
     HasItems = driveInfo?.IsReady ?? directoryUnfo.EnumerateDirectories().Any();
     SubDirectories = new AsyncLoadCollection<IDirectoryViewModel>(subDirectoryProvider);
     SubDirectories.CollectionChanged += _subDirectories_CollectionChanged;
     Files = new AsyncLoadCollection<ISystemObjectViewModel>(filesProvider);
     Children = new UnionCollectionEx<IDirectoryViewModel, ISystemObjectViewModel, ISystemObjectViewModel>(SubDirectories, Files);
 }
Ejemplo n.º 2
0
        public NativeDirectoryInfo(IntPtr pIDL, NativeDirectoryInfo shParent)
        {
            Parent = shParent;
            // We need the Desktop shell item to exist first.
            if (haveRootShell == false)
            {
                throw new Exception("The root shell item must be created before creating a sub-item");
            }

            // Create the FQ PIDL for this new item.
            _pIDL = WinAPI.ILCombine(shParent.PIDL, pIDL);

            // Get the properties of this item.
            WinAPI.SFGAOF uFlags = WinAPI.SFGAOF.SFGAO_FOLDER | WinAPI.SFGAOF.SFGAO_HASSUBFOLDER;

            // Here we get some basic attributes.
            DesktopShellFolder.GetAttributesOf(1, out _pIDL, out uFlags);
            IsFolder = Convert.ToBoolean(uFlags & WinAPI.SFGAOF.SFGAO_FOLDER);
            // bug not working
            HasSubFolder = Convert.ToBoolean(uFlags & WinAPI.SFGAOF.SFGAO_HASSUBFOLDER);
            // Now we want to get extended attributes such as the icon index etc.
            shInfo = new WinAPI.SHFILEINFO();
            WinAPI.SHGetFileInfo(_pIDL, WinAPI.FILE_ATTRIBUTE_NORMAL, out shInfo, (uint)Marshal.SizeOf(shInfo), vFlags);
            DisplayName = shInfo.szDisplayName;
            TypeName    = shInfo.szTypeName;
            IconIndex   = shInfo.iIcon;

            // Create the IShellFolder interface for this item.
            if (IsFolder)
            {
                uint hRes = shParent._shellFolder.BindToObject(pIDL, IntPtr.Zero, ref WinAPI.IID_IShellFolder,
                                                               out _shellFolder);
                if (hRes != 0)
                {
                    Marshal.ThrowExceptionForHR((int)hRes);
                }
            }
        }
Ejemplo n.º 3
0
        public List <NativeDirectoryInfo> GetDirectories()
        {
            lock (_locker)
            {
                var directories = new List <NativeDirectoryInfo>();

                // Make sure we have a folder.
                if (IsFolder == false)
                {
                    throw new Exception("Unable to retrieve sub-folders for a non-folder.");
                }
                if (!HasSubFolder || IsReady())
                {
                    return(directories);
                }
                // Get the IEnumIDList interface pointer.

                while (!pIDL.Equals(IntPtr.Zero) && iGot == 1)
                {
                    // Create the new ShellViewModel object.
                    var child = new NativeDirectoryInfo(pIDL, this);
                    directories.Add(child);
                    // Free the PIDL and reset counters.
                    Marshal.FreeCoTaskMem(pIDL);
                    pIDL = IntPtr.Zero;
                    iGot = 0;
                    // Grab the next item.
                    pEnum.Next(1, out pIDL, out iGot);
                }
                // Free the interface pointer.
                if (pEnum != null)
                {
                    Marshal.ReleaseComObject(pEnum);
                }
                return(directories);
            }
        }
 public override sealed void UpdateParameters()
 {
     var native = ((NativeDirectoryInfo) NativeSystemInfo);
     NativeSystemInfo = new NativeDirectoryInfo(native.PIDL, native.Parent);
     Icon = NativeSystemInfo.Icon;
 }