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); }
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 static Standard.IShellLinkW CreateLinkFromJumpTask(JumpTask jumpTask, bool allowSeparators) { Standard.IShellLinkW kw3; if (string.IsNullOrEmpty(jumpTask.Title) && (!allowSeparators || !string.IsNullOrEmpty(jumpTask.CustomCategory))) { return(null); } Standard.IShellLinkW comObject = (Standard.IShellLinkW)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("00021401-0000-0000-C000-000000000046"))); try { string pszFile = _FullName; if (!string.IsNullOrEmpty(jumpTask.ApplicationPath)) { pszFile = jumpTask.ApplicationPath; } comObject.SetPath(pszFile); if (!string.IsNullOrEmpty(jumpTask.WorkingDirectory)) { comObject.SetWorkingDirectory(jumpTask.WorkingDirectory); } if (!string.IsNullOrEmpty(jumpTask.Arguments)) { comObject.SetArguments(jumpTask.Arguments); } if (jumpTask.IconResourceIndex != -1) { string pszIconPath = _FullName; if (!string.IsNullOrEmpty(jumpTask.IconResourcePath)) { if (jumpTask.IconResourcePath.Length >= 260L) { return(null); } pszIconPath = jumpTask.IconResourcePath; } comObject.SetIconLocation(pszIconPath, jumpTask.IconResourceIndex); } if (!string.IsNullOrEmpty(jumpTask.Description)) { comObject.SetDescription(jumpTask.Description); } Standard.IPropertyStore store = (Standard.IPropertyStore)comObject; using (PROPVARIANT propvariant = new PROPVARIANT()) { Standard.PKEY title = new Standard.PKEY(); if (!string.IsNullOrEmpty(jumpTask.Title)) { propvariant.SetValue(jumpTask.Title); title = Standard.PKEY.Title; } else { propvariant.SetValue(true); title = Standard.PKEY.AppUserModel_IsDestListSeparator; } store.SetValue(ref title, propvariant); } store.Commit(); Standard.IShellLinkW kw2 = comObject; comObject = null; kw3 = kw2; } catch (Exception) { kw3 = null; } finally { Standard.Utility.SafeRelease <Standard.IShellLinkW>(ref comObject); } return(kw3); }