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

fix(settings): load personal settings before constructing core

Fix proxy settings not being passed to toxcore, bug present since
8574162949. Not present in any releases.
This commit is contained in:
Anthony Bilinski 2019-03-28 20:34:01 -07:00
parent 993f6fa5c0
commit bef9d4b773
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
5 changed files with 13 additions and 32 deletions

View File

@ -270,7 +270,7 @@ void Nexus::setProfile(Profile* profile)
{ {
getInstance().profile = profile; getInstance().profile = profile;
if (profile) if (profile)
Settings::getInstance().loadPersonal(profile); Settings::getInstance().loadPersonal(profile->getName(), profile->getPasskey());
} }
/** /**

View File

@ -84,7 +84,7 @@ void Profile::initCore(const QByteArray& toxsave, ICoreSettings& s, bool isNewPr
if (isNewProfile) { if (isNewProfile) {
core->setStatusMessage(tr("Toxing on qTox")); core->setStatusMessage(tr("Toxing on qTox"));
core->setUsername(name); core->setUsername(name);
} }
// save tox file when Core requests it // save tox file when Core requests it
@ -96,14 +96,16 @@ void Profile::initCore(const QByteArray& toxsave, ICoreSettings& s, bool isNewPr
Qt::ConnectionType::QueuedConnection); Qt::ConnectionType::QueuedConnection);
} }
Profile::Profile(QString name, const QString& password, bool isNewProfile, const QByteArray& toxsave) Profile::Profile(QString name, const QString& password, bool isNewProfile, const QByteArray& toxsave, std::unique_ptr<ToxEncrypt> passkey)
: name{name} : name{name}
, passkey{std::move(passkey)}
, isRemoved{false} , isRemoved{false}
, encrypted{this->passkey != nullptr}
{ {
Settings& s = Settings::getInstance(); Settings& s = Settings::getInstance();
s.setCurrentProfile(name); s.setCurrentProfile(name);
s.saveGlobal(); s.saveGlobal();
s.loadPersonal(name, passkey.get());
initCore(toxsave, s, isNewProfile); initCore(toxsave, s, isNewProfile);
const ToxId& selfId = core->getSelfId(); const ToxId& selfId = core->getSelfId();
@ -180,12 +182,7 @@ Profile* Profile::loadProfile(QString name, const QString& password)
} }
saveFile.close(); saveFile.close();
p = new Profile(name, password, false, data); p = new Profile(name, password, false, data, std::move(tmpKey));
p->passkey = std::move(tmpKey);
if (p->passkey) {
p->encrypted = true;
}
return p; return p;
// cleanup in case of error // cleanup in case of error
@ -230,12 +227,7 @@ Profile* Profile::createProfile(QString name, QString password)
} }
Settings::getInstance().createPersonal(name); Settings::getInstance().createPersonal(name);
Profile* p = new Profile(name, password, true, QByteArray()); Profile* p = new Profile(name, password, true, QByteArray(), std::move(tmpKey));
p->passkey = std::move(tmpKey);
if (p->passkey) {
p->encrypted = true;
}
return p; return p;
} }

View File

@ -98,7 +98,7 @@ private slots:
void onAvatarOfferReceived(uint32_t friendId, uint32_t fileId, const QByteArray& avatarHash); void onAvatarOfferReceived(uint32_t friendId, uint32_t fileId, const QByteArray& avatarHash);
private: private:
Profile(QString name, const QString& password, bool newProfile, const QByteArray& toxsave); Profile(QString name, const QString& password, bool newProfile, const QByteArray& toxsave, std::unique_ptr<ToxEncrypt> passKey);
static QStringList getFilesByExt(QString extension); static QStringList getFilesByExt(QString extension);
QString avatarPath(const ToxPk& owner, bool forceUnencrypted = false); QString avatarPath(const ToxPk& owner, bool forceUnencrypted = false);
bool saveToxSave(QByteArray data); bool saveToxSave(QByteArray data);

View File

@ -273,17 +273,7 @@ void Settings::loadGlobal()
loaded = true; loaded = true;
} }
void Settings::loadPersonal() void Settings::loadPersonal(QString profileName, const ToxEncrypt* passKey)
{
Profile* profile = Nexus::getProfile();
if (!profile) {
qCritical() << "No active profile, couldn't load personal settings";
return;
}
loadPersonal(profile);
}
void Settings::loadPersonal(Profile* profile)
{ {
QMutexLocker locker{&bigLock}; QMutexLocker locker{&bigLock};
@ -291,13 +281,13 @@ void Settings::loadPersonal(Profile* profile)
QString filePath = dir.filePath(globalSettingsFile); QString filePath = dir.filePath(globalSettingsFile);
// load from a profile specific friend data list if possible // load from a profile specific friend data list if possible
QString tmp = dir.filePath(profile->getName() + ".ini"); QString tmp = dir.filePath(profileName + ".ini");
if (QFile(tmp).exists()) // otherwise, filePath remains the global file if (QFile(tmp).exists()) // otherwise, filePath remains the global file
filePath = tmp; filePath = tmp;
qDebug() << "Loading personal settings from" << filePath; qDebug() << "Loading personal settings from" << filePath;
SettingsSerializer ps(filePath, profile->getPasskey()); SettingsSerializer ps(filePath, passKey);
ps.load(); ps.load();
friendLst.clear(); friendLst.clear();

View File

@ -146,8 +146,7 @@ public:
void savePersonal(); void savePersonal();
void loadGlobal(); void loadGlobal();
void loadPersonal(); void loadPersonal(QString profileName, const ToxEncrypt* passKey);
void loadPersonal(Profile* profile);
void resetToDefault(); void resetToDefault();