1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <sot/storinfo.hxx>
22 #include <osl/file.hxx>
23 #include <tools/tempfile.hxx>
24 #include <tools/string.hxx>
25 #include <tools/stream.hxx>
26 #include <tools/debug.hxx>
28 #include "sot/stg.hxx"
29 #include "stgelem.hxx"
30 #include "stgcache.hxx"
31 #include "stgstrms.hxx"
36 static long nTmpCount
= 0;
38 // The internal open mode is STREAM_READ | STREAM_TRUNC, which is silly
39 // by itself. It inhibits the checking of sharing modes and is used
40 // during CopyTo() and MoveTo() for opening a stream in read mode
41 // although it may be open in DENYALL mode
43 #define INTERNAL_MODE ( STREAM_READ | STREAM_TRUNC )
45 ///////////////////////// class StorageBase //////////////////////////////
47 TYPEINIT0( StorageBase
);
48 TYPEINIT1( BaseStorageStream
, StorageBase
);
49 TYPEINIT1( BaseStorage
, StorageBase
);
51 StorageBase::StorageBase()
52 : m_bAutoCommit( sal_False
)
54 m_nMode
= STREAM_READ
;
55 m_nError
= SVSTREAM_OK
;
58 StorageBase::~StorageBase()
62 // The following three methods are declared as const, since they
63 // may be called from within a const method.
65 sal_uLong
StorageBase::GetError() const
67 sal_uLong n
= m_nError
;
68 ((StorageBase
*) this)->m_nError
= SVSTREAM_OK
;
72 void StorageBase::SetError( sal_uLong n
) const
75 ((StorageBase
*) this)->m_nError
= n
;
78 void StorageBase::ResetError() const
80 ((StorageBase
*) this)->m_nError
= SVSTREAM_OK
;
83 // Retrieve the underlying SvStream for info purposes
85 const SvStream
* OLEStorageBase::GetSvStream_Impl() const
87 return pIo
? pIo
->GetStrm() : NULL
;
90 OLEStorageBase::OLEStorageBase( StgIo
* p
, StgDirEntry
* pe
, StreamMode
& nMode
)
91 : nStreamMode( nMode
), pIo( p
), pEntry( pe
)
99 OLEStorageBase::~OLEStorageBase()
103 DBG_ASSERT( pEntry
->nRefCnt
, "RefCount unter 0" );
104 if( !--pEntry
->nRefCnt
)
106 if( pEntry
->bZombie
)
116 if( pIo
&& !pIo
->DecRef() )
123 // Validate the instance for I/O
125 sal_Bool
OLEStorageBase::Validate_Impl( sal_Bool bWrite
) const
131 && ( !bWrite
|| !pEntry
->bDirect
|| ( nStreamMode
& STREAM_WRITE
) ) )
136 sal_Bool
OLEStorageBase::ValidateMode_Impl( StreamMode m
, StgDirEntry
* p
) const
138 if( m
== INTERNAL_MODE
)
140 sal_uInt16 nCurMode
= ( p
&& p
->nRefCnt
) ? p
->nMode
: 0xFFFF;
141 if( ( m
& 3 ) == STREAM_READ
)
143 // only SHARE_DENYWRITE or SHARE_DENYALL allowed
144 if( ( ( m
& STREAM_SHARE_DENYWRITE
)
145 && ( nCurMode
& STREAM_SHARE_DENYWRITE
) )
146 || ( ( m
& STREAM_SHARE_DENYALL
)
147 && ( nCurMode
& STREAM_SHARE_DENYALL
) ) )
152 // only SHARE_DENYALL allowed
153 // storages open in r/o mode are OK, since only
154 // the commit may fail
155 if( ( m
& STREAM_SHARE_DENYALL
)
156 && ( nCurMode
& STREAM_SHARE_DENYALL
) )
163 //////////////////////// class StorageStream /////////////////////////////
165 TYPEINIT1( StorageStream
, BaseStorageStream
);
167 StorageStream::StorageStream( StgIo
* p
, StgDirEntry
* q
, StreamMode m
)
168 : OLEStorageBase( p
, q
, m_nMode
), nPos( 0L )
170 // The dir entry may be 0; this means that the stream is invalid.
173 if( q
->nRefCnt
== 1 )
180 m
&= ~STREAM_READWRITE
;
184 StorageStream::~StorageStream()
186 // Do an auto-commit if the entry is open in direct mode
189 if( pEntry
&& pEntry
->nRefCnt
&& pEntry
->bDirect
&& (m_nMode
& STREAM_WRITE
) )
193 sal_Bool
StorageStream::Equals( const BaseStorageStream
& rStream
) const
195 const StorageStream
* pOther
= PTR_CAST( StorageStream
, &rStream
);
196 return pOther
&& ( pOther
->pEntry
== pEntry
);
199 sal_uLong
StorageStream::Read( void* pData
, sal_uLong nSize
)
203 pEntry
->Seek( nPos
);
204 nSize
= pEntry
->Read( pData
, (sal_Int32
) nSize
);
205 pIo
->MoveError( *this );
213 sal_uLong
StorageStream::Write( const void* pData
, sal_uLong nSize
)
215 if( Validate( sal_True
) )
217 pEntry
->Seek( nPos
);
218 nSize
= pEntry
->Write( pData
, (sal_Int32
) nSize
);
219 pIo
->MoveError( *this );
227 sal_uLong
StorageStream::Seek( sal_uLong n
)
230 return nPos
= pEntry
->Seek( n
);
235 void StorageStream::Flush()
237 // Flushing means committing, since streams are never transacted
241 sal_Bool
StorageStream::SetSize( sal_uLong nNewSize
)
243 if( Validate( sal_True
) )
245 sal_Bool b
= pEntry
->SetSize( (sal_Int32
) nNewSize
);
246 pIo
->MoveError( *this );
253 sal_uLong
StorageStream::GetSize() const
256 return pEntry
->GetSize();
260 sal_Bool
StorageStream::Commit()
264 if( !( m_nMode
& STREAM_WRITE
) )
266 SetError( SVSTREAM_ACCESS_DENIED
);
272 pIo
->MoveError( *this );
277 sal_Bool
StorageStream::Revert()
279 sal_Bool bResult
= sal_False
;
284 pIo
->MoveError( *this );
291 sal_Bool
StorageStream::CopyTo( BaseStorageStream
* pDest
)
293 if( !Validate() || !pDest
|| !pDest
->Validate( sal_True
) || Equals( *pDest
) )
295 pEntry
->Copy( *pDest
);
297 pIo
->MoveError( *this );
298 SetError( pDest
->GetError() );
299 return sal_Bool( Good() && pDest
->Good() );
302 const SvStream
* StorageStream::GetSvStream() const
304 return GetSvStream_Impl();
307 sal_Bool
StorageStream::Validate( sal_Bool bValidate
) const
309 sal_Bool bRet
= Validate_Impl( bValidate
);
311 SetError( SVSTREAM_ACCESS_DENIED
);
315 sal_Bool
StorageStream::ValidateMode( StreamMode nMode
) const
317 sal_Bool bRet
= ValidateMode_Impl( nMode
, NULL
);
319 SetError( SVSTREAM_ACCESS_DENIED
);
323 ///////////////////////// class SvStorageInfo //////////////////////////////
325 SvStorageInfo::SvStorageInfo( const StgDirEntry
& rE
)
327 rE
.aEntry
.GetName( aName
);
328 bStorage
= sal_Bool( rE
.aEntry
.GetType() == STG_STORAGE
);
329 bStream
= sal_Bool( rE
.aEntry
.GetType() == STG_STREAM
);
330 nSize
= bStorage
? 0 : rE
.aEntry
.GetSize();
333 /////////////////////////// class Storage ////////////////////////////////
335 sal_Bool
Storage::IsStorageFile( const String
& rFileName
)
338 if( aIo
.Open( rFileName
, STREAM_STD_READ
) )
343 sal_Bool
Storage::IsStorageFile( SvStream
* pStream
)
345 sal_Bool bRet
= sal_False
;
350 sal_uLong nPos
= pStream
->Tell();
351 bRet
= ( aHdr
.Load( *pStream
) && aHdr
.Check() );
353 // It's not a stream error if it is too small for a OLE storage header
354 if ( pStream
->GetErrorCode() == ERRCODE_IO_CANTSEEK
)
355 pStream
->ResetError();
356 pStream
->Seek( nPos
);
362 // Open the storage file. If writing is permitted and the file is not
363 // a storage file, initialize it.
365 TYPEINIT1( Storage
, BaseStorage
);
367 Storage::Storage( const String
& rFile
, StreamMode m
, sal_Bool bDirect
)
368 : OLEStorageBase( new StgIo
, NULL
, m_nMode
), aName( rFile
), bIsRoot( sal_False
)
370 sal_Bool bTemp
= sal_False
;
373 // no name = temporary name!
374 aName
= TempFile::CreateTempName();
377 // the root storage creates the I/O system
379 if( pIo
->Open( aName
, m
) )
381 Init( sal_Bool( ( m
& ( STREAM_TRUNC
| STREAM_NOCREATE
) ) == STREAM_TRUNC
) );
384 pEntry
->bDirect
= bDirect
;
386 pEntry
->bTemp
= bTemp
;
391 pIo
->MoveError( *this );
396 // Create a storage on a given stream.
398 Storage::Storage( SvStream
& r
, sal_Bool bDirect
)
399 : OLEStorageBase( new StgIo
, NULL
, m_nMode
), bIsRoot( sal_False
)
401 m_nMode
= STREAM_READ
;
403 m_nMode
= STREAM_READ
| STREAM_WRITE
;
404 if( r
.GetError() == SVSTREAM_OK
)
406 pIo
->SetStrm( &r
, sal_False
);
407 sal_uLong nSize
= r
.Seek( STREAM_SEEK_TO_END
);
409 // Initializing is OK if the stream is empty
410 Init( sal_Bool( nSize
== 0 ) );
413 pEntry
->bDirect
= bDirect
;
414 pEntry
->nMode
= m_nMode
;
416 pIo
->MoveError( *this );
420 SetError( r
.GetError() );
426 Storage::Storage( UCBStorageStream
& rStrm
, sal_Bool bDirect
)
427 : OLEStorageBase( new StgIo
, NULL
, m_nMode
), bIsRoot( sal_False
)
429 m_nMode
= STREAM_READ
;
431 if ( rStrm
.GetError() != SVSTREAM_OK
)
433 SetError( rStrm
.GetError() );
438 SvStream
* pStream
= rStrm
.GetModifySvStream();
441 OSL_FAIL( "UCBStorageStream can not provide SvStream implementation!\n" );
442 SetError( SVSTREAM_GENERALERROR
);
447 if( pStream
->IsWritable() )
448 m_nMode
= STREAM_READ
| STREAM_WRITE
;
450 pIo
->SetStrm( &rStrm
);
452 sal_uLong nSize
= pStream
->Seek( STREAM_SEEK_TO_END
);
454 // Initializing is OK if the stream is empty
455 Init( sal_Bool( nSize
== 0 ) );
458 pEntry
->bDirect
= bDirect
;
459 pEntry
->nMode
= m_nMode
;
462 pIo
->MoveError( *this );
466 // Perform common code for both ctors above.
468 void Storage::Init( sal_Bool bCreate
)
471 sal_Bool bHdrLoaded
= sal_False
;
474 OSL_ENSURE( pIo
, "The pointer may not be empty at this point!" );
475 if( pIo
->Good() && pIo
->GetStrm() )
477 sal_uLong nSize
= pIo
->GetStrm()->Seek( STREAM_SEEK_TO_END
);
478 pIo
->GetStrm()->Seek( 0L );
481 bHdrLoaded
= pIo
->Load();
482 if( !bHdrLoaded
&& !bCreate
)
484 // File is not a storage and not empty; do not destroy!
485 SetError( SVSTREAM_FILEFORMAT_ERROR
);
490 // file is a storage, empty or should be overwritten
492 // we have to set up the data structures, since
496 if( pIo
->Good() && pIo
->pTOC
)
498 pEntry
= pIo
->pTOC
->GetRoot();
505 Storage::Storage( StgIo
* p
, StgDirEntry
* q
, StreamMode m
)
506 : OLEStorageBase( p
, q
, m_nMode
), bIsRoot( sal_False
)
509 q
->aEntry
.GetName( aName
);
511 m
&= ~STREAM_READWRITE
;
513 if( q
&& q
->nRefCnt
== 1 )
519 // Invalidate all open substorages
524 // Do an auto-commit if the entry is open in direct mode
525 if( pEntry
->nRefCnt
&& pEntry
->bDirect
&& (m_nMode
& STREAM_WRITE
) )
527 if( pEntry
->nRefCnt
== 1 )
528 pEntry
->Invalidate();
530 // close the stream is root storage
533 // remove the file if temporary root storage
534 if( bIsRoot
&& pEntry
&& pEntry
->bTemp
)
536 osl::File::remove( GetName() );
540 const String
& Storage::GetName() const
542 if( !bIsRoot
&& Validate() )
543 pEntry
->aEntry
.GetName( ((Storage
*) this)->aName
);
547 // Fill in the info list for this storage
549 void Storage::FillInfoList( SvStorageInfoList
* pList
) const
551 if( Validate() && pList
)
553 StgIterator
aIter( *pEntry
);
554 StgDirEntry
* p
= aIter
.First();
559 SvStorageInfo
aInfo( *p
);
560 pList
->push_back( aInfo
);
567 // Open or create a substorage
569 BaseStorage
* Storage::OpenUCBStorage( const String
& rName
, StreamMode m
, sal_Bool bDirect
)
571 OSL_FAIL("Not supported!");
572 return OpenStorage( rName
, m
, bDirect
);
575 BaseStorage
* Storage::OpenOLEStorage( const String
& rName
, StreamMode m
, sal_Bool bDirect
)
577 return OpenStorage( rName
, m
, bDirect
);
580 BaseStorage
* Storage::OpenStorage( const String
& rName
, StreamMode m
, bool bDirect
)
582 if( !Validate() || !ValidateMode( m
) )
583 return new Storage( pIo
, NULL
, m
);
584 if( bDirect
&& !pEntry
->bDirect
)
587 StgDirEntry
* p
= pIo
->pTOC
->Find( *pEntry
, rName
);
590 if( !( m
& STREAM_NOCREATE
) )
592 sal_Bool bTemp
= sal_False
;
593 // create a new storage
594 String aNewName
= rName
;
595 if( !aNewName
.Len() )
597 aNewName
.AssignAscii( "Temp Stg " );
598 aNewName
.Append( OUString::number( ++nTmpCount
) );
601 p
= pIo
->pTOC
->Create( *pEntry
, aNewName
, STG_STORAGE
);
606 pIo
->SetError( ( m
& STREAM_WRITE
)
607 ? SVSTREAM_CANNOT_MAKE
: SVSTREAM_FILE_NOT_FOUND
);
609 else if( !ValidateMode( m
, p
) )
611 if( p
&& p
->aEntry
.GetType() != STG_STORAGE
)
613 pIo
->SetError( SVSTREAM_FILE_NOT_FOUND
);
617 // Either direct or transacted mode is supported
618 if( p
&& pEntry
->nRefCnt
== 1 )
619 p
->bDirect
= bDirect
;
621 // Dont check direct conflict if opening readonly
622 if( p
&& (m
& STREAM_WRITE
))
624 if( p
->bDirect
!= bDirect
)
625 SetError( SVSTREAM_ACCESS_DENIED
);
627 Storage
* pStg
= new Storage( pIo
, p
, m
);
628 pIo
->MoveError( *pStg
);
629 if( m
& STREAM_WRITE
) pStg
->m_bAutoCommit
= sal_True
;
635 BaseStorageStream
* Storage::OpenStream( const String
& rName
, StreamMode m
, sal_Bool
,
642 DBG_ASSERT(!pB
, "Encryption not supported");
644 if( !Validate() || !ValidateMode( m
) )
645 return new StorageStream( pIo
, NULL
, m
);
646 StgDirEntry
* p
= pIo
->pTOC
->Find( *pEntry
, rName
);
647 sal_Bool bTemp
= sal_False
;
650 if( !( m
& STREAM_NOCREATE
) )
652 // create a new stream
653 // make a name if the stream is temporary (has no name)
654 String
aNewName( rName
);
655 if( !aNewName
.Len() )
657 aNewName
.AssignAscii( "Temp Strm " );
658 aNewName
.Append( OUString::number( ++nTmpCount
) );
661 p
= pIo
->pTOC
->Create( *pEntry
, aNewName
, STG_STREAM
);
664 pIo
->SetError( ( m
& STREAM_WRITE
)
665 ? SVSTREAM_CANNOT_MAKE
: SVSTREAM_FILE_NOT_FOUND
);
667 else if( !ValidateMode( m
, p
) )
669 if( p
&& p
->aEntry
.GetType() != STG_STREAM
)
671 pIo
->SetError( SVSTREAM_FILE_NOT_FOUND
);
677 p
->bDirect
= pEntry
->bDirect
;
679 StorageStream
* pStm
= new StorageStream( pIo
, p
, m
);
680 if( p
&& !p
->bDirect
)
681 pStm
->SetAutoCommit( sal_True
);
682 pIo
->MoveError( *pStm
);
686 // Delete a stream or substorage by setting the temp bit.
688 sal_Bool
Storage::Remove( const String
& rName
)
690 if( !Validate( sal_True
) )
692 StgDirEntry
* p
= pIo
->pTOC
->Find( *pEntry
, rName
);
695 p
->Invalidate( sal_True
);
700 SetError( SVSTREAM_FILE_NOT_FOUND
);
705 // Rename a storage element
707 sal_Bool
Storage::Rename( const String
& rOld
, const String
& rNew
)
709 if( Validate( sal_True
) )
711 sal_Bool b
= pIo
->pTOC
->Rename( *pEntry
, rOld
, rNew
);
712 pIo
->MoveError( *this );
721 sal_Bool
Storage::CopyTo( const String
& rElem
, BaseStorage
* pDest
, const String
& rNew
)
723 if( !Validate() || !pDest
|| !pDest
->Validate( sal_True
) )
725 StgDirEntry
* pElem
= pIo
->pTOC
->Find( *pEntry
, rElem
);
728 if( pElem
->aEntry
.GetType() == STG_STORAGE
)
730 // copy the entire storage
731 BaseStorage
* p1
= OpenStorage( rElem
, INTERNAL_MODE
);
732 BaseStorage
* p2
= pDest
->OpenOLEStorage( rNew
, STREAM_WRITE
| STREAM_SHARE_DENYALL
, pEntry
->bDirect
);
736 sal_uLong nTmpErr
= p2
->GetError();
739 p2
->SetClassId( p1
->GetClassId() );
741 SetError( p1
->GetError() );
743 nTmpErr
= p2
->GetError();
747 pDest
->SetError( nTmpErr
);
750 pDest
->SetError( nTmpErr
);
755 return sal_Bool( Good() && pDest
->Good() );
760 BaseStorageStream
* p1
= OpenStream( rElem
, INTERNAL_MODE
);
761 BaseStorageStream
* p2
= pDest
->OpenStream( rNew
, STREAM_WRITE
| STREAM_SHARE_DENYALL
, pEntry
->bDirect
);
765 sal_uLong nTmpErr
= p2
->GetError();
769 SetError( p1
->GetError() );
771 nTmpErr
= p2
->GetError();
775 pDest
->SetError( nTmpErr
);
778 pDest
->SetError( nTmpErr
);
783 return sal_Bool( Good() && pDest
->Good() );
786 SetError( SVSTREAM_FILE_NOT_FOUND
);
790 sal_Bool
Storage::CopyTo( BaseStorage
* pDest
) const
792 if( !Validate() || !pDest
|| !pDest
->Validate( sal_True
) || Equals( *pDest
) )
794 SetError( SVSTREAM_ACCESS_DENIED
);
797 Storage
* pThis
= (Storage
*) this;
798 pDest
->SetClassId( GetClassId() );
800 SvStorageInfoList aList
;
801 FillInfoList( &aList
);
802 sal_Bool bRes
= sal_True
;
803 for( size_t i
= 0; i
< aList
.size() && bRes
; i
++ )
805 SvStorageInfo
& rInfo
= aList
[ i
];
806 bRes
= pThis
->CopyTo( rInfo
.GetName(), pDest
, rInfo
.GetName() );
809 SetError( pDest
->GetError() );
810 return sal_Bool( Good() && pDest
->Good() );
815 sal_Bool
Storage::MoveTo( const String
& rElem
, BaseStorage
* pODest
, const String
& rNew
)
817 if( !Validate() || !pODest
|| !pODest
->Validate( sal_True
) || Equals( *pODest
) )
819 SetError( SVSTREAM_ACCESS_DENIED
);
823 StgDirEntry
* pElem
= pIo
->pTOC
->Find( *pEntry
, rElem
);
826 // Simplest case: both storages share the same file
828 Storage
*pOther
= PTR_CAST( Storage
, pODest
);
829 if( pOther
&& pIo
== pOther
->pIo
&& rElem
== rNew
)
831 Storage
*p
= (Storage
*) pODest
;
833 // both storages are conventional storages, use implementation dependent code
834 if( !pElem
->IsContained( pDest
->pEntry
) )
837 SetError( SVSTREAM_ACCESS_DENIED
);
840 bRes
= pIo
->pTOC
->Move( *pEntry
, *pDest
->pEntry
, rNew
);
843 pIo
->MoveError( *this );
844 pDest
->pIo
->MoveError( *pDest
);
845 sal_uLong nErr
= GetError();
847 nErr
= pDest
->GetError();
849 pDest
->SetError( nErr
);
854 bRes
= CopyTo( rElem
, pODest
, rNew
);
856 bRes
= Remove( rElem
);
859 SetError( pIo
->GetError() );
862 SetError( SVSTREAM_FILE_NOT_FOUND
);
866 sal_Bool
Storage::IsStorage( const String
& rName
) const
870 StgDirEntry
* p
= pIo
->pTOC
->Find( *pEntry
, rName
);
872 return sal_Bool( p
->aEntry
.GetType() == STG_STORAGE
);
877 sal_Bool
Storage::IsStream( const String
& rName
) const
881 StgDirEntry
* p
= pIo
->pTOC
->Find( *pEntry
, rName
);
883 return sal_Bool( p
->aEntry
.GetType() == STG_STREAM
);
888 sal_Bool
Storage::IsContained( const String
& rName
) const
891 return sal_Bool( pIo
->pTOC
->Find( *pEntry
, rName
) != NULL
);
896 // Commit all sub-elements within this storage. If this is
897 // the root, commit the FAT, the TOC and the header as well.
899 sal_Bool
Storage::Commit()
901 sal_Bool bRes
= sal_True
;
904 if( !( m_nMode
& STREAM_WRITE
) )
906 SetError( SVSTREAM_ACCESS_DENIED
);
911 // Also commit the sub-streams and Storages
912 StgIterator
aIter( *pEntry
);
913 for( StgDirEntry
* p
= aIter
.First(); p
&& bRes
; p
= aIter
.Next() )
915 if( bRes
&& bIsRoot
)
917 bRes
= pEntry
->Commit();
919 bRes
= pIo
->CommitAll();
921 pIo
->MoveError( *this );
926 sal_Bool
Storage::Revert()
931 ///////////////////////////// OLE Support ////////////////////////////////
933 // Set the storage type
935 void Storage::SetClass( const SvGlobalName
& rClass
,
936 sal_uLong nOriginalClipFormat
,
937 const String
& rUserTypeName
)
939 if( Validate( sal_True
) )
941 // set the class name in the root entry
942 pEntry
->aEntry
.SetClassId( (const ClsId
&) rClass
.GetCLSID() );
944 // then create the streams
945 StgCompObjStream
aCompObj( *this, sal_True
);
946 aCompObj
.GetClsId() = (const ClsId
&) rClass
.GetCLSID();
947 aCompObj
.GetCbFormat() = nOriginalClipFormat
;
948 aCompObj
.GetUserName() = rUserTypeName
;
949 if( !aCompObj
.Store() )
950 SetError( aCompObj
.GetError() );
953 StgOleStream
aOle( *this, STREAM_WRITE
);
955 SetError( aOle
.GetError() );
959 SetError( SVSTREAM_ACCESS_DENIED
);
962 void Storage::SetConvertClass( const SvGlobalName
& rConvertClass
,
963 sal_uLong nOriginalClipFormat
,
964 const String
& rUserTypeName
)
966 if( Validate( sal_True
) )
968 SetClass( rConvertClass
, nOriginalClipFormat
, rUserTypeName
);
969 // plus the convert flag:
970 StgOleStream
aOle( *this, sal_True
);
971 aOle
.GetFlags() |= 4;
973 SetError( aOle
.GetError() );
977 SvGlobalName
Storage::GetClassName()
979 StgCompObjStream
aCompObj( *this, sal_False
);
980 if( aCompObj
.Load() )
981 return SvGlobalName( (const CLSID
&) aCompObj
.GetClsId() );
985 return SvGlobalName( (const CLSID
&) pEntry
->aEntry
.GetClassId() );
987 return SvGlobalName();
990 sal_uLong
Storage::GetFormat()
992 StgCompObjStream
aCompObj( *this, sal_False
);
993 if( aCompObj
.Load() )
994 return aCompObj
.GetCbFormat();
999 String
Storage::GetUserName()
1001 StgCompObjStream
aCompObj( *this, sal_False
);
1002 if( aCompObj
.Load() )
1003 return aCompObj
.GetUserName();
1008 sal_Bool
Storage::ShouldConvert()
1010 StgOleStream
aOle( *this, sal_False
);
1012 return sal_Bool( ( aOle
.GetFlags() & 4 ) != 0 );
1020 sal_Bool
Storage::ValidateFAT()
1022 Link aLink
= StgIo::GetErrorLink();
1023 ErrCode nErr
= pIo
->ValidateFATs();
1024 StgIo::SetErrorLink( aLink
);
1025 return nErr
== ERRCODE_NONE
;
1028 void Storage::SetDirty()
1034 void Storage::SetClassId( const ClsId
& rId
)
1037 pEntry
->aEntry
.SetClassId( rId
);
1040 const ClsId
& Storage::GetClassId() const
1043 return pEntry
->aEntry
.GetClassId();
1045 static ClsId aDummyId
= {0,0,0,0,0,0,0,0,0,0,0};
1049 const SvStream
* Storage::GetSvStream() const
1051 return GetSvStream_Impl();
1054 sal_Bool
Storage::Validate( sal_Bool bValidate
) const
1056 sal_Bool bRet
= Validate_Impl( bValidate
);
1058 SetError( SVSTREAM_ACCESS_DENIED
);
1062 sal_Bool
Storage::ValidateMode( StreamMode nMode
) const
1064 sal_Bool bRet
= ValidateMode_Impl( nMode
);
1066 SetError( SVSTREAM_ACCESS_DENIED
);
1070 sal_Bool
Storage::ValidateMode( StreamMode nMode
, StgDirEntry
* p
) const
1072 sal_Bool bRet
= ValidateMode_Impl( nMode
, p
);
1074 SetError( SVSTREAM_ACCESS_DENIED
);
1078 sal_Bool
Storage::Equals( const BaseStorage
& rStorage
) const
1080 const Storage
* pOther
= PTR_CAST( Storage
, &rStorage
);
1081 return pOther
&& ( pOther
->pEntry
== pEntry
);
1085 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */