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
This commit is contained in:
Matúš Kukan
2014-10-07 16:04:13 +02:00
parent 04ebf43708
commit 9f495d128e
2 changed files with 360 additions and 310 deletions

View File

@@ -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();

View File

@@ -294,7 +294,57 @@ 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");
uno::Sequence < PropertyValue > aPropSet (PKG_SIZE_NOENCR_MNFST);
assert( rInfo.bFolder && rInfo.pFolder && "A valid child object is expected!" );
OUString sTempName = rPath + "/";
if ( !rInfo.pFolder->GetMediaType().isEmpty() )
{
aPropSet[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty;
aPropSet[PKG_MNFST_MEDIATYPE].Value <<= rInfo.pFolder->GetMediaType();
aPropSet[PKG_MNFST_VERSION].Name = sVersionProperty;
aPropSet[PKG_MNFST_VERSION].Value <<= rInfo.pFolder->GetVersion();
aPropSet[PKG_MNFST_FULLPATH].Name = sFullPathProperty;
aPropSet[PKG_MNFST_FULLPATH].Value <<= sTempName;
}
else
aPropSet.realloc( 0 );
rInfo.pFolder->saveContents( sTempName, rManList, rZipOut, rEncryptionKey, rRandomPool);
// 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;
@@ -313,27 +363,8 @@ bool ZipPackageFolder::saveChild( const OUString &rShortName, const ContentInfo
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.pStream && "A valid child object is expected!" );
if ( !rInfo.pFolder->GetMediaType().isEmpty() )
{
aPropSet[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty;
aPropSet[PKG_MNFST_MEDIATYPE].Value <<= rInfo.pFolder->GetMediaType();
aPropSet[PKG_MNFST_VERSION].Name = sVersionProperty;
aPropSet[PKG_MNFST_VERSION].Value <<= rInfo.pFolder->GetVersion();
aPropSet[PKG_MNFST_FULLPATH].Name = sFullPathProperty;
aPropSet[PKG_MNFST_FULLPATH].Value <<= sTempName;
}
else
aPropSet.realloc( 0 );
rInfo.pFolder->saveContents( sTempName, rManList, rZipOut, rEncryptionKey, rRandomPool);
}
else
{
// 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 )