From 2606b696539677ddeae1552c00f4e60b23585fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Kov=C3=A1cs?= Date: Tue, 4 Feb 2025 17:03:36 +0100 Subject: [PATCH] Fix copying sword directory --- qt/main.cpp | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/qt/main.cpp b/qt/main.cpp index 8ce8d46..22f967f 100644 --- a/qt/main.cpp +++ b/qt/main.cpp @@ -6,34 +6,21 @@ using namespace std; -// Taken from https://forum.qt.io/topic/105993/copy-folder-qt-c/5 -void copyAndReplaceFolderContents(const QString &fromDir, const QString &toDir, bool copyAndRemove = false) { - QDirIterator it(fromDir, QDirIterator::Subdirectories); - QDir dir(fromDir); - const int absSourcePathLength = dir.absoluteFilePath(fromDir).length(); - - while (it.hasNext()){ - it.next(); - const auto fileInfo = it.fileInfo(); - if(!fileInfo.isHidden()) { //filters dot and dotdot - const QString subPathStructure = fileInfo.absoluteFilePath().mid(absSourcePathLength); - const QString constructedAbsolutePath = toDir + subPathStructure; - - if(fileInfo.isDir()){ - //Create directory in target folder - dir.mkpath(constructedAbsolutePath); - } else if(fileInfo.isFile()) { - //Copy File to target directory +void copyPath(QString src, QString dst) +{ + QDir dir(src); + if (! dir.exists()) + return; - //Remove file at target location, if it exists, or QFile::copy will fail - QFile::remove(constructedAbsolutePath); - QFile::copy(fileInfo.absoluteFilePath(), constructedAbsolutePath); - } - } + foreach (QString d, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) { + QString dst_path = dst + QDir::separator() + d; + dir.mkpath(dst_path); + copyPath(src+ QDir::separator() + d, dst_path); } - if(copyAndRemove) - dir.removeRecursively(); + foreach (QString f, dir.entryList(QDir::Files)) { + QFile::copy(src + QDir::separator() + f, dst + QDir::separator() + f); + } } // This copies the SWORD modules bundle (assumed in Contents/Resources/sword) to ~/.sword. @@ -49,11 +36,12 @@ void copy_sword_files() { return; } QString appDirectory = qApp -> applicationDirPath(); - QString d2 = appDirectory + QDir::separator() + "Resources" + QDir::separator() + "sword"; + QString d2 = appDirectory + QDir::separator() + ".." + QDir::separator() + "Resources" + QDir::separator() + "sword"; const QFileInfo f2(d2); if (f2.exists() && f2.isDir()) { cout << d1.toStdString() << " does not exist, creating it from bundle" << endl; - copyAndReplaceFolderContents(d2, d1, false); + // copyAndReplaceFolderContents(d2, d1, false); + copyPath(d2,d1); } else { cout << d2.toStdString() << " does not exist, expect problems" << endl;