refs #392 XBus copy feature fine tuning

* New method: CFileUtils::copyRecursively()
* Copy the XBus directory to X-Plane plugins
This commit is contained in:
Michał Garapich
2015-10-29 22:56:17 +01:00
committed by Mathew Sutcliffe
parent 3781cf2095
commit 3dd86d4984
7 changed files with 85 additions and 14 deletions

View File

@@ -59,4 +59,32 @@ namespace BlackMisc
return QDir::cleanPath(path1 + QDir::separator() + path2);
}
bool CFileUtils::copyRecursively(const QString &sourceDir, const QString &destinationDir)
{
QFileInfo sourceFileInfo(sourceDir);
if (sourceFileInfo.isDir())
{
QDir targetDir(destinationDir);
if (!targetDir.mkpath("."))
{
return false;
}
QDir originDir(sourceFileInfo.absoluteFilePath());
auto fileNames = originDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
for (const QString &fileName: fileNames)
{
if (!copyRecursively(originDir.absoluteFilePath(fileName), targetDir.absoluteFilePath(fileName)))
return false;
}
}
else
{
if (!QFile::copy(sourceDir, destinationDir))
return false;
}
return true;
}
} // ns

View File

@@ -39,6 +39,10 @@ namespace BlackMisc
//! Append file paths
//! \sa CNetworkUtils::buildUrl for URLs
static QString appendFilePaths(const QString &path1, const QString &path2);
//! If `sourceDir` is a directory, copies it recursively, so that `sourceDir` becomes `destinationDir`.
//! If it is a file, just copies the file.
static bool copyRecursively(const QString &sourceDir, const QString &destinationDir);
};
} // ns