diff options
author | Peng Wu <peng.wu@intopalo.com> | 2015-03-24 14:04:29 +0200 |
---|---|---|
committer | Peng Wu <peng.wu@intopalo.com> | 2015-03-27 13:18:15 +0000 |
commit | c5fd30b28561ffda729ffa016aed2cd216e44236 (patch) | |
tree | f34ca35fa41990b69c94dd1968b70c0e9d64a7c6 | |
parent | c72325d52575cb8a46cc8595c592c27581089dec (diff) |
Implement flush function in WinRT file engine
This is needed by the abstract file engine.
Change-Id: Ia7ceca1be59f00a90e96e97ccd394634bad8b02f
Task-number: QTBUG-44969
Reviewed-by: Andrew Knight <qt@panimo.net>
-rw-r--r-- | src/plugins/platforms/winrt/qwinrtfileengine.cpp | 36 | ||||
-rw-r--r-- | src/plugins/platforms/winrt/qwinrtfileengine.h | 1 |
2 files changed, 29 insertions, 8 deletions
diff --git a/src/plugins/platforms/winrt/qwinrtfileengine.cpp b/src/plugins/platforms/winrt/qwinrtfileengine.cpp index f4e307eb07..719bb18dd6 100644 --- a/src/plugins/platforms/winrt/qwinrtfileengine.cpp +++ b/src/plugins/platforms/winrt/qwinrtfileengine.cpp @@ -70,7 +70,7 @@ class QWinRTFileEnginePrivate { public: QWinRTFileEnginePrivate(const QString &fileName, IStorageItem *file) - : fileName(fileName), file(file) + : fileName(fileName), file(file), openMode(QIODevice::NotOpen) { HRESULT hr; hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Storage_Streams_Buffer).Get(), @@ -101,6 +101,7 @@ public: int firstDot; ComPtr<IStorageItem> file; ComPtr<IRandomAccessStream> stream; + QIODevice::OpenMode openMode; qint64 pos; @@ -203,6 +204,8 @@ bool QWinRTFileEngine::open(QIODevice::OpenMode openMode) hr = QWinRTFunctions::await(op, d->stream.GetAddressOf()); RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::OpenError, false); + d->openMode = openMode; + return SUCCEEDED(hr); } @@ -220,9 +223,33 @@ bool QWinRTFileEngine::close() hr = closable->Close(); RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::UnspecifiedError, false); d->stream.Reset(); + d->openMode = QIODevice::NotOpen; return SUCCEEDED(hr); } +bool QWinRTFileEngine::flush() +{ + Q_D(QWinRTFileEngine); + + if (!d->stream) + return false; + + if (!(d->openMode & QIODevice::WriteOnly)) + return true; + + ComPtr<IOutputStream> stream; + HRESULT hr = d->stream.As(&stream); + RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::WriteError, false); + ComPtr<IAsyncOperation<bool>> flushOp; + hr = stream->FlushAsync(&flushOp); + RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::WriteError, false); + boolean flushed; + hr = QWinRTFunctions::await(flushOp, &flushed); + RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::WriteError, false); + + return true; +} + qint64 QWinRTFileEngine::size() const { Q_D(const QWinRTFileEngine); @@ -484,13 +511,6 @@ qint64 QWinRTFileEngine::write(const char *data, qint64 maxlen) hr = QWinRTFunctions::await(op, &length); RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::WriteError, -1); - ComPtr<IAsyncOperation<bool>> flushOp; - hr = stream->FlushAsync(&flushOp); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::WriteError, -1); - boolean flushed; - hr = QWinRTFunctions::await(flushOp, &flushed); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::WriteError, -1); - return qint64(length); } diff --git a/src/plugins/platforms/winrt/qwinrtfileengine.h b/src/plugins/platforms/winrt/qwinrtfileengine.h index 30357759fb..983338f2e2 100644 --- a/src/plugins/platforms/winrt/qwinrtfileengine.h +++ b/src/plugins/platforms/winrt/qwinrtfileengine.h @@ -71,6 +71,7 @@ public: bool open(QIODevice::OpenMode openMode) Q_DECL_OVERRIDE; bool close() Q_DECL_OVERRIDE; + bool flush() Q_DECL_OVERRIDE; qint64 size() const Q_DECL_OVERRIDE; qint64 pos() const Q_DECL_OVERRIDE; bool seek(qint64 pos) Q_DECL_OVERRIDE; |