Kaydet (Commit) 736d7a0d authored tarafından Ivo Hinkelmann's avatar Ivo Hinkelmann

CWS-TOOLING: integrate CWS fwk165

...@@ -39,7 +39,12 @@ namespace beans ...@@ -39,7 +39,12 @@ namespace beans
{ {
struct PropertyValue; struct PropertyValue;
} }
namespace packages
{
class ContentInfo;
}
} } } } } }
class ZipFile; class ZipFile;
class ZipPackage; class ZipPackage;
class ZipOutputStream; class ZipOutputStream;
...@@ -85,6 +90,8 @@ public: ...@@ -85,6 +90,8 @@ public:
void setPackageFormat_Impl( sal_Int32 nFormat ) { m_nFormat = nFormat; } void setPackageFormat_Impl( sal_Int32 nFormat ) { m_nFormat = nFormat; }
void setRemoveOnInsertMode_Impl( sal_Bool bRemove ) { this->mbAllowRemoveOnInsert = bRemove; } void setRemoveOnInsertMode_Impl( sal_Bool bRemove ) { this->mbAllowRemoveOnInsert = bRemove; }
bool saveChild(const rtl::OUString &rShortName, const com::sun::star::packages::ContentInfo &rInfo, rtl::OUString &rPath, std::vector < com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > > &rManList, ZipOutputStream & rZipOut, com::sun::star::uno::Sequence < sal_Int8 > &rEncryptionKey, rtlRandomPool & rRandomPool);
// Recursive functions // Recursive functions
void saveContents(rtl::OUString &rPath, std::vector < com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > > &rManList, ZipOutputStream & rZipOut, com::sun::star::uno::Sequence < sal_Int8 > &rEncryptionKey, rtlRandomPool & rRandomPool) void saveContents(rtl::OUString &rPath, std::vector < com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > > &rManList, ZipOutputStream & rZipOut, com::sun::star::uno::Sequence < sal_Int8 > &rEncryptionKey, rtlRandomPool & rRandomPool)
throw(::com::sun::star::uno::RuntimeException); throw(::com::sun::star::uno::RuntimeException);
......
...@@ -48,8 +48,8 @@ ...@@ -48,8 +48,8 @@
using namespace com::sun::star::packages::zip::ZipConstants; using namespace com::sun::star::packages::zip::ZipConstants;
using namespace com::sun::star::packages::zip; using namespace com::sun::star::packages::zip;
using namespace com::sun::star::container;
using namespace com::sun::star::packages; using namespace com::sun::star::packages;
using namespace com::sun::star::container;
using namespace com::sun::star::beans; using namespace com::sun::star::beans;
using namespace com::sun::star::lang; using namespace com::sun::star::lang;
using namespace com::sun::star::uno; using namespace com::sun::star::uno;
...@@ -305,12 +305,10 @@ static void ImplSetStoredData( ZipEntry & rEntry, Reference < XInputStream> & rS ...@@ -305,12 +305,10 @@ static void ImplSetStoredData( ZipEntry & rEntry, Reference < XInputStream> & rS
rEntry.nCrc = aCRC32.getValue(); rEntry.nCrc = aCRC32.getValue();
} }
void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < PropertyValue > > &rManList, ZipOutputStream & rZipOut, Sequence < sal_Int8 > &rEncryptionKey, rtlRandomPool &rRandomPool) bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo &rInfo, OUString &rPath, std::vector < Sequence < PropertyValue > > &rManList, ZipOutputStream & rZipOut, Sequence < sal_Int8 > &rEncryptionKey, rtlRandomPool &rRandomPool)
throw(RuntimeException)
{ {
sal_Bool bWritingFailed = sal_False; bool bSuccess = true;
ZipPackageFolder *pFolder = NULL;
ZipPackageStream *pStream = NULL;
const OUString sMediaTypeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ); const OUString sMediaTypeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) );
const OUString sVersionProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) ); const OUString sVersionProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) );
const OUString sFullPathProperty ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ); const OUString sFullPathProperty ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) );
...@@ -320,66 +318,26 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr ...@@ -320,66 +318,26 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr
const OUString sSizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) ); const OUString sSizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) );
const OUString sDigestProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) ); const OUString sDigestProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) );
sal_Bool bHaveEncryptionKey = rEncryptionKey.getLength() ? sal_True : sal_False;
if ( maContents.begin() == maContents.end() && rPath.getLength() && m_nFormat != embed::StorageFormats::OFOPXML )
{
// it is an empty subfolder, use workaround to store it
ZipEntry* pTempEntry = new ZipEntry();
ZipPackageFolder::copyZipEntry ( *pTempEntry, aEntry );
pTempEntry->nPathLen = (sal_Int16)( ::rtl::OUStringToOString( rPath, RTL_TEXTENCODING_UTF8 ).getLength() );
pTempEntry->nExtraLen = -1;
pTempEntry->sPath = rPath;
try
{
vos::ORef < EncryptionData > aEmptyEncr;
rZipOut.putNextEntry ( *pTempEntry, aEmptyEncr, sal_False );
rZipOut.rawCloseEntry();
}
catch ( ZipException& )
{
VOS_ENSURE( 0, "Error writing ZipOutputStream" );
bWritingFailed = sal_True;
}
catch ( IOException& )
{
VOS_ENSURE( 0, "Error writing ZipOutputStream" );
bWritingFailed = sal_True;
}
}
for ( ContentHash::const_iterator aCI = maContents.begin(), aEnd = maContents.end();
aCI != aEnd;
aCI++)
{
const OUString &rShortName = (*aCI).first;
const ContentInfo &rInfo = *(*aCI).second;
Sequence < PropertyValue > aPropSet (PKG_SIZE_NOENCR_MNFST); Sequence < PropertyValue > aPropSet (PKG_SIZE_NOENCR_MNFST);
if ( rInfo.bFolder ) OSL_ENSURE( ( rInfo.bFolder && rInfo.pFolder ) || ( !rInfo.bFolder && rInfo.pStream ), "A valid child object is expected!" );
pFolder = rInfo.pFolder;
else
pStream = rInfo.pStream;
if ( rInfo.bFolder ) if ( rInfo.bFolder )
{ {
OUString sTempName = rPath + rShortName + OUString( RTL_CONSTASCII_USTRINGPARAM ( "/" ) ); OUString sTempName = rPath + rShortName + OUString( RTL_CONSTASCII_USTRINGPARAM ( "/" ) );
if ( pFolder->GetMediaType().getLength() ) if ( rInfo.pFolder->GetMediaType().getLength() )
{ {
aPropSet[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty; aPropSet[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty;
aPropSet[PKG_MNFST_MEDIATYPE].Value <<= pFolder->GetMediaType(); aPropSet[PKG_MNFST_MEDIATYPE].Value <<= rInfo.pFolder->GetMediaType();
aPropSet[PKG_MNFST_VERSION].Name = sVersionProperty; aPropSet[PKG_MNFST_VERSION].Name = sVersionProperty;
aPropSet[PKG_MNFST_VERSION].Value <<= pFolder->GetVersion(); aPropSet[PKG_MNFST_VERSION].Value <<= rInfo.pFolder->GetVersion();
aPropSet[PKG_MNFST_FULLPATH].Name = sFullPathProperty; aPropSet[PKG_MNFST_FULLPATH].Name = sFullPathProperty;
aPropSet[PKG_MNFST_FULLPATH].Value <<= sTempName; aPropSet[PKG_MNFST_FULLPATH].Value <<= sTempName;
} }
else else
aPropSet.realloc( 0 ); aPropSet.realloc( 0 );
pFolder->saveContents( sTempName, rManList, rZipOut, rEncryptionKey, rRandomPool); rInfo.pFolder->saveContents( sTempName, rManList, rZipOut, rEncryptionKey, rRandomPool);
} }
else else
{ {
...@@ -391,43 +349,43 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr ...@@ -391,43 +349,43 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr
// In case the entry we are reading is also the entry we are writing, we will // In case the entry we are reading is also the entry we are writing, we will
// store the ZipEntry data in pTempEntry // store the ZipEntry data in pTempEntry
ZipPackageFolder::copyZipEntry ( *pTempEntry, pStream->aEntry ); ZipPackageFolder::copyZipEntry ( *pTempEntry, rInfo.pStream->aEntry );
pTempEntry->sPath = rPath + rShortName; pTempEntry->sPath = rPath + rShortName;
pTempEntry->nPathLen = (sal_Int16)( ::rtl::OUStringToOString( pTempEntry->sPath, RTL_TEXTENCODING_UTF8 ).getLength() ); pTempEntry->nPathLen = (sal_Int16)( ::rtl::OUStringToOString( pTempEntry->sPath, RTL_TEXTENCODING_UTF8 ).getLength() );
sal_Bool bToBeEncrypted = pStream->IsToBeEncrypted() && (bHaveEncryptionKey || pStream->HasOwnKey()); sal_Bool bToBeEncrypted = rInfo.pStream->IsToBeEncrypted() && (rEncryptionKey.getLength() || rInfo.pStream->HasOwnKey());
sal_Bool bToBeCompressed = bToBeEncrypted ? sal_True : pStream->IsToBeCompressed(); sal_Bool bToBeCompressed = bToBeEncrypted ? sal_True : rInfo.pStream->IsToBeCompressed();
aPropSet[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty; aPropSet[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty;
aPropSet[PKG_MNFST_MEDIATYPE].Value <<= pStream->GetMediaType( ); aPropSet[PKG_MNFST_MEDIATYPE].Value <<= rInfo.pStream->GetMediaType( );
aPropSet[PKG_MNFST_VERSION].Name = sVersionProperty; aPropSet[PKG_MNFST_VERSION].Name = sVersionProperty;
aPropSet[PKG_MNFST_VERSION].Value <<= ::rtl::OUString(); // no version is stored for streams currently aPropSet[PKG_MNFST_VERSION].Value <<= ::rtl::OUString(); // no version is stored for streams currently
aPropSet[PKG_MNFST_FULLPATH].Name = sFullPathProperty; aPropSet[PKG_MNFST_FULLPATH].Name = sFullPathProperty;
aPropSet[PKG_MNFST_FULLPATH].Value <<= pTempEntry->sPath; aPropSet[PKG_MNFST_FULLPATH].Value <<= pTempEntry->sPath;
OSL_ENSURE( pStream->GetStreamMode() != PACKAGE_STREAM_NOTSET, "Unacceptable ZipPackageStream mode!" ); OSL_ENSURE( rInfo.pStream->GetStreamMode() != PACKAGE_STREAM_NOTSET, "Unacceptable ZipPackageStream mode!" );
sal_Bool bRawStream = sal_False; sal_Bool bRawStream = sal_False;
if ( pStream->GetStreamMode() == PACKAGE_STREAM_DETECT ) if ( rInfo.pStream->GetStreamMode() == PACKAGE_STREAM_DETECT )
bRawStream = pStream->ParsePackageRawStream(); bRawStream = rInfo.pStream->ParsePackageRawStream();
else if ( pStream->GetStreamMode() == PACKAGE_STREAM_RAW ) else if ( rInfo.pStream->GetStreamMode() == PACKAGE_STREAM_RAW )
bRawStream = sal_True; bRawStream = sal_True;
sal_Bool bTransportOwnEncrStreamAsRaw = sal_False; sal_Bool bTransportOwnEncrStreamAsRaw = sal_False;
// During the storing the original size of the stream can be changed // During the storing the original size of the stream can be changed
// TODO/LATER: get rid of this hack // TODO/LATER: get rid of this hack
sal_Int32 nOwnStreamOrigSize = bRawStream ? pStream->GetMagicalHackSize() : pStream->getSize(); sal_Int32 nOwnStreamOrigSize = bRawStream ? rInfo.pStream->GetMagicalHackSize() : rInfo.pStream->getSize();
sal_Bool bUseNonSeekableAccess = sal_False; sal_Bool bUseNonSeekableAccess = sal_False;
Reference < XInputStream > xStream; Reference < XInputStream > xStream;
if ( !pStream->IsPackageMember() && !bRawStream && !bToBeEncrypted && bToBeCompressed ) if ( !rInfo.pStream->IsPackageMember() && !bRawStream && !bToBeEncrypted && bToBeCompressed )
{ {
// the stream is not a package member, not a raw stream, // the stream is not a package member, not a raw stream,
// it should not be encrypted and it should be compressed, // it should not be encrypted and it should be compressed,
// in this case nonseekable access can be used // in this case nonseekable access can be used
xStream = pStream->GetOwnStreamNoWrap(); xStream = rInfo.pStream->GetOwnStreamNoWrap();
Reference < XSeekable > xSeek ( xStream, UNO_QUERY ); Reference < XSeekable > xSeek ( xStream, UNO_QUERY );
bUseNonSeekableAccess = ( xStream.is() && !xSeek.is() ); bUseNonSeekableAccess = ( xStream.is() && !xSeek.is() );
...@@ -435,13 +393,13 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr ...@@ -435,13 +393,13 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr
if ( !bUseNonSeekableAccess ) if ( !bUseNonSeekableAccess )
{ {
xStream = pStream->getRawData(); xStream = rInfo.pStream->getRawData();
if ( !xStream.is() ) if ( !xStream.is() )
{ {
VOS_ENSURE( 0, "ZipPackageStream didn't have a stream associated with it, skipping!" ); VOS_ENSURE( 0, "ZipPackageStream didn't have a stream associated with it, skipping!" );
bWritingFailed = sal_True; bSuccess = false;
continue; return bSuccess;
} }
Reference < XSeekable > xSeek ( xStream, UNO_QUERY ); Reference < XSeekable > xSeek ( xStream, UNO_QUERY );
...@@ -455,7 +413,7 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr ...@@ -455,7 +413,7 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr
{ {
// The raw stream can neither be encrypted nor connected // The raw stream can neither be encrypted nor connected
OSL_ENSURE( !bRawStream || !bToBeCompressed && !bToBeEncrypted, "The stream is already encrypted!\n" ); OSL_ENSURE( !bRawStream || !bToBeCompressed && !bToBeEncrypted, "The stream is already encrypted!\n" );
xSeek->seek ( bRawStream ? pStream->GetMagicalHackPos() : 0 ); xSeek->seek ( bRawStream ? rInfo.pStream->GetMagicalHackPos() : 0 );
ImplSetStoredData ( *pTempEntry, xStream ); ImplSetStoredData ( *pTempEntry, xStream );
// TODO/LATER: Get rid of hacks related to switching of Flag Method and Size properties! // TODO/LATER: Get rid of hacks related to switching of Flag Method and Size properties!
...@@ -475,10 +433,10 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr ...@@ -475,10 +433,10 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr
// check if it's one of our own streams, if it is then we know that // check if it's one of our own streams, if it is then we know that
// each time we ask for it we'll get a new stream that will be // each time we ask for it we'll get a new stream that will be
// at position zero...otherwise, assert and skip this stream... // at position zero...otherwise, assert and skip this stream...
if ( pStream->IsPackageMember() ) if ( rInfo.pStream->IsPackageMember() )
{ {
// if the password has been changed than the stream should not be package member any more // if the password has been changed than the stream should not be package member any more
if ( pStream->IsEncrypted() && pStream->IsToBeEncrypted() ) if ( rInfo.pStream->IsEncrypted() && rInfo.pStream->IsToBeEncrypted() )
{ {
// Should be handled close to the raw stream handling // Should be handled close to the raw stream handling
bTransportOwnEncrStreamAsRaw = sal_True; bTransportOwnEncrStreamAsRaw = sal_True;
...@@ -493,15 +451,16 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr ...@@ -493,15 +451,16 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr
else else
{ {
VOS_ENSURE( 0, "The package component requires that every stream either be FROM a package or it must support XSeekable!" ); VOS_ENSURE( 0, "The package component requires that every stream either be FROM a package or it must support XSeekable!" );
continue; bSuccess = false;
return bSuccess;
} }
} }
} }
catch ( Exception& ) catch ( Exception& )
{ {
VOS_ENSURE( 0, "The stream provided to the package component has problems!" ); VOS_ENSURE( 0, "The stream provided to the package component has problems!" );
bWritingFailed = sal_True; bSuccess = false;
continue; return bSuccess;
} }
if ( bToBeEncrypted || bRawStream || bTransportOwnEncrStreamAsRaw ) if ( bToBeEncrypted || bRawStream || bTransportOwnEncrStreamAsRaw )
...@@ -513,12 +472,12 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr ...@@ -513,12 +472,12 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr
rtl_random_getBytes ( rRandomPool, aVector.getArray(), 8 ); rtl_random_getBytes ( rRandomPool, aVector.getArray(), 8 );
sal_Int32 nIterationCount = 1024; sal_Int32 nIterationCount = 1024;
if ( !pStream->HasOwnKey() ) if ( !rInfo.pStream->HasOwnKey() )
pStream->setKey ( rEncryptionKey ); rInfo.pStream->setKey ( rEncryptionKey );
pStream->setInitialisationVector ( aVector ); rInfo.pStream->setInitialisationVector ( aVector );
pStream->setSalt ( aSalt ); rInfo.pStream->setSalt ( aSalt );
pStream->setIterationCount ( nIterationCount ); rInfo.pStream->setIterationCount ( nIterationCount );
} }
// last property is digest, which is inserted later if we didn't have // last property is digest, which is inserted later if we didn't have
...@@ -526,11 +485,11 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr ...@@ -526,11 +485,11 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr
aPropSet.realloc(PKG_SIZE_ENCR_MNFST); aPropSet.realloc(PKG_SIZE_ENCR_MNFST);
aPropSet[PKG_MNFST_INIVECTOR].Name = sInitialisationVectorProperty; aPropSet[PKG_MNFST_INIVECTOR].Name = sInitialisationVectorProperty;
aPropSet[PKG_MNFST_INIVECTOR].Value <<= pStream->getInitialisationVector(); aPropSet[PKG_MNFST_INIVECTOR].Value <<= rInfo.pStream->getInitialisationVector();
aPropSet[PKG_MNFST_SALT].Name = sSaltProperty; aPropSet[PKG_MNFST_SALT].Name = sSaltProperty;
aPropSet[PKG_MNFST_SALT].Value <<= pStream->getSalt(); aPropSet[PKG_MNFST_SALT].Value <<= rInfo.pStream->getSalt();
aPropSet[PKG_MNFST_ITERATION].Name = sIterationCountProperty; aPropSet[PKG_MNFST_ITERATION].Name = sIterationCountProperty;
aPropSet[PKG_MNFST_ITERATION].Value <<= pStream->getIterationCount (); aPropSet[PKG_MNFST_ITERATION].Value <<= rInfo.pStream->getIterationCount ();
// Need to store the uncompressed size in the manifest // Need to store the uncompressed size in the manifest
OSL_ENSURE( nOwnStreamOrigSize >= 0, "The stream size was not correctly initialized!\n" ); OSL_ENSURE( nOwnStreamOrigSize >= 0, "The stream size was not correctly initialized!\n" );
...@@ -540,7 +499,7 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr ...@@ -540,7 +499,7 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr
if ( bRawStream || bTransportOwnEncrStreamAsRaw ) if ( bRawStream || bTransportOwnEncrStreamAsRaw )
{ {
aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty; aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty;
aPropSet[PKG_MNFST_DIGEST].Value <<= pStream->getDigest(); aPropSet[PKG_MNFST_DIGEST].Value <<= rInfo.pStream->getDigest();
} }
} }
} }
...@@ -549,29 +508,30 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr ...@@ -549,29 +508,30 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr
// want for this write...copy it raw // want for this write...copy it raw
if ( !bUseNonSeekableAccess if ( !bUseNonSeekableAccess
&& ( bRawStream || bTransportOwnEncrStreamAsRaw && ( bRawStream || bTransportOwnEncrStreamAsRaw
|| ( pStream->IsPackageMember() && !bToBeEncrypted || ( rInfo.pStream->IsPackageMember() && !bToBeEncrypted
&& ( ( pStream->aEntry.nMethod == DEFLATED && bToBeCompressed ) && ( ( rInfo.pStream->aEntry.nMethod == DEFLATED && bToBeCompressed )
|| ( pStream->aEntry.nMethod == STORED && !bToBeCompressed ) ) ) ) ) || ( rInfo.pStream->aEntry.nMethod == STORED && !bToBeCompressed ) ) ) ) )
{ {
// If it's a PackageMember, then it's an unbuffered stream and we need // If it's a PackageMember, then it's an unbuffered stream and we need
// to get a new version of it as we can't seek backwards. // to get a new version of it as we can't seek backwards.
if ( pStream->IsPackageMember() ) if ( rInfo.pStream->IsPackageMember() )
{ {
xStream = pStream->getRawData(); xStream = rInfo.pStream->getRawData();
if ( !xStream.is() ) if ( !xStream.is() )
{ {
// Make sure that we actually _got_ a new one ! // Make sure that we actually _got_ a new one !
VOS_ENSURE( 0, "ZipPackageStream didn't have a stream associated with it, skipping!" ); VOS_ENSURE( 0, "ZipPackageStream didn't have a stream associated with it, skipping!" );
continue; bSuccess = false;
return bSuccess;
} }
} }
try try
{ {
if ( bRawStream ) if ( bRawStream )
xStream->skipBytes( pStream->GetMagicalHackPos() ); xStream->skipBytes( rInfo.pStream->GetMagicalHackPos() );
rZipOut.putNextEntry ( *pTempEntry, pStream->getEncryptionData(), sal_False ); rZipOut.putNextEntry ( *pTempEntry, rInfo.pStream->getEncryptionData(), sal_False );
// the entry is provided to the ZipOutputStream that will delete it // the entry is provided to the ZipOutputStream that will delete it
pAutoTempEntry.release(); pAutoTempEntry.release();
...@@ -590,12 +550,12 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr ...@@ -590,12 +550,12 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr
catch ( ZipException& ) catch ( ZipException& )
{ {
VOS_ENSURE( 0, "Error writing ZipOutputStream" ); VOS_ENSURE( 0, "Error writing ZipOutputStream" );
bWritingFailed = sal_True; bSuccess = false;
} }
catch ( IOException& ) catch ( IOException& )
{ {
VOS_ENSURE( 0, "Error writing ZipOutputStream" ); VOS_ENSURE( 0, "Error writing ZipOutputStream" );
bWritingFailed = sal_True; bSuccess = false;
} }
} }
else else
...@@ -610,14 +570,15 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr ...@@ -610,14 +570,15 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr
// If it's a PackageMember, then our previous reference held a 'raw' stream // If it's a PackageMember, then our previous reference held a 'raw' stream
// so we need to re-get it, unencrypted, uncompressed and positioned at the // so we need to re-get it, unencrypted, uncompressed and positioned at the
// beginning of the stream // beginning of the stream
if ( pStream->IsPackageMember() ) if ( rInfo.pStream->IsPackageMember() )
{ {
xStream = pStream->getInputStream(); xStream = rInfo.pStream->getInputStream();
if ( !xStream.is() ) if ( !xStream.is() )
{ {
// Make sure that we actually _got_ a new one ! // Make sure that we actually _got_ a new one !
VOS_ENSURE( 0, "ZipPackageStream didn't have a stream associated with it, skipping!" ); VOS_ENSURE( 0, "ZipPackageStream didn't have a stream associated with it, skipping!" );
continue; bSuccess = false;
return bSuccess;
} }
} }
...@@ -629,7 +590,7 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr ...@@ -629,7 +590,7 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr
try try
{ {
rZipOut.putNextEntry ( *pTempEntry, pStream->getEncryptionData(), bToBeEncrypted); rZipOut.putNextEntry ( *pTempEntry, rInfo.pStream->getEncryptionData(), bToBeEncrypted);
// the entry is provided to the ZipOutputStream that will delete it // the entry is provided to the ZipOutputStream that will delete it
pAutoTempEntry.release(); pAutoTempEntry.release();
...@@ -647,35 +608,35 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr ...@@ -647,35 +608,35 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr
catch ( ZipException& ) catch ( ZipException& )
{ {
VOS_ENSURE( 0, "Error writing ZipOutputStream" ); VOS_ENSURE( 0, "Error writing ZipOutputStream" );
bWritingFailed = sal_True; bSuccess = false;
} }
catch ( IOException& ) catch ( IOException& )
{ {
VOS_ENSURE( 0, "Error writing ZipOutputStream" ); VOS_ENSURE( 0, "Error writing ZipOutputStream" );
bWritingFailed = sal_True; bSuccess = false;
} }
if ( bToBeEncrypted ) if ( bToBeEncrypted )
{ {
aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty; aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty;
aPropSet[PKG_MNFST_DIGEST].Value <<= pStream->getDigest(); aPropSet[PKG_MNFST_DIGEST].Value <<= rInfo.pStream->getDigest();
pStream->SetIsEncrypted ( sal_True ); rInfo.pStream->SetIsEncrypted ( sal_True );
} }
} }
if( !bWritingFailed ) if( bSuccess )
{ {
if ( !pStream->IsPackageMember() ) if ( !rInfo.pStream->IsPackageMember() )
{ {
pStream->CloseOwnStreamIfAny(); rInfo.pStream->CloseOwnStreamIfAny();
pStream->SetPackageMember ( sal_True ); rInfo.pStream->SetPackageMember ( sal_True );
} }
if ( bRawStream ) if ( bRawStream )
{ {
// the raw stream was integrated and now behaves // the raw stream was integrated and now behaves
// as usual encrypted stream // as usual encrypted stream
pStream->SetToBeEncrypted( sal_True ); rInfo.pStream->SetToBeEncrypted( sal_True );
} }
// Remove hacky bit from entry flags // Remove hacky bit from entry flags
...@@ -686,13 +647,13 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr ...@@ -686,13 +647,13 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr
} }
// Then copy it back afterwards... // Then copy it back afterwards...
ZipPackageFolder::copyZipEntry ( pStream->aEntry, *pTempEntry ); ZipPackageFolder::copyZipEntry ( rInfo.pStream->aEntry, *pTempEntry );
// TODO/LATER: get rid of this hack ( the encrypted stream size property is changed during saving ) // TODO/LATER: get rid of this hack ( the encrypted stream size property is changed during saving )
if ( pStream->IsEncrypted() ) if ( rInfo.pStream->IsEncrypted() )
pStream->setSize( nOwnStreamOrigSize ); rInfo.pStream->setSize( nOwnStreamOrigSize );
pStream->aEntry.nOffset *= -1; rInfo.pStream->aEntry.nOffset *= -1;
} }
} }
...@@ -700,6 +661,64 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr ...@@ -700,6 +661,64 @@ void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < Pr
if ( aPropSet.getLength() if ( aPropSet.getLength()
&& ( m_nFormat == embed::StorageFormats::PACKAGE || ( m_nFormat == embed::StorageFormats::OFOPXML && !rInfo.bFolder ) ) ) && ( m_nFormat == embed::StorageFormats::PACKAGE || ( m_nFormat == embed::StorageFormats::OFOPXML && !rInfo.bFolder ) ) )
rManList.push_back( aPropSet ); rManList.push_back( aPropSet );
return bSuccess;
}
void ZipPackageFolder::saveContents(OUString &rPath, std::vector < Sequence < PropertyValue > > &rManList, ZipOutputStream & rZipOut, Sequence < sal_Int8 > &rEncryptionKey, rtlRandomPool &rRandomPool)
throw(RuntimeException)
{
bool bWritingFailed = false;
if ( maContents.begin() == maContents.end() && rPath.getLength() && m_nFormat != embed::StorageFormats::OFOPXML )
{
// it is an empty subfolder, use workaround to store it
ZipEntry* pTempEntry = new ZipEntry();
ZipPackageFolder::copyZipEntry ( *pTempEntry, aEntry );
pTempEntry->nPathLen = (sal_Int16)( ::rtl::OUStringToOString( rPath, RTL_TEXTENCODING_UTF8 ).getLength() );
pTempEntry->nExtraLen = -1;
pTempEntry->sPath = rPath;
try
{
vos::ORef < EncryptionData > aEmptyEncr;
rZipOut.putNextEntry ( *pTempEntry, aEmptyEncr, sal_False );
rZipOut.rawCloseEntry();
}
catch ( ZipException& )
{
VOS_ENSURE( 0, "Error writing ZipOutputStream" );
bWritingFailed = true;
}
catch ( IOException& )
{
VOS_ENSURE( 0, "Error writing ZipOutputStream" );
bWritingFailed = true;
}
}
bool bMimeTypeStreamStored = false;
::rtl::OUString aMimeTypeStreamName( RTL_CONSTASCII_USTRINGPARAM( "mimetype" ) );
if ( m_nFormat == embed::StorageFormats::ZIP && !rPath.getLength() )
{
// let the "mimtype" stream in root folder be stored as the first stream if it is zip format
ContentHash::iterator aIter = maContents.find ( aMimeTypeStreamName );
if ( aIter != maContents.end() && !(*aIter).second->bFolder )
{
bMimeTypeStreamStored = true;
bWritingFailed = !saveChild( (*aIter).first, *(*aIter).second, rPath, rManList, rZipOut, rEncryptionKey, rRandomPool );
}
}
for ( ContentHash::const_iterator aCI = maContents.begin(), aEnd = maContents.end();
aCI != aEnd;
aCI++)
{
const OUString &rShortName = (*aCI).first;
const ContentInfo &rInfo = *(*aCI).second;
if ( !bMimeTypeStreamStored || !rShortName.equals( aMimeTypeStreamName ) )
bWritingFailed = !saveChild( rShortName, rInfo, rPath, rManList, rZipOut, rEncryptionKey, rRandomPool );
} }
if( bWritingFailed ) if( bWritingFailed )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment