예제 #1
0
        private HRESULT _ProcessItem(IShellItem2 psi)
        {
            var hr = GetUNCPathFromItem(psi, out var pszPath);

            if (hr.Failed)
            {
                pszPath = psi.GetDisplayName(SIGDN.SIGDN_FILESYSPATH);
            }

            // the property store for this item. note that this binds to the file system property store even for DBFolder items. we want
            // to fix this in the future
            var psr           = new CPropertyStoreReader(psi, PropSys.GETPROPERTYSTOREFLAGS.GPS_DELAYCREATION, c_rgProps, (uint)c_rgProps.Length);
            var perceivedType = psr.GetInt32(PROPERTYKEY.System.PerceivedType);

            if (3 /* PERCEIVED_TYPE_AUDIO */ == perceivedType)
            {
                var ullDuration = psr.GetUInt64(PROPERTYKEY.System.Media.Duration);
                ullDuration /= 10000000;                 // scale ns to seconds

                var pszTitle = psr.GetString(PROPERTYKEY.System.Title);
                //var ulTrackNumber = psr.GetUInt32(PROPERTYKEY.System.Music.TrackNumber);
                //var pszArtist = psr.GetString(PROPERTYKEY.System.Music.AlbumArtist);
                //var pszAlbum = psr.GetString(PROPERTYKEY.System.Music.AlbumTitle);
                FormatItem((uint)ullDuration, pszTitle, pszPath);
            }
            return(HRESULT.S_OK);
        }
예제 #2
0
        private void StartWatching()
        {
            IDC_LISTVIEW.Items.Clear();

            var fRecursive = IDC_RECURSIVE.Checked;

            _watcher.StartWatching(psiDrop, Handle, c_notifyMessage, SHCNE.SHCNE_ALLEVENTS, fRecursive);

            string pszName = psiDrop.GetDisplayName(SIGDN.SIGDN_NORMALDISPLAY);

            LogMessage(GROUPID.NAMES, "Watching", $"{pszName} {(fRecursive ? "(Recursive)" : string.Empty)}");
            AutoAdjustListView();
            Text = "Watching - " + pszName;
        }
        /// <summary>
        ///     Get the parsing name from the specified <see cref="IShellItem2" />.
        /// </summary>
        /// <param name="shellItem"><see cref="IShellItem2" />.</param>
        /// <returns>Parsing name.</returns>
        /// <exception cref="ShellException">Failed to acquire parsing name.</exception>
        private static string GetParsingName(IShellItem2 shellItem)
        {
            Contract.Requires(shellItem != null);
            Contract.Ensures(Contract.Result <string>() != null);

            string result;
            var    hr = shellItem.GetDisplayName(SIGDN.SIGDN_DESKTOPABSOLUTEPARSING, out result);

            if (HRESULT.Failed(hr) && hr != COMErrorCodes.E_INVALIDARG)
            {
                throw new ShellException(ErrorMessages.ShellHelperGetParsingNameFailed, hr);
            }
            return(result);
        }
예제 #4
0
        private static JumpItem GetJumpItemForShellObject(object shellObject)
        {
            IShellItem2 shellItem  = shellObject as IShellItem2;
            IShellLinkW shellLinkW = shellObject as IShellLinkW;

            if (shellItem != null)
            {
                return(new JumpPath
                {
                    Path = shellItem.GetDisplayName((SIGDN)2147647488u)
                });
            }
            if (shellLinkW != null)
            {
                StringBuilder stringBuilder = new StringBuilder(260);
                shellLinkW.GetPath(stringBuilder, stringBuilder.Capacity, null, SLGP.RAWPATH);
                StringBuilder stringBuilder2 = new StringBuilder(1024);
                shellLinkW.GetArguments(stringBuilder2, stringBuilder2.Capacity);
                StringBuilder stringBuilder3 = new StringBuilder(1024);
                shellLinkW.GetDescription(stringBuilder3, stringBuilder3.Capacity);
                StringBuilder stringBuilder4 = new StringBuilder(260);
                int           iconResourceIndex;
                shellLinkW.GetIconLocation(stringBuilder4, stringBuilder4.Capacity, out iconResourceIndex);
                StringBuilder stringBuilder5 = new StringBuilder(260);
                shellLinkW.GetWorkingDirectory(stringBuilder5, stringBuilder5.Capacity);
                JumpTask jumpTask = new JumpTask
                {
                    ApplicationPath   = stringBuilder.ToString(),
                    Arguments         = stringBuilder2.ToString(),
                    Description       = stringBuilder3.ToString(),
                    IconResourceIndex = iconResourceIndex,
                    IconResourcePath  = stringBuilder4.ToString(),
                    WorkingDirectory  = stringBuilder5.ToString()
                };
                using (PROPVARIANT propvariant = new PROPVARIANT())
                {
                    IPropertyStore propertyStore = (IPropertyStore)shellLinkW;
                    PKEY           title         = PKEY.Title;
                    propertyStore.GetValue(ref title, propvariant);
                    jumpTask.Title = (propvariant.GetValue() ?? "");
                }
                return(jumpTask);
            }
            return(null);
        }
예제 #5
0
 private static string GetDisplayName(IShellItem2 shellItem)
 {
     return(shellItem.GetDisplayName(SIGDN.NORMALDISPLAY).ReadAndFree());
 }