You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.1 KiB

  1. param($installPath, $toolsPath, $package, $project)
  2. # open json.net splash page on package install
  3. # don't open if json.net is installed as a dependency
  4. try
  5. {
  6. $url = "http://james.newtonking.com/json"
  7. $dte2 = Get-Interface $dte ([EnvDTE80.DTE2])
  8. if ($dte2.ActiveWindow.Caption -eq "Package Manager Console")
  9. {
  10. # user is installing from VS NuGet console
  11. # get reference to the window, the console host and the input history
  12. # show webpage if "install-package newtonsoft.json" was last input
  13. $consoleWindow = $(Get-VSComponentModel).GetService([NuGetConsole.IPowerConsoleWindow])
  14. $props = $consoleWindow.GetType().GetProperties([System.Reflection.BindingFlags]::Instance -bor `
  15. [System.Reflection.BindingFlags]::NonPublic)
  16. $prop = $props | ? { $_.Name -eq "ActiveHostInfo" } | select -first 1
  17. if ($prop -eq $null) { return }
  18. $hostInfo = $prop.GetValue($consoleWindow)
  19. if ($hostInfo -eq $null) { return }
  20. $history = $hostInfo.WpfConsole.InputHistory.History
  21. $lastCommand = $history | select -last 1
  22. if ($lastCommand)
  23. {
  24. $lastCommand = $lastCommand.Trim().ToLower()
  25. if ($lastCommand.StartsWith("install-package") -and $lastCommand.Contains("newtonsoft.json"))
  26. {
  27. $dte2.ItemOperations.Navigate($url) | Out-Null
  28. }
  29. }
  30. }
  31. else
  32. {
  33. # user is installing from VS NuGet dialog
  34. # get reference to the window, then smart output console provider
  35. # show webpage if messages in buffered console contains "installing...newtonsoft.json" in last operation
  36. $instanceField = [NuGet.Dialog.PackageManagerWindow].GetField("CurrentInstance", [System.Reflection.BindingFlags]::Static -bor `
  37. [System.Reflection.BindingFlags]::NonPublic)
  38. $consoleField = [NuGet.Dialog.PackageManagerWindow].GetField("_smartOutputConsoleProvider", [System.Reflection.BindingFlags]::Instance -bor `
  39. [System.Reflection.BindingFlags]::NonPublic)
  40. if ($instanceField -eq $null -or $consoleField -eq $null) { return }
  41. $instance = $instanceField.GetValue($null)
  42. if ($instance -eq $null) { return }
  43. $consoleProvider = $consoleField.GetValue($instance)
  44. if ($consoleProvider -eq $null) { return }
  45. $console = $consoleProvider.CreateOutputConsole($false)
  46. $messagesField = $console.GetType().GetField("_messages", [System.Reflection.BindingFlags]::Instance -bor `
  47. [System.Reflection.BindingFlags]::NonPublic)
  48. if ($messagesField -eq $null) { return }
  49. $messages = $messagesField.GetValue($console)
  50. if ($messages -eq $null) { return }
  51. $operations = $messages -split "=============================="
  52. $lastOperation = $operations | select -last 1
  53. if ($lastOperation)
  54. {
  55. $lastOperation = $lastOperation.ToLower()
  56. $lines = $lastOperation -split "`r`n"
  57. $installMatch = $lines | ? { $_.StartsWith("------- installing...newtonsoft.json ") } | select -first 1
  58. if ($installMatch)
  59. {
  60. $dte2.ItemOperations.Navigate($url) | Out-Null
  61. }
  62. }
  63. }
  64. }
  65. catch
  66. {
  67. # stop potential errors from bubbling up
  68. # worst case the splash page won't open
  69. }
  70. # yolo