private string LoadIconResourceId() { lock (resolvePropsLock) { if (_KnownFolderIsInitialized == false) { _KnownFolderIsInitialized = true; _KnownFolder = LoadKnownFolder(); } } if (KnownFolder == null) { return(null); } bool isKFIconResourceIdValid = false; if (KnownFolder != null) { isKFIconResourceIdValid = KnownFolder.IsIconResourceIdValid(); } if (isKFIconResourceIdValid == false) { IdList pidl = null; LoadPidls(); if (ChildIdList != null || ParentIdList != null) { pidl = PidlManager.CombineParentChild(ParentIdList, ChildIdList); } else { pidl = IdList.Create(); } string filename; int index; if (IconHelper.GetIconResourceId(pidl, out filename, out index)) { // Store filename and index for Desktop Root ResourceId return(string.Format("{0},{1}", filename, index)); } } else { return(KnownFolder.IconResourceId); } return(null); }
//// public void LoadProperties() //// { //// if (_KnownFolderIsInitialized == false) //// { //// _KnownFolderIsInitialized = true; //// KnownFolder = LoadKnownFolder(); //// } //// //// if (_ItemTypeIsInitialized == false) //// { //// _ItemTypeIsInitialized = true; //// ItemType = LoadItemType(); //// } //// //// if (_IconResourceIdInitialized == false) //// { //// _IconResourceIdInitialized = true; //// _IconResourceId = LoadIconResourceId(); //// } //// } /// <summary> /// Initializes the items type flags and path properties. /// </summary> /// <param name="path">Is either a path reference a la 'C:' or a /// special folder path reference a la '::{...}' <seealso cref="KF_IID"/> /// for more details.</param> /// <returns>Returns a simple pojo type object to initialize /// the calling object members.</returns> internal static BrowseItemFromPath InitItem(string path) { if (string.IsNullOrEmpty(path) == true) // return unknown references { var ret = new BrowseItemFromPath(path, path); ret.Name = path; return(ret); } if (path.Length == 38) { try { Guid theGuid; if (Guid.TryParse(path, out theGuid) == true) { path = KF_IID.IID_Prefix + path; } } catch { // Catching errors just in case ... } } // Return item for root desktop item if (string.Compare(path, KF_IID.ID_ROOT_Desktop, true) == 0) { return(InitDesktopRootItem()); } ShellHelpers.SpecialPath isSpecialID = ShellHelpers.IsSpecialPath(path); string normPath = null, SpecialPathId = null; bool hasPIDL = false; IdList parentIdList, relativeChildIdList; if (isSpecialID == ShellHelpers.SpecialPath.IsSpecialPath) { SpecialPathId = path; hasPIDL = PidlManager.GetParentIdListFromPath(path, out parentIdList, out relativeChildIdList); } else { normPath = Browser.NormalizePath(path); hasPIDL = PidlManager.GetParentIdListFromPath(normPath, out parentIdList, out relativeChildIdList); } if (hasPIDL == false) // return references that cannot resolve with a PIDL { var ret = new BrowseItemFromPath(path, path); ret.Name = path; return(ret); } string parseName = normPath; string name = normPath; string labelName = null; IdList fullIdList = null; // Get the IShellFolder2 Interface for the original path item... IntPtr fullPidlPtr = default(IntPtr); IntPtr ptrShellFolder = default(IntPtr); IntPtr parentPIDLPtr = default(IntPtr); IntPtr relativeChildPIDLPtr = default(IntPtr); try { // We are asked to build the desktop root item here... if (parentIdList == null && relativeChildIdList == null) { using (var shellFolder = new ShellFolderDesktop()) { parseName = shellFolder.GetShellFolderName(fullPidlPtr, SHGDNF.SHGDN_FORPARSING); name = shellFolder.GetShellFolderName(fullPidlPtr, SHGDNF.SHGDN_INFOLDER | SHGDNF.SHGDN_FOREDITING); labelName = shellFolder.GetShellFolderName(fullPidlPtr, SHGDNF.SHGDN_NORMAL); } } else { fullIdList = PidlManager.CombineParentChild(parentIdList, relativeChildIdList); fullPidlPtr = PidlManager.IdListToPidl(fullIdList); if (fullPidlPtr == default(IntPtr)) { return(null); } HRESULT hr = HRESULT.False; if (fullIdList.Size == 1) // Is this item directly under the desktop root? { hr = NativeMethods.SHGetDesktopFolder(out ptrShellFolder); if (hr != HRESULT.S_OK) { return(null); } using (var shellFolder = new ShellFolder(ptrShellFolder)) { parseName = shellFolder.GetShellFolderName(fullPidlPtr, SHGDNF.SHGDN_FORPARSING); name = shellFolder.GetShellFolderName(fullPidlPtr, SHGDNF.SHGDN_INFOLDER | SHGDNF.SHGDN_FOREDITING); labelName = shellFolder.GetShellFolderName(fullPidlPtr, SHGDNF.SHGDN_NORMAL); } } else { parentPIDLPtr = PidlManager.IdListToPidl(parentIdList); relativeChildPIDLPtr = PidlManager.IdListToPidl(relativeChildIdList); using (var desktopFolder = new ShellFolderDesktop()) { hr = desktopFolder.Obj.BindToObject(parentPIDLPtr, IntPtr.Zero, typeof(IShellFolder2).GUID, out ptrShellFolder); } if (hr != HRESULT.S_OK) { return(null); } // This item is not directly under the Desktop root using (var shellFolder = new ShellFolder(ptrShellFolder)) { parseName = shellFolder.GetShellFolderName(relativeChildPIDLPtr, SHGDNF.SHGDN_FORPARSING); name = shellFolder.GetShellFolderName(relativeChildPIDLPtr, SHGDNF.SHGDN_INFOLDER | SHGDNF.SHGDN_FOREDITING); labelName = shellFolder.GetShellFolderName(relativeChildPIDLPtr, SHGDNF.SHGDN_NORMAL); } } } if (ShellHelpers.IsSpecialPath(parseName) == ShellHelpers.SpecialPath.None) { normPath = parseName; } return(new BrowseItemFromPath(path, parseName, name, labelName, SpecialPathId, normPath //// ,parentIdList, relativeChildIdList )); } finally { PidlManager.ILFree(parentPIDLPtr); PidlManager.ILFree(relativeChildPIDLPtr); if (fullPidlPtr != default(IntPtr)) { NativeMethods.ILFree(fullPidlPtr); } } }