UltraScan III
us_license_t.cpp
Go to the documentation of this file.
1 #include <QtCore>
3 
4 #include "us_license_t.h"
5 #include "us_settings.h"
6 #include "us_defines.h"
7 
8 
9 int US_License_t::isValid( QString& ErrorMessage, const QStringList& newLicense )
10 {
11  QStringList license;
12 
13  if ( newLicense.size() == 0 )
14  license = US_Settings::license();
15  else
16  license = newLicense;
17 
18  if ( license.size() < 12 )
19  {
20  ErrorMessage = QString( qApp->translate( "UltraScan",
21  "You have not yet registered your copy of UltraScan.\n"
22  "Click on 'Register' to register UltraScan\n"
23  "for the %1 platform and %2 Operating System." ) )
24  .arg( TITLE, OS_TITLE );
25 
26  return Missing;
27  }
28 
29  QString lastname = license.value( 0 );
30  QString firstname = license.value( 1 );
31  QString company = license.value( 2 );
32  QString address = license.value( 3 );
33  QString city = license.value( 4 );
34  QString state = license.value( 5 );
35  QString zip = license.value( 6 );
36  QString phone = license.value( 7 );
37  QString email = license.value( 8 );
38  QString platform = license.value( 9 );
39  QString opSys = license.value( 10 );
40  QString version = license.value( 11 );
41 
42  QString validation = "";
43  QString expiration = "";
44 
45  if ( license.size() > 13 )
46  {
47  validation = license.value( 12 );
48  expiration = license.value( 13 );
49  }
50 
51  if ( platform != PLATFORM )
52  {
53  ErrorMessage = QString( qApp->translate( "UltraScan",
54  "You are running UltraScan on a %1 platform,\n"
55  "but your registration is issued for the %2 platform\n\n"
56  "You will have to update your registration before\n"
57  "proceeding. Click on 'Register' to start the process\n"
58  "for the %3 platform." ) )
59  .arg( TITLE, platform, TITLE );
60 
61  return BadPlatform;
62  }
63 
64  if ( opSys != OS )
65  {
66  ErrorMessage = QString( qApp->translate( "UltraScan",
67  "You are running UltraScan with a %1 operating system,\n"
68  "but your registration is issued for the %2 operating system\n\n"
69  "You will have to update your registration before\n"
70  "proceeding. Click on 'Register' to start the process\n"
71  "for a %3 operating system." ) )
72  .arg( OS_TITLE, opSys, OS_TITLE );
73 
74  return BadOS;
75  }
76 
77  if ( license.size() == 12 )
78  {
79  ErrorMessage = QString( qApp->translate( "UltraScan",
80  "Your UltraScan registration is pending.\n"
81  "Please respond to the email sent to complete the process." ) );
82 
83  return Pending;
84  }
85 
86  QString license_string = expiration + email;
87  QString calculation = "";
88  QString str;
89  for ( int i = 0; i < license_string.size(); i++ )
90  calculation += str.sprintf( "%X", license_string[ i ].unicode() );
91 
92  calculation.truncate(24);
93 
94  if ( calculation != validation )
95  {
96  ErrorMessage = qApp->translate( "UltraScan",
97  "The registration is invalid.\n"
98  "You will have to update your registration before\n"
99  "proceeding. Click on 'Register' to begin the registration\n" )
100  + "\n" + validation + "\n" + calculation;
101 
102  return Invalid;
103  }
104 
105  if ( QDate::currentDate() > QDate::fromString( expiration ) )
106  {
107  ErrorMessage = qApp->translate( "UltraScan",
108  "The registration is expired.\n"
109  "You will have to update your registration before\n"
110  "proceeding. Click on 'Update / Renew' to continue.\n" );
111 
112  return Expired;
113  }
114 
115  return OK;
116 }
117