Пример #1
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));
        }
Пример #2
0
 public bool AbsolutePidlEquals(IdList other)
 {
     if (Parts.Count == other.Parts.Count)
     {
         Parts.Zip(other.Parts, (a,b) => a.Equals(b));
     }
     int hr = ShellFolder.DesktopFolder.NativeFolder.CompareIDs(0, this, other);
     bool isError = ((uint)(hr)) >> 31 == 1;
     if (isError)
         Marshal.ThrowExceptionForHR(hr);
     int code = unchecked((int)(((uint)hr) & 0xFFFF));
     return code == 0;
 }
Пример #3
0
 public string GetValue(IdList list)
 {
     if (value != null)
         return value;
     int curOffset = 0;
     int idx = 0;
     while (curOffset < offset)
     {
         byte[] curId = list.Parts[idx].Value;
         if (curOffset + 2 + curId.Length > offset)
         {
             return GetValueFrom(list, idx, offset-curOffset);
         }
         curOffset += curId.Length + 2;
         idx++;
     }
     throw new ArgumentException(String.Format("The offset {0} is not within the IdList", offset), "list");
 }
Пример #4
0
 public IEnumerable<ShellItem> GetChildItems(int bulkRequestCount = 10)
 {
     IEnumIDList enumIdList;
     int hr = NativeFolder.EnumObjects(IntPtr.Zero, SHCONTF.Folder | SHCONTF.NonFolders | SHCONTF.IncludeHidden | SHCONTF.IncludeSuperHidden,
         out enumIdList);
     if (hr == ShellConsts.S_FALSE)
         yield break;
     else if (hr != ShellConsts.S_OK)
         Marshal.ThrowExceptionForHR(hr);
     try
     {
         IntPtr[] idListOut = new IntPtr[bulkRequestCount];
         uint fetched;
         do
         {
             hr = enumIdList.Next((uint)bulkRequestCount, idListOut, out fetched);
             if (hr != ShellConsts.S_OK && hr != ShellConsts.S_FALSE)
                 Marshal.ThrowExceptionForHR(hr);
             IdList[] list = new IdList[(int)fetched];
             for (int i = 0; i < fetched; i++)
             {
                 list[i] = new IdList(idListOut[i]);
                 Marshal.FreeCoTaskMem(idListOut[i]);
             }
             foreach (var idList in list)
             {
                 IdList absId = new IdList(Pidl.Parts.Concat(idList.Parts));
                 yield return ShellItem.GetShellItem(absId, new ShellItemKnownInfo()
                 {
                     ParentParsePath = ParsePath
                 });
             }
         } while (hr == ShellConsts.S_OK);
     }
     finally
     {
         if (enumIdList != null)
             Marshal.ReleaseComObject(enumIdList);
     }
 }
Пример #5
0
 public static string GetDisplayNameOf(this IShellFolder folder, IdList pidl, SHGDNF uFlags)
 {
     //StrRet value;
     StrRetNative value;
     int hr = folder._GetDisplayNameOf(pidl, uFlags, out value);
     if (hr != ShellConsts.S_OK)
         Marshal.ThrowExceptionForHR(hr);
     return new StrRet(value).GetValue(pidl);
 }
Пример #6
0
 private string GetValueFrom(IdList list, int startIdx, int startOffset)
 {
     StringBuilder sb = new StringBuilder();
     int innerOffset = startOffset - 2;
     int idIdx = startIdx;
     List<byte> ansiStr = new List<byte>();
     while (true)
     {
         byte[] curId = list.Parts[idIdx].Value;
         byte[] cb = BitConverter.GetBytes((ushort)(curId.Length + sizeof(ushort)));
         for (; innerOffset < curId.Length; innerOffset++)
         {
             byte b;
             if (innerOffset < 0)
                 b = cb[innerOffset + 2];
             else
                 b = curId[innerOffset];
             if (b == 0)
             {
                 return Encoding.Default.GetString(ansiStr.ToArray());
             }
             else
             {
                 ansiStr.Add(b);
             }
         }
         innerOffset = -2;
         idIdx++;
     }
 }
Пример #7
0
 internal static ShellItem GetShellItem(IdList pidl, ShellItemKnownInfo knownInfo)
 {
     IShellItem nativeItem = SHCreateItemFromIDList<IShellItem>(pidl);
     knownInfo.Attributes = LoadMissingAttributes(nativeItem, knownInfo.LoadedAttributes, knownInfo.Attributes, SFGAO.Browsable | SFGAO.Folder);
     knownInfo.LoadedAttributes |= SFGAO.Browsable | SFGAO.Folder;
     if ((knownInfo.Attributes & (SFGAO.Browsable | SFGAO.Folder)) != SFGAO.None)
         return new ShellFolder(nativeItem, null, knownInfo);
     else
         return new ShellItem(nativeItem, knownInfo);
 }
Пример #8
0
 public static ShellItem GetShellItem(IdList pidl)
 {
     if (pidl.Parts.Count == 0)
         return ShellFolder.DesktopFolder;
     return GetShellItem(pidl, new ShellItemKnownInfo());
 }
Пример #9
0
 internal ShellItem(IdList pidl, ShellItemKnownInfo knownInfo)
 {
     nativeItem = SHCreateItemFromIDList<IShellItem>(pidl);
     Init(knownInfo);
 }