|
| 1 | +// SPDX-FileCopyrightText: Team OpenVPI |
| 2 | +// SPDX-License-Identifier: LGPL-3.0-or-later |
| 3 | + |
| 4 | +#ifndef DIFFSCOPE_BATCHPROCESS_FILESYSTEMACCESSINTERFACE_H |
| 5 | +#define DIFFSCOPE_BATCHPROCESS_FILESYSTEMACCESSINTERFACE_H |
| 6 | + |
| 7 | +#include <QByteArray> |
| 8 | +#include <QByteArrayView> |
| 9 | +#include <QJSValue> |
| 10 | +#include <QList> |
| 11 | +#include <QObject> |
| 12 | +#include <QScopedPointer> |
| 13 | +#include <QStringList> |
| 14 | + |
| 15 | +#include <batchprocess/FileSystemHandle.h> |
| 16 | +#include <batchprocess/FileSystemTypes.h> |
| 17 | +#include <batchprocess/batchprocessglobal.h> |
| 18 | + |
| 19 | +namespace BatchProcess { |
| 20 | + |
| 21 | + namespace Internal { |
| 22 | + class BatchProcessPlugin; |
| 23 | + class FileSystemModuleBridge; |
| 24 | + class FileSystemModuleExtension; |
| 25 | + } |
| 26 | + |
| 27 | + class FileSystemAccessInterfacePrivate; |
| 28 | + class ScriptExecutionContext; |
| 29 | + |
| 30 | + class BATCH_PROCESS_EXPORT FileSystemAccessInterface : public QObject { |
| 31 | + Q_OBJECT |
| 32 | + Q_DECLARE_PRIVATE(FileSystemAccessInterface) |
| 33 | + public: |
| 34 | + ~FileSystemAccessInterface() override; |
| 35 | + |
| 36 | + static FileSystemAccessInterface *instance(); |
| 37 | + |
| 38 | + FileSystemPermissionDecision requestPermission(ScriptExecutionContext *context, const FileSystemPermissionRequest &request, FileSystemError *error = nullptr); |
| 39 | + bool hasPermission(ScriptExecutionContext *context, const QString &path, FileAccessMode access, bool recursive = false) const; |
| 40 | + |
| 41 | + FileSystemHandle getFile(ScriptExecutionContext *context, const QString &path, FileAccessMode access = FileAccessMode::Read, FileSystemError *error = nullptr); |
| 42 | + FileSystemHandle getDirectory(ScriptExecutionContext *context, const QString &path, FileAccessMode access = FileAccessMode::Read, bool recursive = false, FileSystemError *error = nullptr); |
| 43 | + FileSystemHandle scriptPackage(ScriptExecutionContext *context, FileSystemError *error = nullptr); |
| 44 | + FileSystemHandle dataDirectory(ScriptExecutionContext *context, FileSystemError *error = nullptr); |
| 45 | + FileSystemHandle temporaryDirectory(ScriptExecutionContext *context, FileSystemError *error = nullptr); |
| 46 | + |
| 47 | + /** Creates a capability after a trusted host component has independently obtained user authorization. */ |
| 48 | + FileSystemHandle createAuthorizedFileHandle(ScriptExecutionContext *context, const QString &path, FileAccessMode access, FileSystemError *error = nullptr); |
| 49 | + /** Creates a capability after a trusted host component has independently obtained user authorization. */ |
| 50 | + FileSystemHandle createAuthorizedDirectoryHandle(ScriptExecutionContext *context, const QString &path, FileAccessMode access, bool recursive, FileSystemError *error = nullptr); |
| 51 | + bool validateHandle(ScriptExecutionContext *context, const FileSystemHandle &handle, FileAccessMode access, FileSystemHandle::Kind expectedKind = FileSystemHandle::Invalid, FileSystemError *error = nullptr) const; |
| 52 | + |
| 53 | + bool stat(ScriptExecutionContext *context, const QString &path, const FileSystemStatOptions &options, FileSystemStat *result, FileSystemError *error = nullptr) const; |
| 54 | + bool stat(ScriptExecutionContext *context, const FileSystemHandle &handle, const FileSystemStatOptions &options, FileSystemStat *result, FileSystemError *error = nullptr) const; |
| 55 | + bool readText(ScriptExecutionContext *context, const FileSystemHandle &handle, const FileTextReadOptions &options, QString *result, FileSystemError *error = nullptr) const; |
| 56 | + bool readBytes(ScriptExecutionContext *context, const FileSystemHandle &handle, const FileBinaryReadOptions &options, QByteArray *result, FileSystemError *error = nullptr) const; |
| 57 | + bool writeText(ScriptExecutionContext *context, const FileSystemHandle &handle, const QString &text, const FileTextWriteOptions &options, FileSystemError *error = nullptr); |
| 58 | + bool writeBytes(ScriptExecutionContext *context, const FileSystemHandle &handle, QByteArrayView data, const FileBinaryWriteOptions &options, FileSystemError *error = nullptr); |
| 59 | + bool entries(ScriptExecutionContext *context, const FileSystemHandle &handle, const FileSystemDirectoryListOptions &options, QList<FileSystemDirectoryEntry> *result, FileSystemError *error = nullptr) const; |
| 60 | + FileSystemHandle childFile(ScriptExecutionContext *context, const FileSystemHandle &directory, const QString &relativePath, FileAccessMode access = FileAccessMode::Read, FileSystemError *error = nullptr); |
| 61 | + FileSystemHandle childDirectory(ScriptExecutionContext *context, const FileSystemHandle &directory, const QString &relativePath, FileSystemError *error = nullptr); |
| 62 | + |
| 63 | + bool createDirectory(ScriptExecutionContext *context, const QString &path, const FileSystemCreateDirectoryOptions &options, FileSystemError *error = nullptr); |
| 64 | + bool copy(ScriptExecutionContext *context, const QString &source, const QString &destination, const FileSystemCopyOptions &options, FileSystemError *error = nullptr); |
| 65 | + bool move(ScriptExecutionContext *context, const QString &source, const QString &destination, const FileSystemMoveOptions &options, FileSystemError *error = nullptr); |
| 66 | + bool remove(ScriptExecutionContext *context, const QString &path, const FileSystemRemoveOptions &options, FileSystemError *error = nullptr); |
| 67 | + bool realPath(ScriptExecutionContext *context, const QString &path, QString *result, FileSystemError *error = nullptr) const; |
| 68 | + |
| 69 | + QString normalize(const QString &path) const; |
| 70 | + bool resolve(ScriptExecutionContext *context, const QStringList &parts, QString *result, FileSystemError *error = nullptr) const; |
| 71 | + bool relative(ScriptExecutionContext *context, const QString &from, const QString &to, QString *result, FileSystemError *error = nullptr) const; |
| 72 | + bool isAbsolute(const QString &path) const; |
| 73 | + QString join(const QStringList &parts) const; |
| 74 | + QString baseName(const QString &path) const; |
| 75 | + QString directoryName(const QString &path) const; |
| 76 | + QString extension(const QString &path) const; |
| 77 | + FileSystemParsedPath parse(const QString &path) const; |
| 78 | + bool format(const FileSystemParsedPath &path, QString *result, FileSystemError *error = nullptr) const; |
| 79 | + bool matchesPattern(ScriptExecutionContext *context, const QString &path, const QString &pattern, bool *result, FileSystemError *error = nullptr) const; |
| 80 | + |
| 81 | + QJSValue toJavaScriptValue(ScriptExecutionContext *context, const FileSystemHandle &handle, FileSystemError *error = nullptr); |
| 82 | + bool fromJavaScriptValue(ScriptExecutionContext *context, const QJSValue &value, FileSystemHandle *handle, FileSystemHandle::Kind expectedKind = FileSystemHandle::Invalid, FileSystemError *error = nullptr) const; |
| 83 | + |
| 84 | + private: |
| 85 | + friend class Internal::BatchProcessPlugin; |
| 86 | + friend class Internal::FileSystemModuleBridge; |
| 87 | + friend class Internal::FileSystemModuleExtension; |
| 88 | + |
| 89 | + explicit FileSystemAccessInterface(QObject *parent = nullptr); |
| 90 | + |
| 91 | + QScopedPointer<FileSystemAccessInterfacePrivate> d_ptr; |
| 92 | + }; |
| 93 | + |
| 94 | +} |
| 95 | + |
| 96 | +#endif // DIFFSCOPE_BATCHPROCESS_FILESYSTEMACCESSINTERFACE_H |
0 commit comments