summaryrefslogtreecommitdiff
path: root/package
diff options
context:
space:
mode:
authorMartin Gallwey <mtg@openoffice.org>2001-11-29 12:49:35 +0000
committerMartin Gallwey <mtg@openoffice.org>2001-11-29 12:49:35 +0000
commitd3b6ccb9e85b25bf2324326a2db99e958bfcc394 (patch)
treee0814725a50a03c2110ed2c1f87800f2689b7c20 /package
parent66658983fd99dcbcaa4a4575e3084742a9996b41 (diff)
#94573# remove support for pack'n'go disk spanning
Diffstat (limited to 'package')
-rw-r--r--package/source/zipapi/ZipOutputStream.cxx17
-rw-r--r--package/source/zippackage/ZipPackage.cxx838
2 files changed, 42 insertions, 813 deletions
diff --git a/package/source/zipapi/ZipOutputStream.cxx b/package/source/zipapi/ZipOutputStream.cxx
index f1b2fb70d81e..7384b6f8d73a 100644
--- a/package/source/zipapi/ZipOutputStream.cxx
+++ b/package/source/zipapi/ZipOutputStream.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ZipOutputStream.cxx,v $
*
- * $Revision: 1.34 $
+ * $Revision: 1.35 $
*
- * last change: $Author: mtg $ $Date: 2001-11-15 20:23:28 $
+ * last change: $Author: mtg $ $Date: 2001-11-29 13:49:35 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -99,7 +99,7 @@ using namespace com::sun::star::packages::zip::ZipConstants;
/** This class is used to write Zip files
*/
-ZipOutputStream::ZipOutputStream( Reference < XOutputStream > &xOStream, sal_Bool bNewSpanning )
+ZipOutputStream::ZipOutputStream( Reference < XOutputStream > &xOStream )
: xStream(xOStream)
, aChucker(xOStream)
, nMethod(DEFLATED)
@@ -108,7 +108,6 @@ ZipOutputStream::ZipOutputStream( Reference < XOutputStream > &xOStream, sal_Boo
, bEncryptCurrentEntry(sal_False)
, aBuffer(n_ConstBufferSize)
, aDeflater(DEFAULT_COMPRESSION, sal_True)
-, bSpanning ( bNewSpanning )
{
}
@@ -139,16 +138,6 @@ void SAL_CALL ZipOutputStream::putNextEntry( ZipEntry& rEntry,
sal_Bool bEncrypt)
throw(IOException, RuntimeException)
{
- if ( bSpanning && ! aZipList.size() )
- {
- Sequence < sal_Int8 > aSequence ( 4 );
- sal_Int8 *pNum = aSequence.getArray();
- pNum[0] = 'P';
- pNum[1] = 'K';
- pNum[2] = 7;
- pNum[3] = 8;
- aChucker.writeBytes( aSequence, 4, pNum );
- }
if (pCurrentEntry != NULL)
closeEntry();
if (rEntry.nTime == -1)
diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx
index b9f2952de86a..70e90f1b5409 100644
--- a/package/source/zippackage/ZipPackage.cxx
+++ b/package/source/zippackage/ZipPackage.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ZipPackage.cxx,v $
*
- * $Revision: 1.71 $
+ * $Revision: 1.72 $
*
- * last change: $Author: mtg $ $Date: 2001-11-15 21:36:18 $
+ * last change: $Author: mtg $ $Date: 2001-11-29 13:46:23 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -154,26 +154,6 @@
#include <memory>
#include <vector>
-// pack'n'go headers
-#ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_
-#include <com/sun/star/task/XInteractionHandler.hpp>
-#endif
-#ifndef _INTERACTION_REQUEST_HXX_
-#include <InteractionRequest.hxx>
-#endif
-#ifndef _RTL_USTRBUF_HXX_
-#include <rtl/ustrbuf.hxx>
-#endif
-#ifndef _COM_SUN_STAR_UCB_INTERACTIVEAUGMENTEDIOEXCEPTION_HPP_
-#include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
-#endif
-#ifndef _OSL_FILE_HXX_
-#include <osl/file.hxx>
-#endif
-#ifndef _COM_SUN_STAR_UCB_INTERACTIVEWRONGMEDIUMEXCEPTION_HPP_
-#include <com/sun/star/ucb/InteractiveWrongMediumException.hpp>
-#endif
-
using namespace rtl;
using namespace ucb;
@@ -193,75 +173,14 @@ using namespace com::sun::star::packages::zip;
using namespace com::sun::star::packages::manifest;
using namespace com::sun::star::packages::zip::ZipConstants;
-
#define LOGFILE_AUTHOR "mg115289"
-struct SuffixGenerator
-{
- sal_Char mpSuffix[30], *mpSuffixMid, *mpSuffixEnd;
- sal_uInt16 mnDigits;
- SuffixGenerator(): mnDigits (2), mpSuffixMid ( mpSuffix), mpSuffixEnd ( mpSuffix + 2)
- {
- memset ( mpSuffix, 0, 30 );
- mpSuffixMid[0] = 'a';
- mpSuffixMid[1] = 'a'; // first generated suffix will be .ab
- }
- void generateFileName( OUString &rFileName, const OUString &rPrefix );
- void generateFileName( OUString &rFileName, const OUString &rPrefix, sal_uInt16 nDiskNum);
-};
-
-void SuffixGenerator::generateFileName( OUString &rFileName, const OUString &rPrefix )
-{
- // same file prefix, different extension
- OUStringBuffer aStringBuf;
- sal_Char *p;
- for ( p = mpSuffixEnd-1; *p == 'z'; p--)
- *p = 'a';
- ++(*p);
- if (*p == 'z' && p == mpSuffixMid )
- {
- ++mnDigits;
- ++mpSuffixMid;
- *mpSuffixEnd++ = 'a';
- *mpSuffixEnd++ = 'a';
- }
- aStringBuf.append ( rPrefix );
- aStringBuf.appendAscii ( mpSuffix );
- rFileName = aStringBuf.makeStringAndClear();
-}
-void SuffixGenerator::generateFileName( OUString &rFileName, const OUString &rPrefix, sal_uInt16 nDiskNum)
-{
- // same file prefix, different extension
- OUStringBuffer aStringBuf;
- aStringBuf.append ( rPrefix );
- aStringBuf.appendAscii ( nDiskNum < 10 ? "00" : nDiskNum < 100 ? "0" : "" );
- aStringBuf.append ( static_cast < sal_Int32 > ( nDiskNum-1) );
-
- rFileName = aStringBuf.makeStringAndClear();
-}
-
-#ifdef MTG_DEBUG
-char * ImplGetChars( const OUString & rString )
-{
- // Memory leak ? Bah!
- sal_Int32 nLength = rString.getLength();
- const sal_Unicode *pString = rString.getStr();
- char * pChar = new char [nLength+1];
- for ( sal_Int16 i = 0; i < nLength; i++ )
- {
- pChar[i] = static_cast < char > (pString[i]);
- }
- pChar[nLength] = '\0';
- return pChar;
-}
-#endif
ZipPackage::ZipPackage (const Reference < XMultiServiceFactory > &xNewFactory)
: pZipFile( NULL )
, pRootFolder( NULL )
, xFactory( xNewFactory )
, bHasEncryptedEntries ( sal_False )
, eMode ( e_IMode_None )
-, nSegmentSize ( 0 )
{
xRootFolder = pRootFolder = new ZipPackageFolder();
}
@@ -445,7 +364,7 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments )
throw(Exception, RuntimeException)
{
RTL_LOGFILE_TRACE_AUTHOR ( "package", LOGFILE_AUTHOR, "{ ZipPackage::initialize" );
- sal_Bool bBadZipFile = sal_False, bHaveZipFile = sal_True, bSpanned = sal_False;
+ sal_Bool bBadZipFile = sal_False, bHaveZipFile = sal_True;
if ( aArguments.getLength() )
{
@@ -489,20 +408,6 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments )
if ( ! xContentSeek.is() )
throw com::sun::star::uno::Exception ( OUString( RTL_CONSTASCII_USTRINGPARAM ( "The package component _requires_ an XSeekable interface!" ) ),
static_cast < ::cppu::OWeakObject * > ( this ) );
- if ( eMode == e_IMode_URL) // spanned files only supported if initialised with a URL
- {
- Sequence < sal_Int8 > aSequence ( 4 );
- if ( 4 == xContentStream->readBytes( aSequence, 4 ) )
- {
- xContentSeek->seek ( 0 );
- const sal_Int8 *pSeq = aSequence.getConstArray();
- if (pSeq[0] == 'P' &&
- pSeq[1] == 'K' &&
- pSeq[2] == 7 &&
- pSeq[3] == 8 )
- bSpanned = sal_True;
- }
- }
}
else
bHaveZipFile = sal_False;
@@ -518,10 +423,6 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments )
{
try
{
- if ( bSpanned )
- // after unSpanFile, xContentStream will refer to the tempfile containing
- // the unspanned file
- unSpanFile ();
pZipFile = new ZipFile ( xContentStream, xFactory, sal_True );
getZipFileContents();
}
@@ -713,9 +614,10 @@ Reference< XInterface > SAL_CALL ZipPackage::createInstance( )
Reference< XInterface > SAL_CALL ZipPackage::createInstanceWithArguments( const Sequence< Any >& aArguments )
throw(Exception, RuntimeException)
{
- sal_Bool bArg;
+ sal_Bool bArg = sal_False;
Reference < XInterface > xRef;
- aArguments[0] >>= bArg;
+ if ( aArguments.getLength() )
+ aArguments[0] >>= bArg;
if (bArg)
xRef = *new ZipPackageFolder ( );
else
@@ -731,7 +633,7 @@ void ZipPackage::writeTempFile()
Reference < XOutputStream > xTempOut = Reference < XOutputStream > ( xFactory->createInstance ( sServiceName ), UNO_QUERY );
// Hand it to the ZipOutputStream:
- ZipOutputStream aZipOut ( xTempOut, nSegmentSize != 0);
+ ZipOutputStream aZipOut ( xTempOut );
aZipOut.setMethod(DEFLATED);
aZipOut.setLevel(DEFAULT_COMPRESSION);
@@ -883,144 +785,45 @@ void SAL_CALL ZipPackage::commitChanges( )
if ( eMode == e_IMode_URL )
{
- if (!nSegmentSize )
- {
- Reference < XPropertySet > xPropSet ( xContentStream, UNO_QUERY );
- OUString sTargetFolder = sURL.copy ( 0, sURL.lastIndexOf ( static_cast < sal_Unicode > ( '/' ) ) );
- Content aContent ( sTargetFolder, Reference < XCommandEnvironment > () );
- if ( xPropSet.is() )
+ Reference < XPropertySet > xPropSet ( xContentStream, UNO_QUERY );
+ OUString sTargetFolder = sURL.copy ( 0, sURL.lastIndexOf ( static_cast < sal_Unicode > ( '/' ) ) );
+ Content aContent ( sTargetFolder, Reference < XCommandEnvironment > () );
+ if ( xPropSet.is() )
+ {
+ OUString sTempURL;
+ Any aAny = xPropSet->getPropertyValue ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Uri" ) ) );
+ aAny >>= sTempURL;
+ TransferInfo aInfo;
+ aInfo.NameClash = NameClash::OVERWRITE;
+ aInfo.MoveData = sal_False;
+ aInfo.SourceURL = sTempURL;
+ aInfo.NewTitle = rtl::Uri::decode ( sURL.copy ( 1 + sURL.lastIndexOf ( static_cast < sal_Unicode > ( '/' ) ) ),
+ rtl_UriDecodeWithCharset,
+ RTL_TEXTENCODING_UTF8 );
+ aAny <<= aInfo;
+ try
{
- OUString sTempURL;
- Any aAny = xPropSet->getPropertyValue ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Uri" ) ) );
- aAny >>= sTempURL;
- TransferInfo aInfo;
- aInfo.NameClash = NameClash::OVERWRITE;
- aInfo.MoveData = sal_False;
- aInfo.SourceURL = sTempURL;
- aInfo.NewTitle = rtl::Uri::decode ( sURL.copy ( 1 + sURL.lastIndexOf ( static_cast < sal_Unicode > ( '/' ) ) ),
- rtl_UriDecodeWithCharset,
- RTL_TEXTENCODING_UTF8 );
- aAny <<= aInfo;
- try
- {
- aContent.executeCommand ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "transfer" ) ), aAny );
- }
- catch (::com::sun::star::uno::Exception& r)
- {
- throw WrappedTargetException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Unable to write Zip File to disk!" ) ),
- static_cast < OWeakObject * > ( this ), makeAny( r ) );
- }
+ aContent.executeCommand ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "transfer" ) ), aAny );
}
- else
+ catch (::com::sun::star::uno::Exception& r)
{
- // not quite sure how it could happen that xContentStream WOULDN'T support
- // XPropertySet, but just in case... :)
- try
- {
- aContent.writeStream ( xContentStream, sal_True );
- }
- catch (::com::sun::star::uno::Exception& r)
- {
- throw WrappedTargetException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Unable to write Zip File to disk!" ) ),
- static_cast < OWeakObject * > ( this ), makeAny( r ) );
- }
+ throw WrappedTargetException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Unable to write Zip File to disk!" ) ),
+ static_cast < OWeakObject * > ( this ), makeAny( r ) );
}
}
else
{
- // We want to span...first, make sure we have an interaction handler...
- getInteractionHandler();
-
- sal_Int16 nDiskNum = 0;
- VolumeInfo aInfo ( osl_VolumeInfo_Mask_FreeSpace | osl_VolumeInfo_Mask_DeviceHandle | osl_VolumeInfo_Mask_Attributes );
- FileBase::RC aRC = Directory::getVolumeInfo ( sURL, aInfo );
-#ifdef MTG_DEBUG
- fprintf(stderr, "MTG: url is %s getVolumeInfo returned %d\n", ImplGetChars ( sURL), aRC);
- fprintf(stderr, "MTG: isRemovable returned %d\n", aInfo.getRemoveableFlag() );
- fprintf(stderr, "MTG: isValid osl_VolumeInfo_Mask_FreeSpace returned %d\n", aInfo.isValid(osl_VolumeInfo_Mask_FreeSpace) );
- fprintf(stderr, "MTG: isValid osl_VolumeInfo_Mask_DeviceHandle returned %d\n", aInfo.isValid(osl_VolumeInfo_Mask_DeviceHandle) );
- fprintf(stderr, "MTG: isValid osl_VolumeInfo_Mask_Attributes returned %d\n", aInfo.isValid(osl_VolumeInfo_Mask_Attributes) );
- fprintf(stderr, "MTG: getFreeSpace returned %ld\n", static_cast < sal_Int32 > ( aInfo.getFreeSpace() ) );
- fprintf(stderr, "MTG: getUsedSpace returned %ld\n", static_cast < sal_Int32 > ( aInfo.getUsedSpace() ) );
- fprintf(stderr, "MTG: getTotalSpace returned %ld\n", static_cast < sal_Int32 > ( aInfo.getTotalSpace() ) );
-#endif
- VolumeDevice aDevice = aInfo.getDeviceHandle();
- OUString sFileName, sMountPath = aDevice.getMountPath();
-#ifdef MTG_DEBUG
- fprintf(stderr, "MTG: mount path is %s %d\n", ImplGetChars ( sMountPath ), aRC);
-#endif
- sal_Int32 nLastSlash = sURL.lastIndexOf ( '/' );
- OUString sFilePrefix = sURL.copy ( 1 + nLastSlash, sURL.lastIndexOf ( '.' ) - nLastSlash );
-
-#ifdef MTG_DEBUG
- fprintf(stderr, "MTG: url is %s first getVolumeInfo on %s returned %d\n", ImplGetChars ( sURL), ImplGetChars ( sMountPath), aRC);
-#endif
- sal_Bool bIsRemovable = aInfo.getRemoveableFlag();
-#ifdef MTG_DEBUG
- fprintf(stderr, "MTG: Removable flag is %d\n", bIsRemovable);
-#endif
- SegmentEnum eRet = e_Finished;
- SuffixGenerator aGenerator;
- do
+ // not quite sure how it could happen that xContentStream WOULDN'T support
+ // XPropertySet, but just in case... :)
+ try
{
- nDiskNum++;
- sal_Int64 nCurrentPos = xContentSeek->getPosition();
- if ( nDiskNum == 1 )
- sFileName = sURL.copy ( 1 + nLastSlash );
- else
- aGenerator.generateFileName ( sFileName, sFilePrefix, nDiskNum );
- if ( bIsRemovable )
- {
- if ( nDiskNum > 1 && RequestDisk( sMountPath, nDiskNum ) < 0 )
- return;
-
- do
- {
- eRet = writeSegment ( sFileName, sMountPath, xContentStream, nDiskNum );
- if (eRet == e_Aborted)
- return;
- else if ( eRet == e_Retry )
- xContentSeek->seek ( nCurrentPos );
- }
- while ( eRet == e_Retry );
- }
- else
- {
- OUString sFullPath = sURL.copy ( 0, nLastSlash + 1 ) + sFileName;
- if ( xContentSeek->getLength() > static_cast < sal_Int64 > ( aInfo.getFreeSpace() ) )
- {
- // no room on the hard drive, display a message and return
- HandleError ( osl_File_E_NOSPC, EC_YES, sFullPath );
- return;
- }
- else if ( nSegmentSize < 0 )
- {
- try
- {
- Content aContent (sURL, Reference < XCommandEnvironment >() );
- aContent.writeStream ( xContentStream, sal_True );
- }
- catch (::com::sun::star::uno::Exception& r)
- {
- throw WrappedTargetException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Unable to write Zip File to disk!" ) ),
- static_cast < OWeakObject * > ( this ), makeAny( r ) );
- }
- }
- else
- {
- do
- {
- eRet = writeSegment ( sFullPath, xContentStream );
- if (eRet == e_Aborted)
- return;
- else if ( eRet == e_Retry )
- xContentSeek->seek ( nCurrentPos );
- }
- while ( eRet == e_Retry );
- }
- }
+ aContent.writeStream ( xContentStream, sal_True );
+ }
+ catch (::com::sun::star::uno::Exception& r)
+ {
+ throw WrappedTargetException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Unable to write Zip File to disk!" ) ),
+ static_cast < OWeakObject * > ( this ), makeAny( r ) );
}
- while ( eRet != e_Finished );
}
}
RTL_LOGFILE_TRACE_AUTHOR ( "package", LOGFILE_AUTHOR, "} ZipPackage::commitChanges" );
@@ -1131,12 +934,7 @@ void SAL_CALL ZipPackage::setPropertyValue( const OUString& aPropertyName, const
if (!( aValue >>= aEncryptionKey ) )
throw IllegalArgumentException();
}
- else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("SegmentSize") ) )
- {
- if (!( aValue >>= nSegmentSize ) )
- throw IllegalArgumentException();
- }
- else
+ else if (! aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("SegmentSize") ) )
throw UnknownPropertyException();
}
Any SAL_CALL ZipPackage::getPropertyValue( const OUString& PropertyName )
@@ -1155,7 +953,7 @@ Any SAL_CALL ZipPackage::getPropertyValue( const OUString& PropertyName )
}
else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "SegmentSize" ) ) )
{
- aAny <<= nSegmentSize;
+ aAny <<= static_cast < sal_Int32 > ( 0 );
return aAny;
}
else
@@ -1177,561 +975,3 @@ void SAL_CALL ZipPackage::removeVetoableChangeListener( const OUString& Property
throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
{
}
-
-void ZipPackage::getInteractionHandler()
-{
- if ( ! xInteractionHandler.is() )
- {
- OUString sServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.task.InteractionHandler" ) );
- xInteractionHandler = Reference < XInteractionHandler > ( xFactory->createInstance ( sServiceName ), UNO_QUERY );
- }
-}
-
-IOErrorCode Impl_OSLFileErrorToUCBIoErrorCode ( oslFileError aRC )
-{
- IOErrorCode eReturn = IOErrorCode_UNKNOWN;
- switch ( aRC )
- {
- // open
- case osl_File_E_NOMEM:// not enough memory for allocating structures <br>
- eReturn = IOErrorCode_OUT_OF_MEMORY;
- break;
- case osl_File_E_NAMETOOLONG:// pathname was too long<br>
- eReturn = IOErrorCode_NAME_TOO_LONG;
- break;
- case osl_File_E_NOENT:// No such file or directory<br>
- eReturn = IOErrorCode_NOT_EXISTING;
- break;
- case osl_File_E_ACCES:// permission denied<P>
- eReturn = IOErrorCode_ACCESS_DENIED;
- break;
- case osl_File_E_ISDIR:// Is a directory<p>
- eReturn = IOErrorCode_INVALID_ACCESS;
- break;
- case osl_File_E_NOTDIR:// Not a directory<br>
- eReturn = IOErrorCode_NO_DIRECTORY;
- break;
- case osl_File_E_NXIO:// No such device or address<br>
- eReturn = IOErrorCode_INVALID_DEVICE;
- break;
- case osl_File_E_NODEV:// No such device<br>
- eReturn = IOErrorCode_INVALID_DEVICE;
- break;
- case osl_File_E_ROFS:// Read-only file system<br>
- eReturn = IOErrorCode_ACCESS_DENIED;
- break;
- case osl_File_E_FAULT:// Bad address<br>
- eReturn = IOErrorCode_INVALID_DEVICE;
- break;
- case osl_File_E_LOOP:// Too many symbolic links encountered<br>
- break;
- case osl_File_E_MFILE:// too many open files used by the process<br>
- break;
- case osl_File_E_NFILE:// too many open files in the system<br>
- break;
- case osl_File_E_EXIST:// File exists<br>
- eReturn = IOErrorCode_CANT_CREATE;
- break;
- case osl_File_E_MULTIHOP:// Multihop attempted<br>
- break;
- case osl_File_E_FBIG:// File too large<br>
- eReturn = IOErrorCode_INVALID_LENGTH;
- break;
-
- // write
- case osl_File_E_AGAIN:// Operation would block<br>
- break;
- case osl_File_E_NOLCK:// No record locks available<br>
- break;
- case osl_File_E_NOSPC:// No space left on device<br>
- eReturn = IOErrorCode_OUT_OF_DISK_SPACE;
- break;
- case osl_File_E_INVAL:// the format of the parameters was not valid<p>
- eReturn = IOErrorCode_INVALID_PARAMETER;
- break;
-
- // close
- case osl_File_E_BADF:// Bad file<br>
- eReturn = IOErrorCode_NO_FILE;
- break;
- case osl_File_E_INTR:// function call was interrupted<br>
- eReturn = IOErrorCode_ABORT;
- break;
- case osl_File_E_NOLINK:// Link has been severed<br>
- break;
- case osl_File_E_IO:// I/O error<p>
- eReturn = IOErrorCode_GENERAL;
- break;
- }
- return eReturn;
-}
-
-sal_Bool ZipPackage::HandleError ( Any &rAny, sal_uInt16 eContinuations )
-{
- InteractionRequest* pRequest;
- Reference < XInteractionRequest > xRequest ( pRequest = new InteractionRequest ( rAny, eContinuations ));
- xInteractionHandler->handle ( xRequest );
- const sal_uInt16 nSelection = pRequest->getSelection();
- return nSelection == EC_YES || nSelection == EC_RETRY;
-}
-
-sal_Bool ZipPackage::HandleError ( oslFileError aRC, sal_uInt16 eContinuations, const OUString &rFileName )
-{
- Any aAny;
- InteractiveAugmentedIOException aException;
- aException.Code = Impl_OSLFileErrorToUCBIoErrorCode ( aRC );
- aException.Arguments.realloc ( 1 );
- PropertyValue aProperty;
- aProperty.Name = OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Uri" ) );
- aProperty.Handle = static_cast < sal_Int32 > ( -1 );
- aProperty.Value <<= rFileName;
- aException.Arguments[0] <<= aProperty;
- aAny <<= aException;
- return HandleError (aAny, eContinuations );
-}
-
-void ZipPackage::unSpanFile ( )
-{
- const OUString sServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.io.TempFile" ) );
- Reference < XInputStream > xTempIn = Reference < XInputStream > ( xFactory->createInstance ( sServiceName ), UNO_QUERY );
- Reference < XOutputStream > xTempOut = Reference < XOutputStream > ( xTempIn, UNO_QUERY );
- Reference < XSeekable > xTempSeek = Reference < XSeekable > ( xTempIn, UNO_QUERY );
-
-#ifdef MTG_DEBUG
- fprintf ( stderr, "MTG: unspanning %s\n", ImplGetChars ( sURL ) );
-#endif
- Sequence < sal_Int8 > aBuffer;
- sal_Int64 nRead;
- xContentSeek->seek ( 0 );
- do
- {
- nRead = xContentStream->readBytes ( aBuffer, n_ConstBufferSize );
- xTempOut->writeBytes ( aBuffer );
- }
- while ( nRead == n_ConstBufferSize );
-
- // Clear the references to the first segment so that we can unmount the disk
- xContentStream = xTempIn;
- xContentSeek = xTempSeek;
-
- // Check if the buffer just read is the last one
- if ( checkEnd ( aBuffer ) )
- return;
-
- sal_Int16 nDiskNum = 1;
- VolumeInfo aInfo ( osl_VolumeInfo_Mask_FreeSpace | osl_VolumeInfo_Mask_DeviceHandle | osl_VolumeInfo_Mask_Attributes );
- FileBase::RC aRC = Directory::getVolumeInfo ( sURL, aInfo );
-#ifdef MTG_DEBUG
- fprintf ( stderr, "GetVolumeInfo returned %d\n", aRC );
-#endif
- VolumeDevice aDevice = aInfo.getDeviceHandle();
- sal_Bool bIsRemovable = aInfo.getRemoveableFlag();
-#ifdef MTG_DEBUG
- fprintf ( stderr, "isRemovable is %d\n", bIsRemovable );
-#endif
-
- sal_Int32 nLastSlash = sURL.lastIndexOf ( '/' );
- OUString sFileName, sMountPath = aDevice.getMountPath();
-#ifdef MTG_DEBUG
- fprintf ( stderr, "mountpath is %s\n", ImplGetChars ( sMountPath ) );
-#endif
- const OUString sFilePrefix = sURL.copy ( 1 + nLastSlash, sURL.lastIndexOf ( '.' ) - nLastSlash );
- SegmentEnum eRet = e_Finished;
- SuffixGenerator aGenerator;
- do
- {
- //pBuffer->nextSegment( ++nDiskNum);
- nDiskNum++;
- aGenerator.generateFileName ( sFileName, sFilePrefix, nDiskNum );
- if ( bIsRemovable )
- {
- // We need an interaction handler to request disks
- getInteractionHandler();
- if ( RequestDisk( sMountPath, nDiskNum ) < 0 )
- return;
-#ifdef MTG_DEBUG
- fprintf ( stderr, "unSpanFile calling readSegment on disk number %d (mount path is %s )\n", nDiskNum, ImplGetChars ( sMountPath ) );
-#endif
- eRet = readSegment ( sFileName, sMountPath, xTempOut, nDiskNum );
- if (eRet == e_Aborted)
- return;
- }
- else
- {
- OUString sFullPath = sURL.copy ( 0, nLastSlash + 1 ) + sFileName;
- Reference < XInputStream > xStream;
- Content aContent (sFullPath, Reference < XCommandEnvironment >() );
- Reference < XActiveDataSink > xSink = new ZipPackageSink;
- try
- {
- if (aContent.openStream ( xSink ) )
- xStream = xSink->getInputStream();
- if ( xStream.is() )
- {
- do
- {
- nRead = xStream->readBytes ( aBuffer, n_ConstBufferSize );
- xTempOut->writeBytes ( aBuffer );
- }
- while ( nRead == n_ConstBufferSize );
- eRet = checkEnd ( aBuffer ) ? e_Finished : e_Success;
- }
- }
- catch (com::sun::star::uno::Exception&)
- {
- // bad juju
- //
- }
- }
- }
- while ( eRet != e_Finished );
-}
-
-sal_Bool ZipPackage::checkEnd ( Sequence < sal_Int8 > &rSequence )
-{
- sal_Int32 nLength, nPos, nEnd;
-
- nLength = static_cast <sal_Int32 > (rSequence.getLength());
- // Start at what should be the beginning of the end header
- if ( nLength == 0 || nLength < ENDHDR )
- return sal_False;
- nPos = nLength - ENDHDR - ZIP_MAXNAMELEN;
- // We'll only look for the END signature within a sane range (ZIP_MAXNAMELEN)
- nEnd = nPos >= 0 ? nPos : 0;
-
- const sal_Int8 *pBuffer = rSequence.getConstArray();
- nPos = nLength - ENDHDR;
- while ( nPos >= nEnd )
- {
- if (pBuffer[nPos] == 'P' && pBuffer[nPos+1] == 'K' && pBuffer[nPos+2] == 5 && pBuffer[nPos+3] == 6 )
- return sal_True;
- nPos--;
- }
- return sal_False;
-}
-sal_Int32 ZipPackage::RequestDisk ( OUString &rMountPath, sal_Int16 nDiskNum)
-{
- VolumeInfo aInfo ( osl_VolumeInfo_Mask_FreeSpace | osl_VolumeInfo_Mask_DeviceHandle | osl_VolumeInfo_Mask_Attributes );
- VolumeDevice aDevice;
- FileBase::RC aRC;
-
- do
- {
- aRC = Directory::getVolumeInfo ( rMountPath, aInfo );
-#ifdef MTG_DEBUG
- fprintf ( stderr, "MTG: Requesting disk for %s, result is %d\n", ImplGetChars ( rMountPath ), aRC );
-#endif
- if ( aRC == FileBase::E_None )
- aDevice = aInfo.getDeviceHandle();
- else
- {
-#ifdef MTG_DEBUG
- fprintf ( stderr, "MTG: Requesting disk calling HandleError with osl_File_E_INVAL\n" );
-#endif
- if ( ! HandleError ( (oslFileError) aRC, EC_RETRY|EC_ABORT, rMountPath) )
- return -1;
- }
- }
- while ( aRC != FileBase::E_None );
-#ifdef UNX
- do
- {
- aRC = aDevice.unmount();
-#ifdef MTG_DEBUG
- fprintf ( stderr, "MTG: unmount returned %d\n", aRC );
-#endif
- if ( aRC != FileBase::E_None )
- {
- if ( ! HandleError ( (oslFileError) aRC, EC_RETRY|EC_ABORT, rMountPath) )
- return -1;
- }
- }
- while ( aRC != FileBase::E_None );
-#endif
-
- Any aExceptionAny, aMediumException;
- InteractiveWrongMediumException aException;
- aMediumException <<= static_cast < sal_Int16 > (nDiskNum-1);
- aException.Medium = aMediumException;
- aExceptionAny <<= aException;
- if ( !HandleError ( aExceptionAny, EC_YES|EC_ABORT ) )
- return -1;
-#ifdef UNX
- do
- {
- aRC = aDevice.automount();
-
-#ifdef MTG_DEBUG
- fprintf ( stderr, "MTG: automount returned %d\n", aRC );
-#endif
- if ( aRC != FileBase::E_None )
- {
- if ( ! HandleError ( (oslFileError) aRC, EC_RETRY|EC_ABORT, rMountPath) )
- return -1;
- }
- }
- while ( aRC != FileBase::E_None );
- OUString aNewMountPath ( aDevice.getMountPath() );
-
- if (aNewMountPath != rMountPath)
- rMountPath = aNewMountPath;
-#ifdef MTG_DEBUG
- fprintf ( stderr, "MTG: returning, new mountpath is %s\n", ImplGetChars ( rMountPath ) );
-#endif
-#endif
- return FileBase::E_None;
-}
-SegmentEnum ZipPackage::writeSegment ( const OUString &rFileName, OUString &rMountPath, Reference < XInputStream > &xInBuffer, const sal_Int16 nDiskNum )
-{
- File *pFile = NULL;
- FileBase::RC aRC;
- sal_Bool bDynamicSpan = nSegmentSize < 0;
- Sequence < sal_Int8 > aBuffer;
-
- sal_Int32 nRead = n_ConstBufferSize;
- sal_uInt64 nLeft, nWritten;
- VolumeInfo aInfo ( osl_VolumeInfo_Mask_FreeSpace | osl_VolumeInfo_Mask_DeviceHandle | osl_VolumeInfo_Mask_Attributes );
-
-#ifdef MTG_DEBUG
- fprintf (stderr, "MTG: In writeSegment, disk num is %d, file is %s, dir is %s\n",
- nDiskNum, ImplGetChars(rFileName), ImplGetChars(rMountPath));
-#endif
- do
- {
- aRC = Directory::getVolumeInfo ( rMountPath, aInfo );
-#ifdef MTG_DEBUG
- fprintf(stderr, "MTG: getVolumeInfo returned %d\n", aRC );
-#endif
- // return value is not useful, so we check if we have valid attributes instead
- if ( aInfo.isValid ( osl_VolumeInfo_Mask_FreeSpace) )
- {
- sal_Bool bReCheck;
- OUStringBuffer aBuffer;
- aBuffer.append ( rMountPath );
- if ( rMountPath.lastIndexOf ( '/' ) != rMountPath.getLength()-1 )
- aBuffer.appendAscii ( "/" );
- aBuffer.append ( rFileName );
- OUString sFullPath ( aBuffer.makeStringAndClear() );
- do
- {
- bReCheck = sal_False;
- sal_uInt64 nFree = aInfo.getFreeSpace();
-#ifdef MTG_DEBUG
- fprintf(stderr, "MTG: free is %d\n", static_cast < sal_Int32 > ( nFree ) );
-#endif
- if ( ( bDynamicSpan && nFree < 1000 ) ||
- ( !bDynamicSpan && nFree < nSegmentSize ) )
- {
- if ( !HandleError ( osl_File_E_NOSPC, EC_RETRY|EC_ABORT, sFullPath ) )
- {
- if ( pFile )
- delete pFile;
- return e_Aborted;
- }
- else
- {
- aRC = Directory::getVolumeInfo ( rMountPath, aInfo );
- bReCheck = sal_True;
- }
- }
- else
- {
- nLeft = bDynamicSpan ? nFree : nSegmentSize;
-#ifdef MTG_DEBUG
- fprintf(stderr, "MTG: left is %ld\n", static_cast < sal_Int32 > ( nLeft ) );
-#endif
- }
- }
- while ( bReCheck );
-#ifdef MTG_DEBUG
- fprintf( stderr, "MTG: sDirectoryName is %s sFileName is %s FullPath is %s\n",
- ImplGetChars ( rMountPath ), ImplGetChars ( rFileName ), ImplGetChars ( sFullPath ) );
-#endif
- pFile = new File ( sFullPath );
- sal_Bool bExists = sal_False;
- aRC = pFile->open ( osl_File_OpenFlag_Create | osl_File_OpenFlag_Write );
- if ( aRC == FileBase::E_EXIST )
- {
- aRC = pFile->open ( osl_File_OpenFlag_Write );
- bExists = sal_True;
- }
- if ( aRC != FileBase::E_None )
- {
-#ifdef MTG_DEBUG
- fprintf(stderr, "MTG: file open returned %d\n", aRC );
-#endif
- if ( ! HandleError ( (oslFileError) aRC, EC_RETRY|EC_ABORT, sFullPath ) )
- {
- delete pFile;
- return e_Aborted;
- }
- }
- else if ( bExists )
- {
- // Truncate to 0 if necessary
- aRC = pFile->setSize ( 0 );
- }
- }
- else
- {
- aRC = FileBase::E_IO;
- if ( ! HandleError ( (oslFileError) aRC, EC_RETRY|EC_ABORT, rMountPath ) )
- return e_Aborted;
- }
- }
- while (aRC != FileBase::E_None );
-
- // Now! We should have an open file on a disk which has at least nSegmentSize if not
- // dynamic spanning and 1000 bytes if dynamic spanning.
-
-
- // Let's read it all into the buffer in case something goes wrong and also
- // so that the spannable checks in ByteChucker and ZipOutputStream work
-
- nRead = xInBuffer->readBytes ( aBuffer, static_cast < sal_Int32 > ( nLeft ) );
-
- aRC = pFile->write ( aBuffer.getConstArray(), nRead, nWritten );
-#ifdef MTG_DEBUG
- fprintf ( stderr, "MTG: write returned %d\n", aRC );
-#endif
-
- sal_Bool bRetry = sal_False;
-
- if ( nWritten != nRead || aRC != FileBase::E_None )
- bRetry = sal_True;
- else
- {
- aRC = pFile->close ();
-#ifdef MTG_DEBUG
- fprintf ( stderr, "MTG: close returned %d\n", aRC );
-#endif
- if ( aRC != FileBase::E_None )
- bRetry = sal_True;
- }
- delete pFile;
- return nRead < nLeft ? e_Finished : bRetry ? e_Retry : e_Success;
-}
-
-SegmentEnum ZipPackage::writeSegment ( const OUString &rFileName, Reference < XInputStream > &xInBuffer )
-{
- FileBase::RC aRC;
- Sequence < sal_Int8 > aBuffer ( nSegmentSize );
-
- sal_uInt64 nWritten;
-
- sal_Int32 nRead = xInBuffer->readBytes ( aBuffer, static_cast < sal_Int32 > ( nSegmentSize ) );
-
- File aFile ( rFileName );
- aRC = aFile.open ( osl_File_OpenFlag_Create | osl_File_OpenFlag_Write );
- sal_Bool bExists = sal_False;
- if ( aRC == FileBase::E_EXIST )
- {
- aRC = aFile.open ( osl_File_OpenFlag_Write );
- bExists = sal_True;
- }
- if ( aRC != FileBase::E_None )
- {
- if ( ! HandleError ( (oslFileError) aRC, EC_RETRY|EC_ABORT, rFileName ) )
- return e_Aborted;
- }
- else if ( bExists )
- {
- // truncate if necessary
- aFile.setSize ( 0 );
- }
-
- aRC = aFile.write ( aBuffer.getConstArray(), nRead, nWritten );
-#ifdef MTG_DEBUG
- fprintf ( stderr, "MTG: write returned %d\n", aRC );
-#endif
-
- sal_Bool bRetry = sal_False;
- if ( nWritten != nRead || aRC != FileBase::E_None )
- bRetry = sal_True;
- else
- {
- aRC = aFile.close ();
-#ifdef MTG_DEBUG
- fprintf ( stderr, "MTG: close returned %d\n", aRC );
-#endif
- if ( aRC != FileBase::E_None )
- bRetry = sal_True;
- }
- return nRead < nSegmentSize ? e_Finished : bRetry ? e_Retry : e_Success;
-}
-
-SegmentEnum ZipPackage::readSegment ( const OUString &rFileName, OUString &rMountPath, Reference < XOutputStream > &xTempOut, const sal_Int16 nDiskNum )
-{
- File *pFile = NULL;
- FileBase::RC aRC;
- SegmentEnum eRet;
-
- OUStringBuffer aStringBuffer;
- aStringBuffer.append ( rMountPath );
- if ( rMountPath.lastIndexOf ( '/' ) != rMountPath.getLength()-1 )
- aStringBuffer.appendAscii ( "/" );
- aStringBuffer.append ( rFileName );
- OUString sFullPath ( aStringBuffer.makeStringAndClear() );
-
-#ifdef MTG_DEBUG
- fprintf ( stderr, "MTG: trying to read %s\n", ImplGetChars ( sFullPath ) );
-#endif
- DirectoryItem aItem;
- do
- {
- aRC = DirectoryItem::get ( sFullPath, aItem );
-#ifdef MTG_DEBUG
- fprintf ( stderr, "MTG: DirectoryItem::get returned %d\n", aRC );
-#endif
- if ( aRC != FileBase::E_None && !HandleError ( (oslFileError) aRC, EC_RETRY|EC_ABORT, sFullPath ) )
- return e_Aborted;
- }
- while (aRC != FileBase::E_None );
- do
- {
- pFile = new File ( sFullPath );
- aRC = pFile->open ( osl_File_OpenFlag_Read );
-#ifdef MTG_DEBUG
- fprintf ( stderr, "MTG:file open returned %d\n", aRC );
-#endif
- if ( aRC != FileBase::E_None )
- {
- delete pFile;
- if ( ! HandleError ( (oslFileError) aRC, EC_RETRY|EC_ABORT, sFullPath ) )
- return e_Aborted;
- }
- }
- while (aRC != FileBase::E_None );
-
- FileStatus aStatus ( FileStatusMask_FileSize );
- aItem.getFileStatus ( aStatus );
- sal_uInt64 nRead, nLeft = aStatus.getFileSize(), nToRead;
-
- Sequence < sal_Int8 > aBuffer ( n_ConstBufferSize );
- do
- {
- nToRead = nLeft < n_ConstBufferSize ? nLeft : n_ConstBufferSize;
- aRC = pFile->read ( static_cast < void* > ( aBuffer.getArray() ), nToRead, nRead );
-#ifdef MTG_DEBUG
- fprintf ( stderr, "MTG:file read returned %d\n", aRC );
-#endif
- if ( aRC != FileBase::E_None )
- {
- if ( ! HandleError ( (oslFileError) aRC, EC_RETRY|EC_ABORT, sFullPath ) )
- return e_Aborted;
- }
- else
- {
- Sequence < sal_Int8 > aReadBuf ( aBuffer.getConstArray(), static_cast < sal_Int32 > ( nRead ) );
- nLeft -= nRead;
- xTempOut->writeBytes ( aReadBuf );
- if (nLeft == 0)
- eRet = checkEnd ( aReadBuf ) ? e_Finished : e_Success;
- }
- }
- while (nLeft > 0 );
-
- aRC = pFile->close ();
- delete pFile;
- return eRet;
-}