From 206c70eef30f7b6f538b88f7fb9505f397bef073 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 23 Aug 2012 17:23:26 +0200 Subject: fdo#46808, Adapt TempFile UNO service to new style Change-Id: Ia448d6d74201e2be487c6d8317f94be3745808aa --- embedserv/source/embed/ed_ipersiststr.cxx | 143 ++++++++++++++---------------- 1 file changed, 67 insertions(+), 76 deletions(-) (limited to 'embedserv') diff --git a/embedserv/source/embed/ed_ipersiststr.cxx b/embedserv/source/embed/ed_ipersiststr.cxx index 45e863a26ab0..9e9ef8ca7f18 100644 --- a/embedserv/source/embed/ed_ipersiststr.cxx +++ b/embedserv/source/embed/ed_ipersiststr.cxx @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -64,51 +65,46 @@ uno::Reference< io::XInputStream > createTempXInStreamFromIStream( if ( !pStream ) return xResult; - const ::rtl::OUString aServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.io.TempFile" ) ); - uno::Reference < io::XOutputStream > xTempOut = uno::Reference < io::XOutputStream > ( - xFactory->createInstance ( aServiceName ), - uno::UNO_QUERY ); - if ( xTempOut.is() ) - { - ULARGE_INTEGER nNewPos; - LARGE_INTEGER aZero = { 0L, 0L }; - HRESULT hr = pStream->Seek( aZero, STREAM_SEEK_SET, &nNewPos ); - if ( FAILED( hr ) ) return xResult; + uno::Reference < io::XOutputStream > xTempOut( io::TempFile::create(comphelper::ComponentContext(xFactory).getUNOContext()), + uno::UNO_QUERY_THROW ); + ULARGE_INTEGER nNewPos; + LARGE_INTEGER aZero = { 0L, 0L }; + HRESULT hr = pStream->Seek( aZero, STREAM_SEEK_SET, &nNewPos ); + if ( FAILED( hr ) ) return xResult; - STATSTG aStat; - hr = pStream->Stat( &aStat, STATFLAG_NONAME ); - if ( FAILED( hr ) ) return xResult; + STATSTG aStat; + hr = pStream->Stat( &aStat, STATFLAG_NONAME ); + if ( FAILED( hr ) ) return xResult; - sal_uInt32 nSize = (sal_uInt32)aStat.cbSize.QuadPart; - sal_uInt32 nCopied = 0; - uno::Sequence< sal_Int8 > aBuffer( nConstBufferSize ); - try + sal_uInt32 nSize = (sal_uInt32)aStat.cbSize.QuadPart; + sal_uInt32 nCopied = 0; + uno::Sequence< sal_Int8 > aBuffer( nConstBufferSize ); + try + { + sal_uInt32 nRead = 0; + do { - sal_uInt32 nRead = 0; - do - { - pStream->Read( (void*)aBuffer.getArray(), nConstBufferSize, &nRead ); + pStream->Read( (void*)aBuffer.getArray(), nConstBufferSize, &nRead ); - if ( nRead < nConstBufferSize ) - aBuffer.realloc( nRead ); + if ( nRead < nConstBufferSize ) + aBuffer.realloc( nRead ); - xTempOut->writeBytes( aBuffer ); - nCopied += nRead; - } while( nRead == nConstBufferSize ); + xTempOut->writeBytes( aBuffer ); + nCopied += nRead; + } while( nRead == nConstBufferSize ); - if ( nCopied == nSize ) + if ( nCopied == nSize ) + { + uno::Reference < io::XSeekable > xTempSeek ( xTempOut, uno::UNO_QUERY ); + if ( xTempSeek.is() ) { - uno::Reference < io::XSeekable > xTempSeek ( xTempOut, uno::UNO_QUERY ); - if ( xTempSeek.is() ) - { - xTempSeek->seek ( 0 ); - xResult = uno::Reference< io::XInputStream >( xTempOut, uno::UNO_QUERY ); - } + xTempSeek->seek ( 0 ); + xResult = uno::Reference< io::XInputStream >( xTempOut, uno::UNO_QUERY ); } } - catch( const uno::Exception& ) - { - } + } + catch( const uno::Exception& ) + { } return xResult; @@ -620,63 +616,58 @@ STDMETHODIMP EmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad ) HRESULT hr = E_FAIL; - const ::rtl::OUString aServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.io.TempFile" ) ); - uno::Reference < io::XOutputStream > xTempOut = uno::Reference < io::XOutputStream > ( - m_xFactory->createInstance ( aServiceName ), - uno::UNO_QUERY ); + uno::Reference < io::XOutputStream > xTempOut( io::TempFile::create(comphelper::ComponentContext(m_xFactory).getUNOContext()), + uno::UNO_QUERY_THROW ); - if ( xTempOut.is() ) + uno::Reference< frame::XStorable > xStorable( m_pDocHolder->GetDocument(), uno::UNO_QUERY ); + if( xStorable.is() ) { - uno::Reference< frame::XStorable > xStorable( m_pDocHolder->GetDocument(), uno::UNO_QUERY ); - if( xStorable.is() ) + try { - try + xStorable->storeToURL( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "private:stream" ) ), + fillArgsForStoring_Impl( xTempOut ) ); + hr = copyXTempOutToIStream( xTempOut, pTargetStream ); + if ( SUCCEEDED( hr ) ) { - xStorable->storeToURL( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "private:stream" ) ), - fillArgsForStoring_Impl( xTempOut ) ); - hr = copyXTempOutToIStream( xTempOut, pTargetStream ); + // no need to truncate the stream, the size of the stream is always the same + ULARGE_INTEGER nNewPos; + LARGE_INTEGER aZero = { 0L, 0L }; + hr = pNewExtStream->Seek( aZero, STREAM_SEEK_SET, &nNewPos ); if ( SUCCEEDED( hr ) ) { - // no need to truncate the stream, the size of the stream is always the same - ULARGE_INTEGER nNewPos; - LARGE_INTEGER aZero = { 0L, 0L }; - hr = pNewExtStream->Seek( aZero, STREAM_SEEK_SET, &nNewPos ); + SIZEL aSize; + hr = m_pDocHolder->GetExtent( &aSize ); + if ( SUCCEEDED( hr ) ) { - SIZEL aSize; - hr = m_pDocHolder->GetExtent( &aSize ); + sal_uInt32 nWritten; + sal_Int8 aInf[EXT_STREAM_LENGTH]; + *((sal_Int32*)aInf) = 0; + *((sal_Int32*)&aInf[4]) = 0; + *((sal_Int32*)&aInf[8]) = aSize.cx; + *((sal_Int32*)&aInf[12]) = aSize.cy; + + hr = pNewExtStream->Write( (void*)aInf, EXT_STREAM_LENGTH, &nWritten ); + if ( nWritten != EXT_STREAM_LENGTH ) hr = E_FAIL; if ( SUCCEEDED( hr ) ) { - sal_uInt32 nWritten; - sal_Int8 aInf[EXT_STREAM_LENGTH]; - *((sal_Int32*)aInf) = 0; - *((sal_Int32*)&aInf[4]) = 0; - *((sal_Int32*)&aInf[8]) = aSize.cx; - *((sal_Int32*)&aInf[12]) = aSize.cy; - - hr = pNewExtStream->Write( (void*)aInf, EXT_STREAM_LENGTH, &nWritten ); - if ( nWritten != EXT_STREAM_LENGTH ) hr = E_FAIL; - - if ( SUCCEEDED( hr ) ) + m_pOwnStream = CComPtr< IStream >(); + m_pExtStream = CComPtr< IStream >(); + if ( fSameAsLoad || pStgSave == m_pMasterStorage ) { - m_pOwnStream = CComPtr< IStream >(); - m_pExtStream = CComPtr< IStream >(); - if ( fSameAsLoad || pStgSave == m_pMasterStorage ) - { - uno::Reference< util::XModifiable > xMod( m_pDocHolder->GetDocument(), uno::UNO_QUERY ); - if ( xMod.is() ) - xMod->setModified( sal_False ); - m_bIsDirty = sal_False; - } + uno::Reference< util::XModifiable > xMod( m_pDocHolder->GetDocument(), uno::UNO_QUERY ); + if ( xMod.is() ) + xMod->setModified( sal_False ); + m_bIsDirty = sal_False; } } } } } - catch( const uno::Exception& ) - { - } + } + catch( const uno::Exception& ) + { } } -- cgit v1.2.3