diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2020-04-22 10:03:16 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2020-04-27 06:56:36 +0200 |
commit | c5b6bc45d535cdad15d0d614bc3102bdf6cfd856 (patch) | |
tree | b31754b9380f0ce39fa39de68a80480981fcfbfc /vcl/source | |
parent | 25983404aa710990194ca8afa89f91bee879a6be (diff) |
ImpGraphic: move filename handling from swapout to ImpSwapFile
Change-Id: I30930f61385e31e7754d6653ff2eecfea61ce4e1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92945
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/source')
-rw-r--r-- | vcl/source/gdi/impgraph.cxx | 58 |
1 files changed, 35 insertions, 23 deletions
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx index 610d98b9528c..4a3e26946678 100644 --- a/vcl/source/gdi/impgraph.cxx +++ b/vcl/source/gdi/impgraph.cxx @@ -74,8 +74,8 @@ private: OUString maOriginURL; public: - ImpSwapFile(INetURLObject const & aSwapURL, OUString const & rOriginURL) - : maSwapURL(aSwapURL) + ImpSwapFile(INetURLObject const & rSwapURL, OUString const & rOriginURL) + : maSwapURL(rSwapURL) , maOriginURL(rOriginURL) { } @@ -85,8 +85,33 @@ public: utl::UCBContentHelper::Kill(maSwapURL.GetMainURL(INetURLObject::DecodeMechanism::NONE)); } - INetURLObject getSwapURL() { return maSwapURL; } + INetURLObject getSwapURL() + { + return maSwapURL; + } + + OUString getSwapURLString() + { + return maSwapURL.GetMainURL(INetURLObject::DecodeMechanism::NONE); + } + OUString const & getOriginURL() { return maOriginURL; } + + std::unique_ptr<SvStream> openOutputStream() + { + OUString sSwapURL = getSwapURLString(); + if (!sSwapURL.isEmpty()) + { + try + { + return utl::UcbStreamHelper::CreateStream(sSwapURL, StreamMode::READWRITE | StreamMode::SHARE_DENYWRITE); + } + catch (const css::uno::Exception&) + { + } + } + return std::unique_ptr<SvStream>(); + } }; OUString ImpGraphic::getSwapFileURL() @@ -1333,39 +1358,26 @@ bool ImpGraphic::swapOut() utl::TempFile aTempFile; const INetURLObject aTempFileURL(aTempFile.GetURL()); - OUString sTempFileURLString = aTempFileURL.GetMainURL(INetURLObject::DecodeMechanism::NONE); - if (sTempFileURLString.isEmpty()) - return false; - std::unique_ptr<SvStream> xOutputStream; + std::shared_ptr<ImpSwapFile> pSwapFile(new ImpSwapFile(aTempFileURL, getOriginURL()), o3tl::default_delete<ImpSwapFile>()); - try - { - xOutputStream = utl::UcbStreamHelper::CreateStream(sTempFileURLString, StreamMode::READWRITE | StreamMode::SHARE_DENYWRITE); - } - catch (const css::uno::Exception&) - { - } + std::unique_ptr<SvStream> xOutputStream = pSwapFile->openOutputStream(); if (!xOutputStream) return false; + xOutputStream->SetVersion(SOFFICE_FILEFORMAT_50); xOutputStream->SetCompressMode(SvStreamCompressFlags::NATIVE); bool bResult = swapOutToStream(xOutputStream.get()); - if (bResult) - { - mpSwapFile.reset(new ImpSwapFile(aTempFileURL, getOriginURL()), o3tl::default_delete<ImpSwapFile>()); - } - else - { - xOutputStream.reset(); - utl::UCBContentHelper::Kill(sTempFileURLString); - } + xOutputStream.reset(); if (bResult) + { + mpSwapFile = pSwapFile; vcl::graphic::Manager::get().swappedOut(this); + } return bResult; } |