Beispiel #1
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((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);

                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);
        }
Beispiel #2
0
 private static IShellItem2 CreateItemFromJumpPath(JumpPath jumpPath)
 {
     try
     {
         return(JumpList.GetShellItemForPath(Path.GetFullPath(jumpPath.Path)));
     }
     catch (Exception)
     {
     }
     return(null);
 }
Beispiel #3
0
        private static object GetShellObjectForJumpItem(JumpItem jumpItem)
        {
            JumpPath jumpPath = jumpItem as JumpPath;
            JumpTask jumpTask = jumpItem as JumpTask;

            if (jumpPath != null)
            {
                return(JumpList.CreateItemFromJumpPath(jumpPath));
            }
            if (jumpTask != null)
            {
                return(JumpList.CreateLinkFromJumpTask(jumpTask, true));
            }
            return(null);
        }
Beispiel #4
0
        private static IShellItem2 CreateItemFromJumpPath(JumpPath jumpPath)
        {
            Debug.Assert(jumpPath != null);

            try
            {
                // This will return null if the path doesn't exist.
                return(GetShellItemForPath(Path.GetFullPath(jumpPath.Path)));
            }
            catch (Exception)
            {
                // Don't propagate exceptions here.  If we couldn't create the item, it's just invalid.
            }

            return(null);
        }
Beispiel #5
0
 public static void AddToRecentCategory(JumpPath jumpPath)
 {
     Verify.IsNotNull <JumpPath>(jumpPath, "jumpPath");
     JumpList.AddToRecentCategory(jumpPath.Path);
 }
Beispiel #6
0
 public static void AddToRecentCategory(JumpPath jumpPath)
 {
     Verify.IsNotNull(jumpPath, "jumpPath");
     AddToRecentCategory(jumpPath.Path);
 }
Beispiel #7
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((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);

                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;
        }
Beispiel #8
0
        private static IShellItem2 CreateItemFromJumpPath(JumpPath jumpPath)
        {
            Debug.Assert(jumpPath != null);

            try
            {
                // This will return null if the path doesn't exist.
                return GetShellItemForPath(Path.GetFullPath(jumpPath.Path));
            }
            catch (Exception)
            {
                // Don't propagate exceptions here.  If we couldn't create the item, it's just invalid.
            }

            return null;
        }
Beispiel #9
0
 public static void AddToRecentCategory(JumpPath jumpPath)
 {
     Standard.Verify.IsNotNull <JumpPath>(jumpPath, "jumpPath");
     AddToRecentCategory(jumpPath.Path);
 }