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:
@ -83,6 +83,7 @@ Enhancements:
|
||||
- #7438 Compare result of `clickedButton` instead of `exec`
|
||||
- #7440 Fixed light logo filename on about screen
|
||||
- #7441 Share file line logic between logger and message box
|
||||
- #7442 Improve error handling and use long long for dates
|
||||
|
||||
# 1.14.6
|
||||
|
||||
|
||||
@ -31,7 +31,6 @@
|
||||
#include <QApplication>
|
||||
#include <QMessageBox>
|
||||
#include <QThread>
|
||||
#include <exception>
|
||||
|
||||
using namespace synergy::gui;
|
||||
using namespace synergy::license;
|
||||
@ -97,17 +96,9 @@ void ActivationDialog::accept() {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const auto result = m_licenseHandler.changeSerialKey(serialKey);
|
||||
if (result != Result::kSuccess) {
|
||||
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");
|
||||
const auto result = m_licenseHandler.changeSerialKey(serialKey);
|
||||
if (result != Result::kSuccess) {
|
||||
showResultDialog(result);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -31,8 +31,8 @@
|
||||
#include "gui/diagnostic.h"
|
||||
#include "gui/dialogs/SettingsDialog.h"
|
||||
#include "gui/license/LicenseHandler.h"
|
||||
#include "gui/license/license_config.h"
|
||||
#include "gui/license/license_notices.h"
|
||||
#include "gui/license/license_utils.h"
|
||||
#include "gui/messages.h"
|
||||
#include "gui/string_utils.h"
|
||||
#include "gui/styles.h"
|
||||
|
||||
@ -35,8 +35,8 @@
|
||||
#include <QMessageBox>
|
||||
#include <QObject>
|
||||
#include <QtCore>
|
||||
#include <QtGlobal>
|
||||
#include <QtGui>
|
||||
#include <qglobal.h>
|
||||
|
||||
#if defined(Q_OS_MAC)
|
||||
#include <Carbon/Carbon.h>
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
|
||||
#include "gui/config/IAppConfig.h"
|
||||
#include "gui/core/CoreTool.h"
|
||||
#include "gui/license/license_config.h"
|
||||
#include "gui/license/license_utils.h"
|
||||
#include "gui/paths.h"
|
||||
#include "tls/TlsUtility.h"
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
|
||||
#include "UpgradeDialog.h"
|
||||
#include "gui/core/CoreProcess.h"
|
||||
#include "gui/license/license_config.h"
|
||||
#include "gui/license/license_utils.h"
|
||||
#include "gui/messages.h"
|
||||
#include "gui/tls/TlsCertificate.h"
|
||||
#include "gui/tls/TlsUtility.h"
|
||||
|
||||
@ -18,17 +18,21 @@
|
||||
#include "LicenseHandler.h"
|
||||
|
||||
#include "constants.h"
|
||||
#include "gui/license/license_utils.h"
|
||||
#include "license/ProductEdition.h"
|
||||
#include "license/parse_serial_key.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QTimer>
|
||||
#include <QtGlobal>
|
||||
|
||||
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 {
|
||||
return m_license.productEdition();
|
||||
@ -52,7 +56,7 @@ LicenseHandler::changeSerialKey(const QString &hexString) {
|
||||
}
|
||||
|
||||
qDebug() << "changing serial key to:" << hexString;
|
||||
auto serialKey = parseSerialKey(hexString.toStdString());
|
||||
auto serialKey = parseSerialKey(hexString);
|
||||
|
||||
if (serialKey == m_license.serialKey()) {
|
||||
qDebug("serial key did not change, ignoring");
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "gui/constants.h"
|
||||
#include "gui/license/license_config.h"
|
||||
#include "gui/license/license_utils.h"
|
||||
#include "license/License.h"
|
||||
#include "license/ProductEdition.h"
|
||||
|
||||
|
||||
@ -15,8 +15,9 @@
|
||||
* 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 <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
|
||||
@ -17,9 +17,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include "license/SerialKey.h"
|
||||
|
||||
namespace synergy::gui::license {
|
||||
|
||||
bool isLicensedProduct();
|
||||
bool isActivationEnabled();
|
||||
synergy::license::SerialKey parseSerialKey(const QString &hexString);
|
||||
|
||||
} // namespace synergy::gui::license
|
||||
@ -20,7 +20,7 @@
|
||||
#include "Logger.h"
|
||||
#include "common/version.h"
|
||||
#include "constants.h"
|
||||
#include "gui/license/license_config.h"
|
||||
#include "gui/license/license_utils.h"
|
||||
#include "styles.h"
|
||||
|
||||
#include <QAction>
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
#include "TlsUtility.h"
|
||||
|
||||
#include "TlsCertificate.h"
|
||||
#include "gui/license/license_config.h"
|
||||
#include "gui/license/license_utils.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QString>
|
||||
|
||||
@ -19,9 +19,8 @@
|
||||
|
||||
#include "SerialKey.h"
|
||||
#include "SerialKeyType.h"
|
||||
#include "utils/trim.h"
|
||||
#include "utils/string_utils.h"
|
||||
|
||||
#include <cctype>
|
||||
#include <exception>
|
||||
#include <optional>
|
||||
#include <sstream>
|
||||
@ -131,14 +130,20 @@ std::optional<time_point> parseDate(const std::string &unixTimeString) {
|
||||
}
|
||||
|
||||
try {
|
||||
auto seconds = std::stol(clean);
|
||||
auto seconds = std::stoll(clean);
|
||||
if (seconds <= 0) {
|
||||
return std::nullopt;
|
||||
} else {
|
||||
return time_point{std::chrono::seconds{seconds}};
|
||||
}
|
||||
} catch (const std::exception &) {
|
||||
throw InvalidSerialKeyDate(unixTimeString);
|
||||
} catch (std::invalid_argument &) {
|
||||
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 {
|
||||
public:
|
||||
explicit InvalidHexString()
|
||||
: SerialKeyParseError("invalid hex string length") {}
|
||||
explicit InvalidHexString() : SerialKeyParseError("invalid hex string") {}
|
||||
};
|
||||
|
||||
class InvalidSerialKeyFormat : public SerialKeyParseError {
|
||||
@ -42,8 +41,10 @@ public:
|
||||
|
||||
class InvalidSerialKeyDate : public SerialKeyParseError {
|
||||
public:
|
||||
explicit InvalidSerialKeyDate(const std::string &date)
|
||||
: SerialKeyParseError("invalid serial key date: " + date) {}
|
||||
explicit InvalidSerialKeyDate(
|
||||
const std::string &date, const std::string &cause)
|
||||
: SerialKeyParseError("invalid serial key date: " + date + "\n" + cause) {
|
||||
}
|
||||
};
|
||||
|
||||
class InvalidSerialKeyVersion : public SerialKeyParseError {
|
||||
|
||||
Reference in New Issue
Block a user