@@ -41,7 +41,10 @@ source product.
41414242 */
4343using System ;
44+ using System . IO ;
4445using System . Reflection ;
46+ using iTextSharp . text . log ;
47+ using Versions . Attributes ;
4548
4649namespace iTextSharp . text {
4750
@@ -72,22 +75,60 @@ public sealed class Version {
7275 * This String contains the version number of this iText release.
7376 * For debugging purposes, we request you NOT to change this constant.
7477 */
75- static private String release = "5.5.12 " ;
78+ static private String release = "5.5.13 " ;
7679
7780 /**
7881 * This String contains the iText version as shown in the producer line.
7982 * iText is a product developed by iText Group NV.
8083 * iText Group requests that you retain the iText producer line
8184 * in every PDF that is created or manipulated using iText.
8285 */
83- private String iTextVersion = iText + " " + release + " \u00a9 2000-2017 iText Group NV" ;
86+ private String iTextVersion = iText + " " + release + " \u00a9 2000-2018 iText Group NV" ;
8487
8588 /**
8689 * The license key.
8790 */
8891 private String key = null ;
89-
90- /**
92+
93+ private static Type GetLicenseKeyClass ( ) {
94+ String licenseKeyClassPartialName = "iText.License.LicenseKey, itext.licensekey" ;
95+ String licenseKeyClassFullName = null ;
96+
97+ object [ ] keyVersionAttrs = typeof ( Version ) . Assembly . GetCustomAttributes ( typeof ( KeyVersionAttribute ) , false ) ;
98+ object keyVersionAttr = keyVersionAttrs . Length > 0 ? keyVersionAttrs [ 0 ] : null ;
99+ if ( keyVersionAttr is KeyVersionAttribute ) {
100+ String keyVersion = ( ( KeyVersionAttribute ) keyVersionAttr ) . KeyVersion ;
101+ String format = "{0}, Version={1}, Culture=neutral, PublicKeyToken=8354ae6d2174ddca" ;
102+ licenseKeyClassFullName = String . Format ( format , licenseKeyClassPartialName , keyVersion ) ;
103+ }
104+
105+ Type type = null ;
106+ if ( licenseKeyClassFullName != null ) {
107+ String fileLoadExceptionMessage = null ;
108+ try {
109+ type = System . Type . GetType ( licenseKeyClassFullName ) ;
110+ }
111+ catch ( FileLoadException fileLoadException ) {
112+ fileLoadExceptionMessage = fileLoadException . Message ;
113+ }
114+
115+ if ( fileLoadExceptionMessage != null ) {
116+ ILogger logger = LoggerFactory . GetLogger ( typeof ( Version ) ) ;
117+ try {
118+ type = System . Type . GetType ( licenseKeyClassPartialName ) ;
119+ }
120+ catch {
121+ // ignore
122+ }
123+ if ( type == null ) {
124+ logger . Error ( fileLoadExceptionMessage ) ;
125+ }
126+ }
127+ }
128+ return type ;
129+ }
130+
131+ /**
91132 * Gets an instance of the iText version that is currently used.
92133 * Note that iText Group requests that you retain the iText producer line
93134 * in every PDF that is created or manipulated using iText.
@@ -97,41 +138,44 @@ public static Version GetInstance() {
97138 version = new Version ( ) ;
98139 lock ( version ) {
99140 try {
100- Type type = Type . GetType ( "iTextSharp.license.LicenseKey, itextsharp.LicenseKey" ) ;
101- MethodInfo m = type . GetMethod ( "GetLicenseeInfo" ) ;
102- String [ ] info = ( String [ ] ) m . Invoke ( Activator . CreateInstance ( type ) , null ) ;
103- if ( info [ 3 ] != null && info [ 3 ] . Trim ( ) . Length > 0 ) {
104- version . key = info [ 3 ] ;
105- } else {
106- version . key = "Trial version " ;
107- if ( info [ 5 ] == null ) {
108- version . key += "unauthorised" ;
109- } else {
110- version . key += info [ 5 ] ;
111- }
112- }
113- if ( info [ 4 ] != null && info [ 4 ] . Trim ( ) . Length > 0 ) {
114- version . iTextVersion = info [ 4 ] ;
115- } else if ( info [ 2 ] != null && info [ 2 ] . Trim ( ) . Length > 0 ) {
116- version . iTextVersion += " (" + info [ 2 ] ;
117- if ( ! version . key . ToLower ( ) . StartsWith ( "trial" ) ) {
118- version . iTextVersion += "; licensed version)" ;
119- } else {
120- version . iTextVersion += "; " + version . key + ")" ;
121- }
122- } else if ( info [ 0 ] != null && info [ 0 ] . Trim ( ) . Length > 0 ) {
123- // fall back to contact name, if company name is unavailable
124- version . iTextVersion += " (" + info [ 0 ] ;
125- if ( ! version . key . ToLower ( ) . StartsWith ( "trial" ) ) {
126- // we shouldn't have a licensed version without company name,
127- // but let's account for it anyway
128- version . iTextVersion += "; licensed version)" ;
129- } else {
130- version . iTextVersion += "; " + version . key + ")" ;
131- }
132- } else {
133- throw new Exception ( ) ;
134- }
141+ Type type = GetLicenseKeyClass ( ) ;
142+ Type [ ] cArg = new Type [ ] { typeof ( String ) } ;
143+ MethodInfo m = type . GetMethod ( "GetLicenseeInfoForVersion" , cArg ) ;
144+ String coreVersion = release ;
145+ Object [ ] args = new Object [ ] { coreVersion } ;
146+ String [ ] info = ( String [ ] ) m . Invoke ( Activator . CreateInstance ( type ) , args ) ;
147+ if ( info [ 3 ] != null && info [ 3 ] . Trim ( ) . Length > 0 ) {
148+ version . key = info [ 3 ] ;
149+ } else {
150+ version . key = "Trial version " ;
151+ if ( info [ 5 ] == null ) {
152+ version . key += "unauthorised" ;
153+ } else {
154+ version . key += info [ 5 ] ;
155+ }
156+ }
157+ if ( info [ 4 ] != null && info [ 4 ] . Trim ( ) . Length > 0 ) {
158+ version . iTextVersion = info [ 4 ] ;
159+ } else if ( info [ 2 ] != null && info [ 2 ] . Trim ( ) . Length > 0 ) {
160+ version . iTextVersion += " (" + info [ 2 ] ;
161+ if ( ! version . key . ToLower ( ) . StartsWith ( "trial" ) ) {
162+ version . iTextVersion += "; licensed version)" ;
163+ } else {
164+ version . iTextVersion += "; " + version . key + ")" ;
165+ }
166+ } else if ( info [ 0 ] != null && info [ 0 ] . Trim ( ) . Length > 0 ) {
167+ // fall back to contact name, if company name is unavailable
168+ version . iTextVersion += " (" + info [ 0 ] ;
169+ if ( ! version . key . ToLower ( ) . StartsWith ( "trial" ) ) {
170+ // we shouldn't have a licensed version without company name,
171+ // but let's account for it anyway
172+ version . iTextVersion += "; licensed version)" ;
173+ } else {
174+ version . iTextVersion += "; " + version . key + ")" ;
175+ }
176+ } else {
177+ throw new Exception ( ) ;
178+ }
135179 } catch ( Exception ) {
136180 version . iTextVersion += AGPL ;
137181 }
0 commit comments