Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/dlls/coml2/storage32.c
4389 views
1
/*
2
* Compound Storage (32 bit version)
3
* Storage implementation
4
*
5
* This file contains the compound file implementation
6
* of the storage interface.
7
*
8
* Copyright 1999 Francis Beaudet
9
* Copyright 1999 Sylvain St-Germain
10
* Copyright 1999 Thuy Nguyen
11
* Copyright 2005 Mike McCormack
12
*
13
* This library is free software; you can redistribute it and/or
14
* modify it under the terms of the GNU Lesser General Public
15
* License as published by the Free Software Foundation; either
16
* version 2.1 of the License, or (at your option) any later version.
17
*
18
* This library is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21
* Lesser General Public License for more details.
22
*
23
* You should have received a copy of the GNU Lesser General Public
24
* License along with this library; if not, write to the Free Software
25
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26
*
27
* NOTES
28
* The compound file implementation of IStorage used for create
29
* and manage substorages and streams within a storage object
30
* residing in a compound file object.
31
*/
32
33
#include <assert.h>
34
#include <stdarg.h>
35
#include <stdio.h>
36
#include <stdlib.h>
37
#include <string.h>
38
39
#define COBJMACROS
40
#include "windef.h"
41
#include "winbase.h"
42
#include "winnls.h"
43
#include "winuser.h"
44
#include "wine/debug.h"
45
46
#include "ole2.h" /* For Write/ReadClassStm */
47
48
#include "winreg.h"
49
#include "wine/wingdi16.h"
50
51
WINE_DEFAULT_DEBUG_CHANNEL(storage);
52
53
static const BYTE STORAGE_magic[8] ={0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1};
54
55
/***********************************************************************
56
* WriteClassStg [coml2.@]
57
*/
58
HRESULT WINAPI WriteClassStg(IStorage *pStg, REFCLSID rclsid)
59
{
60
if (!pStg)
61
return E_INVALIDARG;
62
63
if (!rclsid)
64
return STG_E_INVALIDPOINTER;
65
66
return IStorage_SetClass(pStg, rclsid);
67
}
68
69
/***********************************************************************
70
* ReadClassStg (coml2.@)
71
*/
72
HRESULT WINAPI ReadClassStg(IStorage *pstg, CLSID *pclsid)
73
{
74
STATSTG pstatstg;
75
HRESULT hRes;
76
77
TRACE("(%p, %p)\n", pstg, pclsid);
78
79
if (!pstg || !pclsid)
80
return E_INVALIDARG;
81
82
/*
83
* read a STATSTG structure (contains the clsid) from the storage
84
*/
85
hRes = IStorage_Stat(pstg, &pstatstg, STATFLAG_NONAME);
86
87
if (SUCCEEDED(hRes))
88
*pclsid = pstatstg.clsid;
89
90
return hRes;
91
}
92
93
/***********************************************************************
94
* WriteClassStm (coml2.@)
95
*/
96
HRESULT WINAPI WriteClassStm(IStream *pStm, REFCLSID rclsid)
97
{
98
TRACE("(%p,%p)\n", pStm, rclsid);
99
100
if (!pStm || !rclsid)
101
return E_INVALIDARG;
102
103
return IStream_Write(pStm, rclsid, sizeof(CLSID), NULL);
104
}
105
106
/***********************************************************************
107
* ReadClassStm (coml2.@)
108
*/
109
HRESULT WINAPI ReadClassStm(IStream *pStm, CLSID *pclsid)
110
{
111
ULONG nbByte;
112
HRESULT res;
113
114
TRACE("(%p,%p)\n", pStm, pclsid);
115
116
if (!pStm || !pclsid)
117
return E_INVALIDARG;
118
119
/* clear the output args */
120
*pclsid = CLSID_NULL;
121
122
res = IStream_Read(pStm, pclsid, sizeof(CLSID), &nbByte);
123
124
if (FAILED(res))
125
return res;
126
127
if (nbByte != sizeof(CLSID))
128
return STG_E_READFAULT;
129
else
130
return S_OK;
131
}
132
133
enum stream_1ole_flags {
134
OleStream_LinkedObject = 0x00000001,
135
OleStream_Convert = 0x00000004
136
};
137
138
/***********************************************************************
139
* GetConvertStg (coml2.@)
140
*/
141
HRESULT WINAPI GetConvertStg(IStorage *stg)
142
{
143
static const DWORD version_magic = 0x02000001;
144
DWORD header[2];
145
IStream *stream;
146
HRESULT hr;
147
148
TRACE("%p\n", stg);
149
150
if (!stg) return E_INVALIDARG;
151
152
hr = IStorage_OpenStream(stg, L"\1Ole", NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stream);
153
if (FAILED(hr)) return hr;
154
155
hr = IStream_Read(stream, header, sizeof(header), NULL);
156
IStream_Release(stream);
157
if (FAILED(hr)) return hr;
158
159
if (header[0] != version_magic)
160
{
161
ERR("got wrong version magic for 1Ole stream, %#lx.\n", header[0]);
162
return E_FAIL;
163
}
164
165
return header[1] & OleStream_Convert ? S_OK : S_FALSE;
166
}
167
168
/******************************************************************************
169
* StgIsStorageILockBytes [coml2.@]
170
*/
171
HRESULT WINAPI StgIsStorageILockBytes(ILockBytes *plkbyt)
172
{
173
BYTE sig[sizeof(STORAGE_magic)];
174
ULARGE_INTEGER offset;
175
ULONG read = 0;
176
177
offset.HighPart = 0;
178
offset.LowPart = 0;
179
180
ILockBytes_ReadAt(plkbyt, offset, sig, sizeof(sig), &read);
181
182
if (read == sizeof(sig) && memcmp(sig, STORAGE_magic, sizeof(sig)) == 0)
183
return S_OK;
184
185
return S_FALSE;
186
}
187
188
/******************************************************************************
189
* StgIsStorageFile [coml2.@]
190
*/
191
HRESULT WINAPI StgIsStorageFile(LPCOLESTR fn)
192
{
193
HANDLE hf;
194
BYTE magic[8];
195
DWORD bytes_read;
196
197
TRACE("%s\n", debugstr_w(fn));
198
hf = CreateFileW(fn, GENERIC_READ,
199
FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
200
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
201
202
if (hf == INVALID_HANDLE_VALUE)
203
return STG_E_FILENOTFOUND;
204
205
if (!ReadFile(hf, magic, 8, &bytes_read, NULL))
206
{
207
WARN(" unable to read file\n");
208
CloseHandle(hf);
209
return S_FALSE;
210
}
211
212
CloseHandle(hf);
213
214
if (bytes_read != 8)
215
{
216
TRACE(" too short\n");
217
return S_FALSE;
218
}
219
220
if (!memcmp(magic, STORAGE_magic, 8))
221
{
222
TRACE(" -> YES\n");
223
return S_OK;
224
}
225
226
TRACE(" -> Invalid header.\n");
227
return S_FALSE;
228
}
229
230
/******************************************************************************
231
* StgCreatePropSetStg [coml2.@]
232
*/
233
HRESULT WINAPI StgCreatePropSetStg(IStorage *pstg, DWORD reserved, IPropertySetStorage **propset)
234
{
235
TRACE("%p, %#lx, %p.\n", pstg, reserved, propset);
236
if (reserved)
237
return STG_E_INVALIDPARAMETER;
238
239
return IStorage_QueryInterface(pstg, &IID_IPropertySetStorage, (void**)propset);
240
}
241
242