Kaydet (Commit) 9f495d12 authored tarafından Matúš Kukan's avatar Matúš Kukan

Split ZipPackageFolder::saveChild into two functions

And make them static. Probably would be better to kill ContentInfo and
add saveChild as pure virtual into ZipPackageEntry, from which are both
ZipPackageFolder and ZipPackageStream inheriting.

This will also create a bit more sensible call graph when profiling.

Change-Id: If8151332cfa6359e8736c912b7a5633a9162ab36
üst 04ebf437
......@@ -79,10 +79,13 @@ public:
void setPackageFormat_Impl( sal_Int32 nFormat ) { m_nFormat = nFormat; }
void setRemoveOnInsertMode_Impl( bool bRemove ) { this->mbAllowRemoveOnInsert = bRemove; }
bool saveChild(const OUString &rShortName, const com::sun::star::packages::ContentInfo &rInfo, OUString &rPath, std::vector < com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > > &rManList, ZipOutputStream & rZipOut, const com::sun::star::uno::Sequence < sal_Int8 >& rEncryptionKey, rtlRandomPool & rRandomPool) const;
// Recursive functions
void saveContents(OUString &rPath, std::vector < com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > > &rManList, ZipOutputStream & rZipOut, const com::sun::star::uno::Sequence< sal_Int8 > &rEncryptionKey, rtlRandomPool & rRandomPool) const
void saveContents(
const OUString &rPath,
std::vector < com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > > &rManList,
ZipOutputStream & rZipOut,
const com::sun::star::uno::Sequence< sal_Int8 > &rEncryptionKey,
const rtlRandomPool & rRandomPool) const
throw(::com::sun::star::uno::RuntimeException);
void releaseUpwardRef();
......
......@@ -294,29 +294,26 @@ static void ImplSetStoredData( ZipEntry & rEntry, uno::Reference< XInputStream>
rEntry.nCrc = aCRC32.getValue();
}
bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo &rInfo, OUString &rPath, std::vector < uno::Sequence < PropertyValue > > &rManList, ZipOutputStream & rZipOut, const uno::Sequence < sal_Int8 >& rEncryptionKey, rtlRandomPool &rRandomPool) const
static bool ZipPackageFolder_saveChild(
const ContentInfo &rInfo,
const OUString &rPath,
std::vector < uno::Sequence < PropertyValue > > &rManList,
ZipOutputStream & rZipOut,
const uno::Sequence < sal_Int8 >& rEncryptionKey,
const rtlRandomPool &rRandomPool,
sal_Int32 nFormat)
{
bool bSuccess = true;
const OUString sMediaTypeProperty ("MediaType");
const OUString sVersionProperty ("Version");
const OUString sFullPathProperty ("FullPath");
const OUString sInitialisationVectorProperty ("InitialisationVector");
const OUString sSaltProperty ("Salt");
const OUString sIterationCountProperty ("IterationCount");
const OUString sSizeProperty ("Size");
const OUString sDigestProperty ("Digest");
const OUString sEncryptionAlgProperty ("EncryptionAlgorithm");
const OUString sStartKeyAlgProperty ("StartKeyAlgorithm");
const OUString sDigestAlgProperty ("DigestAlgorithm");
const OUString sDerivedKeySizeProperty ("DerivedKeySize");
uno::Sequence < PropertyValue > aPropSet (PKG_SIZE_NOENCR_MNFST);
OSL_ENSURE( ( rInfo.bFolder && rInfo.pFolder ) || ( !rInfo.bFolder && rInfo.pStream ), "A valid child object is expected!" );
if ( rInfo.bFolder )
{
OUString sTempName = rPath + rShortName + "/";
assert( rInfo.bFolder && rInfo.pFolder && "A valid child object is expected!" );
OUString sTempName = rPath + "/";
if ( !rInfo.pFolder->GetMediaType().isEmpty() )
{
......@@ -331,9 +328,43 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo
aPropSet.realloc( 0 );
rInfo.pFolder->saveContents( sTempName, rManList, rZipOut, rEncryptionKey, rRandomPool);
}
else
{
// folder can have a mediatype only in package format
if ( aPropSet.getLength()
&& ( nFormat == embed::StorageFormats::PACKAGE || ( nFormat == embed::StorageFormats::OFOPXML && !rInfo.bFolder ) ) )
rManList.push_back( aPropSet );
return bSuccess;
}
static bool ZipPackageStream_saveChild(
const ContentInfo &rInfo,
const OUString &rPath,
std::vector < uno::Sequence < PropertyValue > > &rManList,
ZipOutputStream & rZipOut,
const uno::Sequence < sal_Int8 >& rEncryptionKey,
const rtlRandomPool &rRandomPool,
sal_Int32 nFormat)
{
bool bSuccess = true;
const OUString sMediaTypeProperty ("MediaType");
const OUString sVersionProperty ("Version");
const OUString sFullPathProperty ("FullPath");
const OUString sInitialisationVectorProperty ("InitialisationVector");
const OUString sSaltProperty ("Salt");
const OUString sIterationCountProperty ("IterationCount");
const OUString sSizeProperty ("Size");
const OUString sDigestProperty ("Digest");
const OUString sEncryptionAlgProperty ("EncryptionAlgorithm");
const OUString sStartKeyAlgProperty ("StartKeyAlgorithm");
const OUString sDigestAlgProperty ("DigestAlgorithm");
const OUString sDerivedKeySizeProperty ("DerivedKeySize");
uno::Sequence < PropertyValue > aPropSet (PKG_SIZE_NOENCR_MNFST);
assert( !rInfo.bFolder && rInfo.pStream && "A valid child object is expected!" );
// if pTempEntry is necessary, it will be released and passed to the ZipOutputStream
// and be deleted in the ZipOutputStream destructor
unique_ptr < ZipEntry > pAutoTempEntry ( new ZipEntry );
......@@ -343,7 +374,7 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo
// store the ZipEntry data in pTempEntry
ZipPackageFolder::copyZipEntry ( *pTempEntry, rInfo.pStream->aEntry );
pTempEntry->sPath = rPath + rShortName;
pTempEntry->sPath = rPath;
pTempEntry->nPathLen = (sal_Int16)( OUStringToOString( pTempEntry->sPath, RTL_TEXTENCODING_UTF8 ).getLength() );
bool bToBeEncrypted = rInfo.pStream->IsToBeEncrypted() && (rEncryptionKey.getLength() || rInfo.pStream->HasOwnKey());
......@@ -665,17 +696,21 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo
rInfo.pStream->aEntry.nOffset *= -1;
}
}
// folder can have a mediatype only in package format
if ( aPropSet.getLength()
&& ( m_nFormat == embed::StorageFormats::PACKAGE || ( m_nFormat == embed::StorageFormats::OFOPXML && !rInfo.bFolder ) ) )
&& ( nFormat == embed::StorageFormats::PACKAGE || ( nFormat == embed::StorageFormats::OFOPXML && !rInfo.bFolder ) ) )
rManList.push_back( aPropSet );
return bSuccess;
}
void ZipPackageFolder::saveContents( OUString &rPath, std::vector < uno::Sequence < PropertyValue > > &rManList, ZipOutputStream & rZipOut, const uno::Sequence < sal_Int8 >& rEncryptionKey, rtlRandomPool &rRandomPool ) const
void ZipPackageFolder::saveContents(
const OUString &rPath,
std::vector < uno::Sequence < PropertyValue > > &rManList,
ZipOutputStream & rZipOut,
const uno::Sequence < sal_Int8 >& rEncryptionKey,
const rtlRandomPool &rRandomPool ) const
throw( uno::RuntimeException )
{
bool bWritingFailed = false;
......@@ -708,12 +743,13 @@ void ZipPackageFolder::saveContents( OUString &rPath, std::vector < uno::Sequenc
OUString aMimeTypeStreamName("mimetype");
if ( m_nFormat == embed::StorageFormats::ZIP && rPath.isEmpty() )
{
// let the "mimtype" stream in root folder be stored as the first stream if it is zip format
// let the "mimetype" stream in root folder be stored as the first stream if it is zip format
ContentHash::const_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 );
bWritingFailed = !ZipPackageStream_saveChild(
*aIter->second, rPath + aIter->first, rManList, rZipOut, rEncryptionKey, rRandomPool, m_nFormat );
}
}
......@@ -725,7 +761,18 @@ void ZipPackageFolder::saveContents( OUString &rPath, std::vector < uno::Sequenc
const ContentInfo &rInfo = *(*aCI).second;
if ( !bMimeTypeStreamStored || !rShortName.equals( aMimeTypeStreamName ) )
bWritingFailed = !saveChild( rShortName, rInfo, rPath, rManList, rZipOut, rEncryptionKey, rRandomPool );
{
if (rInfo.bFolder)
{
bWritingFailed = !ZipPackageFolder_saveChild(
rInfo, rPath + rShortName, rManList, rZipOut, rEncryptionKey, rRandomPool, m_nFormat );
}
else
{
bWritingFailed = !ZipPackageStream_saveChild(
rInfo, rPath + rShortName, rManList, rZipOut, rEncryptionKey, rRandomPool, m_nFormat );
}
}
}
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