summaryrefslogtreecommitdiff
path: root/package
diff options
context:
space:
mode:
authorMikhail Voitenko <mav@openoffice.org>2002-04-29 13:31:07 +0000
committerMikhail Voitenko <mav@openoffice.org>2002-04-29 13:31:07 +0000
commit2121ded9b52db7fbf467a2270e54e7d060d64c46 (patch)
tree45f17bb893c3e16c7f203cbca44dd960169a0af2 /package
parenta529307d61ae29c06218cb9bfe8247801c6a7553 (diff)
#98945# write additional magic mimetype file
Diffstat (limited to 'package')
-rw-r--r--package/inc/ZipPackage.hxx6
-rw-r--r--package/source/zippackage/ZipPackage.cxx45
2 files changed, 46 insertions, 5 deletions
diff --git a/package/inc/ZipPackage.hxx b/package/inc/ZipPackage.hxx
index db00afe13078..d459e2dfa684 100644
--- a/package/inc/ZipPackage.hxx
+++ b/package/inc/ZipPackage.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ZipPackage.hxx,v $
*
- * $Revision: 1.31 $
+ * $Revision: 1.32 $
*
- * last change: $Author: mav $ $Date: 2002-02-27 15:51:57 $
+ * last change: $Author: mav $ $Date: 2002-04-29 14:31:07 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -94,6 +94,7 @@
#ifndef _OSL_FILE_H_
#include <osl/file.h>
#endif
+class ZipOutputStream;
class ZipPackageFolder;
class ZipFile;
class ByteGrabber;
@@ -149,6 +150,7 @@ protected:
void getZipFileContents();
sal_Bool writeFileIsTemp();
::com::sun::star::uno::Reference < ::com::sun::star::io::XActiveDataStreamer > openOriginalForOutput();
+ void WriteMimetypeMagicFile( ZipOutputStream& aZipOut );
public:
ZipPackage (const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > &xNewFactory);
diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx
index 11f8241cfeb1..38245d20cdf4 100644
--- a/package/source/zippackage/ZipPackage.cxx
+++ b/package/source/zippackage/ZipPackage.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ZipPackage.cxx,v $
*
- * $Revision: 1.79 $
+ * $Revision: 1.80 $
*
- * last change: $Author: mav $ $Date: 2002-04-11 14:29:37 $
+ * last change: $Author: mav $ $Date: 2002-04-29 14:30:06 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -432,8 +432,12 @@ void ZipPackage::getZipFileContents()
}
}
const OUString sMeta ( RTL_CONSTASCII_USTRINGPARAM ( "META-INF" ) );
- if (xRootFolder->hasByName( sMeta ) )
+ if ( xRootFolder->hasByName( sMeta ) )
xRootFolder->removeByName( sMeta );
+
+ const OUString sMimetype ( RTL_CONSTASCII_USTRINGPARAM ( "mimetype" ) );
+ if ( xRootFolder->hasByName( sMimetype ) )
+ xRootFolder->removeByName( sMimetype );
}
// XInitialization
void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments )
@@ -711,6 +715,37 @@ Reference< XInterface > SAL_CALL ZipPackage::createInstanceWithArguments( const
return xRef;
}
+void ZipPackage::WriteMimetypeMagicFile( ZipOutputStream& aZipOut )
+{
+ const OUString sMime ( RTL_CONSTASCII_USTRINGPARAM ( "mimetype" ) );
+ if (xRootFolder->hasByName( sMime ) )
+ xRootFolder->removeByName( sMime );
+
+ ZipEntry * pEntry = new ZipEntry;
+ sal_Int32 nBufferLength = pRootFolder->GetMediaType( ).getLength();
+ OString sMediaType = OUStringToOString( pRootFolder->GetMediaType(), RTL_TEXTENCODING_ASCII_US );
+ Sequence< sal_Int8 > aType( (sal_Int8*)sMediaType.getStr(),
+ nBufferLength );
+
+ pEntry->sName = sMime;
+ pEntry->nMethod = STORED;
+ pEntry->nCrc =
+ pEntry->nSize = pEntry->nCompressedSize = nBufferLength;
+ pEntry->nTime = ZipOutputStream::getCurrentDosTime();
+
+ try
+ {
+ vos::ORef < EncryptionData > xEmpty;
+ aZipOut.putNextEntry( *pEntry, xEmpty );
+ aZipOut.write( aType, 0, nBufferLength );
+ aZipOut.closeEntry();
+ }
+ catch (::com::sun::star::io::IOException & )
+ {
+ VOS_ENSURE( 0, "Error adding mimetype to the ZipOutputStream" );
+ }
+}
+
sal_Bool ZipPackage::writeFileIsTemp()
{
// In case the target local file does not exist or empty
@@ -755,6 +790,9 @@ sal_Bool ZipPackage::writeFileIsTemp()
if (xRootFolder->hasByName( sMeta ) )
xRootFolder->removeByName( sMeta );
+ // Write a magic file with mimetype
+ WriteMimetypeMagicFile( aZipOut );
+
// Create a vector to store data for the manifest.xml file
vector < Sequence < PropertyValue > > aManList;
@@ -780,6 +818,7 @@ sal_Bool ZipPackage::writeFileIsTemp()
rtlRandomPool aRandomPool = rtl_random_createPool ();
rtl_random_addBytes ( aRandomPool, &aTime, 8 );
+
// call saveContents (it will recursively save sub-directories
OUString aEmptyString;
pRootFolder->saveContents( aEmptyString, aManList, aZipOut, aEncryptionKey, aRandomPool );