/// <summary> /// Creates the specified shell link. /// </summary> /// <param name="shellLinkInfo">The shell link information.</param> /// <returns><c>true</c> if creating the specified shell link successfully, <c>false</c> otherwise.</returns> public bool Create(ShellLinkInfo shellLinkInfo) { if (shellLinkInfo == null) { return(false); } var result = false; try { result = OnCreate(shellLinkInfo); } catch (Exception e) { Logger.GetInstance(typeof(LinkManager)).Error(e.ToString()); } return(result); }
/// <inheritdoc /> protected override bool OnCreate(ShellLinkInfo shellLinkInfo) { if (!Platform.IsWindows) { return(false); } var sourcePath = shellLinkInfo.SourcePath; var targetPath = shellLinkInfo.TargetPath; var targetIconPath = shellLinkInfo.TargetIconPath; var targetIconIndex = shellLinkInfo.TargetIconIndex; if (sourcePath == null || !sourcePath.Exists || targetPath == null) { return(false); } var sourceWorkingPath = shellLinkInfo.SourceWorkingPath ?? sourcePath.Directory; if (sourceWorkingPath == null) { return(false); } var targetParent = targetPath.Directory; if (targetParent != null && !targetParent.Exists) { Directory.CreateDirectory(targetParent.FullName); } var description = shellLinkInfo.Description; var sourceActivatorId = shellLinkInfo.SourceActivatorId; var sourceAppId = shellLinkInfo.SourceAppId; var sourceArguments = shellLinkInfo.SourceArguments; var sourceShowWindowCommand = ConvertFrom(shellLinkInfo.SourceWindowState); using (var windowShellLink = Windows.ShellLink.GetInstance()) { var success = windowShellLink.SetSourcePath(sourcePath); if (!success) { return(false); } success = windowShellLink.SetSourceShowWindowCommand(sourceShowWindowCommand); if (!success) { return(false); } success = windowShellLink.SetSourceWorkingPath(sourceWorkingPath); if (!success) { return(false); } if (targetIconPath != null && File.Exists(targetIconPath.FullName)) { success = windowShellLink.SetTargetIcon( targetIconPath, targetIconIndex ); if (!success) { return(false); } } if (!string.IsNullOrWhiteSpace(description)) { success = windowShellLink.SetDescription(description); if (!success) { return(false); } } if (sourceActivatorId != Guid.Empty) { success = windowShellLink.SetSourceActivatorId(sourceActivatorId); if (!success) { return(false); } } if (!string.IsNullOrWhiteSpace(sourceAppId)) { success = windowShellLink.SetSourceAppId(sourceAppId); if (!success) { return(false); } } if (!string.IsNullOrWhiteSpace(sourceArguments)) { success = windowShellLink.SetSourceArguments(sourceArguments); if (!success) { return(false); } } success = windowShellLink.Save(targetPath); if (!success) { return(false); } } return(true); }
/// <summary> /// Called when creating the specified shell link. /// </summary> /// <param name="shellLinkInfo">The shell link information.</param> /// <returns><c>true</c> if creating the specified shell link successfully, <c>false</c> otherwise.</returns> protected abstract bool OnCreate(ShellLinkInfo shellLinkInfo);