QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCFileHelper.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QByteArray>
4#include <QtCore/QCryptographicHash>
5#include <QtCore/QString>
6#include <QtCore/QTemporaryFile>
7#include <QtCore/QUrl>
8
9#include <memory>
10
12namespace QGCFileHelper {
13
15QByteArray readFile(const QString &filePath, QString *errorString = nullptr,
16 qint64 maxBytes = 0);
17
18// ============================================================================
19// Buffer Configuration
20// ============================================================================
21
23constexpr size_t kBufferSizeMin = 16384; // 16KB
24
26constexpr size_t kBufferSizeMax = 131072; // 128KB
27
29constexpr size_t kBufferSizeDefault = 65536; // 64KB
30
35size_t optimalBufferSize(const QString &path = QString());
36
37// ============================================================================
38// Path Utilities
39// ============================================================================
40
44bool exists(const QString &path);
45
51QString joinPath(const QString &dir, const QString &name);
52
56bool ensureDirectoryExists(const QString &path);
57
61bool ensureParentExists(const QString &filePath);
62
67bool copyDirectoryRecursively(const QString &sourcePath, const QString &destPath);
68
73bool moveFileOrCopy(const QString &sourcePath, const QString &destPath);
74
75// ============================================================================
76// Safe File Operations
77// ============================================================================
78
84bool atomicWrite(const QString &filePath, const QByteArray &data);
85
86// ============================================================================
87// Disk Space Utilities
88// ============================================================================
89
95bool hasSufficientDiskSpace(const QString &path, qint64 requiredBytes, double margin = 1.1);
96
100qint64 availableDiskSpace(const QString &path);
101
102// ============================================================================
103// URL/Path Utilities
104// ============================================================================
105
110QString toLocalPath(const QString &urlOrPath);
111
113QString toLocalPath(const QUrl &url);
114
118bool isLocalPath(const QString &urlOrPath);
119
123bool isQtResource(const QString &path);
124
125// ============================================================================
126// Checksum Utilities
127// ============================================================================
128
130constexpr QCryptographicHash::Algorithm kDefaultHashAlgorithm = QCryptographicHash::Sha256;
131
136QString computeFileHash(const QString &filePath,
137 QCryptographicHash::Algorithm algorithm = kDefaultHashAlgorithm);
138
143QString computeHash(const QByteArray &data,
144 QCryptographicHash::Algorithm algorithm = kDefaultHashAlgorithm);
145
151bool verifyFileHash(const QString &filePath, const QString &expectedHash,
152 QCryptographicHash::Algorithm algorithm = kDefaultHashAlgorithm);
153
157QString hashAlgorithmName(QCryptographicHash::Algorithm algorithm);
158
159// ============================================================================
160// Temporary File Utilities
161// ============================================================================
162
168std::unique_ptr<QTemporaryFile> createTempFile(const QByteArray &data,
169 const QString &templateName = QString());
170
175std::unique_ptr<QTemporaryFile> createTempCopy(const QString &sourcePath,
176 const QString &templateName = QString());
177
180QString tempDirectory();
181
186QString uniqueTempPath(const QString &templateName = QString());
187
194bool replaceFileFromTemp(QTemporaryFile *tempFile, const QString &targetPath,
195 const QString &backupPath = QString());
196
197} // namespace QGCFileHelper
QString errorString
Generic file system helper utilities.
qint64 availableDiskSpace(const QString &path)
bool isLocalPath(const QString &urlOrPath)
bool isQtResource(const QString &path)
QString uniqueTempPath(const QString &templateName)
constexpr size_t kBufferSizeMax
Maximum buffer size for I/O operations.
bool ensureParentExists(const QString &filePath)
bool moveFileOrCopy(const QString &sourcePath, const QString &destPath)
QString hashAlgorithmName(QCryptographicHash::Algorithm algorithm)
QString computeHash(const QByteArray &data, QCryptographicHash::Algorithm algorithm)
QByteArray readFile(const QString &filePath, QString *errorString, qint64 maxBytes)
Read raw file contents.
bool copyDirectoryRecursively(const QString &sourcePath, const QString &destPath)
std::unique_ptr< QTemporaryFile > createTempCopy(const QString &sourcePath, const QString &templateName)
bool atomicWrite(const QString &filePath, const QByteArray &data)
QString toLocalPath(const QString &urlOrPath)
bool hasSufficientDiskSpace(const QString &path, qint64 requiredBytes, double margin)
bool ensureDirectoryExists(const QString &path)
constexpr QCryptographicHash::Algorithm kDefaultHashAlgorithm
Default hash algorithm for checksum operations.
std::unique_ptr< QTemporaryFile > createTempFile(const QByteArray &data, const QString &templateName)
QString joinPath(const QString &dir, const QString &name)
bool exists(const QString &path)
QString computeFileHash(const QString &filePath, QCryptographicHash::Algorithm algorithm)
constexpr size_t kBufferSizeMin
Minimum buffer size for I/O operations.
size_t optimalBufferSize(const QString &path)
bool replaceFileFromTemp(QTemporaryFile *tempFile, const QString &targetPath, const QString &backupPath)
bool verifyFileHash(const QString &filePath, const QString &expectedHash, QCryptographicHash::Algorithm algorithm)
QString tempDirectory()
constexpr size_t kBufferSizeDefault
Default buffer size when detection unavailable.