#5657 Remove SerialKey::m_valid

This commit is contained in:
Andrew Nelless 2016-10-17 17:08:26 +01:00
parent c7dc198d82
commit 8b4d7abfb0
4 changed files with 934 additions and 950 deletions

View File

@ -77,10 +77,18 @@ void ActivationDialog::accept()
return;
}
if (m_subscriptionManager->activeEdition() != kUnregistered) {
Edition edition = m_subscriptionManager->activeEdition();
if (edition != kUnregistered) {
if (m_subscriptionManager->serialKey().isTrial()) {
message.information(this, "Thanks!",
tr("Thanks for trying %1!").arg
(m_subscriptionManager->getEditionName(edition)));
}
else {
message.information(this, "Activated!",
tr("Thanks for activating %1!").arg
(m_subscriptionManager->activeEditionName()));
(m_subscriptionManager->getEditionName(edition)));
}
}
QDialog::accept();

View File

@ -548,7 +548,7 @@ void MainWindow::startSynergy()
args << "--name" << getScreenName();
if (!appConfig().serialKey().isEmpty()) {
args << "--serial-key " << appConfig().serialKey();
args << "--serial-key" << appConfig().serialKey();
}
if (desktopMode)

View File

@ -33,8 +33,7 @@ SerialKey::SerialKey(Edition edition):
m_warnTime(ULLONG_MAX),
m_expireTime(ULLONG_MAX),
m_edition(edition),
m_trial(false),
m_valid(true)
m_trial(false)
{
}
@ -43,47 +42,26 @@ SerialKey::SerialKey(std::string serial) :
m_warnTime(0),
m_expireTime(0),
m_edition(kBasic),
m_trial(true),
m_valid(false)
m_trial(true)
{
string plainText = decode(serial);
bool valid = false;
if (!plainText.empty()) {
parse(plainText);
valid = parse(plainText);
}
if (!m_valid) {
if (!valid) {
throw std::runtime_error ("Invalid serial key");
}
}
bool
SerialKey::isValid(time_t currentTime) const
{
bool result = false;
if (m_valid) {
if (m_trial) {
if (currentTime < m_expireTime) {
result = true;
}
}
else {
result = true;
}
}
return result;
}
bool
SerialKey::isExpiring(time_t currentTime) const
{
bool result = false;
if (m_valid) {
if (m_warnTime <= currentTime && currentTime < m_expireTime) {
result = true;
}
}
return result;
}
@ -93,11 +71,10 @@ SerialKey::isExpired(time_t currentTime) const
{
bool result = false;
if (m_valid) {
if (m_expireTime <= currentTime) {
result = true;
}
}
return result;
}
@ -209,13 +186,13 @@ SerialKey::decode(const std::string& serial)
return output;
}
void
bool
SerialKey::parse(std::string plainSerial)
{
string parityStart = plainSerial.substr(0, 1);
string parityEnd = plainSerial.substr(plainSerial.length() - 1, 1);
m_valid = false;
bool valid = false;
// check for parity chars { and }, record parity result, then remove them.
if (parityStart == "{" && parityEnd == "}") {
@ -247,7 +224,7 @@ SerialKey::parse(std::string plainSerial)
m_company = parts.at(5);
sscanf(parts.at(6).c_str(), "%lld", &m_warnTime);
sscanf(parts.at(7).c_str(), "%lld", &m_expireTime);
m_valid = true;
valid = true;
}
else if ((parts.size() == 9)
&& (parts.at(0).find("v2") != string::npos)) {
@ -260,9 +237,11 @@ SerialKey::parse(std::string plainSerial)
m_company = parts.at(6);
sscanf(parts.at(7).c_str(), "%lld", &m_warnTime);
sscanf(parts.at(8).c_str(), "%lld", &m_expireTime);
m_valid = true;
valid = true;
}
}
return valid;
}
Edition

View File

@ -31,7 +31,6 @@ public:
explicit SerialKey(Edition edition = kUnregistered);
explicit SerialKey(std::string serial);
bool isValid(time_t currentTime) const;
bool isExpiring(time_t currentTime) const;
bool isExpired(time_t currentTime) const;
bool isTrial() const;
@ -44,7 +43,7 @@ public:
static Edition parseEdition(const std::string& editionStr);
private:
void parse(std::string plainSerial);
bool parse(std::string plainSerial);
std::string editionString() const;
#ifdef TEST_ENV
@ -67,7 +66,6 @@ private:
unsigned long long m_expireTime;
Edition m_edition;
bool m_trial;
bool m_valid;
};
@ -80,8 +78,7 @@ operator== (SerialKey const& lhs, SerialKey const& rhs) {
(lhs.m_warnTime == rhs.m_warnTime) &&
(lhs.m_expireTime == rhs.m_expireTime) &&
(lhs.m_edition == rhs.m_edition) &&
(lhs.m_trial == rhs.m_trial) &&
(lhs.m_valid == rhs.m_valid);
(lhs.m_trial == rhs.m_trial);
}
inline bool