| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | /****************************************************************************
 | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2016-01-15 14:58:39 +01:00
										 |  |  | ** Copyright (C) 2016 The Qt Company Ltd. | 
					
						
							|  |  |  | ** Contact: https://www.qt.io/licensing/
 | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | ** This file is part of Qt Creator. | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | ** Commercial License Usage | 
					
						
							|  |  |  | ** Licensees holding valid commercial Qt licenses may use this file in | 
					
						
							|  |  |  | ** accordance with the commercial license agreement provided with the | 
					
						
							|  |  |  | ** Software or, alternatively, in accordance with the terms contained in | 
					
						
							| 
									
										
										
										
											2016-01-15 14:58:39 +01:00
										 |  |  | ** a written agreement between you and The Qt Company. For licensing terms | 
					
						
							|  |  |  | ** and conditions see https://www.qt.io/terms-conditions. For further
 | 
					
						
							|  |  |  | ** information use the contact form at https://www.qt.io/contact-us.
 | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2016-01-15 14:58:39 +01:00
										 |  |  | ** GNU General Public License Usage | 
					
						
							|  |  |  | ** Alternatively, this file may be used under the terms of the GNU | 
					
						
							|  |  |  | ** General Public License version 3 as published by the Free Software | 
					
						
							|  |  |  | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT | 
					
						
							|  |  |  | ** included in the packaging of this file. Please review the following | 
					
						
							|  |  |  | ** information to ensure the GNU General Public License requirements will | 
					
						
							|  |  |  | ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
 | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | ****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-18 07:55:01 +01:00
										 |  |  | #pragma once
 | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "utils_global.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-16 11:16:45 +02:00
										 |  |  | #include "filepath.h"
 | 
					
						
							| 
									
										
										
										
											2017-06-13 14:57:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-15 10:42:41 +01:00
										 |  |  | #include <QCoreApplication>
 | 
					
						
							| 
									
										
										
										
											2020-07-07 10:11:53 +02:00
										 |  |  | #include <QDir>
 | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-16 15:24:26 +02:00
										 |  |  | #ifdef QT_WIDGETS_LIB
 | 
					
						
							|  |  |  | #include <QFileDialog>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-04 20:43:09 +02:00
										 |  |  | #include <functional>
 | 
					
						
							| 
									
										
										
										
											2017-06-29 15:04:01 +02:00
										 |  |  | #include <memory>
 | 
					
						
							| 
									
										
										
										
											2014-09-04 20:43:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  | QT_BEGIN_NAMESPACE | 
					
						
							| 
									
										
										
										
											2014-09-04 20:43:09 +02:00
										 |  |  | class QDataStream; | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  | class QTextStream; | 
					
						
							| 
									
										
										
										
											2014-09-04 20:43:09 +02:00
										 |  |  | class QWidget; | 
					
						
							| 
									
										
										
										
											2022-05-24 00:40:44 +02:00
										 |  |  | class QXmlStreamWriter; | 
					
						
							| 
									
										
										
										
											2014-02-13 11:49:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-05 14:22:26 +02:00
										 |  |  | // for withNtfsPermissions
 | 
					
						
							| 
									
										
										
										
											2017-05-24 15:31:40 +02:00
										 |  |  | #ifdef Q_OS_WIN
 | 
					
						
							|  |  |  | extern Q_CORE_EXPORT int qt_ntfs_permission_lookup; | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  | QT_END_NAMESPACE | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Utils { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-09 08:53:40 +02:00
										 |  |  | class QTCREATOR_UTILS_EXPORT FileUtils | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-07-05 12:59:14 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-06-11 15:41:26 +02:00
										 |  |  | #ifdef QT_GUI_LIB
 | 
					
						
							|  |  |  |     class QTCREATOR_UTILS_EXPORT CopyAskingForOverwrite | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     public: | 
					
						
							| 
									
										
										
										
											2021-02-12 16:06:24 +01:00
										 |  |  |         CopyAskingForOverwrite(QWidget *dialogParent, | 
					
						
							| 
									
										
										
										
											2021-08-09 08:53:40 +02:00
										 |  |  |                                const std::function<void(FilePath)> &postOperation = {}); | 
					
						
							|  |  |  |         bool operator()(const FilePath &src, const FilePath &dest, QString *error); | 
					
						
							| 
									
										
										
										
											2022-07-21 15:58:09 +02:00
										 |  |  |         FilePaths files() const; | 
					
						
							| 
									
										
										
										
											2020-06-11 15:41:26 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     private: | 
					
						
							|  |  |  |         QWidget *m_parent; | 
					
						
							| 
									
										
										
										
											2021-08-09 08:53:40 +02:00
										 |  |  |         FilePaths m_files; | 
					
						
							|  |  |  |         std::function<void(FilePath)> m_postOperation; | 
					
						
							| 
									
										
										
										
											2020-06-11 15:41:26 +02:00
										 |  |  |         bool m_overwriteAll = false; | 
					
						
							|  |  |  |         bool m_skipAll = false; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | #endif // QT_GUI_LIB
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-07 10:11:53 +02:00
										 |  |  |     static bool copyRecursively(const FilePath &srcFilePath, | 
					
						
							|  |  |  |                                 const FilePath &tgtFilePath, | 
					
						
							|  |  |  |                                 QString *error = nullptr); | 
					
						
							|  |  |  |     template<typename T> | 
					
						
							|  |  |  |     static bool copyRecursively(const FilePath &srcFilePath, | 
					
						
							|  |  |  |                                 const FilePath &tgtFilePath, | 
					
						
							|  |  |  |                                 QString *error, | 
					
						
							|  |  |  |                                 T &©Helper); | 
					
						
							| 
									
										
										
										
											2021-01-11 15:57:16 +01:00
										 |  |  |     static bool copyIfDifferent(const FilePath &srcFilePath, | 
					
						
							|  |  |  |                                 const FilePath &tgtFilePath); | 
					
						
							| 
									
										
										
										
											2013-08-16 17:10:45 +02:00
										 |  |  |     static QString fileSystemFriendlyName(const QString &name); | 
					
						
							| 
									
										
										
										
											2013-12-09 12:56:24 +01:00
										 |  |  |     static int indexOfQmakeUnfriendly(const QString &name, int startpos = 0); | 
					
						
							|  |  |  |     static QString qmakeFriendlyName(const QString &name); | 
					
						
							| 
									
										
										
										
											2019-05-28 13:49:26 +02:00
										 |  |  |     static bool makeWritable(const FilePath &path); | 
					
						
							| 
									
										
										
										
											2021-08-23 12:53:47 +02:00
										 |  |  |     static QString normalizedPathName(const QString &name); | 
					
						
							| 
									
										
										
										
											2014-04-11 17:45:11 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     static bool isRelativePath(const QString &fileName); | 
					
						
							|  |  |  |     static bool isAbsolutePath(const QString &fileName) { return !isRelativePath(fileName); } | 
					
						
							| 
									
										
										
										
											2019-05-28 13:49:26 +02:00
										 |  |  |     static FilePath commonPath(const FilePath &oldCommonPath, const FilePath &fileName); | 
					
						
							| 
									
										
										
										
											2022-07-21 18:23:27 +02:00
										 |  |  |     static FilePath commonPath(const FilePaths &paths); | 
					
						
							| 
									
										
										
										
											2019-05-28 13:49:26 +02:00
										 |  |  |     static QByteArray fileId(const FilePath &fileName); | 
					
						
							| 
									
										
										
										
											2021-06-08 13:51:34 +02:00
										 |  |  |     static FilePath homePath(); | 
					
						
							| 
									
										
										
										
											2021-07-16 11:16:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-21 13:11:39 +01:00
										 |  |  |     static void iterateLsOutput(const FilePath &base, | 
					
						
							|  |  |  |                                 const QStringList &entries, | 
					
						
							|  |  |  |                                 const FileFilter &filter, | 
					
						
							|  |  |  |                                 const std::function<bool(const FilePath &)> &callBack); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-16 15:24:26 +02:00
										 |  |  | #ifdef QT_WIDGETS_LIB
 | 
					
						
							|  |  |  |     static void setDialogParentGetter(const std::function<QWidget *()> &getter); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-11 09:01:53 +02:00
										 |  |  |     static FilePath getOpenFilePath(QWidget *parent, | 
					
						
							|  |  |  |                                     const QString &caption, | 
					
						
							| 
									
										
										
										
											2021-07-16 15:24:26 +02:00
										 |  |  |                                     const FilePath &dir = {}, | 
					
						
							|  |  |  |                                     const QString &filter = {}, | 
					
						
							|  |  |  |                                     QString *selectedFilter = nullptr, | 
					
						
							| 
									
										
										
										
											2022-05-31 11:16:44 +02:00
										 |  |  |                                     QFileDialog::Options options = {}, | 
					
						
							|  |  |  |                                     bool fromDeviceIfShiftIsPressed = false); | 
					
						
							| 
									
										
										
										
											2021-07-16 15:24:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-11 09:01:53 +02:00
										 |  |  |     static FilePath getSaveFilePath(QWidget *parent, | 
					
						
							|  |  |  |                                     const QString &caption, | 
					
						
							| 
									
										
										
										
											2021-07-16 15:24:26 +02:00
										 |  |  |                                     const FilePath &dir = {}, | 
					
						
							|  |  |  |                                     const QString &filter = {}, | 
					
						
							|  |  |  |                                     QString *selectedFilter = nullptr, | 
					
						
							|  |  |  |                                     QFileDialog::Options options = {}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-11 09:01:53 +02:00
										 |  |  |     static FilePath getExistingDirectory(QWidget *parent, | 
					
						
							|  |  |  |                                          const QString &caption, | 
					
						
							| 
									
										
										
										
											2021-07-16 15:24:26 +02:00
										 |  |  |                                          const FilePath &dir = {}, | 
					
						
							|  |  |  |                                          QFileDialog::Options options = QFileDialog::ShowDirsOnly); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-11 09:01:53 +02:00
										 |  |  |     static FilePaths getOpenFilePaths(QWidget *parent, | 
					
						
							|  |  |  |                                       const QString &caption, | 
					
						
							| 
									
										
										
										
											2021-07-16 15:24:26 +02:00
										 |  |  |                                       const FilePath &dir = {}, | 
					
						
							|  |  |  |                                       const QString &filter = {}, | 
					
						
							|  |  |  |                                       QString *selectedFilter = nullptr, | 
					
						
							|  |  |  |                                       QFileDialog::Options options = {}); | 
					
						
							| 
									
										
										
										
											2022-05-31 11:16:44 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     static FilePath getOpenFilePathFromDevice(QWidget *parent, | 
					
						
							|  |  |  |                                               const QString &caption, | 
					
						
							|  |  |  |                                               const FilePath &dir = {}, | 
					
						
							|  |  |  |                                               const QString &filter = {}, | 
					
						
							|  |  |  |                                               QString *selectedFilter = nullptr, | 
					
						
							|  |  |  |                                               QFileDialog::Options options = {}); | 
					
						
							| 
									
										
										
										
											2021-07-16 15:24:26 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2022-01-21 13:11:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-05 12:59:14 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-07 10:11:53 +02:00
										 |  |  | template<typename T> | 
					
						
							|  |  |  | bool FileUtils::copyRecursively(const FilePath &srcFilePath, | 
					
						
							|  |  |  |                                 const FilePath &tgtFilePath, | 
					
						
							|  |  |  |                                 QString *error, | 
					
						
							|  |  |  |                                 T &©Helper) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-08-09 08:53:40 +02:00
										 |  |  |     if (srcFilePath.isDir()) { | 
					
						
							| 
									
										
										
										
											2020-07-07 10:11:53 +02:00
										 |  |  |         if (!tgtFilePath.exists()) { | 
					
						
							| 
									
										
										
										
											2021-08-10 10:07:54 +02:00
										 |  |  |             if (!tgtFilePath.ensureWritableDir()) { | 
					
						
							| 
									
										
										
										
											2020-07-07 10:11:53 +02:00
										 |  |  |                 if (error) { | 
					
						
							|  |  |  |                     *error = QCoreApplication::translate("Utils::FileUtils", | 
					
						
							|  |  |  |                                                          "Failed to create directory \"%1\".") | 
					
						
							|  |  |  |                                  .arg(tgtFilePath.toUserOutput()); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 return false; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         const QDir sourceDir(srcFilePath.toString()); | 
					
						
							|  |  |  |         const QStringList fileNames = sourceDir.entryList( | 
					
						
							|  |  |  |             QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System); | 
					
						
							|  |  |  |         for (const QString &fileName : fileNames) { | 
					
						
							|  |  |  |             const FilePath newSrcFilePath = srcFilePath / fileName; | 
					
						
							|  |  |  |             const FilePath newTgtFilePath = tgtFilePath / fileName; | 
					
						
							|  |  |  |             if (!copyRecursively(newSrcFilePath, newTgtFilePath, error, copyHelper)) | 
					
						
							|  |  |  |                 return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2021-08-09 08:53:40 +02:00
										 |  |  |         if (!copyHelper(srcFilePath, tgtFilePath, error)) | 
					
						
							| 
									
										
										
										
											2020-07-07 10:11:53 +02:00
										 |  |  |             return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-24 15:31:40 +02:00
										 |  |  | // for actually finding out if e.g. directories are writable on Windows
 | 
					
						
							|  |  |  | #ifdef Q_OS_WIN
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template <typename T> | 
					
						
							| 
									
										
										
										
											2018-06-05 14:22:26 +02:00
										 |  |  | T withNtfsPermissions(const std::function<T()> &task) | 
					
						
							| 
									
										
										
										
											2017-05-24 15:31:40 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     qt_ntfs_permission_lookup++; | 
					
						
							|  |  |  |     T result = task(); | 
					
						
							|  |  |  |     qt_ntfs_permission_lookup--; | 
					
						
							|  |  |  |     return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-19 15:37:39 +01:00
										 |  |  | template <> | 
					
						
							| 
									
										
										
										
											2018-06-05 14:22:26 +02:00
										 |  |  | QTCREATOR_UTILS_EXPORT void withNtfsPermissions(const std::function<void()> &task); | 
					
						
							| 
									
										
										
										
											2018-02-19 15:37:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-24 15:31:40 +02:00
										 |  |  | #else // Q_OS_WIN
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template <typename T> | 
					
						
							| 
									
										
										
										
											2018-06-05 14:22:26 +02:00
										 |  |  | T withNtfsPermissions(const std::function<T()> &task) | 
					
						
							| 
									
										
										
										
											2017-05-24 15:31:40 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     return task(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // Q_OS_WIN
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  | class QTCREATOR_UTILS_EXPORT FileReader | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-14 12:22:14 +02:00
										 |  |  |     Q_DECLARE_TR_FUNCTIONS(Utils::FileUtils) // sic!
 | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  | public: | 
					
						
							|  |  |  |     static QByteArray fetchQrc(const QString &fileName); // Only for internal resources
 | 
					
						
							| 
									
										
										
										
											2021-05-18 09:47:07 +02:00
										 |  |  |     bool fetch(const FilePath &filePath, QIODevice::OpenMode mode = QIODevice::NotOpen); // QIODevice::ReadOnly is implicit
 | 
					
						
							|  |  |  |     bool fetch(const FilePath &filePath, QIODevice::OpenMode mode, QString *errorString); | 
					
						
							|  |  |  |     bool fetch(const FilePath &filePath, QString *errorString) | 
					
						
							|  |  |  |         { return fetch(filePath, QIODevice::NotOpen, errorString); } | 
					
						
							| 
									
										
										
										
											2017-08-18 14:32:39 +02:00
										 |  |  | #ifdef QT_GUI_LIB
 | 
					
						
							| 
									
										
										
										
											2021-05-18 09:47:07 +02:00
										 |  |  |     bool fetch(const FilePath &filePath, QIODevice::OpenMode mode, QWidget *parent); | 
					
						
							|  |  |  |     bool fetch(const FilePath &filePath, QWidget *parent) | 
					
						
							|  |  |  |         { return fetch(filePath, QIODevice::NotOpen, parent); } | 
					
						
							| 
									
										
										
										
											2017-08-18 14:32:39 +02:00
										 |  |  | #endif // QT_GUI_LIB
 | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  |     const QByteArray &data() const { return m_data; } | 
					
						
							|  |  |  |     const QString &errorString() const { return m_errorString; } | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     QByteArray m_data; | 
					
						
							|  |  |  |     QString m_errorString; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class QTCREATOR_UTILS_EXPORT FileSaverBase | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-14 12:22:14 +02:00
										 |  |  |     Q_DECLARE_TR_FUNCTIONS(Utils::FileUtils) // sic!
 | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  | public: | 
					
						
							|  |  |  |     FileSaverBase(); | 
					
						
							| 
									
										
										
										
											2017-07-03 12:02:26 +02:00
										 |  |  |     virtual ~FileSaverBase(); | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-18 09:47:07 +02:00
										 |  |  |     FilePath filePath() const { return m_filePath; } | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  |     bool hasError() const { return m_hasError; } | 
					
						
							|  |  |  |     QString errorString() const { return m_errorString; } | 
					
						
							|  |  |  |     virtual bool finalize(); | 
					
						
							|  |  |  |     bool finalize(QString *errStr); | 
					
						
							| 
									
										
										
										
											2017-08-18 14:32:39 +02:00
										 |  |  | #ifdef QT_GUI_LIB
 | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  |     bool finalize(QWidget *parent); | 
					
						
							| 
									
										
										
										
											2017-08-18 14:32:39 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     bool write(const char *data, int len); | 
					
						
							|  |  |  |     bool write(const QByteArray &bytes); | 
					
						
							|  |  |  |     bool setResult(QTextStream *stream); | 
					
						
							|  |  |  |     bool setResult(QDataStream *stream); | 
					
						
							|  |  |  |     bool setResult(QXmlStreamWriter *stream); | 
					
						
							|  |  |  |     bool setResult(bool ok); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-29 15:04:01 +02:00
										 |  |  |     QFile *file() { return m_file.get(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  | protected: | 
					
						
							| 
									
										
										
										
											2017-06-29 15:04:01 +02:00
										 |  |  |     std::unique_ptr<QFile> m_file; | 
					
						
							| 
									
										
										
										
											2021-05-18 09:47:07 +02:00
										 |  |  |     FilePath m_filePath; | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  |     QString m_errorString; | 
					
						
							| 
									
										
										
										
											2018-07-23 10:45:40 +02:00
										 |  |  |     bool m_hasError = false; | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     Q_DISABLE_COPY(FileSaverBase) | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class QTCREATOR_UTILS_EXPORT FileSaver : public FileSaverBase | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-14 12:22:14 +02:00
										 |  |  |     Q_DECLARE_TR_FUNCTIONS(Utils::FileUtils) // sic!
 | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2018-05-07 15:07:21 +02:00
										 |  |  |     // QIODevice::WriteOnly is implicit
 | 
					
						
							| 
									
										
										
										
											2021-05-18 09:47:07 +02:00
										 |  |  |     explicit FileSaver(const FilePath &filePath, QIODevice::OpenMode mode = QIODevice::NotOpen); | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-07 15:07:21 +02:00
										 |  |  |     bool finalize() override; | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  |     using FileSaverBase::finalize; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2021-08-09 08:09:39 +02:00
										 |  |  |     bool m_isSafe = false; | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class QTCREATOR_UTILS_EXPORT TempFileSaver : public FileSaverBase | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-14 12:22:14 +02:00
										 |  |  |     Q_DECLARE_TR_FUNCTIONS(Utils::FileUtils) // sic!
 | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  | public: | 
					
						
							|  |  |  |     explicit TempFileSaver(const QString &templ = QString()); | 
					
						
							| 
									
										
										
										
											2018-05-07 15:07:21 +02:00
										 |  |  |     ~TempFileSaver() override; | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void setAutoRemove(bool on) { m_autoRemove = on; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2018-07-23 10:45:40 +02:00
										 |  |  |     bool m_autoRemove = true; | 
					
						
							| 
									
										
										
										
											2011-03-30 12:06:05 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-16 11:16:45 +02:00
										 |  |  | QTCREATOR_UTILS_EXPORT QTextStream &operator<<(QTextStream &s, const FilePath &fn); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-26 13:32:07 +02:00
										 |  |  | bool isRelativePathHelper(const QString &path, OsType osType); | 
					
						
							|  |  |  | QString doCleanPath(const QString &input); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-10 12:23:27 +02:00
										 |  |  | } // namespace Utils
 | 
					
						
							| 
									
										
										
										
											2011-11-08 18:06:45 +01:00
										 |  |  | 
 |