mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-14 01:03:08 -07:00
Fix startup with different profiles
This commit is contained in:
parent
046b741700
commit
a734199383
1 changed files with 27 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue