diff options
author | Martin Gallwey <mtg@openoffice.org> | 2000-11-16 10:55:52 +0000 |
---|---|---|
committer | Martin Gallwey <mtg@openoffice.org> | 2000-11-16 10:55:52 +0000 |
commit | 05ac3fe285dd77e0fc636af6ea5f6fea568a9d1d (patch) | |
tree | 0aee68eedcc2c1ab7d7e4484c1a0a87bf6922f6c | |
parent | f39fff0b3d65e430b6ad40c2d4a871a2f32a4ba5 (diff) |
Added 50% functional generic package implementation and added support
for un-deflated streams to EntryInputStream. This will require further
work RSN.
-rw-r--r-- | package/inc/ZipOutputStream.hxx | 6 | ||||
-rw-r--r-- | package/inc/ZipPackage.hxx | 76 | ||||
-rw-r--r-- | package/inc/ZipPackageFolder.hxx | 144 | ||||
-rw-r--r-- | package/source/zipapi/CRC32.cxx | 6 | ||||
-rw-r--r-- | package/source/zipapi/EntryInputStream.cxx | 20 | ||||
-rw-r--r-- | package/source/zipapi/ZipFile.cxx | 6 | ||||
-rw-r--r-- | package/source/zipapi/ZipOutputStream.cxx | 22 | ||||
-rw-r--r-- | package/util/makefile.mk | 6 |
8 files changed, 262 insertions, 24 deletions
diff --git a/package/inc/ZipOutputStream.hxx b/package/inc/ZipOutputStream.hxx index bfe955d862ef..049f073071c9 100644 --- a/package/inc/ZipOutputStream.hxx +++ b/package/inc/ZipOutputStream.hxx @@ -2,9 +2,9 @@ * * $RCSfile: ZipOutputStream.hxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: mtg $ $Date: 2000-11-13 13:37:57 $ + * last change: $Author: mtg $ $Date: 2000-11-16 11:55:51 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -111,7 +111,7 @@ private: CRC32 aCRC; sal_Bool bFinished; ByteChucker aChucker; - ::std::vector <::com::sun::star::package::ZipEntry*> aZipList; + ::std::vector <::com::sun::star::package::ZipEntry> aZipList; public: ZipOutputStream( com::sun::star::uno::Reference < com::sun::star::io::XOutputStream > &xOStream, sal_Int32 nNewBufferSize); diff --git a/package/inc/ZipPackage.hxx b/package/inc/ZipPackage.hxx new file mode 100644 index 000000000000..ccec5a12bd46 --- /dev/null +++ b/package/inc/ZipPackage.hxx @@ -0,0 +1,76 @@ +#ifndef _ZIP_PACKAGE_HXX +#define _ZIP_PACKAGE_HXX + +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif + +#ifndef _CPPUHELPER_IMPLBASE4_HXX_ +#include <cppuhelper/implbase4.hxx> // helper for implementations +#endif + +#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_ +#include <com/sun/star/lang/XInitialization.hpp> +#endif + +#ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMEACCESS_HPP_ +#include <com/sun/star/container/XHierarchicalNameAccess.hpp> +#endif + +#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#endif + +#ifndef _COM_SUN_STAR_UTIL_XCHANGESBATCH_HPP_ +#include <com/sun/star/util/XChangesBatch.hpp> +#endif + +#ifndef _ZIP_FILE_HXX +#include "ZipFile.hxx" +#endif + +#ifndef _ZIP_OUTPUT_STREAM_HXX +#include "ZipOutputStream.hxx" +#endif + +#include <hash_map> +class ZipPackageFolder; +#include "ZipPackageFolder.hxx" +#include "ZipPackageStream.hxx" +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 + > +{ +private: + ZipPackageFolder aRootFolder; + com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xStream; +public: + ZipFile aZipFile; + ZipOutputStream aZipOut; + ZipPackage (com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xInput, com::sun::star::uno::Reference < com::sun::star::io::XOutputStream > xOutput ); + virtual ~ZipPackage( void ); + // 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); + // XHierarchicalNameAccess + virtual ::com::sun::star::uno::Any SAL_CALL getByHierarchicalName( const ::rtl::OUString& aName ) + throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasByHierarchicalName( const ::rtl::OUString& aName ) + throw(::com::sun::star::uno::RuntimeException); + // XSingleServiceFactory + virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstance( ) + throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstanceWithArguments( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) + throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); + // XChangesBatch + virtual void SAL_CALL commitChanges( ) + throw(::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasPendingChanges( ) + throw(::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::util::ElementChange > SAL_CALL getPendingChanges( ) + throw(::com::sun::star::uno::RuntimeException); +}; +#endif diff --git a/package/inc/ZipPackageFolder.hxx b/package/inc/ZipPackageFolder.hxx new file mode 100644 index 000000000000..3c76ce4edb17 --- /dev/null +++ b/package/inc/ZipPackageFolder.hxx @@ -0,0 +1,144 @@ +#ifndef _ZIP_PACKAGE_FOLDER_HXX +#define _ZIP_PACKAGE_FOLDER_HXX + +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif + +#ifndef _COM_SUN_STAR_IO_XOUTPUTSTREAM_HPP_ +#include <com/sun/star/io/XOutputStream.hpp> +#endif + +#ifndef _COM_SUN_STAR_IO_XACTIVEDATASINK_HPP_ +#include <com/sun/star/io/XActiveDataSink.hpp> +#endif + +#ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_ +#include <com/sun/star/container/XNameContainer.hpp> +#endif + +#ifndef _COM_SUN_STAR_CONTAINER_XENUMERATIONACCESS_HPP_ +#include <com/sun/star/container/XEnumerationAccess.hpp> +#endif + +#ifndef __com_sun_star_package_ZipEntry_hpp__ +#include <com/sun/star/package/ZipEntry.hpp> +#endif + +#ifndef __com_sun_star_beans_XPropertySet_hpp__ +#include <com/sun/star/beans/XPropertySet.hpp> +#endif + +#ifndef __com_sun_star_lang_XUnoTunnel_hpp__ +#include <com/sun/star/lang/XUnoTunnel.hpp> +#endif + +#include <hash_map> + +struct eqFunc +{ + sal_Bool operator()( const rtl::OUString &r1, + const rtl::OUString &r2) const + { + return r1 == r2; + } +}; + +struct hashFunc +{ + sal_Int32 operator()(const rtl::OUString &r1) const + { + return r1.hashCode(); + } +}; +//#include "ZipPackageStream.hxx" + +/* This include must be after the above struct and typedef declarations. + * Ugly...but true :) + */ + +#ifndef _ZIP_PACKAGE_FOLDER_ENUMERATION_HXX +#include "ZipPackageFolderEnumeration.hxx" +#endif + +#ifndef _ZIP_PACKAGE_ENTRY_HXX +#include "ZipPackageEntry.hxx" +#endif + +#ifndef _ZIP_OUTPUT_STREAM_HXX +#include "ZipOutputStream.hxx" +#endif + +typedef std::hash_map < rtl::OUString, com::sun::star::uno::Reference < com::sun::star::beans::XPropertySet > , hashFunc, eqFunc > PropertyHash; + +class ZipPackageFolder : public ZipPackageEntry, + public ::com::sun::star::container::XNameContainer, + public ::com::sun::star::container::XEnumerationAccess, + public ::com::sun::star::beans::XPropertySet, + public ::com::sun::star::lang::XUnoTunnel +{ +private: + //std::hash_map < rtl::OUString, ZipPackageFolder, hashFunc, eqFunc > aFolders; + //StreamHash aStreams; + ZipOutputStream &rZipOut; + ::rtl::OUString sMediaType; + ::rtl::OUString sPath; + PropertyHash aContents; + com::sun::star::uno::Reference < com::sun::star::uno::XInterface > xParent; +public: + ZipPackageFolder (ZipOutputStream &rStream );//ZipPackage &rInPackage); + void saveContents(rtl::OUString &rPath); + 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); + virtual void SAL_CALL acquire( ) + throw(); + virtual void SAL_CALL release( ) + throw(); + // XNameContainer + virtual void SAL_CALL insertByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement ) + throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeByName( const ::rtl::OUString& Name ) + throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + // XEnumerationAccess + virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration( ) + throw(::com::sun::star::uno::RuntimeException); + // XElementAccess + virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) + throw(::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasElements( ) + throw(::com::sun::star::uno::RuntimeException); + // XNameAccess + virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) + throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) + throw(::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) + throw(::com::sun::star::uno::RuntimeException); + // XNameReplace + virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement ) + throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + // XPropertySet + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) + throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + // XUnoTunnel + virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) + throw(::com::sun::star::uno::RuntimeException); +}; +#endif diff --git a/package/source/zipapi/CRC32.cxx b/package/source/zipapi/CRC32.cxx index bca9154af66f..ca866f761fc5 100644 --- a/package/source/zipapi/CRC32.cxx +++ b/package/source/zipapi/CRC32.cxx @@ -2,9 +2,9 @@ * * $RCSfile: CRC32.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: mtg $ $Date: 2000-11-13 13:38:01 $ + * last change: $Author: mtg $ $Date: 2000-11-16 11:55:52 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -81,7 +81,7 @@ void CRC32::reset() } sal_Int32 CRC32::getValue() { - return (sal_Int32) nCRC & 0xFFFFFFFFL; + return nCRC & 0xFFFFFFFFL; } /** Update CRC32 with specified byte */ diff --git a/package/source/zipapi/EntryInputStream.cxx b/package/source/zipapi/EntryInputStream.cxx index a2f65288a7ef..66150d97c16d 100644 --- a/package/source/zipapi/EntryInputStream.cxx +++ b/package/source/zipapi/EntryInputStream.cxx @@ -2,9 +2,9 @@ * * $RCSfile: EntryInputStream.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: mtg $ $Date: 2000-11-13 13:38:01 $ + * last change: $Author: mtg $ $Date: 2000-11-16 11:55:52 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -80,13 +80,15 @@ using namespace com::sun::star; * seek to it before performing any reads. */ -EntryInputStream::EntryInputStream( uno::Reference < io::XInputStream > xNewInput, sal_Int64 nNewBegin, sal_Int64 nNewEnd, sal_Int32 nNewBufferSize) +EntryInputStream::EntryInputStream( uno::Reference < io::XInputStream > xNewInput, sal_Int64 nNewBegin, sal_Int64 nNewEnd, sal_Int32 nNewBufferSize, sal_Bool bNewDeflated) : xStream(xNewInput) , xSeek(xNewInput, uno::UNO_QUERY) , nBegin(nNewBegin) , nCurrent(nNewBegin) , nEnd(nNewEnd) , aSequence ( nNewBufferSize ) +, bDeflated ( bNewDeflated ) +, bReachEOF ( sal_False ) , aInflater( sal_True ) , nLength(0) { @@ -114,6 +116,16 @@ sal_Int32 SAL_CALL EntryInputStream::readBytes( uno::Sequence< sal_Int8 >& aData sal_Int32 n; if (nBytesToRead <=0) return 0; + if (nBytesToRead + nCurrent > nEnd) + { + if (nCurrent > nEnd) + return 0; + nBytesToRead = nEnd - nCurrent; + } + + if (!bDeflated) + return xStream->readBytes(aData, nBytesToRead ); + while ( (n = aInflater.doInflate(aData)) == 0) { if (aInflater.finished() || aInflater.needsDictionary()) @@ -141,7 +153,7 @@ sal_Int32 SAL_CALL EntryInputStream::readSomeBytes( uno::Sequence< sal_Int8 >& a xSeek->seek( nCurrent ); else throw (io::IOException()); - return xStream->readSomeBytes( aData, nMaxBytesToRead ); + return readBytes( aData, nMaxBytesToRead ); } void SAL_CALL EntryInputStream::skipBytes( sal_Int32 nBytesToSkip ) throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx index 3d4d9335fd08..cd8a7aea0eeb 100644 --- a/package/source/zipapi/ZipFile.cxx +++ b/package/source/zipapi/ZipFile.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ZipFile.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: mtg $ $Date: 2000-11-13 13:38:01 $ + * last change: $Author: mtg $ $Date: 2000-11-16 11:55:52 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -211,7 +211,7 @@ uno::Reference< io::XInputStream> ZipFile::getInputStream(const package::ZipEntr sal_Int64 nBegin = rEntry.nOffset; nEnd +=nBegin; - uno::Reference< io::XInputStream > xStreamRef = new EntryInputStream(xStream, nBegin, nEnd, 1024); + uno::Reference< io::XInputStream > xStreamRef = new EntryInputStream(xStream, nBegin, nEnd, 1024, rEntry.nMethod == DEFLATED); return xStreamRef; } sal_Bool ZipFile::readLOC(const package::ZipEntry &rEntry) diff --git a/package/source/zipapi/ZipOutputStream.cxx b/package/source/zipapi/ZipOutputStream.cxx index fa5e8ac5b2d8..a1766937b0f7 100644 --- a/package/source/zipapi/ZipOutputStream.cxx +++ b/package/source/zipapi/ZipOutputStream.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ZipOutputStream.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: mtg $ $Date: 2000-11-13 13:38:01 $ + * last change: $Author: mtg $ $Date: 2000-11-16 11:55:52 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -119,10 +119,10 @@ void SAL_CALL ZipOutputStream::putNextEntry( const package::ZipEntry& rEntry ) case DEFLATED: if (pNonConstEntry->nSize == -1 || pNonConstEntry->nCompressedSize == -1 || pNonConstEntry->nCrc == -1) - pNonConstEntry->nFlag = 8; + pNonConstEntry->nFlag |= 8; else if (pNonConstEntry->nSize != -1 && pNonConstEntry->nCompressedSize != -1 && pNonConstEntry->nCrc != -1) - pNonConstEntry->nFlag=0; + pNonConstEntry->nFlag &= 8; pNonConstEntry->nVersion = 20; break; case STORED: @@ -131,12 +131,12 @@ void SAL_CALL ZipOutputStream::putNextEntry( const package::ZipEntry& rEntry ) else if (pNonConstEntry->nCompressedSize == -1) pNonConstEntry->nCompressedSize = pNonConstEntry->nSize; pNonConstEntry->nVersion = 10; - pNonConstEntry->nFlag = 0; + pNonConstEntry->nFlag &= 8; break; } pNonConstEntry->nOffset = aChucker.getPosition(); writeLOC(rEntry); - aZipList.push_back(pNonConstEntry); + aZipList.push_back(*pNonConstEntry); pCurrentEntry=pNonConstEntry; } void SAL_CALL ZipOutputStream::close( ) @@ -185,7 +185,13 @@ void SAL_CALL ZipOutputStream::closeEntry( ) aDeflater.reset(); break; case STORED: - if (pEntry->nCrc != aCRC.getValue()) + { + sal_uInt32 na= pEntry->nCrc; + sal_uInt32 nb = aCRC.getValue(); + int i=0; + } + + if (static_cast < sal_uInt32 > (pEntry->nCrc) != static_cast <sal_uInt32> (aCRC.getValue())) { // boom DBG_ERROR("Invalid entry crc32"); @@ -234,7 +240,7 @@ void SAL_CALL ZipOutputStream::finish( ) } sal_Int32 nOffset= aChucker.getPosition(); for (int i =0, nEnd = aZipList.size(); i < nEnd; i++) - writeCEN(*aZipList[i]); + writeCEN(aZipList[i]); writeEND( nOffset, aChucker.getPosition() - nOffset); bFinished = sal_True; } diff --git a/package/util/makefile.mk b/package/util/makefile.mk index 6c42e80186fb..e4490fe9b245 100644 --- a/package/util/makefile.mk +++ b/package/util/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.1 $ +# $Revision: 1.2 $ # -# last change: $Author: mtg $ $Date: 2000-11-13 13:38:03 $ +# last change: $Author: mtg $ $Date: 2000-11-16 11:55:52 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -77,7 +77,7 @@ LIB1FILES= \ # --- Shared-Library ----------------------------------------------- -SHL1TARGET= package$(UPD)$(DLLPOSTFIX) +SHL1TARGET= package$(DLLPOSTFIX) SHL1IMPLIB= _ipackage SHL1STDLIBS= \ |