mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-12 16:23:07 -07:00
Add support for different configurations. Partially closes #465
It may be useful to have different configurations either for portable versions or for debugging purposes. To implement this we add two options, avaliable via command line switches 1. An option to change configuration name ("--configuration"). The name supplied via this option is appended to QCoreApplication::applicationName() to form "qBittorrent_<conf_name>" name for the configuration files. 2. An option to provide a path do directory where all the settings are stored (kind of profile directory). There is a shortcut "--portable" which means "use directory 'profile' near the executable location". In order to implement that we have to perform initialisation of the profile directories before the SettingStorage and Preferences singletones are initialised. Thus, options parsing shall be performed without defaults read from preferences.
This commit is contained in:
parent
6ad8a4d8b1
commit
0f746ffd5a
20 changed files with 901 additions and 398 deletions
|
@ -63,6 +63,7 @@
|
|||
#include "base/logger.h"
|
||||
#include "base/preferences.h"
|
||||
#include "base/settingsstorage.h"
|
||||
#include "base/profile.h"
|
||||
#include "base/utils/fs.h"
|
||||
#include "base/utils/misc.h"
|
||||
#include "base/iconprovider.h"
|
||||
|
@ -93,17 +94,33 @@ namespace
|
|||
|
||||
const QString LOG_FOLDER("logs");
|
||||
const char PARAMS_SEPARATOR[] = "|";
|
||||
|
||||
const QString DEFAULT_PORTABLE_MODE_PROFILE_DIR = QLatin1String("profile");
|
||||
}
|
||||
|
||||
Application::Application(const QString &id, int &argc, char **argv)
|
||||
: BaseApplication(id, argc, argv)
|
||||
, m_running(false)
|
||||
, m_shutdownAct(ShutdownDialogAction::Exit)
|
||||
, m_commandLineArgs(parseCommandLine(this->arguments()))
|
||||
{
|
||||
setApplicationName("qBittorrent");
|
||||
validateCommandLineParameters();
|
||||
|
||||
QString profileDir = m_commandLineArgs.portableMode
|
||||
? QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(DEFAULT_PORTABLE_MODE_PROFILE_DIR)
|
||||
: m_commandLineArgs.profileDir;
|
||||
|
||||
Profile::initialize(profileDir, m_commandLineArgs.configurationName);
|
||||
|
||||
Logger::initInstance();
|
||||
SettingsStorage::initInstance();
|
||||
Preferences::initInstance();
|
||||
|
||||
if (m_commandLineArgs.webUiPort > 0) { // it will be -1 when user did not set any value
|
||||
Preferences::instance()->setWebUiPort(m_commandLineArgs.webUiPort);
|
||||
}
|
||||
|
||||
#if defined(Q_OS_MACX) && !defined(DISABLE_GUI)
|
||||
if (QSysInfo::MacintoshVersion > QSysInfo::MV_10_8) {
|
||||
// fix Mac OS X 10.9 (mavericks) font issue
|
||||
|
@ -111,7 +128,6 @@ Application::Application(const QString &id, int &argc, char **argv)
|
|||
QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande");
|
||||
}
|
||||
#endif
|
||||
setApplicationName("qBittorrent");
|
||||
initializeTranslation();
|
||||
#ifndef DISABLE_GUI
|
||||
setAttribute(Qt::AA_UseHighDpiPixmaps, true); // opt-in to the high DPI pixmap support
|
||||
|
@ -137,6 +153,11 @@ QPointer<MainWindow> Application::mainWindow()
|
|||
}
|
||||
#endif
|
||||
|
||||
const QBtCommandLineParameters &Application::commandLineArgs() const
|
||||
{
|
||||
return m_commandLineArgs;
|
||||
}
|
||||
|
||||
bool Application::isFileLoggerEnabled() const
|
||||
{
|
||||
return settings()->loadValue(KEY_FILELOGGER_ENABLED, true).toBool();
|
||||
|
@ -633,3 +654,9 @@ void Application::cleanup()
|
|||
Utils::Misc::shutdownComputer(m_shutdownAct);
|
||||
}
|
||||
}
|
||||
|
||||
void Application::validateCommandLineParameters()
|
||||
{
|
||||
if (m_commandLineArgs.portableMode && !m_commandLineArgs.profileDir.isEmpty())
|
||||
throw CommandLineParameterError(tr("Portable mode and explicit profile directory options are mutually exclusive"));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue