From 053ee486928d4cdd7fbdb0fa02d40d4707bf2cc0 Mon Sep 17 00:00:00 2001 From: Tester798 Date: Sun, 8 Dec 2019 05:00:44 +0200 Subject: [PATCH] Enable portable mode if "profile" directory exists Enable portable mode if "profile" directory exists in the app dir. Remove "--portable" command line argument. Add logging of current profile config directory. Closes #9445. --- src/app/application.cpp | 23 +++++++++++------------ src/app/application.h | 1 - src/app/cmdoptions.cpp | 8 -------- src/app/cmdoptions.h | 2 +- 4 files changed, 12 insertions(+), 22 deletions(-) diff --git a/src/app/application.cpp b/src/app/application.cpp index be915ebbc..867bd5a0f 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -144,13 +144,13 @@ Application::Application(const QString &id, int &argc, char **argv) QPixmapCache::setCacheLimit(PIXMAP_CACHE_SIZE); #endif - validateCommandLineParameters(); + const bool portableModeEnabled = m_commandLineArgs.profileDir.isEmpty() && QDir(QCoreApplication::applicationDirPath()).exists(DEFAULT_PORTABLE_MODE_PROFILE_DIR); - const QString profileDir = m_commandLineArgs.portableMode + const QString profileDir = portableModeEnabled ? QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(DEFAULT_PORTABLE_MODE_PROFILE_DIR) : m_commandLineArgs.profileDir; Profile::initialize(profileDir, m_commandLineArgs.configurationName, - m_commandLineArgs.relativeFastresumePaths || m_commandLineArgs.portableMode); + (m_commandLineArgs.relativeFastresumePaths || portableModeEnabled)); Logger::initInstance(); SettingsStorage::initInstance(); @@ -171,6 +171,14 @@ Application::Application(const QString &id, int &argc, char **argv) m_fileLogger = new FileLogger(fileLoggerPath(), isFileLoggerBackup(), fileLoggerMaxSize(), isFileLoggerDeleteOld(), fileLoggerAge(), static_cast(fileLoggerAgeType())); Logger::instance()->addMessage(tr("qBittorrent %1 started", "qBittorrent v3.2.0alpha started").arg(QBT_VERSION)); + if (portableModeEnabled) { + Logger::instance()->addMessage(tr("Running in portable mode. Auto detected profile folder at: %1").arg(profileDir)); + if (m_commandLineArgs.relativeFastresumePaths) + Logger::instance()->addMessage(tr("Redundant command line flag detected: \"%1\". Portable mode implies relative fastresume.").arg("--relative-fastresume"), Log::WARNING); // to avoid translating the `--relative-fastresume` string + } + else { + Logger::instance()->addMessage(tr("Using config directory: %1").arg(Profile::instance().location(SpecialFolder::Config))); + } } Application::~Application() @@ -737,12 +745,3 @@ 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")); - - if (m_commandLineArgs.portableMode && m_commandLineArgs.relativeFastresumePaths) - Logger::instance()->addMessage(tr("Portable mode implies relative fastresume"), Log::WARNING); -} diff --git a/src/app/application.h b/src/app/application.h index 26384c74c..da9dc4168 100644 --- a/src/app/application.h +++ b/src/app/application.h @@ -144,5 +144,4 @@ private: void processParams(const QStringList ¶ms); void runExternalProgram(const BitTorrent::TorrentHandle *torrent) const; void sendNotificationEmail(const BitTorrent::TorrentHandle *torrent); - void validateCommandLineParameters(); }; diff --git a/src/app/cmdoptions.cpp b/src/app/cmdoptions.cpp index c4604177d..c855f6e53 100644 --- a/src/app/cmdoptions.cpp +++ b/src/app/cmdoptions.cpp @@ -318,7 +318,6 @@ namespace constexpr const IntOption WEBUI_PORT_OPTION {"webui-port"}; constexpr const StringOption PROFILE_OPTION {"profile"}; constexpr const StringOption CONFIGURATION_OPTION {"configuration"}; - constexpr const BoolOption PORTABLE_OPTION {"portable"}; constexpr const BoolOption RELATIVE_FASTRESUME {"relative-fastresume"}; constexpr const StringOption SAVE_PATH_OPTION {"save-path"}; constexpr const TriStateBoolOption PAUSED_OPTION {"add-paused", true}; @@ -332,7 +331,6 @@ namespace QBtCommandLineParameters::QBtCommandLineParameters(const QProcessEnvironment &env) : showHelp(false) , relativeFastresumePaths(RELATIVE_FASTRESUME.value(env)) - , portableMode(PORTABLE_OPTION.value(env)) , skipChecking(SKIP_HASH_CHECK_OPTION.value(env)) , sequential(SEQUENTIAL_OPTION.value(env)) , firstLastPiecePriority(FIRST_AND_LAST_OPTION.value(env)) @@ -437,9 +435,6 @@ QBtCommandLineParameters parseCommandLine(const QStringList &args) else if (arg == RELATIVE_FASTRESUME) { result.relativeFastresumePaths = true; } - else if (arg == PORTABLE_OPTION) { - result.portableMode = true; - } else if (arg == CONFIGURATION_OPTION) { result.configurationName = CONFIGURATION_OPTION.value(arg); } @@ -544,9 +539,6 @@ QString makeUsage(const QString &prgName) stream << RELATIVE_FASTRESUME.usage() << wrapText(QObject::tr("Hack into libtorrent fastresume files and make file paths relative " "to the profile directory")) << '\n'; - stream << PORTABLE_OPTION.usage() - << wrapText(QObject::tr("Shortcut for %1", "Shortcut for --profile=/profile --relative-fastresume") - .arg(QLatin1String("--profile=/profile --relative-fastresume"))) << '\n'; stream << Option::padUsageText(QObject::tr("files or URLs")) << wrapText(QObject::tr("Download the torrents passed by the user")) << '\n' << '\n'; diff --git a/src/app/cmdoptions.h b/src/app/cmdoptions.h index dec975951..5ae297f8d 100644 --- a/src/app/cmdoptions.h +++ b/src/app/cmdoptions.h @@ -42,7 +42,7 @@ class QProcessEnvironment; struct QBtCommandLineParameters { - bool showHelp, relativeFastresumePaths, portableMode, skipChecking, sequential, firstLastPiecePriority; + bool showHelp, relativeFastresumePaths, skipChecking, sequential, firstLastPiecePriority; #if !defined(Q_OS_WIN) || defined(DISABLE_GUI) bool showVersion; #endif