1 |
#Region "Microsoft.VisualBasic::a1c14c20f2acf914567e924bd797f5b1, Microsoft.VisualBasic.Core\ApplicationServices\VBDev\Signature\LicenseMgr.vb"
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
#End Region
|
45 |
|
46 |
Imports System.Runtime.CompilerServices
|
47 |
Imports System.Text
|
48 |
Imports System.Text.RegularExpressions
|
49 |
Imports Microsoft.VisualBasic.Language
|
50 |
Imports Microsoft.VisualBasic.Language.UnixBash
|
51 |
Imports Microsoft.VisualBasic.Linq
|
52 |
Imports Microsoft.VisualBasic.Text.Xml.Models
|
53 |
|
54 |
Namespace ApplicationServices.Development
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
Public Module LicenseMgr
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
Public ReadOnly Property Template As LicenseInfo
|
66 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
67 |
Get
|
68 |
Return New LicenseInfo With {
|
69 |
.Authors = {
|
70 |
New NamedValue With {
|
71 |
.name = "asuka",
|
72 |
.text = "amethyst.asuka@gcmodeller.org"
|
73 |
}
|
74 |
},
|
75 |
.Brief = "Permission is hereby granted, free Of charge, To any person obtaining a copy
|
76 |
Of this software and associated documentation files (the ""Software""), To deal
|
77 |
In the Software without restriction, including without limitation the rights
|
78 |
To use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
79 |
copies Of the Software, and To permit persons To whom the Software is
|
80 |
furnished To do so, subject To the following conditions:
|
81 |
|
82 |
The above copyright notice and this permission notice shall be included in
|
83 |
all copies or substantial portions Of the Software.
|
84 |
|
85 |
THE SOFTWARE IS PROVIDED ""As Is"", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
86 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
87 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
88 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
89 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
90 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
91 |
THE SOFTWARE.",
|
92 |
.Copyright = "Copyright (c) 2016 amethyst.asuka@gcmodeller.org",
|
93 |
.Title = "The MIT License (MIT)"
|
94 |
}
|
95 |
End Get
|
96 |
End Property
|
97 |
|
98 |
Sub New()
|
99 |
Call Template.GetXml.SaveTo(App.HOME & "/License.Template.Xml")
|
100 |
End Sub
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
Public Property Ignores As String() = {".+\.Designer\.vb", "AssemblyInfo\.vb"}
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
<Extension>
|
119 |
Public Function Insert(src As String, info As LicenseInfo, rootDir$) As Boolean
|
120 |
Dim file As String = PathExtensions.RelativePath(rootDir, src, appendParent:=False)
|
121 |
Dim [in] As String = src.ReadAllText
|
122 |
Dim path As String = src
|
123 |
|
124 |
src = Trim([in])
|
125 |
src = RemoveRegion(src)
|
126 |
src = AddRegion(src, info, file)
|
127 |
|
128 |
Try
|
129 |
Return src.SaveTo(path, Encoding.UTF8)
|
130 |
Catch ex As Exception
|
131 |
Dim backup As String = src & ".bak"
|
132 |
|
133 |
ex = New Exception(path, ex)
|
134 |
|
135 |
Call [in].SaveTo(backup, Encoding.UTF8)
|
136 |
Call App.LogException(ex)
|
137 |
|
138 |
Return False
|
139 |
End Try
|
140 |
End Function
|
141 |
|
142 |
Public Function RemoveRegion(src As String) As String
|
143 |
Dim region As String = Regex.Match(src, LicenseMgr.Region, RegexOptions.Singleline).Value
|
144 |
|
145 |
If Not String.IsNullOrEmpty(region) Then
|
146 |
src = src.Replace(region, "")
|
147 |
src = src.Trim(vbCr, vbLf)
|
148 |
End If
|
149 |
|
150 |
Return src
|
151 |
End Function
|
152 |
|
153 |
Public Function AddRegion(src As String, info As LicenseInfo, file As String) As String
|
154 |
Dim sb As New StringBuilder
|
155 |
|
156 |
Call sb.AppendLine($"#Region ""Microsoft.VisualBasic::{SecurityString.GetMd5Hash(src)}, {file}""")
|
157 |
Call sb.AppendLine()
|
158 |
Call sb.AppendLine(" ' Author:")
|
159 |
Call sb.AppendLine(" ' ")
|
160 |
|
161 |
For Each author As NamedValue In info.Authors.SafeQuery
|
162 |
Call sb.AppendLine($" ' {author.name} ({author.text})")
|
163 |
Next
|
164 |
Call sb.AppendLine(" ' ")
|
165 |
Call sb.AppendLine(" ' " & info.Copyright)
|
166 |
Call sb.AppendLine(" ' ")
|
167 |
Call sb.AppendLine(" ' ")
|
168 |
Call sb.AppendLine(" ' " & info.Title)
|
169 |
Call sb.AppendLine(" ' ")
|
170 |
|
171 |
For Each line As String In info.Brief.LineTokens
|
172 |
Call sb.AppendLine(" ' " & line)
|
173 |
Next
|
174 |
|
175 |
sb.AppendLine()
|
176 |
sb.AppendLine()
|
177 |
sb.AppendLine()
|
178 |
sb.AppendLine(" ' /********************************************************************************/")
|
179 |
sb.AppendLine()
|
180 |
sb.AppendLine(" ' Summaries:")
|
181 |
sb.AppendLine()
|
182 |
|
183 |
For Each line As String In VBCodeSignature.SummaryModules(vb:=src).LineTokens
|
184 |
Call sb.AppendLine(" ' " & line)
|
185 |
Next
|
186 |
|
187 |
sb.AppendLine(" ' /********************************************************************************/")
|
188 |
Call sb.AppendLine()
|
189 |
Call sb.AppendLine($"#End Region")
|
190 |
Call sb.AppendLine()
|
191 |
|
192 |
Call sb.AppendLine(src)
|
193 |
|
194 |
Return sb.ToString
|
195 |
End Function
|
196 |
|
197 |
Const Region As String = "^#Region "".+?\.vb"".+?#End Region"
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
Public Function Inserts(info As LicenseInfo, rootDir$) As String()
|
205 |
Dim fails As New List(Of String)
|
206 |
|
207 |
For Each vb As String In ls - l - r - "*.vb" <= rootDir
|
208 |
Dim skip As Boolean = False
|
209 |
|
210 |
|
211 |
For Each ig As String In LicenseMgr.Ignores
|
212 |
If Regex.Match(vb, ig, RegexICSng).Success Then
|
213 |
skip = True
|
214 |
Exit For
|
215 |
End If
|
216 |
Next
|
217 |
|
218 |
If skip Then
|
219 |
Continue For
|
220 |
End If
|
221 |
|
222 |
If Not vb.Insert(info, rootDir) Then
|
223 |
fails += vb
|
224 |
End If
|
225 |
Next
|
226 |
|
227 |
Return fails
|
228 |
End Function
|
229 |
End Module
|
230 |
End Namespace
|