Teach symstore more duplicated DLLs
[LibreOffice.git] / sot / source / sdstor / stgole.cxx
blob62c586a207731e5462f45267d3723cbf3052f4a8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #include <memory>
21 #include <algorithm>
23 #include "stgelem.hxx"
24 #include "stgole.hxx"
25 #include <sot/storinfo.hxx>
27 ///////////////////////// class StgInternalStream
29 StgInternalStream::StgInternalStream( BaseStorage& rStg, const OUString& rName, bool bWr )
31 m_isWritable = true;
32 StreamMode nMode = bWr
33 ? StreamMode::WRITE | StreamMode::SHARE_DENYALL
34 : StreamMode::READ | StreamMode::SHARE_DENYWRITE | StreamMode::NOCREATE;
35 m_pStrm.reset( rStg.OpenStream( rName, nMode ) );
37 // set the error code right here in the stream
38 SetError( rStg.GetError() );
39 SetBufferSize( 1024 );
42 StgInternalStream::~StgInternalStream()
46 std::size_t StgInternalStream::GetData(void* pData, std::size_t nSize)
48 if( m_pStrm )
50 nSize = m_pStrm->Read( pData, nSize );
51 SetError( m_pStrm->GetError() );
52 return nSize;
54 else
55 return 0;
58 std::size_t StgInternalStream::PutData(const void* pData, std::size_t nSize)
60 if( m_pStrm )
62 nSize = m_pStrm->Write( pData, nSize );
63 SetError( m_pStrm->GetError() );
64 return nSize;
66 else
67 return 0;
70 sal_uInt64 StgInternalStream::SeekPos(sal_uInt64 const nPos)
72 return m_pStrm ? m_pStrm->Seek( nPos ) : 0;
75 void StgInternalStream::FlushData()
77 if( m_pStrm )
79 m_pStrm->Flush();
80 SetError( m_pStrm->GetError() );
84 void StgInternalStream::Commit()
86 Flush();
87 m_pStrm->Commit();
90 ///////////////////////// class StgCompObjStream
92 StgCompObjStream::StgCompObjStream( BaseStorage& rStg, bool bWr )
93 : StgInternalStream( rStg, "\1CompObj", bWr )
97 bool StgCompObjStream::Load()
99 memset( &m_aClsId, 0, sizeof( ClsId ) );
100 m_nCbFormat = SotClipboardFormatId::NONE;
101 m_aUserName.clear();
102 if( GetError() != ERRCODE_NONE )
103 return false;
104 Seek( 8 ); // skip the first part
105 sal_Int32 nMarker = 0;
106 ReadInt32( nMarker );
107 if( nMarker == -1 )
109 ReadClsId( *this, m_aClsId );
110 sal_Int32 nLen1 = 0;
111 ReadInt32( nLen1 );
112 if ( nLen1 > 0 )
114 // higher bits are ignored
115 sal_uLong nStrLen = ::std::min( nLen1, sal_Int32(0xFFFE) );
117 std::unique_ptr<sal_Char[]> p(new sal_Char[ nStrLen+1 ]);
118 p[nStrLen] = 0;
119 if (ReadBytes( p.get(), nStrLen ) == nStrLen)
121 //The encoding here is "ANSI", which is pretty useless seeing as
122 //the actual codepage used doesn't seem to be specified/stored
123 //anywhere :-(. Might as well pick 1252 and be consistent on
124 //all platforms and envs
125 //https://bz.apache.org/ooo/attachment.cgi?id=68668
126 //for a good edge-case example
127 m_aUserName = OUString(p.get(), nStrLen, RTL_TEXTENCODING_MS_1252);
128 m_nCbFormat = ReadClipboardFormat( *this );
130 else
131 SetError( SVSTREAM_GENERALERROR );
134 return GetError() == ERRCODE_NONE;
137 bool StgCompObjStream::Store()
139 if( GetError() != ERRCODE_NONE )
140 return false;
141 Seek( 0 );
142 OString aAsciiUserName(OUStringToOString(m_aUserName, RTL_TEXTENCODING_MS_1252));
143 WriteInt16( 1 ); // Version?
144 WriteInt16( -2 ); // 0xFFFE = Byte Order Indicator
145 WriteInt32( 0x0A03 ); // Windows 3.10
146 WriteInt32( -1 );
147 WriteClsId( *this, m_aClsId ); // Class ID
148 WriteInt32( aAsciiUserName.getLength() + 1 );
149 WriteOString( aAsciiUserName );
150 WriteUChar( 0 ); // string terminator
151 WriteClipboardFormat( *this, m_nCbFormat );
152 WriteInt32( 0 ); // terminator
153 Commit();
154 return GetError() == ERRCODE_NONE;
157 /////////////////////////// class StgOleStream
159 StgOleStream::StgOleStream( BaseStorage& rStg )
160 : StgInternalStream( rStg, "\1Ole", true )
164 bool StgOleStream::Store()
166 if( GetError() != ERRCODE_NONE )
167 return false;
169 Seek( 0 );
170 WriteInt32( 0x02000001 ); // OLE version, format
171 WriteInt32( 0 ); // Object flags
172 WriteInt32( 0 ); // Update Options
173 WriteInt32( 0 ); // reserved
174 WriteInt32( 0 ); // Moniker 1
175 Commit();
176 return GetError() == ERRCODE_NONE;
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */