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

fix(settings): Heal invalid ToxPk saved to Personal Settings

Fix #6506
This commit is contained in:
Anthony Bilinski 2022-03-03 14:56:42 -08:00
parent 1206da2b05
commit dd9524085f
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
2 changed files with 24 additions and 2 deletions

View File

@ -18,11 +18,33 @@
*/
#include "personalsettingsupgrader.h"
#include "settingsserializer.h"
#include "src/core/toxpk.h"
#include <QDebug>
#include <cassert>
namespace {
bool version0to1(SettingsSerializer& ps)
{
ps.beginGroup("Friends");
{
int size = ps.beginReadArray("Friend");
for (int i = 0; i < size; i++) {
ps.setArrayIndex(i);
const auto oldFriendAddr = ps.value("addr").toString();
auto newFriendAddr = oldFriendAddr.left(ToxPk::numHexChars);
ps.setValue("addr", newFriendAddr);
}
ps.endArray();
}
ps.endGroup();
return true;
}
} // namespace
bool PersonalSettingsUpgrader::doUpgrade(SettingsSerializer& settingsSerializer, int fromVer, int toVer)
{
if (fromVer == toVer) {
@ -37,7 +59,7 @@ bool PersonalSettingsUpgrader::doUpgrade(SettingsSerializer& settingsSerializer,
}
using SettingsUpgradeFn = bool (*)(SettingsSerializer&);
std::vector<SettingsUpgradeFn> upgradeFns = {};
std::vector<SettingsUpgradeFn> upgradeFns = {version0to1};
assert(fromVer < static_cast<int>(upgradeFns.size()));
assert(toVer == static_cast<int>(upgradeFns.size()));

View File

@ -65,7 +65,7 @@ Settings* Settings::settings{nullptr};
CompatibleRecursiveMutex Settings::bigLock;
QThread* Settings::settingsThread{nullptr};
static constexpr int GLOBAL_SETTINGS_VERSION = 1;
static constexpr int PERSONAL_SETTINGS_VERSION = 0;
static constexpr int PERSONAL_SETTINGS_VERSION = 1;
Settings::Settings()
: loaded(false)