From a734199383b58f34420be2d6ee84562058f386ec Mon Sep 17 00:00:00 2001 From: jagannatharjun Date: Sun, 29 Aug 2021 20:26:15 +0530 Subject: [PATCH] Fix startup with different profiles --- src/base/preferences.cpp | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/base/preferences.cpp b/src/base/preferences.cpp index 1af6cd76a..180c40dd4 100644 --- a/src/base/preferences.cpp +++ b/src/base/preferences.cpp @@ -55,9 +55,20 @@ #include "algorithm.h" #include "global.h" +#include "profile.h" #include "settingsstorage.h" #include "utils/fs.h" +namespace +{ + QString makeProfileID(const QString &profilePath, const QString &profileName) + { + return profilePath.isEmpty() + ? profileName + : profileName + QLatin1Char('@') + Utils::Fs::toValidFileSystemName(profilePath, false, {}); + } +} + Preferences *Preferences::m_instance = nullptr; Preferences::Preferences() = default; @@ -310,21 +321,31 @@ void Preferences::setPreventFromSuspendWhenSeeding(const bool b) #ifdef Q_OS_WIN bool Preferences::WinStartup() const { - QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat); - return settings.contains("qBittorrent"); + const QString profileName = Profile::instance()->profileName(); + const QString profilePath = Profile::instance()->rootPath(); + const QString profileID = makeProfileID(profilePath, profileName); + const QSettings settings {"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat}; + + return settings.contains(profileID); } void Preferences::setWinStartup(const bool b) { - QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat); + const QString profileName = Profile::instance()->profileName(); + const QString profilePath = Profile::instance()->rootPath(); + const QString profileID = makeProfileID(profilePath, profileName); + QSettings settings {"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat}; if (b) { - const QString binPath = '"' + Utils::Fs::toNativePath(qApp->applicationFilePath()) + '"'; - settings.setValue("qBittorrent", binPath); + const QString configuration = Profile::instance()->configurationName(); + + const auto cmd = QString::fromLatin1(R"("%1" "--profile=%2" "--configuration=%3")") + .arg(Utils::Fs::toNativePath(qApp->applicationFilePath()), profilePath, configuration); + settings.setValue(profileID, cmd); } else { - settings.remove("qBittorrent"); + settings.remove(profileID); } } #endif // Q_OS_WIN