/// <summary> /// Internal constructor that takes in a parent ShellObject. /// </summary> /// <param name="shellObject"></param> internal ShellThumbnail(ShellObject shellObject) { if (shellObject == null || shellObject.NativeShellItem == null) throw new ArgumentNullException("shellObject"); shellItemNative = shellObject.NativeShellItem; }
private static string GetParsingName(IShellItem shellItem) { if (shellItem == null) return null; string path = null; IntPtr pszPath = IntPtr.Zero; int hr = shellItem.GetDisplayName(Shell32.SIGDN.SIGDN_DESKTOPABSOLUTEPARSING, out pszPath); if (false == (hr == HRESULT.S_OK || hr == HRESULT.E_INVALIDARG)) throw new COMException("GetParsingName", (int)hr); if (pszPath != IntPtr.Zero) { path = Marshal.PtrToStringAuto(pszPath); Marshal.FreeCoTaskMem(pszPath); pszPath = IntPtr.Zero; } return path; }
private static void TraceAction(string action, IShellItem item, uint hresult) { //TraceAction(action, // item != null ? Marshal.PtrToStringUni(item.GetDisplayName(WindowsAPI.SIGDN.NORMALDISPLAY)) : null, // hresult); }
public virtual void PostNewItem(uint dwFlags, IShellItem psiDestinationFolder, string pszNewName, string pszTemplateName, uint dwFileAttributes, uint hrNew, IShellItem psiNewItem) { TraceAction("PostNewItem", psiNewItem, hrNew); }
public virtual void PostCopyItem( uint dwFlags, IShellItem psiItem, IShellItem psiDestinationFolder, string pszNewName, uint hrCopy, IShellItem psiNewlyCreated) { TraceAction("PostCopyItem", psiNewlyCreated, hrCopy); }
public void PostMoveItem( uint dwFlags, IShellItem psiItem, IShellItem psiDestinationFolder, string pszNewName, uint hrMove, IShellItem psiNewlyCreated) { TraceAction("PostMoveItem", psiNewlyCreated, hrMove); }
internal static IntPtr PidlFromShellItem(IShellItem nativeShellItem) { IntPtr shellItem = Marshal.GetComInterfaceForObject(nativeShellItem, typeof(IShellItem)); IntPtr pidl; int retCode = ShellNativeMethods.SHGetIDListFromObject(shellItem, out pidl); return (CoreErrorHelper.Succeeded(retCode) ? pidl : IntPtr.Zero); }
private static IShellItem GetShellItemFromFolder(IShellItem shellItem, IShellFolder shellFolder) { if (shellItem == null && shellFolder == null) throw new ArgumentNullException("shellItem, shellFolder", "shellItem and shellFolder cannot both be null"); if (shellItem != null) return shellItem; IdList pidl = SHGetIDListFromObject(shellFolder); return SHCreateItemFromIDList<IShellItem>(pidl); }
internal ShellFolder(IShellItem shellItem, IShellFolder shellFolder, ShellItemKnownInfo knownInfo) : base(GetShellItemFromFolder(shellItem, shellFolder), knownInfo) { if (shellFolder == null) { shellFolder = (IShellFolder)shellItem.BindToHandler(null, ShellConsts.BHID_SFObject, typeof(IShellFolder).GUID); } NativeFolder = shellFolder; }
/// <summary> /// Internal constructor that takes in a parent ShellObject. /// </summary> /// <param name="shellObject"></param> internal ShellThumbnail(ShellObject shellObject) { if (shellObject == null || shellObject.NativeShellItem == null) { throw new ArgumentNullException(nameof(shellObject)); } shellItemNative = shellObject.NativeShellItem; }
public HResult GetItemAt(uint dwIndex, out IShellItem ppsi) { int index = (int)dwIndex; if (index < shellItemsList.Count) { ppsi = shellItemsList[index]; return HResult.Ok; } else { ppsi = null; return HResult.Fail; } }
public HResult GetParent(out IShellItem ppsi) { IntPtr pidl = Shell32.ILClone(Pidl); if (Shell32.ILRemoveLastID(pidl)) { ppsi = new ShellItemImpl(pidl, true); return HResult.S_OK; } else { ppsi = null; return HResult.MK_E_NOOBJECT; } }
public HRESULT GetItemAt(uint dwIndex, out IShellItem ppsi) { int index = (int)dwIndex; if (index < shellItemsList.Count) { ppsi = shellItemsList[index]; return HRESULT.S_OK; } else { ppsi = null; return HRESULT.E_FAIL; } }
void IShellItemArray.GetItemAt(uint dwIndex, out IShellItem ppsi) { int index = (int)dwIndex; if (index < shellItemsList.Count) { ppsi = shellItemsList[index]; //return HResult.S_OK; } else { ppsi = null; //return HResult.S_FALSE; } }
public override void PostDeleteItem(TRANSFER_SOURCE_FLAGS dwFlags, IShellItem psiItem, uint hrDelete, IShellItem psiNewlyCreated) { //base.PostDeleteItem(dwFlags,psiItem,hrDelete,psiNewlyCreated); //if (hrDelete == 2555912) { // var theNewItem = FileSystemListItem.InitializeWithIShellItem(this._View.LVHandle, psiItem); // if (this._View.CurrentFolder.Equals(theNewItem.Parent)) { // Shell32.SHChangeNotify( // theNewItem.IsFolder ? Shell32.HChangeNotifyEventID.SHCNE_RMDIR : Shell32.HChangeNotifyEventID.SHCNE_DELETE, // Shell32.HChangeNotifyFlags.SHCNF_IDLIST | Shell32.HChangeNotifyFlags.SHCNF_FLUSH, theNewItem.PIDL, IntPtr.Zero); // } // theNewItem.Dispose(); //} //if (psiItem != null) { // Marshal.FinalReleaseComObject(psiItem); //} // if (psiNewlyCreated != null) { // Marshal.FinalReleaseComObject(psiNewlyCreated); // } //Shell32.SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1); }
internal static string GetParsingName(IShellItem shellItem) { if (shellItem == null) { return null; } string path = null; IntPtr pszPath = IntPtr.Zero; HResult hr = shellItem.GetDisplayName(ShellNativeMethods.ShellItemDesignNameOptions.DesktopAbsoluteParsing, out pszPath); if (hr != HResult.Ok && hr != HResult.InvalidArguments) { throw new ShellException(LocalizedMessages.ShellHelperGetParsingNameFailed, hr); } if (pszPath != IntPtr.Zero) { path = Marshal.PtrToStringAuto(pszPath); Marshal.FreeCoTaskMem(pszPath); pszPath = IntPtr.Zero; } return path; }
public override void PostCopyItem(TRANSFER_SOURCE_FLAGS dwFlags, IShellItem psiItem, IShellItem psiDestinationFolder, string pszNewName, uint hrCopy, IShellItem psiNewlyCreated) { //if (hrCopy == 0) { // var destination = FileSystemListItem.InitializeWithIShellItem(this._View.LVHandle, psiDestinationFolder); // if (destination.Equals(this._View.CurrentFolder)) { // var theNewItem = FileSystemListItem.InitializeWithIShellItem(this._View.LVHandle, psiNewlyCreated); // Shell32.SHChangeNotify( // theNewItem.IsFolder ? Shell32.HChangeNotifyEventID.SHCNE_MKDIR : Shell32.HChangeNotifyEventID.SHCNE_CREATE, // Shell32.HChangeNotifyFlags.SHCNF_IDLIST | Shell32.HChangeNotifyFlags.SHCNF_FLUSH, theNewItem.PIDL, IntPtr.Zero); // this._View.LargeImageList.SupressThumbnailGeneration(false); // Shell32.SHChangeNotify(Shell32.HChangeNotifyEventID.SHCNE_UPDATEITEM, // Shell32.HChangeNotifyFlags.SHCNF_IDLIST | Shell32.HChangeNotifyFlags.SHCNF_FLUSH, theNewItem.PIDL, IntPtr.Zero); // theNewItem.Dispose(); // } // destination.Dispose(); //} //if (psiItem != null) { // Marshal.FinalReleaseComObject(psiItem); //} //if (psiNewlyCreated != null) { // Marshal.FinalReleaseComObject(psiNewlyCreated); //} //Shell32.SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1); }
public virtual void PostDeleteItem( uint dwFlags, IShellItem psiItem, uint hrDelete, IShellItem psiNewlyCreated) { TraceAction("PostDeleteItem", psiItem, hrDelete); }
public static extern void SHCreateItemFromParsingName( [In][MarshalAs(UnmanagedType.LPWStr)] string pszPath, [In] IntPtr pbc, [In][MarshalAs(UnmanagedType.LPStruct)] Guid riid, [Out][MarshalAs(UnmanagedType.Interface, IidParameterIndex = 2)] out IShellItem ppv);
private void printProperties(IShellItem shellItem) { string s = string.Join(";\n", shellItem.GetAllProperties().Select(x => x.Key + "=" + x.Value).ToArray()); Console.WriteLine(s); }
/// <summary>Adds a folder to the library.</summary> /// <param name="location">An IShellItem object that represents the folder to be added to the library.</param> void AddFolder([In, MarshalAs(UnmanagedType.Interface)] IShellItem location);
internal static extern int SHCreateShellItem( IntPtr pidlParent, [In, MarshalAs(UnmanagedType.Interface)] IShellFolder psfParent, IntPtr pidl, [MarshalAs(UnmanagedType.Interface)] out IShellItem ppsi );
public static string GetPathFromShellItem(IShellItem item) { return(item.GetDisplayName(SIGDN.DESKTOPABSOLUTEPARSING)); }
public void OnOverwrite(IFileDialog pfd, IShellItem psi, out NativeMethods.FDE_OVERWRITE_RESPONSE pResponse) { // TODO: Implement overwrite notification support pResponse = NativeMethods.FDE_OVERWRITE_RESPONSE.FDEOR_ACCEPT; }
public virtual void PreRenameItem(uint dwFlags, IShellItem psiItem, string pszNewName) { TraceAction("PreRenameItem", psiItem, 0); }
public static extern HRESULT SHCreateShellItem(IntPtr pidlParent, IntPtr psfParent, IntPtr pidl, out IShellItem ppsi);
public void OnShareViolation(IFileDialog pfd, IShellItem psi, out FDE_SHAREVIOLATION_RESPONSE pResponse) { pResponse = FDE_SHAREVIOLATION_RESPONSE.FDESVR_ACCEPT; }
private static extern int SHCreateItemFromParsingName([MarshalAs(UnmanagedType.LPWStr)] string pszPath, IBindCtx pbc, [MarshalAs(UnmanagedType.LPStruct)] Guid riid, out IShellItem ppv);
private static ImageData LoadThumbnail(string path, DateTime dtLastWriteTime, out Size sizeRaw, out Size sizeActual, out string toolTipText, out bool fCached) { sizeRaw = sizeActual = Size.Empty; toolTipText = null; fCached = false; IntPtr zero = IntPtr.Zero; IShellItem ppsi = null; ISharedBitmap ppvThumb = null; LocalThumbnailCache o = null; try { zero = PInvoke.ILCreateFromPath(path); if ((zero != IntPtr.Zero) && (PInvoke.SHCreateShellItem(IntPtr.Zero, null, zero, out ppsi) == 0)) { o = new LocalThumbnailCache(); IThumbnailCache cache2 = (IThumbnailCache)o; uint flags = 0; uint pOutFlags = 0; WTS_THUMBNAILID pThumbnailID = new WTS_THUMBNAILID(); uint cxyRequestedThumbSize = (uint)Math.Min(0x400, Math.Min(QTUtility.PreviewMaxWidth, QTUtility.PreviewMaxHeight)); if (cache2.GetThumbnail(ppsi, cxyRequestedThumbSize, flags, out ppvThumb, ref pOutFlags, ref pThumbnailID) == 0) { IntPtr ptr2; if ((pOutFlags & 2) == 2) { fCached = true; } if (ppvThumb.Detach(out ptr2) == 0) { Bitmap bmp = Image.FromHbitmap(ptr2); Size size = bmp.Size; sizeRaw = sizeActual = size; ImageData data = new ImageData(bmp, null, path, dtLastWriteTime, size, size); data.Thumbnail = true; try { toolTipText = data.TooltipText = ShellMethods.GetShellInfoTipText(zero, false); } catch { } return(data); } } } } catch (Exception exception) { QTUtility2.MakeErrorLog(exception, null); } finally { if (zero != IntPtr.Zero) { PInvoke.CoTaskMemFree(zero); } if (ppsi != null) { Marshal.ReleaseComObject(ppsi); } if (ppvThumb != null) { Marshal.ReleaseComObject(ppvThumb); } if (o != null) { Marshal.ReleaseComObject(o); } } return(null); }
public virtual void PreNewItem(uint dwFlags, IShellItem psiDestinationFolder, string pszNewName) { TraceAction("PreNewItem", pszNewName, 0); }
private static extern int SHCreateShellItem(IntPtr pidlParent, IntPtr psfParent, IntPtr pidl, out IShellItem ppsi);
public virtual void PostRenameItem(uint dwFlags, IShellItem psiItem, string pszNewName, uint hrRename, IShellItem psiNewlyCreated) { TraceAction("PostRenameItem", psiNewlyCreated, hrRename); }
internal static extern int SHCreateItemFromParsingName( [MarshalAs(UnmanagedType.LPWStr)] string path, // The following parameter is not used - binding context. IntPtr pbc, ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out IShellItem shellItem);
internal static extern int SHShowManageLibraryUI( [In, MarshalAs(UnmanagedType.Interface)] IShellItem library, [In] IntPtr hwndOwner, [In] string title, [In] string instruction, [In] LibraryManageDialogOptions lmdOptions);
/// <summary>Initializes a new instance of the <see cref="ShellFolder"/> class.</summary> internal ShellFolder(IShellItem iShellItem) : base(iShellItem) => iShellFolder = GetInstance();
internal string GetFileNameFromShellItem(IShellItem item) { string filename; item.GetDisplayName(NativeMethods.SIGDN.DESKTOPABSOLUTEPARSING, out filename); return filename; }
internal static extern int SHCreateItemFromParsingName([MarshalAs(UnmanagedType.LPWStr)] string pszPath, IntPtr pbc, ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out IShellItem ppv);
public void OnShareViolation(IFileDialog pfd, IShellItem psi, out NativeMethods.RESPONSE pResponse) { // Do nothing: we will ignore share violations, and don't register // for them, so this method should never be called pResponse = NativeMethods.RESPONSE.ACCEPT; }
/// <summary> /// Initializes a new instance of the <see cref="ShellItem" /> class. /// </summary> /// <param name="comInterface"> /// An <see cref="IShellItem" /> representing the folder. /// </param> public ShellItem(IShellItem comInterface) { ComInterface = comInterface; }
void IIconNativeApi.SHCreateItemFromParsingName(string pszPath, IntPtr pbc, Guid riid, out IShellItem ppv) { SHCreateItemFromParsingName(pszPath, pbc, riid, out ppv); }
internal ShellItem(IdList pidl, ShellItemKnownInfo knownInfo) { nativeItem = SHCreateItemFromIDList <IShellItem>(pidl); Init(knownInfo); }
public void OnOverwrite(IFileDialog pfd, IShellItem psi, out FDE_OVERWRITE_RESPONSE pResponse) { pResponse = FDE_OVERWRITE_RESPONSE.FDEOR_DEFAULT; }
public virtual void PreDeleteItem( uint dwFlags, IShellItem psiItem) { TraceAction("PreDeleteItem", psiItem, 0); }
internal ShellItemArray(IShellItem[] shellItems) { shellItemsList.AddRange(shellItems); }
public static extern int SHCreateShellItem(IntPtr pidlParent, Interop.QTTabBar.IShellFolder psfParent, IntPtr pidl, out IShellItem ppsi);
/// <summary>Initializes a new instance of the <see cref="ShellLibrary"/> class.</summary> /// <param name="iItem">The i item.</param> /// <param name="readOnly">if set to <c>true</c> [read only].</param> internal ShellLibrary(IShellItem iItem, bool readOnly = false) : base(iItem) { lib = new IShellLibrary(); lib.LoadLibraryFromItem(iItem, readOnly ? STGM.STGM_READ : STGM.STGM_READWRITE); }
/// <summary> /// Creates a ShellObject given a native IShellItem interface /// </summary> /// <param name="nativeShellItem"></param> /// <returns>A newly constructed ShellObject object</returns> public static ShellObject Create(IShellItem nativeShellItem) { // Sanity check Debug.Assert(nativeShellItem != null, "nativeShellItem should not be null"); // Need to make sure we're running on Vista or higher if (!CoreHelpers.RunningOnVista) { throw new PlatformNotSupportedException(LocalizedMessages.ShellObjectFactoryPlatformNotSupported); } // A lot of APIs need IShellItem2, so just keep a copy of it here IShellItem2 nativeShellItem2 = nativeShellItem as IShellItem2; // Get the System.ItemType property string itemType = ShellHelper.GetItemType(nativeShellItem2); if (!string.IsNullOrEmpty(itemType)) { itemType = itemType.ToUpperInvariant(); } // Get some IShellItem attributes ShellNativeMethods.ShellFileGetAttributesOptions sfgao; nativeShellItem2.GetAttributes(ShellNativeMethods.ShellFileGetAttributesOptions.FileSystem | ShellNativeMethods.ShellFileGetAttributesOptions.Folder, out sfgao); // Is this item a FileSystem item? bool isFileSystem = (sfgao & ShellNativeMethods.ShellFileGetAttributesOptions.FileSystem) != 0; // Is this item a Folder? bool isFolder = (sfgao & ShellNativeMethods.ShellFileGetAttributesOptions.Folder) != 0; // Shell Library ShellLibrary shellLibrary = null; // Create the right type of ShellObject based on the above information // 1. First check if this is a Shell Link if (itemType == ".lnk") { return(new ShellLink(nativeShellItem2)); } // 2. Check if this is a container or a single item (entity) else if (isFolder) { // 3. If this is a folder, check for types: Shell Library, Shell Folder or Search Container if (itemType == ".library-ms" && (shellLibrary = ShellLibrary.FromShellItem(nativeShellItem2, true)) != null) { return(shellLibrary); // we already created this above while checking for Library } else if (itemType == ".searchconnector-ms") { return(new ShellSearchConnector(nativeShellItem2)); } else if (itemType == ".search-ms") { return(new ShellSavedSearchCollection(nativeShellItem2)); } // 4. It's a ShellFolder if (isFileSystem) { // 5. Is it a (File-System / Non-Virtual) Known Folder if (!IsVirtualKnownFolder(nativeShellItem2)) { //needs to check if it is a known folder and not virtual FileSystemKnownFolder kf = new FileSystemKnownFolder(nativeShellItem2); return(kf); } return(new ShellFileSystemFolder(nativeShellItem2)); } // 5. Is it a (Non File-System / Virtual) Known Folder if (IsVirtualKnownFolder(nativeShellItem2)) { //needs to check if known folder is virtual NonFileSystemKnownFolder kf = new NonFileSystemKnownFolder(nativeShellItem2); return(kf); } return(new ShellNonFileSystemFolder(nativeShellItem2)); } // 6. If this is an entity (single item), check if its filesystem or not if (isFileSystem) { return(new ShellFile(nativeShellItem2)); } return(new ShellNonFileSystemItem(nativeShellItem2)); }
public void OnShareViolation(IFileDialog pfd, IShellItem psi, out NativeMethods.FDE_SHAREVIOLATION_RESPONSE pResponse) { // Do nothing: we will ignore share violations, and don't register // for them, so this method should never be called pResponse = NativeMethods.FDE_SHAREVIOLATION_RESPONSE.FDESVR_ACCEPT; }
public static string GetPathFromShellItem(IShellItem item) { return item.GetDisplayName(SIGDN.DESKTOPABSOLUTEPARSING); }
public HRESULT OnFolderChanging(IFileDialog pfd, IShellItem psiFolder) { return HRESULT.S_OK; }
/// <summary>Initializes a new instance of the <see cref="ShellLibrary"/> class.</summary> /// <param name="iItem">The i item.</param> /// <param name="readOnly">if set to <c>true</c> [read only].</param> public ShellLibrary2(IShellItem iItem, bool readOnly = false) { lib = new IShellLibrary(); lib.LoadLibraryFromItem(iItem, readOnly ? STGM.STGM_READ : STGM.STGM_READWRITE); Init(iItem); }
public void OnOverwrite(IFileDialog pfd, IShellItem psi, out NativeMethods.RESPONSE pResponse) { pResponse = NativeMethods.RESPONSE.ACCEPT; }
internal ShellItem(IShellItem nativeItem, ShellItemKnownInfo knownInfo) { this.nativeItem = nativeItem; Init(knownInfo); }