Ejemplo n.º 1
0
        static void Register(bool perUserInstallation)
        {
            SFGAO DefaultAttributes = SFGAO.SFGAO_FOLDER
                                      | SFGAO.SFGAO_DROPTARGET
                                      | SFGAO.SFGAO_HASSUBFOLDER
                                      | SFGAO.SFGAO_STORAGEANCESTOR
                                      | SFGAO.SFGAO_STORAGE
                                      | SFGAO.SFGAO_STREAM;

            Initializer.ProductGUID         = ProductID;
            Initializer.PerUserInstallation = perUserInstallation;
            Initializer.DisplayName         = "DeviceManagerFolder";
            Initializer.NamespaceLocation   = "MyComputer";
            Initializer.IconLocation        = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))) + "\\DeviceManagerFolder.ico";
            Initializer.Attributes          = (long)DefaultAttributes; // This is for sample's purposes. The default value in the component is already equal to this value
            Initializer.Config("RefreshButtonText=Refresh DeviceManagerFolder");
            Initializer.Config("IPCErrorText=DeviceManagerFolder cannot communicate with its server.");
            try
            {
                Initializer.Install();
                Console.WriteLine("Registered");
            }
            catch (Exception ex)
            {
                Console.WriteLine("EXCEPTION: ");
                Console.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 2
0
        public PIDLIST ParseDisplayName(string displayName, ref uint pchEaten, ref SFGAO attrs, HWND hwnd)
        {
            PIDLIST pidl;

            Com.ParseDisplayName(hwnd, null, displayName, ref pchEaten, out pidl, ref attrs);
            return(pidl);
        }
Ejemplo n.º 3
0
        /// <summary>Initializes a new instance of the <see cref="ShellItem"/> class.</summary>
        /// <param name="parent">The parent Shell item.</param>
        /// <param name="name">The name of the child item.</param>
        public ShellItem(ShellItem parent, string name)
        {
            if (parent == null)
            {
                throw new ArgumentNullException(nameof(parent));
            }
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (!parent.IsFolder)
            {
                throw new ArgumentException("Parent argument must be a folder.");
            }

            if (parent.IsFileSystem)
            {
                Init(ShellUtil.GetShellItemForPath(Path.Combine(parent.FileSystemPath, name)));
            }
            else
            {
                var   eaten = 0;
                PIDL  tempPidl;
                SFGAO attr = 0;
                parent.GetIShellFolder().ParseDisplayName(IntPtr.Zero, null, name, ref eaten, out tempPidl, ref attr);
                Init(tempPidl);
            }
        }
Ejemplo n.º 4
0
        static void Register(bool perUserInstallation)
        {
            SFGAO DefaultAttributes = SFGAO.SFGAO_FOLDER
                                      | SFGAO.SFGAO_DROPTARGET
                                      | SFGAO.SFGAO_HASSUBFOLDER
                                      | SFGAO.SFGAO_STORAGEANCESTOR
                                      | SFGAO.SFGAO_STORAGE
                                      | SFGAO.SFGAO_STREAM;

            Initializer.ProductGUID         = ProductID;
            Initializer.PerUserInstallation = perUserInstallation;
            Initializer.DisplayName         = "Samples.Mirror";
            Initializer.NamespaceLocation   = "MyComputer";
            Initializer.Attributes          = (long)DefaultAttributes; // This is for sample's purposes. The default value in the component is already equal to this value
            Initializer.Config("RefreshButtonText=Refresh Mirror");
            Initializer.Config("IPCErrorText=Overview cannot communicate with its server.");
            try
            {
                Initializer.Install();
                Console.WriteLine("Registered");
            }
            catch (Exception ex)
            {
                Console.WriteLine("EXCEPTION: ");
                Console.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 5
0
        public PIDLIST ParseDisplayName(string displayName, HWND hwnd)
        {
            uint  pchEaten      = 0;
            SFGAO pdwAttributes = 0;

            return(ParseDisplayName(displayName, ref pchEaten, ref pdwAttributes, hwnd));
        }
Ejemplo n.º 6
0
 internal static extern int SHParseDisplayName(
     [MarshalAs(UnmanagedType.LPWStr)] string pszName,
     IntPtr pbc,
     out IntPtr ppidl,
     SFGAO sfgaoIn,
     out SFGAO psfgaoOut
     );
Ejemplo n.º 7
0
        public void Refresh(bool newPath = false)
        {
            _displayName = null;
            if (newPath)
            {
                _fileName = null;
                _path     = null;
            }

            _attributes   = 0;
            _isFileSystem = null;
            _isFolder     = null;

            _smallIcon      = null;
            _largeIcon      = null;
            _extraLargeIcon = null;
            _jumboIcon      = null;

            OnPropertyChanged("DisplayName");
            if (newPath)
            {
                OnPropertyChanged("FileName");
                OnPropertyChanged("Path");
            }

            OnPropertyChanged("Attributes");
            OnPropertyChanged("IsFileSystem");
            OnPropertyChanged("IsFolder");

            OnPropertyChanged("SmallIcon");
            OnPropertyChanged("LargeIcon");
            OnPropertyChanged("ExtraLargeIcon");
            OnPropertyChanged("JumboIcon");
        }
Ejemplo n.º 8
0
    /// <summary>
    /// Get the PIDLs
    /// </summary>
    /// <param name="arrFI">Array of FileInfo</param>
    /// <returns>Array of PIDLs</returns>
    ///
    protected IntPtr[] GetPIDLs(FileInfo[] arrFI)
    {
        if (null == arrFI || 0 == arrFI.Length)
        {
            return(null);
        }

        IntPtr[]     arrPIDLs      = new IntPtr[arrFI.Length];
        IShellFolder oParentFolder = GetParentFolder(arrFI[0].DirectoryName);

        if (null == oParentFolder)
        {
            return(null);
        }

        int n = 0;

        foreach (FileInfo fi in arrFI)
        {
            // Get the file relative to folder
            uint   pchEaten      = 0;
            SFGAO  pdwAttributes = 0;
            IntPtr pPIDL         = IntPtr.Zero;
            int    nResult       = oParentFolder.ParseDisplayName(IntPtr.Zero, IntPtr.Zero, fi.Name.Length == 0 ? fi.FullName : fi.Name, ref pchEaten, out pPIDL, ref pdwAttributes);
            if (S_OK != nResult)
            {
                FreePIDLs(arrPIDLs);
                return(null);
            }
            arrPIDLs[n] = pPIDL;
            n++;
        }

        return(arrPIDLs);
    }
Ejemplo n.º 9
0
        protected override PSDriveInfo NewDrive(PSDriveInfo drive)
        {
            if (drive == null)
            {
                WriteError(new ErrorRecord(
                               new ArgumentNullException("drive"),
                               "NullDrive",
                               ErrorCategory.InvalidArgument,
                               null));

                return(null);
            }
            SFGAO  attributes;
            SFGAO  isContainerQuery = SFGAO.Browsable | SFGAO.Folder;
            IdList pidl             = GetPidlFromPath(drive.Root, isContainerQuery, out attributes);

            if ((attributes & isContainerQuery) == SFGAO.None)
            {
                WriteError(new ErrorRecord(
                               new ArgumentException("drive.Root"),
                               "NotAContainer",
                               ErrorCategory.InvalidArgument,
                               null));
                return(null);
            }

            return(new ShellPSDriveInfo((ShellFolder)ShellItem.GetShellItem(pidl, new ShellItem.ShellItemKnownInfo()
            {
                LoadedAttributes = isContainerQuery,
                Attributes = attributes
            }), drive));
        }
Ejemplo n.º 10
0
        private bool COM_Attribute_Check(SFGAO Check)
        {
            SFGAO sfgao;

            ComInterface.GetAttributes(Check, out sfgao);
            return((sfgao & Check) != 0);
        }
Ejemplo n.º 11
0
 private bool GetAttr(SFGAO attr)
 {
     if (!_attrsSet.Has(attr))
     {
         UpdateAttrs(attr);
     }
     return(_attrs.Has(attr));
 }
Ejemplo n.º 12
0
		public HResult GetAttributes(SFGAO sfgaoMask, out SFGAO psfgaoAttribs) {
			IShellFolder parentFolder = GetParent().GetIShellFolder();
			SFGAO result = sfgaoMask;

			parentFolder.GetAttributesOf(1, new IntPtr[] { Shell32.ILFindLastID(Pidl) }, ref result);
			psfgaoAttribs = result & sfgaoMask;
			return HResult.S_OK;
		}
Ejemplo n.º 13
0
        protected override bool IsItemContainer(string path)
        {
            SFGAO  attributes;
            SFGAO  isContainerQuery = SFGAO.Browsable | SFGAO.Folder;
            IdList pidl             = GetPidlFromPath(path, isContainerQuery, out attributes);

            return((attributes & isContainerQuery) != SFGAO.None);
        }
Ejemplo n.º 14
0
            public uint GetAttributes(SFGAO sfgaoMask)
            {
                var parentFolder = InternalGetParent().GetIShellFolder();
                var result       = sfgaoMask;

                parentFolder.GetAttributesOf(1, new[] { (IntPtr)PIDL.LastId }, ref result);
                return((uint)(result & sfgaoMask));
            }
Ejemplo n.º 15
0
        private bool COM_Attribute_Check(SFGAO Check)
        {
            var   comObject = this.ComInterface;
            SFGAO sfgao;

            comObject.GetAttributes(Check, out sfgao);
            Marshal.FinalReleaseComObject(comObject);
            return((sfgao & Check) != 0);
        }
Ejemplo n.º 16
0
        public HResult GetAttributes(SFGAO sfgaoMask, out SFGAO psfgaoAttribs)
        {
            IShellFolder parentFolder = GetParent().GetIShellFolder();
            SFGAO        result       = sfgaoMask;

            parentFolder.GetAttributesOf(1, new IntPtr[] { Shell32.ILFindLastID(Pidl) }, ref result);
            psfgaoAttribs = result & sfgaoMask;
            return(HResult.S_OK);
        }
Ejemplo n.º 17
0
 private static void UpdateFlagIfSet(ref SFGAO sfgao, SFGAO flag, bool set)
 {
     if (sfgao.HasFlag(flag))
     {
         if (set == false)
         {
             sfgao ^= flag;
         }
     }
 }
Ejemplo n.º 18
0
        public SFGAO GetAttributes(SFGAO sfgaoMask)
        {
            var parentFolder = GetParent().GetIShellFolder();
            var result       = sfgaoMask;

            parentFolder.GetAttributesOf(1,
                                         new[] { Shell32.ILFindLastID(Pidl) },
                                         ref result);
            return(result & sfgaoMask);
        }
Ejemplo n.º 19
0
        public SFGAO GetAttributes(SFGAO sfgaoMask)
        {
            //IShellFolder parentFolder = GetParent().GetIShellFolder();
            SFGAO result = sfgaoMask;

            //parentFolder.GetAttributesOf(1,
            //    new IntPtr[] { ILShell32.ILFindLastID(_pidl) },
            //    ref result);
            return(result & sfgaoMask);
        }
Ejemplo n.º 20
0
 private IdList GetPidlFromPath(string path, SFGAO queryForAttributes, out SFGAO attributes)
 {
     path = path.TrimEnd('\\');
     if (path == "")
     {
         ShellFolder desktopFolder = ShellFolder.DesktopFolder;
         attributes = desktopFolder.GetAttributes(queryForAttributes);
         return(desktopFolder.Pidl);
     }
     return(IdList.Parse(path, queryForAttributes, out attributes));
 }
Ejemplo n.º 21
0
        public static IdList SHParseDisplayName(string name, IBindCtx bc, SFGAO sfgaoIn, out SFGAO sfgaoOut)
        {
            IdList pidl;
            int    hr = _SHParseDisplayName(name, bc, out pidl, sfgaoIn, out sfgaoOut);

            if (hr != 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }
            return(pidl);
        }
Ejemplo n.º 22
0
        public static IntPtr GetShellFolderChildrenPIDL(IShellFolder parentFolder, string displayName)
        {
            var bindCtx = PtrCreateBindCtx();

            uint   pchEaten      = 0;
            SFGAO  pdwAttributes = SFGAO.NONE;
            IntPtr ppidl;

            parentFolder.ParseDisplayName(IntPtr.Zero, null, displayName, ref pchEaten, out ppidl, ref pdwAttributes);

            return(ppidl);
        }
Ejemplo n.º 23
0
        private static IntPtr GetShellFolderChildrenRelativePIDL(IntPtr hwnd, IShellFolder parentFolder, string displayName)
        {
            IntPtr bindCtx;

            CreateBindCtx(0, out bindCtx);
            uint   pchEaten      = 0;
            SFGAO  pdwAttributes = 0;
            IntPtr ppidl;

            parentFolder.ParseDisplayName(hwnd, bindCtx, displayName, ref pchEaten, out ppidl, ref pdwAttributes);
            return(ppidl);
        }
        // Synopsis:  Creates an IShellItemArray containing the sample files to be used in the CopyMultipleFiles sample
        //
        // Arguments: psiSrc - Source folder item
        //
        // Returns:   S_OK if successful
        private static IShellItemArray CreateShellItemArrayOfSampleFiles(IShellItem psiSrc)
        {
            var psfSampleSrc   = psiSrc.BindToHandler <IShellFolder>(null, BHID.BHID_SFObject.Guid());
            var rgpidlChildren = new PIDL[c_cMaxFilesToCreate];

            try
            {
                for (var i = 0; i < rgpidlChildren.Length; i++)
                {
                    var   szSampleFileName = string.Format("{0}{1}.{2}", c_szSampleFileName, i, c_szSampleFileExt);
                    SFGAO attr             = 0;
                    psfSampleSrc.ParseDisplayName(default, null, szSampleFileName, out _, out rgpidlChildren[i], ref attr);
Ejemplo n.º 25
0
        private static SFGAO LoadMissingAttributes(IShellItem nativeItem, SFGAO loadedAttrs, SFGAO curAttrs, SFGAO requestedAttrs)
        {
            SFGAO unloadedAttributes = requestedAttrs & (~loadedAttrs);

            if (unloadedAttributes != SFGAO.None)
            {
                SFGAO newAttributes;
                nativeItem.GetAttributes(unloadedAttributes, out newAttributes);
                curAttrs |= newAttributes;
            }
            return(curAttrs);
        }
Ejemplo n.º 26
0
        private SFGAO GetAttributes()
        {
            SFGAO attrs = 0;

            if (_shellItem?.GetAttributes(SFGAO.FILESYSTEM | SFGAO.FOLDER | SFGAO.HIDDEN | SFGAO.STREAM, out attrs) !=
                NativeMethods.S_OK)
            {
                attrs = 0;
            }

            return(attrs);
        }
Ejemplo n.º 27
0
        private void Init(ShellItemKnownInfo knownInfo)
        {
            _loadedAttrs = knownInfo.LoadedAttributes;
            _attrs = knownInfo.Attributes;
            _parentParsePath = knownInfo.ParentParsePath;

            _pidl = new Lazy<IdList>(() => SHGetIDListFromObject(nativeItem));
            _parentFolder = new Lazy<ShellFolder>(() =>
            {
                var nativeParent = nativeItem.GetParent();
                if (nativeParent == null)
                    return null;
                return new ShellFolder(nativeParent, null, new ShellItemKnownInfo());
            });
            _desktopAbsoluteParsePath = new Lazy<string>(() => nativeItem.GetDisplayName(SIGDN.DesktopAbsoluteParsing));
            _parseName = new Lazy<string>(() => nativeItem.GetDisplayName(SIGDN.ParentRelativeParsing));
            _parsePath = new Lazy<string>(() =>
            {
                if (Pidl.Parts.Count == 0) // The actual desktop
                    return "";
                try
                {
                    if (_parentParsePath != null)
                    {
                        string normParentPath = _parentParsePath.Trim('\\');
                        if (normParentPath != "")
                            normParentPath += "\\";
                        return normParentPath + ParseName;
                    }
                    else
                        return DesktopAbsoluteParsePath;
                }
                catch (ArgumentException)
                {
                    IdList childPidl = new IdList(Pidl.Parts[Pidl.Parts.Count - 1]);
                    return GetParentFolder().NativeFolder.GetDisplayNameOf(childPidl, SHGDNF.ForParsing);
                }
            });
            _fullParsePath = new Lazy<string>(() =>
            {
                if (GetParentFolder() == null)
                    return "";
                string parentParsePath = GetParentFolder().FullParsePath.TrimEnd('\\');
                if (parentParsePath != "")
                    parentParsePath += "\\";
                return parentParsePath + nativeItem.GetDisplayName(SIGDN.ParentRelativeParsing);
            });
            /*_displayName = new Lazy<string>(() => GetParentFolder().NativeFolder.GetDisplayNameOf(
                new IdList(Pidl.Parts[Pidl.Parts.Count - 1]),
                SHGDNF.InFolder | SHGDNF.Normal));*/
            _displayName = new Lazy<string>(() => nativeItem.GetDisplayName(SIGDN.NormalDisplay));
        }
        /// <summary>
        /// Determines whether an overlay should be shown for the shell item with the path 'path' and
        /// the shell attributes 'attributes'.
        /// </summary>
        /// <param name="path">The path for the shell item. This is not necessarily the path
        /// to a physical file or folder.</param>
        /// <param name="attributes">The attributes of the shell item.</param>
        /// <returns>
        ///   <c>true</c> if this an overlay should be shown for the specified item; otherwise, <c>false</c>.
        /// </returns>
        protected override bool CanShowOverlay(string path, SFGAO attributes)
        {
            //  We are going to show the overlay only for read only files.
            if (attributes.HasFlag(SFGAO.SFGAO_FILESYSTEM) == false || attributes.HasFlag(SFGAO.SFGAO_FOLDER)
                || attributes.HasFlag(SFGAO.SFGAO_STREAM))
                return false;

            //  Get the file attributes.
            var fileAttributes = new FileInfo(path);

            //  Return true if the file is read only, meaning we'll show the overlay.
            return fileAttributes.IsReadOnly;
        }
Ejemplo n.º 29
0
        public override bool TryGetAttributes(ShellItemIdList relativeIdl, out SFGAO attributes)
        {
            var name = ValidateNotExistingPidl(relativeIdl);

            if (name == null) // ? this is not ours
            {
                return(base.TryGetAttributes(relativeIdl, out attributes));
            }

            // the default SFGAO for an item (+ SFGAO_FILESYSTEM)
            attributes = DefaultItemAttributes | SFGAO.SFGAO_FILESYSTEM;
            return(true);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Converts a path representation 'C:\' into an
        /// <see cref="IntPtr"/> formated PIDL representation.
        ///
        /// The memory of the PIDL returned must be freed with
        /// <see cref="Marshal.FreeCoTaskMem"/> by the caller.
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static IntPtr GetPIDLFromPath(string path)
        {
            if (string.IsNullOrEmpty(path) == true)
            {
                return(IntPtr.Zero);
            }

            IntPtr pidlPtr = default(IntPtr);

            // Handle Special Folder path notation
            if (ShellHelpers.IsSpecialPath(path) == ShellHelpers.SpecialPath.IsSpecialPath)
            {
                if (HasNoPIDL(path) == true)
                {
                    return(IntPtr.Zero);
                }

                using (var kf = KnownFolderHelper.FromPath(path))
                {
                    if (kf != null)
                    {
                        try
                        {
                            kf.Obj.GetIDList((uint)KNOWN_FOLDER_FLAG.KF_NO_FLAGS, out pidlPtr);
                        }
                        catch (ArgumentException)
                        {
                            Console.WriteLine("ArgumentException '{0}'", path);
                            return(IntPtr.Zero);
                        }

                        return(pidlPtr);
                    }
                }
            }

            using (var desktopFolder = new ShellFolderDesktop())
            {
                SFGAO pdwAttributes = 0;
                uint  pchEaten      = 0;

                if (desktopFolder.Obj.ParseDisplayName(IntPtr.Zero, IntPtr.Zero,
                                                       path, ref pchEaten, out pidlPtr,
                                                       ref pdwAttributes) == (uint)HRESULT.S_OK)
                {
                    return(pidlPtr);
                }
            }

            return(IntPtr.Zero);
        }
        /// <summary>
        /// Determines whether an overlay should be shown for the shell item with the path 'path' and
        /// the shell attributes 'attributes'.
        /// </summary>
        /// <param name="path">The path for the shell item. This is not necessarily the path
        /// to a physical file or folder.</param>
        /// <param name="attributes">The attributes of the shell item.</param>
        /// <returns>
        ///   <c>true</c> if this an overlay should be shown for the specified item; otherwise, <c>false</c>.
        /// </returns>
        protected override bool CanShowOverlay(string path, SFGAO attributes)
        {
            //  We are going to show the overlay only for read only files.
            if (attributes.HasFlag(SFGAO.SFGAO_FILESYSTEM) == false || attributes.HasFlag(SFGAO.SFGAO_FOLDER) ||
                attributes.HasFlag(SFGAO.SFGAO_STREAM))
            {
                return(false);
            }

            //  Get the file attributes.
            var fileAttributes = new FileInfo(path);

            //  Return true if the file is read only, meaning we'll show the overlay.
            return(fileAttributes.IsReadOnly);
        }
Ejemplo n.º 32
0
    /// <summary>
    /// Gets the parent folder
    /// </summary>
    /// <param name="folderName">Folder path</param>
    /// <returns>IShellFolder for the folder (relative from the desktop)</returns>
    private IShellFolder GetParentFolder(string folderName)
    {
        if (null == _oParentFolder)
        {
            IShellFolder oDesktopFolder = GetDesktopFolder();
            if (null == oDesktopFolder)
            {
                return(null);
            }

            // Get the PIDL for the folder file is in
            IntPtr pPIDL         = IntPtr.Zero;
            uint   pchEaten      = 0;
            SFGAO  pdwAttributes = 0;
            if (folderName == null)
            {
                folderName = "::{" + IID_MyComputer.ToString() + "}";
            }
            int nResult = oDesktopFolder.ParseDisplayName(IntPtr.Zero, IntPtr.Zero, folderName, ref pchEaten, out pPIDL, ref pdwAttributes);
            if (S_OK != nResult)
            {
                return(null);
            }

            IntPtr pStrRet = Marshal.AllocCoTaskMem(MAX_PATH * 2 + 4);
            Marshal.WriteInt32(pStrRet, 0, 0);
            nResult = _oDesktopFolder.GetDisplayNameOf(pPIDL, SHGNO.FORPARSING, pStrRet);
            StringBuilder strFolder = new StringBuilder(MAX_PATH);
            StrRetToBuf(pStrRet, pPIDL, strFolder, MAX_PATH);
            Marshal.FreeCoTaskMem(pStrRet);
            pStrRet          = IntPtr.Zero;
            _strParentFolder = strFolder.ToString();

            // Get the IShellFolder for folder
            IntPtr pUnknownParentFolder = IntPtr.Zero;
            nResult = oDesktopFolder.BindToObject(pPIDL, IntPtr.Zero, ref IID_IShellFolder, out pUnknownParentFolder);
            // Free the PIDL first
            Marshal.FreeCoTaskMem(pPIDL);
            if (S_OK != nResult)
            {
                return(null);
            }
            _oParentFolder = (IShellFolder)Marshal.GetTypedObjectForIUnknown(pUnknownParentFolder, typeof(IShellFolder));
        }

        return(_oParentFolder);
    }
Ejemplo n.º 33
0
        private IShellFolder GetParentFolder(string path)
        {
            if (null == _ParentFolder)
            {
                IShellFolder oDesktopFolder = GetDesktopFolder();

                if (null == oDesktopFolder)
                {
                    return(null);
                }

                // Get the PIDL for the folder file is in
                IntPtr PIDL       = IntPtr.Zero;
                uint   eaten      = 0;
                SFGAO  attributes = 0;
                int    result     = oDesktopFolder.ParseDisplayName(IntPtr.Zero, IntPtr.Zero, path, ref eaten, out PIDL, ref attributes);

                if (S_OK != result)
                {
                    return(null);
                }

                IntPtr ret = Marshal.AllocCoTaskMem(MAX_PATH * 2 + 4);
                Marshal.WriteInt32(ret, 0, 0);
                result = _DesktopFolder.GetDisplayNameOf(PIDL, SHGNO.FORPARSING, ret);
                StringBuilder folder = new StringBuilder(MAX_PATH);
                StrRetToBuf(ret, PIDL, folder, MAX_PATH);
                Marshal.FreeCoTaskMem(ret);
                ret = IntPtr.Zero;
                _ParentFolderPath = folder.ToString();
                // Get the IShellFolder for folder
                IntPtr unknownParentFolder = IntPtr.Zero;
                result = oDesktopFolder.BindToObject(PIDL, IntPtr.Zero, ref IID_IShellFolder, out unknownParentFolder);
                // Free the PIDL first
                Marshal.FreeCoTaskMem(PIDL);

                if (S_OK != result)
                {
                    return(null);
                }

                _ParentFolder = (IShellFolder)Marshal.GetTypedObjectForIUnknown(unknownParentFolder, typeof(IShellFolder));
            }

            return(_ParentFolder);
        }
Ejemplo n.º 34
0
        /// <summary>
        /// Translates the display name of a file object or a folder into an item identifier list.
        /// </summary>
        /// <param name="hwnd">A window handle. The client should provide a window handle if it displays a dialog or message box. Otherwise set hwnd to NULL.</param>
        /// <param name="pbc">Optional. A pointer to a bind context used to pass parameters as inputs and outputs to the parsing function.</param>
        /// <param name="pszDisplayName">A null-terminated Unicode string with the display name.</param>
        /// <param name="pchEaten">A pointer to a ULONG value that receives the number of characters of the display name that was parsed. If your application does not need this information, set pchEaten to NULL, and no value will be returned.</param>
        /// <param name="ppidl">When this method returns, contains a pointer to the PIDL for the object.</param>
        /// <param name="pdwAttributes">The value used to query for file attributes. If not used, it should be set to NULL.</param>
        /// <returns>
        /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
        /// </returns>
        /// <exception cref="System.NotImplementedException"></exception>
        int IShellFolder.ParseDisplayName(IntPtr hwnd, IntPtr pbc, string pszDisplayName, ref uint pchEaten, out IntPtr ppidl, ref SFGAO pdwAttributes)
        {
            //  First we can decode the pidl from the display name.
            var idList = IdList.FromParsingString(pszDisplayName);
            ppidl = PidlManager.IdListToPidl(idList);

            //  We always eat the entire display string for SharpShell PIDL/DisplayName parsing.
            pchEaten = (uint)pszDisplayName.Length;


            //  In theory, we should understand the pidl.
            var item = GetChildItem(idList);
            var name = item.GetDisplayName(DisplayNameContext.Normal);

            //  TODO: We may be asked to get the attributes at the same time. If so, we must set them here.
            return WinError.S_OK;
        }
        /// <summary>
        /// Specifies whether an icon overlay should be added to a Shell object's icon.
        /// </summary>
        /// <param name="pwszPath">A Unicode string that contains the fully qualified path of the Shell object.</param>
        /// <param name="dwAttrib">The object's attributes. For a complete list of file attributes and their associated flags, see IShellFolder::GetAttributesOf.</param>
        /// <returns>
        /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
        /// </returns>
        int IShellIconOverlayIdentifier.IsMemberOf(string pwszPath, SFGAO dwAttrib)
        {
            //  Log this key event.
            Log(string.Format("IsMemberOf for {0}", pwszPath));

            //  Always wrap calls to the abstract functions in exception handlers.
            try
            {
                var result = CanShowOverlay(pwszPath, dwAttrib);
                Log("Result is: " + result);

                //  Return OK if we should show the overlay, otherwise false.
                return CanShowOverlay(pwszPath, dwAttrib) ? WinError.S_OK : WinError.S_FALSE;
            }
            catch (Exception exception)
            {
                //  Log the exception.
                LogError("An exception occured when determining whether to show the overlay for '" + pwszPath + "'.", exception);

                //  Return false so we don't try and get the icon for a server that is erroring.
                return WinError.S_FALSE;
            }
        }
 int IShellFolder2.GetAttributesOf(uint cidl, IntPtr apidl, ref SFGAO rgfInOut)
 {
     return ((IShellFolder2)shellFolderImpl).GetAttributesOf(cidl, apidl, ref rgfInOut);
 }
 public bool IsMemberOf(string pwszPath, SFGAO dwAttrib)
 {
     bool flag;
     if (this.FIdentifierPtr == IntPtr.Zero)
     {
         throw new ObjectDisposedException("OverlayIdentifier");
     }
     IShellIconOverlayIdentifier typedObjectForIUnknown = (IShellIconOverlayIdentifier) Marshal.GetTypedObjectForIUnknown(this.FIdentifierPtr, typeof(IShellIconOverlayIdentifier));
     SEM uMode = Windows.SetErrorMode(SEM.SEM_DEFAULT | SEM.SEM_FAILCRITICALERRORS);
     try
     {
         flag = typedObjectForIUnknown.IsMemberOf(pwszPath, dwAttrib) == 0;
     }
     finally
     {
         Windows.SetErrorMode(uMode);
         Marshal.ReleaseComObject(typedObjectForIUnknown);
     }
     return flag;
 }
Ejemplo n.º 38
0
 private IdList GetPidlFromPath(string path, SFGAO queryForAttributes, out SFGAO attributes)
 {
     path = path.TrimEnd('\\');
     if (path == "")
     {
         ShellFolder desktopFolder = ShellFolder.DesktopFolder;
         attributes = desktopFolder.GetAttributes(queryForAttributes);
         return desktopFolder.Pidl;
     }
     return IdList.Parse(path, queryForAttributes, out attributes);
 }
Ejemplo n.º 39
0
 public SFGAO GetAttributes(SFGAO attributes)
 {
     _attrs = LoadMissingAttributes(nativeItem, _loadedAttrs, _attrs, attributes);
     _loadedAttrs = _loadedAttrs | attributes;
     return _attrs;
 }
Ejemplo n.º 40
0
 public static IdList Parse(string displayName, SFGAO queryForAttributes, out SFGAO attributes)
 {
     return ShellNativeFunctions.SHParseDisplayName(displayName, null, queryForAttributes, out attributes);
 }
 /// <summary>
 /// Translates the display name of a file object or a folder into an item identifier list.
 /// </summary>
 /// <param name="hwnd">A window handle. The client should provide a window handle if it displays a dialog or message box. Otherwise set hwnd to NULL.</param>
 /// <param name="pbc">Optional. A pointer to a bind context used to pass parameters as inputs and outputs to the parsing function.</param>
 /// <param name="pszDisplayName">A null-terminated Unicode string with the display name.</param>
 /// <param name="pchEaten">A pointer to a ULONG value that receives the number of characters of the display name that was parsed. If your application does not need this information, set pchEaten to NULL, and no value will be returned.</param>
 /// <param name="ppidl">When this method returns, contains a pointer to the PIDL for the object.</param>
 /// <param name="pdwAttributes">The value used to query for file attributes. If not used, it should be set to NULL.</param>
 /// <returns>
 /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
 /// </returns>
 /// <exception cref="System.NotImplementedException"></exception>
 int IShellFolder.ParseDisplayName(IntPtr hwnd, IntPtr pbc, string pszDisplayName, ref uint pchEaten, out IntPtr ppidl, ref SFGAO pdwAttributes)
 {
     //  Use the ShellFolderImpl to handle the details.
     return ((IShellFolder)shellFolderImpl).ParseDisplayName(hwnd, pbc, pszDisplayName, ref pchEaten, out ppidl,
         ref pdwAttributes);
 }
Ejemplo n.º 42
0
 private static SFGAO LoadMissingAttributes(IShellItem nativeItem, SFGAO loadedAttrs, SFGAO curAttrs, SFGAO requestedAttrs)
 {
     SFGAO unloadedAttributes = requestedAttrs & (~loadedAttrs);
     if (unloadedAttributes != SFGAO.None)
     {
         SFGAO newAttributes;
         nativeItem.GetAttributes(unloadedAttributes, out newAttributes);
         curAttrs |= newAttributes;
     }
     return curAttrs;
 }
 int IShellFolder2.ParseDisplayName(IntPtr hwnd, IntPtr pbc, string pszDisplayName, ref uint pchEaten,
     out IntPtr ppidl, ref SFGAO pdwAttributes)
 {
     return ((IShellFolder2)shellFolderImpl).ParseDisplayName(hwnd, pbc, pszDisplayName, pchEaten, out ppidl,
         ref pdwAttributes);
 }
 /// <summary>
 /// Retrieves the attributes of one or more file objects or subfolders.
 /// Return value: error code, if any
 /// </summary>
 /// <param name="cidl">Number of file objects from which to retrieve attributes.</param>
 /// <param name="apidl">Address of an array of pointers to ITEMIDLIST structures, each of which  uniquely identifies a file object relative to the parent folder.</param>
 /// <param name="rgfInOut">Address of a single ULONG value that, on entry contains the attributes that the caller is
 /// requesting. On exit, this value contains the requested attributes that are common to all of the specified objects. this value can be from the SFGAO enum</param>
 /// <returns>
 /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
 /// </returns>
 /// <exception cref="System.NotImplementedException"></exception>
 int IShellFolder.GetAttributesOf(uint cidl, IntPtr apidl, ref SFGAO rgfInOut)
 {
     //  Use the ShellFolderImpl to handle the details.
     return ((IShellFolder)shellFolderImpl).GetAttributesOf(cidl, apidl, ref rgfInOut);
 }
Ejemplo n.º 45
0
        /// <summary>
        /// Retrieves the attributes of one or more file objects or subfolders.
        /// Return value: error code, if any
        /// </summary>
        /// <param name="cidl">Number of file objects from which to retrieve attributes.</param>
        /// <param name="apidl">Address of an array of pointers to ITEMIDLIST structures, each of which  uniquely identifies a file object relative to the parent folder.</param>
        /// <param name="rgfInOut">Address of a single ULONG value that, on entry contains the attributes that the caller is
        /// requesting. On exit, this value contains the requested attributes that are common to all of the specified objects. this value can be from the SFGAO enum</param>
        /// <returns>
        /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
        /// </returns>
        /// <exception cref="System.NotImplementedException"></exception>
        int IShellFolder.GetAttributesOf(uint cidl, IntPtr apidl, ref SFGAO rgfInOut)
        {
            //  Get each id list.
            var idlists = PidlManager.APidlToIdListArray(apidl, (int)cidl);

            //  Now we can ask for the attributes of each item. We only ask for attributes that
            //  are set in the flags - clearing them if they don't apply to every item.
            var allItems = idlists.Select(GetChildItem).ToList();
            var allAttributes = allItems.Select(sni => sni.GetAttributes()).ToList();
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_BROWSABLE, allAttributes.All(a => a.HasFlag(AttributeFlags.IsBrowsable)));
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_CANCOPY, allAttributes.All(a => a.HasFlag(AttributeFlags.CanByCopied)));
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_CANDELETE, allAttributes.All(a => a.HasFlag(AttributeFlags.CanBeDeleted)));
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_CANLINK, allAttributes.All(a => a.HasFlag(AttributeFlags.CanBeLinked)));
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_CANMOVE, allAttributes.All(a => a.HasFlag(AttributeFlags.CanBeMoved)));
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_CANRENAME, allAttributes.All(a => a.HasFlag(AttributeFlags.CanBeRenamed)));
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_COMPRESSED, allAttributes.All(a => a.HasFlag(AttributeFlags.IsCompressed)));
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_DROPTARGET, allAttributes.All(a => a.HasFlag(AttributeFlags.IsDropTarget)));
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_ENCRYPTED, allAttributes.All(a => a.HasFlag(AttributeFlags.IsEncrypted)));
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_FILESYSANCESTOR, allAttributes.All(a => a.HasFlag(AttributeFlags.IsFileSystemAncestor)));
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_FILESYSTEM, allAttributes.All(a => a.HasFlag(AttributeFlags.IsFileSystem)));
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_FOLDER, allAttributes.All(a => a.HasFlag(AttributeFlags.IsFolder)));
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_GHOSTED, allAttributes.All(a => a.HasFlag(AttributeFlags.IsBrowsable)));
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_HASPROPSHEET, allAttributes.All(a => a.HasFlag(AttributeFlags.HasPropertySheets)));
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_HASSUBFOLDER, allAttributes.All(a => a.HasFlag(AttributeFlags.MayContainSubFolders)));
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_HIDDEN, allAttributes.All(a => a.HasFlag(AttributeFlags.IsHidden)));
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_ISSLOW, allAttributes.All(a => a.HasFlag(AttributeFlags.IsSlow)));
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_LINK, allAttributes.All(a => a.HasFlag(AttributeFlags.IsLink)));
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_NEWCONTENT, allAttributes.All(a => a.HasFlag(AttributeFlags.HasOrIsNewContent)));
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_READONLY, allAttributes.All(a => a.HasFlag(AttributeFlags.IsReadOnly)));
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_REMOVABLE, allAttributes.All(a => a.HasFlag(AttributeFlags.IsRemovableMedia)));
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_SHARE, allAttributes.All(a => a.HasFlag(AttributeFlags.IsShared)));
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_STORAGE, allAttributes.All(a => a.HasFlag(AttributeFlags.IsStorage)));
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_STORAGEANCESTOR, allAttributes.All(a => a.HasFlag(AttributeFlags.IsStorageAncestor)));
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_STREAM, allAttributes.All(a => a.HasFlag(AttributeFlags.IsStream)));
            UpdateFlagIfSet(ref rgfInOut, SFGAO.SFGAO_VALIDATE, allAttributes.All(a => a.HasFlag(AttributeFlags.IsVolatile)));

            //  And we're done.
            return WinError.S_OK;
        }
Ejemplo n.º 46
0
 private static void UpdateFlagIfSet(ref SFGAO sfgao, SFGAO flag, bool set)
 {
     if (sfgao.HasFlag(flag))
     {
         if (set == false)
             sfgao ^= flag;
     }
 }
Ejemplo n.º 47
0
 public static extern uint SHParseDisplayName(string pszName, IntPtr zero, [Out] out IntPtr ppidl,
     SFGAO sfgaoIn, [Out] out SFGAO psfgaoOut);
Ejemplo n.º 48
0
 internal static extern int SHParseDisplayName(
     [MarshalAs(UnmanagedType.LPWStr)] string pszName,
     IntPtr pbc,
     out IntPtr ppidl,
     SFGAO sfgaoIn,
     out SFGAO psfgaoOut
 );
 /// <summary>
 /// Determines whether an overlay should be shown for the shell item with the path 'path' and 
 /// the shell attributes 'attributes'.
 /// </summary>
 /// <param name="path">The path for the shell item. This is not necessarily the path
 /// to a physical file or folder.</param>
 /// <param name="attributes">The attributes of the shell item.</param>
 /// <returns>
 ///   <c>true</c> if this an overlay should be shown for the specified item; otherwise, <c>false</c>.
 /// </returns>
 protected abstract bool CanShowOverlay(string path, SFGAO attributes);
Ejemplo n.º 50
-1
        public SFGAO GetAttributes(SFGAO sfgaoMask)
        {
            IShellFolder parentFolder = GetParent().GetIShellFolder();
            SFGAO result = sfgaoMask;

            parentFolder.GetAttributesOf(1,
                new IntPtr[] { Shell32.ILFindLastID(m_Pidl) },
                ref result);
            return result & sfgaoMask;
        }