vcl/source/gdi/impgraph.cxx | 76 ++++++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 31 deletions(-)
New commits: commit c5b6bc45d535cdad15d0d614bc3102bdf6cfd856 Author: Tomaž Vajngerl <[email protected]> AuthorDate: Wed Apr 22 10:03:16 2020 +0200 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Mon Apr 27 06:56:36 2020 +0200 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 <[email protected]> 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; } commit 25983404aa710990194ca8afa89f91bee879a6be Author: Tomaž Vajngerl <[email protected]> AuthorDate: Mon Apr 20 22:29:04 2020 +0200 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Mon Apr 27 06:56:22 2020 +0200 ImpGraphic: clean-up and simplify swapOut() Change-Id: I3e578c3172fcea341a218798843cd750971a5af1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92944 Tested-by: Tomaž Vajngerl <[email protected]> Reviewed-by: Tomaž Vajngerl <[email protected]> diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx index 9eb42fec39e8..610d98b9528c 100644 --- a/vcl/source/gdi/impgraph.cxx +++ b/vcl/source/gdi/impgraph.cxx @@ -1328,44 +1328,46 @@ bool ImpGraphic::ImplWriteEmbedded( SvStream& rOStm ) bool ImpGraphic::swapOut() { - - if( isSwappedOut() ) + if (isSwappedOut()) return false; - ::utl::TempFile aTempFile; - const INetURLObject aTmpURL( aTempFile.GetURL() ); + utl::TempFile aTempFile; + const INetURLObject aTempFileURL(aTempFile.GetURL()); + OUString sTempFileURLString = aTempFileURL.GetMainURL(INetURLObject::DecodeMechanism::NONE); - if( aTmpURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ).isEmpty() ) + if (sTempFileURLString.isEmpty()) return false; + std::unique_ptr<SvStream> xOutputStream; - std::unique_ptr<SvStream> xOStm; try { - xOStm = ::utl::UcbStreamHelper::CreateStream( aTmpURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READWRITE | StreamMode::SHARE_DENYWRITE ); + xOutputStream = utl::UcbStreamHelper::CreateStream(sTempFileURLString, StreamMode::READWRITE | StreamMode::SHARE_DENYWRITE); } - catch( const css::uno::Exception& ) + catch (const css::uno::Exception&) { } - if( !xOStm ) + + if (!xOutputStream) return false; + xOutputStream->SetVersion(SOFFICE_FILEFORMAT_50); + xOutputStream->SetCompressMode(SvStreamCompressFlags::NATIVE); - xOStm->SetVersion( SOFFICE_FILEFORMAT_50 ); - xOStm->SetCompressMode( SvStreamCompressFlags::NATIVE ); + bool bResult = swapOutToStream(xOutputStream.get()); - bool bRet = swapOutToStream( xOStm.get() ); - if( bRet ) + if (bResult) { - mpSwapFile.reset(new ImpSwapFile(aTmpURL, getOriginURL()), o3tl::default_delete<ImpSwapFile>()); + mpSwapFile.reset(new ImpSwapFile(aTempFileURL, getOriginURL()), o3tl::default_delete<ImpSwapFile>()); } else { - xOStm.reset(); - utl::UCBContentHelper::Kill(aTmpURL.GetMainURL(INetURLObject::DecodeMechanism::NONE)); + xOutputStream.reset(); + utl::UCBContentHelper::Kill(sTempFileURLString); } - if (bRet) + if (bResult) vcl::graphic::Manager::get().swappedOut(this); - return bRet; + + return bResult; } bool ImpGraphic::swapOutToStream(SvStream* xOStm) _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
