summaryrefslogtreecommitdiff
path: root/package
diff options
context:
space:
mode:
authorMartin Gallwey <mtg@openoffice.org>2000-12-13 16:00:47 +0000
committerMartin Gallwey <mtg@openoffice.org>2000-12-13 16:00:47 +0000
commit4b11504f4ad039fb2311061c7544f00b6ff23c0f (patch)
tree77bd71291871a03a9a5e577114914fc4f5cfbbe0 /package
parentd6a8a2916c2c00f702b68d427af75d83e2163eb6 (diff)
This rather enormous commit has the following features:
1. Fixed three different memory leaks, one of them quite serious 2. Considerably streamlined the ZipPackageBuffer class - large performance increase, also streamlined EntryInputClass in the same way... 3. Correctly saves embedded zip files as embedded zip files instead of directories 4. Supports the copying of raw streams instead of de-compressing/re- compressing unnecessarily. Marty
Diffstat (limited to 'package')
-rw-r--r--package/inc/ByteGrabber.hxx7
-rw-r--r--package/inc/ZipFile.hxx9
-rw-r--r--package/inc/ZipOutputStream.hxx11
-rw-r--r--package/inc/ZipPackage.hxx46
-rw-r--r--package/inc/ZipPackageBuffer.hxx9
-rw-r--r--package/inc/ZipPackageFolder.hxx32
-rw-r--r--package/source/zipapi/ByteGrabber.cxx9
-rw-r--r--package/source/zipapi/Deflater.cxx13
-rw-r--r--package/source/zipapi/EntryInputStream.cxx26
-rw-r--r--package/source/zipapi/Inflater.cxx13
-rw-r--r--package/source/zipapi/ZipFile.cxx103
-rw-r--r--package/source/zipapi/ZipOutputStream.cxx14
-rw-r--r--package/source/zippackage/ZipPackage.cxx214
-rw-r--r--package/source/zippackage/ZipPackageBuffer.cxx31
-rw-r--r--package/source/zippackage/ZipPackageFolder.cxx241
-rw-r--r--package/source/zippackage/ZipPackageStream.cxx28
16 files changed, 556 insertions, 250 deletions
diff --git a/package/inc/ByteGrabber.hxx b/package/inc/ByteGrabber.hxx
index baa220eaf54e..3f0fdc195d5b 100644
--- a/package/inc/ByteGrabber.hxx
+++ b/package/inc/ByteGrabber.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ByteGrabber.hxx,v $
*
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: mtg $ $Date: 2000-11-29 13:47:16 $
+ * last change: $Author: mtg $ $Date: 2000-12-13 17:00:36 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -79,9 +79,10 @@ private:
com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xStream;
com::sun::star::uno::Reference < com::sun::star::io::XSeekable > xSeek;
public:
- ByteGrabber (com::sun::star::uno::Reference<com::sun::star::io::XInputStream> xIstream);
+ ByteGrabber (com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xIstream);
~ByteGrabber();
+ void setInputStream (com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewStream);
// XInputStream
virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
diff --git a/package/inc/ZipFile.hxx b/package/inc/ZipFile.hxx
index 0d3e6c1da808..c7cc9dd1c805 100644
--- a/package/inc/ZipFile.hxx
+++ b/package/inc/ZipFile.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ZipFile.hxx,v $
*
- * $Revision: 1.6 $
+ * $Revision: 1.7 $
*
- * last change: $Author: mtg $ $Date: 2000-12-04 11:30:06 $
+ * last change: $Author: mtg $ $Date: 2000-12-13 17:00:36 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -121,7 +121,12 @@ public:
ZipFile( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > &xInput, sal_Bool bInitialise)
throw(::com::sun::star::io::IOException, com::sun::star::package::ZipException, com::sun::star::uno::RuntimeException);
void updateFromManList(std::vector < ManifestEntry * > &rManList);
+ void setInputStream ( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewStream );
+ sal_uInt32 SAL_CALL getHeader(const ::com::sun::star::package::ZipEntry& rEntry)
+ throw(::com::sun::star::io::IOException, ::com::sun::star::package::ZipException, ::com::sun::star::uno::RuntimeException);
virtual ~ZipFile();
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawStream( const ::com::sun::star::package::ZipEntry& rEntry )
+ throw(::com::sun::star::io::IOException, ::com::sun::star::package::ZipException, ::com::sun::star::uno::RuntimeException);
// XElementAccess
virtual ::com::sun::star::uno::Type SAL_CALL getElementType( )
diff --git a/package/inc/ZipOutputStream.hxx b/package/inc/ZipOutputStream.hxx
index d643c3a2da56..9d569f8b7d73 100644
--- a/package/inc/ZipOutputStream.hxx
+++ b/package/inc/ZipOutputStream.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ZipOutputStream.hxx,v $
*
- * $Revision: 1.6 $
+ * $Revision: 1.7 $
*
- * last change: $Author: mtg $ $Date: 2000-12-04 11:30:06 $
+ * last change: $Author: mtg $ $Date: 2000-12-13 17:00:36 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -118,6 +118,13 @@ private:
public:
ZipOutputStream( com::sun::star::uno::Reference < com::sun::star::io::XOutputStream > &xOStream, sal_Int32 nNewBufferSize);
virtual ~ZipOutputStream(void);
+
+ // rawWrite to support a direct write to the output stream
+ void SAL_CALL rawWrite( const ::com::sun::star::uno::Sequence< sal_Int8 >& rBuffer)
+ throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
+ void SAL_CALL rawCloseEntry( )
+ throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
+
virtual void SAL_CALL setComment( const ::rtl::OUString& rComment )
throw(::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL setMethod( sal_Int32 nNewMethod )
diff --git a/package/inc/ZipPackage.hxx b/package/inc/ZipPackage.hxx
index ef8c17489ab5..b9840bb28a4c 100644
--- a/package/inc/ZipPackage.hxx
+++ b/package/inc/ZipPackage.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ZipPackage.hxx,v $
*
- * $Revision: 1.13 $
+ * $Revision: 1.14 $
*
- * last change: $Author: mtg $ $Date: 2000-11-29 13:47:16 $
+ * last change: $Author: mtg $ $Date: 2000-12-13 17:00:36 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -61,8 +61,8 @@
#ifndef _ZIP_PACKAGE_HXX
#define _ZIP_PACKAGE_HXX
-#ifndef _CPPUHELPER_IMPLBASE4_HXX_
-#include <cppuhelper/implbase4.hxx> // helper for implementations
+#ifndef _CPPUHELPER_WEAK_HXX_
+#include <cppuhelper/weak.hxx> // helper for implementations
#endif
#ifndef _CPPUHELPER_FACTORY_HXX_
@@ -85,6 +85,10 @@
#include <com/sun/star/util/XChangesBatch.hpp>
#endif
+#ifndef _COM_SUN_STAR_LANG_XUNOTUNNEL_HPP_
+#include <com/sun/star/lang/XUnoTunnel.hpp>
+#endif
+
#ifndef _UCBHELPER_CONTENT_HXX
#include <ucbhelper/content.hxx>
#endif
@@ -113,10 +117,6 @@
#include "ZipPackageBuffer.hxx"
#endif
-#ifdef _DEBUG_RECURSION_
-#include "testzip.hxx"
-#endif
-
#ifndef _MANIFEST_ENTRY_HXX
#include "ManifestEntry.hxx"
#endif
@@ -130,18 +130,20 @@
#endif
#include <vector>
-
-class ZipPackage : public cppu::WeakImplHelper4<
- com::sun::star::lang::XInitialization,
- com::sun::star::container::XHierarchicalNameAccess,
- com::sun::star::lang::XSingleServiceFactory,
- com::sun::star::util::XChangesBatch
- >
+class ZipPackageFolder;
+
+class ZipPackage : public com::sun::star::lang::XInitialization,
+ public com::sun::star::lang::XSingleServiceFactory,
+ public com::sun::star::lang::XUnoTunnel,
+ public com::sun::star::container::XHierarchicalNameAccess,
+ public com::sun::star::util::XChangesBatch,
+ public ::cppu::OWeakObject
{
private:
ZipPackageFolder *pRootFolder;
ZipFile *pZipFile;
::ucb::Content *pContent;
+ sal_Bool bContained;
::std::vector < com::sun::star::uno::Reference < com::sun::star::lang::XSingleServiceFactory > > aContainedZips;
::com::sun::star::uno::Reference < com::sun::star::package::XZipFile > xZipFile;
::com::sun::star::uno::Reference < com::sun::star::lang::XUnoTunnel > xRootFolder;
@@ -151,6 +153,7 @@ private:
sal_Bool isZipFile(com::sun::star::package::ZipEntry &rEntry);
void getZipFileContents();
void destroyFolderTree( ::com::sun::star::uno::Reference < ::com::sun::star::lang::XUnoTunnel > xFolder );
+
public:
ZipPackage (com::sun::star::uno::Reference < com::sun::star::io::XInputStream > &xInput,
const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > &xNewFactory);
@@ -159,7 +162,16 @@ public:
{
return pRootFolder;
}
+ ZipPackageBuffer & SAL_CALL ZipPackage::writeToBuffer()
+ throw(::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
virtual ~ZipPackage( void );
+ // XInterface
+ virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& rType )
+ throw(::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL acquire( )
+ throw();
+ virtual void SAL_CALL release( )
+ throw();
// XInitialization
virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
@@ -183,5 +195,9 @@ public:
// Uno componentiseralation
com::sun::star::uno::Reference< com::sun::star::uno::XInterface > ZipFile_create(
const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > & xMgr );
+ virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier )
+ throw(::com::sun::star::uno::RuntimeException);
+ com::sun::star::uno::Sequence < sal_Int8 > getUnoTunnelImplementationId( void )
+ throw(::com::sun::star::uno::RuntimeException);
};
#endif
diff --git a/package/inc/ZipPackageBuffer.hxx b/package/inc/ZipPackageBuffer.hxx
index 6c458ba51aa1..93e5bd61db61 100644
--- a/package/inc/ZipPackageBuffer.hxx
+++ b/package/inc/ZipPackageBuffer.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ZipPackageBuffer.hxx,v $
*
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: mtg $ $Date: 2000-11-27 16:51:45 $
+ * last change: $Author: mtg $ $Date: 2000-12-13 17:00:36 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -81,6 +81,8 @@
#include <cppuhelper/weak.hxx>
#endif
+#include <memory.h> // for memcpy
+
class ZipPackageBuffer :
public com::sun::star::io::XInputStream,
public com::sun::star::io::XOutputStream,
@@ -101,6 +103,7 @@ public:
throw();
virtual void SAL_CALL release(void)
throw();
+ // XInputStream
virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
@@ -111,12 +114,14 @@ public:
throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL closeInput( )
throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
+ // XOutputStream
virtual void SAL_CALL writeBytes( const ::com::sun::star::uno::Sequence< sal_Int8 >& aData )
throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL flush( )
throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL closeOutput( )
throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
+ // XSeekable
virtual void SAL_CALL seek( sal_Int64 location )
throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
virtual sal_Int64 SAL_CALL getPosition( )
diff --git a/package/inc/ZipPackageFolder.hxx b/package/inc/ZipPackageFolder.hxx
index 934b7b5080ef..28a7fed0a963 100644
--- a/package/inc/ZipPackageFolder.hxx
+++ b/package/inc/ZipPackageFolder.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ZipPackageFolder.hxx,v $
*
- * $Revision: 1.11 $
+ * $Revision: 1.12 $
*
- * last change: $Author: mtg $ $Date: 2000-12-04 11:30:06 $
+ * last change: $Author: mtg $ $Date: 2000-12-13 17:00:36 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -77,15 +77,15 @@
#include <com/sun/star/container/XEnumerationAccess.hpp>
#endif
-#ifndef __com_sun_star_package_ZipEntry_hpp__
+#ifndef _COM_SUN_STAR_PACKAGE_ZIPENTRY_HPP_
#include <com/sun/star/package/ZipEntry.hpp>
#endif
-#ifndef __com_sun_star_beans_XPropertySet_hpp__
+#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
#include <com/sun/star/beans/XPropertySet.hpp>
#endif
-#ifndef __com_sun_star_lang_XUnoTunnel_hpp__
+#ifndef _COM_SUN_STAR_LANG_XUNOTUNNEl_HPP_
#include <com/sun/star/lang/XUnoTunnel.hpp>
#endif
@@ -131,6 +131,14 @@ struct hashFunc
#include "ZipPackageStream.hxx"
#endif
+#ifndef _ZIP_PACKAGE_HXX
+#include "ZipPackage.hxx"
+#endif
+
+#ifndef _ZIP_PACKAGE_BUFFER_HXX
+#include "ZipPackageBuffer.hxx"
+#endif
+
#ifndef _ZIP_OUTPUT_STREAM_HXX
#include "ZipOutputStream.hxx"
#endif
@@ -143,12 +151,8 @@ struct hashFunc
#include "ManifestEntry.hxx"
#endif
-#ifdef _DEBUG_RECURSION_
-#include "testzip.hxx"
-#endif
-
typedef std::hash_map < rtl::OUString, com::sun::star::uno::Reference < com::sun::star::lang::XUnoTunnel > , hashFunc, eqFunc > TunnelHash;
-
+class ZipPackage;
class ZipPackageFolder : public ZipPackageEntry,
public ::com::sun::star::container::XNameContainer,
public ::com::sun::star::container::XEnumerationAccess,
@@ -158,16 +162,18 @@ private:
::rtl::OUString sMediaType;
TunnelHash aContents;
com::sun::star::uno::Reference < com::sun::star::uno::XInterface > xParent;
- void setEntry(com::sun::star::package::ZipEntry &rDest, com::sun::star::package::ZipEntry &rSrc);
public:
- ZipPackageFolder ( void ) ;
+ ZipPackage *pPackage;
+ ZipPackageFolder ( void );
+ virtual ~ZipPackageFolder( void );
+
+ static void copyZipEntry( com::sun::star::package::ZipEntry &rDest, const com::sun::star::package::ZipEntry &rSource);
void saveContents(rtl::OUString &rPath, std::vector < ManifestEntry * > &rManList, ZipOutputStream & rZipOut)
throw(::com::sun::star::uno::RuntimeException);
void updateReferences( ZipFile * pNewZipFile);
inline sal_Bool isFolder( void ) {return sal_True;}
inline sal_Bool isStream( void ) {return sal_False;}
- virtual ~ZipPackageFolder( void );
// XInterface
virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& rType )
throw(::com::sun::star::uno::RuntimeException);
diff --git a/package/source/zipapi/ByteGrabber.cxx b/package/source/zipapi/ByteGrabber.cxx
index 04d675d54f52..6ee81797eeb3 100644
--- a/package/source/zipapi/ByteGrabber.cxx
+++ b/package/source/zipapi/ByteGrabber.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ByteGrabber.cxx,v $
*
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: mtg $ $Date: 2000-12-01 10:49:47 $
+ * last change: $Author: mtg $ $Date: 2000-12-13 17:00:43 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -78,6 +78,11 @@ ByteGrabber::~ByteGrabber()
if ( xStream.is() )
xStream->closeInput();
}
+void ByteGrabber::setInputStream (uno::Reference < io::XInputStream > xNewStream)
+{
+ xStream = xNewStream;
+ xSeek = uno::Reference < io::XSeekable > (xNewStream, uno::UNO_QUERY);
+}
// XInputStream chained
sal_Int32 SAL_CALL ByteGrabber::readBytes( uno::Sequence< sal_Int8 >& aData,
diff --git a/package/source/zipapi/Deflater.cxx b/package/source/zipapi/Deflater.cxx
index 71b77fa88ae4..3dcec91fa237 100644
--- a/package/source/zipapi/Deflater.cxx
+++ b/package/source/zipapi/Deflater.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: Deflater.cxx,v $
*
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: mtg $ $Date: 2000-11-21 17:57:07 $
+ * last change: $Author: mtg $ $Date: 2000-12-13 17:00:43 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -74,8 +74,7 @@ using namespace com::sun::star;
Deflater::~Deflater(void)
{
- if (pStream)
- delete pStream;
+ end();
}
void Deflater::init (sal_Int32 nLevel, sal_Int32 nStrategy, sal_Bool bNowrap)
{
@@ -312,6 +311,10 @@ void SAL_CALL Deflater::reset( )
void SAL_CALL Deflater::end( )
throw(uno::RuntimeException)
{
- z_deflateEnd(pStream);
+ if (pStream != NULL)
+ {
+ z_deflateEnd(pStream);
+ delete pStream;
+ }
pStream = NULL;
}
diff --git a/package/source/zipapi/EntryInputStream.cxx b/package/source/zipapi/EntryInputStream.cxx
index 34a78847ac50..51ab57f4b2f5 100644
--- a/package/source/zipapi/EntryInputStream.cxx
+++ b/package/source/zipapi/EntryInputStream.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: EntryInputStream.cxx,v $
*
- * $Revision: 1.7 $
+ * $Revision: 1.8 $
*
- * last change: $Author: obo $ $Date: 2000-12-08 12:28:22 $
+ * last change: $Author: mtg $ $Date: 2000-12-13 17:00:43 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -71,6 +71,10 @@ using namespace com::sun::star;
/** Provides access to the compressed data in a zipfile. Decompresses on the fly, but
* does not currently support XSeekable into the compressed data stream.
+ *
+ * 04/12/00 - uncompresses the stream into memory and seeks on it 'in memory'
+ * This is a "temporary" fix which will be changed ASAP (read 2001)
+ *
* Acts on the same underlying XInputStream as both the full Zip File and other
* EntryInputStreams, and thus must maintain its current position in the stream and
* seek to it before performing any reads.
@@ -97,6 +101,7 @@ EntryInputStream::EntryInputStream( uno::Reference < io::XInputStream > xNewInpu
xStream->readBytes(aSequence, static_cast < sal_Int32 > (nNewEnd - nNewBegin));
aInflater.setInputSegment(aSequence, 0, static_cast < sal_Int32 > (nNewEnd - nNewBegin) );
aInflater.doInflate(aBuffer);
+ aInflater.end();
}
else
{
@@ -124,20 +129,15 @@ sal_Int32 SAL_CALL EntryInputStream::readBytes( uno::Sequence< sal_Int8 >& aData
sal_Int32 nBytesToRead )
throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
{
- if (nBytesToRead <=0)
- return 0;
+ if (nBytesToRead <0)
+ throw io::BufferSizeExceededException(::rtl::OUString(), *this);
if (nBytesToRead + nCurrent > nEnd)
- {
- if (nCurrent > nEnd)
- return 0;
nBytesToRead = static_cast < sal_Int32> (nEnd - nCurrent);
- }
aData.realloc( nBytesToRead );
-
- for ( sal_Int32 i = 0; i< nBytesToRead;i++,nCurrent++)
- aData[i] = aBuffer[static_cast < sal_Int32 > (nCurrent)];
+ memcpy(aData.getArray(), aBuffer.getConstArray() + nCurrent, nBytesToRead);
+ nCurrent+=nBytesToRead;
return nBytesToRead;
/*
@@ -186,8 +186,8 @@ sal_Int32 SAL_CALL EntryInputStream::readSomeBytes( uno::Sequence< sal_Int8 >& a
void SAL_CALL EntryInputStream::skipBytes( sal_Int32 nBytesToSkip )
throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
{
- if (nBytesToSkip == 0)
- return;
+ if (nBytesToSkip < 0)
+ throw io::BufferSizeExceededException(::rtl::OUString(), *this);
if (nBytesToSkip + nCurrent > nEnd )
nBytesToSkip = static_cast < sal_Int32 > (nEnd - nCurrent);
diff --git a/package/source/zipapi/Inflater.cxx b/package/source/zipapi/Inflater.cxx
index 5e4eba639f74..934cabb0862d 100644
--- a/package/source/zipapi/Inflater.cxx
+++ b/package/source/zipapi/Inflater.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: Inflater.cxx,v $
*
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
*
- * last change: $Author: mtg $ $Date: 2000-11-21 12:07:21 $
+ * last change: $Author: mtg $ $Date: 2000-12-13 17:00:43 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -116,8 +116,7 @@ Inflater::Inflater()
}
Inflater::~Inflater()
{
- if (pStream)
- delete pStream;
+ end();
}
void SAL_CALL Inflater::setInputSegment( const com::sun::star::uno::Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength )
throw(com::sun::star::uno::RuntimeException)
@@ -231,7 +230,11 @@ void SAL_CALL Inflater::reset( )
void SAL_CALL Inflater::end( )
throw(com::sun::star::uno::RuntimeException)
{
- z_inflateEnd(pStream);
+ if (pStream != NULL)
+ {
+ z_inflateEnd(pStream);
+ delete pStream;
+ }
pStream = NULL;
}
diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx
index 319f8f512b30..82aa2caa6b2e 100644
--- a/package/source/zipapi/ZipFile.cxx
+++ b/package/source/zipapi/ZipFile.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ZipFile.cxx,v $
*
- * $Revision: 1.12 $
+ * $Revision: 1.13 $
*
- * last change: $Author: mtg $ $Date: 2000-12-08 13:40:03 $
+ * last change: $Author: mtg $ $Date: 2000-12-13 17:00:43 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -76,7 +76,7 @@ ZipFile::ZipFile (uno::Reference < io::XInputStream > &xInput)
{
readCEN();
}
-ZipFile::ZipFile( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > &xInput, sal_Bool bInitialise)
+ZipFile::ZipFile( uno::Reference < io::XInputStream > &xInput, sal_Bool bInitialise)
throw(io::IOException, package::ZipException, uno::RuntimeException)
: xStream(xInput)
, aGrabber(xInput)
@@ -84,28 +84,38 @@ ZipFile::ZipFile( com::sun::star::uno::Reference < com::sun::star::io::XInputStr
if (bInitialise)
readCEN();
}
+void ZipFile::setInputStream ( uno::Reference < io::XInputStream > xNewStream )
+{
+ xStream = xNewStream;
+ aGrabber.setInputStream ( xStream );
+}
void ZipFile::updateFromManList(std::vector < ManifestEntry * > &rManList)
{
sal_Int32 i=0, nSize = rManList.size();
aEntries.clear();
+ package::ZipEntry *pEntry = &rManList[i]->aEntry;
for (;i < nSize ; i++)
{
+ // This is a bitwise copy, = is not an overloaded operator
+ // I'm not sure how evil this is in this case...
+ aEntries[pEntry->sName] = *pEntry;//rManList[i]->aEntry;
+ /*
package::ZipEntry *pEntry = new package::ZipEntry;
- pEntry->nVersion = rManList[i]->pEntry->nVersion;
- pEntry->nFlag = rManList[i]->pEntry->nFlag;
- pEntry->nMethod = rManList[i]->pEntry->nMethod;
- pEntry->nTime = rManList[i]->pEntry->nTime;
- pEntry->nCrc = rManList[i]->pEntry->nCrc;
- pEntry->nCompressedSize = rManList[i]->pEntry->nCompressedSize;
- pEntry->nSize = rManList[i]->pEntry->nSize;
- rManList[i]->pEntry->nOffset *=-1;
- pEntry->nOffset = rManList[i]->pEntry->nOffset;
- pEntry->sName = rManList[i]->pEntry->sName;
- pEntry->extra = rManList[i]->pEntry->extra;
- pEntry->sComment = rManList[i]->pEntry->sComment;
+ pEntry->nVersion = rManList[i]->aEntry.nVersion;
+ pEntry->nFlag = rManList[i]->aEntry.nFlag;
+ pEntry->nMethod = rManList[i]->aEntry.nMethod;
+ pEntry->nTime = rManList[i]->aEntry.nTime;
+ pEntry->nCrc = rManList[i]->aEntry.nCrc;
+ pEntry->nCompressedSize = rManList[i]->aEntry.nCompressedSize;
+ pEntry->nSize = rManList[i]->aEntry.nSize;
+ pEntry->nOffset = rManList[i]->aEntry.nOffset;
+ pEntry->sName = rManList[i]->aEntry.sName;
+ pEntry->extra = rManList[i]->aEntry.extra;
+ pEntry->sComment = rManList[i]->aEntry.sComment;
aEntries[pEntry->sName] = *pEntry;
+ */
}
}
@@ -177,7 +187,7 @@ sal_Bool SAL_CALL ZipFile::hasByName( const ::rtl::OUString& aName )
}
uno::Reference< io::XInputStream > SAL_CALL ZipFile::getInputStream( const package::ZipEntry& rEntry )
- throw(io::IOException, package::ZipException, uno::RuntimeException)
+ throw(io::IOException, package::ZipException, uno::RuntimeException)
{
sal_Int64 nEnd = rEntry.nCompressedSize == 0 ? rEntry.nSize : rEntry.nCompressedSize;
if (rEntry.nOffset <= 0)
@@ -189,6 +199,64 @@ uno::Reference< io::XInputStream > SAL_CALL ZipFile::getInputStream( const packa
return xStreamRef;
}
+sal_uInt32 SAL_CALL ZipFile::getHeader(const package::ZipEntry& rEntry)
+ throw(io::IOException, package::ZipException, uno::RuntimeException)
+{
+ uno::Sequence < sal_Int8 > aSequence (4);
+
+ try
+ {
+ if (rEntry.nOffset <= 0)
+ readLOC(rEntry);
+ }
+ catch (package::ZipException&)
+ {
+ VOS_ENSURE(0, "Zip file bug!");
+ return 0;
+ }
+
+ aGrabber.seek(rEntry.nOffset);
+ if (rEntry.nMethod == STORED)
+ {
+ if (xStream->readBytes(aSequence, 4) < 4)
+ return 0;
+ }
+ else if (rEntry.nMethod == DEFLATED)
+ {
+ uno::Reference < io::XInputStream > xEntryStream = getInputStream (rEntry);
+ if (xEntryStream->readBytes(aSequence, 4) < 4)
+ return 0;
+ /*
+ Inflater aInflater ( sal_True );
+ sal_Int32 nSize = rEntry.nCompressedSize < 50 ? rEntry.nCompressedSize : 50;
+ uno::Sequence < sal_Int8 > aCompSeq (nSize );
+ if (xStream->readBytes(aCompSeq, nSize) < nSize)
+ return 0;
+ aInflater.setInput(aCompSeq);
+ aInflater.doInflate(aSequence);
+ aInflater.end();
+ */
+ }
+ return (static_cast < sal_uInt32 >
+ (static_cast < sal_uInt8> (aSequence[0]& 0xFF)
+ | static_cast < sal_uInt8> (aSequence[1]& 0xFF) << 8
+ | static_cast < sal_uInt8> (aSequence[2]& 0xFF) << 16
+ | static_cast < sal_uInt8> (aSequence[3]& 0xFF) << 24));
+}
+
+uno::Reference< io::XInputStream > SAL_CALL ZipFile::getRawStream( const package::ZipEntry& rEntry )
+ throw(io::IOException, package::ZipException, uno::RuntimeException)
+{
+ sal_Int64 nSize = rEntry.nMethod == DEFLATED ? rEntry.nCompressedSize : rEntry.nSize;
+
+ if (rEntry.nOffset <= 0)
+ readLOC(rEntry);
+ sal_Int64 nBegin = rEntry.nOffset;
+
+ uno::Reference< io::XInputStream > xStreamRef = new EntryInputStream(xStream, nBegin, nSize+nBegin, 1024, nSize, sal_False);
+ return xStreamRef;
+}
+
sal_Bool ZipFile::readLOC(const package::ZipEntry &rEntry)
throw(io::IOException, package::ZipException, uno::RuntimeException)
{
@@ -296,9 +364,9 @@ sal_Int32 ZipFile::readCEN()
nLocPos = nCenPos - nCenOff;
aGrabber.seek(nCenPos);
+ package::ZipEntry *pEntry = new package::ZipEntry;
for (nCount = 0 ; nCount < nTotal; nCount++)
{
- package::ZipEntry *pEntry = new package::ZipEntry;
sal_Int32 nTestSig, nCRC, nCompressedSize, nTime, nSize, nExtAttr, nOffset;
sal_Int16 nVerMade, nVersion, nFlag, nHow, nNameLen, nExtraLen, nCommentLen;
sal_Int16 nDisk, nIntAttr;
@@ -368,6 +436,7 @@ sal_Int32 ZipFile::readCEN()
}
aEntries[pEntry->sName] = *pEntry;
}
+ delete pEntry;
if (nCount != nTotal)
throw package::ZipException(OUString::createFromAscii("Count != Total"), uno::Reference < uno::XInterface > ());
diff --git a/package/source/zipapi/ZipOutputStream.cxx b/package/source/zipapi/ZipOutputStream.cxx
index 449129caab5a..bb7e0e08ddd1 100644
--- a/package/source/zipapi/ZipOutputStream.cxx
+++ b/package/source/zipapi/ZipOutputStream.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ZipOutputStream.cxx,v $
*
- * $Revision: 1.13 $
+ * $Revision: 1.14 $
*
- * last change: $Author: mtg $ $Date: 2000-12-07 11:04:05 $
+ * last change: $Author: mtg $ $Date: 2000-12-13 17:00:43 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -218,6 +218,16 @@ void SAL_CALL ZipOutputStream::write( const uno::Sequence< sal_Int8 >& rBuffer,
}
aCRC.updateSegment(rBuffer, nNewOffset, nNewLength);
}
+void SAL_CALL ZipOutputStream::rawWrite( const uno::Sequence< sal_Int8 >& rBuffer)
+{
+ aChucker.writeBytes(rBuffer);
+}
+void SAL_CALL ZipOutputStream::rawCloseEntry( )
+{
+ writeEXT(*pCurrentEntry);
+ aCRC.reset();
+ pCurrentEntry = NULL;
+}
void SAL_CALL ZipOutputStream::finish( )
throw(io::IOException, uno::RuntimeException)
{
diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx
index 74ef9ca8fe81..2dda1a2a6804 100644
--- a/package/source/zippackage/ZipPackage.cxx
+++ b/package/source/zippackage/ZipPackage.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ZipPackage.cxx,v $
*
- * $Revision: 1.23 $
+ * $Revision: 1.24 $
*
- * last change: $Author: obo $ $Date: 2000-12-08 12:37:08 $
+ * last change: $Author: mtg $ $Date: 2000-12-13 17:00:47 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -90,9 +90,9 @@ ZipPackage::ZipPackage (Reference < XInputStream > &xNewInput,
{
pZipFile = new ZipFile(xContentStream, sal_True);
}
- catch (ZipException& rException)
+ catch (ZipException&)// rException)
{
- VOS_DEBUG_ONLY(rException.Message);
+ VOS_ENSURE( 0, "ZipException thrown...bad ZipFile"); // rException.Message );
}
xZipFile = Reference < XZipFile > ( pZipFile );
@@ -120,16 +120,6 @@ ZipPackage::~ZipPackage( void )
{
if (pContent)
delete pContent;
-/* if (pZipFile)
- delete pZipFile;
- if (pZipOut)
- delete pZipOut;
- if (pZipBuffer)
- delete pZipBuffer;
- if (pRootFolder)
- delete pRootFolder;
- destroyFolderTree(xRootFolder);
-*/
}
void ZipPackage::destroyFolderTree( Reference < XUnoTunnel > xFolder )
@@ -190,11 +180,11 @@ void ZipPackage::getZipFileContents()
while ((nIndex = rName.indexOf('/', nOldIndex)) != -1)
{
OUString sTemp = rName.copy (nOldIndex, nIndex - nOldIndex);
- if (nIndex == nOldIndex) //sTemp.getLength() == 1)
+ if (nIndex == nOldIndex)
break;
if (!xCurrent->hasByName(sTemp))
{
- pPkgFolder = new ZipPackageFolder();//*this);
+ pPkgFolder = new ZipPackageFolder();
pPkgFolder->setName(sTemp);
try
{
@@ -202,10 +192,8 @@ void ZipPackage::getZipFileContents()
}
catch ( NoSupportException& )
{
- VOS_DEBUG_ONLY("setParent threw an exception: attempted to set Parent to non-existing interface!");
+ VOS_ENSURE(0, "setParent threw an exception: attempted to set Parent to non-existing interface!");
}
- aAny <<= Reference < XUnoTunnel > (pPkgFolder);
- //xCurrent->insertByName(sTemp, aAny);
xCurrent = Reference < XNameContainer > (pPkgFolder);
}
else
@@ -224,11 +212,11 @@ void ZipPackage::getZipFileContents()
while ((nIndex = rName.indexOf('/', nOldIndex)) != -1)
{
OUString sTemp = rName.copy (nOldIndex, nIndex - nOldIndex);
- if (nIndex == nOldIndex) //sTemp.getLength() == 1)
+ if (nIndex == nOldIndex)
break;
if (!xCurrent->hasByName(sTemp))
{
- pPkgFolder = new ZipPackageFolder();//*this);
+ pPkgFolder = new ZipPackageFolder();
pPkgFolder->setName(sTemp);
try
{
@@ -236,10 +224,8 @@ void ZipPackage::getZipFileContents()
}
catch ( NoSupportException& )
{
- VOS_DEBUG_ONLY("setParent threw an exception: attempted to set Parent to non-existing interface!");
+ VOS_ENSURE( 0, "setParent threw an exception: attempted to set Parent to non-existing interface!");
}
- aAny <<= Reference < XUnoTunnel > (pPkgFolder);
- //xCurrent->insertByName(sTemp, aAny);
xCurrent = Reference < XNameContainer > (pPkgFolder);
}
else
@@ -256,19 +242,17 @@ void ZipPackage::getZipFileContents()
{
Reference < XInputStream > xContentStream = pZipFile->getInputStream(aEntry);
ZipPackage *pInZip = new ZipPackage (xContentStream, xFactory );
- aContainedZips.push_back (Reference < XSingleServiceFactory > (pInZip));
pPkgFolder = pInZip->getRootFolder();
pPkgFolder->setName(sStreamName);
+ pPkgFolder->pPackage = pInZip;
try
{
pPkgFolder->setParent( Reference < XInterface >(xCurrent, UNO_QUERY));
}
catch ( NoSupportException& )
{
- VOS_DEBUG_ONLY("setParent threw an exception: attempted to set Parent to non-existing interface!");
+ VOS_ENSURE( 0, "setParent threw an exception: attempted to set Parent to non-existing interface!");
}
- aAny <<= Reference < XUnoTunnel > (pPkgFolder);
- //xCurrent->insertByName(sStreamName, aAny);
}
else
{
@@ -282,10 +266,8 @@ void ZipPackage::getZipFileContents()
}
catch ( NoSupportException& )
{
- VOS_DEBUG_ONLY("setParent threw an exception: attempted to set Parent to non-existing interface!");
+ VOS_ENSURE( 0, "setParent threw an exception: attempted to set Parent to non-existing interface!");
}
- aAny <<= Reference < XUnoTunnel > (pPkgStream);
- //xCurrent->insertByName(sStreamName, aAny);
}
}
}
@@ -304,7 +286,7 @@ void ZipPackage::getZipFileContents()
}
catch ( com::sun::star::xml::sax::SAXException & )
{
- VOS_DEBUG_ONLY( "SAX threw an exception when reading XML Manifest!");
+ VOS_ENSURE( 0, "SAX threw an exception when reading XML Manifest!");
}
}
}
@@ -327,9 +309,9 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments )
pZipFile = new ZipFile(xContentStream, sal_True);
xZipFile = Reference < XZipFile > ( pZipFile );
}
- catch (ZipException& rException)
+ catch (ZipException&)// rException)
{
- VOS_DEBUG_ONLY(rException.Message);
+ VOS_ENSURE( 0, "ZipException thrown - bad Zip File"); //rException.Message);
}
getZipFileContents();
}
@@ -357,7 +339,7 @@ Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName )
while ((nIndex = aName.indexOf('/', nOldIndex)) != -1)
{
OUString sTemp = aName.copy (nOldIndex, nIndex - nOldIndex);
- if (nIndex == nOldIndex) //sTemp.getLength() == 1)
+ if (nIndex == nOldIndex)
break;
if (xCurrent->hasByName(sTemp))
{
@@ -376,7 +358,7 @@ Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName )
while ((nIndex = aName.indexOf('/', nOldIndex)) != -1)
{
OUString sTemp = aName.copy (nOldIndex, nIndex - nOldIndex);
- if (nIndex == nOldIndex) //sTemp.getLength() == 1)
+ if (nIndex == nOldIndex)
break;
if (xCurrent->hasByName(sTemp))
{
@@ -474,8 +456,7 @@ Reference< XInterface > SAL_CALL ZipPackage::createInstanceWithArguments( const
return xRef;
}
-// XChangesBatch
-void SAL_CALL ZipPackage::commitChanges( )
+ZipPackageBuffer & SAL_CALL ZipPackage::writeToBuffer( )
throw(WrappedTargetException, RuntimeException)
{
std::vector < ManifestEntry * > aManList;
@@ -525,7 +506,7 @@ void SAL_CALL ZipPackage::commitChanges( )
}
catch ( com::sun::star::xml::sax::SAXException & )
{
- VOS_DEBUG_ONLY( "SAX threw an exception when writing XML Manifest!");
+ VOS_ENSURE( 0, "SAX threw an exception when writing XML Manifest!");
}
pManifestStream->setInputStream(Reference < XInputStream > (xManOutStream, UNO_QUERY));
@@ -544,47 +525,66 @@ void SAL_CALL ZipPackage::commitChanges( )
}
catch (::com::sun::star::io::IOException & )
{
- VOS_DEBUG_ONLY ( "Error writing ZipOutputStream" );
+ VOS_ENSURE( 0, "Error writing ZipOutputStream" );
}
- pZipBuffer->seek(0);
-
aAny <<= Reference < XUnoTunnel > (pManifestStream);
pMetaInfFolder->insertByName(OUString::createFromAscii("manifest.xml"), aAny);
+ pManifestStream->aEntry.nOffset *=-1;
+ xContentStream = Reference < XInputStream > (pZipBuffer);
+ xContentSeek = Reference < XSeekable > (pZipBuffer);
+
+ // If we have a valid pZipFile pointer, then we opened a stream
+ // earlier and read from it
+ // Otherwise we are writing a new ZipFile
+ pZipBuffer->seek(0);
+ /*
+ try
+ {
+ pZipFile = new ZipFile(xContentStream, sal_False);
+ xZipFile = Reference < XZipFile > ( pZipFile );
+ pRootFolder->updateReferences ( pZipFile );
+ }
+ catch (ZipException&)// rException)
+ {
+ VOS_ENSURE( 0, "ZipException thrown - bad ZipFile " );//rException.Message);
+ }
+ */
+ pZipFile->setInputStream ( xContentStream );
+ pZipFile->updateFromManList( aManList );
for (sal_uInt32 i=0 ; i < aManList.size(); i++)
{
- ZipEntry * pEntry = aManList[i]->pEntry;
- pEntry->sName = aManList[i]->sShortName;
+ aManList[i]->aEntry.sName = aManList[i]->sShortName;
+ delete aManList[i];
}
+
+ pZipBuffer->seek(0);
+ // If we are writing the zip file for the first time, pZipBuffer becomes
+ // the xContentStream. If so, it will have a refcount of 1 before the following
+ // call.
+ //
+ // Otherwise, it will have a refcount of 0, and will be deleted after the
+ // following call
+ //
+ // (at least...that's the plan!) mtg 6/12/00
+ return *pZipBuffer;
+ // Likewise, pBuffer and pZipOut will be deleted automagically due to the xZipOut and xOutStream
+}
+// XChangesBatch
+void SAL_CALL ZipPackage::commitChanges( )
+ throw(WrappedTargetException, RuntimeException)
+{
try
{
- pContent->writeStream(Reference < XInputStream > (pZipBuffer), sal_True);
+ pContent->writeStream(Reference < XInputStream > (&writeToBuffer()), sal_True);
}
catch (::com::sun::star::ucb::CommandAbortedException&)
{
- VOS_DEBUG_ONLY( "Unable to write Zip File to disk!");
+ VOS_ENSURE( 0, "Unable to write Zip File to disk!");
}
- if (!pZipFile)
- {
- // If we have a valid pZipFile pointer, then we opened a stream
- // earlier and read from it
- // Otherwise we are writing a new ZipFile
- xContentStream = Reference < XInputStream > (pZipBuffer);
- xContentSeek = Reference < XSeekable > (pZipBuffer);
- try
- {
- pZipFile = new ZipFile(xContentStream, sal_False);
- xZipFile = Reference < XZipFile > ( pZipFile );
- pRootFolder->updateReferences ( pZipFile );
- }
- catch (ZipException& rException)
- {
- VOS_DEBUG_ONLY(rException.Message);
- }
- }
- pZipFile->updateFromManList( aManList );
+
}
sal_Bool SAL_CALL ZipPackage::hasPendingChanges( )
@@ -600,22 +600,12 @@ Sequence< ElementChange > SAL_CALL ZipPackage::getPendingChanges( )
sal_Bool ZipPackage::isZipFile(com::sun::star::package::ZipEntry &rEntry)
{
- Reference < XInputStream > xEntryStream = pZipFile->getInputStream(rEntry);
- Sequence < sal_Int8 > aSequence (4);
-
- if (xEntryStream->readBytes(aSequence, 4) < 4)
- return sal_False;
-
- sal_uInt32 nTestSig = static_cast < sal_uInt32 >
- (static_cast < sal_uInt8> (aSequence[0]& 0xFF)
- | static_cast < sal_uInt8> (aSequence[1]& 0xFF) << 8
- | static_cast < sal_uInt8> (aSequence[2]& 0xFF) << 16
- | static_cast < sal_uInt8> (aSequence[3]& 0xFF) << 24);
-
- if (nTestSig == LOCSIG)
- return sal_True;
- else
- return sal_False;
+ if (rEntry.nMethod == STORED)
+ {
+ if (rEntry.nSize < 98) // smallest possible zip file size
+ return sal_False;
+ }
+ return (pZipFile->getHeader(rEntry) == LOCSIG);
}
/**
@@ -664,7 +654,7 @@ extern "C" sal_Bool SAL_CALL component_writeInfo( void* pServiceManager, void* p
}
catch ( InvalidRegistryException& )
{
- VOS_DEBUG_ONLY( "InvalidRegistryException detected\n");
+ VOS_ENSURE( 0, "InvalidRegistryException detected\n");
return sal_False;
}
@@ -702,3 +692,63 @@ extern "C" void * SAL_CALL component_getFactory(
}
return pRet;
}
+//XInterface
+Any SAL_CALL ZipPackage::queryInterface( const Type& rType )
+ throw(RuntimeException)
+{
+ // Ask for my own supported interfaces ...
+ Any aReturn ( ::cppu::queryInterface ( rType ,
+ static_cast< XInitialization* > ( this ) ,
+ static_cast< XSingleServiceFactory* > ( this ) ,
+ static_cast< XUnoTunnel* > ( this ) ,
+ static_cast< XHierarchicalNameAccess*> ( this ) ,
+ static_cast< XChangesBatch* > ( this ) ) );
+
+ // If searched interface supported by this class ...
+ if ( aReturn.hasValue () == sal_True )
+ {
+ // ... return this information.
+ return aReturn ;
+ }
+ else
+ {
+ // Else; ... ask baseclass for interfaces!
+ return OWeakObject::queryInterface ( rType ) ;
+ }
+}
+void SAL_CALL ZipPackage::acquire( )
+ throw()
+{
+ OWeakObject::acquire();
+}
+void SAL_CALL ZipPackage::release( )
+ throw()
+{
+ OWeakObject::release();
+}
+
+// XUnoTunnel
+Sequence< sal_Int8 > ZipPackage::getUnoTunnelImplementationId( void )
+ throw (RuntimeException)
+{
+ static ::cppu::OImplementationId * pId = 0;
+ if (! pId)
+ {
+ ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
+ if (! pId)
+ {
+ static ::cppu::OImplementationId aId;
+ pId = &aId;
+ }
+ }
+ return pId->getImplementationId();
+}
+
+sal_Int64 SAL_CALL ZipPackage::getSomething( const Sequence< sal_Int8 >& aIdentifier )
+ throw(RuntimeException)
+{
+ if (aIdentifier.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), aIdentifier.getConstArray(), 16 ) )
+ return reinterpret_cast < sal_Int64 > ( this );
+ return 0;
+}
+
diff --git a/package/source/zippackage/ZipPackageBuffer.cxx b/package/source/zippackage/ZipPackageBuffer.cxx
index ded6c6321be1..5911c0ba2e4a 100644
--- a/package/source/zippackage/ZipPackageBuffer.cxx
+++ b/package/source/zippackage/ZipPackageBuffer.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ZipPackageBuffer.cxx,v $
*
- * $Revision: 1.5 $
+ * $Revision: 1.6 $
*
- * last change: $Author: mtg $ $Date: 2000-12-01 10:50:49 $
+ * last change: $Author: mtg $ $Date: 2000-12-13 17:00:47 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -100,14 +100,19 @@ void SAL_CALL ZipPackageBuffer::release(void)
sal_Int32 SAL_CALL ZipPackageBuffer::readBytes( Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
{
+ if (nBytesToRead < 0)
+ throw BufferSizeExceededException(::rtl::OUString(),*this);
+
if (nBytesToRead + nCurrent > nEnd)
nBytesToRead = static_cast < sal_Int32 > (nEnd - nCurrent);
- sal_Int64 nEndRead = nBytesToRead+nCurrent;
- for (sal_Int32 i =0; nCurrent < nEndRead; nCurrent++, i++)
- aData[i] = aBuffer[static_cast < sal_Int32 > (nCurrent)];
+ aData.realloc(nBytesToRead);
+ memcpy(aData.getArray(), aBuffer.getConstArray() + nCurrent, nBytesToRead);
+ nCurrent +=nBytesToRead;
+
return nBytesToRead;
}
+
sal_Int32 SAL_CALL ZipPackageBuffer::readSomeBytes( Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
{
@@ -120,11 +125,19 @@ sal_Int32 SAL_CALL ZipPackageBuffer::readSomeBytes( Sequence< sal_Int8 >& aData,
aData[i] = aBuffer[nCurrent];
return nMaxBytesToRead;
*/
+
+ // all data is available at once
return readBytes(aData, nMaxBytesToRead);
}
void SAL_CALL ZipPackageBuffer::skipBytes( sal_Int32 nBytesToSkip )
throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
{
+ if (nBytesToSkip < 0)
+ throw BufferSizeExceededException(::rtl::OUString(),*this);
+
+ if (nBytesToSkip + nCurrent > nEnd)
+ nBytesToSkip = static_cast < sal_Int32 > (nEnd - nCurrent);
+
nCurrent+=nBytesToSkip;
}
sal_Int32 SAL_CALL ZipPackageBuffer::available( )
@@ -142,11 +155,13 @@ void SAL_CALL ZipPackageBuffer::writeBytes( const Sequence< sal_Int8 >& aData )
sal_Int64 nDataLen = aData.getLength();
if (nEnd + nDataLen > nBufferSize)
{
- nBufferSize *=2;
+ while (nEnd + nDataLen > nBufferSize)
+ nBufferSize *=2;
aBuffer.realloc(static_cast < sal_Int32 > (nBufferSize));
}
- for (sal_Int32 i=0; i<nDataLen;i++,nCurrent++)
- aBuffer[static_cast < sal_Int32 > (nCurrent) ] = aData[i];
+
+ memcpy(aBuffer.getArray()+nCurrent, aData.getConstArray(), static_cast < sal_Int32 > (nDataLen));
+ nCurrent+=nDataLen;
if (nCurrent>nEnd)
nEnd = nCurrent;
}
diff --git a/package/source/zippackage/ZipPackageFolder.cxx b/package/source/zippackage/ZipPackageFolder.cxx
index 051ba20538a9..32e4fbdb201a 100644
--- a/package/source/zippackage/ZipPackageFolder.cxx
+++ b/package/source/zippackage/ZipPackageFolder.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ZipPackageFolder.cxx,v $
*
- * $Revision: 1.20 $
+ * $Revision: 1.21 $
*
- * last change: $Author: hjs $ $Date: 2000-12-07 15:48:04 $
+ * last change: $Author: mtg $ $Date: 2000-12-13 17:00:47 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -67,6 +67,7 @@ using namespace com::sun::star;
using namespace rtl;
ZipPackageFolder::ZipPackageFolder (void)
+: pPackage( NULL )
{
aEntry.nVersion = -1;
aEntry.nFlag = 0;
@@ -78,9 +79,23 @@ ZipPackageFolder::ZipPackageFolder (void)
aEntry.nOffset = -1;
}
+
ZipPackageFolder::~ZipPackageFolder( void )
{
-
+}
+void ZipPackageFolder::copyZipEntry( com::sun::star::package::ZipEntry &rDest, const com::sun::star::package::ZipEntry &rSource)
+{
+ rDest.nVersion = rSource.nVersion;
+ rDest.nFlag = rSource.nFlag;
+ rDest.nMethod = rSource.nMethod;
+ rDest.nTime = rSource.nTime;
+ rDest.nCrc = rSource.nCrc;
+ rDest.nCompressedSize = rSource.nCompressedSize;
+ rDest.nSize = rSource.nSize;
+ rDest.nOffset = rSource.nOffset;
+ rDest.sName = rSource.sName;
+ rDest.extra = rSource.extra;
+ rDest.sComment = rSource.sComment;
}
uno::Any SAL_CALL ZipPackageFolder::queryInterface( const uno::Type& rType )
throw(uno::RuntimeException)
@@ -143,7 +158,7 @@ void SAL_CALL ZipPackageFolder::insertByName( const ::rtl::OUString& aName, cons
}
catch ( lang::NoSupportException& )
{
- VOS_DEBUG_ONLY("setParent threw an exception: attempted to set Parent to non-existing interface!");
+ VOS_ENSURE( 0, "setParent threw an exception: attempted to set Parent to non-existing interface!");
}
}
}
@@ -281,14 +296,11 @@ void ZipPackageFolder::saveContents(rtl::OUString &rPath, std::vector < Manifest
throw(uno::RuntimeException)
{
uno::Reference < lang::XUnoTunnel > xTunnel;
- package::ZipEntry *aEntry = NULL;
ZipPackageFolder *pFolder = NULL;
ZipPackageStream *pStream = NULL;
sal_Bool bIsFolder = sal_False;
TunnelHash::const_iterator aCI = aContents.begin();
- //rPath = rPath + getName();
-
for (;aCI!=aContents.end();aCI++)
{
xTunnel = uno::Reference < lang::XUnoTunnel> ((*aCI).second, uno::UNO_QUERY);
@@ -314,76 +326,162 @@ void ZipPackageFolder::saveContents(rtl::OUString &rPath, std::vector < Manifest
if (bIsFolder)
{
- time_t nTime = time(NULL);
- ManifestEntry *pMan = new ManifestEntry;
- pMan->sShortName = (*aCI).first;
- pFolder->aEntry.sName = rPath + pMan->sShortName + OUString::createFromAscii("/");
- pFolder->aEntry.nTime = ZipOutputStream::tmDateToDosDate ( *localtime(&nTime));
- pFolder->aEntry.nCrc = 0;
- pFolder->aEntry.nSize = 0;
- pFolder->aEntry.nCompressedSize = 0;
- pFolder->aEntry.nMethod = STORED;
- try
+ if (pFolder->pPackage)
{
- rZipOut.putNextEntry(pFolder->aEntry);
- rZipOut.closeEntry();
+ // This ZipPackageFolder is the root folder of a zipfile contained within
+ // this zipfile. Things will get a little strange from here on in...
+ ManifestEntry *pMan = new ManifestEntry;
+ pMan->sShortName = (*aCI).first;
+
+ ZipPackageFolder::copyZipEntry(pMan->aEntry, pFolder->aEntry);
+ pMan->aEntry.sName = rPath + pMan->sShortName;
+
+ pMan->aEntry.nCrc = -1;
+ pMan->aEntry.nSize = -1;
+ pMan->aEntry.nCompressedSize = -1;
+ pMan->aEntry.nMethod = STORED;
+
+ try
+ {
+ rZipOut.putNextEntry(pMan->aEntry);
+ ZipPackageBuffer &rBuffer = pFolder->pPackage->writeToBuffer();
+ pMan->aEntry.nSize = pMan->aEntry.nCompressedSize = static_cast < sal_Int32 > (rBuffer.getLength());
+ rZipOut.write(rBuffer.aBuffer, 0, static_cast < sal_Int32 > (rBuffer.getLength()));
+ rZipOut.closeEntry();
+ }
+ catch (::com::sun::star::io::IOException & )
+ {
+ VOS_ENSURE( 0, "Error writing ZipOutputStream" );
+ }
+ // Then copy it back
+ ZipPackageFolder::copyZipEntry(pFolder->aEntry, pMan->aEntry);
+ pFolder->aEntry.nOffset *= -1;
+ rManList.push_back (pMan);
}
- catch (::com::sun::star::io::IOException & )
+ else
{
- VOS_DEBUG_ONLY ( "Error writing ZipOutputStream" );
+ // In case the entry we are reading is also the entry we are writing, we will
+ // store the ZipEntry data in the ManifestEntry struct and then update the
+ // ZipEntry data in the ZipPackageFolder later
+
+ time_t nTime = time(NULL);
+ ManifestEntry *pMan = new ManifestEntry;
+ pMan->sShortName = (*aCI).first;
+
+ // First copy current data to ManifestEntry
+ ZipPackageFolder::copyZipEntry(pMan->aEntry, pFolder->aEntry);
+
+ pMan->aEntry.sName = rPath + pMan->sShortName + OUString::createFromAscii("/");
+ pMan->aEntry.nTime = ZipOutputStream::tmDateToDosDate ( *localtime(&nTime));
+ pMan->aEntry.nCrc = 0;
+ pMan->aEntry.nSize = 0;
+ pMan->aEntry.nCompressedSize = 0;
+ pMan->aEntry.nMethod = STORED;
+
+ try
+ {
+ rZipOut.putNextEntry(pMan->aEntry);
+ rZipOut.closeEntry();
+ }
+ catch (::com::sun::star::io::IOException & )
+ {
+ VOS_ENSURE( 0, "Error writing ZipOutputStream" );
+ }
+ pMan->sMediaType = OUString::createFromAscii("");
+ // Then copy it back
+ ZipPackageFolder::copyZipEntry(pFolder->aEntry, pMan->aEntry);
+ pFolder->aEntry.nOffset *= -1;
+ pFolder->saveContents(pFolder->aEntry.sName, rManList, rZipOut);
+ rManList.push_back (pMan);
}
- pMan->sMediaType = OUString::createFromAscii("");
- pMan->pEntry = &(pFolder->aEntry);
- pFolder->saveContents(pFolder->aEntry.sName, rManList, rZipOut);
- rManList.push_back (pMan);
}
else
{
+ // In case the entry we are reading is also the entry we are writing, we will
+ // store the ZipEntry data in the ManifestEntry struct and then update the
+ // ZipEntry data in the ZipPackageStream later
+
ManifestEntry *pMan = new ManifestEntry;
pMan->sShortName = (*aCI).first;
- pStream->aEntry.sName = rPath + pMan->sShortName;
- uno::Reference < io::XInputStream > xStream = pStream->getInputStream();
- uno::Reference < io::XSeekable > xSeek (xStream, uno::UNO_QUERY);
- sal_Bool bTrackLength = sal_True;
+ // Copy current info to pMan...
+ ZipPackageFolder::copyZipEntry(pMan->aEntry, pStream->aEntry);
+ pMan->aEntry.sName = rPath + pMan->sShortName;
- pStream->aEntry.nCrc = -1;
- pStream->aEntry.nSize = -1;
- pStream->aEntry.nCompressedSize = -1;
- if (xSeek.is())
+ if (pStream->bPackageMember)
{
- xSeek->seek(0);
- if (pStream->aEntry.nMethod == STORED)
+ try
+ {
+ uno::Reference < io::XInputStream > xStream = pStream->getRawStream( pMan->aEntry );
+ try
+ {
+ rZipOut.putNextEntry(pMan->aEntry);
+ while (1)
+ {
+ uno::Sequence < sal_Int8 > aSeq (65535);
+ sal_Int32 nLength;
+ nLength = xStream->readBytes(aSeq, 65535);
+ if (nLength < 65535)
+ aSeq.realloc(nLength);
+ rZipOut.rawWrite(aSeq);
+ if (nLength < 65535) // EOF
+ break;
+ }
+ rZipOut.rawCloseEntry();
+ }
+ catch (package::ZipException&)
+ {
+ }
+ }
+ catch (::com::sun::star::io::IOException & )
{
- pStream->aEntry.nSize = pStream->aEntry.nCompressedSize = static_cast < sal_Int32 > (xSeek->getLength());
- bTrackLength = sal_False;
+ VOS_ENSURE( 0, "Error writing ZipOutputStream" );
}
}
-
- try
+ else
{
- rZipOut.putNextEntry(pStream->aEntry);
- while (1)
+ uno::Reference < io::XInputStream > xStream = pStream->getInputStream();
+ uno::Reference < io::XSeekable > xSeek (xStream, uno::UNO_QUERY);
+ sal_Bool bTrackLength = sal_True;
+
+ pMan->aEntry.nCrc = -1;
+ pMan->aEntry.nSize = -1;
+ pMan->aEntry.nCompressedSize = -1;
+ if (xSeek.is())
+ {
+ xSeek->seek(0);
+ if (pMan->aEntry.nMethod == STORED)
+ {
+ pMan->aEntry.nSize = pMan->aEntry.nCompressedSize = static_cast < sal_Int32 > (xSeek->getLength());
+ bTrackLength = sal_False;
+ }
+ }
+
+ try
{
- uno::Sequence < sal_Int8 > aSeq (65535);
- sal_Int32 nLength;
- nLength = xStream->readBytes(aSeq, 65535);
- if (nLength < 65535)
- aSeq.realloc(nLength);
- rZipOut.write(aSeq, 0, nLength);
+ rZipOut.putNextEntry(pMan->aEntry);
+ while (1)
+ {
+ uno::Sequence < sal_Int8 > aSeq (65535);
+ sal_Int32 nLength;
+ nLength = xStream->readBytes(aSeq, 65535);
+ if (nLength < 65535)
+ aSeq.realloc(nLength);
+ rZipOut.write(aSeq, 0, nLength);
+ if (bTrackLength)
+ pMan->aEntry.nSize+=nLength;
+ if (nLength < 65535) // EOF
+ break;
+ }
if (bTrackLength)
- pStream->aEntry.nSize+=nLength;
- if (nLength < 65535) // EOF
- break;
+ pMan->aEntry.nCompressedSize = pStream->aEntry.nSize;
+ pStream->bPackageMember = sal_True;
+ rZipOut.closeEntry();
+ }
+ catch (::com::sun::star::io::IOException & )
+ {
+ VOS_ENSURE( 0, "Error writing ZipOutputStream" );
}
- if (bTrackLength)
- pStream->aEntry.nCompressedSize = pStream->aEntry.nSize;
- pStream->bPackageMember = sal_True;
- rZipOut.closeEntry();
- }
- catch (::com::sun::star::io::IOException & )
- {
- VOS_DEBUG_ONLY ( "Error writing ZipOutputStream" );
}
try
{
@@ -392,27 +490,15 @@ void ZipPackageFolder::saveContents(rtl::OUString &rPath, std::vector < Manifest
}
catch (::com::sun::star::beans::UnknownPropertyException & )
{
- VOS_DEBUG_ONLY ( "MediaType is an unknown property!!" );
+ VOS_ENSURE( 0, "MediaType is an unknown property!!" );
}
- pMan->pEntry = &(pStream->aEntry);
+ // Then copy it back afterwards...
+ ZipPackageFolder::copyZipEntry(pStream->aEntry, pMan->aEntry);
+ pStream->aEntry.nOffset *= -1;
rManList.push_back (pMan);
}
}
}
-void ZipPackageFolder::setEntry(package::ZipEntry &rDest, package::ZipEntry &rSrc)
-{
- rDest.nVersion = rSrc.nVersion;
- rDest.nFlag = rSrc.nFlag;
- rDest.nMethod = rSrc.nMethod;
- rDest.nTime = rSrc.nTime;
- rDest.nCrc = rSrc.nCrc;
- rDest.nCompressedSize = rSrc.nCompressedSize;
- rDest.nSize = rSrc.nSize;
- rDest.nOffset = rSrc.nOffset;
- rDest.sName = rSrc.sName;
- rDest.extra = rSrc.extra;
- rDest.sComment = rSrc.sComment;
-}
void ZipPackageFolder::updateReferences( ZipFile * pNewZipFile)
{
uno::Reference < lang::XUnoTunnel > xTunnel;
@@ -445,7 +531,12 @@ void ZipPackageFolder::updateReferences( ZipFile * pNewZipFile)
}
if (bIsFolder)
- pFolder->updateReferences(pNewZipFile);
+ {
+ //if pPackage is set,then this is the root folder of a different ZipPackage and
+ // should not be changed
+ if (!pFolder->pPackage)
+ pFolder->updateReferences(pNewZipFile);
+ }
else
pStream->pZipFile = pNewZipFile;
}
diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx
index 4a425771fbad..e972aaa7238f 100644
--- a/package/source/zippackage/ZipPackageStream.cxx
+++ b/package/source/zippackage/ZipPackageStream.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ZipPackageStream.cxx,v $
*
- * $Revision: 1.10 $
+ * $Revision: 1.11 $
*
- * last change: $Author: mtg $ $Date: 2000-12-04 11:30:09 $
+ * last change: $Author: mtg $ $Date: 2000-12-13 17:00:47 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -139,6 +139,26 @@ void SAL_CALL ZipPackageStream::setInputStream( const uno::Reference< io::XInput
bPackageMember = sal_False;
aEntry.nTime = -1;
}
+
+uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawStream( com::sun::star::package::ZipEntry &rEntry )
+ throw(uno::RuntimeException)
+{
+ if (bPackageMember)
+ {
+ try
+ {
+ return pZipFile->getRawStream(rEntry);
+ }
+ catch (package::ZipException &)//rException)
+ {
+ VOS_ENSURE( 0, "ZipException thrown");//rException.Message);
+ return uno::Reference < io::XInputStream > ();
+ }
+ }
+ else
+ return xStream;
+}
+
uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getInputStream( )
throw(uno::RuntimeException)
{
@@ -148,9 +168,9 @@ uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getInputStream( )
{
return pZipFile->getInputStream(aEntry);
}
- catch (package::ZipException &rException)
+ catch (package::ZipException &)//rException)
{
- VOS_DEBUG_ONLY(rException.Message);
+ VOS_ENSURE( 0,"ZipException thrown");//rException.Message);
return uno::Reference < io::XInputStream > ();
}
}