diff options
author | Mathias Bauer <mba@openoffice.org> | 2000-11-20 11:55:09 +0000 |
---|---|---|
committer | Mathias Bauer <mba@openoffice.org> | 2000-11-20 11:55:09 +0000 |
commit | 066f06e8cab65ff100d0986565c0884474999f1e (patch) | |
tree | 2f6dc14983ba1dd00a60f50120abfdf7f390a193 | |
parent | e38e55fdd04345aaf0a85ad41f8a7940d99f30f8 (diff) |
#80466#: new abstract base class for class Storage to support new JAR storages
-rw-r--r-- | sot/inc/stg.hxx | 335 | ||||
-rw-r--r-- | sot/source/sdstor/stg.cxx | 236 | ||||
-rw-r--r-- | sot/source/sdstor/storage.cxx | 92 |
3 files changed, 488 insertions, 175 deletions
diff --git a/sot/inc/stg.hxx b/sot/inc/stg.hxx index 4a823d6b47fe..0252d762e5f0 100644 --- a/sot/inc/stg.hxx +++ b/sot/inc/stg.hxx @@ -2,9 +2,9 @@ * * $RCSfile: stg.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: mba $ $Date: 2000-10-16 14:05:36 $ + * last change: $Author: mba $ $Date: 2000-11-20 12:53:40 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -62,7 +62,9 @@ #ifndef _STG_HXX #define _STG_HXX - +#ifndef _RTTI_HXX //autogen +#include <tools/rtti.hxx> +#endif #ifndef _TOOLS_STREAM_HXX //autogen #include <tools/stream.hxx> #endif @@ -76,106 +78,265 @@ class StgIo; class StgDirEntry; class StgStrm; class SvGlobalName; +struct ClsId; -class StorageBase // common helper class +class StorageBase : public SvRefBase { protected: - StgIo* pIo; // I/O subsystem - StgDirEntry* pEntry; // the dir entry - ULONG nError; // error code - StreamMode nMode; // open mode - BOOL bAutoCommit; - StorageBase( StgIo*, StgDirEntry* ); - ~StorageBase(); - BOOL Validate( BOOL=FALSE ) const; - BOOL ValidateMode( StreamMode, StgDirEntry* ) const; + ULONG nError; // error code + StreamMode nMode; // open mode + BOOL bAutoCommit; + StorageBase(); + virtual ~StorageBase(); public: - void ResetError() const; - void SetError( ULONG ) const; - ULONG GetError() const; - BOOL Good() const { return BOOL( nError == SVSTREAM_OK ); } - StreamMode GetMode() const { return nMode; } - const SvStream* GetSvStream() const; + TYPEINFO(); + virtual const SvStream* GetSvStream() const = 0; + virtual BOOL Validate( BOOL=FALSE ) const = 0; + virtual BOOL ValidateMode( StreamMode ) const = 0; + void ResetError() const; + void SetError( ULONG ) const; + ULONG GetError() const; + BOOL Good() const { return BOOL( nError == SVSTREAM_OK ); } + StreamMode GetMode() const { return nMode; } }; -class StorageStream : public StorageBase +class BaseStorageStream : public StorageBase { - friend class Storage; // for the following ctor - ULONG nPos; // current position - StorageStream( StgIo*, StgDirEntry*, StreamMode ); public: - ~StorageStream(); - ULONG Read( void * pData, ULONG nSize ); - ULONG Write( const void* pData, ULONG nSize ); - ULONG Seek( ULONG nPos ); - ULONG Tell() { return nPos; } - void Flush(); - BOOL SetSize( ULONG nNewSize ); - BOOL CopyTo( StorageStream * pDestStm ); - BOOL Commit(); - BOOL Revert(); + TYPEINFO(); + virtual ULONG Read( void * pData, ULONG nSize ) = 0; + virtual ULONG Write( const void* pData, ULONG nSize ) = 0; + virtual ULONG Seek( ULONG nPos ) = 0; + virtual ULONG Tell() = 0; + virtual void Flush() = 0; + virtual BOOL SetSize( ULONG nNewSize ) = 0; + virtual BOOL CopyTo( BaseStorageStream * pDestStm ) = 0; + virtual BOOL Commit() = 0; + virtual BOOL Revert() = 0; + virtual BOOL Equals( const BaseStorageStream& rStream ) const = 0; }; class SvStorageInfoList; +class BaseStorage : public StorageBase +{ +public: + TYPEINFO(); + virtual const String& GetName() const = 0; + virtual BOOL IsRoot() const = 0; + virtual void SetClassId( const ClsId& ) = 0; + virtual const ClsId& GetClassId() const = 0; + virtual void SetDirty() = 0; + virtual void SetClass( const SvGlobalName & rClass, + ULONG nOriginalClipFormat, + const String & rUserTypeName ) = 0; + virtual void SetConvertClass( const SvGlobalName & rConvertClass, + ULONG nOriginalClipFormat, + const String & rUserTypeName ) = 0; + virtual SvGlobalName GetClassName() = 0; + virtual ULONG GetFormat() = 0; + virtual String GetUserName() = 0; + virtual BOOL ShouldConvert() = 0; + virtual void FillInfoList( SvStorageInfoList* ) const = 0; + virtual BOOL CopyTo( BaseStorage* pDestStg ) const = 0; + virtual BOOL Commit() = 0; + virtual BOOL Revert() = 0; + virtual BaseStorageStream* OpenStream( const String & rEleName, + StreamMode = STREAM_STD_READWRITE, + BOOL bDirect = TRUE ) = 0; + virtual BaseStorage* OpenStorage( const String & rEleName, + StreamMode = STREAM_STD_READWRITE, + BOOL bDirect = FALSE ) = 0; + virtual BOOL IsStream( const String& rEleName ) const = 0; + virtual BOOL IsStorage( const String& rEleName ) const = 0; + virtual BOOL IsContained( const String& rEleName ) const = 0; + virtual BOOL Remove( const String & rEleName ) = 0; + virtual BOOL Rename( const String & rEleName, const String & rNewName ) = 0; + virtual BOOL CopyTo( const String & rEleName, BaseStorage * pDest, const String & rNewName ) = 0; + virtual BOOL MoveTo( const String & rEleName, BaseStorage * pDest, const String & rNewName ) = 0; + virtual BOOL ValidateFAT() = 0; + virtual BOOL Equals( const BaseStorage& rStream ) const = 0; +}; + +class OLEStorageBase +{ +protected: + StreamMode& nStreamMode; // open mode + StgIo* pIo; // I/O subsystem + StgDirEntry* pEntry; // the dir entry + OLEStorageBase( StgIo*, StgDirEntry*, StreamMode& ); + ~OLEStorageBase(); + BOOL Validate_Impl( BOOL=FALSE ) const; + BOOL ValidateMode_Impl( StreamMode, StgDirEntry* p = NULL ) const ; + const SvStream* GetSvStream_Impl() const; +public: +}; + +class StorageStream : public BaseStorageStream, public OLEStorageBase +{ +friend class Storage; + ULONG nPos; // current position + StorageStream( StgIo*, StgDirEntry*, StreamMode ); +public: + TYPEINFO(); + ~StorageStream(); + virtual ULONG Read( void * pData, ULONG nSize ); + virtual ULONG Write( const void* pData, ULONG nSize ); + virtual ULONG Seek( ULONG nPos ); + virtual ULONG Tell() { return nPos; } + virtual void Flush(); + virtual BOOL SetSize( ULONG nNewSize ); + virtual BOOL CopyTo( BaseStorageStream * pDestStm ); + virtual BOOL Commit(); + virtual BOOL Revert(); + virtual BOOL Validate( BOOL=FALSE ) const; + virtual BOOL ValidateMode( StreamMode ) const; + BOOL ValidateMode( StreamMode, StgDirEntry* p ) const; + const SvStream* GetSvStream() const; + virtual BOOL Equals( const BaseStorageStream& rStream ) const; +}; + +class UCBStorageStream_Impl; +class UCBStorageStream : public BaseStorageStream +{ +friend class UCBStorage; -class Storage : public StorageBase + UCBStorageStream_Impl* pImp; + +public: + TYPEINFO(); + UCBStorageStream( const String& rName, StreamMode nMode ); + UCBStorageStream( UCBStorageStream_Impl* ); + ~UCBStorageStream(); + + virtual ULONG Read( void * pData, ULONG nSize ); + virtual ULONG Write( const void* pData, ULONG nSize ); + virtual ULONG Seek( ULONG nPos ); + virtual ULONG Tell(); + virtual void Flush(); + virtual BOOL SetSize( ULONG nNewSize ); + virtual BOOL CopyTo( BaseStorageStream * pDestStm ); + virtual BOOL Commit(); + virtual BOOL Revert(); + virtual BOOL Validate( BOOL=FALSE ) const; + virtual BOOL ValidateMode( StreamMode ) const; + const SvStream* GetSvStream() const; + virtual BOOL Equals( const BaseStorageStream& rStream ) const; +}; + +class Storage : public BaseStorage, public OLEStorageBase { - String aName; - BOOL bIsRoot; // TRUE if root storage - void Init( BOOL bCreate ); - Storage( StgIo*, StgDirEntry*, StreamMode ); + String aName; + BOOL bIsRoot; + void Init( BOOL bCreate ); + Storage( StgIo*, StgDirEntry*, StreamMode ); public: - Storage( const String &, - StreamMode = STREAM_STD_READWRITE, - BOOL bDirect = TRUE ); - Storage( SvStream& rStrm, - BOOL bDirect = TRUE ); - ~Storage(); - static BOOL IsStorageFile( const String & rFileName ); - static BOOL IsStorageFile( SvStream* ); - const String& GetName() const; - BOOL IsRoot() const { return bIsRoot; } - - // eigener Datenbereich - void SetClass( const SvGlobalName & rClass, - ULONG nOriginalClipFormat, - const String & rUserTypeName ); - void SetConvertClass( const SvGlobalName & rConvertClass, - ULONG nOriginalClipFormat, - const String & rUserTypeName ); - SvGlobalName GetClassName();// Typ der Daten im Storage - ULONG GetFormat(); - String GetUserName(); - BOOL ShouldConvert(); - - // Liste aller Elemente - void FillInfoList( SvStorageInfoList* ) const; - BOOL CopyTo( Storage* pDestStg ) const; - BOOL Commit(); - BOOL Revert(); - /* Element Methoden */ - // Stream mit Verbindung zu Storage erzeugen, - // in etwa eine Parent-Child Beziehung - StorageStream* OpenStream( const String & rEleName, + TYPEINFO(); + Storage( const String &, StreamMode = STREAM_STD_READWRITE, BOOL bDirect = TRUE ); + Storage( SvStream& rStrm, BOOL bDirect = TRUE ); + ~Storage(); + + static BOOL IsStorageFile( const String & rFileName ); + static BOOL IsStorageFile( SvStream* ); + + virtual const String& GetName() const; + virtual BOOL IsRoot() const { return bIsRoot; } + virtual void SetClassId( const ClsId& ); + virtual const ClsId& GetClassId() const; + virtual void SetDirty(); + virtual void SetClass( const SvGlobalName & rClass, + ULONG nOriginalClipFormat, + const String & rUserTypeName ); + virtual void SetConvertClass( const SvGlobalName & rConvertClass, + ULONG nOriginalClipFormat, + const String & rUserTypeName ); + virtual SvGlobalName GetClassName(); + virtual ULONG GetFormat(); + virtual String GetUserName(); + virtual BOOL ShouldConvert(); + virtual void FillInfoList( SvStorageInfoList* ) const; + virtual BOOL CopyTo( BaseStorage* pDestStg ) const; + virtual BOOL Commit(); + virtual BOOL Revert(); + virtual BaseStorageStream* OpenStream( const String & rEleName, StreamMode = STREAM_STD_READWRITE, BOOL bDirect = TRUE ); - Storage* OpenStorage( const String & rEleName, - StreamMode = STREAM_STD_READWRITE, - BOOL bDirect = FALSE ); - // Abfrage auf Storage oder Stream - BOOL IsStream( const String& rEleName ) const; - BOOL IsStorage( const String& rEleName ) const; - BOOL IsContained( const String& rEleName ) const; - // Element loeschen - BOOL Remove( const String & rEleName ); - // Elementnamen aendern - BOOL Rename( const String & rEleName, - const String & rNewName ); - BOOL CopyTo( const String & rEleName, Storage * pDest, - const String & rNewName ); - BOOL MoveTo( const String & rEleName, Storage * pDest, - const String & rNewName ); - BOOL ValidateFAT(); + virtual BaseStorage* OpenStorage( const String & rEleName, + StreamMode = STREAM_STD_READWRITE, + BOOL bDirect = FALSE ); + virtual BOOL IsStream( const String& rEleName ) const; + virtual BOOL IsStorage( const String& rEleName ) const; + virtual BOOL IsContained( const String& rEleName ) const; + virtual BOOL Remove( const String & rEleName ); + virtual BOOL Rename( const String & rEleName, const String & rNewName ); + virtual BOOL CopyTo( const String & rEleName, BaseStorage * pDest, const String & rNewName ); + virtual BOOL MoveTo( const String & rEleName, BaseStorage * pDest, const String & rNewName ); + virtual BOOL ValidateFAT(); + virtual BOOL Validate( BOOL=FALSE ) const; + virtual BOOL ValidateMode( StreamMode ) const; + BOOL ValidateMode( StreamMode, StgDirEntry* p ) const; + virtual const SvStream* GetSvStream() const; + virtual BOOL Equals( const BaseStorage& rStream ) const; +}; + +class UCBStorage_Impl; +struct UCBStorageElement_Impl; +class UCBStorage : public BaseStorage +{ + UCBStorage_Impl* pImp; + +public: + static BOOL IsStorageFile( SvStream* ); + + UCBStorage( const String& rName, StreamMode nMode ); + UCBStorage( UCBStorage_Impl* ); + UCBStorage( SvStream& rStrm, BOOL bDirect = TRUE ); + ~UCBStorage(); + + TYPEINFO(); + virtual const String& GetName() const; + virtual BOOL IsRoot() const; + virtual void SetClassId( const ClsId& ); + virtual const ClsId& GetClassId() const; + virtual void SetDirty(); + virtual void SetClass( const SvGlobalName & rClass, + ULONG nOriginalClipFormat, + const String & rUserTypeName ); + virtual void SetConvertClass( const SvGlobalName & rConvertClass, + ULONG nOriginalClipFormat, + const String & rUserTypeName ); + virtual SvGlobalName GetClassName(); + virtual ULONG GetFormat(); + virtual String GetUserName(); + virtual BOOL ShouldConvert(); + virtual void FillInfoList( SvStorageInfoList* ) const; + virtual BOOL CopyTo( BaseStorage* pDestStg ) const; + virtual BOOL Commit(); + virtual BOOL Revert(); + virtual BaseStorageStream* OpenStream( const String & rEleName, + StreamMode = STREAM_STD_READWRITE, + BOOL bDirect = TRUE ); + virtual BaseStorage* OpenStorage( const String & rEleName, + StreamMode = STREAM_STD_READWRITE, + BOOL bDirect = FALSE ); + virtual BOOL IsStream( const String& rEleName ) const; + virtual BOOL IsStorage( const String& rEleName ) const; + virtual BOOL IsContained( const String& rEleName ) const; + virtual BOOL Remove( const String & rEleName ); + virtual BOOL Rename( const String & rEleName, const String & rNewName ); + virtual BOOL CopyTo( const String & rEleName, BaseStorage * pDest, const String & rNewName ); + virtual BOOL MoveTo( const String & rEleName, BaseStorage * pDest, const String & rNewName ); + virtual BOOL ValidateFAT(); + virtual BOOL Validate( BOOL=FALSE ) const; + virtual BOOL ValidateMode( StreamMode ) const; + virtual const SvStream* GetSvStream() const; + virtual BOOL Equals( const BaseStorage& rStream ) const; + +#if __PRIVATE + UCBStorageElement_Impl* FindElement_Impl( const String& rName ) const; + BOOL CopyStorageElement_Impl( UCBStorageElement_Impl& rElement, + BaseStorage* pDest, const String& rNew ) const; +#endif + }; #endif diff --git a/sot/source/sdstor/stg.cxx b/sot/source/sdstor/stg.cxx index ca0d18d0dcd3..ae5313f29b22 100644 --- a/sot/source/sdstor/stg.cxx +++ b/sot/source/sdstor/stg.cxx @@ -2,9 +2,9 @@ * * $RCSfile: stg.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: mba $ $Date: 2000-10-16 14:08:34 $ + * last change: $Author: mba $ $Date: 2000-11-20 12:55:09 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -97,17 +97,58 @@ static long nTmpCount = 0; ///////////////////////// class StorageBase ////////////////////////////// -StorageBase::StorageBase( StgIo* p, StgDirEntry* pe ) - : bAutoCommit( FALSE ), pIo( p ), pEntry( pe ) +TYPEINIT0( StorageBase ); +TYPEINIT1( BaseStorageStream, StorageBase ); +TYPEINIT1( BaseStorage, StorageBase ); + +StorageBase::StorageBase() + : bAutoCommit( FALSE ) { nMode = STREAM_READ; nError = SVSTREAM_OK; +} + +StorageBase::~StorageBase() +{ +} + +// The following three methods are declared as const, since they +// may be called from within a const method. + +ULONG StorageBase::GetError() const +{ + ULONG n = nError; + ((StorageBase*) this)->nError = SVSTREAM_OK; + return n; +} + +void StorageBase::SetError( ULONG n ) const +{ + if( !nError ) + ((StorageBase*) this)->nError = n; +} + +void StorageBase::ResetError() const +{ + ((StorageBase*) this)->nError = SVSTREAM_OK; +} + +// Retrieve the underlying SvStream for info purposes + +const SvStream* OLEStorageBase::GetSvStream_Impl() const +{ + return pIo ? pIo->GetStrm() : NULL; +} + +OLEStorageBase::OLEStorageBase( StgIo* p, StgDirEntry* pe, StreamMode& nMode ) + : pIo( p ), pEntry( pe ), nStreamMode( nMode ) +{ p->IncRef(); if( pe ) pe->nRefCnt++; } -StorageBase::~StorageBase() +OLEStorageBase::~OLEStorageBase() { if( pEntry ) { @@ -128,19 +169,16 @@ StorageBase::~StorageBase() // Validate the instance for I/O -BOOL StorageBase::Validate( BOOL bWrite ) const +BOOL OLEStorageBase::Validate_Impl( BOOL bWrite ) const { if( pEntry && !pEntry->bInvalid - && ( !bWrite || !pEntry->bDirect || ( nMode & STREAM_WRITE ) ) ) + && ( !bWrite || !pEntry->bDirect || ( nStreamMode & STREAM_WRITE ) ) ) return TRUE; - SetError( SVSTREAM_ACCESS_DENIED ); return FALSE; } -// Check the given share flags against the current flags - -BOOL StorageBase::ValidateMode( StreamMode m, StgDirEntry* p ) const +BOOL OLEStorageBase::ValidateMode_Impl( StreamMode m, StgDirEntry* p ) const { if( m == INTERNAL_MODE ) return TRUE; @@ -163,42 +201,16 @@ BOOL StorageBase::ValidateMode( StreamMode m, StgDirEntry* p ) const && ( nCurMode & STREAM_SHARE_DENYALL ) ) return TRUE; } - SetError( SVSTREAM_ACCESS_DENIED ); return FALSE; } -// The following three methods are declared as const, since they -// may be called from within a const method. - -ULONG StorageBase::GetError() const -{ - ULONG n = nError; - ((StorageBase*) this)->nError = SVSTREAM_OK; - return n; -} - -void StorageBase::SetError( ULONG n ) const -{ - if( !nError ) - ((StorageBase*) this)->nError = n; -} - -void StorageBase::ResetError() const -{ - ((StorageBase*) this)->nError = SVSTREAM_OK; -} - -// Retrieve the underlying SvStream for info purposes - -const SvStream* StorageBase::GetSvStream() const -{ - return pIo ? pIo->GetStrm() : NULL; -} //////////////////////// class StorageStream ///////////////////////////// +TYPEINIT1( StorageStream, BaseStorageStream ); + StorageStream::StorageStream( StgIo* p, StgDirEntry* q, StreamMode m ) - : StorageBase( p, q ), nPos( 0L ) + : OLEStorageBase( p, q, nMode ), nPos( 0L ) { // The dir entry may be 0; this means that the stream is invalid. if( q ) @@ -223,6 +235,12 @@ StorageStream::~StorageStream() pEntry->Commit(); } +BOOL StorageStream::Equals( const BaseStorageStream& rStream ) const +{ + const StorageStream* pOther = PTR_CAST( StorageStream, &rStream ); + return pOther && ( pOther->pEntry == pEntry ); +} + ULONG StorageStream::Read( void* pData, ULONG nSize ) { if( Validate() ) @@ -301,17 +319,46 @@ BOOL StorageStream::Revert() return Good(); } -BOOL StorageStream::CopyTo( StorageStream* pDest ) +BOOL StorageStream::CopyTo( BaseStorageStream* pDest ) { - if( !Validate() || !pDest->Validate( TRUE ) || pEntry == pDest->pEntry ) + if( !Validate() || !pDest->Validate( TRUE ) || Equals( *pDest ) ) return FALSE; - pEntry->Copy( *pDest->pEntry ); + pEntry->Copy( *pDest ); pDest->Commit(); pIo->MoveError( *this ); SetError( pDest->GetError() ); return BOOL( Good() && pDest->Good() ); } +const SvStream* StorageStream::GetSvStream() const +{ + return GetSvStream_Impl(); +} + +BOOL StorageStream::Validate( BOOL bValidate ) const +{ + BOOL bRet = Validate_Impl( bValidate ); + if ( !bRet ) + SetError( SVSTREAM_ACCESS_DENIED ); + return bRet; +} + +BOOL StorageStream::ValidateMode( StreamMode nMode ) const +{ + BOOL bRet = ValidateMode_Impl( nMode, NULL ); + if ( !bRet ) + SetError( SVSTREAM_ACCESS_DENIED ); + return bRet; +} + +BOOL StorageStream::ValidateMode( StreamMode nMode, StgDirEntry* p ) const +{ + BOOL bRet = ValidateMode_Impl( nMode, p ); + if ( !bRet ) + SetError( SVSTREAM_ACCESS_DENIED ); + return bRet; +} + ///////////////////////// class SvStorageInfo ////////////////////////////// SvStorageInfo::SvStorageInfo( const StgDirEntry& rE ) @@ -341,8 +388,10 @@ BOOL Storage::IsStorageFile( SvStream* pStream ) // Open the storage file. If writing is permitted and the file is not // a storage file, initialize it. +TYPEINIT1( Storage, BaseStorage ); + Storage::Storage( const String& rFile, StreamMode m, BOOL bDirect ) - : StorageBase( new StgIo, NULL ), aName( rFile ), bIsRoot( FALSE ) + : OLEStorageBase( new StgIo, NULL, nMode ), aName( rFile ), bIsRoot( FALSE ) { BOOL bTemp = FALSE; if( !aName.Len() ) @@ -373,7 +422,7 @@ Storage::Storage( const String& rFile, StreamMode m, BOOL bDirect ) // Create a storage on a given stream. Storage::Storage( SvStream& r, BOOL bDirect ) - : StorageBase( new StgIo, NULL ), bIsRoot( FALSE ) + : OLEStorageBase( new StgIo, NULL, nMode ), bIsRoot( FALSE ) { nMode = STREAM_READ; if( r.IsWritable() ) @@ -437,13 +486,12 @@ void Storage::Init( BOOL bCreate ) // Internal ctor Storage::Storage( StgIo* p, StgDirEntry* q, StreamMode m ) - : StorageBase( p, q ), bIsRoot( FALSE ) + : OLEStorageBase( p, q, nMode ), bIsRoot( FALSE ) { if( q ) q->aEntry.GetName( aName ); else m &= ~STREAM_READWRITE; - bIsRoot = FALSE; nMode = m; if( q && q->nRefCnt == 1 ) q->nMode = m; @@ -501,9 +549,9 @@ void Storage::FillInfoList( SvStorageInfoList* pList ) const // Open or create a substorage -Storage* Storage::OpenStorage( const String& rName, StreamMode m, BOOL bDirect ) +BaseStorage* Storage::OpenStorage( const String& rName, StreamMode m, BOOL bDirect ) { - if( !Validate() || !ValidateMode( m, NULL ) ) + if( !Validate() || !ValidateMode( m ) ) return new Storage( pIo, NULL, m ); BOOL bSetAutoCommit = FALSE; if( bDirect && !pEntry->bDirect ) @@ -558,9 +606,9 @@ Storage* Storage::OpenStorage( const String& rName, StreamMode m, BOOL bDirect ) // Open a stream -StorageStream* Storage::OpenStream( const String& rName, StreamMode m, BOOL ) +BaseStorageStream* Storage::OpenStream( const String& rName, StreamMode m, BOOL ) { - if( !Validate() || !ValidateMode( m, NULL ) ) + if( !Validate() || !ValidateMode( m ) ) return new StorageStream( pIo, NULL, m ); StgDirEntry* p = pIo->pTOC->Find( *pEntry, rName ); BOOL bTemp = FALSE; @@ -637,7 +685,7 @@ BOOL Storage::Rename( const String& rOld, const String& rNew ) // Copy one element -BOOL Storage::CopyTo( const String& rElem, Storage* pDest, const String& rNew ) +BOOL Storage::CopyTo( const String& rElem, BaseStorage* pDest, const String& rNew ) { if( !Validate() || !pDest || !pDest->Validate( TRUE ) ) return FALSE; @@ -655,10 +703,9 @@ BOOL Storage::CopyTo( const String& rElem, Storage* pDest, const String& rNew ) if( pElem->aEntry.GetType() == STG_STORAGE ) { // copy the entire storage - Storage* p1 = OpenStorage( rElem, INTERNAL_MODE ); - Storage* p2 = pDest->OpenStorage - ( rNew, STREAM_WRITE | STREAM_SHARE_DENYALL, pEntry->bDirect ); - p2->pEntry->aEntry.SetClassId( p1->pEntry->aEntry.GetClassId() ); + BaseStorage* p1 = OpenStorage( rElem, INTERNAL_MODE ); + BaseStorage* p2 = pDest->OpenStorage( rNew, STREAM_WRITE | STREAM_SHARE_DENYALL, pEntry->bDirect ); + p2->SetClassId( p1->GetClassId() ); p1->CopyTo( p2 ); SetError( p1->GetError() ); if( p2->GetError() ) @@ -672,9 +719,8 @@ BOOL Storage::CopyTo( const String& rElem, Storage* pDest, const String& rNew ) else { // stream copy - StorageStream* p1 = OpenStream( rElem, INTERNAL_MODE ); - StorageStream* p2 = pDest->OpenStream - ( rNew, STREAM_WRITE | STREAM_SHARE_DENYALL, pEntry->bDirect ); + BaseStorageStream* p1 = OpenStream( rElem, INTERNAL_MODE ); + BaseStorageStream* p2 = pDest->OpenStream( rNew, STREAM_WRITE | STREAM_SHARE_DENYALL, pEntry->bDirect ); p1->CopyTo( p2 ); SetError( p1->GetError() ); if( p2->GetError() ) @@ -690,10 +736,9 @@ BOOL Storage::CopyTo( const String& rElem, Storage* pDest, const String& rNew ) return FALSE; } -BOOL Storage::CopyTo( Storage* pDest ) const +BOOL Storage::CopyTo( BaseStorage* pDest ) const { - if( !Validate() || !pDest || !pDest->Validate( TRUE ) - || pDest->pEntry == pEntry ) + if( !Validate() || !pDest || !pDest->Validate( TRUE ) || Equals( *pDest ) ) { SetError( SVSTREAM_ACCESS_DENIED ); return FALSE; @@ -706,8 +751,8 @@ BOOL Storage::CopyTo( Storage* pDest ) const return FALSE; } */ - pDest->pEntry->aEntry.SetClassId( pEntry->aEntry.GetClassId() ); - pDest->pEntry->SetDirty(); + pDest->SetClassId( GetClassId() ); + pDest->SetDirty(); SvStorageInfoList aList; FillInfoList( &aList ); BOOL bRes = TRUE; @@ -723,21 +768,25 @@ BOOL Storage::CopyTo( Storage* pDest ) const // Move one element -BOOL Storage::MoveTo( const String& rElem, Storage* pDest, const String& rNew ) +BOOL Storage::MoveTo( const String& rElem, BaseStorage* pDest, const String& rNew ) { - if( !Validate() || !pDest || !pDest->Validate( TRUE ) - || pDest->pEntry == pEntry ) + if( !Validate() || !pDest || !pDest->Validate( TRUE ) || Equals( *pDest ) ) { SetError( SVSTREAM_ACCESS_DENIED ); return FALSE; } + StgDirEntry* pElem = pIo->pTOC->Find( *pEntry, rElem ); if( pElem ) { // Simplest case: both storages share the same file BOOL bRes; - if( pIo == pDest->pIo && rElem == rNew ) + Storage *pOther = PTR_CAST( Storage, pDest ); + if( pOther && pIo == pOther->pIo && rElem == rNew ) { + Storage *p = (Storage*) pDest; + Storage *pDest = p; + // both storages are conventional storages, use implementation dependent code if( !pElem->IsContained( pDest->pEntry ) ) { // cyclic move @@ -928,3 +977,54 @@ BOOL Storage::ValidateFAT() return nErr == ERRCODE_NONE; } +void Storage::SetDirty() +{ + pEntry->SetDirty(); +} + +void Storage::SetClassId( const ClsId& rId ) +{ + pEntry->aEntry.SetClassId( rId ); +} + +const ClsId& Storage::GetClassId() const +{ + return pEntry->aEntry.GetClassId(); +} + +const SvStream* Storage::GetSvStream() const +{ + return GetSvStream_Impl(); +} + +BOOL Storage::Validate( BOOL bValidate ) const +{ + BOOL bRet = Validate_Impl( bValidate ); + if ( !bRet ) + SetError( SVSTREAM_ACCESS_DENIED ); + return bRet; +} + +BOOL Storage::ValidateMode( StreamMode nMode ) const +{ + BOOL bRet = ValidateMode_Impl( nMode ); + if ( !bRet ) + SetError( SVSTREAM_ACCESS_DENIED ); + return bRet; +} + +BOOL Storage::ValidateMode( StreamMode nMode, StgDirEntry* p ) const +{ + BOOL bRet = ValidateMode_Impl( nMode, p ); + if ( !bRet ) + SetError( SVSTREAM_ACCESS_DENIED ); + return bRet; +} + +BOOL Storage::Equals( const BaseStorage& rStorage ) const +{ + const Storage* pOther = PTR_CAST( Storage, &rStorage ); + return pOther && ( pOther->pEntry == pEntry ); +} + + diff --git a/sot/source/sdstor/storage.cxx b/sot/source/sdstor/storage.cxx index 6ec7506dbf8f..18a7d2145ae2 100644 --- a/sot/source/sdstor/storage.cxx +++ b/sot/source/sdstor/storage.cxx @@ -2,9 +2,9 @@ * * $RCSfile: storage.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: mba $ $Date: 2000-10-20 14:12:19 $ + * last change: $Author: mba $ $Date: 2000-11-20 12:55:09 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -64,6 +64,9 @@ #include <storinfo.hxx> #include <storage.hxx> +#ifndef _UNTOOLS_UCBSTREAMHELPER_HXX +#include <unotools/ucbstreamhelper.hxx> +#endif #ifndef _TOOLS_FSYS_HXX #include <tools/fsys.hxx> #endif @@ -71,6 +74,8 @@ #include <tools/cachestr.hxx> #endif #include <tools/debug.hxx> +#include <tools/urlobj.hxx> +#include <unotools/localfilehelper.hxx> #pragma hdrstop /************** class SotStorageStream ***********************************/ @@ -137,7 +142,7 @@ SotStorageStream::SotStorageStream( const String & rName, StreamMode nMode, DBG_ASSERT( !nStorageMode,"StorageModes ignored" ) } -SotStorageStream::SotStorageStream( StorageStream * pStm ) +SotStorageStream::SotStorageStream( BaseStorageStream * pStm ) { if( STREAM_WRITE & pStm->GetMode() ) bIsWritable = TRUE; @@ -455,39 +460,74 @@ void SotStorage::TestMemberInvariant( BOOL bPrint ) , bIsRoot( FALSE ) \ , bDelStm( FALSE ) \ , nVersion( SOFFICE_FILEFORMAT_NOW ) \ - , pTmpStg( NULL ) \ , pOwnStg( NULL ) \ , pStorStm( NULL ) SotStorage::SotStorage() INIT_SotStorage() { + // ??? What's this ??? } #define ERASEMASK ( STREAM_TRUNC | STREAM_WRITE | STREAM_SHARE_DENYALL ) -SotStorage::SotStorage( const String & rName, StreamMode nMode, - StorageMode nStorageMode ) +SotStorage::SotStorage( const String & rName, StreamMode nMode, StorageMode nStorageMode ) INIT_SotStorage() { aName = rName; // Namen merken - // Sicherheitshalber wird die Storage File geloescht, wenn - // sie neu erzeugt werden soll - if( aName.Len() && ( ( nMode & ERASEMASK ) == ERASEMASK ) ) + if( aName.Len() ) { - osl::File::remove( rName ); - } + // named storage + if( ( ( nMode & ERASEMASK ) == ERASEMASK ) ) + // ??? + osl::File::remove( rName ); + + String aURL; + INetURLObject aObj( rName ); + if ( aObj.GetProtocol() == INET_PROT_NOT_VALID ) + { + String aURL; + ::utl::LocalFileHelper::ConvertPhysicalNameToURL( rName, aURL ); + aObj.SetURL( aURL ); + } - pTmpStg = new Storage( aName, nMode, - (nStorageMode & STORAGE_TRANSACTED) ? FALSE : TRUE ); - pOwnStg = pTmpStg; - if( !aName.Len() ) + pStorStm = ::utl::UcbStreamHelper::CreateStream( aObj.GetMainURL(), nMode ); + if ( pStorStm ) + { + // try as UCBStorage, next try as OLEStorage + if ( UCBStorage::IsStorageFile( pStorStm ) ) + { + // UCBStorage always works directly on the UCB content, so discard the stream first + DELETEZ( pStorStm ); + DBG_ASSERT( (nStorageMode & STORAGE_TRANSACTED), "No direct mode supported!" ); + pOwnStg = new UCBStorage( rName, nMode ); + } + else + { + // OLEStorage can be opened with a stream + pOwnStg = new Storage( *pStorStm, (nStorageMode & STORAGE_TRANSACTED) ? FALSE : TRUE ); + bDelStm = TRUE; + } + } + else + { + pOwnStg = new Storage( rName, nMode, (nStorageMode & STORAGE_TRANSACTED) ? FALSE : TRUE ); + SetError( ERRCODE_IO_NOTSUPPORTED ); + } + } + else + { + // temporary storage + // try as UCBStorage, next try as OLEStorage ( how to check which one is desired ?! ) + pOwnStg = new Storage( rName, nMode, (nStorageMode & STORAGE_TRANSACTED) ? FALSE : TRUE ); aName = pOwnStg->GetName(); + } + ULONG nErr = pOwnStg->GetError(); SetError( nErr ); } -SotStorage::SotStorage( Storage * pStor ) +SotStorage::SotStorage( BaseStorage * pStor ) INIT_SotStorage() { aName = pStor->GetName(); // Namen merken @@ -502,14 +542,24 @@ SotStorage::SotStorage( SvStream & rStm ) INIT_SotStorage() { SetError( rStm.GetError() ); - pOwnStg = new Storage( rStm, FALSE ); + + // try as UCBStorage, next try as OLEStorage + if ( UCBStorage::IsStorageFile( pStorStm ) ) + pOwnStg = new UCBStorage( rStm, FALSE ); + else + pOwnStg = new Storage( rStm, FALSE ); } SotStorage::SotStorage( SvStream * pStm, BOOL bDelete ) INIT_SotStorage() { SetError( pStm->GetError() ); - pOwnStg = new Storage( *pStm, FALSE ); + + // try as UCBStorage, next try as OLEStorage + if ( UCBStorage::IsStorageFile( pStorStm ) ) + pOwnStg = new UCBStorage( *pStm, FALSE ); + else + pOwnStg = new Storage( *pStm, FALSE ); ULONG nError = pOwnStg->GetError(); if ( nError != SVSTREAM_OK ) @@ -559,11 +609,13 @@ SvMemoryStream * SotStorage::CreateMemoryStream() *************************************************************************/ BOOL SotStorage::IsStorageFile( const String & rFileName ) { + /** code for new storages must come first! **/ return Storage::IsStorageFile( rFileName ); } BOOL SotStorage::IsStorageFile( SvStream* pStream ) { + /** code for new storages must come first! **/ if ( pStream ) { long nPos = pStream->Tell(); @@ -778,7 +830,7 @@ SotStorageStream * SotStorage::OpenSotStream( const String & rEleName, // egal was kommt, nur exclusiv gestattet nMode |= STREAM_SHARE_DENYALL; ErrCode nE = pOwnStg->GetError(); - StorageStream * p = pOwnStg->OpenStream( rEleName, nMode, + BaseStorageStream * p = pOwnStg->OpenStream( rEleName, nMode, (nStorageMode & STORAGE_TRANSACTED) ? FALSE : TRUE ); pStm = new SotStorageStream( p ); if( !nE ) @@ -806,7 +858,7 @@ SotStorage * SotStorage::OpenSotStorage( const String & rEleName, { nMode |= STREAM_SHARE_DENYALL; ErrCode nE = pOwnStg->GetError(); - Storage * p = pOwnStg->OpenStorage( rEleName, nMode, + BaseStorage * p = pOwnStg->OpenStorage( rEleName, nMode, (nStorageMode & STORAGE_TRANSACTED) ? FALSE : TRUE ); pStor = new SotStorage( p ); if( !nE ) |