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:
Eugene Shalygin
2016-05-13 20:32:47 +02:00
parent 0710a59bf5
commit a8d95dd8bd
9 changed files with 127 additions and 21 deletions

View File

@@ -36,8 +36,9 @@
Profile *Profile::m_instance = nullptr;
Profile::Profile(Private::Profile *impl)
: m_impl(impl)
Profile::Profile(Private::Profile *impl, Private::PathConverter *pathConverter)
: m_profileImpl(impl)
, m_pathConverterImpl(pathConverter)
{
ensureDirectoryExists(SpecialFolder::Cache);
ensureDirectoryExists(SpecialFolder::Config);
@@ -48,11 +49,17 @@ Profile::Profile(Private::Profile *impl)
// to generate correct call to ProfilePrivate::~ProfileImpl()
Profile::~Profile() = default;
void Profile::initialize(const QString &rootProfilePath, const QString &configurationName)
void Profile::initialize(const QString &rootProfilePath, const QString &configurationName,
bool convertPathsToProfileRelative)
{
m_instance = new Profile(rootProfilePath.isEmpty()
? static_cast<Private::Profile *>(new Private::DefaultProfile(configurationName))
: static_cast<Private::Profile *>(new Private::CustomProfile(rootProfilePath, configurationName)));
QScopedPointer<Private::Profile> profile(rootProfilePath.isEmpty()
? static_cast<Private::Profile *>(new Private::DefaultProfile(configurationName))
: static_cast<Private::Profile *>(new Private::CustomProfile(rootProfilePath, configurationName)));
QScopedPointer<Private::PathConverter> converter(convertPathsToProfileRelative
? static_cast<Private::PathConverter *>(new Private::Converter(profile->baseDirectory()))
: static_cast<Private::PathConverter *>(new Private::NoConvertConverter()));
m_instance = new Profile(profile.take(), converter.take());
}
const Profile &Profile::instance()
@@ -65,16 +72,16 @@ QString Profile::location(SpecialFolder folder) const
QString result;
switch (folder) {
case SpecialFolder::Cache:
result = m_impl->cacheLocation();
result = m_profileImpl->cacheLocation();
break;
case SpecialFolder::Config:
result = m_impl->configLocation();
result = m_profileImpl->configLocation();
break;
case SpecialFolder::Data:
result = m_impl->dataLocation();
result = m_profileImpl->dataLocation();
break;
case SpecialFolder::Downloads:
result = m_impl->downloadLocation();
result = m_profileImpl->downloadLocation();
break;
}
@@ -85,12 +92,12 @@ QString Profile::location(SpecialFolder folder) const
QString Profile::configurationName() const
{
return m_impl->configurationName();
return m_profileImpl->configurationName();
}
SettingsPtr Profile::applicationSettings(const QString &name) const
{
return m_impl->applicationSettings(name);
return m_profileImpl->applicationSettings(name);
}
void Profile::ensureDirectoryExists(SpecialFolder folder)
@@ -99,3 +106,13 @@ void Profile::ensureDirectoryExists(SpecialFolder folder)
if (!locationPath.isEmpty() && !QDir().mkpath(locationPath))
qFatal("Could not create required directory '%s'", qPrintable(locationPath));
}
QString Profile::toPortablePath(const QString &absolutePath) const
{
return m_pathConverterImpl->toPortablePath(absolutePath);
}
QString Profile::fromPortablePath(const QString &portablePath) const
{
return m_pathConverterImpl->fromPortablePath(portablePath);
}