| 1 |
#Region "Microsoft.VisualBasic::d769d01cfe5863149e541557a9abb7e8, Microsoft.VisualBasic.Core\ApplicationServices\VBDev\ApplicationInfoUtils.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 |
#End Region
|
| 44 |
|
| 45 |
Imports System.Reflection
|
| 46 |
Imports System.Runtime.CompilerServices
|
| 47 |
Imports System.Runtime.InteropServices
|
| 48 |
|
| 49 |
Namespace ApplicationServices.Development
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
Public Module ApplicationInfoUtils
|
| 58 |
|
| 59 |
<Extension>
|
| 60 |
Public Function FromAssembly(assm As Assembly) As AssemblyInfo
|
| 61 |
Return New AssemblyInfo With {
|
| 62 |
.AssemblyCompany = GetCompanyName(assm),
|
| 63 |
.AssemblyFileVersion = GetProductVersion(assm),
|
| 64 |
.AssemblyProduct = GetProductName(assm),
|
| 65 |
.AssemblyCopyright = GetCopyRightsDetail(assm),
|
| 66 |
.AssemblyTitle = GetProductTitle(assm),
|
| 67 |
.AssemblyDescription = GetProductDescription(assm),
|
| 68 |
.Guid = GetGuid(assm)
|
| 69 |
}
|
| 70 |
End Function
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
| 77 |
Public Function VBCore() As AssemblyInfo
|
| 78 |
Return GetType(ApplicationInfoUtils).Assembly.FromAssembly
|
| 79 |
End Function
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
Public Function CurrentExe() As AssemblyInfo
|
| 86 |
Try
|
| 87 |
Return Assembly.LoadFile(App.ExecutablePath).FromAssembly
|
| 88 |
Catch ex As Exception
|
| 89 |
ex = New Exception(App.ExecutablePath, ex)
|
| 90 |
Call App.LogException(ex)
|
| 91 |
Return Nothing
|
| 92 |
End Try
|
| 93 |
End Function
|
| 94 |
|
| 95 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
| 96 |
<Extension>
|
| 97 |
Public Function FromTypeModule(type As Type) As AssemblyInfo
|
| 98 |
Return type.Assembly.FromAssembly
|
| 99 |
End Function
|
| 100 |
|
| 101 |
Public Function GetGuid(assm As Assembly) As String
|
| 102 |
If assm IsNot Nothing Then
|
| 103 |
Dim attrs = assm.GetCustomAttributes(GetType(GuidAttribute), False)
|
| 104 |
|
| 105 |
If attrs.IsNullOrEmpty Then
|
| 106 |
Return ""
|
| 107 |
Else
|
| 108 |
Return DirectCast(attrs(Scan0), GuidAttribute).Value
|
| 109 |
End If
|
| 110 |
Else
|
| 111 |
Return ""
|
| 112 |
End If
|
| 113 |
End Function
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
Public Function GetCompanyName(assm As Assembly) As String
|
| 121 |
If assm IsNot Nothing Then
|
| 122 |
Dim companyName As String = ""
|
| 123 |
Dim customAttributes As Object() = assm.GetCustomAttributes(GetType(AssemblyCompanyAttribute), False)
|
| 124 |
If (customAttributes IsNot Nothing) AndAlso (customAttributes.Length > 0) Then
|
| 125 |
companyName = DirectCast(customAttributes(0), AssemblyCompanyAttribute).Company
|
| 126 |
End If
|
| 127 |
If String.IsNullOrEmpty(companyName) Then
|
| 128 |
companyName = String.Empty
|
| 129 |
End If
|
| 130 |
|
| 131 |
Return companyName
|
| 132 |
Else
|
| 133 |
Return ""
|
| 134 |
End If
|
| 135 |
End Function
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
Public Function GetProductVersion(assembly As Assembly) As String
|
| 143 |
If assembly IsNot Nothing Then
|
| 144 |
Dim productVersion As String = ""
|
| 145 |
Dim customAttributes As Object() = assembly.GetCustomAttributes(GetType(AssemblyVersionAttribute), False)
|
| 146 |
If (customAttributes IsNot Nothing) AndAlso (customAttributes.Length > 0) Then
|
| 147 |
productVersion = DirectCast(customAttributes(0), AssemblyVersionAttribute).Version
|
| 148 |
End If
|
| 149 |
If String.IsNullOrEmpty(productVersion) Then
|
| 150 |
productVersion = String.Empty
|
| 151 |
End If
|
| 152 |
Return productVersion
|
| 153 |
Else
|
| 154 |
Return ""
|
| 155 |
End If
|
| 156 |
End Function
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
Public Function GetProductName(assembly As Assembly) As String
|
| 164 |
If assembly IsNot Nothing Then
|
| 165 |
Dim productName As String = ""
|
| 166 |
Dim customAttributes As Object() = assembly.GetCustomAttributes(GetType(AssemblyProductAttribute), False)
|
| 167 |
If (customAttributes IsNot Nothing) AndAlso (customAttributes.Length > 0) Then
|
| 168 |
productName = DirectCast(customAttributes(0), AssemblyProductAttribute).Product
|
| 169 |
End If
|
| 170 |
If String.IsNullOrEmpty(productName) Then
|
| 171 |
productName = String.Empty
|
| 172 |
End If
|
| 173 |
Return productName
|
| 174 |
Else
|
| 175 |
Return ""
|
| 176 |
End If
|
| 177 |
End Function
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
Public Function GetCopyRightsDetail(assembly As Assembly) As String
|
| 185 |
If assembly IsNot Nothing Then
|
| 186 |
Dim copyrightsDetail As String = ""
|
| 187 |
Dim customAttributes As Object() = assembly.GetCustomAttributes(GetType(AssemblyCopyrightAttribute), False)
|
| 188 |
If (customAttributes IsNot Nothing) AndAlso (customAttributes.Length > 0) Then
|
| 189 |
copyrightsDetail = DirectCast(customAttributes(0), AssemblyCopyrightAttribute).Copyright
|
| 190 |
End If
|
| 191 |
If String.IsNullOrEmpty(copyrightsDetail) Then
|
| 192 |
copyrightsDetail = String.Empty
|
| 193 |
End If
|
| 194 |
Return copyrightsDetail
|
| 195 |
Else
|
| 196 |
Return ""
|
| 197 |
End If
|
| 198 |
End Function
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
Public Function GetProductTitle(assembly As Assembly) As String
|
| 206 |
If assembly IsNot Nothing Then
|
| 207 |
Dim productTitle As String = ""
|
| 208 |
Dim customAttributes As Object() = assembly.GetCustomAttributes(GetType(AssemblyTitleAttribute), False)
|
| 209 |
If (customAttributes IsNot Nothing) AndAlso (customAttributes.Length > 0) Then
|
| 210 |
productTitle = DirectCast(customAttributes(0), AssemblyTitleAttribute).Title
|
| 211 |
End If
|
| 212 |
If String.IsNullOrEmpty(productTitle) Then
|
| 213 |
productTitle = String.Empty
|
| 214 |
End If
|
| 215 |
Return productTitle
|
| 216 |
Else
|
| 217 |
Return ""
|
| 218 |
End If
|
| 219 |
End Function
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
Public Function GetProductDescription(assembly As Assembly) As String
|
| 227 |
If assembly IsNot Nothing Then
|
| 228 |
Dim productDescription As String = ""
|
| 229 |
Dim customAttributes As Object() = assembly.GetCustomAttributes(GetType(AssemblyDescriptionAttribute), False)
|
| 230 |
If (customAttributes IsNot Nothing) AndAlso (customAttributes.Length > 0) Then
|
| 231 |
productDescription = DirectCast(customAttributes(0), AssemblyDescriptionAttribute).Description
|
| 232 |
End If
|
| 233 |
If String.IsNullOrEmpty(productDescription) Then
|
| 234 |
productDescription = String.Empty
|
| 235 |
End If
|
| 236 |
Return productDescription
|
| 237 |
Else
|
| 238 |
Return ""
|
| 239 |
End If
|
| 240 |
End Function
|
| 241 |
End Module
|
| 242 |
End Namespace
|