public void Generate(ShortcutRequest shortcutRequest) { var shortcutName = shortcutRequest.ShortcutName.ToLower().Replace(" ", "-"); var shortcutPath = Path.Combine( shortcutRequest.ShortcutDirectoryPath, $"{shortcutName}.desktop"); if (File.Exists(shortcutPath)) { var exception = new InvalidOperationException("Shortcut already exists."); exception.Data[ExceptionData.ShortcutPath] = shortcutPath; throw exception; } var shortcutBuilder = new StringBuilder(); shortcutBuilder.AppendLine("[Desktop Entry]"); shortcutBuilder.AppendLine($"Name={shortcutRequest.ShortcutName}"); shortcutBuilder.AppendLine($"Exec={shortcutRequest.SourceFullPath}"); shortcutBuilder.AppendLine($"Path={shortcutRequest.WorkingDirectory}"); shortcutBuilder.AppendLine("Type=Application"); shortcutBuilder.AppendLine($"Icon={shortcutRequest.IconPath}"); shortcutBuilder.AppendLine("Comment="); shortcutBuilder.AppendLine("Terminal=false"); File.WriteAllText(shortcutPath, shortcutBuilder.ToString()); UnixFileSystemInfo.GetFileSystemEntry(shortcutPath).FileAccessPermissions |= FileAccessPermissions.UserExecute; }
public void Generate(ShortcutRequest shortcutRequest) { var shortcutPath = Path.Combine( shortcutRequest.ShortcutDirectoryPath, $"{shortcutRequest.ShortcutName}.lnk"); if (File.Exists(shortcutPath)) { throw new InvalidOperationException("Shortcut already exists."); } var shortcut = new CSharpLib.Shortcut(); shortcut.CreateShortcutToFile(shortcutRequest.SourceFullPath, shortcutPath, WorkingDirectory: shortcutRequest.WorkingDirectory); }