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 .
20 #ifndef INCLUDED_SOT_STG_HXX
21 #define INCLUDED_SOT_STG_HXX
23 #include <tools/stream.hxx>
24 #include <tools/globname.hxx>
25 #include <sot/storinfo.hxx>
26 #include <sot/sotdllapi.h>
27 #include <config_options.h>
29 namespace com::sun::star::ucb
{ class XProgressHandler
; }
30 namespace com::sun::star::uno
{ class Any
; }
31 namespace com::sun::star::uno
{ template <typename
> class Reference
; }
35 typedef struct SvGUID ClsId
;
37 class StorageBase
: public SvRefBase
40 mutable ErrCode m_nError
; // error code
41 StreamMode m_nMode
; // open mode
44 virtual ~StorageBase() override
;
46 virtual bool Validate( bool=false ) const = 0;
47 virtual bool ValidateMode( StreamMode
) const = 0;
48 void ResetError() const;
49 void SetError( ErrCode
) const;
50 ErrCode
GetError() const;
51 bool Good() const { return m_nError
== ERRCODE_NONE
; }
52 StreamMode
GetMode() const { return m_nMode
; }
53 void SetAutoCommit( bool bSet
)
54 { m_bAutoCommit
= bSet
; }
57 class BaseStorageStream
: public StorageBase
60 virtual sal_Int32
Read( void * pData
, sal_Int32 nSize
) = 0;
61 virtual sal_Int32
Write( const void* pData
, sal_Int32 nSize
) = 0;
62 virtual sal_uInt64
Seek( sal_uInt64 nPos
) = 0;
63 virtual sal_uInt64
Tell() = 0;
64 virtual void Flush() = 0;
65 virtual bool SetSize( sal_uInt64 nNewSize
) = 0;
66 virtual sal_uInt64
GetSize() const = 0;
67 virtual void CopyTo( BaseStorageStream
* pDestStm
) = 0;
68 virtual bool Commit() = 0;
69 virtual bool Equals( const BaseStorageStream
& rStream
) const = 0;
72 enum class SotClipboardFormatId
: sal_uInt32
;
74 class SAL_DLLPUBLIC_RTTI BaseStorage
: public StorageBase
77 virtual const OUString
& GetName() const = 0;
78 virtual bool IsRoot() const = 0;
79 virtual void SetClassId( const ClsId
& ) = 0;
80 virtual const ClsId
& GetClassId() const = 0;
81 virtual void SetDirty() = 0;
82 virtual void SetClass( const SvGlobalName
& rClass
,
83 SotClipboardFormatId nOriginalClipFormat
,
84 const OUString
& rUserTypeName
) = 0;
85 virtual SvGlobalName
GetClassName() = 0;
86 virtual SotClipboardFormatId
GetFormat() = 0;
87 virtual OUString
GetUserName() = 0;
88 virtual void FillInfoList( SvStorageInfoList
* ) const = 0;
89 virtual bool CopyTo( BaseStorage
* pDestStg
) const = 0;
90 virtual bool Commit() = 0;
91 virtual bool Revert() = 0;
92 virtual BaseStorageStream
* OpenStream( const OUString
& rEleName
,
93 StreamMode
= StreamMode::STD_READWRITE
,
94 bool bDirect
= true ) = 0;
95 virtual BaseStorage
* OpenStorage( const OUString
& rEleName
,
96 StreamMode
= StreamMode::STD_READWRITE
,
97 bool bDirect
= false ) = 0;
98 virtual BaseStorage
* OpenUCBStorage( const OUString
& rEleName
,
99 StreamMode
= StreamMode::STD_READWRITE
,
100 bool bDirect
= false ) = 0;
101 virtual BaseStorage
* OpenOLEStorage( const OUString
& rEleName
,
102 StreamMode
= StreamMode::STD_READWRITE
,
103 bool bDirect
= false ) = 0;
104 virtual bool IsStream( const OUString
& rEleName
) const = 0;
105 virtual bool IsStorage( const OUString
& rEleName
) const = 0;
106 virtual bool IsContained( const OUString
& rEleName
) const = 0;
107 virtual void Remove( const OUString
& rEleName
) = 0;
108 virtual bool CopyTo( const OUString
& rEleName
, BaseStorage
* pDest
, const OUString
& rNewName
) = 0;
109 virtual bool ValidateFAT() = 0;
110 virtual bool Equals( const BaseStorage
& rStream
) const = 0;
116 StreamMode
& nStreamMode
; // open mode
117 StgIo
* pIo
; // I/O subsystem
118 StgDirEntry
* pEntry
; // the dir entry
119 OLEStorageBase( StgIo
*, StgDirEntry
*, StreamMode
& );
121 bool Validate_Impl( bool ) const;
122 static bool ValidateMode_Impl( StreamMode
, StgDirEntry
const * p
= nullptr );
125 class StorageStream final
: public BaseStorageStream
, public OLEStorageBase
127 //friend class Storage;
128 sal_uInt64 nPos
; // current position
130 virtual ~StorageStream() override
;
132 StorageStream( StgIo
*, StgDirEntry
*, StreamMode
);
133 virtual sal_Int32
Read( void * pData
, sal_Int32 nSize
) override
;
134 virtual sal_Int32
Write( const void* pData
, sal_Int32 nSize
) override
;
135 virtual sal_uInt64
Seek( sal_uInt64 nPos
) override
;
136 virtual sal_uInt64
Tell() override
{ return nPos
; }
137 virtual void Flush() override
;
138 virtual bool SetSize( sal_uInt64 nNewSize
) override
;
139 virtual sal_uInt64
GetSize() const override
;
140 virtual void CopyTo( BaseStorageStream
* pDestStm
) override
;
141 virtual bool Commit() final override
;
142 virtual bool Validate( bool=false ) const override
;
143 virtual bool ValidateMode( StreamMode
) const override
;
144 virtual bool Equals( const BaseStorageStream
& rStream
) const override
;
147 class UCBStorageStream
;
149 class UNLESS_MERGELIBS(SOT_DLLPUBLIC
) Storage final
: public BaseStorage
, public OLEStorageBase
153 void Init( bool bCreate
);
154 Storage( StgIo
*, StgDirEntry
*, StreamMode
);
155 virtual ~Storage() override
;
157 Storage( const OUString
&, StreamMode
, bool bDirect
);
158 Storage( SvStream
& rStrm
, bool bDirect
);
159 Storage( UCBStorageStream
& rStrm
, bool bDirect
);
161 static bool IsStorageFile( const OUString
& rFileName
);
162 static bool IsStorageFile( SvStream
* );
164 virtual const OUString
& GetName() const final override
;
165 virtual bool IsRoot() const override
{ return bIsRoot
; }
166 virtual void SetClassId( const ClsId
& ) override
;
167 virtual const ClsId
& GetClassId() const override
;
168 virtual void SetDirty() override
;
169 virtual void SetClass( const SvGlobalName
& rClass
,
170 SotClipboardFormatId nOriginalClipFormat
,
171 const OUString
& rUserTypeName
) override
;
172 virtual SvGlobalName
GetClassName() override
;
173 virtual SotClipboardFormatId
GetFormat() override
;
174 virtual OUString
GetUserName() override
;
175 virtual void FillInfoList( SvStorageInfoList
* ) const override
;
176 virtual bool CopyTo( BaseStorage
* pDestStg
) const override
;
177 virtual bool Commit() final override
;
178 virtual bool Revert() override
;
179 virtual BaseStorageStream
* OpenStream( const OUString
& rEleName
,
180 StreamMode
= StreamMode::STD_READWRITE
,
181 bool bDirect
= true ) override
;
182 virtual BaseStorage
* OpenStorage( const OUString
& rEleName
,
183 StreamMode
= StreamMode::STD_READWRITE
,
184 bool bDirect
= false ) override
;
185 virtual BaseStorage
* OpenUCBStorage( const OUString
& rEleName
,
186 StreamMode
= StreamMode::STD_READWRITE
,
187 bool bDirect
= false ) override
;
188 virtual BaseStorage
* OpenOLEStorage( const OUString
& rEleName
,
189 StreamMode
= StreamMode::STD_READWRITE
,
190 bool bDirect
= false ) override
;
191 virtual bool IsStream( const OUString
& rEleName
) const override
;
192 virtual bool IsStorage( const OUString
& rEleName
) const override
;
193 virtual bool IsContained( const OUString
& rEleName
) const override
;
194 virtual void Remove( const OUString
& rEleName
) override
;
195 virtual bool CopyTo( const OUString
& rEleName
, BaseStorage
* pDest
, const OUString
& rNewName
) override
;
196 virtual bool ValidateFAT() override
;
197 virtual bool Validate( bool=false ) const override
;
198 virtual bool ValidateMode( StreamMode
) const override
;
199 bool ValidateMode( StreamMode
, StgDirEntry
const * p
) const;
200 virtual bool Equals( const BaseStorage
& rStream
) const override
;
203 class UCBStorageStream_Impl
;
204 class UCBStorageStream final
: public BaseStorageStream
206 friend class UCBStorage
;
208 UCBStorageStream_Impl
*
210 virtual ~UCBStorageStream() override
;
212 UCBStorageStream( const OUString
& rName
, StreamMode nMode
, bool bDirect
, bool bRepair
, css::uno::Reference
< css::ucb::XProgressHandler
> const & xProgress
);
213 UCBStorageStream( UCBStorageStream_Impl
* );
215 virtual sal_Int32
Read( void * pData
, sal_Int32 nSize
) override
;
216 virtual sal_Int32
Write( const void* pData
, sal_Int32 nSize
) override
;
217 virtual sal_uInt64
Seek( sal_uInt64 nPos
) override
;
218 virtual sal_uInt64
Tell() override
;
219 virtual void Flush() override
;
220 virtual bool SetSize( sal_uInt64 nNewSize
) override
;
221 virtual sal_uInt64
GetSize() const override
;
222 virtual void CopyTo( BaseStorageStream
* pDestStm
) override
;
223 virtual bool Commit() override
;
224 virtual bool Validate( bool=false ) const override
;
225 virtual bool ValidateMode( StreamMode
) const override
;
226 virtual bool Equals( const BaseStorageStream
& rStream
) const override
;
227 bool SetProperty( const OUString
& rName
, const css::uno::Any
& rValue
);
229 SvStream
* GetModifySvStream();
237 class UCBStorage_Impl
;
238 struct UCBStorageElement_Impl
;
239 class SOT_DLLPUBLIC UCBStorage final
: public BaseStorage
241 UCBStorage_Impl
* pImp
;
243 virtual ~UCBStorage() override
;
245 static bool IsStorageFile( SvStream
* );
247 UCBStorage( const ::ucbhelper::Content
& rContent
,
248 const OUString
& rName
,
253 UCBStorage( const OUString
& rName
,
258 UCBStorage( const OUString
& rName
,
263 css::uno::Reference
< css::ucb::XProgressHandler
> const &
266 UCBStorage( UCBStorage_Impl
* );
268 UCBStorage( SvStream
& rStrm
, bool bDirect
);
270 virtual const OUString
& GetName() const override
;
271 virtual bool IsRoot() const override
;
272 virtual void SetClassId( const ClsId
& ) override
;
273 virtual const ClsId
& GetClassId() const override
;
274 virtual void SetDirty() override
;
275 virtual void SetClass( const SvGlobalName
& rClass
,
276 SotClipboardFormatId nOriginalClipFormat
,
277 const OUString
& rUserTypeName
) override
;
278 virtual SvGlobalName
GetClassName() override
;
279 virtual SotClipboardFormatId
GetFormat() override
;
280 virtual OUString
GetUserName() override
;
281 virtual void FillInfoList( SvStorageInfoList
* ) const override
;
282 virtual bool CopyTo( BaseStorage
* pDestStg
) const override
;
283 virtual bool Commit() final override
;
284 virtual bool Revert() override
;
285 virtual BaseStorageStream
* OpenStream( const OUString
& rEleName
,
286 StreamMode
= StreamMode::STD_READWRITE
,
287 bool bDirect
= true ) override
;
288 virtual BaseStorage
* OpenStorage( const OUString
& rEleName
,
289 StreamMode
= StreamMode::STD_READWRITE
,
290 bool bDirect
= false ) override
;
291 virtual BaseStorage
* OpenUCBStorage( const OUString
& rEleName
,
292 StreamMode
= StreamMode::STD_READWRITE
,
293 bool bDirect
= false ) override
;
294 virtual BaseStorage
* OpenOLEStorage( const OUString
& rEleName
,
295 StreamMode
= StreamMode::STD_READWRITE
,
296 bool bDirect
= false ) override
;
297 virtual bool IsStream( const OUString
& rEleName
) const override
;
298 virtual bool IsStorage( const OUString
& rEleName
) const override
;
299 virtual bool IsContained( const OUString
& rEleName
) const override
;
300 virtual void Remove( const OUString
& rEleName
) override
;
301 virtual bool CopyTo( const OUString
& rEleName
, BaseStorage
* pDest
, const OUString
& rNewName
) override
;
302 virtual bool ValidateFAT() override
;
303 virtual bool Validate( bool=false ) const override
;
304 virtual bool ValidateMode( StreamMode
) const override
;
305 virtual bool Equals( const BaseStorage
& rStream
) const override
;
307 UCBStorageElement_Impl
* FindElement_Impl( std::u16string_view rName
) const;
308 bool CopyStorageElement_Impl( UCBStorageElement_Impl
const & rElement
,
309 BaseStorage
* pDest
, const OUString
& rNew
) const;
310 BaseStorage
* OpenStorage_Impl( const OUString
& rEleName
,
311 StreamMode
, bool bDirect
, bool bForceUCBStorage
);
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */