示例#1
0
        /// <summary>
        /// Generate a unique string for the ShellLink that can be used for equality checks.
        /// </summary>
        private static string ShellLinkToString(IShellLinkW shellLink)
        {
            var pathBuilder = new StringBuilder(Win32Constant.MAX_PATH);

            shellLink.GetPath(pathBuilder, pathBuilder.Capacity, null, SLGP.RAWPATH);

            string title = null;

            // Need to use the property store to get the title for the link.
            using (PROPVARIANT pv = new PROPVARIANT())
            {
                var  propStore = (IPropertyStore)shellLink;
                PKEY pkeyTitle = PKEY.Title;

                propStore.GetValue(ref pkeyTitle, pv);

                // PKEY_Title should be an LPWSTR if it's not empty.
                title = pv.GetValue() ?? "";
            }

            var argsBuilder = new StringBuilder(Win32Constant.INFOTIPSIZE);

            shellLink.GetArguments(argsBuilder, argsBuilder.Capacity);

            // Path and title should be case insensitive.
            // Shell treats arguments as case sensitive because apps can handle those differently.
            return(pathBuilder.ToString().ToUpperInvariant() + title.ToUpperInvariant() + argsBuilder.ToString());
        }
示例#2
0
        private static JumpItem GetJumpItemForShellObject(object shellObject)
        {
            var shellItem = shellObject as IShellItem2;
            var shellLink = shellObject as IShellLinkW;

            if (shellItem != null)
            {
                JumpPath path = new JumpPath
                {
                    Path = shellItem.GetDisplayName(SIGDN.DESKTOPABSOLUTEPARSING),
                };
                return(path);
            }

            if (shellLink != null)
            {
                var pathBuilder = new StringBuilder(Win32Constant.MAX_PATH);
                shellLink.GetPath(pathBuilder, pathBuilder.Capacity, null, SLGP.RAWPATH);
                var argsBuilder = new StringBuilder(Win32Constant.INFOTIPSIZE);
                shellLink.GetArguments(argsBuilder, argsBuilder.Capacity);
                var descBuilder = new StringBuilder(Win32Constant.INFOTIPSIZE);
                shellLink.GetDescription(descBuilder, descBuilder.Capacity);
                var iconBuilder = new StringBuilder(Win32Constant.MAX_PATH);
                int iconIndex;
                shellLink.GetIconLocation(iconBuilder, iconBuilder.Capacity, out iconIndex);
                var dirBuilder = new StringBuilder(Win32Constant.MAX_PATH);
                shellLink.GetWorkingDirectory(dirBuilder, dirBuilder.Capacity);

                JumpTask task = new JumpTask
                {
                    // Set ApplicationPath and IconResources, even if they're from the current application.
                    // This means that equivalent JumpTasks won't necessarily compare property-for-property.
                    ApplicationPath   = pathBuilder.ToString(),
                    Arguments         = argsBuilder.ToString(),
                    Description       = descBuilder.ToString(),
                    IconResourceIndex = iconIndex,
                    IconResourcePath  = iconBuilder.ToString(),
                    WorkingDirectory  = dirBuilder.ToString(),
                };

                using (PROPVARIANT pv = new PROPVARIANT())
                {
                    var  propStore = (IPropertyStore)shellLink;
                    PKEY pkeyTitle = PKEY.Title;

                    propStore.GetValue(ref pkeyTitle, pv);

                    // PKEY_Title should be an LPWSTR if it's not empty.
                    task.Title = pv.GetValue() ?? "";
                }

                return(task);
            }

            // Unsupported type?
            Debug.Assert(false);
            return(null);
        }
示例#3
0
        private static JumpItem GetJumpItemForShellObject(object shellObject)
        {
            int num;

            Standard.IShellItem2 item = shellObject as Standard.IShellItem2;
            Standard.IShellLinkW kw   = shellObject as Standard.IShellLinkW;
            if (item != null)
            {
                return(new JumpPath {
                    Path = item.GetDisplayName(unchecked ((Standard.SIGDN)(-2147319808)))
                });
            }
            if (kw == null)
            {
                return(null);
            }
            StringBuilder pszFile = new StringBuilder(260);

            kw.GetPath(pszFile, pszFile.Capacity, null, Standard.SLGP.RAWPATH);
            StringBuilder pszArgs = new StringBuilder(0x400);

            kw.GetArguments(pszArgs, pszArgs.Capacity);
            StringBuilder builder3 = new StringBuilder(0x400);

            kw.GetDescription(builder3, builder3.Capacity);
            StringBuilder pszIconPath = new StringBuilder(260);

            kw.GetIconLocation(pszIconPath, pszIconPath.Capacity, out num);
            StringBuilder pszDir = new StringBuilder(260);

            kw.GetWorkingDirectory(pszDir, pszDir.Capacity);
            JumpTask task = new JumpTask {
                ApplicationPath   = pszFile.ToString(),
                Arguments         = pszArgs.ToString(),
                Description       = builder3.ToString(),
                IconResourceIndex = num,
                IconResourcePath  = pszIconPath.ToString(),
                WorkingDirectory  = pszDir.ToString()
            };

            using (PROPVARIANT propvariant = new PROPVARIANT())
            {
                Standard.IPropertyStore store = (Standard.IPropertyStore)kw;
                Standard.PKEY           title = Standard.PKEY.Title;
                store.GetValue(ref title, propvariant);
                task.Title = propvariant.GetValue() ?? "";
            }
            return(task);
        }
示例#4
0
        private static JumpItem GetJumpItemForShellObject(object shellObject)
        {
            var shellItem = shellObject as IShellItem2;
            var shellLink = shellObject as IShellLinkW;

            if (shellItem != null)
            {
                var path = new JumpPath {
                    Path = shellItem.GetDisplayName(SIGDN.DESKTOPABSOLUTEPARSING),
                };
                return(path);
            }
            if (shellLink != null)
            {
                var pathBuilder = new StringBuilder((int)Win32Value.MAX_PATH);
                shellLink.GetPath(pathBuilder, pathBuilder.Capacity, null, SLGP.RAWPATH);
                var argsBuilder = new StringBuilder((int)Win32Value.INFOTIPSIZE);
                shellLink.GetArguments(argsBuilder, argsBuilder.Capacity);
                var descBuilder = new StringBuilder((int)Win32Value.INFOTIPSIZE);
                shellLink.GetDescription(descBuilder, descBuilder.Capacity);
                var iconBuilder = new StringBuilder((int)Win32Value.MAX_PATH);
                int iconIndex;
                shellLink.GetIconLocation(iconBuilder, iconBuilder.Capacity, out iconIndex);
                var dirBuilder = new StringBuilder((int)Win32Value.MAX_PATH);
                shellLink.GetWorkingDirectory(dirBuilder, dirBuilder.Capacity);
                var task = new JumpTask
                {
                    ApplicationPath   = pathBuilder.ToString(),
                    Arguments         = argsBuilder.ToString(),
                    Description       = descBuilder.ToString(),
                    IconResourceIndex = iconIndex,
                    IconResourcePath  = iconBuilder.ToString(),
                    WorkingDirectory  = dirBuilder.ToString(),
                };
                using (var pv = new PROPVARIANT())
                {
                    var propStore = (IPropertyStore)shellLink;
                    var pkeyTitle = PKEY.Title;
                    propStore.GetValue(ref pkeyTitle, pv);

                    task.Title = pv.GetValue() ?? "";
                }
                return(task);
            }

            Debug.Assert(false);
            return(null);
        }
示例#5
0
        private static AudioDevice CreateDevice(IMMDevice dev)
        {
            if (dev == null)
            {
                return(null);
            }

            string id;

            dev.GetId(out id);
            DEVICE_STATE state;

            dev.GetState(out state);
            Dictionary <string, object> properties = new Dictionary <string, object>();
            IPropertyStore store;

            dev.OpenPropertyStore(STGM.STGM_READ, out store);
            if (store != null)
            {
                int propCount;
                store.GetCount(out propCount);
                for (int j = 0; j < propCount; j++)
                {
                    PROPERTYKEY pk;
                    if (store.GetAt(j, out pk) == 0)
                    {
                        PROPVARIANT value = new PROPVARIANT();
                        int         hr    = store.GetValue(ref pk, ref value);
                        object      v     = value.GetValue();
                        try
                        {
                            if (value.vt != VARTYPE.VT_BLOB) // for some reason, this fails?
                            {
                                PropVariantClear(ref value);
                            }
                        }
                        catch
                        {
                        }
                        string name = pk.ToString();
                        properties[name] = v;
                    }
                }
            }
            return(new AudioDevice(id, (AudioDeviceState)state, properties));
        }
示例#6
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);
        }
示例#7
0
        private static string ShellLinkToString(IShellLinkW shellLink)
        {
            StringBuilder stringBuilder = new StringBuilder(260);

            shellLink.GetPath(stringBuilder, stringBuilder.Capacity, null, SLGP.RAWPATH);
            string text = null;

            using (PROPVARIANT propvariant = new PROPVARIANT())
            {
                IPropertyStore propertyStore = (IPropertyStore)shellLink;
                PKEY           title         = PKEY.Title;
                propertyStore.GetValue(ref title, propvariant);
                text = (propvariant.GetValue() ?? "");
            }
            StringBuilder stringBuilder2 = new StringBuilder(1024);

            shellLink.GetArguments(stringBuilder2, stringBuilder2.Capacity);
            return(stringBuilder.ToString().ToUpperInvariant() + text.ToUpperInvariant() + stringBuilder2.ToString());
        }
        private double GetDoubleProperty(ILocationReport report, PROPERTYKEY propkey)
        {
            double val = double.NaN;

            PROPVARIANT pv = new PROPVARIANT();

            using (pv)
            {
                if (0 == report.GetValue(ref propkey, pv))
                {
                    if (pv.vt == VarEnum.VT_R8)
                    {
                        val = (double)pv.GetValue();
                    }
                }
            }

            return(val);
        }
示例#9
0
        private static string ShellLinkToString(Standard.IShellLinkW shellLink)
        {
            StringBuilder pszFile = new StringBuilder(260);

            shellLink.GetPath(pszFile, pszFile.Capacity, null, Standard.SLGP.RAWPATH);
            string str = null;

            using (PROPVARIANT propvariant = new PROPVARIANT())
            {
                Standard.IPropertyStore store = (Standard.IPropertyStore)shellLink;
                Standard.PKEY           title = Standard.PKEY.Title;
                store.GetValue(ref title, propvariant);
                str = propvariant.GetValue() ?? "";
            }
            StringBuilder pszArgs = new StringBuilder(0x400);

            shellLink.GetArguments(pszArgs, pszArgs.Capacity);
            return(pszFile.ToString().ToUpperInvariant() + str.ToUpperInvariant() + pszArgs.ToString());
        }
        private string GetStringProperty(ILocationReport report, PROPERTYKEY propkey)
        {
            string val = String.Empty;

            PROPVARIANT pv = new PROPVARIANT();

            using (pv)
            {
                int hr = report.GetValue(ref propkey, pv);
                if (0 == hr)
                {
                    if (pv.vt == VarEnum.VT_LPWSTR)
                    {
                        val = (string)pv.GetValue();
                    }
                }
            }

            return(val);
        }
        private static AudioDevice CreateDevice(IMMDevice dev)
        {
            if (dev == null)
                return null;

            string id;
            dev.GetId(out id);
            DEVICE_STATE state;
            dev.GetState(out state);
            Dictionary<string, object> properties = new Dictionary<string, object>();
            IPropertyStore store;
            dev.OpenPropertyStore(STGM.STGM_READ, out store);
            if (store != null)
            {
                int propCount;
                store.GetCount(out propCount);
                for (int j = 0; j < propCount; j++)
                {
                    PROPERTYKEY pk;
                    if (store.GetAt(j, out pk) == 0)
                    {
                        PROPVARIANT value = new PROPVARIANT();
                        int hr = store.GetValue(ref pk, ref value);
                        object v = value.GetValue();
                        try
                        {
                            if (value.vt != VARTYPE.VT_BLOB) // for some reason, this fails?
                            {
                                PropVariantClear(ref value);
                            }
                        }
                        catch
                        {
                        }
                        string name = pk.ToString();
                        properties[name] = v;
                    }
                }
            }
            return new AudioDevice(id, (AudioDeviceState)state, properties);
        }
示例#12
0
        private static string ShellLinkToString(IShellLinkW shellLink)
        {
            var pathBuilder = new StringBuilder((int)Win32Value.MAX_PATH);

            shellLink.GetPath(pathBuilder, pathBuilder.Capacity, null, SLGP.RAWPATH);
            string title = null;

            using (var pv = new PROPVARIANT())
            {
                var propStore = (IPropertyStore)shellLink;
                var pkeyTitle = PKEY.Title;
                propStore.GetValue(ref pkeyTitle, pv);

                title = pv.GetValue() ?? "";
            }
            var argsBuilder = new StringBuilder((int)Win32Value.INFOTIPSIZE);

            shellLink.GetArguments(argsBuilder, argsBuilder.Capacity);

            return(pathBuilder.ToString().ToUpperInvariant() + title.ToUpperInvariant() + argsBuilder);
        }