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

4
src/persistence/paths.h

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

21
src/persistence/settings.cpp

@ -110,8 +110,6 @@ void Settings::loadGlobal()
createSettingsDir(); createSettingsDir();
makeToxPortable = Settings::isToxPortable();
QDir dir(paths.getSettingsDirPath()); QDir dir(paths.getSettingsDirPath());
QString filePath = dir.filePath(globalSettingsFile); QString filePath = dir.filePath(globalSettingsFile);
@ -262,20 +260,6 @@ void Settings::loadGlobal()
loaded = true; 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) void Settings::updateProfileData(Profile* profile, const QCommandLineParser* parser)
{ {
QMutexLocker locker{&bigLock}; QMutexLocker locker{&bigLock};
@ -889,13 +873,12 @@ void Settings::setMakeToxPortable(bool newValue)
bool changed = false; bool changed = false;
{ {
QMutexLocker locker{&bigLock}; QMutexLocker locker{&bigLock};
QFile(paths.getSettingsDirPath() + globalSettingsFile).remove()
if (newValue != makeToxPortable) { if (newValue != makeToxPortable) {
QFile(paths.getSettingsDirPath() + globalSettingsFile).remove(); QFile(paths.getSettingsDirPath() + globalSettingsFile).remove();
makeToxPortable = newValue; makeToxPortable = newValue;
changed = paths.setPortable(newValue);
saveGlobal(); saveGlobal();
changed = true;
} }
} }
if (changed) { if (changed) {

1
src/persistence/settings.h

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

Loading…
Cancel
Save