File indexing completed on 2025-01-05 04:58:39
0001 /* 0002 * Copyright (C) 2016 Christian Mollekopf <chrigi_1@fastmail.fm> 0003 * 0004 * This program is free software; you can redistribute it and/or modify 0005 * it under the terms of the GNU General Public License as published by 0006 * the Free Software Foundation; either version 2 of the License, or 0007 * (at your option) any later version. 0008 * 0009 * This program is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 * GNU General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU General Public License 0015 * along with this program; if not, write to the 0016 * Free Software Foundation, Inc., 0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 0018 */ 0019 #pragma once 0020 0021 #include <QFileInfo> 0022 #include <QDir> 0023 #include <QDebug> 0024 0025 static bool copyRecursively(const QString &srcFilePath, const QString &tgtFilePath) 0026 { 0027 QFileInfo srcFileInfo(srcFilePath); 0028 if (srcFileInfo.isDir()) { 0029 QDir targetDir(tgtFilePath); 0030 targetDir.cdUp(); 0031 if (!targetDir.mkdir(QFileInfo(srcFilePath).fileName())) { 0032 qWarning() << "Failed to create directory " << tgtFilePath; 0033 return false; 0034 } 0035 QDir sourceDir(srcFilePath); 0036 QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System); 0037 foreach (const QString &fileName, fileNames) { 0038 const QString newSrcFilePath = srcFilePath + QLatin1Char('/') + fileName; 0039 const QString newTgtFilePath = tgtFilePath + QLatin1Char('/') + fileName; 0040 if (!copyRecursively(newSrcFilePath, newTgtFilePath)) 0041 return false; 0042 } 0043 } else { 0044 if (!QFile::copy(srcFilePath, tgtFilePath)) { 0045 qWarning() << "Failed to copy file " << tgtFilePath; 0046 return false; 0047 } 0048 } 0049 return true; 0050 }