Add Newtonsoft.Json NuGet package
[StratumLibrary.git] / packages / Newtonsoft.Json.7.0.1 / tools / install.ps1
1 param($installPath, $toolsPath, $package, $project)\r
2 \r
3 # open json.net splash page on package install\r
4 # don't open if json.net is installed as a dependency\r
5 \r
6 try\r
7 {\r
8   $url = "http://www.newtonsoft.com/json/install?version=" + $package.Version\r
9   $dte2 = Get-Interface $dte ([EnvDTE80.DTE2])\r
10 \r
11   if ($dte2.ActiveWindow.Caption -eq "Package Manager Console")\r
12   {\r
13     # user is installing from VS NuGet console\r
14     # get reference to the window, the console host and the input history\r
15     # show webpage if "install-package newtonsoft.json" was last input\r
16 \r
17     $consoleWindow = $(Get-VSComponentModel).GetService([NuGetConsole.IPowerConsoleWindow])\r
18 \r
19     $props = $consoleWindow.GetType().GetProperties([System.Reflection.BindingFlags]::Instance -bor `\r
20       [System.Reflection.BindingFlags]::NonPublic)\r
21 \r
22     $prop = $props | ? { $_.Name -eq "ActiveHostInfo" } | select -first 1\r
23     if ($prop -eq $null) { return }\r
24   \r
25     $hostInfo = $prop.GetValue($consoleWindow)\r
26     if ($hostInfo -eq $null) { return }\r
27 \r
28     $history = $hostInfo.WpfConsole.InputHistory.History\r
29 \r
30     $lastCommand = $history | select -last 1\r
31 \r
32     if ($lastCommand)\r
33     {\r
34       $lastCommand = $lastCommand.Trim().ToLower()\r
35       if ($lastCommand.StartsWith("install-package") -and $lastCommand.Contains("newtonsoft.json"))\r
36       {\r
37         $dte2.ItemOperations.Navigate($url) | Out-Null\r
38       }\r
39     }\r
40   }\r
41   else\r
42   {\r
43     # user is installing from VS NuGet dialog\r
44     # get reference to the window, then smart output console provider\r
45     # show webpage if messages in buffered console contains "installing...newtonsoft.json" in last operation\r
46 \r
47     $instanceField = [NuGet.Dialog.PackageManagerWindow].GetField("CurrentInstance", [System.Reflection.BindingFlags]::Static -bor `\r
48       [System.Reflection.BindingFlags]::NonPublic)\r
49 \r
50     $consoleField = [NuGet.Dialog.PackageManagerWindow].GetField("_smartOutputConsoleProvider", [System.Reflection.BindingFlags]::Instance -bor `\r
51       [System.Reflection.BindingFlags]::NonPublic)\r
52 \r
53     if ($instanceField -eq $null -or $consoleField -eq $null) { return }\r
54 \r
55     $instance = $instanceField.GetValue($null)\r
56 \r
57     if ($instance -eq $null) { return }\r
58 \r
59     $consoleProvider = $consoleField.GetValue($instance)\r
60     if ($consoleProvider -eq $null) { return }\r
61 \r
62     $console = $consoleProvider.CreateOutputConsole($false)\r
63 \r
64     $messagesField = $console.GetType().GetField("_messages", [System.Reflection.BindingFlags]::Instance -bor `\r
65       [System.Reflection.BindingFlags]::NonPublic)\r
66     if ($messagesField -eq $null) { return }\r
67 \r
68     $messages = $messagesField.GetValue($console)\r
69     if ($messages -eq $null) { return }\r
70 \r
71     $operations = $messages -split "=============================="\r
72 \r
73     $lastOperation = $operations | select -last 1\r
74 \r
75     if ($lastOperation)\r
76     {\r
77       $lastOperation = $lastOperation.ToLower()\r
78 \r
79       $lines = $lastOperation -split "`r`n"\r
80 \r
81       $installMatch = $lines | ? { $_.StartsWith("------- installing...newtonsoft.json ") } | select -first 1\r
82 \r
83       if ($installMatch)\r
84       {\r
85         $dte2.ItemOperations.Navigate($url) | Out-Null\r
86       }\r
87     }\r
88   }\r
89 }\r
90 catch\r
91 {\r
92   try\r
93   {\r
94     $pmPane = $dte2.ToolWindows.OutputWindow.OutputWindowPanes.Item("Package Manager")\r
95 \r
96     $selection = $pmPane.TextDocument.Selection\r
97     $selection.StartOfDocument($false)\r
98     $selection.EndOfDocument($true)\r
99 \r
100     if ($selection.Text.StartsWith("Attempting to gather dependencies information for package 'Newtonsoft.Json." + $package.Version + "'"))\r
101     {\r
102       $dte2.ItemOperations.Navigate($url) | Out-Null\r
103     }\r
104   }\r
105   catch\r
106   {\r
107     # stop potential errors from bubbling up\r
108     # worst case the splash page won't open  \r
109   }\r
110 }\r
111 \r
112 # still yolo