void GetPathAndElementName(IShellItem item, out string path, out string elementName)
 {
     item.GetDisplayName(SIGDN.PARENTRELATIVEFORADDRESSBAR, out elementName);
     try
     {
         item.GetDisplayName(SIGDN.FILESYSPATH, out path);
     }
     catch (ArgumentException ex) when(ex.HResult == -2147024809)
     {
         path = null;
     }
 }
Example #2
0
        public DialogResult ShowDialog(IWin32Window owner)
        {
            IShellItem      result = null;
            IFileOpenDialog dialog = (IFileOpenDialog) new FileOpenDialog();

            if (!string.IsNullOrEmpty(SelectedPath))
            {
                SelectInitialPath(dialog, SelectedPath);
            }
            else if (!string.IsNullOrEmpty(SelectedDesktopAbsoluteParsing))
            {
                SelectInitialPath(dialog, SelectedDesktopAbsoluteParsing);
            }

            if (!string.IsNullOrWhiteSpace(Title))
            {
                dialog.SetTitle(Title);
            }

            dialog.SetOptions(FOS.FOS_PICKFOLDERS | FOS.FOS_ALLNONSTORAGEITEMS);
            uint hr = dialog.Show(owner != null ? owner.Handle : IntPtr.Zero);

            if (hr == ERROR_CANCELLED)
            {
                return(DialogResult.Cancel);
            }

            if (hr != 0)
            {
                return(DialogResult.Abort);
            }

            dialog.GetResult(out result);

            string path;

            result.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out path);
            SelectedPath = path;

            result.GetDisplayName(SIGDN.SIGDN_NORMALDISPLAY, out path);
            SelectedNormalDisplay = path;

            result.GetDisplayName(SIGDN.SIGDN_DESKTOPABSOLUTEPARSING, out path);
            SelectedDesktopAbsoluteParsing = path;

            result.GetDisplayName(SIGDN.SIGDN_URL, out path);
            SelectedUrl = path;

            return(DialogResult.OK);
        }
        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;

        }
        public static string GetName(IShellItem applicationItem)
        {
            applicationItem.GetDisplayName(SIGDN.SIGDN_NORMALDISPLAY, out var pName);
            var name = Marshal.PtrToStringUni(pName);

            return(name);
        }
Example #5
0
 private static void TraceAction(
     string action, IShellItem item, uint hresult)
 {
     TraceAction(action,
                 item != null ? item.GetDisplayName(SIGDN.SIGDN_NORMALDISPLAY) : null,
                 hresult);
 }
Example #6
0
        private static string GetDisplayNameImpl(IShellItem shellItem, ShellNativeMethods.ShellItemDesignNameOptions shellItemDesignNameOptions)
        {
            if (shellItem == null)
            {
                return(null);
            }

            string path = null;

            IntPtr  pszPath = IntPtr.Zero;
            HResult hr      = shellItem.GetDisplayName(shellItemDesignNameOptions, 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);
        }
Example #7
0
        internal static string GetParsingName(IShellItem shellItem)
        {
            if (shellItem == null)
            {
                return(null);
            }

            string path = null;

            IntPtr  pszPath = IntPtr.Zero;
            HRESULT hr      = shellItem.GetDisplayName(ShellNativeMethods.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);
        }
Example #8
0
 public virtual void PostNewItem
 (
     TSF dwFlags,
     IShellItem psiDestinationFolder,
     string pszNewName,
     string pszTemplateName,
     FILE_ATTRIBUTE dwFileAttributes,
     int hrNew,
     IShellItem psiNewItem
 )
 {
     this.fileOperation.OnPostNew?.Invoke
     (
         this.fileOperation,
         new PostNewEventArgs
         (
             (TransferSourceFlags)dwFlags,
             psiDestinationFolder.GetDisplayName(SIGDN.DESKTOPABSOLUTEPARSING),
             pszNewName,
             pszTemplateName,
             (FileAttributes)dwFileAttributes,
             psiNewItem.GetDisplayName(SIGDN.DESKTOPABSOLUTEPARSING),
             hrNew
         )
     );
 }
Example #9
0
        internal string GetFileNameFromShellItem(IShellItem item)
        {
            string filename;

            item.GetDisplayName(NativeMethods.SIGDN.SIGDN_DESKTOPABSOLUTEPARSING, out filename);
            return(filename);
        }
Example #10
0
        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 Exception("GetParsingName has failed: " + hr);
            }

            if (pszPath != IntPtr.Zero)
            {
                path = Marshal.PtrToStringAuto(pszPath);
                Marshal.FreeCoTaskMem(pszPath);
                pszPath = IntPtr.Zero;
            }

            return(path);
        }
Example #11
0
        public static String GetFileNameFromShellItem(IShellItem item)
#endif
        {
            if (item is null)
            {
                return(null);
            }
            else
            {
                HResult hr = item.GetDisplayName(ShellItemDesignNameOptions.DesktopAbsoluteParsing, out IntPtr pszString);
                if (hr == HResult.Ok && pszString != IntPtr.Zero)
                {
#if NETCOREAPP3_1_OR_GREATER
                    String fileName = Marshal.PtrToStringAuto(pszString) !;                      // `PtrToStringAuto` won't return `null` if its `ptr` argument is not null, which we check for.
#else
                    String fileName = Marshal.PtrToStringAuto(pszString);
#endif
                    Marshal.FreeCoTaskMem(pszString);
                    return(fileName);
                }
                else
                {
                    return(null);
                }
            }
        }
Example #12
0
        public static string GetAppModelUserId(IShellItem applicationItem)
        {
            applicationItem.GetDisplayName(SIGDN.SIGDN_DESKTOPABSOLUTEPARSING, out var pName);
            var name = Marshal.PtrToStringUni(pName);

            return(name);
        }
Example #13
0
        private string GetDisplayName(SIGDN purpose)
        {
            IntPtr hString = IntPtr.Zero;
            string name    = string.Empty;

            try
            {
                if (_shellItem?.GetDisplayName(purpose, out hString) == NativeMethods.S_OK)
                {
                    if (hString != IntPtr.Zero)
                    {
                        name = Marshal.PtrToStringAuto(hString);
                    }
                }
            }
            catch (Exception e)
            {
                ShellLogger.Error($"ShellItem: Unable to get {purpose} display name: {e.Message}");
            }
            finally
            {
                Marshal.FreeCoTaskMem(hString);
            }

            return(name);
        }
        internal static string GetParsingName(IShellItem shellItem)
        {
            if (shellItem == null)
            {
                return(null);
            }

            string path = null;

            HResult hr = shellItem.GetDisplayName(ShellItemDesignNameOptions.DesktopAbsoluteParsing, out IntPtr 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);
        }
Example #15
0
 private static void TraceAction(
     string action, IShellItem item, uint hresult)
 {
     // ReSharper disable once InvocationIsSkipped
     TraceAction(action,
                 item?.GetDisplayName(SIGDN.SIGDN_NORMALDISPLAY),
                 hresult);
 }
        private void GetPathAndElementName([NotNull] IShellItem item, out string path, out string elementName)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            item.GetDisplayName(Sigdn.Parentrelativeforaddressbar, out elementName);
            try
            {
                item.GetDisplayName(Sigdn.Filesyspath, out path);
            }
            catch (ArgumentException ex) when(ex.HResult == -2147024809)
            {
                path = null;
            }
        }
Example #17
0
    private static string GetDisplayName(IShellItem item, SIGDN sigdnName)
    {
        item.GetDisplayName(sigdnName, out var ptr);
        var name = Marshal.PtrToStringUni(ptr);

        Marshal.FreeCoTaskMem(ptr);
        return(name);
    }
Example #18
0
        public void ShellItem_GetDisplayName()
        {
            IKnownFolderManager manager = ShellMethods.GetKnownFolderManager();
            IKnownFolder        folder  = manager.GetFolder(KnownFolderIds.Windows);
            IShellItem          item    = folder.GetShellItem(0, new Guid(InterfaceIds.IID_IShellItem));

            item.GetDisplayName(ShellItemDisplayNames.NormalDisplay).Should().Be("Windows");
        }
Example #19
0
        public void ShellItem_GetDisplayName()
        {
            IKnownFolderManager manager = ShellDesktopMethods.GetKnownFolderManager();
            IKnownFolder        folder  = manager.GetFolder(KNOWNFOLDERID.Windows);
            IShellItem          item    = folder.GetShellItem(0, new Guid(InterfaceIds.IID_IShellItem));

            item.GetDisplayName(SIGDN.NORMALDISPLAY).Should().Be("Windows");
        }
Example #20
0
        public static HRESULT DisplayItem(this IShellItemArray psia, HWND hwnd = default)
        {
            // Get the first ShellItem and display its name
            IShellItem psi            = psia.GetItemAt(0);
            var        pszDisplayName = psi.GetDisplayName(SIGDN.SIGDN_NORMALDISPLAY);

            User32.MessageBox(hwnd, pszDisplayName, pszDisplayName, User32.MB_FLAGS.MB_OK);
            return(HRESULT.S_OK);
        }
Example #21
0
        internal override string[] ProcessVistaFiles(IFileDialog dialog)
        {
            IShellItem result = dialog.GetResult();

            return(new string[]
            {
                result.GetDisplayName((SIGDN)2147647488U)
            });
        }
Example #22
0
 public static void PrintShellItemArray(IShellItemArray shellItemArray)
 {
     for (uint i = 0; i < shellItemArray.GetCount(); i++)
     {
         IShellItem si = shellItemArray.GetItemAt(i);
         Console.Out.WriteLine(si.GetDisplayName(SIGDN.SIGDN_FILESYSPATH));
         Marshal.ReleaseComObject(si);
     }
 }
 public override void PostCopyItem(uint dwFlags, IShellItem psiItem, IShellItem psiDestinationFolder, string pszNewName, uint hrCopy, IShellItem psiNewlyCreated)
 {
     if (hrCopy != 0)
     {
         return;
     }
     ((Dictionary <string, string>)Application.Current.Properties["FileOperationResult"]).Add(
         psiItem.GetDisplayName(SIGDN.SIGDN_FILESYSPATH),
         psiNewlyCreated.GetDisplayName(SIGDN.SIGDN_FILESYSPATH));
 }
Example #24
0
        internal static string GetFilePathFromShellItem(IShellItem item)
        {
            string str;

            unchecked
            {
                item.GetDisplayName((SIGDN)(-2147319808), out str);
            }
            return(str);
        }
Example #25
0
 public virtual void PreDeleteItem(TSF dwFlags, IShellItem psiItem)
 {
     this.fileOperation.OnPreDelete?.Invoke
     (
         this.fileOperation,
         new PreDeleteEventArgs
         (
             (TransferSourceFlags)dwFlags,
             psiItem.GetDisplayName(SIGDN.DESKTOPABSOLUTEPARSING)
         )
     );
 }
        public override void PostDeleteItem(uint dwFlags, IShellItem psiItem, uint hrDelete, IShellItem psiNewlyCreated)
        {
            if ((CopyEngineResult)hrDelete != CopyEngineResult.COPYENGINE_OK &&
                (CopyEngineResult)hrDelete != CopyEngineResult.COPYENGINE_S_DONT_PROCESS_CHILDREN)
            {
                return;
            }

            FileOperationResult.Add(
                psiItem.GetDisplayName(SIGDN.SIGDN_FILESYSPATH),
                null);
        }
Example #27
0
 internal static string GetFileNameFromShellItem(IShellItem item)
 {
     string filename = null;
     IntPtr pszString = IntPtr.Zero;
     HResult hr = item.GetDisplayName(ShellNativeMethods.ShellItemDesignNameOptions.DesktopAbsoluteParsing, out pszString);
     if (hr == HResult.Ok && pszString != IntPtr.Zero)
     {
         filename = Marshal.PtrToStringAuto(pszString);
         Marshal.FreeCoTaskMem(pszString);
     }
     return filename;
 }
        public override void PostCopyItem(uint dwFlags, IShellItem psiItem, IShellItem psiDestinationFolder,
                                          string pszNewName, uint hrCopy, IShellItem psiNewlyCreated)
        {
            if ((CopyEngineResult)hrCopy != CopyEngineResult.COPYENGINE_OK &&
                (CopyEngineResult)hrCopy != CopyEngineResult.COPYENGINE_S_DONT_PROCESS_CHILDREN)
            {
                return;
            }

            FileOperationResult.Add(
                psiItem.GetDisplayName(SIGDN.SIGDN_FILESYSPATH),
                psiNewlyCreated.GetDisplayName(SIGDN.SIGDN_FILESYSPATH));
        }
Example #29
0
 public virtual void PreRenameItem(TSF dwFlags, IShellItem psiItem, string pszNewName)
 {
     this.fileOperation.OnPreRename?.Invoke
     (
         this.fileOperation,
         new PreRenameEventArgs
         (
             (TransferSourceFlags)dwFlags,
             psiItem.GetDisplayName(SIGDN.DESKTOPABSOLUTEPARSING),
             pszNewName
         )
     );
 }
Example #30
0
 public virtual void PostRenameItem
 (
     TSF dwFlags,
     IShellItem psiItem,
     string pszNewName,
     int hrRename,
     IShellItem psiNewlyCreated
 )
 {
     this.fileOperation.OnPostRename?.Invoke
     (
         this.fileOperation,
         new PostRenameEventArgs
         (
             (TransferSourceFlags)dwFlags,
             psiItem.GetDisplayName(SIGDN.DESKTOPABSOLUTEPARSING),
             pszNewName,
             psiNewlyCreated.GetDisplayName(SIGDN.DESKTOPABSOLUTEPARSING),
             psiNewlyCreated.GetDisplayName(SIGDN.PARENTRELATIVE),
             hrRename
         )
     );
 }
Example #31
0
        private static unsafe string?GetAbsoluteFilePath(IShellItem shellItem)
        {
            var pszString = new IntPtr(shellItem.GetDisplayName(SIGDN_FILESYSPATH));

            if (pszString != IntPtr.Zero)
            {
                try
                {
                    return(Marshal.PtrToStringUni(pszString));
                }
                finally
                {
                    Marshal.FreeCoTaskMem(pszString);
                }
            }
            return(default);
Example #32
0
		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;

		}
 internal string GetFileNameFromShellItem(IShellItem item)
 {
     string filename;
     item.GetDisplayName(NativeMethods.SIGDN.DESKTOPABSOLUTEPARSING, out filename);
     return filename;
 }
Example #34
0
 public static string GetPathFromShellItem(IShellItem item)
 {
     return item.GetDisplayName(SIGDN.DESKTOPABSOLUTEPARSING);
 }
 private static void TraceAction(
     string action, IShellItem item, uint hresult)
 {
     TraceAction(action, 
         item != null ? item.GetDisplayName(SIGDN.SIGDN_NORMALDISPLAY) : null, 
         hresult);
 }
 internal static string GetFileNameFromShellItem(IShellItem item)
 {
     string filename = null;
     IntPtr pszString = IntPtr.Zero;
     HResult hr = item.GetDisplayName(ShellNativeMethods.ShellItemDesignNameOptions.DesktopAbsoluteParsing, out pszString);
     if (hr == HResult.Ok && pszString != IntPtr.Zero)
     {
         filename = Marshal.PtrToStringAuto(pszString);
         Marshal.FreeCoTaskMem(pszString);
     }
     return filename;
 }
Example #37
0
		internal static string GetFilePathFromShellItem(IShellItem item)
		{
			string str;
			unchecked
			{
				item.GetDisplayName((SIGDN)(-2147319808), out str);
			}
			return str;
		}
Example #38
0
        private string RemoveCustomCategoryItem(IShellItem item)
        {
            string path = null;

            if (customCategoriesCollection != null)
            {
                IntPtr pszString = IntPtr.Zero;
                HRESULT hr = item.GetDisplayName(ShellNativeMethods.SIGDN.SIGDN_FILESYSPATH, out pszString);
                if (hr == HRESULT.S_OK && pszString != IntPtr.Zero)
                {
                    path = Marshal.PtrToStringAuto(pszString);
                    // Free the string
                    Marshal.FreeCoTaskMem(pszString);
                }

                // Remove this item from each category
                foreach (JumpListCustomCategory category in customCategoriesCollection)
                    category.RemoveJumpListItem(path);

            }

            return path;
        }
 public override void PostCopyItem(uint dwFlags, IShellItem psiItem, IShellItem psiDestinationFolder, string pszNewName, uint hrCopy, IShellItem psiNewlyCreated) {
   if ((CopyEngineResult)hrCopy != CopyEngineResult.COPYENGINE_OK && (CopyEngineResult)hrCopy != CopyEngineResult.COPYENGINE_S_DONT_PROCESS_CHILDREN) return;
   ((Dictionary<string, string>)Application.Current.Properties[nameof(AppProps.FileOperationResult)]).Add(
     psiItem.GetDisplayName(SIGDN.SIGDN_FILESYSPATH), 
     psiNewlyCreated.GetDisplayName(SIGDN.SIGDN_FILESYSPATH));
 }
 internal static string GetFileNameFromShellItem( IShellItem item )
 {
     string filename = null;
     IntPtr pszString = IntPtr.Zero;
     HRESULT hr = item.GetDisplayName( ShellNativeMethods.SIGDN.SIGDN_DESKTOPABSOLUTEPARSING, out pszString );
     if (hr == HRESULT.S_OK && pszString != IntPtr.Zero)
     {
         filename = Marshal.PtrToStringAuto(pszString);
         Marshal.FreeCoTaskMem(pszString);
     }
     return filename;
 }
Example #41
0
        private string RemoveCustomCategoryItem(IShellItem item)
        {
            string path = null;

            if (customCategoriesCollection != null)
            {
                IntPtr pszString = IntPtr.Zero;
                HResult hr = item.GetDisplayName(ShellNativeMethods.ShellItemDesignNameOptions.FileSystemPath, out pszString);
                if (hr == HResult.Ok && pszString != IntPtr.Zero)
                {
                    path = Marshal.PtrToStringAuto(pszString);
                    // Free the string
                    Marshal.FreeCoTaskMem(pszString);
                }

                // Remove this item from each category
                foreach (JumpListCustomCategory category in customCategoriesCollection)
                {
                    category.RemoveJumpListItem(path);
                }

            }

            return path;
        }