Skip to content

Commit a734199

Browse files
jagannatharjunglassez
authored andcommitted
Fix startup with different profiles
1 parent 046b741 commit a734199

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

src/base/preferences.cpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,20 @@
5555

5656
#include "algorithm.h"
5757
#include "global.h"
58+
#include "profile.h"
5859
#include "settingsstorage.h"
5960
#include "utils/fs.h"
6061

62+
namespace
63+
{
64+
QString makeProfileID(const QString &profilePath, const QString &profileName)
65+
{
66+
return profilePath.isEmpty()
67+
? profileName
68+
: profileName + QLatin1Char('@') + Utils::Fs::toValidFileSystemName(profilePath, false, {});
69+
}
70+
}
71+
6172
Preferences *Preferences::m_instance = nullptr;
6273

6374
Preferences::Preferences() = default;
@@ -310,21 +321,31 @@ void Preferences::setPreventFromSuspendWhenSeeding(const bool b)
310321
#ifdef Q_OS_WIN
311322
bool Preferences::WinStartup() const
312323
{
313-
QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
314-
return settings.contains("qBittorrent");
324+
const QString profileName = Profile::instance()->profileName();
325+
const QString profilePath = Profile::instance()->rootPath();
326+
const QString profileID = makeProfileID(profilePath, profileName);
327+
const QSettings settings {"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat};
328+
329+
return settings.contains(profileID);
315330
}
316331

317332
void Preferences::setWinStartup(const bool b)
318333
{
319-
QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
334+
const QString profileName = Profile::instance()->profileName();
335+
const QString profilePath = Profile::instance()->rootPath();
336+
const QString profileID = makeProfileID(profilePath, profileName);
337+
QSettings settings {"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat};
320338
if (b)
321339
{
322-
const QString binPath = '"' + Utils::Fs::toNativePath(qApp->applicationFilePath()) + '"';
323-
settings.setValue("qBittorrent", binPath);
340+
const QString configuration = Profile::instance()->configurationName();
341+
342+
const auto cmd = QString::fromLatin1(R"("%1" "--profile=%2" "--configuration=%3")")
343+
.arg(Utils::Fs::toNativePath(qApp->applicationFilePath()), profilePath, configuration);
344+
settings.setValue(profileID, cmd);
324345
}
325346
else
326347
{
327-
settings.remove("qBittorrent");
348+
settings.remove(profileID);
328349
}
329350
}
330351
#endif // Q_OS_WIN

0 commit comments

Comments
 (0)