4#include <QtCore/QDebug>
9using namespace Qt::StringLiterals;
39 if (!QWasmFileEngineHandler::isWasmFileName(fileName))
43 if (singleton->m_files.contains(fileName)) {
44 qstdweb::File file = singleton->m_files.value(fileName);
45 return std::make_unique<QWasmFileEngine>(fileName, file);
46 }
else if (singleton->m_fileSystemFiles.contains(fileName)) {
47 qstdweb::FileSystemFileHandle file = singleton->m_fileSystemFiles.value(fileName);
48 return std::make_unique<QWasmFileEngine>(fileName, file);
58 return QUrl(fileName).scheme() == wasmlocalfileScheme;
64 static std::atomic<uint64_t> sid = 0;
65 const uint64_t id = ++sid;
66 return wasmlocalfileScheme + QStringLiteral(
":/%1/%2").arg(id).arg(nativeFileName);
72 QUrl url(wasmFileName);
73 if (url.scheme() == wasmlocalfileScheme) {
74 QString path = url.path();
76 const qsizetype idx = path.indexOf(u'/', 1);
78 return path.mid(idx + 1);
86 QString nativeFileName = QString::fromStdString(file.name());
87 QString wasmFileName = makeWasmFileName(nativeFileName);
88 singleton->m_files.insert(wasmFileName, file);
95 QString nativeFileName = QString::fromStdString(file.name());
96 QString wasmFileName = makeWasmFileName(nativeFileName);
97 singleton->m_fileSystemFiles.insert(wasmFileName, file);
104 singleton->m_files.remove(fileName);
105 singleton->m_fileSystemFiles.remove(fileName);
110 return singleton->m_files.value(fileName);
115 return singleton->m_fileSystemFiles.value(fileName);
119
120
121
122
145bool QWasmFileEngine::open(QIODevice::OpenMode openMode, std::optional<QFile::Permissions> permissions)
147 Q_UNUSED(permissions);
148 m_openMode = openMode;
151 return m_fileDevice->open(openMode);
152 else if (m_blobDevice)
153 return m_blobDevice->open(openMode);
160 if (m_openMode == QIODevice::NotOpen)
165 m_fileDevice->close();
168 m_blobDevice->close();
171 m_openMode = QIODevice::NotOpen;
188 return m_fileDevice->size();
190 return m_blobDevice->size();
197 return m_fileDevice->pos();
199 return m_blobDevice->pos();
206 return m_fileDevice->seek(pos);
208 return m_blobDevice->seek(pos);
247 std::optional<QFile::Permissions> permissions)
const
250 Q_UNUSED(createParentDirectories);
251 Q_UNUSED(permissions);
258 Q_UNUSED(recurseParentDirectories);
281 return type & (QAbstractFileEngine::FileFlag::ExistsFlag |
282 QAbstractFileEngine::FileFlag::FileType |
283 QAbstractFileEngine::FileFlag::ReadOwnerPerm |
284 QAbstractFileEngine::FileFlag::WriteOwnerPerm);
306 QString native = QWasmFileEngineHandler::nativeFileName(m_fileName);
307 QFileInfo info(native);
308 return info.fileName();
311 case AbsolutePathName:
312 case CanonicalPathName: {
313 QString native = QWasmFileEngineHandler::nativeFileName(m_fileName);
314 QFileInfo info(native);
315 QString path = info.path();
316 return path.isEmpty() ?
"."_L1 : path;
348 if (m_fileName == file)
362 return QAbstractFileEngine::TriStateResult::NotSupported;
366 const QStringList &filterNames)
370 Q_UNUSED(filterNames);
376 if (!(m_openMode & QIODevice::ReadOnly))
380 return m_fileDevice->read(data, maxlen);
382 return m_blobDevice->read(data, maxlen);
388 if (!(m_openMode & QIODevice::ReadOnly))
392 return m_fileDevice->readLine(data, maxlen);
394 return m_blobDevice->readLine(data, maxlen);
400 if (!(m_openMode & QIODevice::WriteOnly))
404 return m_fileDevice->write(data, len);
qstdweb::FileSystemFileHandle getFileSystemFile(const QString fileName)
virtual ~QWasmFileEngineHandler() override
virtual std::unique_ptr< QAbstractFileEngine > create(const QString &fileName) const override
If this file handler can handle fileName, this method creates a file engine and returns it wrapped in...
qstdweb::File getFile(const QString fileName)
The QWasmFileEngine class provides a QAbstractFileEngine for files that has the prefix ':weblocalfile...
virtual bool link(const QString &newName) override
Creates a link from the file currently specified by fileName() to newName.
virtual bool flush() override
Flushes the open file, returning true if successful; otherwise returns false.
virtual qint64 read(char *data, qint64 maxlen) override
Reads a number of characters from the file into data.
virtual void setFileName(const QString &file) override
Sets the file engine's file name to file.
virtual bool rmdir(const QString &dirName, bool recurseParentDirectories) const override
Requests that the directory dirName is deleted from the file system.
virtual bool setSize(qint64 size) override
Requests that the file be set to size size.
virtual bool copy(const QString &newName) override
Copies the contents of this file to a file with the name newName.
virtual uint ownerId(FileOwner) const override
If owner is OwnerUser return the ID of the user who owns the file.
virtual bool caseSensitive() const override
Should return true if the underlying file system is case-sensitive; otherwise return false.
virtual QString fileName(FileName file=DefaultName) const override
Return the file engine's current file name in the format specified by file.
virtual qint64 pos() const override
Returns the current file position.
virtual bool supportsExtension(Extension extension) const override
virtual bool extension(Extension extension, const ExtensionOption *option=nullptr, ExtensionReturn *output=nullptr) override
virtual bool close() override
Closes the file, returning true if successful; otherwise returns false.
virtual bool isSequential() const override
Returns true if the file is a sequential access device; returns false if the file is a direct access ...
virtual bool syncToDisk() override
virtual bool seek(qint64 pos) override
Sets the file position to the given offset.
virtual qint64 write(const char *data, qint64 len) override
Writes len bytes from data to the file.
virtual TriStateResult cloneTo(QAbstractFileEngine *target) override
virtual bool rename(const QString &newName) override
Requests that the file be renamed to newName in the file system.
virtual QByteArray id() const override
virtual QString owner(FileOwner) const override
If owner is OwnerUser return the name of the user who owns the file.
virtual qint64 readLine(char *data, qint64 maxlen) override
This function reads one line, terminated by a '\n' character, from the file info data.
virtual bool setPermissions(uint perms) override
Requests that the file's permissions be set to perms.
virtual int handle() const override
Returns the native file handle for this file engine.
virtual bool remove() override
Requests that the file is deleted from the file system.
virtual IteratorUniquePtr beginEntryList(const QString &path, QDirListing::IteratorFlags filters, const QStringList &filterNames) override
Returns a QAbstractFileEngine::IteratorUniquePtr, that can be used to iterate over the entries in pat...
virtual FileFlags fileFlags(FileFlags type=FileInfoAll) const override
This function should return the set of OR'd flags that are true for the file engine's file,...
virtual bool mkdir(const QString &dirName, bool createParentDirectories, std::optional< QFile::Permissions > permissions=std::nullopt) const override
Requests that the directory dirName be created with the specified permissions.
~QWasmFileEngine() override
virtual qint64 size() const override
Returns the size of the file.
QWasmFileEngine(const QString &fileName, qstdweb::File file)
virtual bool renameOverwrite(const QString &newName) override
virtual bool isRelativePath() const override
Return true if the file referred to by this file engine has a relative path; otherwise return false.
virtual QDateTime fileTime(QFile::FileTime time) const override
If time is BirthTime, return when the file was born (created).
virtual bool setFileTime(const QDateTime &newDate, QFile::FileTime time) override
Combined button and popup list for selecting options.
static constexpr QLatin1StringView wasmlocalfileScheme