Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(settings): load personal settings before constructing core
Browse files Browse the repository at this point in the history
Fix proxy settings not being passed to toxcore, bug present since
8574162. Not present in any releases.
  • Loading branch information
anthonybilinski committed Mar 30, 2019
1 parent 993f6fa commit bef9d4b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/nexus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ void Nexus::setProfile(Profile* profile)
{
getInstance().profile = profile;
if (profile)
Settings::getInstance().loadPersonal(profile);
Settings::getInstance().loadPersonal(profile->getName(), profile->getPasskey());
}

/**
Expand Down
22 changes: 7 additions & 15 deletions src/persistence/profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void Profile::initCore(const QByteArray& toxsave, ICoreSettings& s, bool isNewPr

if (isNewProfile) {
core->setStatusMessage(tr("Toxing on qTox"));
core->setUsername(name);
core->setUsername(name);
}

// save tox file when Core requests it
Expand All @@ -96,14 +96,16 @@ void Profile::initCore(const QByteArray& toxsave, ICoreSettings& s, bool isNewPr
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}
, passkey{std::move(passkey)}
, isRemoved{false}
, encrypted{this->passkey != nullptr}
{
Settings& s = Settings::getInstance();
s.setCurrentProfile(name);
s.saveGlobal();

s.loadPersonal(name, passkey.get());
initCore(toxsave, s, isNewProfile);

const ToxId& selfId = core->getSelfId();
Expand Down Expand Up @@ -180,12 +182,7 @@ Profile* Profile::loadProfile(QString name, const QString& password)
}

saveFile.close();
p = new Profile(name, password, false, data);
p->passkey = std::move(tmpKey);
if (p->passkey) {
p->encrypted = true;
}

p = new Profile(name, password, false, data, std::move(tmpKey));
return p;

// cleanup in case of error
Expand Down Expand Up @@ -230,12 +227,7 @@ Profile* Profile::createProfile(QString name, QString password)
}

Settings::getInstance().createPersonal(name);
Profile* p = new Profile(name, password, true, QByteArray());
p->passkey = std::move(tmpKey);
if (p->passkey) {
p->encrypted = true;
}

Profile* p = new Profile(name, password, true, QByteArray(), std::move(tmpKey));
return p;
}

Expand Down
2 changes: 1 addition & 1 deletion src/persistence/profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private slots:
void onAvatarOfferReceived(uint32_t friendId, uint32_t fileId, const QByteArray& avatarHash);

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);
QString avatarPath(const ToxPk& owner, bool forceUnencrypted = false);
bool saveToxSave(QByteArray data);
Expand Down
16 changes: 3 additions & 13 deletions src/persistence/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,31 +273,21 @@ void Settings::loadGlobal()
loaded = true;
}

void Settings::loadPersonal()
{
Profile* profile = Nexus::getProfile();
if (!profile) {
qCritical() << "No active profile, couldn't load personal settings";
return;
}
loadPersonal(profile);
}

void Settings::loadPersonal(Profile* profile)
void Settings::loadPersonal(QString profileName, const ToxEncrypt* passKey)
{
QMutexLocker locker{&bigLock};

QDir dir(getSettingsDirPath());
QString filePath = dir.filePath(globalSettingsFile);

// 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
filePath = tmp;

qDebug() << "Loading personal settings from" << filePath;

SettingsSerializer ps(filePath, profile->getPasskey());
SettingsSerializer ps(filePath, passKey);
ps.load();
friendLst.clear();

Expand Down
3 changes: 1 addition & 2 deletions src/persistence/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ class Settings : public QObject,
void savePersonal();

void loadGlobal();
void loadPersonal();
void loadPersonal(Profile* profile);
void loadPersonal(QString profileName, const ToxEncrypt* passKey);

void resetToDefault();

Expand Down

0 comments on commit bef9d4b

Please sign in to comment.