2010-10-12 15:57:08 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-22 18:32:07 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2006-09-17 16:28:29 +00:00
|
|
|
|
2014-10-09 15:22:54 +02:00
|
|
|
#include <ZipOutputStream.hxx>
|
|
|
|
|
2001-07-04 13:56:37 +00:00
|
|
|
#include <com/sun/star/packages/zip/ZipConstants.hpp>
|
2014-12-14 00:11:53 +01:00
|
|
|
#include <com/sun/star/io/XInputStream.hpp>
|
2011-03-09 17:29:09 +01:00
|
|
|
#include <com/sun/star/io/XOutputStream.hpp>
|
|
|
|
#include <comphelper/storagehelper.hxx>
|
2015-06-05 11:45:36 +01:00
|
|
|
#include <cppuhelper/exc_hlp.hxx>
|
2011-03-09 17:29:09 +01:00
|
|
|
|
2014-10-20 21:13:50 +02:00
|
|
|
#include <osl/time.h>
|
2016-12-01 11:14:24 +00:00
|
|
|
#include <osl/thread.hxx>
|
2014-10-20 21:13:50 +02:00
|
|
|
|
2001-07-04 13:56:37 +00:00
|
|
|
#include <PackageConstants.hxx>
|
2001-09-14 14:01:22 +00:00
|
|
|
#include <ZipEntry.hxx>
|
2014-10-21 15:17:13 +02:00
|
|
|
#include <ZipOutputEntry.hxx>
|
2014-10-20 21:13:50 +02:00
|
|
|
#include <ZipPackageStream.hxx>
|
2001-11-15 19:23:28 +00:00
|
|
|
|
2011-03-09 17:29:09 +01:00
|
|
|
using namespace com::sun::star;
|
2001-05-31 09:23:43 +00:00
|
|
|
using namespace com::sun::star::io;
|
2001-04-27 13:56:07 +00:00
|
|
|
using namespace com::sun::star::uno;
|
2001-07-04 13:56:37 +00:00
|
|
|
using namespace com::sun::star::packages::zip::ZipConstants;
|
2000-11-13 12:38:03 +00:00
|
|
|
|
|
|
|
/** This class is used to write Zip files
|
|
|
|
*/
|
2014-10-09 15:22:54 +02:00
|
|
|
ZipOutputStream::ZipOutputStream( const uno::Reference < io::XOutputStream > &xOStream )
|
|
|
|
: m_xStream(xOStream)
|
2016-07-08 14:29:53 +02:00
|
|
|
, mpThreadTaskTag( comphelper::ThreadPool::createThreadTaskTag() )
|
2014-10-07 14:44:53 +02:00
|
|
|
, m_aChucker(xOStream)
|
2015-11-10 10:20:43 +01:00
|
|
|
, m_pCurrentEntry(nullptr)
|
2000-11-13 12:38:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-04-14 12:44:47 +02:00
|
|
|
ZipOutputStream::~ZipOutputStream()
|
2000-11-13 12:38:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-10-21 10:37:02 +02:00
|
|
|
void ZipOutputStream::setEntry( ZipEntry *pEntry )
|
2014-10-20 21:13:50 +02:00
|
|
|
{
|
2014-10-21 10:37:02 +02:00
|
|
|
if (pEntry->nTime == -1)
|
|
|
|
pEntry->nTime = getCurrentDosTime();
|
|
|
|
if (pEntry->nMethod == -1)
|
|
|
|
pEntry->nMethod = DEFLATED;
|
|
|
|
pEntry->nVersion = 20;
|
|
|
|
pEntry->nFlag = 1 << 11;
|
|
|
|
if (pEntry->nSize == -1 || pEntry->nCompressedSize == -1 ||
|
|
|
|
pEntry->nCrc == -1)
|
2014-10-20 21:13:50 +02:00
|
|
|
{
|
2014-10-21 10:37:02 +02:00
|
|
|
pEntry->nSize = pEntry->nCompressedSize = 0;
|
|
|
|
pEntry->nFlag |= 8;
|
2014-10-20 21:13:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-03 16:19:55 +02:00
|
|
|
void ZipOutputStream::addDeflatingThread( ZipOutputEntry *pEntry, std::unique_ptr<comphelper::ThreadTask> pThread )
|
2014-10-21 15:17:13 +02:00
|
|
|
{
|
2018-07-03 16:19:55 +02:00
|
|
|
comphelper::ThreadPool::getSharedOptimalPool().pushTask(std::move(pThread));
|
2014-10-21 15:17:13 +02:00
|
|
|
m_aEntries.push_back(pEntry);
|
|
|
|
}
|
|
|
|
|
2014-10-27 14:26:54 +01:00
|
|
|
void ZipOutputStream::rawWrite( const Sequence< sal_Int8 >& rBuffer )
|
2014-10-20 21:13:50 +02:00
|
|
|
{
|
2014-10-27 14:26:54 +01:00
|
|
|
m_aChucker.WriteBytes( rBuffer );
|
2014-10-20 21:13:50 +02:00
|
|
|
}
|
|
|
|
|
2014-10-21 10:37:02 +02:00
|
|
|
void ZipOutputStream::rawCloseEntry( bool bEncrypt )
|
2000-12-13 16:00:47 +00:00
|
|
|
{
|
2014-10-21 10:37:02 +02:00
|
|
|
assert(m_pCurrentEntry && "Forgot to call writeLOC()?");
|
2014-10-20 21:13:50 +02:00
|
|
|
if ( m_pCurrentEntry->nMethod == DEFLATED && ( m_pCurrentEntry->nFlag & 8 ) )
|
|
|
|
writeEXT(*m_pCurrentEntry);
|
2014-10-21 12:21:22 +02:00
|
|
|
|
2014-10-21 10:37:02 +02:00
|
|
|
if (bEncrypt)
|
2014-10-21 12:21:22 +02:00
|
|
|
m_pCurrentEntry->nMethod = STORED;
|
|
|
|
|
2015-11-10 10:20:43 +01:00
|
|
|
m_pCurrentEntry = nullptr;
|
2000-12-13 16:00:47 +00:00
|
|
|
}
|
2001-05-31 09:23:43 +00:00
|
|
|
|
2018-08-11 10:23:06 +02:00
|
|
|
void ZipOutputStream::consumeScheduledThreadEntry(std::unique_ptr<ZipOutputEntry> pCandidate)
|
2000-11-13 12:38:03 +00:00
|
|
|
{
|
2016-03-16 15:14:13 +01:00
|
|
|
//Any exceptions thrown in the threads were caught and stored for now
|
2018-07-28 20:00:26 +01:00
|
|
|
const std::exception_ptr& rCaughtException(pCandidate->getParallelDeflateException());
|
|
|
|
if (rCaughtException)
|
2016-06-23 11:24:55 +02:00
|
|
|
{
|
2018-07-28 20:00:26 +01:00
|
|
|
m_aDeflateException = rCaughtException; // store it for later throwing
|
2016-06-23 11:24:55 +02:00
|
|
|
// the exception handler in DeflateThread should have cleaned temp file
|
|
|
|
return;
|
|
|
|
}
|
2014-10-21 15:17:13 +02:00
|
|
|
|
2016-03-16 15:14:13 +01:00
|
|
|
writeLOC(pCandidate->getZipEntry(), pCandidate->isEncrypt());
|
|
|
|
|
|
|
|
sal_Int32 nRead;
|
|
|
|
uno::Sequence< sal_Int8 > aSequence(n_ConstBufferSize);
|
|
|
|
uno::Reference< io::XInputStream > xInput = pCandidate->getData();
|
|
|
|
do
|
2014-10-21 15:17:13 +02:00
|
|
|
{
|
2016-03-16 15:14:13 +01:00
|
|
|
nRead = xInput->readBytes(aSequence, n_ConstBufferSize);
|
|
|
|
if (nRead < n_ConstBufferSize)
|
|
|
|
aSequence.realloc(nRead);
|
2015-06-05 11:45:36 +01:00
|
|
|
|
2016-03-16 15:14:13 +01:00
|
|
|
rawWrite(aSequence);
|
|
|
|
}
|
|
|
|
while (nRead == n_ConstBufferSize);
|
|
|
|
xInput.clear();
|
2014-12-14 00:11:53 +01:00
|
|
|
|
2016-03-16 15:14:13 +01:00
|
|
|
rawCloseEntry(pCandidate->isEncrypt());
|
|
|
|
|
|
|
|
pCandidate->getZipPackageStream()->successfullyWritten(pCandidate->getZipEntry());
|
|
|
|
pCandidate->deleteBufferFile();
|
|
|
|
}
|
2014-12-14 00:11:53 +01:00
|
|
|
|
2016-03-16 15:14:13 +01:00
|
|
|
void ZipOutputStream::consumeFinishedScheduledThreadEntries()
|
|
|
|
{
|
|
|
|
std::vector< ZipOutputEntry* > aNonFinishedEntries;
|
|
|
|
|
2018-08-11 10:23:06 +02:00
|
|
|
for(ZipOutputEntry* pEntry : m_aEntries)
|
2016-03-16 15:14:13 +01:00
|
|
|
{
|
2018-08-11 10:23:06 +02:00
|
|
|
if(pEntry->isFinished())
|
2016-03-16 15:14:13 +01:00
|
|
|
{
|
2018-08-11 10:23:06 +02:00
|
|
|
consumeScheduledThreadEntry(std::unique_ptr<ZipOutputEntry>(pEntry));
|
2014-12-14 00:11:53 +01:00
|
|
|
}
|
2016-03-16 15:14:13 +01:00
|
|
|
else
|
|
|
|
{
|
2018-08-11 10:23:06 +02:00
|
|
|
aNonFinishedEntries.push_back(pEntry);
|
2016-03-16 15:14:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// always reset to non-consumed entries
|
|
|
|
m_aEntries = aNonFinishedEntries;
|
|
|
|
}
|
2014-12-14 00:11:53 +01:00
|
|
|
|
2016-09-12 09:31:41 +02:00
|
|
|
void ZipOutputStream::reduceScheduledThreadsToGivenNumberOrLess(sal_Int32 nThreads)
|
2016-03-16 15:14:13 +01:00
|
|
|
{
|
|
|
|
while(static_cast< sal_Int32 >(m_aEntries.size()) > nThreads)
|
|
|
|
{
|
|
|
|
consumeFinishedScheduledThreadEntries();
|
2001-05-31 09:23:43 +00:00
|
|
|
|
2016-03-16 15:14:13 +01:00
|
|
|
if(static_cast< sal_Int32 >(m_aEntries.size()) > nThreads)
|
|
|
|
{
|
2018-07-07 13:34:20 +02:00
|
|
|
osl::Thread::wait(std::chrono::microseconds(100));
|
2016-03-16 15:14:13 +01:00
|
|
|
}
|
2014-10-21 15:17:13 +02:00
|
|
|
}
|
2016-03-16 15:14:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ZipOutputStream::finish()
|
|
|
|
{
|
|
|
|
assert(!m_aZipList.empty() && "Zip file must have at least one entry!");
|
|
|
|
|
|
|
|
// Wait for all threads to finish & write
|
2016-07-08 14:29:53 +02:00
|
|
|
comphelper::ThreadPool::getSharedOptimalPool().waitUntilDone(mpThreadTaskTag);
|
2016-03-16 15:14:13 +01:00
|
|
|
|
|
|
|
// consume all processed entries
|
2016-11-08 09:33:15 +02:00
|
|
|
while(!m_aEntries.empty())
|
|
|
|
{
|
|
|
|
ZipOutputEntry* pCandidate = m_aEntries.back();
|
|
|
|
m_aEntries.pop_back();
|
2018-08-11 10:23:06 +02:00
|
|
|
consumeScheduledThreadEntry(std::unique_ptr<ZipOutputEntry>(pCandidate));
|
2016-11-08 09:33:15 +02:00
|
|
|
}
|
2001-05-31 09:23:43 +00:00
|
|
|
|
2014-10-07 14:44:53 +02:00
|
|
|
sal_Int32 nOffset= static_cast < sal_Int32 > (m_aChucker.GetPosition());
|
2016-05-05 10:10:54 +02:00
|
|
|
for (ZipEntry* p : m_aZipList)
|
2014-10-21 15:17:13 +02:00
|
|
|
{
|
2016-05-05 10:10:54 +02:00
|
|
|
writeCEN( *p );
|
|
|
|
delete p;
|
2014-10-21 15:17:13 +02:00
|
|
|
}
|
2014-10-07 14:44:53 +02:00
|
|
|
writeEND( nOffset, static_cast < sal_Int32 > (m_aChucker.GetPosition()) - nOffset);
|
|
|
|
m_xStream->flush();
|
2014-10-21 15:17:13 +02:00
|
|
|
m_aZipList.clear();
|
2016-06-23 22:02:04 +02:00
|
|
|
|
2018-07-28 20:00:26 +01:00
|
|
|
if (m_aDeflateException)
|
2016-06-23 22:02:04 +02:00
|
|
|
{ // throw once all threads are finished and m_aEntries can be released
|
2018-07-28 20:00:26 +01:00
|
|
|
std::rethrow_exception(m_aDeflateException);
|
2016-06-23 22:02:04 +02:00
|
|
|
}
|
2000-11-13 12:38:03 +00:00
|
|
|
}
|
2001-05-31 09:23:43 +00:00
|
|
|
|
2016-04-14 10:20:52 +02:00
|
|
|
const css::uno::Reference< css::io::XOutputStream >& ZipOutputStream::getStream()
|
2014-12-13 23:09:10 +01:00
|
|
|
{
|
|
|
|
return m_xStream;
|
|
|
|
}
|
|
|
|
|
2000-11-13 12:38:03 +00:00
|
|
|
void ZipOutputStream::writeEND(sal_uInt32 nOffset, sal_uInt32 nLength)
|
|
|
|
{
|
2014-12-11 08:21:51 +02:00
|
|
|
m_aChucker.WriteInt32( ENDSIG );
|
2015-01-15 12:23:20 +02:00
|
|
|
m_aChucker.WriteInt16( 0 );
|
|
|
|
m_aChucker.WriteInt16( 0 );
|
|
|
|
m_aChucker.WriteInt16( m_aZipList.size() );
|
|
|
|
m_aChucker.WriteInt16( m_aZipList.size() );
|
2014-12-11 08:21:51 +02:00
|
|
|
m_aChucker.WriteUInt32( nLength );
|
|
|
|
m_aChucker.WriteUInt32( nOffset );
|
2015-01-15 12:23:20 +02:00
|
|
|
m_aChucker.WriteInt16( 0 );
|
2000-11-13 12:38:03 +00:00
|
|
|
}
|
2012-09-21 13:09:29 +01:00
|
|
|
|
|
|
|
static sal_uInt32 getTruncated( sal_Int64 nNum, bool *pIsTruncated )
|
|
|
|
{
|
|
|
|
if( nNum >= 0xffffffff )
|
|
|
|
{
|
|
|
|
*pIsTruncated = true;
|
|
|
|
return 0xffffffff;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return static_cast< sal_uInt32 >( nNum );
|
|
|
|
}
|
|
|
|
|
2001-05-31 09:23:43 +00:00
|
|
|
void ZipOutputStream::writeCEN( const ZipEntry &rEntry )
|
2000-11-13 12:38:03 +00:00
|
|
|
{
|
2014-02-16 22:51:15 +01:00
|
|
|
if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( rEntry.sPath, true ) )
|
2014-05-23 12:03:21 +02:00
|
|
|
throw IOException("Unexpected character is used in file name." );
|
2009-02-12 10:27:21 +00:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OString sUTF8Name = OUStringToOString( rEntry.sPath, RTL_TEXTENCODING_UTF8 );
|
2009-02-12 10:27:21 +00:00
|
|
|
sal_Int16 nNameLength = static_cast < sal_Int16 > ( sUTF8Name.getLength() );
|
2000-11-13 12:38:03 +00:00
|
|
|
|
2014-12-11 08:21:51 +02:00
|
|
|
m_aChucker.WriteInt32( CENSIG );
|
|
|
|
m_aChucker.WriteInt16( rEntry.nVersion );
|
|
|
|
m_aChucker.WriteInt16( rEntry.nVersion );
|
|
|
|
m_aChucker.WriteInt16( rEntry.nFlag );
|
|
|
|
m_aChucker.WriteInt16( rEntry.nMethod );
|
2012-09-21 13:09:29 +01:00
|
|
|
bool bWrite64Header = false;
|
|
|
|
|
2015-01-15 12:23:20 +02:00
|
|
|
m_aChucker.WriteUInt32( rEntry.nTime );
|
|
|
|
m_aChucker.WriteUInt32( rEntry.nCrc );
|
2014-12-11 08:21:51 +02:00
|
|
|
m_aChucker.WriteUInt32( getTruncated( rEntry.nCompressedSize, &bWrite64Header ) );
|
|
|
|
m_aChucker.WriteUInt32( getTruncated( rEntry.nSize, &bWrite64Header ) );
|
|
|
|
m_aChucker.WriteInt16( nNameLength );
|
2015-01-15 12:23:20 +02:00
|
|
|
m_aChucker.WriteInt16( 0 );
|
|
|
|
m_aChucker.WriteInt16( 0 );
|
|
|
|
m_aChucker.WriteInt16( 0 );
|
|
|
|
m_aChucker.WriteInt16( 0 );
|
|
|
|
m_aChucker.WriteInt32( 0 );
|
2014-12-11 08:21:51 +02:00
|
|
|
m_aChucker.WriteUInt32( getTruncated( rEntry.nOffset, &bWrite64Header ) );
|
2012-09-21 13:09:29 +01:00
|
|
|
|
|
|
|
if( bWrite64Header )
|
|
|
|
{
|
|
|
|
// FIXME64: need to append a ZIP64 header instead of throwing
|
2014-05-14 14:15:38 -04:00
|
|
|
// We're about to silently lose people's data - which they are
|
2012-09-21 13:09:29 +01:00
|
|
|
// unlikely to appreciate so fail instead:
|
2014-05-23 12:03:21 +02:00
|
|
|
throw IOException( "File contains streams that are too large." );
|
2012-09-21 13:09:29 +01:00
|
|
|
}
|
2001-05-31 09:23:43 +00:00
|
|
|
|
2015-01-17 18:50:39 +01:00
|
|
|
Sequence < sal_Int8 > aSequence( reinterpret_cast<sal_Int8 const *>(sUTF8Name.getStr()), sUTF8Name.getLength() );
|
2014-10-07 14:44:53 +02:00
|
|
|
m_aChucker.WriteBytes( aSequence );
|
2000-11-13 12:38:03 +00:00
|
|
|
}
|
2000-11-21 11:07:21 +00:00
|
|
|
|
2014-10-20 21:13:50 +02:00
|
|
|
void ZipOutputStream::writeEXT( const ZipEntry &rEntry )
|
|
|
|
{
|
|
|
|
bool bWrite64Header = false;
|
|
|
|
|
2014-12-11 08:21:51 +02:00
|
|
|
m_aChucker.WriteInt32( EXTSIG );
|
2015-01-15 12:23:20 +02:00
|
|
|
m_aChucker.WriteUInt32( rEntry.nCrc );
|
2014-12-11 08:21:51 +02:00
|
|
|
m_aChucker.WriteUInt32( getTruncated( rEntry.nCompressedSize, &bWrite64Header ) );
|
|
|
|
m_aChucker.WriteUInt32( getTruncated( rEntry.nSize, &bWrite64Header ) );
|
2014-10-20 21:13:50 +02:00
|
|
|
|
|
|
|
if( bWrite64Header )
|
|
|
|
{
|
|
|
|
// FIXME64: need to append a ZIP64 header instead of throwing
|
|
|
|
// We're about to silently lose people's data - which they are
|
|
|
|
// unlikely to appreciate so fail instead:
|
|
|
|
throw IOException( "File contains streams that are too large." );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-21 10:37:02 +02:00
|
|
|
void ZipOutputStream::writeLOC( ZipEntry *pEntry, bool bEncrypt )
|
2014-10-20 21:13:50 +02:00
|
|
|
{
|
2014-10-21 10:37:02 +02:00
|
|
|
assert(!m_pCurrentEntry && "Forgot to close an entry with rawCloseEntry()?");
|
|
|
|
m_pCurrentEntry = pEntry;
|
|
|
|
m_aZipList.push_back( m_pCurrentEntry );
|
|
|
|
const ZipEntry &rEntry = *m_pCurrentEntry;
|
|
|
|
|
2014-10-20 21:13:50 +02:00
|
|
|
if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( rEntry.sPath, true ) )
|
|
|
|
throw IOException("Unexpected character is used in file name." );
|
|
|
|
|
|
|
|
OString sUTF8Name = OUStringToOString( rEntry.sPath, RTL_TEXTENCODING_UTF8 );
|
|
|
|
sal_Int16 nNameLength = static_cast < sal_Int16 > ( sUTF8Name.getLength() );
|
|
|
|
|
2014-12-11 08:21:51 +02:00
|
|
|
m_aChucker.WriteInt32( LOCSIG );
|
|
|
|
m_aChucker.WriteInt16( rEntry.nVersion );
|
2014-10-20 21:13:50 +02:00
|
|
|
|
2014-12-11 08:21:51 +02:00
|
|
|
m_aChucker.WriteInt16( rEntry.nFlag );
|
2014-10-21 12:21:22 +02:00
|
|
|
// If it's an encrypted entry, we pretend its stored plain text
|
2014-10-21 10:37:02 +02:00
|
|
|
if (bEncrypt)
|
2015-01-15 12:23:20 +02:00
|
|
|
m_aChucker.WriteInt16( STORED );
|
2014-10-20 21:13:50 +02:00
|
|
|
else
|
2014-12-11 08:21:51 +02:00
|
|
|
m_aChucker.WriteInt16( rEntry.nMethod );
|
2014-10-20 21:13:50 +02:00
|
|
|
|
|
|
|
bool bWrite64Header = false;
|
|
|
|
|
2015-01-15 12:23:20 +02:00
|
|
|
m_aChucker.WriteUInt32( rEntry.nTime );
|
2014-10-20 21:13:50 +02:00
|
|
|
if ((rEntry.nFlag & 8) == 8 )
|
|
|
|
{
|
2015-01-15 12:23:20 +02:00
|
|
|
m_aChucker.WriteInt32( 0 );
|
|
|
|
m_aChucker.WriteInt32( 0 );
|
|
|
|
m_aChucker.WriteInt32( 0 );
|
2014-10-20 21:13:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-15 12:23:20 +02:00
|
|
|
m_aChucker.WriteUInt32( rEntry.nCrc );
|
2014-12-11 08:21:51 +02:00
|
|
|
m_aChucker.WriteUInt32( getTruncated( rEntry.nCompressedSize, &bWrite64Header ) );
|
|
|
|
m_aChucker.WriteUInt32( getTruncated( rEntry.nSize, &bWrite64Header ) );
|
2014-10-20 21:13:50 +02:00
|
|
|
}
|
2014-12-11 08:21:51 +02:00
|
|
|
m_aChucker.WriteInt16( nNameLength );
|
2015-01-15 12:23:20 +02:00
|
|
|
m_aChucker.WriteInt16( 0 );
|
2014-10-20 21:13:50 +02:00
|
|
|
|
|
|
|
if( bWrite64Header )
|
|
|
|
{
|
|
|
|
// FIXME64: need to append a ZIP64 header instead of throwing
|
|
|
|
// We're about to silently lose people's data - which they are
|
|
|
|
// unlikely to appreciate so fail instead:
|
|
|
|
throw IOException( "File contains streams that are too large." );
|
|
|
|
}
|
|
|
|
|
2015-01-17 18:50:39 +01:00
|
|
|
Sequence < sal_Int8 > aSequence( reinterpret_cast<sal_Int8 const *>(sUTF8Name.getStr()), sUTF8Name.getLength() );
|
2014-10-20 21:13:50 +02:00
|
|
|
m_aChucker.WriteBytes( aSequence );
|
|
|
|
|
2014-10-21 10:37:02 +02:00
|
|
|
m_pCurrentEntry->nOffset = m_aChucker.GetPosition() - (LOCHDR + nNameLength);
|
2014-10-20 21:13:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sal_uInt32 ZipOutputStream::getCurrentDosTime()
|
|
|
|
{
|
|
|
|
oslDateTime aDateTime;
|
|
|
|
TimeValue aTimeValue;
|
|
|
|
osl_getSystemTime ( &aTimeValue );
|
|
|
|
osl_getDateTimeFromTimeValue( &aTimeValue, &aDateTime);
|
|
|
|
|
|
|
|
// at year 2108, there is an overflow
|
|
|
|
// -> some decision needs to be made
|
|
|
|
// how to handle the ZIP file format (just overflow?)
|
|
|
|
|
|
|
|
// if the current system time is before 1980,
|
|
|
|
// then the time traveller will have to make a decision
|
|
|
|
// how to handle the ZIP file format before it is invented
|
|
|
|
// (just underflow?)
|
|
|
|
|
|
|
|
assert(aDateTime.Year > 1980 && aDateTime.Year < 2108);
|
|
|
|
|
|
|
|
sal_uInt32 nYear = static_cast <sal_uInt32> (aDateTime.Year);
|
|
|
|
|
|
|
|
if (nYear>=1980)
|
|
|
|
nYear-=1980;
|
|
|
|
else if (nYear>=80)
|
|
|
|
{
|
|
|
|
nYear-=80;
|
|
|
|
}
|
|
|
|
sal_uInt32 nResult = static_cast < sal_uInt32>( ( ( ( aDateTime.Day) +
|
|
|
|
( 32 * (aDateTime.Month)) +
|
|
|
|
( 512 * nYear ) ) << 16) |
|
|
|
|
( ( aDateTime.Seconds/2) +
|
|
|
|
( 32 * aDateTime.Minutes) +
|
|
|
|
( 2048 * static_cast <sal_uInt32 > (aDateTime.Hours) ) ) );
|
|
|
|
return nResult;
|
|
|
|
}
|
|
|
|
|
2010-10-12 15:57:08 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|