2000-11-13 06:38:03 -06:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* $RCSfile: ZipOutputStream.cxx,v $
|
|
|
|
*
|
2001-10-02 16:08:40 -05:00
|
|
|
* $Revision: 1.33 $
|
2000-11-13 06:38:03 -06:00
|
|
|
*
|
2001-10-02 16:08:40 -05:00
|
|
|
* last change: $Author: mtg $ $Date: 2001-10-02 22:08:40 $
|
2000-11-13 06:38:03 -06:00
|
|
|
*
|
|
|
|
* The Contents of this file are made available subject to the terms of
|
|
|
|
* either of the following licenses
|
|
|
|
*
|
|
|
|
* - GNU Lesser General Public License Version 2.1
|
|
|
|
* - Sun Industry Standards Source License Version 1.1
|
|
|
|
*
|
|
|
|
* Sun Microsystems Inc., October, 2000
|
|
|
|
*
|
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2000 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Sun Industry Standards Source License Version 1.1
|
|
|
|
* =================================================
|
|
|
|
* The contents of this file are subject to the Sun Industry Standards
|
|
|
|
* Source License Version 1.1 (the "License"); You may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of the
|
|
|
|
* License at http://www.openoffice.org/license.html.
|
|
|
|
*
|
|
|
|
* Software provided under this License is provided on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
|
|
|
|
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
|
|
|
|
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
|
|
|
|
* See the License for the specific provisions governing your rights and
|
|
|
|
* obligations concerning the Software.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* Copyright: 2000 by Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
2000-12-19 14:55:41 -06:00
|
|
|
* Contributor(s): Martin Gallwey (gallwey@sun.com)
|
2000-11-13 06:38:03 -06:00
|
|
|
*
|
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
#ifndef _ZIP_OUTPUT_STREAM_HXX
|
2001-04-19 08:13:40 -05:00
|
|
|
#include <ZipOutputStream.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _VOS_DIAGNOSE_H_
|
|
|
|
#include <vos/diagnose.hxx>
|
|
|
|
#endif
|
2001-07-04 08:56:37 -05:00
|
|
|
#ifndef _COM_SUN_STAR_PACKAGES_ZIP_ZIPCONSTANTS_HPP_
|
|
|
|
#include <com/sun/star/packages/zip/ZipConstants.hpp>
|
2000-11-13 06:38:03 -06:00
|
|
|
#endif
|
2001-04-27 08:56:07 -05:00
|
|
|
#ifndef _OSL_TIME_H_
|
|
|
|
#include <osl/time.h>
|
|
|
|
#endif
|
2001-05-08 07:59:39 -05:00
|
|
|
#ifndef _ENCRYPTION_DATA_HXX_
|
|
|
|
#include <EncryptionData.hxx>
|
|
|
|
#endif
|
2001-07-04 08:56:37 -05:00
|
|
|
#ifndef _IMPL_VALID_CHARACTERS_HXX_
|
|
|
|
#include <ImplValidCharacters.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _PACKAGE_CONSTANTS_HXX_
|
|
|
|
#include <PackageConstants.hxx>
|
|
|
|
#endif
|
2001-09-14 09:01:22 -05:00
|
|
|
#ifndef _ZIP_ENTRY_HXX_
|
|
|
|
#include <ZipEntry.hxx>
|
|
|
|
#endif
|
2000-11-13 06:38:03 -06:00
|
|
|
using namespace rtl;
|
2001-05-31 04:23:43 -05:00
|
|
|
using namespace com::sun::star::io;
|
2001-04-27 08:56:07 -05:00
|
|
|
using namespace com::sun::star::uno;
|
2001-07-04 08:56:37 -05:00
|
|
|
using namespace com::sun::star::packages;
|
|
|
|
using namespace com::sun::star::packages::zip;
|
|
|
|
using namespace com::sun::star::packages::zip::ZipConstants;
|
2000-11-13 06:38:03 -06:00
|
|
|
|
|
|
|
/** This class is used to write Zip files
|
|
|
|
*/
|
2001-07-04 08:56:37 -05:00
|
|
|
ZipOutputStream::ZipOutputStream( Reference < XOutputStream > &xOStream, sal_Bool bNewSpanning )
|
2000-11-13 06:38:03 -06:00
|
|
|
: xStream(xOStream)
|
|
|
|
, aChucker(xOStream)
|
|
|
|
, nMethod(DEFLATED)
|
|
|
|
, pCurrentEntry(NULL)
|
|
|
|
, bFinished(sal_False)
|
2001-04-27 08:56:07 -05:00
|
|
|
, bEncryptCurrentEntry(sal_False)
|
2001-07-04 08:56:37 -05:00
|
|
|
, aBuffer(n_ConstBufferSize)
|
2000-11-13 06:38:03 -06:00
|
|
|
, aDeflater(DEFAULT_COMPRESSION, sal_True)
|
2001-07-04 08:56:37 -05:00
|
|
|
, bSpanning ( bNewSpanning )
|
2000-11-13 06:38:03 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ZipOutputStream::~ZipOutputStream( void )
|
|
|
|
{
|
2001-04-19 08:13:40 -05:00
|
|
|
for (sal_Int32 i = 0, nEnd = aZipList.size(); i < nEnd; i++)
|
|
|
|
delete aZipList[i];
|
2000-11-13 06:38:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL ZipOutputStream::setComment( const ::rtl::OUString& rComment )
|
2001-05-31 04:23:43 -05:00
|
|
|
throw(RuntimeException)
|
2000-11-13 06:38:03 -06:00
|
|
|
{
|
|
|
|
sComment = rComment;
|
|
|
|
}
|
|
|
|
void SAL_CALL ZipOutputStream::setMethod( sal_Int32 nNewMethod )
|
2001-05-31 04:23:43 -05:00
|
|
|
throw(RuntimeException)
|
2000-11-13 06:38:03 -06:00
|
|
|
{
|
2000-12-01 03:50:49 -06:00
|
|
|
nMethod = static_cast < sal_Int16 > (nNewMethod);
|
2000-11-13 06:38:03 -06:00
|
|
|
}
|
|
|
|
void SAL_CALL ZipOutputStream::setLevel( sal_Int32 nNewLevel )
|
2001-05-31 04:23:43 -05:00
|
|
|
throw(RuntimeException)
|
2000-11-13 06:38:03 -06:00
|
|
|
{
|
|
|
|
aDeflater.setLevel( nNewLevel);
|
|
|
|
}
|
2001-04-27 08:56:07 -05:00
|
|
|
|
2001-05-31 04:23:43 -05:00
|
|
|
void SAL_CALL ZipOutputStream::putNextEntry( ZipEntry& rEntry,
|
2001-09-05 12:54:28 -05:00
|
|
|
vos::ORef < EncryptionData > &xEncryptData,
|
2001-04-27 08:56:07 -05:00
|
|
|
sal_Bool bEncrypt)
|
2001-05-31 04:23:43 -05:00
|
|
|
throw(IOException, RuntimeException)
|
2000-11-13 06:38:03 -06:00
|
|
|
{
|
2001-07-04 08:56:37 -05:00
|
|
|
if ( bSpanning && ! aZipList.size() )
|
|
|
|
{
|
|
|
|
Sequence < sal_Int8 > aSequence ( 4 );
|
|
|
|
sal_Int8 *pNum = aSequence.getArray();
|
|
|
|
pNum[0] = 'P';
|
|
|
|
pNum[1] = 'K';
|
|
|
|
pNum[2] = 7;
|
|
|
|
pNum[3] = 8;
|
|
|
|
aChucker.writeBytes( aSequence, 4, pNum );
|
|
|
|
}
|
2000-11-13 06:38:03 -06:00
|
|
|
if (pCurrentEntry != NULL)
|
|
|
|
closeEntry();
|
2001-04-27 08:56:07 -05:00
|
|
|
if (rEntry.nTime == -1)
|
|
|
|
rEntry.nTime = getCurrentDosTime();
|
|
|
|
if (rEntry.nMethod == -1)
|
|
|
|
rEntry.nMethod = nMethod;
|
|
|
|
rEntry.nVersion = 20;
|
|
|
|
if (rEntry.nSize == -1 || rEntry.nCompressedSize == -1 ||
|
|
|
|
rEntry.nCrc == -1)
|
|
|
|
rEntry.nFlag = 8;
|
|
|
|
else if (rEntry.nSize != -1 && rEntry.nCompressedSize != -1 &&
|
|
|
|
rEntry.nCrc != -1)
|
|
|
|
rEntry.nFlag = 0;
|
2000-11-28 03:50:54 -06:00
|
|
|
|
2001-04-27 08:56:07 -05:00
|
|
|
if (bEncrypt)
|
|
|
|
{
|
|
|
|
bEncryptCurrentEntry = sal_True;
|
|
|
|
rtlCipherError aResult;
|
|
|
|
|
|
|
|
aCipher = rtl_cipher_create ( rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream);
|
|
|
|
aResult = rtl_cipher_init( aCipher, rtl_Cipher_DirectionEncode,
|
2001-05-08 07:59:39 -05:00
|
|
|
reinterpret_cast < const sal_uInt8 * > (xEncryptData->aKey.getConstArray()),
|
|
|
|
xEncryptData->aKey.getLength(),
|
|
|
|
xEncryptData->aInitVector.getConstArray(),
|
|
|
|
xEncryptData->aInitVector.getLength());
|
2001-04-27 08:56:07 -05:00
|
|
|
OSL_ASSERT( aResult == rtl_Cipher_E_None );
|
2001-10-02 16:08:40 -05:00
|
|
|
aDigest = rtl_digest_createSHA1();
|
|
|
|
mnDigested = 0;
|
2001-05-31 04:23:43 -05:00
|
|
|
rEntry.nFlag |= 1 << 4;
|
2001-09-05 12:54:28 -05:00
|
|
|
xCurrentEncryptData = xEncryptData;
|
2001-04-27 08:56:07 -05:00
|
|
|
}
|
2001-07-04 08:56:37 -05:00
|
|
|
sal_Int32 nLOCLength = writeLOC(rEntry);
|
|
|
|
rEntry.nOffset = static_cast < sal_Int32 > (aChucker.getPosition()) - nLOCLength;
|
2001-05-31 04:23:43 -05:00
|
|
|
aZipList.push_back( &rEntry );
|
|
|
|
pCurrentEntry = &rEntry;
|
2000-11-13 06:38:03 -06:00
|
|
|
}
|
|
|
|
void SAL_CALL ZipOutputStream::close( )
|
2001-05-31 04:23:43 -05:00
|
|
|
throw(IOException, RuntimeException)
|
2000-11-13 06:38:03 -06:00
|
|
|
{
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL ZipOutputStream::closeEntry( )
|
2001-05-31 04:23:43 -05:00
|
|
|
throw(IOException, RuntimeException)
|
2000-11-13 06:38:03 -06:00
|
|
|
{
|
2001-05-31 04:23:43 -05:00
|
|
|
ZipEntry *pEntry = pCurrentEntry;
|
2000-11-13 06:38:03 -06:00
|
|
|
if (pEntry)
|
|
|
|
{
|
|
|
|
switch (pEntry->nMethod)
|
|
|
|
{
|
|
|
|
case DEFLATED:
|
|
|
|
aDeflater.finish();
|
|
|
|
while (!aDeflater.finished())
|
|
|
|
doDeflate();
|
|
|
|
if ((pEntry->nFlag & 8) == 0)
|
|
|
|
{
|
|
|
|
if (pEntry->nSize != aDeflater.getTotalIn())
|
|
|
|
{
|
2000-11-21 05:07:21 -06:00
|
|
|
VOS_DEBUG_ONLY("Invalid entry size");
|
2000-11-13 06:38:03 -06:00
|
|
|
}
|
|
|
|
if (pEntry->nCompressedSize != aDeflater.getTotalOut())
|
|
|
|
{
|
2000-11-21 05:07:21 -06:00
|
|
|
//VOS_DEBUG_ONLY("Invalid entry compressed size");
|
2000-11-16 15:50:51 -06:00
|
|
|
// Different compression strategies make the merit of this
|
|
|
|
// test somewhat dubious
|
|
|
|
pEntry->nCompressedSize = aDeflater.getTotalOut();
|
2000-11-13 06:38:03 -06:00
|
|
|
}
|
|
|
|
if (pEntry->nCrc != aCRC.getValue())
|
|
|
|
{
|
2000-11-21 05:07:21 -06:00
|
|
|
VOS_DEBUG_ONLY("Invalid entry CRC-32");
|
2000-11-13 06:38:03 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pEntry->nSize = aDeflater.getTotalIn();
|
|
|
|
pEntry->nCompressedSize = aDeflater.getTotalOut();
|
|
|
|
pEntry->nCrc = aCRC.getValue();
|
2001-05-08 07:59:39 -05:00
|
|
|
if ( bEncryptCurrentEntry )
|
|
|
|
pEntry->nSize = pEntry->nCompressedSize;
|
2001-05-31 04:23:43 -05:00
|
|
|
writeEXT(*pEntry);
|
2000-11-13 06:38:03 -06:00
|
|
|
}
|
|
|
|
aDeflater.reset();
|
2001-05-31 04:23:43 -05:00
|
|
|
aCRC.reset();
|
2000-11-13 06:38:03 -06:00
|
|
|
break;
|
|
|
|
case STORED:
|
2000-12-07 04:04:07 -06:00
|
|
|
if (!((pEntry->nFlag & 8) == 0))
|
2001-05-31 04:23:43 -05:00
|
|
|
VOS_ENSURE ( 0, "Serious error, one of compressed size, size or CRC was -1 in a STORED stream");
|
2000-11-13 06:38:03 -06:00
|
|
|
break;
|
|
|
|
default:
|
2000-11-21 05:07:21 -06:00
|
|
|
VOS_DEBUG_ONLY("Invalid compression method");
|
2000-11-13 06:38:03 -06:00
|
|
|
break;
|
|
|
|
}
|
2001-05-31 04:23:43 -05:00
|
|
|
|
2001-04-27 08:56:07 -05:00
|
|
|
if (bEncryptCurrentEntry)
|
|
|
|
{
|
2001-09-05 12:54:28 -05:00
|
|
|
rtlDigestError aDigestResult;
|
2001-04-27 08:56:07 -05:00
|
|
|
aEncryptionBuffer.realloc ( 0 );
|
|
|
|
bEncryptCurrentEntry = sal_False;
|
2001-05-08 07:59:39 -05:00
|
|
|
rtl_cipher_destroy ( aCipher );
|
2001-10-02 16:08:40 -05:00
|
|
|
xCurrentEncryptData->aDigest.realloc ( RTL_DIGEST_LENGTH_SHA1 );
|
|
|
|
aDigestResult = rtl_digest_getSHA1 ( aDigest, xCurrentEncryptData->aDigest.getArray(), RTL_DIGEST_LENGTH_SHA1 );
|
2001-09-05 12:54:28 -05:00
|
|
|
OSL_ASSERT( aDigestResult == rtl_Digest_E_None );
|
2001-10-02 16:08:40 -05:00
|
|
|
rtl_digest_destroySHA1 ( aDigest );
|
2001-04-27 08:56:07 -05:00
|
|
|
}
|
2000-11-13 06:38:03 -06:00
|
|
|
pCurrentEntry = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-31 04:23:43 -05:00
|
|
|
void SAL_CALL ZipOutputStream::write( const Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength )
|
|
|
|
throw(IOException, RuntimeException)
|
2000-11-13 06:38:03 -06:00
|
|
|
{
|
|
|
|
switch (pCurrentEntry->nMethod)
|
|
|
|
{
|
|
|
|
case DEFLATED:
|
|
|
|
if (!aDeflater.finished())
|
|
|
|
{
|
|
|
|
aDeflater.setInputSegment(rBuffer, nNewOffset, nNewLength);
|
2000-11-23 07:15:52 -06:00
|
|
|
while (!aDeflater.needsInput())
|
2000-11-13 06:38:03 -06:00
|
|
|
doDeflate();
|
2001-05-08 07:59:39 -05:00
|
|
|
if (!bEncryptCurrentEntry)
|
|
|
|
aCRC.updateSegment(rBuffer, nNewOffset, nNewLength);
|
2000-11-13 06:38:03 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STORED:
|
2001-09-05 12:54:28 -05:00
|
|
|
{
|
|
|
|
Sequence < sal_Int8 > aTmpBuffer ( rBuffer.getConstArray(), nNewLength );
|
|
|
|
aChucker.writeBytes( aTmpBuffer );
|
|
|
|
}
|
2000-11-13 06:38:03 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-05-31 04:23:43 -05:00
|
|
|
|
|
|
|
void SAL_CALL ZipOutputStream::rawWrite( Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength )
|
|
|
|
throw(IOException, RuntimeException)
|
2000-12-13 10:00:47 -06:00
|
|
|
{
|
2001-09-05 12:54:28 -05:00
|
|
|
Sequence < sal_Int8 > aTmpBuffer ( rBuffer.getConstArray(), nNewLength );
|
|
|
|
aChucker.writeBytes( aTmpBuffer );
|
2000-12-13 10:00:47 -06:00
|
|
|
}
|
2001-05-31 04:23:43 -05:00
|
|
|
|
2000-12-13 10:00:47 -06:00
|
|
|
void SAL_CALL ZipOutputStream::rawCloseEntry( )
|
2001-05-31 04:23:43 -05:00
|
|
|
throw(IOException, RuntimeException)
|
2000-12-13 10:00:47 -06:00
|
|
|
{
|
2001-05-31 04:23:43 -05:00
|
|
|
if ( pCurrentEntry->nMethod == DEFLATED )
|
|
|
|
writeEXT(*pCurrentEntry);
|
2000-12-13 10:00:47 -06:00
|
|
|
pCurrentEntry = NULL;
|
|
|
|
}
|
2001-05-31 04:23:43 -05:00
|
|
|
|
2000-11-13 06:38:03 -06:00
|
|
|
void SAL_CALL ZipOutputStream::finish( )
|
2001-05-31 04:23:43 -05:00
|
|
|
throw(IOException, RuntimeException)
|
2000-11-13 06:38:03 -06:00
|
|
|
{
|
|
|
|
if (bFinished)
|
|
|
|
return;
|
2001-05-31 04:23:43 -05:00
|
|
|
|
2000-11-13 06:38:03 -06:00
|
|
|
if (pCurrentEntry != NULL)
|
|
|
|
closeEntry();
|
2001-05-31 04:23:43 -05:00
|
|
|
|
2000-11-13 06:38:03 -06:00
|
|
|
if (aZipList.size() < 1)
|
2000-11-21 05:07:21 -06:00
|
|
|
VOS_DEBUG_ONLY("Zip file must have at least one entry!\n");
|
2001-05-31 04:23:43 -05:00
|
|
|
|
2000-12-01 03:50:49 -06:00
|
|
|
sal_Int32 nOffset= static_cast < sal_Int32 > (aChucker.getPosition());
|
2001-04-19 08:13:40 -05:00
|
|
|
for (sal_Int32 i =0, nEnd = aZipList.size(); i < nEnd; i++)
|
|
|
|
writeCEN( *aZipList[i] );
|
2000-12-01 03:50:49 -06:00
|
|
|
writeEND( nOffset, static_cast < sal_Int32 > (aChucker.getPosition()) - nOffset);
|
2000-11-13 06:38:03 -06:00
|
|
|
bFinished = sal_True;
|
2001-09-18 06:53:16 -05:00
|
|
|
xStream->flush();
|
2000-11-13 06:38:03 -06:00
|
|
|
}
|
2001-05-31 04:23:43 -05:00
|
|
|
|
2000-11-13 06:38:03 -06:00
|
|
|
void ZipOutputStream::doDeflate()
|
|
|
|
{
|
2000-11-16 15:50:51 -06:00
|
|
|
sal_Int32 nLength = aDeflater.doDeflateSegment(aBuffer, 0, aBuffer.getLength());
|
2000-11-22 09:55:27 -06:00
|
|
|
sal_Int32 nOldLength = aBuffer.getLength();
|
2001-05-31 04:23:43 -05:00
|
|
|
|
|
|
|
if ( nLength > 0 )
|
2000-11-13 06:38:03 -06:00
|
|
|
{
|
2001-09-05 12:54:28 -05:00
|
|
|
Sequence < sal_Int8 > aTmpBuffer ( aBuffer.getConstArray(), nLength );
|
|
|
|
const void *pTmpBuffer = static_cast < const void * > ( aTmpBuffer.getConstArray() );
|
2001-04-27 08:56:07 -05:00
|
|
|
if (bEncryptCurrentEntry)
|
|
|
|
{
|
2001-09-05 12:54:28 -05:00
|
|
|
// Need to update our digest before encryption...
|
2001-10-02 16:08:40 -05:00
|
|
|
rtlDigestError aDigestResult = rtl_Digest_E_None;
|
|
|
|
sal_Int16 nDiff = n_ConstDigestLength - mnDigested;
|
|
|
|
if ( nDiff )
|
|
|
|
{
|
|
|
|
sal_Int16 nEat = static_cast < sal_Int16 > ( nDiff > nLength ? nLength : nDiff );
|
|
|
|
aDigestResult = rtl_digest_updateSHA1 ( aDigest, pTmpBuffer, nEat );
|
|
|
|
mnDigested += nEat;
|
|
|
|
}
|
2001-09-05 12:54:28 -05:00
|
|
|
OSL_ASSERT( aDigestResult == rtl_Digest_E_None );
|
|
|
|
|
2001-04-27 08:56:07 -05:00
|
|
|
aEncryptionBuffer.realloc ( nLength );
|
2001-09-05 12:54:28 -05:00
|
|
|
|
|
|
|
rtlCipherError aCipherResult;
|
|
|
|
aCipherResult = rtl_cipher_encode ( aCipher, pTmpBuffer,
|
2001-04-27 08:56:07 -05:00
|
|
|
nLength, reinterpret_cast < sal_uInt8 * > (aEncryptionBuffer.getArray()), nLength );
|
2001-09-05 12:54:28 -05:00
|
|
|
OSL_ASSERT( aCipherResult == rtl_Cipher_E_None );
|
|
|
|
|
2001-04-27 08:56:07 -05:00
|
|
|
aChucker.writeBytes ( aEncryptionBuffer );
|
2001-05-08 07:59:39 -05:00
|
|
|
aCRC.update ( aEncryptionBuffer );
|
2001-04-27 08:56:07 -05:00
|
|
|
aEncryptionBuffer.realloc ( nOldLength );
|
|
|
|
}
|
|
|
|
else
|
2001-09-05 12:54:28 -05:00
|
|
|
aChucker.writeBytes ( aTmpBuffer );
|
2000-11-13 06:38:03 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void ZipOutputStream::writeEND(sal_uInt32 nOffset, sal_uInt32 nLength)
|
2001-05-31 04:23:43 -05:00
|
|
|
throw(IOException, RuntimeException)
|
2000-11-13 06:38:03 -06:00
|
|
|
{
|
|
|
|
aChucker << ENDSIG;
|
|
|
|
aChucker << static_cast < sal_Int16 > ( 0 );
|
|
|
|
aChucker << static_cast < sal_Int16 > ( 0 );
|
|
|
|
aChucker << static_cast < sal_Int16 > ( aZipList.size() );
|
|
|
|
aChucker << static_cast < sal_Int16 > ( aZipList.size() );
|
|
|
|
aChucker << nLength;
|
|
|
|
aChucker << nOffset;
|
2001-09-14 09:01:22 -05:00
|
|
|
aChucker << static_cast < sal_Int16 > ( 0 );
|
2000-11-13 06:38:03 -06:00
|
|
|
}
|
2001-05-31 04:23:43 -05:00
|
|
|
void ZipOutputStream::writeCEN( const ZipEntry &rEntry )
|
|
|
|
throw(IOException, RuntimeException)
|
2000-11-13 06:38:03 -06:00
|
|
|
{
|
2001-09-14 09:01:22 -05:00
|
|
|
sal_Int16 nNameLength = static_cast < sal_Int16 > ( rEntry.sName.getLength() );
|
2000-11-13 06:38:03 -06:00
|
|
|
|
|
|
|
aChucker << CENSIG;
|
|
|
|
aChucker << rEntry.nVersion;
|
|
|
|
aChucker << rEntry.nVersion;
|
2001-05-31 04:23:43 -05:00
|
|
|
if (rEntry.nFlag & (1 << 4) )
|
|
|
|
{
|
|
|
|
// If it's an encrypted entry, we pretend its stored plain text
|
|
|
|
ZipEntry *pEntry = const_cast < ZipEntry * > ( &rEntry );
|
|
|
|
pEntry->nFlag &= ~(1 <<4 );
|
|
|
|
aChucker << rEntry.nFlag;
|
|
|
|
aChucker << static_cast < sal_Int16 > ( STORED );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aChucker << rEntry.nFlag;
|
|
|
|
aChucker << rEntry.nMethod;
|
|
|
|
}
|
2001-07-04 08:56:37 -05:00
|
|
|
aChucker << static_cast < sal_uInt32> ( rEntry.nTime );
|
|
|
|
aChucker << static_cast < sal_uInt32> ( rEntry.nCrc );
|
2000-11-13 06:38:03 -06:00
|
|
|
aChucker << rEntry.nCompressedSize;
|
|
|
|
aChucker << rEntry.nSize;
|
|
|
|
aChucker << nNameLength;
|
2001-09-14 09:01:22 -05:00
|
|
|
aChucker << static_cast < sal_Int16> (0);
|
|
|
|
aChucker << static_cast < sal_Int16> (0);
|
2001-08-08 12:24:46 -05:00
|
|
|
aChucker << static_cast < sal_Int16> (0);
|
2000-11-13 06:38:03 -06:00
|
|
|
aChucker << static_cast < sal_Int16> (0);
|
|
|
|
aChucker << static_cast < sal_Int32> (0);
|
|
|
|
aChucker << rEntry.nOffset;
|
2001-05-31 04:23:43 -05:00
|
|
|
|
2000-11-13 06:38:03 -06:00
|
|
|
const sal_Unicode *pChar = rEntry.sName.getStr();
|
2001-05-31 04:23:43 -05:00
|
|
|
Sequence < sal_Int8 > aSequence (nNameLength);
|
2001-04-19 08:13:40 -05:00
|
|
|
sal_Int8 *pArray = aSequence.getArray();
|
|
|
|
|
2001-09-14 09:01:22 -05:00
|
|
|
VOS_ENSURE ( Impl_IsValidChar ( pChar, nNameLength, sal_True ), "Non US ASCII character in zipentry name!");
|
2001-04-19 08:13:40 -05:00
|
|
|
for ( sal_Int16 i = 0; i < nNameLength; i++)
|
2001-07-04 08:56:37 -05:00
|
|
|
pArray[i] = static_cast < const sal_Int8 > (pChar[i]);
|
2000-11-13 06:38:03 -06:00
|
|
|
|
2001-07-04 08:56:37 -05:00
|
|
|
aChucker.writeBytes( aSequence, nNameLength, pArray );
|
2000-11-13 06:38:03 -06:00
|
|
|
}
|
2001-05-31 04:23:43 -05:00
|
|
|
void ZipOutputStream::writeEXT( const ZipEntry &rEntry )
|
|
|
|
throw(IOException, RuntimeException)
|
2000-11-13 06:38:03 -06:00
|
|
|
{
|
|
|
|
aChucker << EXTSIG;
|
2001-05-31 04:23:43 -05:00
|
|
|
aChucker << static_cast < sal_uInt32> ( rEntry.nCrc );
|
2000-11-13 06:38:03 -06:00
|
|
|
aChucker << rEntry.nCompressedSize;
|
|
|
|
aChucker << rEntry.nSize;
|
|
|
|
}
|
|
|
|
|
2001-07-04 08:56:37 -05:00
|
|
|
sal_Int32 ZipOutputStream::writeLOC( const ZipEntry &rEntry )
|
2001-05-31 04:23:43 -05:00
|
|
|
throw(IOException, RuntimeException)
|
2000-11-13 06:38:03 -06:00
|
|
|
{
|
2001-09-14 09:01:22 -05:00
|
|
|
sal_Int16 nNameLength = static_cast < sal_Int16 > (rEntry.sName.getLength());
|
2001-05-31 04:23:43 -05:00
|
|
|
Sequence < sal_Int8 > aSequence(nNameLength);
|
2000-12-20 05:36:39 -06:00
|
|
|
sal_Int8 *pArray = aSequence.getArray();
|
2001-04-19 08:13:40 -05:00
|
|
|
|
2000-11-13 06:38:03 -06:00
|
|
|
aChucker << LOCSIG;
|
|
|
|
aChucker << rEntry.nVersion;
|
2001-05-31 04:23:43 -05:00
|
|
|
|
|
|
|
if (rEntry.nFlag & (1 << 4) )
|
|
|
|
{
|
|
|
|
// If it's an encrypted entry, we pretend its stored plain text
|
|
|
|
sal_Int16 nTmpFlag = rEntry.nFlag;
|
|
|
|
nTmpFlag &= ~(1 <<4 );
|
|
|
|
aChucker << nTmpFlag;
|
|
|
|
aChucker << static_cast < sal_Int16 > ( STORED );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aChucker << rEntry.nFlag;
|
|
|
|
aChucker << rEntry.nMethod;
|
|
|
|
}
|
|
|
|
|
2000-11-28 06:13:29 -06:00
|
|
|
aChucker << static_cast < sal_uInt32 > (rEntry.nTime);
|
2000-11-13 06:38:03 -06:00
|
|
|
if ((rEntry.nFlag & 8) == 8 )
|
|
|
|
{
|
|
|
|
aChucker << static_cast < sal_Int32 > (0);
|
|
|
|
aChucker << static_cast < sal_Int32 > (0);
|
|
|
|
aChucker << static_cast < sal_Int32 > (0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aChucker << static_cast < sal_uInt32 > (rEntry.nCrc);
|
|
|
|
aChucker << rEntry.nCompressedSize;
|
|
|
|
aChucker << rEntry.nSize;
|
|
|
|
}
|
|
|
|
aChucker << nNameLength;
|
2001-09-14 09:01:22 -05:00
|
|
|
aChucker << static_cast < sal_Int16 > (0);
|
2000-11-13 06:38:03 -06:00
|
|
|
|
|
|
|
const sal_Unicode *pChar = rEntry.sName.getStr();
|
2001-09-14 09:01:22 -05:00
|
|
|
VOS_ENSURE ( Impl_IsValidChar ( pChar, nNameLength, sal_True ), "Non US ASCII character in zipentry name!");
|
2001-04-19 08:13:40 -05:00
|
|
|
for ( sal_Int16 i = 0; i < nNameLength; i++)
|
2001-07-04 08:56:37 -05:00
|
|
|
pArray[i] = static_cast < const sal_Int8 > (pChar[i]);
|
|
|
|
aChucker.writeBytes( aSequence, nNameLength, pArray );
|
2001-09-14 09:01:22 -05:00
|
|
|
return LOCHDR + nNameLength;
|
2000-11-13 06:38:03 -06:00
|
|
|
}
|
2001-03-07 09:09:44 -06:00
|
|
|
sal_uInt32 ZipOutputStream::getCurrentDosTime( )
|
2000-11-21 05:07:21 -06:00
|
|
|
{
|
2001-04-27 08:56:07 -05:00
|
|
|
oslDateTime aDateTime;
|
|
|
|
TimeValue aTimeValue;
|
|
|
|
osl_getSystemTime ( &aTimeValue );
|
|
|
|
osl_getDateTimeFromTimeValue( &aTimeValue, &aDateTime);
|
2001-03-07 09:09:44 -06:00
|
|
|
|
2001-04-27 08:56:07 -05:00
|
|
|
sal_uInt32 nYear = static_cast <sal_uInt32> (aDateTime.Year);
|
2000-11-21 05:07:21 -06:00
|
|
|
|
|
|
|
if (nYear>1980)
|
|
|
|
nYear-=1980;
|
|
|
|
else if (nYear>80)
|
|
|
|
nYear-=80;
|
2001-04-27 08:56:07 -05:00
|
|
|
sal_uInt32 nResult = static_cast < sal_uInt32>( ( ( ( aDateTime.Day) +
|
|
|
|
( 32 * (aDateTime.Month)) +
|
2000-11-21 05:07:21 -06:00
|
|
|
( 512 * nYear ) ) << 16) |
|
2001-04-27 08:56:07 -05:00
|
|
|
( ( aDateTime.Seconds/2) +
|
|
|
|
( 32 * aDateTime.Minutes) +
|
|
|
|
( 2048 * static_cast <sal_uInt32 > (aDateTime.Hours) ) ) );
|
2001-03-07 09:09:44 -06:00
|
|
|
return nResult;
|
2000-11-21 05:07:21 -06:00
|
|
|
}
|
2001-03-07 09:09:44 -06:00
|
|
|
/*
|
|
|
|
|
|
|
|
This is actually never used, so I removed it, but thought that the
|
|
|
|
implementation details may be useful in the future...mtg 20010307
|
|
|
|
|
2001-04-27 08:56:07 -05:00
|
|
|
I stopped using the time library and used the OSL version instead, but
|
|
|
|
it might still be useful to have this code here..
|
|
|
|
|
2000-11-21 05:07:21 -06:00
|
|
|
void ZipOutputStream::dosDateToTMDate ( tm &rTime, sal_uInt32 nDosDate)
|
|
|
|
{
|
|
|
|
sal_uInt32 nDate = static_cast < sal_uInt32 > (nDosDate >> 16);
|
|
|
|
rTime.tm_mday = static_cast < sal_uInt32 > ( nDate & 0x1F);
|
|
|
|
rTime.tm_mon = static_cast < sal_uInt32 > ( ( ( (nDate) & 0x1E0)/0x20)-1);
|
|
|
|
rTime.tm_year = static_cast < sal_uInt32 > ( ( (nDate & 0x0FE00)/0x0200)+1980);
|
|
|
|
|
|
|
|
rTime.tm_hour = static_cast < sal_uInt32 > ( (nDosDate & 0xF800)/0x800);
|
|
|
|
rTime.tm_min = static_cast < sal_uInt32 > ( (nDosDate & 0x7E0)/0x20);
|
|
|
|
rTime.tm_sec = static_cast < sal_uInt32 > ( 2 * (nDosDate & 0x1F) );
|
|
|
|
}
|
2001-03-07 09:09:44 -06:00
|
|
|
*/
|
2000-11-21 05:07:21 -06:00
|
|
|
|