Implement update check on startup
[ArchiSteamFarm.git] / packages / Newtonsoft.Json.8.0.1-beta1 / tools / install.ps1
blob0cebb5e8e9f897170124f6ce8bd439e7f85eca97
1 param($installPath, $toolsPath, $package, $project)
3 # open json.net splash page on package install
4 # don't open if json.net is installed as a dependency
6 try
8 $url = "http://www.newtonsoft.com/json/install?version=" + $package.Version
9 $dte2 = Get-Interface $dte ([EnvDTE80.DTE2])
11 if ($dte2.ActiveWindow.Caption -eq "Package Manager Console")
13 # user is installing from VS NuGet console
14 # get reference to the window, the console host and the input history
15 # show webpage if "install-package newtonsoft.json" was last input
17 $consoleWindow = $(Get-VSComponentModel).GetService([NuGetConsole.IPowerConsoleWindow])
19 $props = $consoleWindow.GetType().GetProperties([System.Reflection.BindingFlags]::Instance -bor `
20 [System.Reflection.BindingFlags]::NonPublic)
22 $prop = $props | ? { $_.Name -eq "ActiveHostInfo" } | select -first 1
23 if ($prop -eq $null) { return }
25 $hostInfo = $prop.GetValue($consoleWindow)
26 if ($hostInfo -eq $null) { return }
28 $history = $hostInfo.WpfConsole.InputHistory.History
30 $lastCommand = $history | select -last 1
32 if ($lastCommand)
34 $lastCommand = $lastCommand.Trim().ToLower()
35 if ($lastCommand.StartsWith("install-package") -and $lastCommand.Contains("newtonsoft.json"))
37 $dte2.ItemOperations.Navigate($url) | Out-Null
41 else
43 # user is installing from VS NuGet dialog
44 # get reference to the window, then smart output console provider
45 # show webpage if messages in buffered console contains "installing...newtonsoft.json" in last operation
47 $instanceField = [NuGet.Dialog.PackageManagerWindow].GetField("CurrentInstance", [System.Reflection.BindingFlags]::Static -bor `
48 [System.Reflection.BindingFlags]::NonPublic)
50 $consoleField = [NuGet.Dialog.PackageManagerWindow].GetField("_smartOutputConsoleProvider", [System.Reflection.BindingFlags]::Instance -bor `
51 [System.Reflection.BindingFlags]::NonPublic)
53 if ($instanceField -eq $null -or $consoleField -eq $null) { return }
55 $instance = $instanceField.GetValue($null)
57 if ($instance -eq $null) { return }
59 $consoleProvider = $consoleField.GetValue($instance)
60 if ($consoleProvider -eq $null) { return }
62 $console = $consoleProvider.CreateOutputConsole($false)
64 $messagesField = $console.GetType().GetField("_messages", [System.Reflection.BindingFlags]::Instance -bor `
65 [System.Reflection.BindingFlags]::NonPublic)
66 if ($messagesField -eq $null) { return }
68 $messages = $messagesField.GetValue($console)
69 if ($messages -eq $null) { return }
71 $operations = $messages -split "=============================="
73 $lastOperation = $operations | select -last 1
75 if ($lastOperation)
77 $lastOperation = $lastOperation.ToLower()
79 $lines = $lastOperation -split "`r`n"
81 $installMatch = $lines | ? { $_.StartsWith("------- installing...newtonsoft.json ") } | select -first 1
83 if ($installMatch)
85 $dte2.ItemOperations.Navigate($url) | Out-Null
90 catch
92 try
94 $pmPane = $dte2.ToolWindows.OutputWindow.OutputWindowPanes.Item("Package Manager")
96 $selection = $pmPane.TextDocument.Selection
97 $selection.StartOfDocument($false)
98 $selection.EndOfDocument($true)
100 if ($selection.Text.StartsWith("Attempting to gather dependencies information for package 'Newtonsoft.Json." + $package.Version + "'"))
102 # don't show on upgrade
103 if (!$selection.Text.Contains("Removed package"))
105 $dte2.ItemOperations.Navigate($url) | Out-Null
109 catch
111 # stop potential errors from bubbling up
112 # worst case the splash page won't open
116 # still yolo