mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 08:36:52 +08:00
refs #392 XBus copy feature fine tuning
* New method: CFileUtils::copyRecursively() * Copy the XBus directory to X-Plane plugins
This commit is contained in:
committed by
Mathew Sutcliffe
parent
3781cf2095
commit
3dd86d4984
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user