Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/packages/Newtonsoft.Json.8.0.1/tools/install.ps1

Parent Directory Parent Directory | Revision Log Revision Log


Revision 58 - (hide annotations) (download)
Sun Aug 4 08:09:58 2019 UTC (4 years, 10 months ago) by momen2009
File size: 3852 byte(s)
[kakuretter]投稿できないようになってしまったため、修正。
1 momen2009 58 param($installPath, $toolsPath, $package, $project)
2    
3     # open json.net splash page on package install
4     # don't open if json.net is installed as a dependency
5    
6     try
7     {
8     $url = "http://www.newtonsoft.com/json/install?version=" + $package.Version
9     $dte2 = Get-Interface $dte ([EnvDTE80.DTE2])
10    
11     if ($dte2.ActiveWindow.Caption -eq "Package Manager Console")
12     {
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
16    
17     $consoleWindow = $(Get-VSComponentModel).GetService([NuGetConsole.IPowerConsoleWindow])
18    
19     $props = $consoleWindow.GetType().GetProperties([System.Reflection.BindingFlags]::Instance -bor `
20     [System.Reflection.BindingFlags]::NonPublic)
21    
22     $prop = $props | ? { $_.Name -eq "ActiveHostInfo" } | select -first 1
23     if ($prop -eq $null) { return }
24    
25     $hostInfo = $prop.GetValue($consoleWindow)
26     if ($hostInfo -eq $null) { return }
27    
28     $history = $hostInfo.WpfConsole.InputHistory.History
29    
30     $lastCommand = $history | select -last 1
31    
32     if ($lastCommand)
33     {
34     $lastCommand = $lastCommand.Trim().ToLower()
35     if ($lastCommand.StartsWith("install-package") -and $lastCommand.Contains("newtonsoft.json"))
36     {
37     $dte2.ItemOperations.Navigate($url) | Out-Null
38     }
39     }
40     }
41     else
42     {
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
46    
47     $instanceField = [NuGet.Dialog.PackageManagerWindow].GetField("CurrentInstance", [System.Reflection.BindingFlags]::Static -bor `
48     [System.Reflection.BindingFlags]::NonPublic)
49    
50     $consoleField = [NuGet.Dialog.PackageManagerWindow].GetField("_smartOutputConsoleProvider", [System.Reflection.BindingFlags]::Instance -bor `
51     [System.Reflection.BindingFlags]::NonPublic)
52    
53     if ($instanceField -eq $null -or $consoleField -eq $null) { return }
54    
55     $instance = $instanceField.GetValue($null)
56    
57     if ($instance -eq $null) { return }
58    
59     $consoleProvider = $consoleField.GetValue($instance)
60     if ($consoleProvider -eq $null) { return }
61    
62     $console = $consoleProvider.CreateOutputConsole($false)
63    
64     $messagesField = $console.GetType().GetField("_messages", [System.Reflection.BindingFlags]::Instance -bor `
65     [System.Reflection.BindingFlags]::NonPublic)
66     if ($messagesField -eq $null) { return }
67    
68     $messages = $messagesField.GetValue($console)
69     if ($messages -eq $null) { return }
70    
71     $operations = $messages -split "=============================="
72    
73     $lastOperation = $operations | select -last 1
74    
75     if ($lastOperation)
76     {
77     $lastOperation = $lastOperation.ToLower()
78    
79     $lines = $lastOperation -split "`r`n"
80    
81     $installMatch = $lines | ? { $_.StartsWith("------- installing...newtonsoft.json ") } | select -first 1
82    
83     if ($installMatch)
84     {
85     $dte2.ItemOperations.Navigate($url) | Out-Null
86     }
87     }
88     }
89     }
90     catch
91     {
92     try
93     {
94     $pmPane = $dte2.ToolWindows.OutputWindow.OutputWindowPanes.Item("Package Manager")
95    
96     $selection = $pmPane.TextDocument.Selection
97     $selection.StartOfDocument($false)
98     $selection.EndOfDocument($true)
99    
100     if ($selection.Text.StartsWith("Attempting to gather dependencies information for package 'Newtonsoft.Json." + $package.Version + "'"))
101     {
102     # don't show on upgrade
103     if (!$selection.Text.Contains("Removed package"))
104     {
105     $dte2.ItemOperations.Navigate($url) | Out-Null
106     }
107     }
108     }
109     catch
110     {
111     # stop potential errors from bubbling up
112     # worst case the splash page won't open
113     }
114     }
115    
116     # still yolo

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26