Browse Source

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
reviewable/pr6469/r3
Anthony Bilinski 3 years ago
parent
commit
0eb56fb9bb
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
  1. 27
      src/persistence/paths.cpp
  2. 4
      src/persistence/paths.h
  3. 21
      src/persistence/settings.cpp
  4. 1
      src/persistence/settings.h

27
src/persistence/paths.cpp

@ -27,6 +27,7 @@ @@ -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) @@ -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) @@ -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.

4
src/persistence/paths.h

@ -21,6 +21,7 @@ @@ -21,6 +21,7 @@
#include <QString>
#include <QStringList>
#include <atomic>
#define PATHS_VERSION_TCS_COMPLIANT 0
@ -35,6 +36,7 @@ public: @@ -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: @@ -58,5 +60,5 @@ private:
private:
QString basePath{};
const bool portable = false;
std::atomic_bool portable{false};
};

21
src/persistence/settings.cpp

@ -110,8 +110,6 @@ void Settings::loadGlobal() @@ -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() @@ -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) @@ -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) {

1
src/persistence/settings.h

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

Loading…
Cancel
Save