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

fix(Paths): Track portable state in Paths to updates paths correctly

Paths must be aware of the "makeToxPortable" state to so that on shutdown,
saving saves to the new location.

This reverts to old behaviour which was broken in
5d56a3c039

Fix #6443
This commit is contained in:
Anthony Bilinski 2022-02-09 20:24:50 -08:00
parent d0c120e0a8
commit 0eb56fb9bb
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
4 changed files with 27 additions and 26 deletions

View File

@ -27,6 +27,7 @@
#include <QString>
#include <QStringBuilder>
#include <QStringList>
#include <QSettings>
namespace {
const QLatin1String globalSettingsFile{"qtox.ini"};
@ -95,14 +96,16 @@ Paths* Paths::makePaths(Portable mode)
portable = false;
break;
case Portable::Auto:
// auto detect
if (QFile{portableSettingsPath}.exists()) {
qDebug() << "Automatic portable";
portable = true;
if (QFile(portableSettingsPath).exists()) {
QSettings ps(portableSettingsPath, QSettings::IniFormat);
ps.setIniCodec("UTF-8");
ps.beginGroup("Advanced");
portable = ps.value("makeToxPortable", false).toBool();
ps.endGroup();
} else {
qDebug() << "Automatic non-portable";
portable = false;
}
qDebug()<< "Auto portable mode:" << portable;
break;
}
@ -121,6 +124,20 @@ Paths::Paths(const QString& basePath, bool portable)
, portable{portable}
{}
/**
* @brief Set paths to passed portable or system wide
* @param newPortable
* @return True if portable mode changed, else false.
*/
bool Paths::setPortable(bool newPortable)
{
auto oldVal = portable.exchange(newPortable);
if (oldVal != newPortable) {
return true;
}
return false;
}
/**
* @brief Check if qTox is running in portable mode.
* @return True if running in portable mode, false else.

View File

@ -21,6 +21,7 @@
#include <QString>
#include <QStringList>
#include <atomic>
#define PATHS_VERSION_TCS_COMPLIANT 0
@ -35,6 +36,7 @@ public:
static Paths* makePaths(Portable mode = Portable::Auto);
bool setPortable(bool portable);
bool isPortable() const;
#if PATHS_VERSION_TCS_COMPLIANT
QString getGlobalSettingsPath() const;
@ -58,5 +60,5 @@ private:
private:
QString basePath{};
const bool portable = false;
std::atomic_bool portable{false};
};

View File

@ -110,8 +110,6 @@ void Settings::loadGlobal()
createSettingsDir();
makeToxPortable = Settings::isToxPortable();
QDir dir(paths.getSettingsDirPath());
QString filePath = dir.filePath(globalSettingsFile);
@ -262,20 +260,6 @@ void Settings::loadGlobal()
loaded = true;
}
bool Settings::isToxPortable()
{
QString localSettingsPath = qApp->applicationDirPath() + QDir::separator() + globalSettingsFile;
if (!QFile(localSettingsPath).exists()) {
return false;
}
QSettings ps(localSettingsPath, QSettings::IniFormat);
ps.setIniCodec("UTF-8");
ps.beginGroup("Advanced");
bool result = ps.value("makeToxPortable", false).toBool();
ps.endGroup();
return result;
}
void Settings::updateProfileData(Profile* profile, const QCommandLineParser* parser)
{
QMutexLocker locker{&bigLock};
@ -889,13 +873,12 @@ void Settings::setMakeToxPortable(bool newValue)
bool changed = false;
{
QMutexLocker locker{&bigLock};
QFile(paths.getSettingsDirPath() + globalSettingsFile).remove()
if (newValue != makeToxPortable) {
QFile(paths.getSettingsDirPath() + globalSettingsFile).remove();
makeToxPortable = newValue;
changed = paths.setPortable(newValue);
saveGlobal();
changed = true;
}
}
if (changed) {

View File

@ -155,7 +155,6 @@ public:
void savePersonal();
void loadGlobal();
bool isToxPortable();
void loadPersonal(QString profileName, const ToxEncrypt* passKey);
void resetToDefault();