Browse Source

Merge pull request #11614 from Tester798/master

Enable portable mode if "profile" folder exists
adaptive-webui-19844
Mike Tzou 5 years ago committed by GitHub
parent
commit
99c002ae27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      src/app/application.cpp
  2. 1
      src/app/application.h
  3. 8
      src/app/cmdoptions.cpp
  4. 2
      src/app/cmdoptions.h

23
src/app/application.cpp

@ -144,13 +144,13 @@ Application::Application(const QString &id, int &argc, char **argv) @@ -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) @@ -171,6 +171,14 @@ Application::Application(const QString &id, int &argc, char **argv)
m_fileLogger = new FileLogger(fileLoggerPath(), isFileLoggerBackup(), fileLoggerMaxSize(), isFileLoggerDeleteOld(), fileLoggerAge(), static_cast<FileLogger::FileLogAgeType>(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() @@ -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);
}

1
src/app/application.h

@ -144,5 +144,4 @@ private: @@ -144,5 +144,4 @@ private:
void processParams(const QStringList &params);
void runExternalProgram(const BitTorrent::TorrentHandle *torrent) const;
void sendNotificationEmail(const BitTorrent::TorrentHandle *torrent);
void validateCommandLineParameters();
};

8
src/app/cmdoptions.cpp

@ -318,7 +318,6 @@ namespace @@ -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 @@ -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) @@ -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) @@ -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=<exe dir>/profile --relative-fastresume")
.arg(QLatin1String("--profile=<exe dir>/profile --relative-fastresume"))) << '\n';
stream << Option::padUsageText(QObject::tr("files or URLs"))
<< wrapText(QObject::tr("Download the torrents passed by the user")) << '\n'
<< '\n';

2
src/app/cmdoptions.h

@ -42,7 +42,7 @@ class QProcessEnvironment; @@ -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

Loading…
Cancel
Save