mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-01 05:08:05 -06:00
Save relative paths in fastresume files
Conditionally change absolute paths to relative in the fastresume data files. The condition is specified by user via a command line parameter and paths are relative to the profile dir. On Windows the convertion to relative path is performed if the path and the profile are on the same drive only.
This commit is contained in:
@@ -207,3 +207,44 @@ SettingsPtr Private::CustomProfile::applicationSettings(const QString &name) con
|
||||
const QString settingsFileName {QDir(configLocation()).absoluteFilePath(name + QLatin1String(CONF_FILE_EXTENSION))};
|
||||
return SettingsPtr(new QSettings(settingsFileName, QSettings::IniFormat));
|
||||
}
|
||||
|
||||
QString Private::NoConvertConverter::fromPortablePath(const QString &portablePath) const
|
||||
{
|
||||
return portablePath;
|
||||
}
|
||||
|
||||
QString Private::NoConvertConverter::toPortablePath(const QString &path) const
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
Private::Converter::Converter(const QString &basePath)
|
||||
: m_baseDir {basePath}
|
||||
{
|
||||
m_baseDir.makeAbsolute();
|
||||
}
|
||||
|
||||
QString Private::Converter::toPortablePath(const QString &path) const
|
||||
{
|
||||
if (path.isEmpty() || m_baseDir.path().isEmpty())
|
||||
return path;
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
if (QDir::isAbsolutePath(path)) {
|
||||
QChar driveLeter = path[0].toUpper();
|
||||
QChar baseDriveLetter = m_baseDir.path()[0].toUpper();
|
||||
bool onSameDrive = (driveLeter.category() == QChar::Letter_Uppercase) && (driveLeter == baseDriveLetter);
|
||||
if (!onSameDrive)
|
||||
return path;
|
||||
}
|
||||
#endif
|
||||
return m_baseDir.relativeFilePath(path);
|
||||
}
|
||||
|
||||
QString Private::Converter::fromPortablePath(const QString &portablePath) const
|
||||
{
|
||||
if (QDir::isAbsolutePath(portablePath))
|
||||
return portablePath;
|
||||
|
||||
return QDir::cleanPath(m_baseDir.absoluteFilePath(portablePath));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user