Improve error handling and use long long for dates (#7442)
* Improve error handling * Remove unused includes * Use long long for unix date * Update ChangeLog * Fixed include * Clang format
This commit is contained in:
parent
28cefff13b
commit
3293deff39
15 changed files with 53 additions and 33 deletions
|
|
@ -83,6 +83,7 @@ Enhancements:
|
||||||
- #7438 Compare result of `clickedButton` instead of `exec`
|
- #7438 Compare result of `clickedButton` instead of `exec`
|
||||||
- #7440 Fixed light logo filename on about screen
|
- #7440 Fixed light logo filename on about screen
|
||||||
- #7441 Share file line logic between logger and message box
|
- #7441 Share file line logic between logger and message box
|
||||||
|
- #7442 Improve error handling and use long long for dates
|
||||||
|
|
||||||
# 1.14.6
|
# 1.14.6
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,6 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <exception>
|
|
||||||
|
|
||||||
using namespace synergy::gui;
|
using namespace synergy::gui;
|
||||||
using namespace synergy::license;
|
using namespace synergy::license;
|
||||||
|
|
@ -97,17 +96,9 @@ void ActivationDialog::accept() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const auto result = m_licenseHandler.changeSerialKey(serialKey);
|
||||||
const auto result = m_licenseHandler.changeSerialKey(serialKey);
|
if (result != Result::kSuccess) {
|
||||||
if (result != Result::kSuccess) {
|
showResultDialog(result);
|
||||||
showResultDialog(result);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (const std::exception &e) { // NOSONAR
|
|
||||||
qCritical("failed to change serial key: %s", e.what());
|
|
||||||
return;
|
|
||||||
} catch (...) { // NOSONAR
|
|
||||||
qCritical("failed to change serial key");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,8 @@
|
||||||
#include "gui/diagnostic.h"
|
#include "gui/diagnostic.h"
|
||||||
#include "gui/dialogs/SettingsDialog.h"
|
#include "gui/dialogs/SettingsDialog.h"
|
||||||
#include "gui/license/LicenseHandler.h"
|
#include "gui/license/LicenseHandler.h"
|
||||||
#include "gui/license/license_config.h"
|
|
||||||
#include "gui/license/license_notices.h"
|
#include "gui/license/license_notices.h"
|
||||||
|
#include "gui/license/license_utils.h"
|
||||||
#include "gui/messages.h"
|
#include "gui/messages.h"
|
||||||
#include "gui/string_utils.h"
|
#include "gui/string_utils.h"
|
||||||
#include "gui/styles.h"
|
#include "gui/styles.h"
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,8 @@
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
|
#include <QtGlobal>
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include <qglobal.h>
|
|
||||||
|
|
||||||
#if defined(Q_OS_MAC)
|
#if defined(Q_OS_MAC)
|
||||||
#include <Carbon/Carbon.h>
|
#include <Carbon/Carbon.h>
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
#include "gui/config/IAppConfig.h"
|
#include "gui/config/IAppConfig.h"
|
||||||
#include "gui/core/CoreTool.h"
|
#include "gui/core/CoreTool.h"
|
||||||
#include "gui/license/license_config.h"
|
#include "gui/license/license_utils.h"
|
||||||
#include "gui/paths.h"
|
#include "gui/paths.h"
|
||||||
#include "tls/TlsUtility.h"
|
#include "tls/TlsUtility.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
#include "UpgradeDialog.h"
|
#include "UpgradeDialog.h"
|
||||||
#include "gui/core/CoreProcess.h"
|
#include "gui/core/CoreProcess.h"
|
||||||
#include "gui/license/license_config.h"
|
#include "gui/license/license_utils.h"
|
||||||
#include "gui/messages.h"
|
#include "gui/messages.h"
|
||||||
#include "gui/tls/TlsCertificate.h"
|
#include "gui/tls/TlsCertificate.h"
|
||||||
#include "gui/tls/TlsUtility.h"
|
#include "gui/tls/TlsUtility.h"
|
||||||
|
|
|
||||||
|
|
@ -18,17 +18,21 @@
|
||||||
#include "LicenseHandler.h"
|
#include "LicenseHandler.h"
|
||||||
|
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
|
#include "gui/license/license_utils.h"
|
||||||
#include "license/ProductEdition.h"
|
#include "license/ProductEdition.h"
|
||||||
#include "license/parse_serial_key.h"
|
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QProcessEnvironment>
|
#include <QProcessEnvironment>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
using namespace synergy::license;
|
using namespace synergy::gui::license;
|
||||||
|
using License = synergy::license::License;
|
||||||
|
|
||||||
const License &LicenseHandler::license() const { return m_license; }
|
const synergy::license::License &LicenseHandler::license() const {
|
||||||
|
return m_license;
|
||||||
|
}
|
||||||
|
|
||||||
Edition LicenseHandler::productEdition() const {
|
Edition LicenseHandler::productEdition() const {
|
||||||
return m_license.productEdition();
|
return m_license.productEdition();
|
||||||
|
|
@ -52,7 +56,7 @@ LicenseHandler::changeSerialKey(const QString &hexString) {
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "changing serial key to:" << hexString;
|
qDebug() << "changing serial key to:" << hexString;
|
||||||
auto serialKey = parseSerialKey(hexString.toStdString());
|
auto serialKey = parseSerialKey(hexString);
|
||||||
|
|
||||||
if (serialKey == m_license.serialKey()) {
|
if (serialKey == m_license.serialKey()) {
|
||||||
qDebug("serial key did not change, ignoring");
|
qDebug("serial key did not change, ignoring");
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "gui/constants.h"
|
#include "gui/constants.h"
|
||||||
#include "gui/license/license_config.h"
|
#include "gui/license/license_utils.h"
|
||||||
#include "license/License.h"
|
#include "license/License.h"
|
||||||
#include "license/ProductEdition.h"
|
#include "license/ProductEdition.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,9 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "license_config.h"
|
#include "license_utils.h"
|
||||||
|
|
||||||
|
#include "license/parse_serial_key.h"
|
||||||
#include "string_utils.h"
|
#include "string_utils.h"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
@ -55,4 +56,16 @@ bool isActivationEnabled() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
synergy::license::SerialKey parseSerialKey(const QString &hexString) {
|
||||||
|
try {
|
||||||
|
return synergy::license::parseSerialKey(hexString.toStdString());
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
qFatal("failed to parse serial key: %s", e.what());
|
||||||
|
abort();
|
||||||
|
} catch (...) {
|
||||||
|
qFatal("failed to parse serial key, unknown error");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace synergy::gui::license
|
} // namespace synergy::gui::license
|
||||||
|
|
@ -17,9 +17,14 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
#include "license/SerialKey.h"
|
||||||
|
|
||||||
namespace synergy::gui::license {
|
namespace synergy::gui::license {
|
||||||
|
|
||||||
bool isLicensedProduct();
|
bool isLicensedProduct();
|
||||||
bool isActivationEnabled();
|
bool isActivationEnabled();
|
||||||
|
synergy::license::SerialKey parseSerialKey(const QString &hexString);
|
||||||
|
|
||||||
} // namespace synergy::gui::license
|
} // namespace synergy::gui::license
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "common/version.h"
|
#include "common/version.h"
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include "gui/license/license_config.h"
|
#include "gui/license/license_utils.h"
|
||||||
#include "styles.h"
|
#include "styles.h"
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
#include "TlsUtility.h"
|
#include "TlsUtility.h"
|
||||||
|
|
||||||
#include "TlsCertificate.h"
|
#include "TlsCertificate.h"
|
||||||
#include "gui/license/license_config.h"
|
#include "gui/license/license_utils.h"
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,8 @@
|
||||||
|
|
||||||
#include "SerialKey.h"
|
#include "SerialKey.h"
|
||||||
#include "SerialKeyType.h"
|
#include "SerialKeyType.h"
|
||||||
#include "utils/trim.h"
|
#include "utils/string_utils.h"
|
||||||
|
|
||||||
#include <cctype>
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
@ -131,14 +130,20 @@ std::optional<time_point> parseDate(const std::string &unixTimeString) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
auto seconds = std::stol(clean);
|
auto seconds = std::stoll(clean);
|
||||||
if (seconds <= 0) {
|
if (seconds <= 0) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
} else {
|
} else {
|
||||||
return time_point{std::chrono::seconds{seconds}};
|
return time_point{std::chrono::seconds{seconds}};
|
||||||
}
|
}
|
||||||
} catch (const std::exception &) {
|
} catch (std::invalid_argument &) {
|
||||||
throw InvalidSerialKeyDate(unixTimeString);
|
throw InvalidSerialKeyDate(unixTimeString, "invalid argument");
|
||||||
|
} catch (std::out_of_range &) {
|
||||||
|
throw InvalidSerialKeyDate(unixTimeString, "out of range");
|
||||||
|
} catch (std::exception &ex) {
|
||||||
|
throw InvalidSerialKeyDate(unixTimeString, ex.what());
|
||||||
|
} catch (...) { // NOSONAR
|
||||||
|
throw InvalidSerialKeyDate(unixTimeString, "unknown error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,7 @@ public:
|
||||||
|
|
||||||
class InvalidHexString : public SerialKeyParseError {
|
class InvalidHexString : public SerialKeyParseError {
|
||||||
public:
|
public:
|
||||||
explicit InvalidHexString()
|
explicit InvalidHexString() : SerialKeyParseError("invalid hex string") {}
|
||||||
: SerialKeyParseError("invalid hex string length") {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class InvalidSerialKeyFormat : public SerialKeyParseError {
|
class InvalidSerialKeyFormat : public SerialKeyParseError {
|
||||||
|
|
@ -42,8 +41,10 @@ public:
|
||||||
|
|
||||||
class InvalidSerialKeyDate : public SerialKeyParseError {
|
class InvalidSerialKeyDate : public SerialKeyParseError {
|
||||||
public:
|
public:
|
||||||
explicit InvalidSerialKeyDate(const std::string &date)
|
explicit InvalidSerialKeyDate(
|
||||||
: SerialKeyParseError("invalid serial key date: " + date) {}
|
const std::string &date, const std::string &cause)
|
||||||
|
: SerialKeyParseError("invalid serial key date: " + date + "\n" + cause) {
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class InvalidSerialKeyVersion : public SerialKeyParseError {
|
class InvalidSerialKeyVersion : public SerialKeyParseError {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue