Example #1
0
		internal static string GetItemType(IShellItem2 shellItem) {
			if (shellItem != null) {
				string itemType = null;
				HResult hr = shellItem.GetString(ref ItemTypePropertyKey, out itemType);
				if (hr == HResult.Ok) { return itemType; }
			}

			return null;
		}
Example #2
0
        internal static string GetItemType(IShellItem2 shellItem)
        {
            if (shellItem != null)
            {
                string itemType = null;

                HRESULT hr = shellItem.GetString(ref ItemTypePropertyKey, out itemType);

                if (hr == HRESULT.S_OK)
                    return itemType;
            }

            return null;
        }
        /// <summary>
        ///     Initialize a new instance of the <see cref="ShellItem" /> class
        ///     to the specified <see cref="IShellItem2" />.
        /// </summary>
        /// <param name="shellItem2"><see cref="IShellItem2" />.</param>
        internal ShellItem(IShellItem2 shellItem2)
        {
            Contract.Requires <ArgumentNullException>(shellItem2 != null);

            this.ShellItemInterface = shellItem2;
            this.PIDL = PIDL.FromShellItem(this.ShellItemInterface);

            try
            {
                var attributes = GetAttributes(SFGAO.SFGAO_LINK | SFGAO.SFGAO_FILESYSTEM | SFGAO.SFGAO_FOLDER);

                this.IsLink       = (attributes & SFGAO.SFGAO_LINK) != 0;
                this.IsFileSystem = (attributes & SFGAO.SFGAO_FILESYSTEM) != 0;
                this.IsFolder     = (attributes & SFGAO.SFGAO_FOLDER) != 0;
            }
            catch
            {
                this.IsLink       = false;
                this.IsFileSystem = false;
                this.IsFolder     = false;
            }
        }
        /// <summary>
        ///     Get the item type from the specified <see cref="IShellItem2" />.
        /// </summary>
        /// <param name="shellItem"><see cref="IShellItem2" />.</param>
        /// <returns>Item type string.</returns>
        private static string GetItemType(IShellItem2 shellItem)
        {
            Contract.Requires(shellItem != null);
            Contract.Ensures(Contract.Result <string>() != null);

            var    itemTypeKey = new PROPERTYKEY(new Guid("28636AA6-953D-11D2-B5D6-00C04FD918D0"), 11);
            string result;
            var    hr = shellItem.GetString(ref itemTypeKey, out result);

            if (HRESULT.Failed(hr))
            {
                try
                {
                    result = Path.GetExtension(GetParsingName(shellItem));
                }
                catch (Exception)
                {
                    result = String.Empty;
                }
            }

            return(result);
        }
Example #5
0
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
            }
            if (_pStore != null)
            {
                Marshal.FinalReleaseComObject(_pStore);
                _pStore = null;
            }
            if (_pSource != null)
            {
                Marshal.FinalReleaseComObject(_pSource);
                _pSource = null;
            }
            // free native resources
            _disposed = true;
        }
 public static extern void SHCreateItemFromParsingName([MarshalAs(UnmanagedType.LPWStr)] string pszPath, [MarshalAs(UnmanagedType.Interface)] System.Runtime.InteropServices.ComTypes.IBindCtx pbc, [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid, [MarshalAs(UnmanagedType.Interface)] out IShellItem2 ppv);
Example #7
0
 internal ShellFile(IShellItem2 shellItem)
 {
     nativeShellItem = shellItem;
 }
Example #8
0
        /// <summary>
        /// Loads a <see cref="PropertyStore"/> for the specified file or extension, containing only the specified properties. Note that if creating a PropertyStore based on extension only, this store will be read only. The <see cref="GetFlags.BestEffort"/>
        /// should be used for retrieving that store, as the file does not exist to enable the reading of properties that would be stored in it, and any other flags are likely to produce an exception.
        /// </summary>
        /// <param name="path">The path or extension of the file the store is required for</param>
        /// <param name="keys">The required <see cref="PropertyKey"/>s</param>
        /// <param name="flags">The <see cref="GetFlags"/> indicating the type of store to load</param>
        public PropertyStore(string path, IEnumerable <PropertyKey> keys, GetFlags flags)
        {
            int    nKeys    = keys.Count();
            IntPtr keyArray = Marshal.AllocCoTaskMem(nKeys * Marshal.SizeOf(typeof(PROPERTYKEY)));

            try {
                IntPtr keyPtr = keyArray;
                foreach (PropertyKey key in keys)
                {
                    Marshal.StructureToPtr <PROPERTYKEY>(key.PROPERTKEY, keyPtr, false);
                    keyPtr += Marshal.SizeOf(typeof(PROPERTYKEY));
                }
                if (File.Exists(path))
                {
                    IntPtr pidl = ILCreateFromPath(Path.GetFullPath(path));
                    try {
                        IntPtr shUnk = IntPtr.Zero;
                        SHCreateItemFromIDList(pidl, IID.IShellItem2, out shUnk);
                        _pSource = (IShellItem2)Marshal.GetUniqueObjectForIUnknown(shUnk);
                        try {
                            IntPtr pUnk = IntPtr.Zero;
                            _pSource.GetPropertyStoreForKeys(keyArray, (uint)nKeys, (GETPROPERTYSTOREFLAGS)flags, IID.IPropertyStore, out pUnk);
                            try {
                                _pStore = (IPropertyStore)Marshal.GetUniqueObjectForIUnknown(pUnk);
                            }
                            finally { Marshal.Release(pUnk); }
                        }
                        finally {
                            if (shUnk != IntPtr.Zero)
                            {
                                Marshal.Release(shUnk);
                            }
                        }
                    }
                    finally {
                        if (pidl != IntPtr.Zero)
                        {
                            Marshal.FreeCoTaskMem(pidl);
                        }
                    }
                }
                else
                {
                    string file;
                    path = path.Substring(path.LastIndexOf('\\') + 1);
                    if (path[0] == '.' || !path.Contains('.'))
                    {
                        file = Path.ChangeExtension("_Fake", path);
                    }
                    else
                    {
                        file = Path.GetFileName(path);
                    }
                    WIN32_FIND_DATA fd = new WIN32_FIND_DATA()
                    {
                        nFileSizeLow = 42
                    };
                    using (FakeFile f = new FakeFile(ref fd, file))
                    {
                        _pSource = (IShellItem2)f.GetShellItem();
                        IntPtr pUnk = IntPtr.Zero;
                        try
                        {
                            _pSource.GetPropertyStoreForKeys(keyArray, (uint)nKeys, (GETPROPERTYSTOREFLAGS)flags, IID.IPropertyStore, out pUnk);
                            _pStore = (IPropertyStore)Marshal.GetUniqueObjectForIUnknown(pUnk);
                        }
                        finally
                        {
                            if (pUnk != IntPtr.Zero)
                            {
                                Marshal.Release(pUnk);
                            }
                        }
                    }
                }
            }
            finally {
                if (keyArray != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(keyArray);
                }
            }
        }
 public ShellNonFileSystemFolder(IShellItem2 shellItem)
 {
     nativeShellItem = shellItem;
 }
 internal ShellSavedSearchCollection(IShellItem2 shellItem)
     : base(shellItem)
 {
 }
 internal ShellSearchConnector(IShellItem2 shellItem)
     : this()
 {            
     nativeShellItem = shellItem;
 }
Example #12
0
 internal ShellLink(IShellItem2 shellItem) => nativeShellItem = shellItem;
        internal ShellSearchConnector(IShellItem2 shellItem)
        {
            CoreHelpers.ThrowIfNotWin7();

            nativeShellItem = shellItem;
        }
Example #14
0
 protected ShellObject(IShellItem2 shellItem) => nativeShellItem = shellItem;
Example #15
0
        private static String ShowDialogInner(IFileSaveDialog dialog, IntPtr parentWindowHandle, String title, String initialDirectory, String defaultFileName, IReadOnlyCollection <Filter> filters, Int32 selectedFilterZeroBasedIndex = -1)
        {
            FileOpenOptions flags =
                FileOpenOptions.NoTestFileCreate |
                FileOpenOptions.PathMustExist |
                FileOpenOptions.ForceFilesystem |
                FileOpenOptions.OverwritePrompt;

            dialog.SetOptions(flags);

            if (title != null)
            {
                dialog.SetTitle(title);
            }

            if (initialDirectory != null)
            {
                IShellItem2 initialDirectoryShellItem = Utility.ParseShellItem2Name(initialDirectory);
                if (initialDirectoryShellItem != null)
                {
                    dialog.SetFolder(initialDirectoryShellItem);
                }
            }

//            if( initialSaveAsItem != null )
//            {
//                IShellItem2 initialSaveAsItemShellItem = Utility.ParseShellItem2Name( initialDirectory );
//                if( initialSaveAsItemShellItem != null )
//                {
//                    dialog.SetSaveAsItem( initialSaveAsItemShellItem );
//                }
//            }

            if (defaultFileName != null)
            {
                dialog.SetFileName(defaultFileName);
            }

            Utility.SetFilters(dialog, filters, selectedFilterZeroBasedIndex);

            HResult result = dialog.Show(parentWindowHandle);

            if (result == HResult.Ok)
            {
                IShellItem selectedItem;
                dialog.GetResult(out selectedItem);

                if (selectedItem != null)
                {
                    return(Utility.GetFileNameFromShellItem(selectedItem));
                }
                else
                {
                    return(null);
                }
            }
            else if (result == HResult_Win32_Canceled)
            {
                // Cancelled by user.
                return(null);
            }
            else
            {
                UInt32 win32ErrorCode = Utility.Win32ErrorFromHResult((UInt32)result);
                throw new Win32Exception(error: (Int32)win32ErrorCode);
            }
        }
Example #16
0
 public ShellLink(IShellItem2 shellItem)
 {
     nativeShellItem = shellItem;
 }
Example #17
0
 internal ShellLink(IShellItem2 shellItem)
 {
     this.nativeShellItem = shellItem;
 }
        /// <summary>
        /// Release the native and managed objects
        /// </summary>
        /// <param name="disposing">Indicates that this is being called from Dispose(), rather than the finalizer.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                internalParsingName = null;
            }

            if (nativeShellItem != null)
            {
                Marshal.ReleaseComObject(nativeShellItem);
                nativeShellItem = null;
            }
        }
Example #19
0
 internal ShellLink(IShellItem2 shellItem)
 {
     nativeShellItem = shellItem;
 }
 public ShellContainer(IShellItem2 shellItem) : base(shellItem)
 {
 }
Example #21
0
 private ShellItem()
 {
     _pItem = null;
 }
Example #22
0
 internal ShellFile(IShellItem2 shellItem)
 {
     nativeShellItem = shellItem;
 }
 public NonFileSystemKnownFolder(IShellItem2 shellItem) : base(shellItem)
 {
 }
Example #24
0
 internal ShellSavedSearchCollection(IShellItem2 shellItem)
     : base(shellItem)
 {
     CoreHelpers.ThrowIfNotVista();
 }
 public ShellSearchConnector(IShellItem2 shellItem)
     : this()
 {
     nativeShellItem = shellItem;
 }
 public ShellSearchCollection(IShellItem2 shellItem)
     : base(shellItem)
 {
 }
 internal ShellNonFileSystemFolder(IShellItem2 shellItem) => nativeShellItem = shellItem;
 public NonFileSystemKnownFolder(IShellItem2 shellItem)
     : base(shellItem)
 {
 }
        private static String ShowDialogInner(IFileSaveDialog dialog, IntPtr parentHWnd, String title, String initialDirectory, String defaultFileName, IReadOnlyCollection <Filter> filters, Int32 selectedFilterZeroBasedIndex = -1)
        {
            FileOpenOptions flags =
                FileOpenOptions.NoTestFileCreate |
                FileOpenOptions.PathMustExist |
                FileOpenOptions.ForceFilesystem |
                FileOpenOptions.OverwritePrompt;

            dialog.SetOptions(flags);

            if (title != null)
            {
                dialog.SetTitle(title);
            }

            if (initialDirectory != null)
            {
                IShellItem2 initialDirectoryShellItem = Utility.ParseShellItem2Name(initialDirectory);
                if (initialDirectoryShellItem != null)
                {
                    dialog.SetFolder(initialDirectoryShellItem);
                }
            }

//			if( initialSaveAsItem != null )
//			{
//				IShellItem2 initialSaveAsItemShellItem = Utility.ParseShellItem2Name( initialDirectory );
//				if( initialSaveAsItemShellItem != null )
//				{
//					dialog.SetSaveAsItem( initialSaveAsItemShellItem );
//				}
//			}

            if (defaultFileName != null)
            {
                dialog.SetFileName(defaultFileName);
            }

            Utility.SetFilters(dialog, filters, selectedFilterZeroBasedIndex);

            HResult result = dialog.Show(parentHWnd);

            HResult cancelledAsHResult = Utility.HResultFromWin32((int)HResult.Win32ErrorCanceled);

            if (result == cancelledAsHResult)
            {
                // Cancelled
                return(null);
            }
            else
            {
                // OK

                IShellItem selectedItem;
                dialog.GetResult(out selectedItem);

                if (selectedItem != null)
                {
                    return(Utility.GetFileNameFromShellItem(selectedItem));
                }
                else
                {
                    return(null);
                }
            }
        }
Example #30
0
 public ShellFile(IShellItem2 shellItem)
 {
     nativeShellItem = shellItem;
 }
Example #31
0
 internal ShellContainer(IShellItem2 shellItem) : base(shellItem)
 {
 }
Example #32
0
 internal ShellFileSystemFolder(IShellItem2 shellItem)
 {
     nativeShellItem = shellItem;
 }
Example #33
0
 internal ShellObject(IShellItem2 shellItem)
 {
     nativeShellItem = shellItem;
 }
 internal ShellSearchConnector(IShellItem2 shellItem)
     : this()
 {
     nativeShellItem = shellItem;
 }
 internal NonFileSystemKnownFolder(IShellItem2 shellItem) : base(shellItem) { }
Example #36
0
        internal 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("Shell Object creation requires Windows Vista or higher operating system.");
            }

            // 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.ToLower();
            }

            // Get some IShellItem attributes
            ShellNativeMethods.SFGAO sfgao;
            nativeShellItem2.GetAttributes(ShellNativeMethods.SFGAO.SFGAO_FILESYSTEM | ShellNativeMethods.SFGAO.SFGAO_FOLDER, out sfgao);

            // Is this item a FileSystem item?
            bool isFileSystem = (sfgao & ShellNativeMethods.SFGAO.SFGAO_FILESYSTEM) != 0;

            // Is this item a Folder?
            bool isFolder = (sfgao & ShellNativeMethods.SFGAO.SFGAO_FOLDER) != 0;

            // Shell Library
            ShellLibrary shellLibrary = null;

            // For KnownFolders
            bool isKnownFolderVirtual = false;

            // 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));
                }
                else
                {
                    // 4. It's a ShellFolder
                    if (isFileSystem)
                    {
                        // 5. Is it a (File-System / Non-Virtual) Known Folder
                        if ((GetNativeKnownFolder(nativeShellItem2, out isKnownFolderVirtual) != null) && !isKnownFolderVirtual)
                        {
                            FileSystemKnownFolder kf = new FileSystemKnownFolder(nativeShellItem2);
                            return(kf);
                        }
                        else
                        {
                            return(new ShellFileSystemFolder(nativeShellItem2));
                        }
                    }
                    else
                    {
                        // 5. Is it a (Non File-System / Virtual) Known Folder
                        if ((GetNativeKnownFolder(nativeShellItem2, out isKnownFolderVirtual) != null) && isKnownFolderVirtual)
                        {
                            NonFileSystemKnownFolder kf = new NonFileSystemKnownFolder(nativeShellItem2);
                            return(kf);
                        }
                        else
                        {
                            return(new ShellNonFileSystemFolder(nativeShellItem2));
                        }
                    }
                }
            }
            else
            {
                // 6. If this is an entity (single item), check if its filesystem or not
                if (isFileSystem)
                {
                    return(new ShellFile(nativeShellItem2));
                }
                else
                {
                    return(new ShellNonFileSystemItem(nativeShellItem2));
                }
            }
        }
Example #37
0
        /// <summary>
        /// Creates a ShellObject given a native IShellItem interface
        /// </summary>
        /// <param name="nativeShellItem"></param>
        /// <returns>A newly constructed ShellObject object</returns>
        internal 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));
        }
Example #38
0
 public ShellNonFileSystemItem(IShellItem2 shellItem)
 {
     nativeShellItem = shellItem;
 }
 internal ShellNonFileSystemItem(IShellItem2 shellItem)
 {
     nativeShellItem = shellItem;
 }
Example #40
0
 internal ShellFileSystemFolder(IShellItem2 shellItem)
 {
     nativeShellItem = shellItem;
 }
        // This is a work around for the STA thread bug.  This will execute the call on a non-sta thread, then return the result
        private static bool IsVirtualKnownFolder(IShellItem2 nativeShellItem2)
        {
            IntPtr pidl = IntPtr.Zero;
            try
            {
                IKnownFolderNative nativeFolder = null;
                KnownFoldersSafeNativeMethods.NativeFolderDefinition definition = new KnownFoldersSafeNativeMethods.NativeFolderDefinition();

                // We found a bug where the enumeration of shell folders was
                // not reliable when called from a STA thread - it would return
                // different results the first time vs the other times.
                //
                // This is a work around.  We call FindFolderFromIDList on a
                // worker MTA thread instead of the main STA thread.
                //
                // Ultimately, it would be a very good idea to replace the 'getting shell object' logic
                // to get a list of pidl's in 1 step, then look up their information in a 2nd, rather than
                // looking them up as we get them.  This would replace the need for the work around.
                object padlock = new object();
                lock (padlock)
                {
                    IntPtr unknown = Marshal.GetIUnknownForObject(nativeShellItem2);

                    ThreadPool.QueueUserWorkItem(obj =>
                    {
                        lock (padlock)
                        {
                            pidl = ShellHelper.PidlFromUnknown(unknown);

                            new KnownFolderManagerClass().FindFolderFromIDList(pidl, out nativeFolder);

                            if (nativeFolder != null)
                            {
                                nativeFolder.GetFolderDefinition(out definition);
                            }

                            Monitor.Pulse(padlock);
                        }
                    });

                    Monitor.Wait(padlock);
                }

                return nativeFolder != null && definition.category == FolderCategory.Virtual;
            }
            finally
            {
                ShellNativeMethods.ILFree(pidl);
            }
        }
Example #42
0
 /// <summary>
 /// Loads a <see cref="PropertyStore"/> for the specified file or extension. Note that if creating a PropertyStore based on extension only, this store will be read only. The <see cref="GetFlags.BestEffort"/>
 /// should be used for retrieving that store, as the file does not exist to enable the reading of properties that would be stored in it, and any other flags are likely to produce an exception.
 /// </summary>
 /// <param name="path">The path or extension of the file the store is required for</param>
 /// <param name="flags">The <see cref="GetFlags"/> indicating the type of store to load</param>
 public PropertyStore(string path, GetFlags flags)
 {
     if (File.Exists(path))
     {
         IntPtr pidl = ILCreateFromPath(Path.GetFullPath(path));
         try {
             IntPtr  shUnk = IntPtr.Zero;
             HRESULT hr    = SHCreateItemFromIDList(pidl, IID.IShellItem2, out shUnk);
             _pSource = (IShellItem2)Marshal.GetUniqueObjectForIUnknown(shUnk);
             try {
                 IntPtr pUnk = IntPtr.Zero;
                 _pSource.GetPropertyStore((GETPROPERTYSTOREFLAGS)flags, IID.IPropertyStore, out pUnk);
                 try {
                     _pStore = (IPropertyStore)Marshal.GetUniqueObjectForIUnknown(pUnk);
                 }
                 finally { Marshal.Release(pUnk); }
             }
             finally {
                 if (shUnk != IntPtr.Zero)
                 {
                     Marshal.Release(shUnk);
                 }
             }
         }
         finally {
             if (pidl != IntPtr.Zero)
             {
                 Marshal.FreeCoTaskMem(pidl);
             }
         }
     }
     else
     {
         string file;
         path = path.Substring(path.LastIndexOf('\\') + 1);
         if (path[0] == '.' || !path.Contains('.'))
         {
             file = Path.ChangeExtension("_Fake", path);
         }
         else
         {
             file = Path.GetFileName(path);
         }
         WIN32_FIND_DATA fd = new WIN32_FIND_DATA()
         {
             nFileSizeLow = 42
         };
         FakeFile f = new FakeFile(ref fd, file);
         _pSource = (IShellItem2)f.GetShellItem();
         IntPtr pUnk = IntPtr.Zero;
         try {
             _pSource.GetPropertyStore((GETPROPERTYSTOREFLAGS)flags, IID.IPropertyStore, out pUnk);
             _pStore = (IPropertyStore)Marshal.GetUniqueObjectForIUnknown(pUnk);
         }
         finally {
             if (pUnk != IntPtr.Zero)
             {
                 Marshal.Release(pUnk);
             }
         }
     }
 }
Example #43
0
 internal ShellItem(IntPtr pUnk)
 {
     _pItem = (IShellItem2)Marshal.GetUniqueObjectForIUnknown(pUnk);
 }
 internal ShellNonFileSystemItem(IShellItem2 shellItem)
 {
     this.nativeShellItem = shellItem;
 }
 internal ShellSavedSearchCollection(IShellItem2 shellItem)
     : base(shellItem)
 {
     CoreHelpers.ThrowIfNotVista();
 }
Example #46
0
 public 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 IShellItem2 shellItem);
 internal FileSystemKnownFolder(IShellItem2 shellItem)
     : base(shellItem)
 {
 }
Example #48
0
 public static extern int SHCreateItemFromIDList(
     /*PCIDLIST_ABSOLUTE*/ IntPtr pidl,
     ref Guid riid,
     [MarshalAs(UnmanagedType.Interface)] out IShellItem2 ppv);
Example #49
0
 internal ShellSearchCollection(IShellItem2 shellItem) : base(shellItem)
 {
 }
 public ShellNonFileSystemItem(IShellItem2 shellItem)
 {
     nativeShellItem = shellItem;
 }