1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix(settings): repair saved invalid proxy type due to #5311

This commit is contained in:
Anthony Bilinski 2018-12-07 23:16:56 -08:00
parent e80dbe2d83
commit c8ffa1f921
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
3 changed files with 17 additions and 0 deletions

View File

@ -12,6 +12,7 @@ class ICoreSettings {
public:
enum class ProxyType
{
// If changed, don't forget to update Settings::fixInvalidProxyType
ptNone = 0,
ptSOCKS5 = 1,
ptHTTP = 2

View File

@ -402,6 +402,7 @@ void Settings::loadPersonal(Profile* profile)
ps.beginGroup("Proxy");
{
proxyType = static_cast<ProxyType>(ps.value("proxyType", 0 /* ProxyType::None */).toInt());
proxyType = fixInvalidProxyType(proxyType);
proxyAddr = ps.value("proxyAddr", proxyAddr).toString();
proxyPort = static_cast<quint16>(ps.value("proxyPort", proxyPort).toUInt());
}
@ -2444,3 +2445,17 @@ Settings::friendProp& Settings::getOrInsertFriendPropRef(const ToxPk& id)
return *it;
}
ICoreSettings::ProxyType Settings::fixInvalidProxyType(ICoreSettings::ProxyType proxyType)
{
// Repair uninitialized enum that was saved to settings due to bug (https://github.com/qTox/qTox/issues/5311)
switch (proxyType) {
case ICoreSettings::ProxyType::ptNone:
case ICoreSettings::ProxyType::ptSOCKS5:
case ICoreSettings::ProxyType::ptHTTP:
return proxyType;
default:
qWarning() << "Repairing invalid ProxyType, UDP will be enabled";
return ICoreSettings::ProxyType::ptNone;
}
}

View File

@ -578,6 +578,7 @@ private:
Settings& operator=(const Settings&) = delete;
void savePersonal(QString profileName, const ToxEncrypt* passkey);
friendProp& getOrInsertFriendPropRef(const ToxPk& id);
ICoreSettings::ProxyType fixInvalidProxyType(ICoreSettings::ProxyType proxyType);
public slots:
void savePersonal(Profile* profile);