summaryrefslogtreecommitdiffstats
path: root/src/libs/installer/fileutils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/installer/fileutils.cpp')
-rw-r--r--src/libs/installer/fileutils.cpp67
1 files changed, 44 insertions, 23 deletions
diff --git a/src/libs/installer/fileutils.cpp b/src/libs/installer/fileutils.cpp
index 79dc4273e..04a24ad8e 100644
--- a/src/libs/installer/fileutils.cpp
+++ b/src/libs/installer/fileutils.cpp
@@ -181,10 +181,11 @@ void QInstaller::removeFiles(const QString &path, bool ignoreErrors)
QFile f(fi.filePath());
if (!f.remove()) {
const QString errorMessage = QCoreApplication::translate("QInstaller",
- "Could not remove file %1: %2").arg(f.fileName(), f.errorString());
+ "Cannot remove file \"%1\": %2").arg(
+ QDir::toNativeSeparators(f.fileName()), f.errorString());
if (!ignoreErrors)
throw Error(errorMessage);
- qWarning() << errorMessage;
+ qWarning().noquote() << errorMessage;
}
}
}
@@ -222,10 +223,11 @@ void QInstaller::removeDirectory(const QString &path, bool ignoreErrors)
errno = 0;
if (d.exists(path) && !d.rmdir(dir)) {
const QString errorMessage = QCoreApplication::translate("QInstaller",
- "Could not remove folder %1: %2").arg(dir, errnoToQString(errno));
+ "Cannot remove directory \"%1\": %2").arg(QDir::toNativeSeparators(dir),
+ errnoToQString(errno));
if (!ignoreErrors)
throw Error(errorMessage);
- qWarning() << errorMessage;
+ qWarning().noquote() << errorMessage;
}
}
}
@@ -269,7 +271,7 @@ void QInstaller::removeDirectoryThreaded(const QString &path, bool ignoreErrors)
{
RemoveDirectoryThread thread(path, ignoreErrors);
QEventLoop loop;
- QObject::connect(&thread, SIGNAL(finished()), &loop, SLOT(quit()));
+ QObject::connect(&thread, &RemoveDirectoryThread::finished, &loop, &QEventLoop::quit);
thread.start();
loop.exec();
if (!thread.error().isEmpty())
@@ -292,8 +294,8 @@ void QInstaller::copyDirectoryContents(const QString &sourceDir, const QString &
Q_ASSERT(QFileInfo(sourceDir).isDir());
Q_ASSERT(!QFileInfo(targetDir).exists() || QFileInfo(targetDir).isDir());
if (!QDir().mkpath(targetDir)) {
- throw Error(QCoreApplication::translate("QInstaller", "Could not create folder %1")
- .arg(targetDir));
+ throw Error(QCoreApplication::translate("QInstaller", "Cannot create directory \"%1\".")
+ .arg(QDir::toNativeSeparators(targetDir)));
}
QDirIterator it(sourceDir, QDir::NoDotAndDotDot | QDir::AllEntries);
while (it.hasNext()) {
@@ -306,8 +308,10 @@ void QInstaller::copyDirectoryContents(const QString &sourceDir, const QString &
const QString target = QDir(targetDir).absoluteFilePath(i.fileName());
if (!f.copy(target)) {
throw Error(QCoreApplication::translate("QInstaller",
- "Could not copy file from %1 to %2: %3").arg(f.fileName(), target,
- f.errorString()));
+ "Cannot copy file from \"%1\" to \"%2\": %3").arg(
+ QDir::toNativeSeparators(f.fileName()),
+ QDir::toNativeSeparators(target),
+ f.errorString()));
}
}
}
@@ -318,8 +322,8 @@ void QInstaller::moveDirectoryContents(const QString &sourceDir, const QString &
Q_ASSERT(QFileInfo(sourceDir).isDir());
Q_ASSERT(!QFileInfo(targetDir).exists() || QFileInfo(targetDir).isDir());
if (!QDir().mkpath(targetDir)) {
- throw Error(QCoreApplication::translate("QInstaller", "Could not create folder %1")
- .arg(targetDir));
+ throw Error(QCoreApplication::translate("QInstaller", "Cannot create directory \"%1\".")
+ .arg(QDir::toNativeSeparators(targetDir)));
}
QDirIterator it(sourceDir, QDir::NoDotAndDotDot | QDir::AllEntries);
while (it.hasNext()) {
@@ -335,8 +339,10 @@ void QInstaller::moveDirectoryContents(const QString &sourceDir, const QString &
const QString target = QDir(targetDir).absoluteFilePath(i.fileName());
if (!f.rename(target)) {
throw Error(QCoreApplication::translate("QInstaller",
- "Could not move file from %1 to %2: %3").arg(f.fileName(), target,
- f.errorString()));
+ "Cannot move file from \"%1\" to \"%2\": %3").arg(
+ QDir::toNativeSeparators(f.fileName()),
+ QDir::toNativeSeparators(target),
+ f.errorString()));
}
}
}
@@ -346,8 +352,8 @@ void QInstaller::mkdir(const QString &path)
{
errno = 0;
if (!QDir().mkdir(QFileInfo(path).absoluteFilePath())) {
- throw Error(QCoreApplication::translate("QInstaller", "Could not create folder %1: %2")
- .arg(path, errnoToQString(errno)));
+ throw Error(QCoreApplication::translate("QInstaller", "Cannot create directory \"%1\": %2")
+ .arg(QDir::toNativeSeparators(path), errnoToQString(errno)));
}
}
@@ -355,8 +361,8 @@ void QInstaller::mkpath(const QString &path)
{
errno = 0;
if (!QDir().mkpath(QFileInfo(path).absoluteFilePath())) {
- throw Error(QCoreApplication::translate("QInstaller", "Could not create folder %1: %2")
- .arg(path, errnoToQString(errno)));
+ throw Error(QCoreApplication::translate("QInstaller", "Cannot create directory \"%1\": %2")
+ .arg(QDir::toNativeSeparators(path), errnoToQString(errno)));
}
}
@@ -366,7 +372,7 @@ QString QInstaller::generateTemporaryFileName(const QString &templ)
QTemporaryFile f;
if (!f.open()) {
throw Error(QCoreApplication::translate("QInstaller",
- "Could not open temporary file: %1").arg(f.errorString()));
+ "Cannot open temporary file: %1").arg(f.errorString()));
}
return f.fileName();
}
@@ -385,7 +391,7 @@ QString QInstaller::generateTemporaryFileName(const QString &templ)
QFile f(tmp.arg(templ, suffix).arg(count));
if (!f.open(QIODevice::WriteOnly)) {
throw Error(QCoreApplication::translate("QInstaller",
- "Could not open temporary file for template %1: %2").arg(templ, f.errorString()));
+ "Cannot open temporary file for template %1: %2").arg(templ, f.errorString()));
}
f.remove();
return f.fileName();
@@ -486,14 +492,13 @@ void QInstaller::setApplicationIcon(const QString &application, const QString &i
{
QFile iconFile(icon);
if (!iconFile.open(QIODevice::ReadOnly)) {
- qWarning() << QString::fromLatin1("Could not use '%1' as application icon: %2.")
- .arg(icon, iconFile.errorString());
+ qWarning() << "Cannot use" << icon << "as an application icon:" << iconFile.errorString();
return;
}
if (QImageReader::imageFormat(icon) != "ico") {
- qWarning() << QString::fromLatin1("Could not use '%1' as application icon, unsupported format %2.")
- .arg(icon, QLatin1String(QImageReader::imageFormat(icon)));
+ qWarning() << "Cannot use" << icon << "as an application icon, unsupported format"
+ << QImageReader::imageFormat(icon).constData();
return;
}
@@ -579,3 +584,19 @@ bool QInstaller::isInBundle(const QString &path, QString *bundlePath)
#endif
return false;
}
+
+/*!
+ Replaces the path \a before with the path \a after at the beginning of \a path and returns
+ the replaced path. If \a before cannot be found in \a path, the original value is returned.
+*/
+QString QInstaller::replacePath(const QString &path, const QString &before, const QString &after)
+{
+ if (path.isEmpty() || before.isEmpty())
+ return path;
+
+ QString pathToPatch = QDir::cleanPath(path);
+ const QString pathToReplace = QDir::cleanPath(before);
+ if (pathToPatch.startsWith(pathToReplace))
+ return QDir::cleanPath(after) + pathToPatch.mid(pathToReplace.size());
+ return path;
+}