1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Compound Storage (32 bit version)
|
|
|
|
* Storage implementation
|
|
|
|
*
|
|
|
|
* This file contains the compound file implementation
|
|
|
|
* of the storage interface.
|
|
|
|
*
|
|
|
|
* Copyright 1999 Francis Beaudet
|
|
|
|
* Copyright 1999 Sylvain St-Germain
|
|
|
|
* Copyright 1999 Thuy Nguyen
|
2005-03-05 11:48:11 +01:00
|
|
|
* Copyright 2005 Mike McCormack
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-07-07 19:21:44 +02:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The compound file implementation of IStorage used for create
|
|
|
|
* and manage substorages and streams within a storage object
|
|
|
|
* residing in a compound file object.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
1999-01-30 14:24:23 +01:00
|
|
|
#include <stdio.h>
|
2000-03-08 19:25:22 +01:00
|
|
|
#include <stdlib.h>
|
1999-01-30 14:24:23 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
2004-10-07 05:06:48 +02:00
|
|
|
#define COBJMACROS
|
2003-01-07 21:36:20 +01:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
2004-10-07 05:06:48 +02:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2000-02-25 21:58:25 +01:00
|
|
|
#include "winnls.h"
|
2003-05-11 04:40:29 +02:00
|
|
|
#include "winuser.h"
|
2000-08-14 16:41:19 +02:00
|
|
|
#include "wine/unicode.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
#include "storage32.h"
|
1999-08-18 20:35:57 +02:00
|
|
|
#include "ole2.h" /* For Write/ReadClassStm */
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-02-25 21:58:25 +01:00
|
|
|
#include "winreg.h"
|
|
|
|
#include "wine/wingdi16.h"
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(storage);
|
1999-04-19 16:56:29 +02:00
|
|
|
|
2000-02-25 21:58:25 +01:00
|
|
|
/* Used for OleConvertIStorageToOLESTREAM and OleConvertOLESTREAMToIStorage */
|
|
|
|
#define OLESTREAM_ID 0x501
|
|
|
|
#define OLESTREAM_MAX_STR_LEN 255
|
|
|
|
|
2007-03-20 15:18:30 +01:00
|
|
|
/*
|
|
|
|
* These are signatures to detect the type of Document file.
|
|
|
|
*/
|
|
|
|
static const BYTE STORAGE_magic[8] ={0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1};
|
|
|
|
static const BYTE STORAGE_oldmagic[8] ={0xd0,0xcf,0x11,0xe0,0x0e,0x11,0xfc,0x0d};
|
|
|
|
|
2009-11-12 20:37:58 +01:00
|
|
|
static const char rootEntryName[] = "Root Entry";
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2006-08-02 13:31:26 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Storage32InternalImpl definitions.
|
|
|
|
*
|
|
|
|
* Definition of the implementation structure for the IStorage32 interface.
|
|
|
|
* This one implements the IStorage32 interface for storage that are
|
|
|
|
* inside another storage.
|
|
|
|
*/
|
|
|
|
struct StorageInternalImpl
|
|
|
|
{
|
|
|
|
struct StorageBaseImpl base;
|
2009-11-19 20:42:47 +01:00
|
|
|
|
2006-08-02 13:31:26 +02:00
|
|
|
/*
|
2009-11-19 20:42:47 +01:00
|
|
|
* Entry in the parent's stream tracking list
|
2006-08-02 13:31:26 +02:00
|
|
|
*/
|
2009-11-19 20:42:47 +01:00
|
|
|
struct list ParentListEntry;
|
2006-08-02 13:31:26 +02:00
|
|
|
};
|
|
|
|
typedef struct StorageInternalImpl StorageInternalImpl;
|
|
|
|
|
|
|
|
/* Method definitions for the Storage32InternalImpl class. */
|
|
|
|
static StorageInternalImpl* StorageInternalImpl_Construct(StorageImpl* ancestorStorage,
|
2009-11-12 22:53:42 +01:00
|
|
|
DWORD openFlags, DirRef storageDirEntry);
|
2006-08-02 13:31:26 +02:00
|
|
|
static void StorageImpl_Destroy(StorageBaseImpl* iface);
|
|
|
|
static BOOL StorageImpl_ReadBigBlock(StorageImpl* This, ULONG blockIndex, void* buffer);
|
2007-07-04 21:12:48 +02:00
|
|
|
static BOOL StorageImpl_WriteBigBlock(StorageImpl* This, ULONG blockIndex, const void* buffer);
|
2006-08-02 13:31:26 +02:00
|
|
|
static void StorageImpl_SetNextBlockInChain(StorageImpl* This, ULONG blockIndex, ULONG nextBlock);
|
|
|
|
static HRESULT StorageImpl_LoadFileHeader(StorageImpl* This);
|
|
|
|
static void StorageImpl_SaveFileHeader(StorageImpl* This);
|
|
|
|
|
|
|
|
static void Storage32Impl_AddBlockDepot(StorageImpl* This, ULONG blockIndex);
|
|
|
|
static ULONG Storage32Impl_AddExtBlockDepot(StorageImpl* This);
|
|
|
|
static ULONG Storage32Impl_GetNextExtendedBlock(StorageImpl* This, ULONG blockIndex);
|
|
|
|
static ULONG Storage32Impl_GetExtDepotBlock(StorageImpl* This, ULONG depotIndex);
|
|
|
|
static void Storage32Impl_SetExtDepotBlock(StorageImpl* This, ULONG depotIndex, ULONG blockIndex);
|
|
|
|
|
|
|
|
static ULONG BlockChainStream_GetHeadOfChain(BlockChainStream* This);
|
|
|
|
static ULARGE_INTEGER BlockChainStream_GetSize(BlockChainStream* This);
|
|
|
|
static ULONG BlockChainStream_GetCount(BlockChainStream* This);
|
|
|
|
|
|
|
|
static ULARGE_INTEGER SmallBlockChainStream_GetSize(SmallBlockChainStream* This);
|
2009-08-19 22:19:10 +02:00
|
|
|
static ULONG SmallBlockChainStream_GetHeadOfChain(SmallBlockChainStream* This);
|
2007-03-16 19:34:28 +01:00
|
|
|
static BOOL StorageImpl_WriteDWordToBigBlock( StorageImpl* This,
|
|
|
|
ULONG blockIndex, ULONG offset, DWORD value);
|
|
|
|
static BOOL StorageImpl_ReadDWordFromBigBlock( StorageImpl* This,
|
|
|
|
ULONG blockIndex, ULONG offset, DWORD* value);
|
2000-02-25 21:58:25 +01:00
|
|
|
|
2009-11-18 17:38:10 +01:00
|
|
|
static BOOL StorageBaseImpl_IsStreamOpen(StorageBaseImpl * stg, DirRef streamEntry);
|
2009-11-19 20:55:34 +01:00
|
|
|
static BOOL StorageBaseImpl_IsStorageOpen(StorageBaseImpl * stg, DirRef storageEntry);
|
2009-11-19 20:42:47 +01:00
|
|
|
static void StorageInternalImpl_Invalidate( StorageInternalImpl *This );
|
2009-11-18 17:38:10 +01:00
|
|
|
|
2000-02-25 21:58:25 +01:00
|
|
|
/* OLESTREAM memory structure to use for Get and Put Routines */
|
|
|
|
/* Used for OleConvertIStorageToOLESTREAM and OleConvertOLESTREAMToIStorage */
|
2002-06-01 01:06:46 +02:00
|
|
|
typedef struct
|
2000-02-25 21:58:25 +01:00
|
|
|
{
|
|
|
|
DWORD dwOleID;
|
|
|
|
DWORD dwTypeID;
|
|
|
|
DWORD dwOleTypeNameLength;
|
|
|
|
CHAR strOleTypeName[OLESTREAM_MAX_STR_LEN];
|
2000-02-29 23:03:14 +01:00
|
|
|
CHAR *pstrOleObjFileName;
|
|
|
|
DWORD dwOleObjFileNameLength;
|
2000-02-25 21:58:25 +01:00
|
|
|
DWORD dwMetaFileWidth;
|
|
|
|
DWORD dwMetaFileHeight;
|
2008-04-09 21:33:37 +02:00
|
|
|
CHAR strUnknown[8]; /* don't know what this 8 byte information in OLE stream is. */
|
2000-02-25 21:58:25 +01:00
|
|
|
DWORD dwDataLength;
|
|
|
|
BYTE *pData;
|
|
|
|
}OLECONVERT_OLESTREAM_DATA;
|
|
|
|
|
|
|
|
/* CompObj Stream structure */
|
|
|
|
/* Used for OleConvertIStorageToOLESTREAM and OleConvertOLESTREAMToIStorage */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
BYTE byUnknown1[12];
|
|
|
|
CLSID clsid;
|
|
|
|
DWORD dwCLSIDNameLength;
|
|
|
|
CHAR strCLSIDName[OLESTREAM_MAX_STR_LEN];
|
|
|
|
DWORD dwOleTypeNameLength;
|
|
|
|
CHAR strOleTypeName[OLESTREAM_MAX_STR_LEN];
|
|
|
|
DWORD dwProgIDNameLength;
|
|
|
|
CHAR strProgIDName[OLESTREAM_MAX_STR_LEN];
|
|
|
|
BYTE byUnknown2[16];
|
|
|
|
}OLECONVERT_ISTORAGE_COMPOBJ;
|
|
|
|
|
|
|
|
|
2008-04-09 21:33:37 +02:00
|
|
|
/* Ole Presentation Stream structure */
|
2000-02-25 21:58:25 +01:00
|
|
|
/* Used for OleConvertIStorageToOLESTREAM and OleConvertOLESTREAMToIStorage */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
BYTE byUnknown1[28];
|
|
|
|
DWORD dwExtentX;
|
|
|
|
DWORD dwExtentY;
|
2002-06-01 01:06:46 +02:00
|
|
|
DWORD dwSize;
|
2000-02-25 21:58:25 +01:00
|
|
|
BYTE *pData;
|
|
|
|
}OLECONVERT_ISTORAGE_OLEPRES;
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* Forward declaration of internal functions used by the method DestroyElement
|
|
|
|
*/
|
2009-11-12 20:46:04 +01:00
|
|
|
static HRESULT deleteStorageContents(
|
2009-10-28 20:53:30 +01:00
|
|
|
StorageBaseImpl *parentStorage,
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef indexToDelete,
|
2009-11-12 20:46:04 +01:00
|
|
|
DirEntry entryDataToDelete);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 20:46:04 +01:00
|
|
|
static HRESULT deleteStreamContents(
|
2009-10-28 20:53:30 +01:00
|
|
|
StorageBaseImpl *parentStorage,
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef indexToDelete,
|
2009-11-12 20:46:04 +01:00
|
|
|
DirEntry entryDataToDelete);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-10-28 20:24:18 +01:00
|
|
|
static HRESULT removeFromTree(
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl *This,
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef parentStorageIndex,
|
|
|
|
DirRef deletedIndex);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
2009-11-10 21:30:59 +01:00
|
|
|
* Declaration of the functions used to manipulate DirEntry
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
|
|
|
|
2009-10-28 19:42:42 +01:00
|
|
|
static HRESULT createDirEntry(
|
|
|
|
StorageImpl *storage,
|
2009-11-10 21:30:59 +01:00
|
|
|
const DirEntry *newData,
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef *index);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-02 19:25:46 +01:00
|
|
|
static HRESULT destroyDirEntry(
|
|
|
|
StorageImpl *storage,
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef index);
|
2009-11-02 19:25:46 +01:00
|
|
|
|
2009-11-02 19:41:09 +01:00
|
|
|
static HRESULT insertIntoTree(
|
|
|
|
StorageImpl *This,
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef parentStorageIndex,
|
|
|
|
DirRef newEntryIndex);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 20:55:49 +01:00
|
|
|
static LONG entryNameCmp(
|
|
|
|
const OLECHAR *name1,
|
|
|
|
const OLECHAR *name2);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 22:53:42 +01:00
|
|
|
static DirRef findElement(
|
2009-10-23 20:57:42 +02:00
|
|
|
StorageImpl *storage,
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef storageEntry,
|
2009-10-23 20:57:42 +02:00
|
|
|
const OLECHAR *name,
|
2009-11-10 21:30:59 +01:00
|
|
|
DirEntry *data);
|
1999-02-13 13:10:15 +01:00
|
|
|
|
2009-10-27 21:31:01 +01:00
|
|
|
static HRESULT findTreeParent(
|
|
|
|
StorageImpl *storage,
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef storageEntry,
|
2009-10-27 21:31:01 +01:00
|
|
|
const OLECHAR *childName,
|
2009-11-10 21:30:59 +01:00
|
|
|
DirEntry *parentData,
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef *parentEntry,
|
2009-10-27 21:31:01 +01:00
|
|
|
ULONG *relation);
|
|
|
|
|
1999-02-13 13:10:15 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* Declaration of miscellaneous functions...
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static HRESULT validateSTGM(DWORD stgmValue);
|
1999-02-13 13:10:15 +01:00
|
|
|
|
|
|
|
static DWORD GetShareModeFromSTGM(DWORD stgm);
|
|
|
|
static DWORD GetAccessModeFromSTGM(DWORD stgm);
|
|
|
|
static DWORD GetCreationModeFromSTGM(DWORD stgm);
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
extern const IPropertySetStorageVtbl IPropertySetStorage_Vtbl;
|
1999-02-13 13:10:15 +01:00
|
|
|
|
|
|
|
|
2006-08-02 13:31:26 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* IEnumSTATSTGImpl definitions.
|
|
|
|
*
|
|
|
|
* Definition of the implementation structure for the IEnumSTATSTGImpl interface.
|
|
|
|
* This class allows iterating through the content of a storage and to find
|
|
|
|
* specific items inside it.
|
|
|
|
*/
|
|
|
|
struct IEnumSTATSTGImpl
|
|
|
|
{
|
|
|
|
const IEnumSTATSTGVtbl *lpVtbl; /* Needs to be the first item in the struct
|
|
|
|
* since we want to cast this in an IEnumSTATSTG pointer */
|
|
|
|
|
|
|
|
LONG ref; /* Reference count */
|
|
|
|
StorageImpl* parentStorage; /* Reference to the parent storage */
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef storageDirEntry; /* Directory entry of the storage to enumerate */
|
2006-08-02 13:31:26 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The current implementation of the IEnumSTATSTGImpl class uses a stack
|
2009-11-12 21:02:20 +01:00
|
|
|
* to walk the directory entries to get the content of a storage. This stack
|
2006-08-02 13:31:26 +02:00
|
|
|
* is implemented by the following 3 data members
|
|
|
|
*/
|
|
|
|
ULONG stackSize;
|
|
|
|
ULONG stackMaxSize;
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef* stackToVisit;
|
2006-08-02 13:31:26 +02:00
|
|
|
|
|
|
|
#define ENUMSTATSGT_SIZE_INCREMENT 10
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-11-12 22:53:42 +01:00
|
|
|
static IEnumSTATSTGImpl* IEnumSTATSTGImpl_Construct(StorageImpl* This, DirRef storageDirEntry);
|
2006-08-02 13:31:26 +02:00
|
|
|
static void IEnumSTATSTGImpl_Destroy(IEnumSTATSTGImpl* This);
|
2009-11-12 22:53:42 +01:00
|
|
|
static void IEnumSTATSTGImpl_PushSearchNode(IEnumSTATSTGImpl* This, DirRef nodeToPush);
|
|
|
|
static DirRef IEnumSTATSTGImpl_PopSearchNode(IEnumSTATSTGImpl* This, BOOL remove);
|
2006-08-02 13:31:26 +02:00
|
|
|
|
2007-03-16 19:34:28 +01:00
|
|
|
/************************************************************************
|
|
|
|
** Block Functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
static ULONG BLOCK_GetBigBlockOffset(ULONG index)
|
|
|
|
{
|
|
|
|
if (index == 0xffffffff)
|
|
|
|
index = 0;
|
|
|
|
else
|
|
|
|
index ++;
|
|
|
|
|
|
|
|
return index * BIG_BLOCK_SIZE;
|
|
|
|
}
|
1999-02-13 13:10:15 +01:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/************************************************************************
|
2008-04-09 21:33:37 +02:00
|
|
|
** Storage32BaseImpl implementation
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2007-03-16 19:34:28 +01:00
|
|
|
static HRESULT StorageImpl_ReadAt(StorageImpl* This,
|
|
|
|
ULARGE_INTEGER offset,
|
|
|
|
void* buffer,
|
|
|
|
ULONG size,
|
|
|
|
ULONG* bytesRead)
|
|
|
|
{
|
|
|
|
return BIGBLOCKFILE_ReadAt(This->bigBlockFile,offset,buffer,size,bytesRead);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT StorageImpl_WriteAt(StorageImpl* This,
|
|
|
|
ULARGE_INTEGER offset,
|
2007-07-04 21:12:48 +02:00
|
|
|
const void* buffer,
|
2007-03-16 19:34:28 +01:00
|
|
|
const ULONG size,
|
|
|
|
ULONG* bytesWritten)
|
|
|
|
{
|
|
|
|
return BIGBLOCKFILE_WriteAt(This->bigBlockFile,offset,buffer,size,bytesWritten);
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* Storage32BaseImpl_QueryInterface (IUnknown)
|
|
|
|
*
|
|
|
|
* This method implements the common QueryInterface for all IStorage32
|
|
|
|
* implementations contained in this file.
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
1999-01-30 14:24:23 +01:00
|
|
|
* See Windows documentation for more details on IUnknown methods.
|
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI StorageBaseImpl_QueryInterface(
|
1999-02-26 12:11:13 +01:00
|
|
|
IStorage* iface,
|
1999-01-30 14:24:23 +01:00
|
|
|
REFIID riid,
|
|
|
|
void** ppvObject)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
StorageBaseImpl *This = (StorageBaseImpl *)iface;
|
2009-10-03 00:21:33 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
if ( (This==0) || (ppvObject==0) )
|
|
|
|
return E_INVALIDARG;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
*ppvObject = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-07-31 20:10:58 +02:00
|
|
|
if (IsEqualGUID(&IID_IUnknown, riid) ||
|
|
|
|
IsEqualGUID(&IID_IStorage, riid))
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-02-11 10:48:38 +01:00
|
|
|
*ppvObject = This;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
2006-07-31 20:10:58 +02:00
|
|
|
else if (IsEqualGUID(&IID_IPropertySetStorage, riid))
|
2005-02-21 21:58:09 +01:00
|
|
|
{
|
2009-02-11 10:48:38 +01:00
|
|
|
*ppvObject = &This->pssVtbl;
|
2005-02-21 21:58:09 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
if ((*ppvObject)==0)
|
|
|
|
return E_NOINTERFACE;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-03-31 17:26:30 +02:00
|
|
|
IStorage_AddRef(iface);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
1999-02-18 14:26:22 +01:00
|
|
|
return S_OK;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/************************************************************************
|
|
|
|
* Storage32BaseImpl_AddRef (IUnknown)
|
|
|
|
*
|
|
|
|
* This method implements the common AddRef for all IStorage32
|
|
|
|
* implementations contained in this file.
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
1999-01-30 14:24:23 +01:00
|
|
|
* See Windows documentation for more details on IUnknown methods.
|
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
static ULONG WINAPI StorageBaseImpl_AddRef(
|
1999-02-26 12:11:13 +01:00
|
|
|
IStorage* iface)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
StorageBaseImpl *This = (StorageBaseImpl *)iface;
|
2005-02-25 14:58:37 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p) AddRef to %d\n", This, ref);
|
2005-02-25 14:58:37 +01:00
|
|
|
|
|
|
|
return ref;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/************************************************************************
|
|
|
|
* Storage32BaseImpl_Release (IUnknown)
|
|
|
|
*
|
|
|
|
* This method implements the common Release for all IStorage32
|
|
|
|
* implementations contained in this file.
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
1999-01-30 14:24:23 +01:00
|
|
|
* See Windows documentation for more details on IUnknown methods.
|
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
static ULONG WINAPI StorageBaseImpl_Release(
|
1999-02-26 12:11:13 +01:00
|
|
|
IStorage* iface)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
StorageBaseImpl *This = (StorageBaseImpl *)iface;
|
2009-10-03 00:21:33 +02:00
|
|
|
|
2004-09-24 03:16:53 +02:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p) ReleaseRef to %d\n", This, ref);
|
2005-02-25 14:58:37 +01:00
|
|
|
|
2004-09-24 03:16:53 +02:00
|
|
|
if (ref == 0)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
/*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Since we are using a system of base-classes, we want to call the
|
|
|
|
* destructor of the appropriate derived class. To do this, we are
|
1999-01-30 14:24:23 +01:00
|
|
|
* using virtual functions to implement the destructor.
|
|
|
|
*/
|
|
|
|
This->v_destructor(This);
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-09-24 03:16:53 +02:00
|
|
|
return ref;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* Storage32BaseImpl_OpenStream (IStorage)
|
|
|
|
*
|
|
|
|
* This method will open the specified stream object from the current storage.
|
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IStorage methods.
|
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI StorageBaseImpl_OpenStream(
|
1999-02-26 12:11:13 +01:00
|
|
|
IStorage* iface,
|
|
|
|
const OLECHAR* pwcsName, /* [string][in] */
|
1999-05-02 13:41:10 +02:00
|
|
|
void* reserved1, /* [unique][in] */
|
2002-06-01 01:06:46 +02:00
|
|
|
DWORD grfMode, /* [in] */
|
|
|
|
DWORD reserved2, /* [in] */
|
|
|
|
IStream** ppstm) /* [out] */
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
StorageBaseImpl *This = (StorageBaseImpl *)iface;
|
1999-01-30 14:24:23 +01:00
|
|
|
StgStreamImpl* newStream;
|
2009-11-12 21:32:35 +01:00
|
|
|
DirEntry currentEntry;
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef streamEntryRef;
|
2002-01-31 22:01:35 +01:00
|
|
|
HRESULT res = STG_E_UNKNOWN;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p, %s, %p, %x, %d, %p)\n",
|
1999-05-02 13:41:10 +02:00
|
|
|
iface, debugstr_w(pwcsName), reserved1, grfMode, reserved2, ppstm);
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
if ( (pwcsName==NULL) || (ppstm==0) )
|
2002-01-31 22:01:35 +01:00
|
|
|
{
|
|
|
|
res = E_INVALIDARG;
|
|
|
|
goto end;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-01-31 22:01:35 +01:00
|
|
|
*ppstm = NULL;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-07-31 18:00:25 +02:00
|
|
|
if ( FAILED( validateSTGM(grfMode) ) ||
|
|
|
|
STGM_SHARE_MODE(grfMode) != STGM_SHARE_EXCLUSIVE)
|
2002-01-31 22:01:35 +01:00
|
|
|
{
|
|
|
|
res = STG_E_INVALIDFLAG;
|
|
|
|
goto end;
|
|
|
|
}
|
1999-02-13 13:10:15 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* As documented.
|
|
|
|
*/
|
2006-07-31 18:00:25 +02:00
|
|
|
if ( (grfMode & STGM_DELETEONRELEASE) || (grfMode & STGM_TRANSACTED) )
|
2002-01-31 22:01:35 +01:00
|
|
|
{
|
|
|
|
res = STG_E_INVALIDFUNCTION;
|
|
|
|
goto end;
|
|
|
|
}
|
1999-02-13 13:10:15 +01:00
|
|
|
|
2009-11-19 20:42:47 +01:00
|
|
|
if (!This->ancestorStorage)
|
|
|
|
{
|
|
|
|
res = STG_E_REVERTED;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2005-05-13 15:58:43 +02:00
|
|
|
/*
|
2006-02-21 09:02:04 +01:00
|
|
|
* Check that we're compatible with the parent's storage mode, but
|
|
|
|
* only if we are not in transacted mode
|
2005-05-13 15:58:43 +02:00
|
|
|
*/
|
2006-02-21 09:02:04 +01:00
|
|
|
if(!(This->ancestorStorage->base.openFlags & STGM_TRANSACTED)) {
|
2006-05-03 15:48:58 +02:00
|
|
|
if ( STGM_ACCESS_MODE( grfMode ) > STGM_ACCESS_MODE( This->openFlags ) )
|
2006-02-21 09:02:04 +01:00
|
|
|
{
|
|
|
|
res = STG_E_ACCESSDENIED;
|
|
|
|
goto end;
|
|
|
|
}
|
2005-05-13 15:58:43 +02:00
|
|
|
}
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
2009-10-23 20:57:42 +02:00
|
|
|
* Search for the element with the given name
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-11-12 21:32:35 +01:00
|
|
|
streamEntryRef = findElement(
|
2002-06-01 01:06:46 +02:00
|
|
|
This->ancestorStorage,
|
2009-11-12 20:19:37 +01:00
|
|
|
This->storageDirEntry,
|
1999-01-30 14:24:23 +01:00
|
|
|
pwcsName,
|
2009-11-12 21:32:35 +01:00
|
|
|
¤tEntry);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* If it was found, construct the stream object and return a pointer to it.
|
|
|
|
*/
|
2009-11-12 21:32:35 +01:00
|
|
|
if ( (streamEntryRef!=DIRENTRY_NULL) &&
|
|
|
|
(currentEntry.stgType==STGTY_STREAM) )
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-18 17:38:10 +01:00
|
|
|
if (StorageBaseImpl_IsStreamOpen(This, streamEntryRef))
|
|
|
|
{
|
|
|
|
/* A single stream cannot be opened a second time. */
|
|
|
|
res = STG_E_ACCESSDENIED;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
newStream = StgStreamImpl_Construct(This, grfMode, streamEntryRef);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
if (newStream!=0)
|
|
|
|
{
|
2000-01-26 03:04:44 +01:00
|
|
|
newStream->grfMode = grfMode;
|
1999-02-26 12:11:13 +01:00
|
|
|
*ppstm = (IStream*)newStream;
|
1999-02-18 14:26:22 +01:00
|
|
|
|
2005-03-31 17:26:30 +02:00
|
|
|
IStream_AddRef(*ppstm);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-01-31 22:01:35 +01:00
|
|
|
res = S_OK;
|
|
|
|
goto end;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-01-31 22:01:35 +01:00
|
|
|
res = E_OUTOFMEMORY;
|
|
|
|
goto end;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-01-31 22:01:35 +01:00
|
|
|
res = STG_E_FILENOTFOUND;
|
|
|
|
|
|
|
|
end:
|
|
|
|
if (res == S_OK)
|
|
|
|
TRACE("<-- IStream %p\n", *ppstm);
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("<-- %08x\n", res);
|
2002-01-31 22:01:35 +01:00
|
|
|
return res;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* Storage32BaseImpl_OpenStorage (IStorage)
|
|
|
|
*
|
|
|
|
* This method will open a new storage object from the current storage.
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
1999-01-30 14:24:23 +01:00
|
|
|
* See Windows documentation for more details on IStorage methods.
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI StorageBaseImpl_OpenStorage(
|
1999-02-26 12:11:13 +01:00
|
|
|
IStorage* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
const OLECHAR* pwcsName, /* [string][unique][in] */
|
|
|
|
IStorage* pstgPriority, /* [unique][in] */
|
|
|
|
DWORD grfMode, /* [in] */
|
|
|
|
SNB snbExclude, /* [unique][in] */
|
|
|
|
DWORD reserved, /* [in] */
|
|
|
|
IStorage** ppstg) /* [out] */
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
StorageBaseImpl *This = (StorageBaseImpl *)iface;
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageInternalImpl* newStorage;
|
2009-11-12 21:32:35 +01:00
|
|
|
DirEntry currentEntry;
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef storageEntryRef;
|
2002-01-31 22:01:35 +01:00
|
|
|
HRESULT res = STG_E_UNKNOWN;
|
1999-05-02 13:41:10 +02:00
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p, %s, %p, %x, %p, %d, %p)\n",
|
2002-06-01 01:06:46 +02:00
|
|
|
iface, debugstr_w(pwcsName), pstgPriority,
|
1999-05-02 13:41:10 +02:00
|
|
|
grfMode, snbExclude, reserved, ppstg);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
if ( (This==0) || (pwcsName==NULL) || (ppstg==0) )
|
2002-01-31 22:01:35 +01:00
|
|
|
{
|
|
|
|
res = E_INVALIDARG;
|
|
|
|
goto end;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-01-31 22:01:35 +01:00
|
|
|
/* as documented */
|
|
|
|
if (snbExclude != NULL)
|
|
|
|
{
|
|
|
|
res = STG_E_INVALIDPARAMETER;
|
|
|
|
goto end;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-02-13 13:10:15 +01:00
|
|
|
if ( FAILED( validateSTGM(grfMode) ))
|
2002-01-31 22:01:35 +01:00
|
|
|
{
|
|
|
|
res = STG_E_INVALIDFLAG;
|
|
|
|
goto end;
|
|
|
|
}
|
1999-02-13 13:10:15 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* As documented.
|
|
|
|
*/
|
2005-03-05 11:48:11 +01:00
|
|
|
if ( STGM_SHARE_MODE(grfMode) != STGM_SHARE_EXCLUSIVE ||
|
1999-02-13 13:10:15 +01:00
|
|
|
(grfMode & STGM_DELETEONRELEASE) ||
|
|
|
|
(grfMode & STGM_PRIORITY) )
|
2002-01-31 22:01:35 +01:00
|
|
|
{
|
|
|
|
res = STG_E_INVALIDFUNCTION;
|
|
|
|
goto end;
|
|
|
|
}
|
1999-02-13 13:10:15 +01:00
|
|
|
|
2009-11-19 20:42:47 +01:00
|
|
|
if (!This->ancestorStorage)
|
|
|
|
return STG_E_REVERTED;
|
|
|
|
|
2005-05-13 15:58:43 +02:00
|
|
|
/*
|
2006-02-21 09:02:04 +01:00
|
|
|
* Check that we're compatible with the parent's storage mode,
|
|
|
|
* but only if we are not transacted
|
2005-05-13 15:58:43 +02:00
|
|
|
*/
|
2006-02-21 09:02:04 +01:00
|
|
|
if(!(This->ancestorStorage->base.openFlags & STGM_TRANSACTED)) {
|
2006-05-03 15:48:58 +02:00
|
|
|
if ( STGM_ACCESS_MODE( grfMode ) > STGM_ACCESS_MODE( This->openFlags ) )
|
2006-02-21 09:02:04 +01:00
|
|
|
{
|
|
|
|
res = STG_E_ACCESSDENIED;
|
|
|
|
goto end;
|
|
|
|
}
|
2005-05-13 15:58:43 +02:00
|
|
|
}
|
|
|
|
|
2002-01-31 22:01:35 +01:00
|
|
|
*ppstg = NULL;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
storageEntryRef = findElement(
|
2009-10-23 20:57:42 +02:00
|
|
|
This->ancestorStorage,
|
2009-11-12 20:19:37 +01:00
|
|
|
This->storageDirEntry,
|
1999-01-30 14:24:23 +01:00
|
|
|
pwcsName,
|
2009-11-12 21:32:35 +01:00
|
|
|
¤tEntry);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
if ( (storageEntryRef!=DIRENTRY_NULL) &&
|
|
|
|
(currentEntry.stgType==STGTY_STORAGE) )
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-19 20:55:34 +01:00
|
|
|
if (StorageBaseImpl_IsStorageOpen(This, storageEntryRef))
|
|
|
|
{
|
|
|
|
/* A single storage cannot be opened a second time. */
|
|
|
|
res = STG_E_ACCESSDENIED;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
newStorage = StorageInternalImpl_Construct(
|
1999-01-30 14:24:23 +01:00
|
|
|
This->ancestorStorage,
|
2005-05-13 15:58:43 +02:00
|
|
|
grfMode,
|
2009-11-12 21:32:35 +01:00
|
|
|
storageEntryRef);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
if (newStorage != 0)
|
|
|
|
{
|
1999-02-26 12:11:13 +01:00
|
|
|
*ppstg = (IStorage*)newStorage;
|
1999-02-18 14:26:22 +01:00
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageBaseImpl_AddRef(*ppstg);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-11-19 20:42:47 +01:00
|
|
|
list_add_tail(&This->storageHead, &newStorage->ParentListEntry);
|
|
|
|
|
2002-01-31 22:01:35 +01:00
|
|
|
res = S_OK;
|
|
|
|
goto end;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-01-31 22:01:35 +01:00
|
|
|
res = STG_E_INSUFFICIENTMEMORY;
|
|
|
|
goto end;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-01-31 22:01:35 +01:00
|
|
|
res = STG_E_FILENOTFOUND;
|
|
|
|
|
|
|
|
end:
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("<-- %08x\n", res);
|
2002-01-31 22:01:35 +01:00
|
|
|
return res;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* Storage32BaseImpl_EnumElements (IStorage)
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* This method will create an enumerator object that can be used to
|
2009-11-12 21:32:35 +01:00
|
|
|
* retrieve information about all the elements in the storage object.
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
1999-01-30 14:24:23 +01:00
|
|
|
* See Windows documentation for more details on IStorage methods.
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI StorageBaseImpl_EnumElements(
|
1999-05-02 13:41:10 +02:00
|
|
|
IStorage* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
DWORD reserved1, /* [in] */
|
|
|
|
void* reserved2, /* [size_is][unique][in] */
|
|
|
|
DWORD reserved3, /* [in] */
|
|
|
|
IEnumSTATSTG** ppenum) /* [out] */
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
StorageBaseImpl *This = (StorageBaseImpl *)iface;
|
1999-01-30 14:24:23 +01:00
|
|
|
IEnumSTATSTGImpl* newEnum;
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p, %d, %p, %d, %p)\n",
|
1999-05-02 13:41:10 +02:00
|
|
|
iface, reserved1, reserved2, reserved3, ppenum);
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
if ( (This==0) || (ppenum==0))
|
|
|
|
return E_INVALIDARG;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-11-19 20:42:47 +01:00
|
|
|
if (!This->ancestorStorage)
|
|
|
|
return STG_E_REVERTED;
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
newEnum = IEnumSTATSTGImpl_Construct(
|
|
|
|
This->ancestorStorage,
|
2009-11-12 20:19:37 +01:00
|
|
|
This->storageDirEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
if (newEnum!=0)
|
|
|
|
{
|
1999-02-18 14:26:22 +01:00
|
|
|
*ppenum = (IEnumSTATSTG*)newEnum;
|
|
|
|
|
2005-03-31 17:26:30 +02:00
|
|
|
IEnumSTATSTG_AddRef(*ppenum);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* Storage32BaseImpl_Stat (IStorage)
|
|
|
|
*
|
|
|
|
* This method will retrieve information about this storage object.
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
1999-01-30 14:24:23 +01:00
|
|
|
* See Windows documentation for more details on IStorage methods.
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI StorageBaseImpl_Stat(
|
1999-02-26 12:11:13 +01:00
|
|
|
IStorage* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
STATSTG* pstatstg, /* [out] */
|
|
|
|
DWORD grfStatFlag) /* [in] */
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
StorageBaseImpl *This = (StorageBaseImpl *)iface;
|
2009-11-12 21:32:35 +01:00
|
|
|
DirEntry currentEntry;
|
2002-01-31 22:01:35 +01:00
|
|
|
BOOL readSuccessful;
|
|
|
|
HRESULT res = STG_E_UNKNOWN;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p, %p, %x)\n",
|
1999-05-02 13:41:10 +02:00
|
|
|
iface, pstatstg, grfStatFlag);
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
if ( (This==0) || (pstatstg==0))
|
2002-01-31 22:01:35 +01:00
|
|
|
{
|
|
|
|
res = E_INVALIDARG;
|
|
|
|
goto end;
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-19 20:42:47 +01:00
|
|
|
if (!This->ancestorStorage)
|
|
|
|
{
|
|
|
|
res = STG_E_REVERTED;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2009-11-10 21:39:10 +01:00
|
|
|
readSuccessful = StorageImpl_ReadDirEntry(
|
1999-01-30 14:24:23 +01:00
|
|
|
This->ancestorStorage,
|
2009-11-12 20:19:37 +01:00
|
|
|
This->storageDirEntry,
|
2009-11-12 21:32:35 +01:00
|
|
|
¤tEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-01-29 22:12:58 +01:00
|
|
|
if (readSuccessful)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-10 21:49:47 +01:00
|
|
|
StorageUtl_CopyDirEntryToSTATSTG(
|
2002-06-01 01:06:46 +02:00
|
|
|
pstatstg,
|
2009-11-12 21:32:35 +01:00
|
|
|
¤tEntry,
|
1999-01-30 14:24:23 +01:00
|
|
|
grfStatFlag);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-05-03 15:49:51 +02:00
|
|
|
pstatstg->grfMode = This->openFlags;
|
2007-06-07 20:17:56 +02:00
|
|
|
pstatstg->grfStateBits = This->stateBits;
|
2006-05-03 15:49:51 +02:00
|
|
|
|
2002-01-31 22:01:35 +01:00
|
|
|
res = S_OK;
|
|
|
|
goto end;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-01-31 22:01:35 +01:00
|
|
|
res = E_FAIL;
|
|
|
|
|
|
|
|
end:
|
|
|
|
if (res == S_OK)
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("<-- STATSTG: pwcsName: %s, type: %d, cbSize.Low/High: %d/%d, grfMode: %08x, grfLocksSupported: %d, grfStateBits: %08x\n", debugstr_w(pstatstg->pwcsName), pstatstg->type, pstatstg->cbSize.u.LowPart, pstatstg->cbSize.u.HighPart, pstatstg->grfMode, pstatstg->grfLocksSupported, pstatstg->grfStateBits);
|
2002-01-31 22:01:35 +01:00
|
|
|
}
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("<-- %08x\n", res);
|
2002-01-31 22:01:35 +01:00
|
|
|
return res;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* Storage32BaseImpl_RenameElement (IStorage)
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* This method will rename the specified element.
|
1999-01-30 14:24:23 +01:00
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IStorage methods.
|
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI StorageBaseImpl_RenameElement(
|
1999-02-26 12:11:13 +01:00
|
|
|
IStorage* iface,
|
|
|
|
const OLECHAR* pwcsOldName, /* [in] */
|
|
|
|
const OLECHAR* pwcsNewName) /* [in] */
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
StorageBaseImpl *This = (StorageBaseImpl *)iface;
|
2009-11-12 21:32:35 +01:00
|
|
|
DirEntry currentEntry;
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef currentEntryRef;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
TRACE("(%p, %s, %s)\n",
|
1999-05-02 13:41:10 +02:00
|
|
|
iface, debugstr_w(pwcsOldName), debugstr_w(pwcsNewName));
|
|
|
|
|
2009-11-19 20:42:47 +01:00
|
|
|
if (!This->ancestorStorage)
|
|
|
|
return STG_E_REVERTED;
|
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
currentEntryRef = findElement(This->ancestorStorage,
|
2009-11-12 20:19:37 +01:00
|
|
|
This->storageDirEntry,
|
2009-10-23 20:57:42 +02:00
|
|
|
pwcsNewName,
|
2009-11-12 21:32:35 +01:00
|
|
|
¤tEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
if (currentEntryRef != DIRENTRY_NULL)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
/*
|
2009-11-12 21:32:35 +01:00
|
|
|
* There is already an element with the new name
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
|
|
|
return STG_E_FILEALREADYEXISTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-10-23 20:57:42 +02:00
|
|
|
* Search for the old element name
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-11-12 21:32:35 +01:00
|
|
|
currentEntryRef = findElement(This->ancestorStorage,
|
2009-11-12 20:19:37 +01:00
|
|
|
This->storageDirEntry,
|
2009-10-23 20:57:42 +02:00
|
|
|
pwcsOldName,
|
2009-11-12 21:32:35 +01:00
|
|
|
¤tEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
if (currentEntryRef != DIRENTRY_NULL)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-19 20:57:43 +01:00
|
|
|
if (StorageBaseImpl_IsStreamOpen(This, currentEntryRef) ||
|
|
|
|
StorageBaseImpl_IsStorageOpen(This, currentEntryRef))
|
2009-11-18 18:19:18 +01:00
|
|
|
{
|
2009-11-19 20:57:43 +01:00
|
|
|
WARN("Element is already open; cannot rename.\n");
|
2009-11-18 18:19:18 +01:00
|
|
|
return STG_E_ACCESSDENIED;
|
|
|
|
}
|
|
|
|
|
2009-11-02 19:48:02 +01:00
|
|
|
/* Remove the element from its current position in the tree */
|
2009-11-12 20:19:37 +01:00
|
|
|
removeFromTree(This->ancestorStorage, This->storageDirEntry,
|
2009-11-12 21:32:35 +01:00
|
|
|
currentEntryRef);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-11-02 19:48:02 +01:00
|
|
|
/* Change the name of the element */
|
2009-11-12 21:32:35 +01:00
|
|
|
strcpyW(currentEntry.name, pwcsNewName);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
StorageImpl_WriteDirEntry(This->ancestorStorage, currentEntryRef,
|
|
|
|
¤tEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-02 19:48:02 +01:00
|
|
|
/* Insert the element in a new position in the tree */
|
2009-11-12 20:19:37 +01:00
|
|
|
insertIntoTree(This->ancestorStorage, This->storageDirEntry,
|
2009-11-12 21:32:35 +01:00
|
|
|
currentEntryRef);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
2009-11-12 21:32:35 +01:00
|
|
|
* There is no element with the old name
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
|
|
|
return STG_E_FILENOTFOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* Storage32BaseImpl_CreateStream (IStorage)
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* This method will create a stream object within this storage
|
1999-01-30 14:24:23 +01:00
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IStorage methods.
|
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI StorageBaseImpl_CreateStream(
|
1999-02-26 12:11:13 +01:00
|
|
|
IStorage* iface,
|
|
|
|
const OLECHAR* pwcsName, /* [string][in] */
|
1999-05-02 13:41:10 +02:00
|
|
|
DWORD grfMode, /* [in] */
|
|
|
|
DWORD reserved1, /* [in] */
|
|
|
|
DWORD reserved2, /* [in] */
|
1999-02-26 12:11:13 +01:00
|
|
|
IStream** ppstm) /* [out] */
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
StorageBaseImpl *This = (StorageBaseImpl *)iface;
|
1999-01-30 14:24:23 +01:00
|
|
|
StgStreamImpl* newStream;
|
2009-11-12 21:32:35 +01:00
|
|
|
DirEntry currentEntry, newStreamEntry;
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef currentEntryRef, newStreamEntryRef;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p, %s, %x, %d, %d, %p)\n",
|
2002-06-01 01:06:46 +02:00
|
|
|
iface, debugstr_w(pwcsName), grfMode,
|
1999-05-02 13:41:10 +02:00
|
|
|
reserved1, reserved2, ppstm);
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
if (ppstm == 0)
|
|
|
|
return STG_E_INVALIDPOINTER;
|
|
|
|
|
|
|
|
if (pwcsName == 0)
|
|
|
|
return STG_E_INVALIDNAME;
|
|
|
|
|
2005-01-11 11:44:28 +01:00
|
|
|
if (reserved1 || reserved2)
|
|
|
|
return STG_E_INVALIDPARAMETER;
|
|
|
|
|
1999-02-13 13:10:15 +01:00
|
|
|
if ( FAILED( validateSTGM(grfMode) ))
|
|
|
|
return STG_E_INVALIDFLAG;
|
|
|
|
|
2005-03-05 11:48:11 +01:00
|
|
|
if (STGM_SHARE_MODE(grfMode) != STGM_SHARE_EXCLUSIVE)
|
2005-01-11 11:44:28 +01:00
|
|
|
return STG_E_INVALIDFLAG;
|
|
|
|
|
2009-11-19 20:42:47 +01:00
|
|
|
if (!This->ancestorStorage)
|
|
|
|
return STG_E_REVERTED;
|
|
|
|
|
1999-02-13 13:10:15 +01:00
|
|
|
/*
|
|
|
|
* As documented.
|
|
|
|
*/
|
2005-01-11 11:44:28 +01:00
|
|
|
if ((grfMode & STGM_DELETEONRELEASE) ||
|
|
|
|
(grfMode & STGM_TRANSACTED))
|
1999-02-13 13:10:15 +01:00
|
|
|
return STG_E_INVALIDFUNCTION;
|
|
|
|
|
2009-05-29 23:30:56 +02:00
|
|
|
/* Can't create a stream on read-only storage */
|
|
|
|
if ( STGM_ACCESS_MODE( This->openFlags ) == STGM_READ )
|
|
|
|
return STG_E_ACCESSDENIED;
|
|
|
|
|
2005-05-13 15:58:43 +02:00
|
|
|
/*
|
|
|
|
* Check that we're compatible with the parent's storage mode
|
2006-02-21 09:02:04 +01:00
|
|
|
* if not in transacted mode
|
2005-05-13 15:58:43 +02:00
|
|
|
*/
|
2006-05-03 15:48:58 +02:00
|
|
|
if(!(This->ancestorStorage->base.openFlags & STGM_TRANSACTED)) {
|
|
|
|
if ( STGM_ACCESS_MODE( grfMode ) > STGM_ACCESS_MODE( This->openFlags ) )
|
2006-02-21 09:02:04 +01:00
|
|
|
return STG_E_ACCESSDENIED;
|
|
|
|
}
|
2005-05-13 15:58:43 +02:00
|
|
|
|
2009-06-01 12:06:10 +02:00
|
|
|
if(This->ancestorStorage->base.openFlags & STGM_SIMPLE)
|
|
|
|
if(grfMode & STGM_CREATE) return STG_E_INVALIDFLAG;
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
*ppstm = 0;
|
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
currentEntryRef = findElement(This->ancestorStorage,
|
2009-11-12 20:19:37 +01:00
|
|
|
This->storageDirEntry,
|
2009-10-23 20:57:42 +02:00
|
|
|
pwcsName,
|
2009-11-12 21:32:35 +01:00
|
|
|
¤tEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
if (currentEntryRef != DIRENTRY_NULL)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
/*
|
2002-06-01 01:06:46 +02:00
|
|
|
* An element with this name already exists
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2005-03-05 11:48:11 +01:00
|
|
|
if (STGM_CREATE_MODE(grfMode) == STGM_CREATE)
|
1999-05-02 13:41:10 +02:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
IStorage_DestroyElement(iface, pwcsName);
|
1999-05-02 13:41:10 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
else
|
1999-01-30 14:24:23 +01:00
|
|
|
return STG_E_FILEALREADYEXISTS;
|
|
|
|
}
|
2006-05-03 15:49:17 +02:00
|
|
|
else if (STGM_ACCESS_MODE(This->openFlags) == STGM_READ)
|
|
|
|
{
|
|
|
|
WARN("read-only storage\n");
|
|
|
|
return STG_E_ACCESSDENIED;
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
2009-11-12 21:32:35 +01:00
|
|
|
* memset the empty entry
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-11-12 21:32:35 +01:00
|
|
|
memset(&newStreamEntry, 0, sizeof(DirEntry));
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
newStreamEntry.sizeOfNameString =
|
1999-02-26 12:11:13 +01:00
|
|
|
( lstrlenW(pwcsName)+1 ) * sizeof(WCHAR);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
if (newStreamEntry.sizeOfNameString > DIRENTRY_NAME_BUFFER_LEN)
|
1999-01-30 14:24:23 +01:00
|
|
|
return STG_E_INVALIDNAME;
|
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
strcpyW(newStreamEntry.name, pwcsName);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
newStreamEntry.stgType = STGTY_STREAM;
|
|
|
|
newStreamEntry.startingBlock = BLOCK_END_OF_CHAIN;
|
|
|
|
newStreamEntry.size.u.LowPart = 0;
|
|
|
|
newStreamEntry.size.u.HighPart = 0;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
newStreamEntry.leftChild = DIRENTRY_NULL;
|
|
|
|
newStreamEntry.rightChild = DIRENTRY_NULL;
|
|
|
|
newStreamEntry.dirRootEntry = DIRENTRY_NULL;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/* call CoFileTime to get the current time
|
2009-11-12 21:32:35 +01:00
|
|
|
newStreamEntry.ctime
|
|
|
|
newStreamEntry.mtime
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
/* newStreamEntry.clsid */
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
2009-11-12 21:32:35 +01:00
|
|
|
* Create an entry with the new data
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
2009-11-12 21:32:35 +01:00
|
|
|
createDirEntry(This->ancestorStorage, &newStreamEntry, &newStreamEntryRef);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
2009-11-12 21:32:35 +01:00
|
|
|
* Insert the new entry in the parent storage's tree.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-11-02 19:41:09 +01:00
|
|
|
insertIntoTree(
|
|
|
|
This->ancestorStorage,
|
2009-11-12 20:19:37 +01:00
|
|
|
This->storageDirEntry,
|
2009-11-12 21:32:35 +01:00
|
|
|
newStreamEntryRef);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
1999-01-30 14:24:23 +01:00
|
|
|
* Open the stream to return it.
|
|
|
|
*/
|
2009-11-12 21:32:35 +01:00
|
|
|
newStream = StgStreamImpl_Construct(This, grfMode, newStreamEntryRef);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
if (newStream != 0)
|
|
|
|
{
|
1999-02-26 12:11:13 +01:00
|
|
|
*ppstm = (IStream*)newStream;
|
1999-02-18 14:26:22 +01:00
|
|
|
|
2005-03-31 17:26:30 +02:00
|
|
|
IStream_AddRef(*ppstm);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return STG_E_INSUFFICIENTMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* Storage32BaseImpl_SetClass (IStorage)
|
|
|
|
*
|
2009-11-12 21:32:35 +01:00
|
|
|
* This method will write the specified CLSID in the directory entry of this
|
1999-01-30 14:24:23 +01:00
|
|
|
* storage.
|
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IStorage methods.
|
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI StorageBaseImpl_SetClass(
|
1999-02-26 12:11:13 +01:00
|
|
|
IStorage* iface,
|
1999-05-02 13:41:10 +02:00
|
|
|
REFCLSID clsid) /* [in] */
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
StorageBaseImpl *This = (StorageBaseImpl *)iface;
|
1999-01-30 14:24:23 +01:00
|
|
|
HRESULT hRes = E_FAIL;
|
2009-11-12 21:32:35 +01:00
|
|
|
DirEntry currentEntry;
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL success;
|
1999-05-02 13:41:10 +02:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p, %p)\n", iface, clsid);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-11-19 20:42:47 +01:00
|
|
|
if (!This->ancestorStorage)
|
|
|
|
return STG_E_REVERTED;
|
|
|
|
|
2009-11-10 21:39:10 +01:00
|
|
|
success = StorageImpl_ReadDirEntry(This->ancestorStorage,
|
2009-11-12 20:19:37 +01:00
|
|
|
This->storageDirEntry,
|
2009-11-12 21:32:35 +01:00
|
|
|
¤tEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
if (success)
|
|
|
|
{
|
2009-11-12 21:32:35 +01:00
|
|
|
currentEntry.clsid = *clsid;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-10 21:40:05 +01:00
|
|
|
success = StorageImpl_WriteDirEntry(This->ancestorStorage,
|
2009-11-12 20:19:37 +01:00
|
|
|
This->storageDirEntry,
|
2009-11-12 21:32:35 +01:00
|
|
|
¤tEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
if (success)
|
|
|
|
hRes = S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hRes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
** Storage32Impl implementation
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/************************************************************************
|
2009-10-28 20:35:24 +01:00
|
|
|
* Storage32BaseImpl_CreateStorage (IStorage)
|
1999-01-30 14:24:23 +01:00
|
|
|
*
|
|
|
|
* This method will create the storage object within the provided storage.
|
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IStorage methods.
|
|
|
|
*/
|
2009-10-28 20:35:24 +01:00
|
|
|
static HRESULT WINAPI StorageBaseImpl_CreateStorage(
|
1999-02-26 12:11:13 +01:00
|
|
|
IStorage* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
const OLECHAR *pwcsName, /* [string][in] */
|
|
|
|
DWORD grfMode, /* [in] */
|
|
|
|
DWORD reserved1, /* [in] */
|
|
|
|
DWORD reserved2, /* [in] */
|
|
|
|
IStorage **ppstg) /* [out] */
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-10-28 20:35:24 +01:00
|
|
|
StorageBaseImpl* const This=(StorageBaseImpl*)iface;
|
1999-02-18 14:26:22 +01:00
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
DirEntry currentEntry;
|
|
|
|
DirEntry newEntry;
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef currentEntryRef;
|
|
|
|
DirRef newEntryRef;
|
1999-01-30 14:24:23 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p, %s, %x, %d, %d, %p)\n",
|
2002-06-01 01:06:46 +02:00
|
|
|
iface, debugstr_w(pwcsName), grfMode,
|
1999-05-02 13:41:10 +02:00
|
|
|
reserved1, reserved2, ppstg);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
if (ppstg == 0)
|
|
|
|
return STG_E_INVALIDPOINTER;
|
|
|
|
|
|
|
|
if (pwcsName == 0)
|
|
|
|
return STG_E_INVALIDNAME;
|
|
|
|
|
2005-09-22 12:34:40 +02:00
|
|
|
*ppstg = NULL;
|
|
|
|
|
1999-02-13 13:10:15 +01:00
|
|
|
if ( FAILED( validateSTGM(grfMode) ) ||
|
|
|
|
(grfMode & STGM_DELETEONRELEASE) )
|
2005-09-22 12:34:40 +02:00
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
WARN("bad grfMode: 0x%x\n", grfMode);
|
1999-02-13 13:10:15 +01:00
|
|
|
return STG_E_INVALIDFLAG;
|
2005-09-22 12:34:40 +02:00
|
|
|
}
|
1999-02-13 13:10:15 +01:00
|
|
|
|
2009-11-19 20:42:47 +01:00
|
|
|
if (!This->ancestorStorage)
|
|
|
|
return STG_E_REVERTED;
|
|
|
|
|
2005-05-13 15:58:43 +02:00
|
|
|
/*
|
|
|
|
* Check that we're compatible with the parent's storage mode
|
|
|
|
*/
|
2009-10-28 20:35:24 +01:00
|
|
|
if ( STGM_ACCESS_MODE( grfMode ) > STGM_ACCESS_MODE( This->openFlags ) )
|
2005-09-22 12:34:40 +02:00
|
|
|
{
|
|
|
|
WARN("access denied\n");
|
2005-05-13 15:58:43 +02:00
|
|
|
return STG_E_ACCESSDENIED;
|
2005-09-22 12:34:40 +02:00
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
currentEntryRef = findElement(This->ancestorStorage,
|
2009-11-12 20:19:37 +01:00
|
|
|
This->storageDirEntry,
|
2009-10-23 20:57:42 +02:00
|
|
|
pwcsName,
|
2009-11-12 21:32:35 +01:00
|
|
|
¤tEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
if (currentEntryRef != DIRENTRY_NULL)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
/*
|
2002-06-01 01:06:46 +02:00
|
|
|
* An element with this name already exists
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-05-29 23:40:15 +02:00
|
|
|
if (STGM_CREATE_MODE(grfMode) == STGM_CREATE &&
|
2009-10-28 20:35:24 +01:00
|
|
|
STGM_ACCESS_MODE(This->openFlags) != STGM_READ)
|
2009-05-29 23:54:06 +02:00
|
|
|
{
|
|
|
|
hr = IStorage_DestroyElement(iface, pwcsName);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
else
|
2005-09-22 12:34:40 +02:00
|
|
|
{
|
|
|
|
WARN("file already exists\n");
|
1999-01-30 14:24:23 +01:00
|
|
|
return STG_E_FILEALREADYEXISTS;
|
2005-09-22 12:34:40 +02:00
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
2009-10-28 20:35:24 +01:00
|
|
|
else if (STGM_ACCESS_MODE(This->openFlags) == STGM_READ)
|
2006-05-03 15:49:17 +02:00
|
|
|
{
|
|
|
|
WARN("read-only storage\n");
|
|
|
|
return STG_E_ACCESSDENIED;
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
memset(&newEntry, 0, sizeof(DirEntry));
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
newEntry.sizeOfNameString = (lstrlenW(pwcsName)+1)*sizeof(WCHAR);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
if (newEntry.sizeOfNameString > DIRENTRY_NAME_BUFFER_LEN)
|
2005-09-22 12:34:40 +02:00
|
|
|
{
|
|
|
|
FIXME("name too long\n");
|
1999-01-30 14:24:23 +01:00
|
|
|
return STG_E_INVALIDNAME;
|
2005-09-22 12:34:40 +02:00
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
strcpyW(newEntry.name, pwcsName);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
newEntry.stgType = STGTY_STORAGE;
|
|
|
|
newEntry.startingBlock = BLOCK_END_OF_CHAIN;
|
|
|
|
newEntry.size.u.LowPart = 0;
|
|
|
|
newEntry.size.u.HighPart = 0;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
newEntry.leftChild = DIRENTRY_NULL;
|
|
|
|
newEntry.rightChild = DIRENTRY_NULL;
|
|
|
|
newEntry.dirRootEntry = DIRENTRY_NULL;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/* call CoFileTime to get the current time
|
2009-11-12 21:32:35 +01:00
|
|
|
newEntry.ctime
|
|
|
|
newEntry.mtime
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
/* newEntry.clsid */
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
2009-11-12 21:32:35 +01:00
|
|
|
* Create a new directory entry for the storage
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
2009-11-12 21:32:35 +01:00
|
|
|
createDirEntry(This->ancestorStorage, &newEntry, &newEntryRef);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
2009-11-12 21:32:35 +01:00
|
|
|
* Insert the new directory entry into the parent storage's tree
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-11-02 19:41:09 +01:00
|
|
|
insertIntoTree(
|
|
|
|
This->ancestorStorage,
|
2009-11-12 20:19:37 +01:00
|
|
|
This->storageDirEntry,
|
2009-11-12 21:32:35 +01:00
|
|
|
newEntryRef);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
1999-01-30 14:24:23 +01:00
|
|
|
* Open it to get a pointer to return.
|
|
|
|
*/
|
2008-01-14 23:02:11 +01:00
|
|
|
hr = IStorage_OpenStorage(iface, pwcsName, 0, grfMode, 0, 0, ppstg);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
if( (hr != S_OK) || (*ppstg == NULL))
|
|
|
|
{
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
*
|
|
|
|
* Internal Method
|
|
|
|
*
|
2009-10-28 19:42:42 +01:00
|
|
|
* Reserve a directory entry in the file and initialize it.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-10-28 19:42:42 +01:00
|
|
|
static HRESULT createDirEntry(
|
|
|
|
StorageImpl *storage,
|
2009-11-10 21:30:59 +01:00
|
|
|
const DirEntry *newData,
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef *index)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-12 21:47:07 +01:00
|
|
|
ULONG currentEntryIndex = 0;
|
|
|
|
ULONG newEntryIndex = DIRENTRY_NULL;
|
2009-10-28 19:42:42 +01:00
|
|
|
HRESULT hr = S_OK;
|
2009-11-11 17:34:45 +01:00
|
|
|
BYTE currentData[RAW_DIRENTRY_SIZE];
|
2009-10-28 18:49:09 +01:00
|
|
|
WORD sizeOfNameString;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2009-10-28 21:01:32 +01:00
|
|
|
hr = StorageImpl_ReadRawDirEntry(storage,
|
2009-11-12 21:47:07 +01:00
|
|
|
currentEntryIndex,
|
2009-10-28 19:42:42 +01:00
|
|
|
currentData);
|
2009-10-28 18:49:09 +01:00
|
|
|
|
2009-10-28 19:42:42 +01:00
|
|
|
if (SUCCEEDED(hr))
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-10-28 18:49:09 +01:00
|
|
|
StorageUtl_ReadWord(
|
|
|
|
currentData,
|
|
|
|
OFFSET_PS_NAMELENGTH,
|
|
|
|
&sizeOfNameString);
|
|
|
|
|
|
|
|
if (sizeOfNameString == 0)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
2009-11-12 21:47:07 +01:00
|
|
|
* The entry exists and is available, we found it.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-11-12 21:47:07 +01:00
|
|
|
newEntryIndex = currentEntryIndex;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
2009-11-12 21:47:07 +01:00
|
|
|
* We exhausted the directory entries, we will create more space below
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-11-12 21:47:07 +01:00
|
|
|
newEntryIndex = currentEntryIndex;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
2009-11-12 21:47:07 +01:00
|
|
|
currentEntryIndex++;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 21:47:07 +01:00
|
|
|
} while (newEntryIndex == DIRENTRY_NULL);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
2009-11-12 21:47:07 +01:00
|
|
|
* grow the directory stream
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-10-28 19:42:42 +01:00
|
|
|
if (FAILED(hr))
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-11 17:34:45 +01:00
|
|
|
BYTE emptyData[RAW_DIRENTRY_SIZE];
|
1999-01-30 14:24:23 +01:00
|
|
|
ULARGE_INTEGER newSize;
|
2009-11-12 21:47:07 +01:00
|
|
|
ULONG entryIndex;
|
|
|
|
ULONG lastEntry = 0;
|
1999-01-30 14:24:23 +01:00
|
|
|
ULONG blockCount = 0;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
2009-11-12 21:47:07 +01:00
|
|
|
* obtain the new count of blocks in the directory stream
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
|
|
|
blockCount = BlockChainStream_GetCount(
|
2009-10-28 21:01:32 +01:00
|
|
|
storage->rootBlockChain)+1;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
2009-11-12 21:47:07 +01:00
|
|
|
* initialize the size used by the directory stream
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2004-01-23 02:51:33 +01:00
|
|
|
newSize.u.HighPart = 0;
|
|
|
|
newSize.u.LowPart = storage->bigBlockSize * blockCount;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
2009-11-12 21:47:07 +01:00
|
|
|
* add a block to the directory stream
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-10-28 21:01:32 +01:00
|
|
|
BlockChainStream_SetSize(storage->rootBlockChain, newSize);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
2009-11-12 21:47:07 +01:00
|
|
|
* memset the empty entry in order to initialize the unused newly
|
|
|
|
* created entries
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-11-11 17:34:45 +01:00
|
|
|
memset(&emptyData, 0, RAW_DIRENTRY_SIZE);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
1999-01-30 14:24:23 +01:00
|
|
|
* initialize them
|
|
|
|
*/
|
2009-11-12 21:47:07 +01:00
|
|
|
lastEntry = storage->bigBlockSize / RAW_DIRENTRY_SIZE * blockCount;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
for(
|
2009-11-12 21:47:07 +01:00
|
|
|
entryIndex = newEntryIndex + 1;
|
|
|
|
entryIndex < lastEntry;
|
|
|
|
entryIndex++)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-10-28 18:49:09 +01:00
|
|
|
StorageImpl_WriteRawDirEntry(
|
2009-10-28 21:01:32 +01:00
|
|
|
storage,
|
2009-11-12 21:47:07 +01:00
|
|
|
entryIndex,
|
2009-10-28 18:49:09 +01:00
|
|
|
emptyData);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-28 19:42:42 +01:00
|
|
|
UpdateRawDirEntry(currentData, newData);
|
|
|
|
|
2009-11-12 21:47:07 +01:00
|
|
|
hr = StorageImpl_WriteRawDirEntry(storage, newEntryIndex, currentData);
|
2009-10-28 19:42:42 +01:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
2009-11-12 21:47:07 +01:00
|
|
|
*index = newEntryIndex;
|
2009-10-28 19:42:42 +01:00
|
|
|
|
|
|
|
return hr;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
2009-11-02 19:25:46 +01:00
|
|
|
/***************************************************************************
|
|
|
|
*
|
|
|
|
* Internal Method
|
|
|
|
*
|
|
|
|
* Mark a directory entry in the file as free.
|
|
|
|
*/
|
|
|
|
static HRESULT destroyDirEntry(
|
|
|
|
StorageImpl *storage,
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef index)
|
2009-11-02 19:25:46 +01:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
2009-11-11 17:34:45 +01:00
|
|
|
BYTE emptyData[RAW_DIRENTRY_SIZE];
|
2009-11-02 19:25:46 +01:00
|
|
|
|
2009-11-11 17:34:45 +01:00
|
|
|
memset(&emptyData, 0, RAW_DIRENTRY_SIZE);
|
2009-11-02 19:25:46 +01:00
|
|
|
|
|
|
|
hr = StorageImpl_WriteRawDirEntry(storage, index, emptyData);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* Internal Method
|
|
|
|
*
|
2009-11-10 21:30:59 +01:00
|
|
|
* Case insensitive comparison of DirEntry.name by first considering
|
1999-01-30 14:24:23 +01:00
|
|
|
* their size.
|
|
|
|
*
|
2009-11-12 20:55:49 +01:00
|
|
|
* Returns <0 when name1 < name2
|
|
|
|
* >0 when name1 > name2
|
|
|
|
* 0 when name1 == name2
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-11-12 20:55:49 +01:00
|
|
|
static LONG entryNameCmp(
|
|
|
|
const OLECHAR *name1,
|
|
|
|
const OLECHAR *name2)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-12 20:55:49 +01:00
|
|
|
LONG diff = lstrlenW(name1) - lstrlenW(name2);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if (diff == 0)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
2003-07-09 04:52:57 +02:00
|
|
|
* We compare the string themselves only when they are of the same length
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-11-12 20:55:49 +01:00
|
|
|
diff = lstrcmpiW( name1, name2);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
return diff;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* Internal Method
|
|
|
|
*
|
2009-11-12 21:47:07 +01:00
|
|
|
* Add a directory entry to a storage
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-11-02 19:41:09 +01:00
|
|
|
static HRESULT insertIntoTree(
|
|
|
|
StorageImpl *This,
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef parentStorageIndex,
|
|
|
|
DirRef newEntryIndex)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-12 20:51:17 +01:00
|
|
|
DirEntry currentEntry;
|
|
|
|
DirEntry newEntry;
|
2009-11-02 19:41:09 +01:00
|
|
|
|
|
|
|
/*
|
2009-11-12 21:47:07 +01:00
|
|
|
* Read the inserted entry
|
2009-11-02 19:41:09 +01:00
|
|
|
*/
|
2009-11-10 21:39:10 +01:00
|
|
|
StorageImpl_ReadDirEntry(This,
|
2009-11-12 20:51:17 +01:00
|
|
|
newEntryIndex,
|
|
|
|
&newEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
2009-11-12 21:47:07 +01:00
|
|
|
* Read the storage entry
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-11-10 21:39:10 +01:00
|
|
|
StorageImpl_ReadDirEntry(This,
|
2009-11-02 19:41:09 +01:00
|
|
|
parentStorageIndex,
|
2009-11-12 20:51:17 +01:00
|
|
|
¤tEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 20:51:17 +01:00
|
|
|
if (currentEntry.dirRootEntry != DIRENTRY_NULL)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
1999-01-30 14:24:23 +01:00
|
|
|
* The root storage contains some element, therefore, start the research
|
|
|
|
* for the appropriate location.
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL found = 0;
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef current, next, previous, currentEntryId;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
2009-11-12 21:47:07 +01:00
|
|
|
* Keep a reference to the root of the storage's element tree
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-11-12 20:51:17 +01:00
|
|
|
currentEntryId = currentEntry.dirRootEntry;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Read
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-11-10 21:39:10 +01:00
|
|
|
StorageImpl_ReadDirEntry(This,
|
2009-11-12 20:51:17 +01:00
|
|
|
currentEntry.dirRootEntry,
|
|
|
|
¤tEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 20:51:17 +01:00
|
|
|
previous = currentEntry.leftChild;
|
|
|
|
next = currentEntry.rightChild;
|
|
|
|
current = currentEntryId;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
while (found == 0)
|
|
|
|
{
|
2009-11-12 20:55:49 +01:00
|
|
|
LONG diff = entryNameCmp( newEntry.name, currentEntry.name);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
if (diff < 0)
|
|
|
|
{
|
2009-11-10 21:55:25 +01:00
|
|
|
if (previous != DIRENTRY_NULL)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-10 21:39:10 +01:00
|
|
|
StorageImpl_ReadDirEntry(This,
|
1999-01-30 14:24:23 +01:00
|
|
|
previous,
|
2009-11-12 20:51:17 +01:00
|
|
|
¤tEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
current = previous;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-11-12 20:51:17 +01:00
|
|
|
currentEntry.leftChild = newEntryIndex;
|
2009-11-10 21:40:05 +01:00
|
|
|
StorageImpl_WriteDirEntry(This,
|
1999-01-30 14:24:23 +01:00
|
|
|
current,
|
2009-11-12 20:51:17 +01:00
|
|
|
¤tEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
}
|
1999-05-02 13:41:10 +02:00
|
|
|
else if (diff > 0)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-10 21:55:25 +01:00
|
|
|
if (next != DIRENTRY_NULL)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-10 21:39:10 +01:00
|
|
|
StorageImpl_ReadDirEntry(This,
|
1999-01-30 14:24:23 +01:00
|
|
|
next,
|
2009-11-12 20:51:17 +01:00
|
|
|
¤tEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
current = next;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-11-12 20:51:17 +01:00
|
|
|
currentEntry.rightChild = newEntryIndex;
|
2009-11-10 21:40:05 +01:00
|
|
|
StorageImpl_WriteDirEntry(This,
|
1999-01-30 14:24:23 +01:00
|
|
|
current,
|
2009-11-12 20:51:17 +01:00
|
|
|
¤tEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
}
|
1999-05-02 13:41:10 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Trying to insert an item with the same name in the
|
|
|
|
* subtree structure.
|
|
|
|
*/
|
2009-11-02 19:41:09 +01:00
|
|
|
return STG_E_FILEALREADYEXISTS;
|
1999-05-02 13:41:10 +02:00
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 20:51:17 +01:00
|
|
|
previous = currentEntry.leftChild;
|
|
|
|
next = currentEntry.rightChild;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
2009-11-12 21:47:07 +01:00
|
|
|
* The storage is empty, make the new entry the root of its element tree
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-11-12 20:51:17 +01:00
|
|
|
currentEntry.dirRootEntry = newEntryIndex;
|
2009-11-10 21:40:05 +01:00
|
|
|
StorageImpl_WriteDirEntry(This,
|
2009-11-02 19:41:09 +01:00
|
|
|
parentStorageIndex,
|
2009-11-12 20:51:17 +01:00
|
|
|
¤tEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
2009-11-02 19:41:09 +01:00
|
|
|
|
|
|
|
return S_OK;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
2009-10-23 20:57:42 +02:00
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* Internal Method
|
|
|
|
*
|
|
|
|
* Find and read the element of a storage with the given name.
|
|
|
|
*/
|
2009-11-12 22:53:42 +01:00
|
|
|
static DirRef findElement(StorageImpl *storage, DirRef storageEntry,
|
2009-11-10 21:30:59 +01:00
|
|
|
const OLECHAR *name, DirEntry *data)
|
2009-10-23 20:57:42 +02:00
|
|
|
{
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef currentEntry;
|
2009-10-23 20:57:42 +02:00
|
|
|
|
|
|
|
/* Read the storage entry to find the root of the tree. */
|
2009-11-10 21:39:10 +01:00
|
|
|
StorageImpl_ReadDirEntry(storage, storageEntry, data);
|
2009-10-23 20:57:42 +02:00
|
|
|
|
2009-11-11 17:40:12 +01:00
|
|
|
currentEntry = data->dirRootEntry;
|
2009-10-23 20:57:42 +02:00
|
|
|
|
2009-11-10 21:55:25 +01:00
|
|
|
while (currentEntry != DIRENTRY_NULL)
|
2009-10-23 20:57:42 +02:00
|
|
|
{
|
|
|
|
LONG cmp;
|
|
|
|
|
2009-11-10 21:39:10 +01:00
|
|
|
StorageImpl_ReadDirEntry(storage, currentEntry, data);
|
2009-10-23 20:57:42 +02:00
|
|
|
|
2009-11-12 20:55:49 +01:00
|
|
|
cmp = entryNameCmp(name, data->name);
|
2009-10-23 20:57:42 +02:00
|
|
|
|
|
|
|
if (cmp == 0)
|
|
|
|
/* found it */
|
|
|
|
break;
|
|
|
|
|
|
|
|
else if (cmp < 0)
|
|
|
|
currentEntry = data->leftChild;
|
|
|
|
|
|
|
|
else if (cmp > 0)
|
|
|
|
currentEntry = data->rightChild;
|
|
|
|
}
|
|
|
|
|
|
|
|
return currentEntry;
|
|
|
|
}
|
|
|
|
|
2009-10-27 21:31:01 +01:00
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* Internal Method
|
|
|
|
*
|
|
|
|
* Find and read the binary tree parent of the element with the given name.
|
|
|
|
*
|
|
|
|
* If there is no such element, find a place where it could be inserted and
|
|
|
|
* return STG_E_FILENOTFOUND.
|
|
|
|
*/
|
2009-11-12 22:53:42 +01:00
|
|
|
static HRESULT findTreeParent(StorageImpl *storage, DirRef storageEntry,
|
|
|
|
const OLECHAR *childName, DirEntry *parentData, DirRef *parentEntry,
|
2009-10-27 21:31:01 +01:00
|
|
|
ULONG *relation)
|
|
|
|
{
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef childEntry;
|
2009-11-10 21:30:59 +01:00
|
|
|
DirEntry childData;
|
2009-10-27 21:31:01 +01:00
|
|
|
|
|
|
|
/* Read the storage entry to find the root of the tree. */
|
2009-11-10 21:39:10 +01:00
|
|
|
StorageImpl_ReadDirEntry(storage, storageEntry, parentData);
|
2009-10-27 21:31:01 +01:00
|
|
|
|
|
|
|
*parentEntry = storageEntry;
|
2009-11-11 17:42:19 +01:00
|
|
|
*relation = DIRENTRY_RELATION_DIR;
|
2009-10-27 21:31:01 +01:00
|
|
|
|
2009-11-11 17:40:12 +01:00
|
|
|
childEntry = parentData->dirRootEntry;
|
2009-10-27 21:31:01 +01:00
|
|
|
|
2009-11-10 21:55:25 +01:00
|
|
|
while (childEntry != DIRENTRY_NULL)
|
2009-10-27 21:31:01 +01:00
|
|
|
{
|
|
|
|
LONG cmp;
|
|
|
|
|
2009-11-10 21:39:10 +01:00
|
|
|
StorageImpl_ReadDirEntry(storage, childEntry, &childData);
|
2009-10-27 21:31:01 +01:00
|
|
|
|
2009-11-12 20:55:49 +01:00
|
|
|
cmp = entryNameCmp(childName, childData.name);
|
2009-10-27 21:31:01 +01:00
|
|
|
|
|
|
|
if (cmp == 0)
|
|
|
|
/* found it */
|
|
|
|
break;
|
|
|
|
|
|
|
|
else if (cmp < 0)
|
|
|
|
{
|
|
|
|
*parentData = childData;
|
|
|
|
*parentEntry = childEntry;
|
2009-11-11 17:42:19 +01:00
|
|
|
*relation = DIRENTRY_RELATION_PREVIOUS;
|
2009-10-27 21:31:01 +01:00
|
|
|
|
|
|
|
childEntry = parentData->leftChild;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (cmp > 0)
|
|
|
|
{
|
|
|
|
*parentData = childData;
|
|
|
|
*parentEntry = childEntry;
|
2009-11-11 17:42:19 +01:00
|
|
|
*relation = DIRENTRY_RELATION_NEXT;
|
2009-10-27 21:31:01 +01:00
|
|
|
|
|
|
|
childEntry = parentData->rightChild;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-10 21:55:25 +01:00
|
|
|
if (childEntry == DIRENTRY_NULL)
|
2009-10-27 21:31:01 +01:00
|
|
|
return STG_E_FILENOTFOUND;
|
|
|
|
else
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-02-18 14:26:22 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* CopyTo (IStorage)
|
|
|
|
*/
|
2009-10-28 20:48:39 +01:00
|
|
|
static HRESULT WINAPI StorageBaseImpl_CopyTo(
|
1999-02-26 12:11:13 +01:00
|
|
|
IStorage* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
DWORD ciidExclude, /* [in] */
|
|
|
|
const IID* rgiidExclude, /* [size_is][unique][in] */
|
|
|
|
SNB snbExclude, /* [unique][in] */
|
|
|
|
IStorage* pstgDest) /* [unique][in] */
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
1999-04-15 17:47:48 +02:00
|
|
|
IEnumSTATSTG *elements = 0;
|
|
|
|
STATSTG curElement, strStat;
|
|
|
|
HRESULT hr;
|
|
|
|
IStorage *pstgTmp, *pstgChild;
|
|
|
|
IStream *pstrTmp, *pstrChild;
|
2009-10-09 17:53:31 +02:00
|
|
|
BOOL skip = FALSE, skip_storage = FALSE, skip_stream = FALSE;
|
|
|
|
int i;
|
1999-05-02 13:41:10 +02:00
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p, %d, %p, %p, %p)\n",
|
2002-06-01 01:06:46 +02:00
|
|
|
iface, ciidExclude, rgiidExclude,
|
1999-05-02 13:41:10 +02:00
|
|
|
snbExclude, pstgDest);
|
1999-04-15 17:47:48 +02:00
|
|
|
|
|
|
|
if ( pstgDest == 0 )
|
|
|
|
return STG_E_INVALIDPOINTER;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
1999-04-15 17:47:48 +02:00
|
|
|
* Enumerate the elements
|
|
|
|
*/
|
|
|
|
hr = IStorage_EnumElements( iface, 0, 0, 0, &elements );
|
|
|
|
|
|
|
|
if ( hr != S_OK )
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set the class ID
|
|
|
|
*/
|
1999-05-02 13:41:10 +02:00
|
|
|
IStorage_Stat( iface, &curElement, STATFLAG_NONAME);
|
1999-04-15 17:47:48 +02:00
|
|
|
IStorage_SetClass( pstgDest, &curElement.clsid );
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-10-09 17:53:31 +02:00
|
|
|
for(i = 0; i < ciidExclude; ++i)
|
|
|
|
{
|
|
|
|
if(IsEqualGUID(&IID_IStorage, &rgiidExclude[i]))
|
|
|
|
skip_storage = TRUE;
|
|
|
|
else if(IsEqualGUID(&IID_IStream, &rgiidExclude[i]))
|
|
|
|
skip_stream = TRUE;
|
|
|
|
else
|
|
|
|
WARN("Unknown excluded GUID: %s\n", debugstr_guid(&rgiidExclude[i]));
|
|
|
|
}
|
|
|
|
|
1999-04-15 17:47:48 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Obtain the next element
|
|
|
|
*/
|
|
|
|
hr = IEnumSTATSTG_Next( elements, 1, &curElement, NULL );
|
|
|
|
|
|
|
|
if ( hr == S_FALSE )
|
|
|
|
{
|
|
|
|
hr = S_OK; /* done, every element has been copied */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-10-05 23:13:55 +02:00
|
|
|
if ( snbExclude )
|
|
|
|
{
|
|
|
|
WCHAR **snb = snbExclude;
|
|
|
|
skip = FALSE;
|
|
|
|
while ( *snb != NULL && !skip )
|
|
|
|
{
|
|
|
|
if ( lstrcmpW(curElement.pwcsName, *snb) == 0 )
|
|
|
|
skip = TRUE;
|
|
|
|
++snb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( skip )
|
|
|
|
continue;
|
|
|
|
|
1999-04-15 17:47:48 +02:00
|
|
|
if (curElement.type == STGTY_STORAGE)
|
|
|
|
{
|
2009-10-09 17:53:31 +02:00
|
|
|
if(skip_storage)
|
|
|
|
continue;
|
|
|
|
|
1999-04-15 17:47:48 +02:00
|
|
|
/*
|
|
|
|
* open child source storage
|
|
|
|
*/
|
1999-05-02 13:41:10 +02:00
|
|
|
hr = IStorage_OpenStorage( iface, curElement.pwcsName, NULL,
|
|
|
|
STGM_READ|STGM_SHARE_EXCLUSIVE,
|
|
|
|
NULL, 0, &pstgChild );
|
1999-04-15 17:47:48 +02:00
|
|
|
|
|
|
|
if (hr != S_OK)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if destination storage is not a child of the source
|
|
|
|
* storage, which will cause an infinite loop
|
|
|
|
*/
|
|
|
|
if (pstgChild == pstgDest)
|
|
|
|
{
|
|
|
|
IEnumSTATSTG_Release(elements);
|
|
|
|
|
|
|
|
return STG_E_ACCESSDENIED;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-15 17:47:48 +02:00
|
|
|
/*
|
|
|
|
* create a new storage in destination storage
|
|
|
|
*/
|
|
|
|
hr = IStorage_CreateStorage( pstgDest, curElement.pwcsName,
|
1999-05-02 13:41:10 +02:00
|
|
|
STGM_FAILIFTHERE|STGM_WRITE|STGM_SHARE_EXCLUSIVE,
|
|
|
|
0, 0,
|
1999-04-15 17:47:48 +02:00
|
|
|
&pstgTmp );
|
|
|
|
/*
|
|
|
|
* if it already exist, don't create a new one use this one
|
|
|
|
*/
|
|
|
|
if (hr == STG_E_FILEALREADYEXISTS)
|
|
|
|
{
|
|
|
|
hr = IStorage_OpenStorage( pstgDest, curElement.pwcsName, NULL,
|
|
|
|
STGM_WRITE|STGM_SHARE_EXCLUSIVE,
|
|
|
|
NULL, 0, &pstgTmp );
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-15 17:47:48 +02:00
|
|
|
if (hr != S_OK)
|
|
|
|
break;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-15 17:47:48 +02:00
|
|
|
/*
|
|
|
|
* do the copy recursively
|
|
|
|
*/
|
|
|
|
hr = IStorage_CopyTo( pstgChild, ciidExclude, rgiidExclude,
|
2009-10-05 23:13:55 +02:00
|
|
|
NULL, pstgTmp );
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-15 17:47:48 +02:00
|
|
|
IStorage_Release( pstgTmp );
|
|
|
|
IStorage_Release( pstgChild );
|
|
|
|
}
|
|
|
|
else if (curElement.type == STGTY_STREAM)
|
|
|
|
{
|
2009-10-09 17:53:31 +02:00
|
|
|
if(skip_stream)
|
|
|
|
continue;
|
|
|
|
|
1999-04-15 17:47:48 +02:00
|
|
|
/*
|
|
|
|
* create a new stream in destination storage. If the stream already
|
|
|
|
* exist, it will be deleted and a new one will be created.
|
|
|
|
*/
|
|
|
|
hr = IStorage_CreateStream( pstgDest, curElement.pwcsName,
|
|
|
|
STGM_CREATE|STGM_WRITE|STGM_SHARE_EXCLUSIVE,
|
|
|
|
0, 0, &pstrTmp );
|
|
|
|
|
|
|
|
if (hr != S_OK)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* open child stream storage
|
|
|
|
*/
|
1999-05-02 13:41:10 +02:00
|
|
|
hr = IStorage_OpenStream( iface, curElement.pwcsName, NULL,
|
|
|
|
STGM_READ|STGM_SHARE_EXCLUSIVE,
|
|
|
|
0, &pstrChild );
|
1999-04-15 17:47:48 +02:00
|
|
|
|
|
|
|
if (hr != S_OK)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
1999-05-02 13:41:10 +02:00
|
|
|
* Get the size of the source stream
|
1999-04-15 17:47:48 +02:00
|
|
|
*/
|
|
|
|
IStream_Stat( pstrChild, &strStat, STATFLAG_NONAME );
|
1999-05-02 13:41:10 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the size of the destination stream.
|
|
|
|
*/
|
|
|
|
IStream_SetSize(pstrTmp, strStat.cbSize);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-15 17:47:48 +02:00
|
|
|
/*
|
|
|
|
* do the copy
|
|
|
|
*/
|
|
|
|
hr = IStream_CopyTo( pstrChild, pstrTmp, strStat.cbSize,
|
|
|
|
NULL, NULL );
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-15 17:47:48 +02:00
|
|
|
IStream_Release( pstrTmp );
|
|
|
|
IStream_Release( pstrChild );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
WARN("unknown element type: %d\n", curElement.type);
|
1999-04-15 17:47:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} while (hr == S_OK);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clean-up
|
|
|
|
*/
|
|
|
|
IEnumSTATSTG_Release(elements);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-04-15 17:47:48 +02:00
|
|
|
return hr;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-02-18 14:26:22 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* MoveElementTo (IStorage)
|
|
|
|
*/
|
2009-10-28 20:49:30 +01:00
|
|
|
static HRESULT WINAPI StorageBaseImpl_MoveElementTo(
|
1999-02-26 12:11:13 +01:00
|
|
|
IStorage* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
const OLECHAR *pwcsName, /* [string][in] */
|
|
|
|
IStorage *pstgDest, /* [unique][in] */
|
|
|
|
const OLECHAR *pwcsNewName,/* [string][in] */
|
|
|
|
DWORD grfFlags) /* [in] */
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
FIXME("(%p %s %p %s %u): stub\n", iface,
|
2006-07-31 18:00:36 +02:00
|
|
|
debugstr_w(pwcsName), pstgDest,
|
|
|
|
debugstr_w(pwcsNewName), grfFlags);
|
1999-01-30 14:24:23 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-02-18 14:26:22 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* Commit (IStorage)
|
2005-07-07 19:21:44 +02:00
|
|
|
*
|
|
|
|
* Ensures that any changes made to a storage object open in transacted mode
|
|
|
|
* are reflected in the parent storage
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Wine doesn't implement transacted mode, which seems to be a basic
|
|
|
|
* optimization, so we can ignore this stub for now.
|
1999-02-18 14:26:22 +01:00
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI StorageImpl_Commit(
|
1999-02-26 12:11:13 +01:00
|
|
|
IStorage* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
DWORD grfCommitFlags)/* [in] */
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
FIXME("(%p %d): stub\n", iface, grfCommitFlags);
|
1999-02-13 13:10:15 +01:00
|
|
|
return S_OK;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-02-18 14:26:22 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* Revert (IStorage)
|
2005-07-07 19:21:44 +02:00
|
|
|
*
|
|
|
|
* Discard all changes that have been made since the last commit operation
|
1999-02-18 14:26:22 +01:00
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI StorageImpl_Revert(
|
1999-02-26 12:11:13 +01:00
|
|
|
IStorage* iface)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2006-07-31 18:00:36 +02:00
|
|
|
FIXME("(%p): stub\n", iface);
|
1999-01-30 14:24:23 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
1999-02-18 14:26:22 +01:00
|
|
|
* DestroyElement (IStorage)
|
1999-01-30 14:24:23 +01:00
|
|
|
*
|
2006-03-21 18:24:49 +01:00
|
|
|
* Strategy: This implementation is built this way for simplicity not for speed.
|
|
|
|
* I always delete the topmost element of the enumeration and adjust
|
2002-06-01 01:06:46 +02:00
|
|
|
* the deleted element pointer all the time. This takes longer to
|
|
|
|
* do but allow to reinvoke DestroyElement whenever we encounter a
|
2006-03-21 18:24:49 +01:00
|
|
|
* storage object. The optimisation resides in the usage of another
|
|
|
|
* enumeration strategy that would give all the leaves of a storage
|
1999-01-30 14:24:23 +01:00
|
|
|
* first. (postfix order)
|
|
|
|
*/
|
2009-10-28 20:53:30 +01:00
|
|
|
static HRESULT WINAPI StorageBaseImpl_DestroyElement(
|
1999-02-26 12:11:13 +01:00
|
|
|
IStorage* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
const OLECHAR *pwcsName)/* [string][in] */
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-10-28 20:53:30 +01:00
|
|
|
StorageBaseImpl* const This=(StorageBaseImpl*)iface;
|
1999-02-18 14:26:22 +01:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
HRESULT hr = S_OK;
|
2009-11-12 21:32:35 +01:00
|
|
|
DirEntry entryToDelete;
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef entryToDeleteRef;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
TRACE("(%p, %s)\n",
|
1999-05-02 13:41:10 +02:00
|
|
|
iface, debugstr_w(pwcsName));
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if (pwcsName==NULL)
|
1999-01-30 14:24:23 +01:00
|
|
|
return STG_E_INVALIDPOINTER;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-11-19 20:42:47 +01:00
|
|
|
if (!This->ancestorStorage)
|
|
|
|
return STG_E_REVERTED;
|
|
|
|
|
2009-10-28 20:53:30 +01:00
|
|
|
if ( STGM_ACCESS_MODE( This->openFlags ) == STGM_READ )
|
2009-05-29 23:45:44 +02:00
|
|
|
return STG_E_ACCESSDENIED;
|
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
entryToDeleteRef = findElement(
|
2009-10-28 20:53:30 +01:00
|
|
|
This->ancestorStorage,
|
2009-11-12 20:19:37 +01:00
|
|
|
This->storageDirEntry,
|
1999-01-30 14:24:23 +01:00
|
|
|
pwcsName,
|
2009-11-12 21:32:35 +01:00
|
|
|
&entryToDelete);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
if ( entryToDeleteRef == DIRENTRY_NULL )
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
return STG_E_FILENOTFOUND;
|
|
|
|
}
|
|
|
|
|
2009-11-12 21:32:35 +01:00
|
|
|
if ( entryToDelete.stgType == STGTY_STORAGE )
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-12 20:46:04 +01:00
|
|
|
hr = deleteStorageContents(
|
2002-06-01 01:06:46 +02:00
|
|
|
This,
|
2009-11-12 21:32:35 +01:00
|
|
|
entryToDeleteRef,
|
|
|
|
entryToDelete);
|
2002-06-01 01:06:46 +02:00
|
|
|
}
|
2009-11-12 21:32:35 +01:00
|
|
|
else if ( entryToDelete.stgType == STGTY_STREAM )
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-12 20:46:04 +01:00
|
|
|
hr = deleteStreamContents(
|
2002-06-01 01:06:46 +02:00
|
|
|
This,
|
2009-11-12 21:32:35 +01:00
|
|
|
entryToDeleteRef,
|
|
|
|
entryToDelete);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if (hr!=S_OK)
|
1999-01-30 14:24:23 +01:00
|
|
|
return hr;
|
|
|
|
|
|
|
|
/*
|
2009-11-12 21:32:35 +01:00
|
|
|
* Remove the entry from its parent storage
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-10-28 20:24:18 +01:00
|
|
|
hr = removeFromTree(
|
2009-10-28 20:53:30 +01:00
|
|
|
This->ancestorStorage,
|
2009-11-12 20:19:37 +01:00
|
|
|
This->storageDirEntry,
|
2009-11-12 21:32:35 +01:00
|
|
|
entryToDeleteRef);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-10-28 20:06:23 +01:00
|
|
|
/*
|
2009-11-12 21:32:35 +01:00
|
|
|
* Invalidate the entry
|
2009-10-28 20:06:23 +01:00
|
|
|
*/
|
2009-11-02 19:25:46 +01:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
destroyDirEntry(This->ancestorStorage,
|
2009-11-12 21:32:35 +01:00
|
|
|
entryToDeleteRef);
|
2009-10-28 20:06:23 +01:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/************************************************************************
|
|
|
|
* StorageImpl_Stat (IStorage)
|
|
|
|
*
|
|
|
|
* This method will retrieve information about this storage object.
|
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IStorage methods.
|
2002-01-01 01:13:32 +01:00
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI StorageImpl_Stat( IStorage* iface,
|
2002-01-01 01:13:32 +01:00
|
|
|
STATSTG* pstatstg, /* [out] */
|
|
|
|
DWORD grfStatFlag) /* [in] */
|
|
|
|
{
|
|
|
|
StorageImpl* const This = (StorageImpl*)iface;
|
|
|
|
HRESULT result = StorageBaseImpl_Stat( iface, pstatstg, grfStatFlag );
|
|
|
|
|
2008-10-08 01:32:53 +02:00
|
|
|
if ( SUCCEEDED(result) && ((grfStatFlag & STATFLAG_NONAME) == 0) && This->pwcsName )
|
2002-01-01 01:13:32 +01:00
|
|
|
{
|
|
|
|
CoTaskMemFree(pstatstg->pwcsName);
|
|
|
|
pstatstg->pwcsName = CoTaskMemAlloc((lstrlenW(This->pwcsName)+1)*sizeof(WCHAR));
|
|
|
|
strcpyW(pstatstg->pwcsName, This->pwcsName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2006-02-21 09:03:36 +01:00
|
|
|
/******************************************************************************
|
2006-07-29 10:13:53 +02:00
|
|
|
* Internal stream list handlers
|
2006-02-21 09:03:36 +01:00
|
|
|
*/
|
|
|
|
|
2007-02-26 13:57:19 +01:00
|
|
|
void StorageBaseImpl_AddStream(StorageBaseImpl * stg, StgStreamImpl * strm)
|
2006-02-21 09:03:36 +01:00
|
|
|
{
|
|
|
|
TRACE("Stream added (stg=%p strm=%p)\n", stg, strm);
|
|
|
|
list_add_tail(&stg->strmHead,&strm->StrmListEntry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StorageBaseImpl_RemoveStream(StorageBaseImpl * stg, StgStreamImpl * strm)
|
|
|
|
{
|
|
|
|
TRACE("Stream removed (stg=%p strm=%p)\n", stg,strm);
|
|
|
|
list_remove(&(strm->StrmListEntry));
|
|
|
|
}
|
|
|
|
|
2009-11-18 17:38:10 +01:00
|
|
|
static BOOL StorageBaseImpl_IsStreamOpen(StorageBaseImpl * stg, DirRef streamEntry)
|
|
|
|
{
|
|
|
|
StgStreamImpl *strm;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(strm, &stg->strmHead, StgStreamImpl, StrmListEntry)
|
|
|
|
{
|
|
|
|
if (strm->dirEntry == streamEntry)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-11-19 20:55:34 +01:00
|
|
|
static BOOL StorageBaseImpl_IsStorageOpen(StorageBaseImpl * stg, DirRef storageEntry)
|
|
|
|
{
|
|
|
|
StorageInternalImpl *childstg;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(childstg, &stg->storageHead, StorageInternalImpl, ParentListEntry)
|
|
|
|
{
|
|
|
|
if (childstg->base.storageDirEntry == storageEntry)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-08-02 13:31:26 +02:00
|
|
|
static void StorageBaseImpl_DeleteAll(StorageBaseImpl * stg)
|
2006-02-21 09:03:36 +01:00
|
|
|
{
|
|
|
|
struct list *cur, *cur2;
|
|
|
|
StgStreamImpl *strm=NULL;
|
2009-11-19 20:42:47 +01:00
|
|
|
StorageInternalImpl *childstg=NULL;
|
2006-02-21 09:03:36 +01:00
|
|
|
|
|
|
|
LIST_FOR_EACH_SAFE(cur, cur2, &stg->strmHead) {
|
|
|
|
strm = LIST_ENTRY(cur,StgStreamImpl,StrmListEntry);
|
2009-11-19 20:42:47 +01:00
|
|
|
TRACE("Streams invalidated (stg=%p strm=%p next=%p prev=%p)\n", stg,strm,cur->next,cur->prev);
|
2006-07-29 10:13:53 +02:00
|
|
|
strm->parentStorage = NULL;
|
2006-02-21 09:03:36 +01:00
|
|
|
list_remove(cur);
|
|
|
|
}
|
2009-11-19 20:42:47 +01:00
|
|
|
|
|
|
|
LIST_FOR_EACH_SAFE(cur, cur2, &stg->storageHead) {
|
|
|
|
childstg = LIST_ENTRY(cur,StorageInternalImpl,ParentListEntry);
|
|
|
|
StorageInternalImpl_Invalidate( childstg );
|
|
|
|
}
|
2006-02-21 09:03:36 +01:00
|
|
|
}
|
2002-01-01 01:13:32 +01:00
|
|
|
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Internal Method
|
|
|
|
*
|
2009-11-12 20:46:04 +01:00
|
|
|
* Delete the contents of a storage entry.
|
1999-01-30 14:24:23 +01:00
|
|
|
*
|
|
|
|
*/
|
2009-11-12 20:46:04 +01:00
|
|
|
static HRESULT deleteStorageContents(
|
2009-10-28 20:53:30 +01:00
|
|
|
StorageBaseImpl *parentStorage,
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef indexToDelete,
|
2009-11-12 20:46:04 +01:00
|
|
|
DirEntry entryDataToDelete)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
IEnumSTATSTG *elements = 0;
|
1999-02-26 12:11:13 +01:00
|
|
|
IStorage *childStorage = 0;
|
1999-01-30 14:24:23 +01:00
|
|
|
STATSTG currentElement;
|
|
|
|
HRESULT hr;
|
|
|
|
HRESULT destroyHr = S_OK;
|
2009-11-19 21:02:23 +01:00
|
|
|
StorageInternalImpl *stg, *stg2;
|
|
|
|
|
|
|
|
/* Invalidate any open storage objects. */
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(stg, stg2, &parentStorage->storageHead, StorageInternalImpl, ParentListEntry)
|
|
|
|
{
|
|
|
|
if (stg->base.storageDirEntry == indexToDelete)
|
|
|
|
{
|
|
|
|
StorageInternalImpl_Invalidate(stg);
|
|
|
|
}
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Open the storage and enumerate it
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
hr = StorageBaseImpl_OpenStorage(
|
|
|
|
(IStorage*)parentStorage,
|
2009-11-12 20:46:04 +01:00
|
|
|
entryDataToDelete.name,
|
1999-01-30 14:24:23 +01:00
|
|
|
0,
|
2006-05-31 04:35:53 +02:00
|
|
|
STGM_WRITE | STGM_SHARE_EXCLUSIVE,
|
1999-01-30 14:24:23 +01:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
&childStorage);
|
|
|
|
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
1999-01-30 14:24:23 +01:00
|
|
|
* Enumerate the elements
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
IStorage_EnumElements( childStorage, 0, 0, 0, &elements);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Obtain the next element
|
|
|
|
*/
|
|
|
|
hr = IEnumSTATSTG_Next(elements, 1, ¤tElement, NULL);
|
|
|
|
if (hr==S_OK)
|
|
|
|
{
|
2009-10-28 20:53:30 +01:00
|
|
|
destroyHr = IStorage_DestroyElement(childStorage, currentElement.pwcsName);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
CoTaskMemFree(currentElement.pwcsName);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We need to Reset the enumeration every time because we delete elements
|
|
|
|
* and the enumeration could be invalid
|
|
|
|
*/
|
|
|
|
IEnumSTATSTG_Reset(elements);
|
|
|
|
|
|
|
|
} while ((hr == S_OK) && (destroyHr == S_OK));
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
IStorage_Release(childStorage);
|
1999-01-30 14:24:23 +01:00
|
|
|
IEnumSTATSTG_Release(elements);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
return destroyHr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
*
|
|
|
|
* Internal Method
|
|
|
|
*
|
2009-11-12 20:46:04 +01:00
|
|
|
* Perform the deletion of a stream's data
|
1999-01-30 14:24:23 +01:00
|
|
|
*
|
|
|
|
*/
|
2009-11-12 20:46:04 +01:00
|
|
|
static HRESULT deleteStreamContents(
|
2009-10-28 20:53:30 +01:00
|
|
|
StorageBaseImpl *parentStorage,
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef indexToDelete,
|
2009-11-12 20:46:04 +01:00
|
|
|
DirEntry entryDataToDelete)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
1999-02-26 12:11:13 +01:00
|
|
|
IStream *pis;
|
1999-01-30 14:24:23 +01:00
|
|
|
HRESULT hr;
|
|
|
|
ULARGE_INTEGER size;
|
2009-11-18 17:27:16 +01:00
|
|
|
StgStreamImpl *strm, *strm2;
|
2009-11-18 17:22:50 +01:00
|
|
|
|
|
|
|
/* Invalidate any open stream objects. */
|
2009-11-18 17:27:16 +01:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(strm, strm2, &parentStorage->strmHead, StgStreamImpl, StrmListEntry)
|
2009-11-18 17:22:50 +01:00
|
|
|
{
|
|
|
|
if (strm->dirEntry == indexToDelete)
|
|
|
|
{
|
|
|
|
TRACE("Stream deleted %p\n", strm);
|
|
|
|
strm->parentStorage = NULL;
|
|
|
|
list_remove(&strm->StrmListEntry);
|
|
|
|
}
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
size.u.HighPart = 0;
|
|
|
|
size.u.LowPart = 0;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-02-11 10:48:38 +01:00
|
|
|
hr = StorageBaseImpl_OpenStream((IStorage*)parentStorage,
|
2009-11-12 20:46:04 +01:00
|
|
|
entryDataToDelete.name, NULL, STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, &pis);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
if (hr!=S_OK)
|
|
|
|
{
|
|
|
|
return(hr);
|
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
|
|
|
* Zap the stream
|
|
|
|
*/
|
|
|
|
hr = IStream_SetSize(pis, size);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
if(hr != S_OK)
|
|
|
|
{
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
1999-05-02 13:41:10 +02:00
|
|
|
/*
|
|
|
|
* Release the stream object.
|
|
|
|
*/
|
|
|
|
IStream_Release(pis);
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-11-12 22:53:42 +01:00
|
|
|
static void setEntryLink(DirEntry *entry, ULONG relation, DirRef new_target)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-10-27 23:34:49 +01:00
|
|
|
switch (relation)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-11 17:42:19 +01:00
|
|
|
case DIRENTRY_RELATION_PREVIOUS:
|
2009-11-12 21:47:07 +01:00
|
|
|
entry->leftChild = new_target;
|
2009-10-27 23:34:49 +01:00
|
|
|
break;
|
2009-11-11 17:42:19 +01:00
|
|
|
case DIRENTRY_RELATION_NEXT:
|
2009-11-12 21:47:07 +01:00
|
|
|
entry->rightChild = new_target;
|
2009-10-27 23:34:49 +01:00
|
|
|
break;
|
2009-11-11 17:42:19 +01:00
|
|
|
case DIRENTRY_RELATION_DIR:
|
2009-11-12 21:47:07 +01:00
|
|
|
entry->dirRootEntry = new_target;
|
2009-10-27 23:34:49 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* Internal Method
|
|
|
|
*
|
2009-10-28 20:24:18 +01:00
|
|
|
* This method removes a directory entry from its parent storage tree without
|
|
|
|
* freeing any resources attached to it.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-10-28 20:24:18 +01:00
|
|
|
static HRESULT removeFromTree(
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl *This,
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef parentStorageIndex,
|
|
|
|
DirRef deletedIndex)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL res = TRUE;
|
2009-11-12 21:47:07 +01:00
|
|
|
DirEntry entryToDelete;
|
|
|
|
DirEntry parentEntry;
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef parentEntryRef;
|
2009-10-28 20:24:18 +01:00
|
|
|
ULONG typeOfRelation;
|
|
|
|
|
2009-11-12 21:47:07 +01:00
|
|
|
res = StorageImpl_ReadDirEntry(This, deletedIndex, &entryToDelete);
|
2009-10-28 20:24:18 +01:00
|
|
|
|
|
|
|
/*
|
2009-11-12 21:47:07 +01:00
|
|
|
* Find the element that links to the one we want to delete.
|
2009-10-28 20:24:18 +01:00
|
|
|
*/
|
2009-11-12 21:47:07 +01:00
|
|
|
hr = findTreeParent(This, parentStorageIndex, entryToDelete.name,
|
|
|
|
&parentEntry, &parentEntryRef, &typeOfRelation);
|
2009-10-28 20:24:18 +01:00
|
|
|
|
|
|
|
if (hr != S_OK)
|
|
|
|
return hr;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-11-12 21:47:07 +01:00
|
|
|
if (entryToDelete.leftChild != DIRENTRY_NULL)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-10-27 22:48:39 +01:00
|
|
|
/*
|
|
|
|
* Replace the deleted entry with its left child
|
|
|
|
*/
|
2009-11-12 21:47:07 +01:00
|
|
|
setEntryLink(&parentEntry, typeOfRelation, entryToDelete.leftChild);
|
2009-10-27 23:34:49 +01:00
|
|
|
|
2009-11-10 21:40:05 +01:00
|
|
|
res = StorageImpl_WriteDirEntry(
|
2009-10-28 21:03:19 +01:00
|
|
|
This,
|
2009-11-12 21:47:07 +01:00
|
|
|
parentEntryRef,
|
|
|
|
&parentEntry);
|
2009-10-27 23:34:49 +01:00
|
|
|
if(!res)
|
|
|
|
{
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 21:47:07 +01:00
|
|
|
if (entryToDelete.rightChild != DIRENTRY_NULL)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
2009-10-27 23:34:49 +01:00
|
|
|
* We need to reinsert the right child somewhere. We already know it and
|
|
|
|
* its children are greater than everything in the left tree, so we
|
|
|
|
* insert it at the rightmost point in the left tree.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef newRightChildParent = entryToDelete.leftChild;
|
2009-11-12 21:47:07 +01:00
|
|
|
DirEntry newRightChildParentEntry;
|
2009-10-27 23:34:49 +01:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2009-11-10 21:39:10 +01:00
|
|
|
res = StorageImpl_ReadDirEntry(
|
2009-10-28 21:03:19 +01:00
|
|
|
This,
|
2009-10-27 23:34:49 +01:00
|
|
|
newRightChildParent,
|
2009-11-12 21:47:07 +01:00
|
|
|
&newRightChildParentEntry);
|
2009-10-27 23:34:49 +01:00
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2009-11-12 21:47:07 +01:00
|
|
|
if (newRightChildParentEntry.rightChild != DIRENTRY_NULL)
|
|
|
|
newRightChildParent = newRightChildParentEntry.rightChild;
|
|
|
|
} while (newRightChildParentEntry.rightChild != DIRENTRY_NULL);
|
2009-10-27 23:34:49 +01:00
|
|
|
|
2009-11-12 21:47:07 +01:00
|
|
|
newRightChildParentEntry.rightChild = entryToDelete.rightChild;
|
2009-10-27 23:34:49 +01:00
|
|
|
|
2009-11-10 21:40:05 +01:00
|
|
|
res = StorageImpl_WriteDirEntry(
|
2009-10-28 21:03:19 +01:00
|
|
|
This,
|
2009-10-27 23:34:49 +01:00
|
|
|
newRightChildParent,
|
2009-11-12 21:47:07 +01:00
|
|
|
&newRightChildParentEntry);
|
2009-10-27 23:34:49 +01:00
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
2009-10-27 22:48:39 +01:00
|
|
|
}
|
2009-10-27 23:34:49 +01:00
|
|
|
else
|
2009-10-27 22:48:39 +01:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
2009-10-27 22:48:39 +01:00
|
|
|
* Replace the deleted entry with its right child
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
2009-11-12 21:47:07 +01:00
|
|
|
setEntryLink(&parentEntry, typeOfRelation, entryToDelete.rightChild);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-10 21:40:05 +01:00
|
|
|
res = StorageImpl_WriteDirEntry(
|
2009-10-28 21:03:19 +01:00
|
|
|
This,
|
2009-11-12 21:47:07 +01:00
|
|
|
parentEntryRef,
|
|
|
|
&parentEntry);
|
2009-10-27 23:34:49 +01:00
|
|
|
if(!res)
|
|
|
|
{
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-18 14:26:22 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* SetElementTimes (IStorage)
|
|
|
|
*/
|
2009-10-28 20:54:36 +01:00
|
|
|
static HRESULT WINAPI StorageBaseImpl_SetElementTimes(
|
1999-02-26 12:11:13 +01:00
|
|
|
IStorage* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
const OLECHAR *pwcsName,/* [string][in] */
|
|
|
|
const FILETIME *pctime, /* [in] */
|
|
|
|
const FILETIME *patime, /* [in] */
|
|
|
|
const FILETIME *pmtime) /* [in] */
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2001-07-14 02:47:52 +02:00
|
|
|
FIXME("(%s,...), stub!\n",debugstr_w(pwcsName));
|
|
|
|
return S_OK;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
1999-02-18 14:26:22 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* SetStateBits (IStorage)
|
|
|
|
*/
|
2009-10-28 20:56:19 +01:00
|
|
|
static HRESULT WINAPI StorageBaseImpl_SetStateBits(
|
1999-02-26 12:11:13 +01:00
|
|
|
IStorage* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
DWORD grfStateBits,/* [in] */
|
|
|
|
DWORD grfMask) /* [in] */
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-10-28 20:56:19 +01:00
|
|
|
StorageBaseImpl* const This = (StorageBaseImpl*)iface;
|
2009-11-19 20:42:47 +01:00
|
|
|
|
|
|
|
if (!This->ancestorStorage)
|
|
|
|
return STG_E_REVERTED;
|
|
|
|
|
2009-10-28 20:56:19 +01:00
|
|
|
This->stateBits = (This->stateBits & ~grfMask) | (grfStateBits & grfMask);
|
2007-06-07 20:17:56 +02:00
|
|
|
return S_OK;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
2005-03-31 17:26:30 +02:00
|
|
|
/*
|
|
|
|
* Virtual function table for the IStorage32Impl class.
|
|
|
|
*/
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IStorageVtbl Storage32Impl_Vtbl =
|
2005-03-31 17:26:30 +02:00
|
|
|
{
|
|
|
|
StorageBaseImpl_QueryInterface,
|
|
|
|
StorageBaseImpl_AddRef,
|
|
|
|
StorageBaseImpl_Release,
|
|
|
|
StorageBaseImpl_CreateStream,
|
|
|
|
StorageBaseImpl_OpenStream,
|
2009-10-28 20:35:24 +01:00
|
|
|
StorageBaseImpl_CreateStorage,
|
2005-03-31 17:26:30 +02:00
|
|
|
StorageBaseImpl_OpenStorage,
|
2009-10-28 20:48:39 +01:00
|
|
|
StorageBaseImpl_CopyTo,
|
2009-10-28 20:49:30 +01:00
|
|
|
StorageBaseImpl_MoveElementTo,
|
2005-03-31 17:26:30 +02:00
|
|
|
StorageImpl_Commit,
|
|
|
|
StorageImpl_Revert,
|
|
|
|
StorageBaseImpl_EnumElements,
|
2009-10-28 20:53:30 +01:00
|
|
|
StorageBaseImpl_DestroyElement,
|
2005-03-31 17:26:30 +02:00
|
|
|
StorageBaseImpl_RenameElement,
|
2009-10-28 20:54:36 +01:00
|
|
|
StorageBaseImpl_SetElementTimes,
|
2005-03-31 17:26:30 +02:00
|
|
|
StorageBaseImpl_SetClass,
|
2009-10-28 20:56:19 +01:00
|
|
|
StorageBaseImpl_SetStateBits,
|
2005-03-31 17:26:30 +02:00
|
|
|
StorageImpl_Stat
|
|
|
|
};
|
|
|
|
|
2006-08-02 13:31:26 +02:00
|
|
|
static HRESULT StorageImpl_Construct(
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl* This,
|
|
|
|
HANDLE hFile,
|
2002-01-01 01:13:32 +01:00
|
|
|
LPCOLESTR pwcsName,
|
1999-05-08 12:05:08 +02:00
|
|
|
ILockBytes* pLkbyt,
|
|
|
|
DWORD openFlags,
|
2000-02-25 21:58:25 +01:00
|
|
|
BOOL fileBased,
|
2009-05-29 17:51:22 +02:00
|
|
|
BOOL create)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
2009-11-12 21:51:34 +01:00
|
|
|
DirEntry currentEntry;
|
2000-01-29 22:12:58 +01:00
|
|
|
BOOL readSuccessful;
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef currentEntryRef;
|
2002-01-01 01:13:32 +01:00
|
|
|
|
1999-02-13 13:10:15 +01:00
|
|
|
if ( FAILED( validateSTGM(openFlags) ))
|
|
|
|
return STG_E_INVALIDFLAG;
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
memset(This, 0, sizeof(StorageImpl));
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-02-21 09:03:36 +01:00
|
|
|
list_init(&This->base.strmHead);
|
|
|
|
|
2009-11-19 20:42:47 +01:00
|
|
|
list_init(&This->base.storageHead);
|
|
|
|
|
2005-02-24 20:39:27 +01:00
|
|
|
This->base.lpVtbl = &Storage32Impl_Vtbl;
|
|
|
|
This->base.pssVtbl = &IPropertySetStorage_Vtbl;
|
2008-07-06 14:00:24 +02:00
|
|
|
This->base.v_destructor = StorageImpl_Destroy;
|
2006-05-03 15:49:51 +02:00
|
|
|
This->base.openFlags = (openFlags & ~STGM_CREATE);
|
2009-05-29 18:14:41 +02:00
|
|
|
This->create = create;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
2002-01-31 22:01:35 +01:00
|
|
|
* This is the top-level storage so initialize the ancestor pointer
|
1999-01-30 14:24:23 +01:00
|
|
|
* to this.
|
|
|
|
*/
|
2005-02-24 20:39:27 +01:00
|
|
|
This->base.ancestorStorage = This;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
This->hFile = hFile;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-01-01 01:13:32 +01:00
|
|
|
if(pwcsName) {
|
2002-06-01 01:06:46 +02:00
|
|
|
This->pwcsName = HeapAlloc(GetProcessHeap(), 0,
|
2002-01-01 01:13:32 +01:00
|
|
|
(lstrlenW(pwcsName)+1)*sizeof(WCHAR));
|
|
|
|
if (!This->pwcsName)
|
|
|
|
return STG_E_INSUFFICIENTMEMORY;
|
2002-06-01 01:06:46 +02:00
|
|
|
strcpyW(This->pwcsName, pwcsName);
|
2002-01-01 01:13:32 +01:00
|
|
|
}
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Initialize the big block cache.
|
|
|
|
*/
|
|
|
|
This->bigBlockSize = DEF_BIG_BLOCK_SIZE;
|
|
|
|
This->smallBlockSize = DEF_SMALL_BLOCK_SIZE;
|
1999-02-18 16:55:53 +01:00
|
|
|
This->bigBlockFile = BIGBLOCKFILE_Construct(hFile,
|
1999-05-08 12:05:08 +02:00
|
|
|
pLkbyt,
|
1999-02-18 16:55:53 +01:00
|
|
|
openFlags,
|
1999-05-08 12:05:08 +02:00
|
|
|
This->bigBlockSize,
|
|
|
|
fileBased);
|
1999-02-18 16:55:53 +01:00
|
|
|
|
|
|
|
if (This->bigBlockFile == 0)
|
|
|
|
return E_FAIL;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-05-29 17:51:22 +02:00
|
|
|
if (create)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
ULARGE_INTEGER size;
|
2007-03-16 19:34:28 +01:00
|
|
|
BYTE bigBlockBuffer[BIG_BLOCK_SIZE];
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize all header variables:
|
|
|
|
* - The big block depot consists of one block and it is at block 0
|
2009-11-12 21:51:34 +01:00
|
|
|
* - The directory table starts at block 1
|
1999-01-30 14:24:23 +01:00
|
|
|
* - There is no small block depot
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
memset( This->bigBlockDepotStart,
|
|
|
|
BLOCK_UNUSED,
|
1999-01-30 14:24:23 +01:00
|
|
|
sizeof(This->bigBlockDepotStart));
|
|
|
|
|
|
|
|
This->bigBlockDepotCount = 1;
|
|
|
|
This->bigBlockDepotStart[0] = 0;
|
|
|
|
This->rootStartBlock = 1;
|
|
|
|
This->smallBlockDepotStart = BLOCK_END_OF_CHAIN;
|
|
|
|
This->bigBlockSizeBits = DEF_BIG_BLOCK_SIZE_BITS;
|
|
|
|
This->smallBlockSizeBits = DEF_SMALL_BLOCK_SIZE_BITS;
|
|
|
|
This->extBigBlockDepotStart = BLOCK_END_OF_CHAIN;
|
|
|
|
This->extBigBlockDepotCount = 0;
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl_SaveFileHeader(This);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
2009-11-12 21:51:34 +01:00
|
|
|
* Add one block for the big block depot and one block for the directory table
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2004-01-23 02:51:33 +01:00
|
|
|
size.u.HighPart = 0;
|
|
|
|
size.u.LowPart = This->bigBlockSize * 3;
|
1999-01-30 14:24:23 +01:00
|
|
|
BIGBLOCKFILE_SetSize(This->bigBlockFile, size);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the big block depot
|
|
|
|
*/
|
|
|
|
memset(bigBlockBuffer, BLOCK_UNUSED, This->bigBlockSize);
|
|
|
|
StorageUtl_WriteDWord(bigBlockBuffer, 0, BLOCK_SPECIAL);
|
|
|
|
StorageUtl_WriteDWord(bigBlockBuffer, sizeof(ULONG), BLOCK_END_OF_CHAIN);
|
2007-03-16 19:34:28 +01:00
|
|
|
StorageImpl_WriteBigBlock(This, 0, bigBlockBuffer);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
else
|
1999-02-24 11:36:34 +01:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Load the header for the file.
|
|
|
|
*/
|
1999-03-17 16:11:27 +01:00
|
|
|
hr = StorageImpl_LoadFileHeader(This);
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
BIGBLOCKFILE_Destructor(This->bigBlockFile);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
1999-02-24 11:36:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There is no block depot cached yet.
|
|
|
|
*/
|
|
|
|
This->indexBlockDepotCached = 0xFFFFFFFF;
|
1999-03-09 18:40:00 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Start searching for free blocks with block 0.
|
|
|
|
*/
|
|
|
|
This->prevFreeBlock = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Create the block chain abstractions.
|
|
|
|
*/
|
2002-08-16 21:55:14 +02:00
|
|
|
if(!(This->rootBlockChain =
|
2009-11-10 21:55:25 +01:00
|
|
|
BlockChainStream_Construct(This, &This->rootStartBlock, DIRENTRY_NULL)))
|
2002-08-16 21:55:14 +02:00
|
|
|
return STG_E_READFAULT;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-08-16 21:55:14 +02:00
|
|
|
if(!(This->smallBlockDepotChain =
|
|
|
|
BlockChainStream_Construct(This, &This->smallBlockDepotStart,
|
2009-11-10 21:55:25 +01:00
|
|
|
DIRENTRY_NULL)))
|
2002-08-16 21:55:14 +02:00
|
|
|
return STG_E_READFAULT;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
2009-11-12 21:51:34 +01:00
|
|
|
* Write the root storage entry (memory only)
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-05-29 17:51:22 +02:00
|
|
|
if (create)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-12 21:51:34 +01:00
|
|
|
DirEntry rootEntry;
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
2009-11-12 21:51:34 +01:00
|
|
|
* Initialize the directory table
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-11-12 21:51:34 +01:00
|
|
|
memset(&rootEntry, 0, sizeof(rootEntry));
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, rootEntryName, -1, rootEntry.name,
|
|
|
|
sizeof(rootEntry.name)/sizeof(WCHAR) );
|
|
|
|
rootEntry.sizeOfNameString = (strlenW(rootEntry.name)+1) * sizeof(WCHAR);
|
|
|
|
rootEntry.stgType = STGTY_ROOT;
|
|
|
|
rootEntry.leftChild = DIRENTRY_NULL;
|
|
|
|
rootEntry.rightChild = DIRENTRY_NULL;
|
|
|
|
rootEntry.dirRootEntry = DIRENTRY_NULL;
|
|
|
|
rootEntry.startingBlock = BLOCK_END_OF_CHAIN;
|
|
|
|
rootEntry.size.u.HighPart = 0;
|
|
|
|
rootEntry.size.u.LowPart = 0;
|
|
|
|
|
|
|
|
StorageImpl_WriteDirEntry(This, 0, &rootEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-11-12 21:51:34 +01:00
|
|
|
* Find the ID of the root storage.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-11-12 21:51:34 +01:00
|
|
|
currentEntryRef = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
do
|
|
|
|
{
|
2009-11-10 21:39:10 +01:00
|
|
|
readSuccessful = StorageImpl_ReadDirEntry(
|
2002-06-01 01:06:46 +02:00
|
|
|
This,
|
2009-11-12 21:51:34 +01:00
|
|
|
currentEntryRef,
|
|
|
|
¤tEntry);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-01-29 22:12:58 +01:00
|
|
|
if (readSuccessful)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-12 21:51:34 +01:00
|
|
|
if ( (currentEntry.sizeOfNameString != 0 ) &&
|
|
|
|
(currentEntry.stgType == STGTY_ROOT) )
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-12 21:51:34 +01:00
|
|
|
This->base.storageDirEntry = currentEntryRef;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-12 21:51:34 +01:00
|
|
|
currentEntryRef++;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-11-12 20:19:37 +01:00
|
|
|
} while (readSuccessful && (This->base.storageDirEntry == DIRENTRY_NULL) );
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-01-29 22:12:58 +01:00
|
|
|
if (!readSuccessful)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
/* TODO CLEANUP */
|
2002-08-16 21:55:14 +02:00
|
|
|
return STG_E_READFAULT;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the block chain abstraction for the small block root chain.
|
|
|
|
*/
|
2002-08-16 21:55:14 +02:00
|
|
|
if(!(This->smallBlockRootChain =
|
2009-11-12 20:19:37 +01:00
|
|
|
BlockChainStream_Construct(This, NULL, This->base.storageDirEntry)))
|
2002-08-16 21:55:14 +02:00
|
|
|
return STG_E_READFAULT;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2006-08-02 13:31:26 +02:00
|
|
|
static void StorageImpl_Destroy(StorageBaseImpl* iface)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2005-02-24 20:39:27 +01:00
|
|
|
StorageImpl *This = (StorageImpl*) iface;
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p)\n", This);
|
1999-05-02 13:41:10 +02:00
|
|
|
|
2006-02-21 09:03:36 +01:00
|
|
|
StorageBaseImpl_DeleteAll(&This->base);
|
|
|
|
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->pwcsName);
|
2002-01-01 01:13:32 +01:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
BlockChainStream_Destroy(This->smallBlockRootChain);
|
|
|
|
BlockChainStream_Destroy(This->rootBlockChain);
|
|
|
|
BlockChainStream_Destroy(This->smallBlockDepotChain);
|
|
|
|
|
|
|
|
BIGBLOCKFILE_Destructor(This->bigBlockFile);
|
2005-05-10 17:59:59 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Storage32Impl_GetNextFreeBigBlock
|
|
|
|
*
|
|
|
|
* Returns the index of the next free big block.
|
|
|
|
* If the big block depot is filled, this method will enlarge it.
|
|
|
|
*
|
|
|
|
*/
|
2006-08-02 13:31:26 +02:00
|
|
|
static ULONG StorageImpl_GetNextFreeBigBlock(
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl* This)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
ULONG depotBlockIndexPos;
|
2007-03-16 19:34:28 +01:00
|
|
|
BYTE depotBuffer[BIG_BLOCK_SIZE];
|
|
|
|
BOOL success;
|
1999-01-30 14:24:23 +01:00
|
|
|
ULONG depotBlockOffset;
|
|
|
|
ULONG blocksPerDepot = This->bigBlockSize / sizeof(ULONG);
|
|
|
|
ULONG nextBlockIndex = BLOCK_SPECIAL;
|
|
|
|
int depotIndex = 0;
|
1999-03-09 18:40:00 +01:00
|
|
|
ULONG freeBlock = BLOCK_UNUSED;
|
|
|
|
|
|
|
|
depotIndex = This->prevFreeBlock / blocksPerDepot;
|
|
|
|
depotBlockOffset = (This->prevFreeBlock % blocksPerDepot) * sizeof(ULONG);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Scan the entire big block depot until we find a block marked free
|
|
|
|
*/
|
1999-02-24 11:36:34 +01:00
|
|
|
while (nextBlockIndex != BLOCK_UNUSED)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
1999-02-24 11:36:34 +01:00
|
|
|
if (depotIndex < COUNT_BBDEPOTINHEADER)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
1999-02-24 11:36:34 +01:00
|
|
|
depotBlockIndexPos = This->bigBlockDepotStart[depotIndex];
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
1999-02-24 11:36:34 +01:00
|
|
|
* Grow the primary depot.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
1999-02-24 11:36:34 +01:00
|
|
|
if (depotBlockIndexPos == BLOCK_UNUSED)
|
|
|
|
{
|
|
|
|
depotBlockIndexPos = depotIndex*blocksPerDepot;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
1999-02-24 11:36:34 +01:00
|
|
|
/*
|
|
|
|
* Add a block depot.
|
|
|
|
*/
|
|
|
|
Storage32Impl_AddBlockDepot(This, depotBlockIndexPos);
|
|
|
|
This->bigBlockDepotCount++;
|
|
|
|
This->bigBlockDepotStart[depotIndex] = depotBlockIndexPos;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
1999-02-24 11:36:34 +01:00
|
|
|
/*
|
|
|
|
* Flag it as a block depot.
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl_SetNextBlockInChain(This,
|
1999-02-24 11:36:34 +01:00
|
|
|
depotBlockIndexPos,
|
|
|
|
BLOCK_SPECIAL);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
1999-02-24 11:36:34 +01:00
|
|
|
/* Save new header information.
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl_SaveFileHeader(This);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
1999-02-24 11:36:34 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
depotBlockIndexPos = Storage32Impl_GetExtDepotBlock(This, depotIndex);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
1999-02-24 11:36:34 +01:00
|
|
|
if (depotBlockIndexPos == BLOCK_UNUSED)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Grow the extended depot.
|
|
|
|
*/
|
|
|
|
ULONG extIndex = BLOCK_UNUSED;
|
|
|
|
ULONG numExtBlocks = depotIndex - COUNT_BBDEPOTINHEADER;
|
|
|
|
ULONG extBlockOffset = numExtBlocks % (blocksPerDepot - 1);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
1999-02-24 11:36:34 +01:00
|
|
|
if (extBlockOffset == 0)
|
|
|
|
{
|
|
|
|
/* We need an extended block.
|
|
|
|
*/
|
|
|
|
extIndex = Storage32Impl_AddExtBlockDepot(This);
|
|
|
|
This->extBigBlockDepotCount++;
|
|
|
|
depotBlockIndexPos = extIndex + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
depotBlockIndexPos = depotIndex * blocksPerDepot;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a block depot and mark it in the extended block.
|
|
|
|
*/
|
|
|
|
Storage32Impl_AddBlockDepot(This, depotBlockIndexPos);
|
|
|
|
This->bigBlockDepotCount++;
|
|
|
|
Storage32Impl_SetExtDepotBlock(This, depotIndex, depotBlockIndexPos);
|
|
|
|
|
|
|
|
/* Flag the block depot.
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl_SetNextBlockInChain(This,
|
1999-02-24 11:36:34 +01:00
|
|
|
depotBlockIndexPos,
|
|
|
|
BLOCK_SPECIAL);
|
|
|
|
|
|
|
|
/* If necessary, flag the extended depot block.
|
|
|
|
*/
|
|
|
|
if (extIndex != BLOCK_UNUSED)
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl_SetNextBlockInChain(This, extIndex, BLOCK_EXTBBDEPOT);
|
1999-02-24 11:36:34 +01:00
|
|
|
|
|
|
|
/* Save header information.
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl_SaveFileHeader(This);
|
1999-02-24 11:36:34 +01:00
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
2007-03-16 19:34:28 +01:00
|
|
|
success = StorageImpl_ReadBigBlock(This, depotBlockIndexPos, depotBuffer);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2007-03-16 19:34:28 +01:00
|
|
|
if (success)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
1999-02-24 11:36:34 +01:00
|
|
|
while ( ( (depotBlockOffset/sizeof(ULONG) ) < blocksPerDepot) &&
|
1999-01-30 14:24:23 +01:00
|
|
|
( nextBlockIndex != BLOCK_UNUSED))
|
|
|
|
{
|
|
|
|
StorageUtl_ReadDWord(depotBuffer, depotBlockOffset, &nextBlockIndex);
|
|
|
|
|
1999-03-09 18:40:00 +01:00
|
|
|
if (nextBlockIndex == BLOCK_UNUSED)
|
|
|
|
{
|
|
|
|
freeBlock = (depotIndex * blocksPerDepot) +
|
|
|
|
(depotBlockOffset/sizeof(ULONG));
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
depotBlockOffset += sizeof(ULONG);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
depotIndex++;
|
1999-03-09 18:40:00 +01:00
|
|
|
depotBlockOffset = 0;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
2006-08-03 21:25:14 +02:00
|
|
|
/*
|
|
|
|
* make sure that the block physically exists before using it
|
|
|
|
*/
|
|
|
|
BIGBLOCKFILE_EnsureExists(This->bigBlockFile, freeBlock);
|
|
|
|
|
1999-03-09 18:40:00 +01:00
|
|
|
This->prevFreeBlock = freeBlock;
|
|
|
|
|
|
|
|
return freeBlock;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
1999-02-24 11:36:34 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* Storage32Impl_AddBlockDepot
|
|
|
|
*
|
|
|
|
* This will create a depot block, essentially it is a block initialized
|
|
|
|
* to BLOCK_UNUSEDs.
|
|
|
|
*/
|
2006-08-02 13:31:26 +02:00
|
|
|
static void Storage32Impl_AddBlockDepot(StorageImpl* This, ULONG blockIndex)
|
1999-02-24 11:36:34 +01:00
|
|
|
{
|
2007-03-16 19:34:28 +01:00
|
|
|
BYTE blockBuffer[BIG_BLOCK_SIZE];
|
1999-02-24 11:36:34 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize blocks as free
|
|
|
|
*/
|
|
|
|
memset(blockBuffer, BLOCK_UNUSED, This->bigBlockSize);
|
2007-03-16 19:34:28 +01:00
|
|
|
StorageImpl_WriteBigBlock(This, blockIndex, blockBuffer);
|
1999-02-24 11:36:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Storage32Impl_GetExtDepotBlock
|
|
|
|
*
|
|
|
|
* Returns the index of the block that corresponds to the specified depot
|
|
|
|
* index. This method is only for depot indexes equal or greater than
|
|
|
|
* COUNT_BBDEPOTINHEADER.
|
|
|
|
*/
|
2006-08-02 13:31:26 +02:00
|
|
|
static ULONG Storage32Impl_GetExtDepotBlock(StorageImpl* This, ULONG depotIndex)
|
1999-02-24 11:36:34 +01:00
|
|
|
{
|
|
|
|
ULONG depotBlocksPerExtBlock = (This->bigBlockSize / sizeof(ULONG)) - 1;
|
|
|
|
ULONG numExtBlocks = depotIndex - COUNT_BBDEPOTINHEADER;
|
|
|
|
ULONG extBlockCount = numExtBlocks / depotBlocksPerExtBlock;
|
|
|
|
ULONG extBlockOffset = numExtBlocks % depotBlocksPerExtBlock;
|
|
|
|
ULONG blockIndex = BLOCK_UNUSED;
|
|
|
|
ULONG extBlockIndex = This->extBigBlockDepotStart;
|
|
|
|
|
|
|
|
assert(depotIndex >= COUNT_BBDEPOTINHEADER);
|
|
|
|
|
|
|
|
if (This->extBigBlockDepotStart == BLOCK_END_OF_CHAIN)
|
|
|
|
return BLOCK_UNUSED;
|
|
|
|
|
|
|
|
while (extBlockCount > 0)
|
|
|
|
{
|
|
|
|
extBlockIndex = Storage32Impl_GetNextExtendedBlock(This, extBlockIndex);
|
|
|
|
extBlockCount--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (extBlockIndex != BLOCK_UNUSED)
|
2007-03-16 19:34:28 +01:00
|
|
|
StorageImpl_ReadDWordFromBigBlock(This, extBlockIndex,
|
|
|
|
extBlockOffset * sizeof(ULONG), &blockIndex);
|
1999-02-24 11:36:34 +01:00
|
|
|
|
|
|
|
return blockIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Storage32Impl_SetExtDepotBlock
|
|
|
|
*
|
|
|
|
* Associates the specified block index to the specified depot index.
|
|
|
|
* This method is only for depot indexes equal or greater than
|
|
|
|
* COUNT_BBDEPOTINHEADER.
|
|
|
|
*/
|
2006-08-02 13:31:26 +02:00
|
|
|
static void Storage32Impl_SetExtDepotBlock(StorageImpl* This, ULONG depotIndex, ULONG blockIndex)
|
1999-02-24 11:36:34 +01:00
|
|
|
{
|
|
|
|
ULONG depotBlocksPerExtBlock = (This->bigBlockSize / sizeof(ULONG)) - 1;
|
|
|
|
ULONG numExtBlocks = depotIndex - COUNT_BBDEPOTINHEADER;
|
|
|
|
ULONG extBlockCount = numExtBlocks / depotBlocksPerExtBlock;
|
|
|
|
ULONG extBlockOffset = numExtBlocks % depotBlocksPerExtBlock;
|
|
|
|
ULONG extBlockIndex = This->extBigBlockDepotStart;
|
|
|
|
|
|
|
|
assert(depotIndex >= COUNT_BBDEPOTINHEADER);
|
|
|
|
|
|
|
|
while (extBlockCount > 0)
|
|
|
|
{
|
|
|
|
extBlockIndex = Storage32Impl_GetNextExtendedBlock(This, extBlockIndex);
|
|
|
|
extBlockCount--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (extBlockIndex != BLOCK_UNUSED)
|
|
|
|
{
|
2007-03-16 19:34:28 +01:00
|
|
|
StorageImpl_WriteDWordToBigBlock(This, extBlockIndex,
|
|
|
|
extBlockOffset * sizeof(ULONG),
|
|
|
|
blockIndex);
|
1999-02-24 11:36:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Storage32Impl_AddExtBlockDepot
|
|
|
|
*
|
|
|
|
* Creates an extended depot block.
|
|
|
|
*/
|
2006-08-02 13:31:26 +02:00
|
|
|
static ULONG Storage32Impl_AddExtBlockDepot(StorageImpl* This)
|
1999-02-24 11:36:34 +01:00
|
|
|
{
|
|
|
|
ULONG numExtBlocks = This->extBigBlockDepotCount;
|
|
|
|
ULONG nextExtBlock = This->extBigBlockDepotStart;
|
2007-03-16 19:34:28 +01:00
|
|
|
BYTE depotBuffer[BIG_BLOCK_SIZE];
|
1999-02-24 11:36:34 +01:00
|
|
|
ULONG index = BLOCK_UNUSED;
|
|
|
|
ULONG nextBlockOffset = This->bigBlockSize - sizeof(ULONG);
|
|
|
|
ULONG blocksPerDepotBlock = This->bigBlockSize / sizeof(ULONG);
|
|
|
|
ULONG depotBlocksPerExtBlock = blocksPerDepotBlock - 1;
|
|
|
|
|
|
|
|
index = (COUNT_BBDEPOTINHEADER + (numExtBlocks * depotBlocksPerExtBlock)) *
|
|
|
|
blocksPerDepotBlock;
|
|
|
|
|
|
|
|
if ((numExtBlocks == 0) && (nextExtBlock == BLOCK_END_OF_CHAIN))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The first extended block.
|
|
|
|
*/
|
|
|
|
This->extBigBlockDepotStart = index;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-09-22 04:46:38 +02:00
|
|
|
unsigned int i;
|
1999-02-24 11:36:34 +01:00
|
|
|
/*
|
|
|
|
* Follow the chain to the last one.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < (numExtBlocks - 1); i++)
|
|
|
|
{
|
|
|
|
nextExtBlock = Storage32Impl_GetNextExtendedBlock(This, nextExtBlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add the new extended block to the chain.
|
|
|
|
*/
|
2007-03-16 19:34:28 +01:00
|
|
|
StorageImpl_WriteDWordToBigBlock(This, nextExtBlock, nextBlockOffset,
|
|
|
|
index);
|
1999-02-24 11:36:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize this block.
|
|
|
|
*/
|
|
|
|
memset(depotBuffer, BLOCK_UNUSED, This->bigBlockSize);
|
2007-03-16 19:34:28 +01:00
|
|
|
StorageImpl_WriteBigBlock(This, index, depotBuffer);
|
1999-02-24 11:36:34 +01:00
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* Storage32Impl_FreeBigBlock
|
|
|
|
*
|
|
|
|
* This method will flag the specified block as free in the big block depot.
|
|
|
|
*/
|
2006-08-02 13:31:26 +02:00
|
|
|
static void StorageImpl_FreeBigBlock(
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl* This,
|
1999-01-30 14:24:23 +01:00
|
|
|
ULONG blockIndex)
|
|
|
|
{
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl_SetNextBlockInChain(This, blockIndex, BLOCK_UNUSED);
|
1999-03-09 18:40:00 +01:00
|
|
|
|
|
|
|
if (blockIndex < This->prevFreeBlock)
|
|
|
|
This->prevFreeBlock = blockIndex;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* Storage32Impl_GetNextBlockInChain
|
|
|
|
*
|
|
|
|
* This method will retrieve the block index of the next big block in
|
|
|
|
* in the chain.
|
|
|
|
*
|
|
|
|
* Params: This - Pointer to the Storage object.
|
|
|
|
* blockIndex - Index of the block to retrieve the chain
|
|
|
|
* for.
|
2002-08-16 21:55:14 +02:00
|
|
|
* nextBlockIndex - receives the return value.
|
1999-01-30 14:24:23 +01:00
|
|
|
*
|
|
|
|
* Returns: This method returns the index of the next block in the chain.
|
|
|
|
* It will return the constants:
|
|
|
|
* BLOCK_SPECIAL - If the block given was not part of a
|
|
|
|
* chain.
|
|
|
|
* BLOCK_END_OF_CHAIN - If the block given was the last in
|
|
|
|
* a chain.
|
|
|
|
* BLOCK_UNUSED - If the block given was not past of a chain
|
|
|
|
* and is available.
|
1999-02-24 11:36:34 +01:00
|
|
|
* BLOCK_EXTBBDEPOT - This block is part of the extended
|
|
|
|
* big block depot.
|
|
|
|
*
|
1999-01-30 14:24:23 +01:00
|
|
|
* See Windows documentation for more details on IStorage methods.
|
1999-02-24 11:36:34 +01:00
|
|
|
*/
|
2006-08-02 13:31:26 +02:00
|
|
|
static HRESULT StorageImpl_GetNextBlockInChain(
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl* This,
|
2002-08-16 21:55:14 +02:00
|
|
|
ULONG blockIndex,
|
|
|
|
ULONG* nextBlockIndex)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
ULONG offsetInDepot = blockIndex * sizeof (ULONG);
|
|
|
|
ULONG depotBlockCount = offsetInDepot / This->bigBlockSize;
|
|
|
|
ULONG depotBlockOffset = offsetInDepot % This->bigBlockSize;
|
2007-03-16 19:34:28 +01:00
|
|
|
BYTE depotBuffer[BIG_BLOCK_SIZE];
|
|
|
|
BOOL success;
|
1999-01-30 14:24:23 +01:00
|
|
|
ULONG depotBlockIndexPos;
|
2002-08-16 21:55:14 +02:00
|
|
|
int index;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-08-16 21:55:14 +02:00
|
|
|
*nextBlockIndex = BLOCK_SPECIAL;
|
|
|
|
|
|
|
|
if(depotBlockCount >= This->bigBlockDepotCount)
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
WARN("depotBlockCount %d, bigBlockDepotCount %d\n", depotBlockCount,
|
2002-08-16 21:55:14 +02:00
|
|
|
This->bigBlockDepotCount);
|
|
|
|
return STG_E_READFAULT;
|
|
|
|
}
|
1999-02-24 11:36:34 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Cache the currently accessed depot block.
|
|
|
|
*/
|
|
|
|
if (depotBlockCount != This->indexBlockDepotCached)
|
|
|
|
{
|
|
|
|
This->indexBlockDepotCached = depotBlockCount;
|
|
|
|
|
|
|
|
if (depotBlockCount < COUNT_BBDEPOTINHEADER)
|
|
|
|
{
|
|
|
|
depotBlockIndexPos = This->bigBlockDepotStart[depotBlockCount];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We have to look in the extended depot.
|
|
|
|
*/
|
|
|
|
depotBlockIndexPos = Storage32Impl_GetExtDepotBlock(This, depotBlockCount);
|
|
|
|
}
|
|
|
|
|
2007-03-16 19:34:28 +01:00
|
|
|
success = StorageImpl_ReadBigBlock(This, depotBlockIndexPos, depotBuffer);
|
1999-02-24 11:36:34 +01:00
|
|
|
|
2007-03-16 19:34:28 +01:00
|
|
|
if (!success)
|
2002-08-16 21:55:14 +02:00
|
|
|
return STG_E_READFAULT;
|
1999-02-24 11:36:34 +01:00
|
|
|
|
2002-08-16 21:55:14 +02:00
|
|
|
for (index = 0; index < NUM_BLOCKS_PER_DEPOT_BLOCK; index++)
|
|
|
|
{
|
|
|
|
StorageUtl_ReadDWord(depotBuffer, index*sizeof(ULONG), nextBlockIndex);
|
|
|
|
This->blockDepotCached[index] = *nextBlockIndex;
|
1999-02-24 11:36:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-16 21:55:14 +02:00
|
|
|
*nextBlockIndex = This->blockDepotCached[depotBlockOffset/sizeof(ULONG)];
|
1999-02-24 11:36:34 +01:00
|
|
|
|
2002-08-16 21:55:14 +02:00
|
|
|
return S_OK;
|
1999-02-24 11:36:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Storage32Impl_GetNextExtendedBlock
|
|
|
|
*
|
|
|
|
* Given an extended block this method will return the next extended block.
|
|
|
|
*
|
|
|
|
* NOTES:
|
|
|
|
* The last ULONG of an extended block is the block index of the next
|
|
|
|
* extended block. Extended blocks are marked as BLOCK_EXTBBDEPOT in the
|
|
|
|
* depot.
|
|
|
|
*
|
|
|
|
* Return values:
|
|
|
|
* - The index of the next extended block
|
|
|
|
* - BLOCK_UNUSED: there is no next extended block.
|
|
|
|
* - Any other return values denotes failure.
|
|
|
|
*/
|
2006-08-02 13:31:26 +02:00
|
|
|
static ULONG Storage32Impl_GetNextExtendedBlock(StorageImpl* This, ULONG blockIndex)
|
1999-02-24 11:36:34 +01:00
|
|
|
{
|
|
|
|
ULONG nextBlockIndex = BLOCK_SPECIAL;
|
|
|
|
ULONG depotBlockOffset = This->bigBlockSize - sizeof(ULONG);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2007-03-16 19:34:28 +01:00
|
|
|
StorageImpl_ReadDWordFromBigBlock(This, blockIndex, depotBlockOffset,
|
|
|
|
&nextBlockIndex);
|
1999-02-24 11:36:34 +01:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
return nextBlockIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Storage32Impl_SetNextBlockInChain
|
|
|
|
*
|
|
|
|
* This method will write the index of the specified block's next block
|
|
|
|
* in the big block depot.
|
|
|
|
*
|
|
|
|
* For example: to create the chain 3 -> 1 -> 7 -> End of Chain
|
|
|
|
* do the following
|
|
|
|
*
|
|
|
|
* Storage32Impl_SetNextBlockInChain(This, 3, 1);
|
|
|
|
* Storage32Impl_SetNextBlockInChain(This, 1, 7);
|
|
|
|
* Storage32Impl_SetNextBlockInChain(This, 7, BLOCK_END_OF_CHAIN);
|
|
|
|
*
|
|
|
|
*/
|
2006-08-02 13:31:26 +02:00
|
|
|
static void StorageImpl_SetNextBlockInChain(
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl* This,
|
1999-01-30 14:24:23 +01:00
|
|
|
ULONG blockIndex,
|
|
|
|
ULONG nextBlock)
|
|
|
|
{
|
|
|
|
ULONG offsetInDepot = blockIndex * sizeof (ULONG);
|
|
|
|
ULONG depotBlockCount = offsetInDepot / This->bigBlockSize;
|
|
|
|
ULONG depotBlockOffset = offsetInDepot % This->bigBlockSize;
|
|
|
|
ULONG depotBlockIndexPos;
|
|
|
|
|
|
|
|
assert(depotBlockCount < This->bigBlockDepotCount);
|
1999-03-12 18:06:46 +01:00
|
|
|
assert(blockIndex != nextBlock);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
1999-02-24 11:36:34 +01:00
|
|
|
if (depotBlockCount < COUNT_BBDEPOTINHEADER)
|
|
|
|
{
|
|
|
|
depotBlockIndexPos = This->bigBlockDepotStart[depotBlockCount];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We have to look in the extended depot.
|
|
|
|
*/
|
|
|
|
depotBlockIndexPos = Storage32Impl_GetExtDepotBlock(This, depotBlockCount);
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2007-03-16 19:34:28 +01:00
|
|
|
StorageImpl_WriteDWordToBigBlock(This, depotBlockIndexPos, depotBlockOffset,
|
|
|
|
nextBlock);
|
1999-02-24 11:36:34 +01:00
|
|
|
/*
|
|
|
|
* Update the cached block depot, if necessary.
|
|
|
|
*/
|
|
|
|
if (depotBlockCount == This->indexBlockDepotCached)
|
|
|
|
{
|
|
|
|
This->blockDepotCached[depotBlockOffset/sizeof(ULONG)] = nextBlock;
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Storage32Impl_LoadFileHeader
|
|
|
|
*
|
|
|
|
* This method will read in the file header, i.e. big block index -1.
|
|
|
|
*/
|
2006-08-02 13:31:26 +02:00
|
|
|
static HRESULT StorageImpl_LoadFileHeader(
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl* This)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
HRESULT hr = STG_E_FILENOTFOUND;
|
2007-03-16 19:34:28 +01:00
|
|
|
BYTE headerBigBlock[BIG_BLOCK_SIZE];
|
|
|
|
BOOL success;
|
1999-01-30 14:24:23 +01:00
|
|
|
int index;
|
|
|
|
|
2006-02-24 18:06:35 +01:00
|
|
|
TRACE("\n");
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Get a pointer to the big block of data containing the header.
|
|
|
|
*/
|
2007-03-16 19:34:28 +01:00
|
|
|
success = StorageImpl_ReadBigBlock(This, -1, headerBigBlock);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Extract the information from the header.
|
|
|
|
*/
|
2007-03-16 19:34:28 +01:00
|
|
|
if (success)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Check for the "magic number" signature and return an error if it is not
|
|
|
|
* found.
|
|
|
|
*/
|
|
|
|
if (memcmp(headerBigBlock, STORAGE_oldmagic, sizeof(STORAGE_oldmagic))==0)
|
|
|
|
{
|
|
|
|
return STG_E_OLDFORMAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (memcmp(headerBigBlock, STORAGE_magic, sizeof(STORAGE_magic))!=0)
|
|
|
|
{
|
|
|
|
return STG_E_INVALIDHEADER;
|
|
|
|
}
|
|
|
|
|
|
|
|
StorageUtl_ReadWord(
|
2002-06-01 01:06:46 +02:00
|
|
|
headerBigBlock,
|
|
|
|
OFFSET_BIGBLOCKSIZEBITS,
|
1999-01-30 14:24:23 +01:00
|
|
|
&This->bigBlockSizeBits);
|
|
|
|
|
|
|
|
StorageUtl_ReadWord(
|
2002-06-01 01:06:46 +02:00
|
|
|
headerBigBlock,
|
|
|
|
OFFSET_SMALLBLOCKSIZEBITS,
|
1999-01-30 14:24:23 +01:00
|
|
|
&This->smallBlockSizeBits);
|
|
|
|
|
|
|
|
StorageUtl_ReadDWord(
|
2002-06-01 01:06:46 +02:00
|
|
|
headerBigBlock,
|
|
|
|
OFFSET_BBDEPOTCOUNT,
|
1999-01-30 14:24:23 +01:00
|
|
|
&This->bigBlockDepotCount);
|
|
|
|
|
|
|
|
StorageUtl_ReadDWord(
|
2002-06-01 01:06:46 +02:00
|
|
|
headerBigBlock,
|
|
|
|
OFFSET_ROOTSTARTBLOCK,
|
1999-01-30 14:24:23 +01:00
|
|
|
&This->rootStartBlock);
|
|
|
|
|
|
|
|
StorageUtl_ReadDWord(
|
2002-06-01 01:06:46 +02:00
|
|
|
headerBigBlock,
|
|
|
|
OFFSET_SBDEPOTSTART,
|
1999-01-30 14:24:23 +01:00
|
|
|
&This->smallBlockDepotStart);
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
StorageUtl_ReadDWord(
|
|
|
|
headerBigBlock,
|
|
|
|
OFFSET_EXTBBDEPOTSTART,
|
1999-01-30 14:24:23 +01:00
|
|
|
&This->extBigBlockDepotStart);
|
|
|
|
|
|
|
|
StorageUtl_ReadDWord(
|
2002-06-01 01:06:46 +02:00
|
|
|
headerBigBlock,
|
|
|
|
OFFSET_EXTBBDEPOTCOUNT,
|
1999-01-30 14:24:23 +01:00
|
|
|
&This->extBigBlockDepotCount);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
for (index = 0; index < COUNT_BBDEPOTINHEADER; index ++)
|
|
|
|
{
|
|
|
|
StorageUtl_ReadDWord(
|
2002-06-01 01:06:46 +02:00
|
|
|
headerBigBlock,
|
1999-01-30 14:24:23 +01:00
|
|
|
OFFSET_BBDEPOTSTART + (sizeof(ULONG)*index),
|
|
|
|
&(This->bigBlockDepotStart[index]));
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Make the bitwise arithmetic to get the size of the blocks in bytes.
|
|
|
|
*/
|
2008-08-17 19:34:04 +02:00
|
|
|
This->bigBlockSize = 0x000000001 << (DWORD)This->bigBlockSizeBits;
|
|
|
|
This->smallBlockSize = 0x000000001 << (DWORD)This->smallBlockSizeBits;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Right now, the code is making some assumptions about the size of the
|
1999-01-30 14:24:23 +01:00
|
|
|
* blocks, just make sure they are what we're expecting.
|
|
|
|
*/
|
2002-01-31 22:01:35 +01:00
|
|
|
if (This->bigBlockSize != DEF_BIG_BLOCK_SIZE ||
|
|
|
|
This->smallBlockSize != DEF_SMALL_BLOCK_SIZE)
|
|
|
|
{
|
|
|
|
WARN("Broken OLE storage file\n");
|
|
|
|
hr = STG_E_INVALIDHEADER;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = S_OK;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Storage32Impl_SaveFileHeader
|
|
|
|
*
|
|
|
|
* This method will save to the file the header, i.e. big block -1.
|
|
|
|
*/
|
2006-08-02 13:31:26 +02:00
|
|
|
static void StorageImpl_SaveFileHeader(
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl* This)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
BYTE headerBigBlock[BIG_BLOCK_SIZE];
|
|
|
|
int index;
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL success;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a pointer to the big block of data containing the header.
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
success = StorageImpl_ReadBigBlock(This, -1, headerBigBlock);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* If the block read failed, the file is probably new.
|
|
|
|
*/
|
|
|
|
if (!success)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Initialize for all unknown fields.
|
|
|
|
*/
|
|
|
|
memset(headerBigBlock, 0, BIG_BLOCK_SIZE);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Initialize the magic number.
|
|
|
|
*/
|
|
|
|
memcpy(headerBigBlock, STORAGE_magic, sizeof(STORAGE_magic));
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* And a bunch of things we don't know what they mean
|
|
|
|
*/
|
|
|
|
StorageUtl_WriteWord(headerBigBlock, 0x18, 0x3b);
|
|
|
|
StorageUtl_WriteWord(headerBigBlock, 0x1a, 0x3);
|
|
|
|
StorageUtl_WriteWord(headerBigBlock, 0x1c, (WORD)-2);
|
|
|
|
StorageUtl_WriteDWord(headerBigBlock, 0x38, (DWORD)0x1000);
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Write the information to the header.
|
|
|
|
*/
|
2002-08-16 21:55:14 +02:00
|
|
|
StorageUtl_WriteWord(
|
|
|
|
headerBigBlock,
|
|
|
|
OFFSET_BIGBLOCKSIZEBITS,
|
|
|
|
This->bigBlockSizeBits);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-08-16 21:55:14 +02:00
|
|
|
StorageUtl_WriteWord(
|
|
|
|
headerBigBlock,
|
|
|
|
OFFSET_SMALLBLOCKSIZEBITS,
|
|
|
|
This->smallBlockSizeBits);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-08-16 21:55:14 +02:00
|
|
|
StorageUtl_WriteDWord(
|
|
|
|
headerBigBlock,
|
|
|
|
OFFSET_BBDEPOTCOUNT,
|
|
|
|
This->bigBlockDepotCount);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-08-16 21:55:14 +02:00
|
|
|
StorageUtl_WriteDWord(
|
|
|
|
headerBigBlock,
|
|
|
|
OFFSET_ROOTSTARTBLOCK,
|
|
|
|
This->rootStartBlock);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-08-16 21:55:14 +02:00
|
|
|
StorageUtl_WriteDWord(
|
|
|
|
headerBigBlock,
|
|
|
|
OFFSET_SBDEPOTSTART,
|
|
|
|
This->smallBlockDepotStart);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-08-16 21:55:14 +02:00
|
|
|
StorageUtl_WriteDWord(
|
|
|
|
headerBigBlock,
|
|
|
|
OFFSET_SBDEPOTCOUNT,
|
|
|
|
This->smallBlockDepotChain ?
|
|
|
|
BlockChainStream_GetCount(This->smallBlockDepotChain) : 0);
|
|
|
|
|
|
|
|
StorageUtl_WriteDWord(
|
|
|
|
headerBigBlock,
|
|
|
|
OFFSET_EXTBBDEPOTSTART,
|
|
|
|
This->extBigBlockDepotStart);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-08-16 21:55:14 +02:00
|
|
|
StorageUtl_WriteDWord(
|
|
|
|
headerBigBlock,
|
|
|
|
OFFSET_EXTBBDEPOTCOUNT,
|
|
|
|
This->extBigBlockDepotCount);
|
|
|
|
|
|
|
|
for (index = 0; index < COUNT_BBDEPOTINHEADER; index ++)
|
|
|
|
{
|
1999-01-30 14:24:23 +01:00
|
|
|
StorageUtl_WriteDWord(
|
2002-06-01 01:06:46 +02:00
|
|
|
headerBigBlock,
|
2002-08-16 21:55:14 +02:00
|
|
|
OFFSET_BBDEPOTSTART + (sizeof(ULONG)*index),
|
|
|
|
(This->bigBlockDepotStart[index]));
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Write the big block back to the file.
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl_WriteBigBlock(This, -1, headerBigBlock);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
2009-10-28 17:37:30 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* StorageImpl_ReadRawDirEntry
|
|
|
|
*
|
|
|
|
* This method will read the raw data from a directory entry in the file.
|
|
|
|
*
|
2009-11-12 21:54:23 +01:00
|
|
|
* buffer must be RAW_DIRENTRY_SIZE bytes long.
|
2009-10-28 17:37:30 +01:00
|
|
|
*/
|
|
|
|
HRESULT StorageImpl_ReadRawDirEntry(StorageImpl *This, ULONG index, BYTE *buffer)
|
|
|
|
{
|
|
|
|
ULARGE_INTEGER offset;
|
|
|
|
HRESULT hr;
|
|
|
|
ULONG bytesRead;
|
|
|
|
|
|
|
|
offset.u.HighPart = 0;
|
2009-11-11 17:34:45 +01:00
|
|
|
offset.u.LowPart = index * RAW_DIRENTRY_SIZE;
|
2009-10-28 17:37:30 +01:00
|
|
|
|
|
|
|
hr = BlockChainStream_ReadAt(
|
|
|
|
This->rootBlockChain,
|
|
|
|
offset,
|
2009-11-11 17:34:45 +01:00
|
|
|
RAW_DIRENTRY_SIZE,
|
2009-10-28 17:37:30 +01:00
|
|
|
buffer,
|
|
|
|
&bytesRead);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2009-10-28 17:41:50 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* StorageImpl_WriteRawDirEntry
|
|
|
|
*
|
|
|
|
* This method will write the raw data from a directory entry in the file.
|
|
|
|
*
|
2009-11-12 21:54:23 +01:00
|
|
|
* buffer must be RAW_DIRENTRY_SIZE bytes long.
|
2009-10-28 17:41:50 +01:00
|
|
|
*/
|
|
|
|
HRESULT StorageImpl_WriteRawDirEntry(StorageImpl *This, ULONG index, const BYTE *buffer)
|
|
|
|
{
|
|
|
|
ULARGE_INTEGER offset;
|
|
|
|
HRESULT hr;
|
|
|
|
ULONG bytesRead;
|
|
|
|
|
|
|
|
offset.u.HighPart = 0;
|
2009-11-11 17:34:45 +01:00
|
|
|
offset.u.LowPart = index * RAW_DIRENTRY_SIZE;
|
2009-10-28 17:41:50 +01:00
|
|
|
|
|
|
|
hr = BlockChainStream_WriteAt(
|
|
|
|
This->rootBlockChain,
|
|
|
|
offset,
|
2009-11-11 17:34:45 +01:00
|
|
|
RAW_DIRENTRY_SIZE,
|
2009-10-28 17:41:50 +01:00
|
|
|
buffer,
|
|
|
|
&bytesRead);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2009-10-28 19:27:52 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* UpdateRawDirEntry
|
|
|
|
*
|
|
|
|
* Update raw directory entry data from the fields in newData.
|
|
|
|
*
|
2009-11-12 21:54:23 +01:00
|
|
|
* buffer must be RAW_DIRENTRY_SIZE bytes long.
|
2009-10-28 19:27:52 +01:00
|
|
|
*/
|
2009-11-10 21:30:59 +01:00
|
|
|
void UpdateRawDirEntry(BYTE *buffer, const DirEntry *newData)
|
2009-10-28 19:27:52 +01:00
|
|
|
{
|
2009-11-11 17:34:45 +01:00
|
|
|
memset(buffer, 0, RAW_DIRENTRY_SIZE);
|
2009-10-28 19:27:52 +01:00
|
|
|
|
|
|
|
memcpy(
|
|
|
|
buffer + OFFSET_PS_NAME,
|
|
|
|
newData->name,
|
2009-11-11 17:31:55 +01:00
|
|
|
DIRENTRY_NAME_BUFFER_LEN );
|
2009-10-28 19:27:52 +01:00
|
|
|
|
2009-11-12 19:34:05 +01:00
|
|
|
memcpy(buffer + OFFSET_PS_STGTYPE, &newData->stgType, 1);
|
2009-10-28 19:27:52 +01:00
|
|
|
|
|
|
|
StorageUtl_WriteWord(
|
|
|
|
buffer,
|
|
|
|
OFFSET_PS_NAMELENGTH,
|
|
|
|
newData->sizeOfNameString);
|
|
|
|
|
|
|
|
StorageUtl_WriteDWord(
|
|
|
|
buffer,
|
|
|
|
OFFSET_PS_LEFTCHILD,
|
|
|
|
newData->leftChild);
|
|
|
|
|
|
|
|
StorageUtl_WriteDWord(
|
|
|
|
buffer,
|
|
|
|
OFFSET_PS_RIGHTCHILD,
|
|
|
|
newData->rightChild);
|
|
|
|
|
|
|
|
StorageUtl_WriteDWord(
|
|
|
|
buffer,
|
2009-11-11 17:40:12 +01:00
|
|
|
OFFSET_PS_DIRROOT,
|
|
|
|
newData->dirRootEntry);
|
2009-10-28 19:27:52 +01:00
|
|
|
|
|
|
|
StorageUtl_WriteGUID(
|
|
|
|
buffer,
|
|
|
|
OFFSET_PS_GUID,
|
2009-11-12 20:10:17 +01:00
|
|
|
&newData->clsid);
|
2009-10-28 19:27:52 +01:00
|
|
|
|
|
|
|
StorageUtl_WriteDWord(
|
|
|
|
buffer,
|
|
|
|
OFFSET_PS_CTIMELOW,
|
|
|
|
newData->ctime.dwLowDateTime);
|
|
|
|
|
|
|
|
StorageUtl_WriteDWord(
|
|
|
|
buffer,
|
|
|
|
OFFSET_PS_CTIMEHIGH,
|
|
|
|
newData->ctime.dwHighDateTime);
|
|
|
|
|
|
|
|
StorageUtl_WriteDWord(
|
|
|
|
buffer,
|
|
|
|
OFFSET_PS_MTIMELOW,
|
|
|
|
newData->mtime.dwLowDateTime);
|
|
|
|
|
|
|
|
StorageUtl_WriteDWord(
|
|
|
|
buffer,
|
|
|
|
OFFSET_PS_MTIMEHIGH,
|
|
|
|
newData->ctime.dwHighDateTime);
|
|
|
|
|
|
|
|
StorageUtl_WriteDWord(
|
|
|
|
buffer,
|
|
|
|
OFFSET_PS_STARTBLOCK,
|
|
|
|
newData->startingBlock);
|
|
|
|
|
|
|
|
StorageUtl_WriteDWord(
|
|
|
|
buffer,
|
|
|
|
OFFSET_PS_SIZE,
|
|
|
|
newData->size.u.LowPart);
|
|
|
|
}
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/******************************************************************************
|
2009-11-12 21:54:23 +01:00
|
|
|
* Storage32Impl_ReadDirEntry
|
1999-01-30 14:24:23 +01:00
|
|
|
*
|
2009-11-12 21:54:23 +01:00
|
|
|
* This method will read the specified directory entry.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-11-10 21:39:10 +01:00
|
|
|
BOOL StorageImpl_ReadDirEntry(
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl* This,
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef index,
|
2009-11-10 21:30:59 +01:00
|
|
|
DirEntry* buffer)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-12 21:54:23 +01:00
|
|
|
BYTE currentEntry[RAW_DIRENTRY_SIZE];
|
2006-09-11 12:13:47 +02:00
|
|
|
HRESULT readRes;
|
1999-03-12 18:06:46 +01:00
|
|
|
|
2009-11-12 21:54:23 +01:00
|
|
|
readRes = StorageImpl_ReadRawDirEntry(This, index, currentEntry);
|
2002-01-31 22:01:35 +01:00
|
|
|
|
2006-09-11 12:13:47 +02:00
|
|
|
if (SUCCEEDED(readRes))
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2002-01-31 22:01:35 +01:00
|
|
|
/* replace the name of root entry (often "Root Entry") by the file name */
|
2009-11-12 21:54:23 +01:00
|
|
|
WCHAR *entryName = (index == This->base.storageDirEntry) ?
|
|
|
|
This->filename : (WCHAR *)currentEntry+OFFSET_PS_NAME;
|
2002-01-31 22:01:35 +01:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
memset(buffer->name, 0, sizeof(buffer->name));
|
|
|
|
memcpy(
|
2002-06-01 01:06:46 +02:00
|
|
|
buffer->name,
|
2009-11-12 21:54:23 +01:00
|
|
|
entryName,
|
2009-11-11 17:31:55 +01:00
|
|
|
DIRENTRY_NAME_BUFFER_LEN );
|
2002-01-31 22:01:35 +01:00
|
|
|
TRACE("storage name: %s\n", debugstr_w(buffer->name));
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 21:54:23 +01:00
|
|
|
memcpy(&buffer->stgType, currentEntry + OFFSET_PS_STGTYPE, 1);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
StorageUtl_ReadWord(
|
2009-11-12 21:54:23 +01:00
|
|
|
currentEntry,
|
2002-06-01 01:06:46 +02:00
|
|
|
OFFSET_PS_NAMELENGTH,
|
1999-01-30 14:24:23 +01:00
|
|
|
&buffer->sizeOfNameString);
|
|
|
|
|
|
|
|
StorageUtl_ReadDWord(
|
2009-11-12 21:54:23 +01:00
|
|
|
currentEntry,
|
2009-10-23 20:36:59 +02:00
|
|
|
OFFSET_PS_LEFTCHILD,
|
|
|
|
&buffer->leftChild);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
StorageUtl_ReadDWord(
|
2009-11-12 21:54:23 +01:00
|
|
|
currentEntry,
|
2009-10-23 20:36:59 +02:00
|
|
|
OFFSET_PS_RIGHTCHILD,
|
|
|
|
&buffer->rightChild);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
StorageUtl_ReadDWord(
|
2009-11-12 21:54:23 +01:00
|
|
|
currentEntry,
|
2009-11-11 17:40:12 +01:00
|
|
|
OFFSET_PS_DIRROOT,
|
|
|
|
&buffer->dirRootEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
StorageUtl_ReadGUID(
|
2009-11-12 21:54:23 +01:00
|
|
|
currentEntry,
|
2002-06-01 01:06:46 +02:00
|
|
|
OFFSET_PS_GUID,
|
2009-11-12 20:10:17 +01:00
|
|
|
&buffer->clsid);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
StorageUtl_ReadDWord(
|
2009-11-12 21:54:23 +01:00
|
|
|
currentEntry,
|
2009-10-23 20:29:56 +02:00
|
|
|
OFFSET_PS_CTIMELOW,
|
|
|
|
&buffer->ctime.dwLowDateTime);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
StorageUtl_ReadDWord(
|
2009-11-12 21:54:23 +01:00
|
|
|
currentEntry,
|
2009-10-23 20:29:56 +02:00
|
|
|
OFFSET_PS_CTIMEHIGH,
|
|
|
|
&buffer->ctime.dwHighDateTime);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
StorageUtl_ReadDWord(
|
2009-11-12 21:54:23 +01:00
|
|
|
currentEntry,
|
2009-10-23 20:29:56 +02:00
|
|
|
OFFSET_PS_MTIMELOW,
|
|
|
|
&buffer->mtime.dwLowDateTime);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
StorageUtl_ReadDWord(
|
2009-11-12 21:54:23 +01:00
|
|
|
currentEntry,
|
2009-10-23 20:29:56 +02:00
|
|
|
OFFSET_PS_MTIMEHIGH,
|
|
|
|
&buffer->mtime.dwHighDateTime);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
StorageUtl_ReadDWord(
|
2009-11-12 21:54:23 +01:00
|
|
|
currentEntry,
|
2002-06-01 01:06:46 +02:00
|
|
|
OFFSET_PS_STARTBLOCK,
|
1999-01-30 14:24:23 +01:00
|
|
|
&buffer->startingBlock);
|
|
|
|
|
|
|
|
StorageUtl_ReadDWord(
|
2009-11-12 21:54:23 +01:00
|
|
|
currentEntry,
|
2002-06-01 01:06:46 +02:00
|
|
|
OFFSET_PS_SIZE,
|
2004-01-23 02:51:33 +01:00
|
|
|
&buffer->size.u.LowPart);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
buffer->size.u.HighPart = 0;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
2006-09-11 12:13:47 +02:00
|
|
|
return SUCCEEDED(readRes) ? TRUE : FALSE;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2009-11-12 21:54:23 +01:00
|
|
|
* Write the specified directory entry to the file
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-11-10 21:40:05 +01:00
|
|
|
BOOL StorageImpl_WriteDirEntry(
|
2007-07-04 21:12:48 +02:00
|
|
|
StorageImpl* This,
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef index,
|
2009-11-10 21:30:59 +01:00
|
|
|
const DirEntry* buffer)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-12 21:54:23 +01:00
|
|
|
BYTE currentEntry[RAW_DIRENTRY_SIZE];
|
2006-09-11 12:13:47 +02:00
|
|
|
HRESULT writeRes;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 21:54:23 +01:00
|
|
|
UpdateRawDirEntry(currentEntry, buffer);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 21:54:23 +01:00
|
|
|
writeRes = StorageImpl_WriteRawDirEntry(This, index, currentEntry);
|
2006-09-11 12:13:47 +02:00
|
|
|
return SUCCEEDED(writeRes) ? TRUE : FALSE;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
2006-08-02 13:31:26 +02:00
|
|
|
static BOOL StorageImpl_ReadBigBlock(
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl* This,
|
1999-01-30 14:24:23 +01:00
|
|
|
ULONG blockIndex,
|
|
|
|
void* buffer)
|
|
|
|
{
|
2007-03-16 19:34:28 +01:00
|
|
|
ULARGE_INTEGER ulOffset;
|
|
|
|
DWORD read;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2007-03-16 19:34:28 +01:00
|
|
|
ulOffset.u.HighPart = 0;
|
|
|
|
ulOffset.u.LowPart = BLOCK_GetBigBlockOffset(blockIndex);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2007-03-16 19:34:28 +01:00
|
|
|
StorageImpl_ReadAt(This, ulOffset, buffer, This->bigBlockSize, &read);
|
|
|
|
return (read == This->bigBlockSize);
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2007-03-16 19:34:28 +01:00
|
|
|
static BOOL StorageImpl_ReadDWordFromBigBlock(
|
|
|
|
StorageImpl* This,
|
|
|
|
ULONG blockIndex,
|
|
|
|
ULONG offset,
|
|
|
|
DWORD* value)
|
|
|
|
{
|
|
|
|
ULARGE_INTEGER ulOffset;
|
|
|
|
DWORD read;
|
|
|
|
DWORD tmp;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2007-03-16 19:34:28 +01:00
|
|
|
ulOffset.u.HighPart = 0;
|
|
|
|
ulOffset.u.LowPart = BLOCK_GetBigBlockOffset(blockIndex);
|
|
|
|
ulOffset.u.LowPart += offset;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2007-03-16 19:34:28 +01:00
|
|
|
StorageImpl_ReadAt(This, ulOffset, &tmp, sizeof(DWORD), &read);
|
2009-04-23 18:17:49 +02:00
|
|
|
*value = lendian32toh(tmp);
|
2007-03-16 19:34:28 +01:00
|
|
|
return (read == sizeof(DWORD));
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
2006-08-02 13:31:26 +02:00
|
|
|
static BOOL StorageImpl_WriteBigBlock(
|
2007-07-04 21:12:48 +02:00
|
|
|
StorageImpl* This,
|
|
|
|
ULONG blockIndex,
|
|
|
|
const void* buffer)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2007-03-16 19:34:28 +01:00
|
|
|
ULARGE_INTEGER ulOffset;
|
|
|
|
DWORD wrote;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2007-03-16 19:34:28 +01:00
|
|
|
ulOffset.u.HighPart = 0;
|
|
|
|
ulOffset.u.LowPart = BLOCK_GetBigBlockOffset(blockIndex);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2007-03-16 19:34:28 +01:00
|
|
|
StorageImpl_WriteAt(This, ulOffset, buffer, This->bigBlockSize, &wrote);
|
|
|
|
return (wrote == This->bigBlockSize);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
2007-03-16 19:34:28 +01:00
|
|
|
static BOOL StorageImpl_WriteDWordToBigBlock(
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl* This,
|
2007-03-16 19:34:28 +01:00
|
|
|
ULONG blockIndex,
|
|
|
|
ULONG offset,
|
|
|
|
DWORD value)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2007-03-16 19:34:28 +01:00
|
|
|
ULARGE_INTEGER ulOffset;
|
|
|
|
DWORD wrote;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2007-03-16 19:34:28 +01:00
|
|
|
ulOffset.u.HighPart = 0;
|
|
|
|
ulOffset.u.LowPart = BLOCK_GetBigBlockOffset(blockIndex);
|
|
|
|
ulOffset.u.LowPart += offset;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2007-03-16 19:34:28 +01:00
|
|
|
value = htole32(value);
|
|
|
|
StorageImpl_WriteAt(This, ulOffset, &value, sizeof(DWORD), &wrote);
|
|
|
|
return (wrote == sizeof(DWORD));
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
1999-02-13 13:10:15 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* Storage32Impl_SmallBlocksToBigBlocks
|
|
|
|
*
|
|
|
|
* This method will convert a small block chain to a big block chain.
|
|
|
|
* The small block chain will be destroyed.
|
|
|
|
*/
|
|
|
|
BlockChainStream* Storage32Impl_SmallBlocksToBigBlocks(
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl* This,
|
1999-02-13 13:10:15 +01:00
|
|
|
SmallBlockChainStream** ppsbChain)
|
|
|
|
{
|
|
|
|
ULONG bbHeadOfChain = BLOCK_END_OF_CHAIN;
|
|
|
|
ULARGE_INTEGER size, offset;
|
2006-11-26 14:47:54 +01:00
|
|
|
ULONG cbRead, cbWritten;
|
|
|
|
ULARGE_INTEGER cbTotalRead;
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef streamEntryRef;
|
2006-09-11 12:14:25 +02:00
|
|
|
HRESULT resWrite = S_OK;
|
2006-09-11 12:13:47 +02:00
|
|
|
HRESULT resRead;
|
2009-11-12 21:59:09 +01:00
|
|
|
DirEntry streamEntry;
|
1999-07-31 19:34:43 +02:00
|
|
|
BYTE *buffer;
|
1999-02-13 13:10:15 +01:00
|
|
|
BlockChainStream *bbTempChain = NULL;
|
|
|
|
BlockChainStream *bigBlockChain = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a temporary big block chain that doesn't have
|
2009-11-12 21:59:09 +01:00
|
|
|
* an associated directory entry. This temporary chain will be
|
1999-02-13 13:10:15 +01:00
|
|
|
* used to copy data from small blocks to big blocks.
|
|
|
|
*/
|
|
|
|
bbTempChain = BlockChainStream_Construct(This,
|
|
|
|
&bbHeadOfChain,
|
2009-11-10 21:55:25 +01:00
|
|
|
DIRENTRY_NULL);
|
2002-08-16 21:55:14 +02:00
|
|
|
if(!bbTempChain) return NULL;
|
1999-02-13 13:10:15 +01:00
|
|
|
/*
|
|
|
|
* Grow the big block chain.
|
|
|
|
*/
|
|
|
|
size = SmallBlockChainStream_GetSize(*ppsbChain);
|
|
|
|
BlockChainStream_SetSize(bbTempChain, size);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy the contents of the small block chain to the big block chain
|
|
|
|
* by small block size increments.
|
|
|
|
*/
|
2004-01-23 02:51:33 +01:00
|
|
|
offset.u.LowPart = 0;
|
|
|
|
offset.u.HighPart = 0;
|
2006-11-26 14:47:54 +01:00
|
|
|
cbTotalRead.QuadPart = 0;
|
1999-02-13 13:10:15 +01:00
|
|
|
|
2005-03-21 12:25:13 +01:00
|
|
|
buffer = HeapAlloc(GetProcessHeap(),0,DEF_SMALL_BLOCK_SIZE);
|
1999-02-13 13:10:15 +01:00
|
|
|
do
|
|
|
|
{
|
2006-09-11 12:13:47 +02:00
|
|
|
resRead = SmallBlockChainStream_ReadAt(*ppsbChain,
|
|
|
|
offset,
|
2009-08-21 21:33:40 +02:00
|
|
|
min(This->smallBlockSize, size.u.LowPart - offset.u.LowPart),
|
2006-09-11 12:13:47 +02:00
|
|
|
buffer,
|
|
|
|
&cbRead);
|
|
|
|
if (FAILED(resRead))
|
2006-01-06 12:16:04 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (cbRead > 0)
|
|
|
|
{
|
2006-11-26 14:47:54 +01:00
|
|
|
cbTotalRead.QuadPart += cbRead;
|
1999-02-24 11:36:34 +01:00
|
|
|
|
2006-09-11 12:13:47 +02:00
|
|
|
resWrite = BlockChainStream_WriteAt(bbTempChain,
|
1999-02-13 13:10:15 +01:00
|
|
|
offset,
|
1999-02-24 11:36:34 +01:00
|
|
|
cbRead,
|
1999-02-13 13:10:15 +01:00
|
|
|
buffer,
|
|
|
|
&cbWritten);
|
1999-02-24 11:36:34 +01:00
|
|
|
|
2006-09-11 12:13:47 +02:00
|
|
|
if (FAILED(resWrite))
|
2006-01-06 12:16:04 +01:00
|
|
|
break;
|
1999-02-13 13:10:15 +01:00
|
|
|
|
2009-08-21 21:33:40 +02:00
|
|
|
offset.u.LowPart += cbRead;
|
2006-01-06 12:16:04 +01:00
|
|
|
}
|
2006-11-26 14:47:54 +01:00
|
|
|
} while (cbTotalRead.QuadPart < size.QuadPart);
|
2000-02-25 21:58:25 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,buffer);
|
1999-02-13 13:10:15 +01:00
|
|
|
|
2009-08-19 22:19:03 +02:00
|
|
|
size.u.HighPart = 0;
|
|
|
|
size.u.LowPart = 0;
|
|
|
|
|
2006-09-11 12:14:25 +02:00
|
|
|
if (FAILED(resRead) || FAILED(resWrite))
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
ERR("conversion failed: resRead = 0x%08x, resWrite = 0x%08x\n", resRead, resWrite);
|
2009-08-19 22:19:03 +02:00
|
|
|
BlockChainStream_SetSize(bbTempChain, size);
|
2006-09-11 12:14:25 +02:00
|
|
|
BlockChainStream_Destroy(bbTempChain);
|
|
|
|
return NULL;
|
|
|
|
}
|
1999-02-13 13:10:15 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Destroy the small block chain.
|
|
|
|
*/
|
2009-11-12 21:59:09 +01:00
|
|
|
streamEntryRef = (*ppsbChain)->ownerDirEntry;
|
1999-02-13 13:10:15 +01:00
|
|
|
SmallBlockChainStream_SetSize(*ppsbChain, size);
|
|
|
|
SmallBlockChainStream_Destroy(*ppsbChain);
|
|
|
|
*ppsbChain = 0;
|
|
|
|
|
|
|
|
/*
|
2009-11-12 21:59:09 +01:00
|
|
|
* Change the directory entry. This chain is now a big block chain
|
1999-02-13 13:10:15 +01:00
|
|
|
* and it doesn't reside in the small blocks chain anymore.
|
|
|
|
*/
|
2009-11-12 21:59:09 +01:00
|
|
|
StorageImpl_ReadDirEntry(This, streamEntryRef, &streamEntry);
|
1999-02-13 13:10:15 +01:00
|
|
|
|
2009-11-12 21:59:09 +01:00
|
|
|
streamEntry.startingBlock = bbHeadOfChain;
|
1999-02-13 13:10:15 +01:00
|
|
|
|
2009-11-12 21:59:09 +01:00
|
|
|
StorageImpl_WriteDirEntry(This, streamEntryRef, &streamEntry);
|
1999-02-13 13:10:15 +01:00
|
|
|
|
|
|
|
/*
|
2009-11-12 21:59:09 +01:00
|
|
|
* Destroy the temporary entryless big block chain.
|
|
|
|
* Create a new big block chain associated with this entry.
|
1999-02-13 13:10:15 +01:00
|
|
|
*/
|
|
|
|
BlockChainStream_Destroy(bbTempChain);
|
|
|
|
bigBlockChain = BlockChainStream_Construct(This,
|
|
|
|
NULL,
|
2009-11-12 21:59:09 +01:00
|
|
|
streamEntryRef);
|
1999-02-13 13:10:15 +01:00
|
|
|
|
|
|
|
return bigBlockChain;
|
|
|
|
}
|
|
|
|
|
2009-08-19 22:19:10 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Storage32Impl_BigBlocksToSmallBlocks
|
|
|
|
*
|
|
|
|
* This method will convert a big block chain to a small block chain.
|
|
|
|
* The big block chain will be destroyed on success.
|
|
|
|
*/
|
|
|
|
SmallBlockChainStream* Storage32Impl_BigBlocksToSmallBlocks(
|
|
|
|
StorageImpl* This,
|
|
|
|
BlockChainStream** ppbbChain)
|
|
|
|
{
|
|
|
|
ULARGE_INTEGER size, offset, cbTotalRead;
|
2009-11-12 22:53:42 +01:00
|
|
|
ULONG cbRead, cbWritten, sbHeadOfChain = BLOCK_END_OF_CHAIN;
|
|
|
|
DirRef streamEntryRef;
|
2009-08-19 22:19:10 +02:00
|
|
|
HRESULT resWrite = S_OK, resRead;
|
2009-11-12 21:59:09 +01:00
|
|
|
DirEntry streamEntry;
|
2009-08-19 22:19:10 +02:00
|
|
|
BYTE* buffer;
|
|
|
|
SmallBlockChainStream* sbTempChain;
|
|
|
|
|
|
|
|
TRACE("%p %p\n", This, ppbbChain);
|
|
|
|
|
|
|
|
sbTempChain = SmallBlockChainStream_Construct(This, &sbHeadOfChain,
|
2009-11-10 21:55:25 +01:00
|
|
|
DIRENTRY_NULL);
|
2009-08-19 22:19:10 +02:00
|
|
|
|
|
|
|
if(!sbTempChain)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
size = BlockChainStream_GetSize(*ppbbChain);
|
|
|
|
SmallBlockChainStream_SetSize(sbTempChain, size);
|
|
|
|
|
|
|
|
offset.u.HighPart = 0;
|
|
|
|
offset.u.LowPart = 0;
|
|
|
|
cbTotalRead.QuadPart = 0;
|
|
|
|
buffer = HeapAlloc(GetProcessHeap(), 0, This->bigBlockSize);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
resRead = BlockChainStream_ReadAt(*ppbbChain, offset,
|
2009-08-21 21:33:40 +02:00
|
|
|
min(This->bigBlockSize, size.u.LowPart - offset.u.LowPart),
|
|
|
|
buffer, &cbRead);
|
2009-08-19 22:19:10 +02:00
|
|
|
|
|
|
|
if(FAILED(resRead))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if(cbRead > 0)
|
|
|
|
{
|
|
|
|
cbTotalRead.QuadPart += cbRead;
|
|
|
|
|
|
|
|
resWrite = SmallBlockChainStream_WriteAt(sbTempChain, offset,
|
|
|
|
cbRead, buffer, &cbWritten);
|
|
|
|
|
|
|
|
if(FAILED(resWrite))
|
|
|
|
break;
|
|
|
|
|
2009-08-21 21:33:40 +02:00
|
|
|
offset.u.LowPart += cbRead;
|
2009-08-19 22:19:10 +02:00
|
|
|
}
|
|
|
|
}while(cbTotalRead.QuadPart < size.QuadPart);
|
|
|
|
HeapFree(GetProcessHeap(), 0, buffer);
|
|
|
|
|
|
|
|
size.u.HighPart = 0;
|
|
|
|
size.u.LowPart = 0;
|
|
|
|
|
|
|
|
if(FAILED(resRead) || FAILED(resWrite))
|
|
|
|
{
|
|
|
|
ERR("conversion failed: resRead = 0x%08x, resWrite = 0x%08x\n", resRead, resWrite);
|
|
|
|
SmallBlockChainStream_SetSize(sbTempChain, size);
|
|
|
|
SmallBlockChainStream_Destroy(sbTempChain);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* destroy the original big block chain */
|
2009-11-12 21:59:09 +01:00
|
|
|
streamEntryRef = (*ppbbChain)->ownerDirEntry;
|
2009-08-19 22:19:10 +02:00
|
|
|
BlockChainStream_SetSize(*ppbbChain, size);
|
|
|
|
BlockChainStream_Destroy(*ppbbChain);
|
|
|
|
*ppbbChain = NULL;
|
|
|
|
|
2009-11-12 21:59:09 +01:00
|
|
|
StorageImpl_ReadDirEntry(This, streamEntryRef, &streamEntry);
|
|
|
|
streamEntry.startingBlock = sbHeadOfChain;
|
|
|
|
StorageImpl_WriteDirEntry(This, streamEntryRef, &streamEntry);
|
2009-08-19 22:19:10 +02:00
|
|
|
|
|
|
|
SmallBlockChainStream_Destroy(sbTempChain);
|
2009-11-12 21:59:09 +01:00
|
|
|
return SmallBlockChainStream_Construct(This, NULL, streamEntryRef);
|
2009-08-19 22:19:10 +02:00
|
|
|
}
|
|
|
|
|
2009-11-19 20:42:47 +01:00
|
|
|
static void StorageInternalImpl_Invalidate( StorageInternalImpl *This )
|
|
|
|
{
|
|
|
|
if (This->base.ancestorStorage)
|
|
|
|
{
|
|
|
|
TRACE("Storage invalidated (stg=%p)\n", This);
|
|
|
|
|
|
|
|
This->base.ancestorStorage = NULL;
|
|
|
|
|
|
|
|
StorageBaseImpl_DeleteAll(&This->base);
|
|
|
|
|
|
|
|
list_remove(&This->ParentListEntry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-02 13:31:26 +02:00
|
|
|
static void StorageInternalImpl_Destroy( StorageBaseImpl *iface)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2005-02-24 20:39:27 +01:00
|
|
|
StorageInternalImpl* This = (StorageInternalImpl*) iface;
|
|
|
|
|
2009-11-19 20:42:47 +01:00
|
|
|
StorageInternalImpl_Invalidate(This);
|
2009-11-18 17:16:13 +01:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
**
|
|
|
|
** Storage32InternalImpl_Commit
|
|
|
|
**
|
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI StorageInternalImpl_Commit(
|
1999-02-26 12:11:13 +01:00
|
|
|
IStorage* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
DWORD grfCommitFlags) /* [in] */
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-10-02 22:27:24 +02:00
|
|
|
FIXME("(%p,%x): stub\n", iface, grfCommitFlags);
|
1999-01-30 14:24:23 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/******************************************************************************
|
|
|
|
**
|
|
|
|
** Storage32InternalImpl_Revert
|
|
|
|
**
|
|
|
|
*/
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI StorageInternalImpl_Revert(
|
1999-02-26 12:11:13 +01:00
|
|
|
IStorage* iface)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-10-02 22:27:24 +02:00
|
|
|
FIXME("(%p): stub\n", iface);
|
1999-01-30 14:24:23 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2006-08-02 13:31:26 +02:00
|
|
|
static void IEnumSTATSTGImpl_Destroy(IEnumSTATSTGImpl* This)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
1999-02-26 12:11:13 +01:00
|
|
|
IStorage_Release((IStorage*)This->parentStorage);
|
1999-01-30 14:24:23 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->stackToVisit);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI IEnumSTATSTGImpl_QueryInterface(
|
1999-02-18 14:26:22 +01:00
|
|
|
IEnumSTATSTG* iface,
|
1999-01-30 14:24:23 +01:00
|
|
|
REFIID riid,
|
|
|
|
void** ppvObject)
|
|
|
|
{
|
1999-02-18 14:26:22 +01:00
|
|
|
IEnumSTATSTGImpl* const This=(IEnumSTATSTGImpl*)iface;
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
if (ppvObject==0)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*ppvObject = 0;
|
|
|
|
|
2005-03-31 17:26:30 +02:00
|
|
|
if (IsEqualGUID(&IID_IUnknown, riid) ||
|
2006-08-09 19:16:10 +02:00
|
|
|
IsEqualGUID(&IID_IEnumSTATSTG, riid))
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-02-11 10:48:38 +01:00
|
|
|
*ppvObject = This;
|
2005-03-31 17:26:30 +02:00
|
|
|
IEnumSTATSTG_AddRef((IEnumSTATSTG*)This);
|
|
|
|
return S_OK;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
2005-03-31 17:26:30 +02:00
|
|
|
return E_NOINTERFACE;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-06-10 11:59:15 +02:00
|
|
|
static ULONG WINAPI IEnumSTATSTGImpl_AddRef(
|
1999-02-18 14:26:22 +01:00
|
|
|
IEnumSTATSTG* iface)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
1999-02-18 14:26:22 +01:00
|
|
|
IEnumSTATSTGImpl* const This=(IEnumSTATSTGImpl*)iface;
|
2004-09-24 03:16:53 +02:00
|
|
|
return InterlockedIncrement(&This->ref);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-06-10 11:59:15 +02:00
|
|
|
static ULONG WINAPI IEnumSTATSTGImpl_Release(
|
1999-02-18 14:26:22 +01:00
|
|
|
IEnumSTATSTG* iface)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
1999-02-18 14:26:22 +01:00
|
|
|
IEnumSTATSTGImpl* const This=(IEnumSTATSTGImpl*)iface;
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
ULONG newRef;
|
|
|
|
|
2004-09-24 03:16:53 +02:00
|
|
|
newRef = InterlockedDecrement(&This->ref);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
if (newRef==0)
|
|
|
|
{
|
|
|
|
IEnumSTATSTGImpl_Destroy(This);
|
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
return newRef;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI IEnumSTATSTGImpl_Next(
|
1999-02-18 14:26:22 +01:00
|
|
|
IEnumSTATSTG* iface,
|
1999-01-30 14:24:23 +01:00
|
|
|
ULONG celt,
|
|
|
|
STATSTG* rgelt,
|
|
|
|
ULONG* pceltFetched)
|
|
|
|
{
|
1999-02-18 14:26:22 +01:00
|
|
|
IEnumSTATSTGImpl* const This=(IEnumSTATSTGImpl*)iface;
|
|
|
|
|
2009-11-12 22:01:51 +01:00
|
|
|
DirEntry currentEntry;
|
1999-01-30 14:24:23 +01:00
|
|
|
STATSTG* currentReturnStruct = rgelt;
|
|
|
|
ULONG objectFetched = 0;
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef currentSearchNode;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
if ( (rgelt==0) || ( (celt!=1) && (pceltFetched==0) ) )
|
2002-06-01 01:06:46 +02:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* To avoid the special case, get another pointer to a ULONG value if
|
|
|
|
* the caller didn't supply one.
|
|
|
|
*/
|
|
|
|
if (pceltFetched==0)
|
|
|
|
pceltFetched = &objectFetched;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Start the iteration, we will iterate until we hit the end of the
|
|
|
|
* linked list or until we hit the number of items to iterate through
|
|
|
|
*/
|
|
|
|
*pceltFetched = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start with the node at the top of the stack.
|
|
|
|
*/
|
|
|
|
currentSearchNode = IEnumSTATSTGImpl_PopSearchNode(This, FALSE);
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
while ( ( *pceltFetched < celt) &&
|
2009-11-10 21:55:25 +01:00
|
|
|
( currentSearchNode!=DIRENTRY_NULL) )
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
1999-01-30 14:24:23 +01:00
|
|
|
* Remove the top node from the stack
|
|
|
|
*/
|
|
|
|
IEnumSTATSTGImpl_PopSearchNode(This, TRUE);
|
|
|
|
|
|
|
|
/*
|
2009-11-12 22:01:51 +01:00
|
|
|
* Read the entry from the storage.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-11-10 21:39:10 +01:00
|
|
|
StorageImpl_ReadDirEntry(This->parentStorage,
|
2002-06-01 01:06:46 +02:00
|
|
|
currentSearchNode,
|
2009-11-12 22:01:51 +01:00
|
|
|
¤tEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy the information to the return buffer.
|
|
|
|
*/
|
2009-11-10 21:49:47 +01:00
|
|
|
StorageUtl_CopyDirEntryToSTATSTG(currentReturnStruct,
|
2009-11-12 22:01:51 +01:00
|
|
|
¤tEntry,
|
1999-01-30 14:24:23 +01:00
|
|
|
STATFLAG_DEFAULT);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Step to the next item in the iteration
|
|
|
|
*/
|
|
|
|
(*pceltFetched)++;
|
|
|
|
currentReturnStruct++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Push the next search node in the search stack.
|
|
|
|
*/
|
2009-11-12 22:01:51 +01:00
|
|
|
IEnumSTATSTGImpl_PushSearchNode(This, currentEntry.rightChild);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* continue the iteration.
|
|
|
|
*/
|
|
|
|
currentSearchNode = IEnumSTATSTGImpl_PopSearchNode(This, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*pceltFetched == celt)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI IEnumSTATSTGImpl_Skip(
|
1999-02-18 14:26:22 +01:00
|
|
|
IEnumSTATSTG* iface,
|
1999-01-30 14:24:23 +01:00
|
|
|
ULONG celt)
|
|
|
|
{
|
1999-02-18 14:26:22 +01:00
|
|
|
IEnumSTATSTGImpl* const This=(IEnumSTATSTGImpl*)iface;
|
|
|
|
|
2009-11-12 22:01:51 +01:00
|
|
|
DirEntry currentEntry;
|
1999-01-30 14:24:23 +01:00
|
|
|
ULONG objectFetched = 0;
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef currentSearchNode;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Start with the node at the top of the stack.
|
|
|
|
*/
|
|
|
|
currentSearchNode = IEnumSTATSTGImpl_PopSearchNode(This, FALSE);
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
while ( (objectFetched < celt) &&
|
2009-11-10 21:55:25 +01:00
|
|
|
(currentSearchNode!=DIRENTRY_NULL) )
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
1999-01-30 14:24:23 +01:00
|
|
|
* Remove the top node from the stack
|
|
|
|
*/
|
|
|
|
IEnumSTATSTGImpl_PopSearchNode(This, TRUE);
|
|
|
|
|
|
|
|
/*
|
2009-11-12 22:01:51 +01:00
|
|
|
* Read the entry from the storage.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-11-10 21:39:10 +01:00
|
|
|
StorageImpl_ReadDirEntry(This->parentStorage,
|
2002-06-01 01:06:46 +02:00
|
|
|
currentSearchNode,
|
2009-11-12 22:01:51 +01:00
|
|
|
¤tEntry);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Step to the next item in the iteration
|
|
|
|
*/
|
|
|
|
objectFetched++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Push the next search node in the search stack.
|
|
|
|
*/
|
2009-11-12 22:01:51 +01:00
|
|
|
IEnumSTATSTGImpl_PushSearchNode(This, currentEntry.rightChild);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* continue the iteration.
|
|
|
|
*/
|
|
|
|
currentSearchNode = IEnumSTATSTGImpl_PopSearchNode(This, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (objectFetched == celt)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI IEnumSTATSTGImpl_Reset(
|
1999-02-18 14:26:22 +01:00
|
|
|
IEnumSTATSTG* iface)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
1999-02-18 14:26:22 +01:00
|
|
|
IEnumSTATSTGImpl* const This=(IEnumSTATSTGImpl*)iface;
|
|
|
|
|
2009-11-12 22:01:51 +01:00
|
|
|
DirEntry storageEntry;
|
2000-01-29 22:12:58 +01:00
|
|
|
BOOL readSuccessful;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Re-initialize the search stack to an empty stack
|
|
|
|
*/
|
|
|
|
This->stackSize = 0;
|
|
|
|
|
|
|
|
/*
|
2009-11-12 22:01:51 +01:00
|
|
|
* Read the storage entry from the top-level storage.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-11-10 21:39:10 +01:00
|
|
|
readSuccessful = StorageImpl_ReadDirEntry(
|
1999-01-30 14:24:23 +01:00
|
|
|
This->parentStorage,
|
2009-11-12 21:02:20 +01:00
|
|
|
This->storageDirEntry,
|
2009-11-12 22:01:51 +01:00
|
|
|
&storageEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-01-29 22:12:58 +01:00
|
|
|
if (readSuccessful)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-12 22:01:51 +01:00
|
|
|
assert(storageEntry.sizeOfNameString!=0);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Push the search node in the search stack.
|
|
|
|
*/
|
2009-11-12 22:01:51 +01:00
|
|
|
IEnumSTATSTGImpl_PushSearchNode(This, storageEntry.dirRootEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-06-10 11:59:15 +02:00
|
|
|
static HRESULT WINAPI IEnumSTATSTGImpl_Clone(
|
1999-02-18 14:26:22 +01:00
|
|
|
IEnumSTATSTG* iface,
|
1999-01-30 14:24:23 +01:00
|
|
|
IEnumSTATSTG** ppenum)
|
|
|
|
{
|
1999-02-18 14:26:22 +01:00
|
|
|
IEnumSTATSTGImpl* const This=(IEnumSTATSTGImpl*)iface;
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
IEnumSTATSTGImpl* newClone;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform a sanity check on the parameters.
|
|
|
|
*/
|
|
|
|
if (ppenum==0)
|
|
|
|
return E_INVALIDARG;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
newClone = IEnumSTATSTGImpl_Construct(This->parentStorage,
|
2009-11-12 21:02:20 +01:00
|
|
|
This->storageDirEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* The new clone enumeration must point to the same current node as
|
|
|
|
* the ole one.
|
|
|
|
*/
|
|
|
|
newClone->stackSize = This->stackSize ;
|
|
|
|
newClone->stackMaxSize = This->stackMaxSize ;
|
2002-06-01 01:06:46 +02:00
|
|
|
newClone->stackToVisit =
|
1999-01-30 14:24:23 +01:00
|
|
|
HeapAlloc(GetProcessHeap(), 0, sizeof(ULONG) * newClone->stackMaxSize);
|
|
|
|
|
|
|
|
memcpy(
|
2002-06-01 01:06:46 +02:00
|
|
|
newClone->stackToVisit,
|
|
|
|
This->stackToVisit,
|
2009-11-12 22:53:42 +01:00
|
|
|
sizeof(DirRef) * newClone->stackSize);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
1999-02-18 14:26:22 +01:00
|
|
|
*ppenum = (IEnumSTATSTG*)newClone;
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Don't forget to nail down a reference to the clone before
|
|
|
|
* returning it.
|
|
|
|
*/
|
1999-02-18 14:26:22 +01:00
|
|
|
IEnumSTATSTGImpl_AddRef(*ppenum);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2006-08-02 13:31:26 +02:00
|
|
|
static void IEnumSTATSTGImpl_PushSearchNode(
|
1999-01-30 14:24:23 +01:00
|
|
|
IEnumSTATSTGImpl* This,
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef nodeToPush)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-12 22:01:51 +01:00
|
|
|
DirEntry storageEntry;
|
2000-01-29 22:12:58 +01:00
|
|
|
BOOL readSuccessful;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* First, make sure we're not trying to push an unexisting node.
|
|
|
|
*/
|
2009-11-10 21:55:25 +01:00
|
|
|
if (nodeToPush==DIRENTRY_NULL)
|
1999-01-30 14:24:23 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First push the node to the stack
|
|
|
|
*/
|
|
|
|
if (This->stackSize == This->stackMaxSize)
|
|
|
|
{
|
|
|
|
This->stackMaxSize += ENUMSTATSGT_SIZE_INCREMENT;
|
|
|
|
|
|
|
|
This->stackToVisit = HeapReAlloc(
|
2002-06-01 01:06:46 +02:00
|
|
|
GetProcessHeap(),
|
1999-01-30 14:24:23 +01:00
|
|
|
0,
|
|
|
|
This->stackToVisit,
|
2009-11-12 22:53:42 +01:00
|
|
|
sizeof(DirRef) * This->stackMaxSize);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
This->stackToVisit[This->stackSize] = nodeToPush;
|
|
|
|
This->stackSize++;
|
|
|
|
|
|
|
|
/*
|
2009-11-12 22:01:51 +01:00
|
|
|
* Read the storage entry from the top-level storage.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-11-10 21:39:10 +01:00
|
|
|
readSuccessful = StorageImpl_ReadDirEntry(
|
1999-01-30 14:24:23 +01:00
|
|
|
This->parentStorage,
|
2002-06-01 01:06:46 +02:00
|
|
|
nodeToPush,
|
2009-11-12 22:01:51 +01:00
|
|
|
&storageEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-01-29 22:12:58 +01:00
|
|
|
if (readSuccessful)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-12 22:01:51 +01:00
|
|
|
assert(storageEntry.sizeOfNameString!=0);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Push the previous search node in the search stack.
|
|
|
|
*/
|
2009-11-12 22:01:51 +01:00
|
|
|
IEnumSTATSTGImpl_PushSearchNode(This, storageEntry.leftChild);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-12 22:53:42 +01:00
|
|
|
static DirRef IEnumSTATSTGImpl_PopSearchNode(
|
1999-01-30 14:24:23 +01:00
|
|
|
IEnumSTATSTGImpl* This,
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL remove)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef topNode;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
if (This->stackSize == 0)
|
2009-11-10 21:55:25 +01:00
|
|
|
return DIRENTRY_NULL;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
topNode = This->stackToVisit[This->stackSize-1];
|
|
|
|
|
|
|
|
if (remove)
|
|
|
|
This->stackSize--;
|
|
|
|
|
|
|
|
return topNode;
|
|
|
|
}
|
|
|
|
|
2005-03-31 17:26:30 +02:00
|
|
|
/*
|
|
|
|
* Virtual function table for the IEnumSTATSTGImpl class.
|
|
|
|
*/
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IEnumSTATSTGVtbl IEnumSTATSTGImpl_Vtbl =
|
2005-03-31 17:26:30 +02:00
|
|
|
{
|
|
|
|
IEnumSTATSTGImpl_QueryInterface,
|
|
|
|
IEnumSTATSTGImpl_AddRef,
|
|
|
|
IEnumSTATSTGImpl_Release,
|
|
|
|
IEnumSTATSTGImpl_Next,
|
|
|
|
IEnumSTATSTGImpl_Skip,
|
|
|
|
IEnumSTATSTGImpl_Reset,
|
|
|
|
IEnumSTATSTGImpl_Clone
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
** IEnumSTATSTGImpl implementation
|
|
|
|
*/
|
|
|
|
|
2006-08-02 13:31:26 +02:00
|
|
|
static IEnumSTATSTGImpl* IEnumSTATSTGImpl_Construct(
|
2005-03-31 17:26:30 +02:00
|
|
|
StorageImpl* parentStorage,
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef storageDirEntry)
|
2005-03-31 17:26:30 +02:00
|
|
|
{
|
|
|
|
IEnumSTATSTGImpl* newEnumeration;
|
|
|
|
|
|
|
|
newEnumeration = HeapAlloc(GetProcessHeap(), 0, sizeof(IEnumSTATSTGImpl));
|
|
|
|
|
|
|
|
if (newEnumeration!=0)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Set-up the virtual function table and reference count.
|
|
|
|
*/
|
|
|
|
newEnumeration->lpVtbl = &IEnumSTATSTGImpl_Vtbl;
|
|
|
|
newEnumeration->ref = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We want to nail-down the reference to the storage in case the
|
|
|
|
* enumeration out-lives the storage in the client application.
|
|
|
|
*/
|
|
|
|
newEnumeration->parentStorage = parentStorage;
|
|
|
|
IStorage_AddRef((IStorage*)newEnumeration->parentStorage);
|
|
|
|
|
2009-11-12 21:02:20 +01:00
|
|
|
newEnumeration->storageDirEntry = storageDirEntry;
|
2005-03-31 17:26:30 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the search stack
|
|
|
|
*/
|
|
|
|
newEnumeration->stackSize = 0;
|
|
|
|
newEnumeration->stackMaxSize = ENUMSTATSGT_SIZE_INCREMENT;
|
|
|
|
newEnumeration->stackToVisit =
|
2009-11-12 22:53:42 +01:00
|
|
|
HeapAlloc(GetProcessHeap(), 0, sizeof(DirRef)*ENUMSTATSGT_SIZE_INCREMENT);
|
2005-03-31 17:26:30 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure the current node of the iterator is the first one.
|
|
|
|
*/
|
|
|
|
IEnumSTATSTGImpl_Reset((IEnumSTATSTG*)newEnumeration);
|
|
|
|
}
|
|
|
|
|
|
|
|
return newEnumeration;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Virtual function table for the Storage32InternalImpl class.
|
|
|
|
*/
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IStorageVtbl Storage32InternalImpl_Vtbl =
|
2005-03-31 17:26:30 +02:00
|
|
|
{
|
|
|
|
StorageBaseImpl_QueryInterface,
|
|
|
|
StorageBaseImpl_AddRef,
|
|
|
|
StorageBaseImpl_Release,
|
|
|
|
StorageBaseImpl_CreateStream,
|
|
|
|
StorageBaseImpl_OpenStream,
|
2009-10-28 20:35:24 +01:00
|
|
|
StorageBaseImpl_CreateStorage,
|
2005-03-31 17:26:30 +02:00
|
|
|
StorageBaseImpl_OpenStorage,
|
2009-10-28 20:48:39 +01:00
|
|
|
StorageBaseImpl_CopyTo,
|
2009-10-28 20:49:30 +01:00
|
|
|
StorageBaseImpl_MoveElementTo,
|
2005-03-31 17:26:30 +02:00
|
|
|
StorageInternalImpl_Commit,
|
|
|
|
StorageInternalImpl_Revert,
|
|
|
|
StorageBaseImpl_EnumElements,
|
2009-10-28 20:53:30 +01:00
|
|
|
StorageBaseImpl_DestroyElement,
|
2005-03-31 17:26:30 +02:00
|
|
|
StorageBaseImpl_RenameElement,
|
2009-10-28 20:54:36 +01:00
|
|
|
StorageBaseImpl_SetElementTimes,
|
2005-03-31 17:26:30 +02:00
|
|
|
StorageBaseImpl_SetClass,
|
2009-10-28 20:56:19 +01:00
|
|
|
StorageBaseImpl_SetStateBits,
|
2005-03-31 17:26:30 +02:00
|
|
|
StorageBaseImpl_Stat
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
** Storage32InternalImpl implementation
|
|
|
|
*/
|
|
|
|
|
2006-08-02 13:31:26 +02:00
|
|
|
static StorageInternalImpl* StorageInternalImpl_Construct(
|
2005-03-31 17:26:30 +02:00
|
|
|
StorageImpl* ancestorStorage,
|
2005-05-13 15:58:43 +02:00
|
|
|
DWORD openFlags,
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef storageDirEntry)
|
2005-03-31 17:26:30 +02:00
|
|
|
{
|
|
|
|
StorageInternalImpl* newStorage;
|
|
|
|
|
2007-04-25 00:57:55 +02:00
|
|
|
newStorage = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(StorageInternalImpl));
|
2005-03-31 17:26:30 +02:00
|
|
|
|
|
|
|
if (newStorage!=0)
|
|
|
|
{
|
2006-02-21 09:03:36 +01:00
|
|
|
list_init(&newStorage->base.strmHead);
|
2009-11-19 20:42:47 +01:00
|
|
|
|
|
|
|
list_init(&newStorage->base.storageHead);
|
2006-02-21 09:03:36 +01:00
|
|
|
|
2005-03-31 17:26:30 +02:00
|
|
|
/*
|
|
|
|
* Initialize the virtual function table.
|
|
|
|
*/
|
|
|
|
newStorage->base.lpVtbl = &Storage32InternalImpl_Vtbl;
|
2008-07-06 14:00:24 +02:00
|
|
|
newStorage->base.v_destructor = StorageInternalImpl_Destroy;
|
2006-05-03 15:49:51 +02:00
|
|
|
newStorage->base.openFlags = (openFlags & ~STGM_CREATE);
|
2005-03-31 17:26:30 +02:00
|
|
|
|
|
|
|
/*
|
2009-09-25 16:27:49 +02:00
|
|
|
* Keep the ancestor storage pointer but do not nail a reference to it.
|
2005-03-31 17:26:30 +02:00
|
|
|
*/
|
|
|
|
newStorage->base.ancestorStorage = ancestorStorage;
|
|
|
|
|
|
|
|
/*
|
2009-11-12 22:03:09 +01:00
|
|
|
* Keep a reference to the directory entry of this storage
|
2005-03-31 17:26:30 +02:00
|
|
|
*/
|
2009-11-12 22:03:09 +01:00
|
|
|
newStorage->base.storageDirEntry = storageDirEntry;
|
2005-03-31 17:26:30 +02:00
|
|
|
|
|
|
|
return newStorage;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/******************************************************************************
|
|
|
|
** StorageUtl implementation
|
|
|
|
*/
|
|
|
|
|
2005-03-17 11:25:13 +01:00
|
|
|
void StorageUtl_ReadWord(const BYTE* buffer, ULONG offset, WORD* value)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2005-04-24 19:22:26 +02:00
|
|
|
WORD tmp;
|
|
|
|
|
|
|
|
memcpy(&tmp, buffer+offset, sizeof(WORD));
|
2009-04-23 18:17:49 +02:00
|
|
|
*value = lendian16toh(tmp);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
2005-03-17 11:25:13 +01:00
|
|
|
void StorageUtl_WriteWord(BYTE* buffer, ULONG offset, WORD value)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2005-04-24 19:22:26 +02:00
|
|
|
value = htole16(value);
|
2005-03-17 11:25:13 +01:00
|
|
|
memcpy(buffer+offset, &value, sizeof(WORD));
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
2005-03-17 11:25:13 +01:00
|
|
|
void StorageUtl_ReadDWord(const BYTE* buffer, ULONG offset, DWORD* value)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2005-04-24 19:22:26 +02:00
|
|
|
DWORD tmp;
|
|
|
|
|
|
|
|
memcpy(&tmp, buffer+offset, sizeof(DWORD));
|
2009-04-23 18:17:49 +02:00
|
|
|
*value = lendian32toh(tmp);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
2005-03-17 11:25:13 +01:00
|
|
|
void StorageUtl_WriteDWord(BYTE* buffer, ULONG offset, DWORD value)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2005-04-24 19:22:26 +02:00
|
|
|
value = htole32(value);
|
2005-03-17 11:25:13 +01:00
|
|
|
memcpy(buffer+offset, &value, sizeof(DWORD));
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
2005-05-14 13:06:44 +02:00
|
|
|
void StorageUtl_ReadULargeInteger(const BYTE* buffer, ULONG offset,
|
|
|
|
ULARGE_INTEGER* value)
|
|
|
|
{
|
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
ULARGE_INTEGER tmp;
|
|
|
|
|
|
|
|
memcpy(&tmp, buffer + offset, sizeof(ULARGE_INTEGER));
|
2005-05-18 11:44:13 +02:00
|
|
|
value->u.LowPart = htole32(tmp.u.HighPart);
|
|
|
|
value->u.HighPart = htole32(tmp.u.LowPart);
|
2005-05-14 13:06:44 +02:00
|
|
|
#else
|
|
|
|
memcpy(value, buffer + offset, sizeof(ULARGE_INTEGER));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void StorageUtl_WriteULargeInteger(BYTE* buffer, ULONG offset,
|
|
|
|
const ULARGE_INTEGER *value)
|
|
|
|
{
|
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
ULARGE_INTEGER tmp;
|
|
|
|
|
2005-05-18 11:44:13 +02:00
|
|
|
tmp.u.LowPart = htole32(value->u.HighPart);
|
|
|
|
tmp.u.HighPart = htole32(value->u.LowPart);
|
2005-05-14 13:06:44 +02:00
|
|
|
memcpy(buffer + offset, &tmp, sizeof(ULARGE_INTEGER));
|
|
|
|
#else
|
|
|
|
memcpy(buffer + offset, value, sizeof(ULARGE_INTEGER));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-03-17 11:25:13 +01:00
|
|
|
void StorageUtl_ReadGUID(const BYTE* buffer, ULONG offset, GUID* value)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
StorageUtl_ReadDWord(buffer, offset, &(value->Data1));
|
|
|
|
StorageUtl_ReadWord(buffer, offset+4, &(value->Data2));
|
|
|
|
StorageUtl_ReadWord(buffer, offset+6, &(value->Data3));
|
|
|
|
|
2005-03-17 11:25:13 +01:00
|
|
|
memcpy(value->Data4, buffer+offset+8, sizeof(value->Data4));
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
2005-03-17 11:25:13 +01:00
|
|
|
void StorageUtl_WriteGUID(BYTE* buffer, ULONG offset, const GUID* value)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
StorageUtl_WriteDWord(buffer, offset, value->Data1);
|
|
|
|
StorageUtl_WriteWord(buffer, offset+4, value->Data2);
|
|
|
|
StorageUtl_WriteWord(buffer, offset+6, value->Data3);
|
|
|
|
|
2005-03-17 11:25:13 +01:00
|
|
|
memcpy(buffer+offset+8, value->Data4, sizeof(value->Data4));
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
2009-11-10 21:49:47 +01:00
|
|
|
void StorageUtl_CopyDirEntryToSTATSTG(
|
2007-07-04 21:12:48 +02:00
|
|
|
STATSTG* destination,
|
2009-11-10 21:30:59 +01:00
|
|
|
const DirEntry* source,
|
2007-07-04 21:12:48 +02:00
|
|
|
int statFlags)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The copy of the string occurs only when the flag is not set
|
|
|
|
*/
|
2004-08-11 01:41:58 +02:00
|
|
|
if( ((statFlags & STATFLAG_NONAME) != 0) ||
|
|
|
|
(source->name == NULL) ||
|
|
|
|
(source->name[0] == 0) )
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
destination->pwcsName = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
destination->pwcsName =
|
1999-02-26 12:11:13 +01:00
|
|
|
CoTaskMemAlloc((lstrlenW(source->name)+1)*sizeof(WCHAR));
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-02-11 10:48:38 +01:00
|
|
|
strcpyW(destination->pwcsName, source->name);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-11-12 19:34:05 +01:00
|
|
|
switch (source->stgType)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-10 21:21:31 +01:00
|
|
|
case STGTY_STORAGE:
|
|
|
|
case STGTY_ROOT:
|
1999-01-30 14:24:23 +01:00
|
|
|
destination->type = STGTY_STORAGE;
|
|
|
|
break;
|
2009-11-10 21:21:31 +01:00
|
|
|
case STGTY_STREAM:
|
1999-01-30 14:24:23 +01:00
|
|
|
destination->type = STGTY_STREAM;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
destination->type = STGTY_STREAM;
|
2002-06-01 01:06:46 +02:00
|
|
|
break;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
destination->cbSize = source->size;
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
1999-01-30 14:24:23 +01:00
|
|
|
currentReturnStruct->mtime = {0}; TODO
|
|
|
|
currentReturnStruct->ctime = {0};
|
2002-06-01 01:06:46 +02:00
|
|
|
currentReturnStruct->atime = {0};
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
|
|
|
destination->grfMode = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
destination->grfLocksSupported = 0;
|
2009-11-12 20:10:17 +01:00
|
|
|
destination->clsid = source->clsid;
|
2002-06-01 01:06:46 +02:00
|
|
|
destination->grfStateBits = 0;
|
|
|
|
destination->reserved = 0;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
** BlockChainStream implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
BlockChainStream* BlockChainStream_Construct(
|
2002-06-01 01:06:46 +02:00
|
|
|
StorageImpl* parentStorage,
|
1999-01-30 14:24:23 +01:00
|
|
|
ULONG* headOfStreamPlaceHolder,
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef dirEntry)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
BlockChainStream* newStream;
|
1999-03-12 18:06:46 +01:00
|
|
|
ULONG blockIndex;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
newStream = HeapAlloc(GetProcessHeap(), 0, sizeof(BlockChainStream));
|
|
|
|
|
|
|
|
newStream->parentStorage = parentStorage;
|
|
|
|
newStream->headOfStreamPlaceHolder = headOfStreamPlaceHolder;
|
2009-11-12 20:31:25 +01:00
|
|
|
newStream->ownerDirEntry = dirEntry;
|
1999-03-12 18:06:46 +01:00
|
|
|
newStream->lastBlockNoInSequence = 0xFFFFFFFF;
|
|
|
|
newStream->tailIndex = BLOCK_END_OF_CHAIN;
|
|
|
|
newStream->numBlocks = 0;
|
|
|
|
|
|
|
|
blockIndex = BlockChainStream_GetHeadOfChain(newStream);
|
|
|
|
|
|
|
|
while (blockIndex != BLOCK_END_OF_CHAIN)
|
|
|
|
{
|
|
|
|
newStream->numBlocks++;
|
|
|
|
newStream->tailIndex = blockIndex;
|
|
|
|
|
2002-08-16 21:55:14 +02:00
|
|
|
if(FAILED(StorageImpl_GetNextBlockInChain(
|
|
|
|
parentStorage,
|
|
|
|
blockIndex,
|
|
|
|
&blockIndex)))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, newStream);
|
|
|
|
return NULL;
|
|
|
|
}
|
1999-03-12 18:06:46 +01:00
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
return newStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlockChainStream_Destroy(BlockChainStream* This)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* BlockChainStream_GetHeadOfChain
|
|
|
|
*
|
|
|
|
* Returns the head of this stream chain.
|
2009-11-12 22:05:51 +01:00
|
|
|
* Some special chains don't have directory entries, their heads are kept in
|
1999-01-30 14:24:23 +01:00
|
|
|
* This->headOfStreamPlaceHolder.
|
|
|
|
*
|
|
|
|
*/
|
2006-08-02 13:31:26 +02:00
|
|
|
static ULONG BlockChainStream_GetHeadOfChain(BlockChainStream* This)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-12 22:05:51 +01:00
|
|
|
DirEntry chainEntry;
|
2000-01-29 22:12:58 +01:00
|
|
|
BOOL readSuccessful;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
if (This->headOfStreamPlaceHolder != 0)
|
|
|
|
return *(This->headOfStreamPlaceHolder);
|
|
|
|
|
2009-11-12 20:31:25 +01:00
|
|
|
if (This->ownerDirEntry != DIRENTRY_NULL)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-10 21:39:10 +01:00
|
|
|
readSuccessful = StorageImpl_ReadDirEntry(
|
1999-01-30 14:24:23 +01:00
|
|
|
This->parentStorage,
|
2009-11-12 20:31:25 +01:00
|
|
|
This->ownerDirEntry,
|
2009-11-12 22:05:51 +01:00
|
|
|
&chainEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-01-29 22:12:58 +01:00
|
|
|
if (readSuccessful)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-12 22:05:51 +01:00
|
|
|
return chainEntry.startingBlock;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return BLOCK_END_OF_CHAIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* BlockChainStream_GetCount
|
|
|
|
*
|
|
|
|
* Returns the number of blocks that comprises this chain.
|
|
|
|
* This is not the size of the stream as the last block may not be full!
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2006-08-02 13:31:26 +02:00
|
|
|
static ULONG BlockChainStream_GetCount(BlockChainStream* This)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
ULONG blockIndex;
|
|
|
|
ULONG count = 0;
|
|
|
|
|
|
|
|
blockIndex = BlockChainStream_GetHeadOfChain(This);
|
|
|
|
|
|
|
|
while (blockIndex != BLOCK_END_OF_CHAIN)
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
|
2002-08-16 21:55:14 +02:00
|
|
|
if(FAILED(StorageImpl_GetNextBlockInChain(
|
2002-06-01 01:06:46 +02:00
|
|
|
This->parentStorage,
|
2002-08-16 21:55:14 +02:00
|
|
|
blockIndex,
|
|
|
|
&blockIndex)))
|
|
|
|
return 0;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* BlockChainStream_ReadAt
|
1999-01-30 14:24:23 +01:00
|
|
|
*
|
|
|
|
* Reads a specified number of bytes from this chain at the specified offset.
|
|
|
|
* bytesRead may be NULL.
|
|
|
|
* Failure will be returned if the specified number of bytes has not been read.
|
|
|
|
*/
|
2006-09-11 12:13:47 +02:00
|
|
|
HRESULT BlockChainStream_ReadAt(BlockChainStream* This,
|
1999-01-30 14:24:23 +01:00
|
|
|
ULARGE_INTEGER offset,
|
|
|
|
ULONG size,
|
|
|
|
void* buffer,
|
|
|
|
ULONG* bytesRead)
|
|
|
|
{
|
2004-01-23 02:51:33 +01:00
|
|
|
ULONG blockNoInSequence = offset.u.LowPart / This->parentStorage->bigBlockSize;
|
|
|
|
ULONG offsetInBlock = offset.u.LowPart % This->parentStorage->bigBlockSize;
|
1999-01-30 14:24:23 +01:00
|
|
|
ULONG bytesToReadInBuffer;
|
|
|
|
ULONG blockIndex;
|
|
|
|
BYTE* bufferWalker;
|
2007-03-16 19:34:28 +01:00
|
|
|
|
|
|
|
TRACE("(%p)-> %i %p %i %p\n",This, offset.u.LowPart, buffer, size, bytesRead);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the first block in the stream that contains part of the buffer.
|
|
|
|
*/
|
1999-05-02 13:41:10 +02:00
|
|
|
if ( (This->lastBlockNoInSequence == 0xFFFFFFFF) ||
|
|
|
|
(This->lastBlockNoInSequenceIndex == BLOCK_END_OF_CHAIN) ||
|
|
|
|
(blockNoInSequence < This->lastBlockNoInSequence) )
|
|
|
|
{
|
|
|
|
blockIndex = BlockChainStream_GetHeadOfChain(This);
|
|
|
|
This->lastBlockNoInSequence = blockNoInSequence;
|
|
|
|
}
|
|
|
|
else
|
1999-03-12 18:06:46 +01:00
|
|
|
{
|
|
|
|
ULONG temp = blockNoInSequence;
|
|
|
|
|
|
|
|
blockIndex = This->lastBlockNoInSequenceIndex;
|
|
|
|
blockNoInSequence -= This->lastBlockNoInSequence;
|
|
|
|
This->lastBlockNoInSequence = temp;
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
while ( (blockNoInSequence > 0) && (blockIndex != BLOCK_END_OF_CHAIN))
|
|
|
|
{
|
2002-08-16 21:55:14 +02:00
|
|
|
if(FAILED(StorageImpl_GetNextBlockInChain(This->parentStorage, blockIndex, &blockIndex)))
|
2006-09-11 12:13:47 +02:00
|
|
|
return STG_E_DOCFILECORRUPT;
|
1999-01-30 14:24:23 +01:00
|
|
|
blockNoInSequence--;
|
|
|
|
}
|
|
|
|
|
2005-12-22 17:15:05 +01:00
|
|
|
if ((blockNoInSequence > 0) && (blockIndex == BLOCK_END_OF_CHAIN))
|
2006-09-11 12:13:47 +02:00
|
|
|
return STG_E_DOCFILECORRUPT; /* We failed to find the starting block */
|
2005-12-22 17:15:05 +01:00
|
|
|
|
1999-03-12 18:06:46 +01:00
|
|
|
This->lastBlockNoInSequenceIndex = blockIndex;
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Start reading the buffer.
|
|
|
|
*/
|
|
|
|
*bytesRead = 0;
|
|
|
|
bufferWalker = buffer;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
while ( (size > 0) && (blockIndex != BLOCK_END_OF_CHAIN) )
|
|
|
|
{
|
2007-03-16 19:34:28 +01:00
|
|
|
ULARGE_INTEGER ulOffset;
|
|
|
|
DWORD bytesReadAt;
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Calculate how many bytes we can copy from this big block.
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
bytesToReadInBuffer =
|
2000-03-25 22:44:35 +01:00
|
|
|
min(This->parentStorage->bigBlockSize - offsetInBlock, size);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2007-03-16 19:34:28 +01:00
|
|
|
TRACE("block %i\n",blockIndex);
|
|
|
|
ulOffset.u.HighPart = 0;
|
|
|
|
ulOffset.u.LowPart = BLOCK_GetBigBlockOffset(blockIndex) +
|
|
|
|
offsetInBlock;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2007-03-16 19:34:28 +01:00
|
|
|
StorageImpl_ReadAt(This->parentStorage,
|
|
|
|
ulOffset,
|
|
|
|
bufferWalker,
|
|
|
|
bytesToReadInBuffer,
|
|
|
|
&bytesReadAt);
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Step to the next big block.
|
|
|
|
*/
|
2007-03-16 19:34:28 +01:00
|
|
|
if( size > bytesReadAt && FAILED(StorageImpl_GetNextBlockInChain(This->parentStorage, blockIndex, &blockIndex)))
|
2006-09-11 12:13:47 +02:00
|
|
|
return STG_E_DOCFILECORRUPT;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2007-03-16 19:34:28 +01:00
|
|
|
bufferWalker += bytesReadAt;
|
|
|
|
size -= bytesReadAt;
|
|
|
|
*bytesRead += bytesReadAt;
|
1999-01-30 14:24:23 +01:00
|
|
|
offsetInBlock = 0; /* There is no offset on the next block */
|
|
|
|
|
2007-03-16 19:34:28 +01:00
|
|
|
if (bytesToReadInBuffer != bytesReadAt)
|
|
|
|
break;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-09-11 12:13:47 +02:00
|
|
|
return (size == 0) ? S_OK : STG_E_READFAULT;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* BlockChainStream_WriteAt
|
|
|
|
*
|
|
|
|
* Writes the specified number of bytes to this chain at the specified offset.
|
|
|
|
* Will fail if not all specified number of bytes have been written.
|
|
|
|
*/
|
2006-09-11 12:13:47 +02:00
|
|
|
HRESULT BlockChainStream_WriteAt(BlockChainStream* This,
|
1999-01-30 14:24:23 +01:00
|
|
|
ULARGE_INTEGER offset,
|
|
|
|
ULONG size,
|
|
|
|
const void* buffer,
|
|
|
|
ULONG* bytesWritten)
|
|
|
|
{
|
2004-01-23 02:51:33 +01:00
|
|
|
ULONG blockNoInSequence = offset.u.LowPart / This->parentStorage->bigBlockSize;
|
|
|
|
ULONG offsetInBlock = offset.u.LowPart % This->parentStorage->bigBlockSize;
|
1999-01-30 14:24:23 +01:00
|
|
|
ULONG bytesToWrite;
|
|
|
|
ULONG blockIndex;
|
2004-11-30 22:38:57 +01:00
|
|
|
const BYTE* bufferWalker;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the first block in the stream that contains part of the buffer.
|
|
|
|
*/
|
1999-05-02 13:41:10 +02:00
|
|
|
if ( (This->lastBlockNoInSequence == 0xFFFFFFFF) ||
|
|
|
|
(This->lastBlockNoInSequenceIndex == BLOCK_END_OF_CHAIN) ||
|
|
|
|
(blockNoInSequence < This->lastBlockNoInSequence) )
|
|
|
|
{
|
|
|
|
blockIndex = BlockChainStream_GetHeadOfChain(This);
|
|
|
|
This->lastBlockNoInSequence = blockNoInSequence;
|
|
|
|
}
|
|
|
|
else
|
1999-03-12 18:06:46 +01:00
|
|
|
{
|
|
|
|
ULONG temp = blockNoInSequence;
|
|
|
|
|
|
|
|
blockIndex = This->lastBlockNoInSequenceIndex;
|
|
|
|
blockNoInSequence -= This->lastBlockNoInSequence;
|
|
|
|
This->lastBlockNoInSequence = temp;
|
|
|
|
}
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
while ( (blockNoInSequence > 0) && (blockIndex != BLOCK_END_OF_CHAIN))
|
|
|
|
{
|
2002-08-16 21:55:14 +02:00
|
|
|
if(FAILED(StorageImpl_GetNextBlockInChain(This->parentStorage, blockIndex,
|
|
|
|
&blockIndex)))
|
2006-09-11 12:13:47 +02:00
|
|
|
return STG_E_DOCFILECORRUPT;
|
1999-01-30 14:24:23 +01:00
|
|
|
blockNoInSequence--;
|
|
|
|
}
|
|
|
|
|
1999-03-12 18:06:46 +01:00
|
|
|
This->lastBlockNoInSequenceIndex = blockIndex;
|
|
|
|
|
2006-09-11 12:15:01 +02:00
|
|
|
/* BlockChainStream_SetSize should have already been called to ensure we have
|
|
|
|
* enough blocks in the chain to write into */
|
|
|
|
if (blockIndex == BLOCK_END_OF_CHAIN)
|
|
|
|
{
|
|
|
|
ERR("not enough blocks in chain to write data\n");
|
|
|
|
return STG_E_DOCFILECORRUPT;
|
|
|
|
}
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
*bytesWritten = 0;
|
2009-02-11 10:48:38 +01:00
|
|
|
bufferWalker = buffer;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
while ( (size > 0) && (blockIndex != BLOCK_END_OF_CHAIN) )
|
|
|
|
{
|
2007-03-16 19:34:28 +01:00
|
|
|
ULARGE_INTEGER ulOffset;
|
|
|
|
DWORD bytesWrittenAt;
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Calculate how many bytes we can copy from this big block.
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
bytesToWrite =
|
2000-03-25 22:44:35 +01:00
|
|
|
min(This->parentStorage->bigBlockSize - offsetInBlock, size);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2007-03-16 19:34:28 +01:00
|
|
|
TRACE("block %i\n",blockIndex);
|
|
|
|
ulOffset.u.HighPart = 0;
|
|
|
|
ulOffset.u.LowPart = BLOCK_GetBigBlockOffset(blockIndex) +
|
|
|
|
offsetInBlock;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2007-03-16 19:34:28 +01:00
|
|
|
StorageImpl_WriteAt(This->parentStorage,
|
|
|
|
ulOffset,
|
2007-07-06 00:27:24 +02:00
|
|
|
bufferWalker,
|
2007-03-16 19:34:28 +01:00
|
|
|
bytesToWrite,
|
|
|
|
&bytesWrittenAt);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Step to the next big block.
|
|
|
|
*/
|
2007-03-16 19:34:28 +01:00
|
|
|
if(size > bytesWrittenAt && FAILED(StorageImpl_GetNextBlockInChain(This->parentStorage, blockIndex,
|
2002-08-16 21:55:14 +02:00
|
|
|
&blockIndex)))
|
2006-09-11 12:13:47 +02:00
|
|
|
return STG_E_DOCFILECORRUPT;
|
2007-03-16 19:34:28 +01:00
|
|
|
|
|
|
|
bufferWalker += bytesWrittenAt;
|
|
|
|
size -= bytesWrittenAt;
|
|
|
|
*bytesWritten += bytesWrittenAt;
|
1999-01-30 14:24:23 +01:00
|
|
|
offsetInBlock = 0; /* There is no offset on the next block */
|
2007-03-16 19:34:28 +01:00
|
|
|
|
|
|
|
if (bytesWrittenAt != bytesToWrite)
|
|
|
|
break;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-09-11 12:13:47 +02:00
|
|
|
return (size == 0) ? S_OK : STG_E_WRITEFAULT;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* BlockChainStream_Shrink
|
|
|
|
*
|
|
|
|
* Shrinks this chain in the big block depot.
|
|
|
|
*/
|
2006-08-02 13:31:26 +02:00
|
|
|
static BOOL BlockChainStream_Shrink(BlockChainStream* This,
|
|
|
|
ULARGE_INTEGER newSize)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
ULONG blockIndex, extraBlock;
|
|
|
|
ULONG numBlocks;
|
|
|
|
ULONG count = 1;
|
|
|
|
|
1999-05-02 13:41:10 +02:00
|
|
|
/*
|
|
|
|
* Reset the last accessed block cache.
|
|
|
|
*/
|
|
|
|
This->lastBlockNoInSequence = 0xFFFFFFFF;
|
|
|
|
This->lastBlockNoInSequenceIndex = BLOCK_END_OF_CHAIN;
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Figure out how many blocks are needed to contain the new size
|
|
|
|
*/
|
2004-01-23 02:51:33 +01:00
|
|
|
numBlocks = newSize.u.LowPart / This->parentStorage->bigBlockSize;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
if ((newSize.u.LowPart % This->parentStorage->bigBlockSize) != 0)
|
1999-01-30 14:24:23 +01:00
|
|
|
numBlocks++;
|
|
|
|
|
|
|
|
blockIndex = BlockChainStream_GetHeadOfChain(This);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Go to the new end of chain
|
|
|
|
*/
|
|
|
|
while (count < numBlocks)
|
|
|
|
{
|
2002-08-16 21:55:14 +02:00
|
|
|
if(FAILED(StorageImpl_GetNextBlockInChain(This->parentStorage, blockIndex,
|
|
|
|
&blockIndex)))
|
|
|
|
return FALSE;
|
1999-01-30 14:24:23 +01:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the next block before marking the new end */
|
2002-08-16 21:55:14 +02:00
|
|
|
if(FAILED(StorageImpl_GetNextBlockInChain(This->parentStorage, blockIndex,
|
|
|
|
&extraBlock)))
|
|
|
|
return FALSE;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/* Mark the new end of chain */
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl_SetNextBlockInChain(
|
2002-06-01 01:06:46 +02:00
|
|
|
This->parentStorage,
|
|
|
|
blockIndex,
|
1999-01-30 14:24:23 +01:00
|
|
|
BLOCK_END_OF_CHAIN);
|
|
|
|
|
1999-03-12 18:06:46 +01:00
|
|
|
This->tailIndex = blockIndex;
|
|
|
|
This->numBlocks = numBlocks;
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Mark the extra blocks as free
|
|
|
|
*/
|
|
|
|
while (extraBlock != BLOCK_END_OF_CHAIN)
|
|
|
|
{
|
2002-08-16 21:55:14 +02:00
|
|
|
if(FAILED(StorageImpl_GetNextBlockInChain(This->parentStorage, extraBlock,
|
|
|
|
&blockIndex)))
|
|
|
|
return FALSE;
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl_FreeBigBlock(This->parentStorage, extraBlock);
|
1999-01-30 14:24:23 +01:00
|
|
|
extraBlock = blockIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* BlockChainStream_Enlarge
|
|
|
|
*
|
|
|
|
* Grows this chain in the big block depot.
|
|
|
|
*/
|
2006-08-02 13:31:26 +02:00
|
|
|
static BOOL BlockChainStream_Enlarge(BlockChainStream* This,
|
|
|
|
ULARGE_INTEGER newSize)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
ULONG blockIndex, currentBlock;
|
|
|
|
ULONG newNumBlocks;
|
|
|
|
ULONG oldNumBlocks = 0;
|
|
|
|
|
|
|
|
blockIndex = BlockChainStream_GetHeadOfChain(This);
|
|
|
|
|
|
|
|
/*
|
1999-02-13 13:10:15 +01:00
|
|
|
* Empty chain. Create the head.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
|
|
|
if (blockIndex == BLOCK_END_OF_CHAIN)
|
|
|
|
{
|
1999-02-26 12:11:13 +01:00
|
|
|
blockIndex = StorageImpl_GetNextFreeBigBlock(This->parentStorage);
|
|
|
|
StorageImpl_SetNextBlockInChain(This->parentStorage,
|
1999-02-13 13:10:15 +01:00
|
|
|
blockIndex,
|
|
|
|
BLOCK_END_OF_CHAIN);
|
|
|
|
|
|
|
|
if (This->headOfStreamPlaceHolder != 0)
|
|
|
|
{
|
|
|
|
*(This->headOfStreamPlaceHolder) = blockIndex;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-11-12 22:05:51 +01:00
|
|
|
DirEntry chainEntry;
|
2009-11-12 20:31:25 +01:00
|
|
|
assert(This->ownerDirEntry != DIRENTRY_NULL);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-10 21:39:10 +01:00
|
|
|
StorageImpl_ReadDirEntry(
|
2002-06-01 01:06:46 +02:00
|
|
|
This->parentStorage,
|
2009-11-12 20:31:25 +01:00
|
|
|
This->ownerDirEntry,
|
2009-11-12 22:05:51 +01:00
|
|
|
&chainEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 22:05:51 +01:00
|
|
|
chainEntry.startingBlock = blockIndex;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-10 21:40:05 +01:00
|
|
|
StorageImpl_WriteDirEntry(
|
2002-06-01 01:06:46 +02:00
|
|
|
This->parentStorage,
|
2009-11-12 20:31:25 +01:00
|
|
|
This->ownerDirEntry,
|
2009-11-12 22:05:51 +01:00
|
|
|
&chainEntry);
|
1999-03-12 18:06:46 +01:00
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
1999-03-12 18:06:46 +01:00
|
|
|
This->tailIndex = blockIndex;
|
|
|
|
This->numBlocks = 1;
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Figure out how many blocks are needed to contain this stream
|
|
|
|
*/
|
2004-01-23 02:51:33 +01:00
|
|
|
newNumBlocks = newSize.u.LowPart / This->parentStorage->bigBlockSize;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
if ((newSize.u.LowPart % This->parentStorage->bigBlockSize) != 0)
|
1999-01-30 14:24:23 +01:00
|
|
|
newNumBlocks++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Go to the current end of chain
|
|
|
|
*/
|
1999-03-12 18:06:46 +01:00
|
|
|
if (This->tailIndex == BLOCK_END_OF_CHAIN)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
currentBlock = blockIndex;
|
|
|
|
|
1999-03-12 18:06:46 +01:00
|
|
|
while (blockIndex != BLOCK_END_OF_CHAIN)
|
|
|
|
{
|
|
|
|
This->numBlocks++;
|
|
|
|
currentBlock = blockIndex;
|
|
|
|
|
2002-08-16 21:55:14 +02:00
|
|
|
if(FAILED(StorageImpl_GetNextBlockInChain(This->parentStorage, currentBlock,
|
|
|
|
&blockIndex)))
|
|
|
|
return FALSE;
|
1999-03-12 18:06:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
This->tailIndex = currentBlock;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
1999-03-12 18:06:46 +01:00
|
|
|
currentBlock = This->tailIndex;
|
|
|
|
oldNumBlocks = This->numBlocks;
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Add new blocks to the chain
|
|
|
|
*/
|
1999-05-02 13:41:10 +02:00
|
|
|
if (oldNumBlocks < newNumBlocks)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
1999-05-02 13:41:10 +02:00
|
|
|
while (oldNumBlocks < newNumBlocks)
|
|
|
|
{
|
|
|
|
blockIndex = StorageImpl_GetNextFreeBigBlock(This->parentStorage);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
1999-05-02 13:41:10 +02:00
|
|
|
StorageImpl_SetNextBlockInChain(
|
2002-06-01 01:06:46 +02:00
|
|
|
This->parentStorage,
|
|
|
|
currentBlock,
|
1999-05-02 13:41:10 +02:00
|
|
|
blockIndex);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
1999-05-02 13:41:10 +02:00
|
|
|
StorageImpl_SetNextBlockInChain(
|
2002-06-01 01:06:46 +02:00
|
|
|
This->parentStorage,
|
|
|
|
blockIndex,
|
1999-05-02 13:41:10 +02:00
|
|
|
BLOCK_END_OF_CHAIN);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
1999-05-02 13:41:10 +02:00
|
|
|
currentBlock = blockIndex;
|
|
|
|
oldNumBlocks++;
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
1999-05-02 13:41:10 +02:00
|
|
|
This->tailIndex = blockIndex;
|
|
|
|
This->numBlocks = newNumBlocks;
|
|
|
|
}
|
1999-03-12 18:06:46 +01:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* BlockChainStream_SetSize
|
|
|
|
*
|
|
|
|
* Sets the size of this stream. The big block depot will be updated.
|
|
|
|
* The file will grow if we grow the chain.
|
|
|
|
*
|
|
|
|
* TODO: Free the actual blocks in the file when we shrink the chain.
|
|
|
|
* Currently, the blocks are still in the file. So the file size
|
2002-06-01 01:06:46 +02:00
|
|
|
* doesn't shrink even if we shrink streams.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL BlockChainStream_SetSize(
|
1999-01-30 14:24:23 +01:00
|
|
|
BlockChainStream* This,
|
|
|
|
ULARGE_INTEGER newSize)
|
|
|
|
{
|
|
|
|
ULARGE_INTEGER size = BlockChainStream_GetSize(This);
|
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
if (newSize.u.LowPart == size.u.LowPart)
|
1999-01-30 14:24:23 +01:00
|
|
|
return TRUE;
|
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
if (newSize.u.LowPart < size.u.LowPart)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
BlockChainStream_Shrink(This, newSize);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BlockChainStream_Enlarge(This, newSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* BlockChainStream_GetSize
|
|
|
|
*
|
|
|
|
* Returns the size of this chain.
|
2009-11-12 22:05:51 +01:00
|
|
|
* Will return the block count if this chain doesn't have a directory entry.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2006-08-02 13:31:26 +02:00
|
|
|
static ULARGE_INTEGER BlockChainStream_GetSize(BlockChainStream* This)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-12 22:05:51 +01:00
|
|
|
DirEntry chainEntry;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
if(This->headOfStreamPlaceHolder == NULL)
|
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
2009-11-12 22:05:51 +01:00
|
|
|
* This chain has a directory entry so use the size value from there.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2009-11-10 21:39:10 +01:00
|
|
|
StorageImpl_ReadDirEntry(
|
1999-01-30 14:24:23 +01:00
|
|
|
This->parentStorage,
|
2009-11-12 20:31:25 +01:00
|
|
|
This->ownerDirEntry,
|
2009-11-12 22:05:51 +01:00
|
|
|
&chainEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 22:05:51 +01:00
|
|
|
return chainEntry.size;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
2009-11-12 22:05:51 +01:00
|
|
|
* this chain is a chain that does not have a directory entry, figure out the
|
2002-06-01 01:06:46 +02:00
|
|
|
* size by making the product number of used blocks times the
|
1999-01-30 14:24:23 +01:00
|
|
|
* size of them
|
|
|
|
*/
|
|
|
|
ULARGE_INTEGER result;
|
2004-01-23 02:51:33 +01:00
|
|
|
result.u.HighPart = 0;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
result.u.LowPart =
|
2002-06-01 01:06:46 +02:00
|
|
|
BlockChainStream_GetCount(This) *
|
1999-01-30 14:24:23 +01:00
|
|
|
This->parentStorage->bigBlockSize;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
** SmallBlockChainStream implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
SmallBlockChainStream* SmallBlockChainStream_Construct(
|
2002-06-01 01:06:46 +02:00
|
|
|
StorageImpl* parentStorage,
|
2009-08-19 22:19:07 +02:00
|
|
|
ULONG* headOfStreamPlaceHolder,
|
2009-11-12 22:53:42 +01:00
|
|
|
DirRef dirEntry)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
SmallBlockChainStream* newStream;
|
|
|
|
|
|
|
|
newStream = HeapAlloc(GetProcessHeap(), 0, sizeof(SmallBlockChainStream));
|
|
|
|
|
|
|
|
newStream->parentStorage = parentStorage;
|
2009-08-19 22:19:07 +02:00
|
|
|
newStream->headOfStreamPlaceHolder = headOfStreamPlaceHolder;
|
2009-11-12 20:36:07 +01:00
|
|
|
newStream->ownerDirEntry = dirEntry;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
return newStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SmallBlockChainStream_Destroy(
|
|
|
|
SmallBlockChainStream* This)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* SmallBlockChainStream_GetHeadOfChain
|
|
|
|
*
|
|
|
|
* Returns the head of this chain of small blocks.
|
|
|
|
*/
|
2006-08-02 13:31:26 +02:00
|
|
|
static ULONG SmallBlockChainStream_GetHeadOfChain(
|
1999-01-30 14:24:23 +01:00
|
|
|
SmallBlockChainStream* This)
|
|
|
|
{
|
2009-11-12 22:07:39 +01:00
|
|
|
DirEntry chainEntry;
|
2000-01-29 22:12:58 +01:00
|
|
|
BOOL readSuccessful;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-08-19 22:19:07 +02:00
|
|
|
if (This->headOfStreamPlaceHolder != NULL)
|
|
|
|
return *(This->headOfStreamPlaceHolder);
|
|
|
|
|
2009-11-12 20:36:07 +01:00
|
|
|
if (This->ownerDirEntry)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-10 21:39:10 +01:00
|
|
|
readSuccessful = StorageImpl_ReadDirEntry(
|
1999-01-30 14:24:23 +01:00
|
|
|
This->parentStorage,
|
2009-11-12 20:36:07 +01:00
|
|
|
This->ownerDirEntry,
|
2009-11-12 22:07:39 +01:00
|
|
|
&chainEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-01-29 22:12:58 +01:00
|
|
|
if (readSuccessful)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-12 22:07:39 +01:00
|
|
|
return chainEntry.startingBlock;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return BLOCK_END_OF_CHAIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* SmallBlockChainStream_GetNextBlockInChain
|
|
|
|
*
|
|
|
|
* Returns the index of the next small block in this chain.
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
1999-01-30 14:24:23 +01:00
|
|
|
* Return Values:
|
|
|
|
* - BLOCK_END_OF_CHAIN: end of this chain
|
|
|
|
* - BLOCK_UNUSED: small block 'blockIndex' is free
|
|
|
|
*/
|
2006-08-02 13:31:26 +02:00
|
|
|
static HRESULT SmallBlockChainStream_GetNextBlockInChain(
|
1999-01-30 14:24:23 +01:00
|
|
|
SmallBlockChainStream* This,
|
2002-08-16 21:55:14 +02:00
|
|
|
ULONG blockIndex,
|
|
|
|
ULONG* nextBlockInChain)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
ULARGE_INTEGER offsetOfBlockInDepot;
|
|
|
|
DWORD buffer;
|
|
|
|
ULONG bytesRead;
|
2006-09-11 12:13:47 +02:00
|
|
|
HRESULT res;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2002-08-16 21:55:14 +02:00
|
|
|
*nextBlockInChain = BLOCK_END_OF_CHAIN;
|
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
offsetOfBlockInDepot.u.HighPart = 0;
|
|
|
|
offsetOfBlockInDepot.u.LowPart = blockIndex * sizeof(ULONG);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read those bytes in the buffer from the small block file.
|
|
|
|
*/
|
2006-09-11 12:13:47 +02:00
|
|
|
res = BlockChainStream_ReadAt(
|
1999-01-30 14:24:23 +01:00
|
|
|
This->parentStorage->smallBlockDepotChain,
|
|
|
|
offsetOfBlockInDepot,
|
|
|
|
sizeof(DWORD),
|
|
|
|
&buffer,
|
|
|
|
&bytesRead);
|
|
|
|
|
2006-09-11 12:13:47 +02:00
|
|
|
if (SUCCEEDED(res))
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2005-03-17 11:25:13 +01:00
|
|
|
StorageUtl_ReadDWord((BYTE *)&buffer, 0, nextBlockInChain);
|
2002-08-16 21:55:14 +02:00
|
|
|
return S_OK;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
2006-09-11 12:13:47 +02:00
|
|
|
return res;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* SmallBlockChainStream_SetNextBlockInChain
|
|
|
|
*
|
|
|
|
* Writes the index of the next block of the specified block in the small
|
|
|
|
* block depot.
|
|
|
|
* To set the end of chain use BLOCK_END_OF_CHAIN as nextBlock.
|
|
|
|
* To flag a block as free use BLOCK_UNUSED as nextBlock.
|
|
|
|
*/
|
2006-08-02 13:31:26 +02:00
|
|
|
static void SmallBlockChainStream_SetNextBlockInChain(
|
1999-01-30 14:24:23 +01:00
|
|
|
SmallBlockChainStream* This,
|
|
|
|
ULONG blockIndex,
|
|
|
|
ULONG nextBlock)
|
|
|
|
{
|
|
|
|
ULARGE_INTEGER offsetOfBlockInDepot;
|
|
|
|
DWORD buffer;
|
|
|
|
ULONG bytesWritten;
|
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
offsetOfBlockInDepot.u.HighPart = 0;
|
|
|
|
offsetOfBlockInDepot.u.LowPart = blockIndex * sizeof(ULONG);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2005-03-17 11:25:13 +01:00
|
|
|
StorageUtl_WriteDWord((BYTE *)&buffer, 0, nextBlock);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read those bytes in the buffer from the small block file.
|
|
|
|
*/
|
|
|
|
BlockChainStream_WriteAt(
|
|
|
|
This->parentStorage->smallBlockDepotChain,
|
|
|
|
offsetOfBlockInDepot,
|
|
|
|
sizeof(DWORD),
|
|
|
|
&buffer,
|
|
|
|
&bytesWritten);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* SmallBlockChainStream_FreeBlock
|
|
|
|
*
|
|
|
|
* Flag small block 'blockIndex' as free in the small block depot.
|
|
|
|
*/
|
2006-08-02 13:31:26 +02:00
|
|
|
static void SmallBlockChainStream_FreeBlock(
|
1999-01-30 14:24:23 +01:00
|
|
|
SmallBlockChainStream* This,
|
|
|
|
ULONG blockIndex)
|
|
|
|
{
|
|
|
|
SmallBlockChainStream_SetNextBlockInChain(This, blockIndex, BLOCK_UNUSED);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* SmallBlockChainStream_GetNextFreeBlock
|
|
|
|
*
|
|
|
|
* Returns the index of a free small block. The small block depot will be
|
|
|
|
* enlarged if necessary. The small block chain will also be enlarged if
|
|
|
|
* necessary.
|
|
|
|
*/
|
2006-08-02 13:31:26 +02:00
|
|
|
static ULONG SmallBlockChainStream_GetNextFreeBlock(
|
1999-01-30 14:24:23 +01:00
|
|
|
SmallBlockChainStream* This)
|
|
|
|
{
|
|
|
|
ULARGE_INTEGER offsetOfBlockInDepot;
|
|
|
|
DWORD buffer;
|
|
|
|
ULONG bytesRead;
|
|
|
|
ULONG blockIndex = 0;
|
|
|
|
ULONG nextBlockIndex = BLOCK_END_OF_CHAIN;
|
2006-09-11 12:13:47 +02:00
|
|
|
HRESULT res = S_OK;
|
1999-01-30 14:24:23 +01:00
|
|
|
ULONG smallBlocksPerBigBlock;
|
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
offsetOfBlockInDepot.u.HighPart = 0;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Scan the small block depot for a free block
|
|
|
|
*/
|
|
|
|
while (nextBlockIndex != BLOCK_UNUSED)
|
|
|
|
{
|
2004-01-23 02:51:33 +01:00
|
|
|
offsetOfBlockInDepot.u.LowPart = blockIndex * sizeof(ULONG);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2006-09-11 12:13:47 +02:00
|
|
|
res = BlockChainStream_ReadAt(
|
1999-01-30 14:24:23 +01:00
|
|
|
This->parentStorage->smallBlockDepotChain,
|
|
|
|
offsetOfBlockInDepot,
|
|
|
|
sizeof(DWORD),
|
|
|
|
&buffer,
|
|
|
|
&bytesRead);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we run out of space for the small block depot, enlarge it
|
|
|
|
*/
|
2006-09-11 12:13:47 +02:00
|
|
|
if (SUCCEEDED(res))
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2005-03-17 11:25:13 +01:00
|
|
|
StorageUtl_ReadDWord((BYTE *)&buffer, 0, &nextBlockIndex);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
if (nextBlockIndex != BLOCK_UNUSED)
|
|
|
|
blockIndex++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
ULONG count =
|
1999-01-30 14:24:23 +01:00
|
|
|
BlockChainStream_GetCount(This->parentStorage->smallBlockDepotChain);
|
|
|
|
|
|
|
|
ULONG sbdIndex = This->parentStorage->smallBlockDepotStart;
|
|
|
|
ULONG nextBlock, newsbdIndex;
|
2007-03-16 19:34:28 +01:00
|
|
|
BYTE smallBlockDepot[BIG_BLOCK_SIZE];
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
nextBlock = sbdIndex;
|
|
|
|
while (nextBlock != BLOCK_END_OF_CHAIN)
|
|
|
|
{
|
|
|
|
sbdIndex = nextBlock;
|
2002-08-16 21:55:14 +02:00
|
|
|
StorageImpl_GetNextBlockInChain(This->parentStorage, sbdIndex, &nextBlock);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
newsbdIndex = StorageImpl_GetNextFreeBigBlock(This->parentStorage);
|
1999-01-30 14:24:23 +01:00
|
|
|
if (sbdIndex != BLOCK_END_OF_CHAIN)
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl_SetNextBlockInChain(
|
2002-06-01 01:06:46 +02:00
|
|
|
This->parentStorage,
|
|
|
|
sbdIndex,
|
1999-01-30 14:24:23 +01:00
|
|
|
newsbdIndex);
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl_SetNextBlockInChain(
|
2002-06-01 01:06:46 +02:00
|
|
|
This->parentStorage,
|
|
|
|
newsbdIndex,
|
1999-01-30 14:24:23 +01:00
|
|
|
BLOCK_END_OF_CHAIN);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize all the small blocks to free
|
|
|
|
*/
|
|
|
|
memset(smallBlockDepot, BLOCK_UNUSED, This->parentStorage->bigBlockSize);
|
2007-03-16 19:34:28 +01:00
|
|
|
StorageImpl_WriteBigBlock(This->parentStorage, newsbdIndex, smallBlockDepot);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
if (count == 0)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We have just created the small block depot.
|
|
|
|
*/
|
2009-11-12 22:07:39 +01:00
|
|
|
DirEntry rootEntry;
|
2002-06-01 01:06:46 +02:00
|
|
|
ULONG sbStartIndex;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Save it in the header
|
|
|
|
*/
|
|
|
|
This->parentStorage->smallBlockDepotStart = newsbdIndex;
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl_SaveFileHeader(This->parentStorage);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
2002-06-01 01:06:46 +02:00
|
|
|
* And allocate the first big block that will contain small blocks
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
sbStartIndex =
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl_GetNextFreeBigBlock(This->parentStorage);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl_SetNextBlockInChain(
|
2002-06-01 01:06:46 +02:00
|
|
|
This->parentStorage,
|
|
|
|
sbStartIndex,
|
1999-01-30 14:24:23 +01:00
|
|
|
BLOCK_END_OF_CHAIN);
|
|
|
|
|
2009-11-10 21:39:10 +01:00
|
|
|
StorageImpl_ReadDirEntry(
|
2002-06-01 01:06:46 +02:00
|
|
|
This->parentStorage,
|
2009-11-12 20:19:37 +01:00
|
|
|
This->parentStorage->base.storageDirEntry,
|
2009-11-12 22:07:39 +01:00
|
|
|
&rootEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 22:07:39 +01:00
|
|
|
rootEntry.startingBlock = sbStartIndex;
|
|
|
|
rootEntry.size.u.HighPart = 0;
|
|
|
|
rootEntry.size.u.LowPart = This->parentStorage->bigBlockSize;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-10 21:40:05 +01:00
|
|
|
StorageImpl_WriteDirEntry(
|
2002-06-01 01:06:46 +02:00
|
|
|
This->parentStorage,
|
2009-11-12 20:19:37 +01:00
|
|
|
This->parentStorage->base.storageDirEntry,
|
2009-11-12 22:07:39 +01:00
|
|
|
&rootEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
2007-08-28 11:11:14 +02:00
|
|
|
else
|
|
|
|
StorageImpl_SaveFileHeader(This->parentStorage);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
smallBlocksPerBigBlock =
|
1999-01-30 14:24:23 +01:00
|
|
|
This->parentStorage->bigBlockSize / This->parentStorage->smallBlockSize;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify if we have to allocate big blocks to contain small blocks
|
|
|
|
*/
|
|
|
|
if (blockIndex % smallBlocksPerBigBlock == 0)
|
|
|
|
{
|
2009-11-12 22:07:39 +01:00
|
|
|
DirEntry rootEntry;
|
1999-01-30 14:24:23 +01:00
|
|
|
ULONG blocksRequired = (blockIndex / smallBlocksPerBigBlock) + 1;
|
|
|
|
|
2009-11-10 21:39:10 +01:00
|
|
|
StorageImpl_ReadDirEntry(
|
2002-06-01 01:06:46 +02:00
|
|
|
This->parentStorage,
|
2009-11-12 20:19:37 +01:00
|
|
|
This->parentStorage->base.storageDirEntry,
|
2009-11-12 22:07:39 +01:00
|
|
|
&rootEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 22:07:39 +01:00
|
|
|
if (rootEntry.size.u.LowPart <
|
1999-01-30 14:24:23 +01:00
|
|
|
(blocksRequired * This->parentStorage->bigBlockSize))
|
|
|
|
{
|
2009-11-12 22:07:39 +01:00
|
|
|
rootEntry.size.u.LowPart += This->parentStorage->bigBlockSize;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
BlockChainStream_SetSize(
|
2002-06-01 01:06:46 +02:00
|
|
|
This->parentStorage->smallBlockRootChain,
|
2009-11-12 22:07:39 +01:00
|
|
|
rootEntry.size);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-10 21:40:05 +01:00
|
|
|
StorageImpl_WriteDirEntry(
|
2002-06-01 01:06:46 +02:00
|
|
|
This->parentStorage,
|
2009-11-12 20:19:37 +01:00
|
|
|
This->parentStorage->base.storageDirEntry,
|
2009-11-12 22:07:39 +01:00
|
|
|
&rootEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return blockIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* SmallBlockChainStream_ReadAt
|
|
|
|
*
|
|
|
|
* Reads a specified number of bytes from this chain at the specified offset.
|
|
|
|
* bytesRead may be NULL.
|
2002-06-01 01:06:46 +02:00
|
|
|
* Failure will be returned if the specified number of bytes has not been read.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2005-12-22 17:15:05 +01:00
|
|
|
HRESULT SmallBlockChainStream_ReadAt(
|
1999-01-30 14:24:23 +01:00
|
|
|
SmallBlockChainStream* This,
|
|
|
|
ULARGE_INTEGER offset,
|
|
|
|
ULONG size,
|
|
|
|
void* buffer,
|
|
|
|
ULONG* bytesRead)
|
|
|
|
{
|
2005-12-22 17:15:05 +01:00
|
|
|
HRESULT rc = S_OK;
|
1999-01-30 14:24:23 +01:00
|
|
|
ULARGE_INTEGER offsetInBigBlockFile;
|
2002-06-01 01:06:46 +02:00
|
|
|
ULONG blockNoInSequence =
|
2004-01-23 02:51:33 +01:00
|
|
|
offset.u.LowPart / This->parentStorage->smallBlockSize;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
ULONG offsetInBlock = offset.u.LowPart % This->parentStorage->smallBlockSize;
|
1999-01-30 14:24:23 +01:00
|
|
|
ULONG bytesToReadInBuffer;
|
|
|
|
ULONG blockIndex;
|
|
|
|
ULONG bytesReadFromBigBlockFile;
|
|
|
|
BYTE* bufferWalker;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This should never happen on a small block file.
|
|
|
|
*/
|
2004-01-23 02:51:33 +01:00
|
|
|
assert(offset.u.HighPart==0);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the first block in the stream that contains part of the buffer.
|
|
|
|
*/
|
|
|
|
blockIndex = SmallBlockChainStream_GetHeadOfChain(This);
|
|
|
|
|
|
|
|
while ( (blockNoInSequence > 0) && (blockIndex != BLOCK_END_OF_CHAIN))
|
|
|
|
{
|
2005-12-22 17:15:05 +01:00
|
|
|
rc = SmallBlockChainStream_GetNextBlockInChain(This, blockIndex, &blockIndex);
|
|
|
|
if(FAILED(rc))
|
|
|
|
return rc;
|
1999-01-30 14:24:23 +01:00
|
|
|
blockNoInSequence--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start reading the buffer.
|
|
|
|
*/
|
|
|
|
*bytesRead = 0;
|
|
|
|
bufferWalker = buffer;
|
|
|
|
|
|
|
|
while ( (size > 0) && (blockIndex != BLOCK_END_OF_CHAIN) )
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Calculate how many bytes we can copy from this small block.
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
bytesToReadInBuffer =
|
2000-03-25 22:44:35 +01:00
|
|
|
min(This->parentStorage->smallBlockSize - offsetInBlock, size);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate the offset of the small block in the small block file.
|
|
|
|
*/
|
2004-01-23 02:51:33 +01:00
|
|
|
offsetInBigBlockFile.u.HighPart = 0;
|
|
|
|
offsetInBigBlockFile.u.LowPart =
|
1999-01-30 14:24:23 +01:00
|
|
|
blockIndex * This->parentStorage->smallBlockSize;
|
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
offsetInBigBlockFile.u.LowPart += offsetInBlock;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read those bytes in the buffer from the small block file.
|
2005-12-22 17:15:05 +01:00
|
|
|
* The small block has already been identified so it shouldn't fail
|
|
|
|
* unless the file is corrupt.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2006-09-11 12:13:47 +02:00
|
|
|
rc = BlockChainStream_ReadAt(This->parentStorage->smallBlockRootChain,
|
1999-01-30 14:24:23 +01:00
|
|
|
offsetInBigBlockFile,
|
|
|
|
bytesToReadInBuffer,
|
|
|
|
bufferWalker,
|
2006-09-11 12:13:47 +02:00
|
|
|
&bytesReadFromBigBlockFile);
|
|
|
|
|
|
|
|
if (FAILED(rc))
|
|
|
|
return rc;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Step to the next big block.
|
|
|
|
*/
|
2005-12-22 17:15:05 +01:00
|
|
|
rc = SmallBlockChainStream_GetNextBlockInChain(This, blockIndex, &blockIndex);
|
|
|
|
if(FAILED(rc))
|
2006-09-11 12:13:47 +02:00
|
|
|
return STG_E_DOCFILECORRUPT;
|
2005-12-22 17:15:05 +01:00
|
|
|
|
2006-09-11 12:14:25 +02:00
|
|
|
bufferWalker += bytesReadFromBigBlockFile;
|
|
|
|
size -= bytesReadFromBigBlockFile;
|
|
|
|
*bytesRead += bytesReadFromBigBlockFile;
|
|
|
|
offsetInBlock = (offsetInBlock + bytesReadFromBigBlockFile) % This->parentStorage->smallBlockSize;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
2006-09-11 12:13:47 +02:00
|
|
|
return (size == 0) ? S_OK : STG_E_READFAULT;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* SmallBlockChainStream_WriteAt
|
|
|
|
*
|
|
|
|
* Writes the specified number of bytes to this chain at the specified offset.
|
|
|
|
* Will fail if not all specified number of bytes have been written.
|
|
|
|
*/
|
2006-09-11 12:13:47 +02:00
|
|
|
HRESULT SmallBlockChainStream_WriteAt(
|
1999-01-30 14:24:23 +01:00
|
|
|
SmallBlockChainStream* This,
|
|
|
|
ULARGE_INTEGER offset,
|
|
|
|
ULONG size,
|
|
|
|
const void* buffer,
|
|
|
|
ULONG* bytesWritten)
|
|
|
|
{
|
|
|
|
ULARGE_INTEGER offsetInBigBlockFile;
|
2002-06-01 01:06:46 +02:00
|
|
|
ULONG blockNoInSequence =
|
2004-01-23 02:51:33 +01:00
|
|
|
offset.u.LowPart / This->parentStorage->smallBlockSize;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
ULONG offsetInBlock = offset.u.LowPart % This->parentStorage->smallBlockSize;
|
1999-01-30 14:24:23 +01:00
|
|
|
ULONG bytesToWriteInBuffer;
|
|
|
|
ULONG blockIndex;
|
2006-09-11 12:14:25 +02:00
|
|
|
ULONG bytesWrittenToBigBlockFile;
|
2004-11-30 22:38:57 +01:00
|
|
|
const BYTE* bufferWalker;
|
2006-09-11 12:13:47 +02:00
|
|
|
HRESULT res;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* This should never happen on a small block file.
|
|
|
|
*/
|
2004-01-23 02:51:33 +01:00
|
|
|
assert(offset.u.HighPart==0);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Find the first block in the stream that contains part of the buffer.
|
|
|
|
*/
|
|
|
|
blockIndex = SmallBlockChainStream_GetHeadOfChain(This);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
while ( (blockNoInSequence > 0) && (blockIndex != BLOCK_END_OF_CHAIN))
|
|
|
|
{
|
2002-08-16 21:55:14 +02:00
|
|
|
if(FAILED(SmallBlockChainStream_GetNextBlockInChain(This, blockIndex, &blockIndex)))
|
2006-09-11 12:13:47 +02:00
|
|
|
return STG_E_DOCFILECORRUPT;
|
1999-01-30 14:24:23 +01:00
|
|
|
blockNoInSequence--;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Start writing the buffer.
|
|
|
|
*/
|
|
|
|
*bytesWritten = 0;
|
2009-02-11 10:48:38 +01:00
|
|
|
bufferWalker = buffer;
|
1999-01-30 14:24:23 +01:00
|
|
|
while ( (size > 0) && (blockIndex != BLOCK_END_OF_CHAIN) )
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Calculate how many bytes we can copy to this small block.
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
bytesToWriteInBuffer =
|
2000-03-25 22:44:35 +01:00
|
|
|
min(This->parentStorage->smallBlockSize - offsetInBlock, size);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Calculate the offset of the small block in the small block file.
|
|
|
|
*/
|
2004-01-23 02:51:33 +01:00
|
|
|
offsetInBigBlockFile.u.HighPart = 0;
|
|
|
|
offsetInBigBlockFile.u.LowPart =
|
1999-01-30 14:24:23 +01:00
|
|
|
blockIndex * This->parentStorage->smallBlockSize;
|
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
offsetInBigBlockFile.u.LowPart += offsetInBlock;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Write those bytes in the buffer to the small block file.
|
|
|
|
*/
|
2006-09-11 12:13:47 +02:00
|
|
|
res = BlockChainStream_WriteAt(
|
|
|
|
This->parentStorage->smallBlockRootChain,
|
1999-01-30 14:24:23 +01:00
|
|
|
offsetInBigBlockFile,
|
|
|
|
bytesToWriteInBuffer,
|
|
|
|
bufferWalker,
|
2006-09-11 12:14:25 +02:00
|
|
|
&bytesWrittenToBigBlockFile);
|
2006-09-11 12:13:47 +02:00
|
|
|
if (FAILED(res))
|
|
|
|
return res;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Step to the next big block.
|
|
|
|
*/
|
2002-08-16 21:55:14 +02:00
|
|
|
if(FAILED(SmallBlockChainStream_GetNextBlockInChain(This, blockIndex,
|
|
|
|
&blockIndex)))
|
|
|
|
return FALSE;
|
2006-09-11 12:14:25 +02:00
|
|
|
bufferWalker += bytesWrittenToBigBlockFile;
|
|
|
|
size -= bytesWrittenToBigBlockFile;
|
|
|
|
*bytesWritten += bytesWrittenToBigBlockFile;
|
|
|
|
offsetInBlock = (offsetInBlock + bytesWrittenToBigBlockFile) % This->parentStorage->smallBlockSize;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-09-11 12:13:47 +02:00
|
|
|
return (size == 0) ? S_OK : STG_E_WRITEFAULT;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* SmallBlockChainStream_Shrink
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Shrinks this chain in the small block depot.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2006-08-02 13:31:26 +02:00
|
|
|
static BOOL SmallBlockChainStream_Shrink(
|
1999-01-30 14:24:23 +01:00
|
|
|
SmallBlockChainStream* This,
|
|
|
|
ULARGE_INTEGER newSize)
|
|
|
|
{
|
|
|
|
ULONG blockIndex, extraBlock;
|
|
|
|
ULONG numBlocks;
|
1999-05-02 13:41:10 +02:00
|
|
|
ULONG count = 0;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
numBlocks = newSize.u.LowPart / This->parentStorage->smallBlockSize;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
if ((newSize.u.LowPart % This->parentStorage->smallBlockSize) != 0)
|
1999-01-30 14:24:23 +01:00
|
|
|
numBlocks++;
|
|
|
|
|
|
|
|
blockIndex = SmallBlockChainStream_GetHeadOfChain(This);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Go to the new end of chain
|
|
|
|
*/
|
|
|
|
while (count < numBlocks)
|
|
|
|
{
|
2002-08-16 21:55:14 +02:00
|
|
|
if(FAILED(SmallBlockChainStream_GetNextBlockInChain(This, blockIndex,
|
|
|
|
&blockIndex)))
|
|
|
|
return FALSE;
|
1999-01-30 14:24:23 +01:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
1999-05-02 13:41:10 +02:00
|
|
|
/*
|
|
|
|
* If the count is 0, we have a special case, the head of the chain was
|
2002-06-01 01:06:46 +02:00
|
|
|
* just freed.
|
1999-05-02 13:41:10 +02:00
|
|
|
*/
|
|
|
|
if (count == 0)
|
|
|
|
{
|
2009-11-12 22:07:39 +01:00
|
|
|
DirEntry chainEntry;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-10 21:39:10 +01:00
|
|
|
StorageImpl_ReadDirEntry(This->parentStorage,
|
2009-11-12 20:36:07 +01:00
|
|
|
This->ownerDirEntry,
|
2009-11-12 22:07:39 +01:00
|
|
|
&chainEntry);
|
1999-05-02 13:41:10 +02:00
|
|
|
|
2009-11-12 22:07:39 +01:00
|
|
|
chainEntry.startingBlock = BLOCK_END_OF_CHAIN;
|
1999-05-02 13:41:10 +02:00
|
|
|
|
2009-11-10 21:40:05 +01:00
|
|
|
StorageImpl_WriteDirEntry(This->parentStorage,
|
2009-11-12 20:36:07 +01:00
|
|
|
This->ownerDirEntry,
|
2009-11-12 22:07:39 +01:00
|
|
|
&chainEntry);
|
1999-05-02 13:41:10 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We start freeing the chain at the head block.
|
|
|
|
*/
|
|
|
|
extraBlock = blockIndex;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Get the next block before marking the new end */
|
2002-08-16 21:55:14 +02:00
|
|
|
if(FAILED(SmallBlockChainStream_GetNextBlockInChain(This, blockIndex,
|
|
|
|
&extraBlock)))
|
|
|
|
return FALSE;
|
1999-05-02 13:41:10 +02:00
|
|
|
|
|
|
|
/* Mark the new end of chain */
|
|
|
|
SmallBlockChainStream_SetNextBlockInChain(
|
2002-06-01 01:06:46 +02:00
|
|
|
This,
|
|
|
|
blockIndex,
|
1999-05-02 13:41:10 +02:00
|
|
|
BLOCK_END_OF_CHAIN);
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark the extra blocks as free
|
|
|
|
*/
|
|
|
|
while (extraBlock != BLOCK_END_OF_CHAIN)
|
|
|
|
{
|
2002-08-16 21:55:14 +02:00
|
|
|
if(FAILED(SmallBlockChainStream_GetNextBlockInChain(This, extraBlock,
|
|
|
|
&blockIndex)))
|
|
|
|
return FALSE;
|
1999-01-30 14:24:23 +01:00
|
|
|
SmallBlockChainStream_FreeBlock(This, extraBlock);
|
|
|
|
extraBlock = blockIndex;
|
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
return TRUE;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* SmallBlockChainStream_Enlarge
|
|
|
|
*
|
|
|
|
* Grows this chain in the small block depot.
|
|
|
|
*/
|
2006-08-02 13:31:26 +02:00
|
|
|
static BOOL SmallBlockChainStream_Enlarge(
|
1999-01-30 14:24:23 +01:00
|
|
|
SmallBlockChainStream* This,
|
|
|
|
ULARGE_INTEGER newSize)
|
|
|
|
{
|
|
|
|
ULONG blockIndex, currentBlock;
|
|
|
|
ULONG newNumBlocks;
|
|
|
|
ULONG oldNumBlocks = 0;
|
|
|
|
|
|
|
|
blockIndex = SmallBlockChainStream_GetHeadOfChain(This);
|
|
|
|
|
|
|
|
/*
|
2009-08-19 22:19:07 +02:00
|
|
|
* Empty chain. Create the head.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
|
|
|
if (blockIndex == BLOCK_END_OF_CHAIN)
|
|
|
|
{
|
2009-08-19 22:19:07 +02:00
|
|
|
blockIndex = SmallBlockChainStream_GetNextFreeBlock(This);
|
|
|
|
SmallBlockChainStream_SetNextBlockInChain(
|
|
|
|
This,
|
|
|
|
blockIndex,
|
|
|
|
BLOCK_END_OF_CHAIN);
|
1999-05-02 13:41:10 +02:00
|
|
|
|
2009-08-19 22:19:07 +02:00
|
|
|
if (This->headOfStreamPlaceHolder != NULL)
|
|
|
|
{
|
|
|
|
*(This->headOfStreamPlaceHolder) = blockIndex;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-11-12 22:07:39 +01:00
|
|
|
DirEntry chainEntry;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 20:36:07 +01:00
|
|
|
StorageImpl_ReadDirEntry(This->parentStorage, This->ownerDirEntry,
|
2009-11-12 22:07:39 +01:00
|
|
|
&chainEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 22:07:39 +01:00
|
|
|
chainEntry.startingBlock = blockIndex;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 20:36:07 +01:00
|
|
|
StorageImpl_WriteDirEntry(This->parentStorage, This->ownerDirEntry,
|
2009-11-12 22:07:39 +01:00
|
|
|
&chainEntry);
|
2009-08-19 22:19:07 +02:00
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
currentBlock = blockIndex;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Figure out how many blocks are needed to contain this stream
|
|
|
|
*/
|
2004-01-23 02:51:33 +01:00
|
|
|
newNumBlocks = newSize.u.LowPart / This->parentStorage->smallBlockSize;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
if ((newSize.u.LowPart % This->parentStorage->smallBlockSize) != 0)
|
1999-01-30 14:24:23 +01:00
|
|
|
newNumBlocks++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Go to the current end of chain
|
|
|
|
*/
|
|
|
|
while (blockIndex != BLOCK_END_OF_CHAIN)
|
|
|
|
{
|
|
|
|
oldNumBlocks++;
|
|
|
|
currentBlock = blockIndex;
|
2002-08-16 21:55:14 +02:00
|
|
|
if(FAILED(SmallBlockChainStream_GetNextBlockInChain(This, currentBlock, &blockIndex)))
|
|
|
|
return FALSE;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add new blocks to the chain
|
|
|
|
*/
|
|
|
|
while (oldNumBlocks < newNumBlocks)
|
|
|
|
{
|
|
|
|
blockIndex = SmallBlockChainStream_GetNextFreeBlock(This);
|
|
|
|
SmallBlockChainStream_SetNextBlockInChain(This, currentBlock, blockIndex);
|
|
|
|
|
|
|
|
SmallBlockChainStream_SetNextBlockInChain(
|
2002-06-01 01:06:46 +02:00
|
|
|
This,
|
|
|
|
blockIndex,
|
1999-01-30 14:24:23 +01:00
|
|
|
BLOCK_END_OF_CHAIN);
|
|
|
|
|
|
|
|
currentBlock = blockIndex;
|
|
|
|
oldNumBlocks++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* SmallBlockChainStream_SetSize
|
|
|
|
*
|
|
|
|
* Sets the size of this stream.
|
|
|
|
* The file will grow if we grow the chain.
|
|
|
|
*
|
|
|
|
* TODO: Free the actual blocks in the file when we shrink the chain.
|
|
|
|
* Currently, the blocks are still in the file. So the file size
|
2002-06-01 01:06:46 +02:00
|
|
|
* doesn't shrink even if we shrink streams.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL SmallBlockChainStream_SetSize(
|
1999-01-30 14:24:23 +01:00
|
|
|
SmallBlockChainStream* This,
|
|
|
|
ULARGE_INTEGER newSize)
|
|
|
|
{
|
|
|
|
ULARGE_INTEGER size = SmallBlockChainStream_GetSize(This);
|
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
if (newSize.u.LowPart == size.u.LowPart)
|
1999-01-30 14:24:23 +01:00
|
|
|
return TRUE;
|
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
if (newSize.u.LowPart < size.u.LowPart)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
SmallBlockChainStream_Shrink(This, newSize);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SmallBlockChainStream_Enlarge(This, newSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-08-19 22:19:07 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* SmallBlockChainStream_GetCount
|
|
|
|
*
|
|
|
|
* Returns the number of small blocks that comprises this chain.
|
|
|
|
* This is not the size of the stream as the last block may not be full!
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static ULONG SmallBlockChainStream_GetCount(SmallBlockChainStream* This)
|
|
|
|
{
|
|
|
|
ULONG blockIndex;
|
|
|
|
ULONG count = 0;
|
|
|
|
|
|
|
|
blockIndex = SmallBlockChainStream_GetHeadOfChain(This);
|
|
|
|
|
|
|
|
while(blockIndex != BLOCK_END_OF_CHAIN)
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
|
|
|
|
if(FAILED(SmallBlockChainStream_GetNextBlockInChain(This,
|
|
|
|
blockIndex, &blockIndex)))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* SmallBlockChainStream_GetSize
|
|
|
|
*
|
|
|
|
* Returns the size of this chain.
|
|
|
|
*/
|
2006-08-02 13:31:26 +02:00
|
|
|
static ULARGE_INTEGER SmallBlockChainStream_GetSize(SmallBlockChainStream* This)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2009-11-12 22:07:39 +01:00
|
|
|
DirEntry chainEntry;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-08-19 22:19:07 +02:00
|
|
|
if(This->headOfStreamPlaceHolder != NULL)
|
|
|
|
{
|
|
|
|
ULARGE_INTEGER result;
|
|
|
|
result.u.HighPart = 0;
|
|
|
|
|
|
|
|
result.u.LowPart = SmallBlockChainStream_GetCount(This) *
|
|
|
|
This->parentStorage->smallBlockSize;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-11-10 21:39:10 +01:00
|
|
|
StorageImpl_ReadDirEntry(
|
1999-01-30 14:24:23 +01:00
|
|
|
This->parentStorage,
|
2009-11-12 20:36:07 +01:00
|
|
|
This->ownerDirEntry,
|
2009-11-12 22:07:39 +01:00
|
|
|
&chainEntry);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-11-12 22:07:39 +01:00
|
|
|
return chainEntry.size;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* StgCreateDocfile [OLE32.@]
|
2006-02-24 18:06:35 +01:00
|
|
|
* Creates a new compound file storage object
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pwcsName [ I] Unicode string with filename (can be relative or NULL)
|
|
|
|
* grfMode [ I] Access mode for opening the new storage object (see STGM_ constants)
|
|
|
|
* reserved [ ?] unused?, usually 0
|
|
|
|
* ppstgOpen [IO] A pointer to IStorage pointer to the new onject
|
|
|
|
*
|
|
|
|
* RETURNS
|
2006-03-21 18:24:49 +01:00
|
|
|
* S_OK if the file was successfully created
|
2006-02-24 18:06:35 +01:00
|
|
|
* some STG_E_ value if error
|
|
|
|
* NOTES
|
|
|
|
* if pwcsName is NULL, create file with new unique name
|
|
|
|
* the function can returns
|
|
|
|
* STG_S_CONVERTED if the specified file was successfully converted to storage format
|
|
|
|
* (unrealized now)
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
HRESULT WINAPI StgCreateDocfile(
|
|
|
|
LPCOLESTR pwcsName,
|
1999-01-30 14:24:23 +01:00
|
|
|
DWORD grfMode,
|
|
|
|
DWORD reserved,
|
1999-02-26 12:11:13 +01:00
|
|
|
IStorage **ppstgOpen)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
1999-02-26 12:11:13 +01:00
|
|
|
StorageImpl* newStorage = 0;
|
|
|
|
HANDLE hFile = INVALID_HANDLE_VALUE;
|
2005-03-09 12:44:59 +01:00
|
|
|
HRESULT hr = STG_E_INVALIDFLAG;
|
1999-02-13 13:10:15 +01:00
|
|
|
DWORD shareMode;
|
|
|
|
DWORD accessMode;
|
|
|
|
DWORD creationMode;
|
|
|
|
DWORD fileAttributes;
|
1999-03-13 13:48:27 +01:00
|
|
|
WCHAR tempFileName[MAX_PATH];
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%s, %x, %d, %p)\n",
|
2002-06-01 01:06:46 +02:00
|
|
|
debugstr_w(pwcsName), grfMode,
|
1999-05-02 13:41:10 +02:00
|
|
|
reserved, ppstgOpen);
|
|
|
|
|
1999-03-13 13:48:27 +01:00
|
|
|
if (ppstgOpen == 0)
|
1999-01-30 14:24:23 +01:00
|
|
|
return STG_E_INVALIDPOINTER;
|
2005-01-10 13:26:25 +01:00
|
|
|
if (reserved != 0)
|
|
|
|
return STG_E_INVALIDPARAMETER;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2007-05-10 00:31:08 +02:00
|
|
|
/* if no share mode given then DENY_NONE is the default */
|
|
|
|
if (STGM_SHARE_MODE(grfMode) == 0)
|
|
|
|
grfMode |= STGM_SHARE_DENY_NONE;
|
|
|
|
|
1999-02-13 13:10:15 +01:00
|
|
|
if ( FAILED( validateSTGM(grfMode) ))
|
2005-03-09 12:44:59 +01:00
|
|
|
goto end;
|
1999-02-13 13:10:15 +01:00
|
|
|
|
2006-05-01 19:33:26 +02:00
|
|
|
/* StgCreateDocFile seems to refuse readonly access, despite MSDN */
|
2005-03-05 11:48:11 +01:00
|
|
|
switch(STGM_ACCESS_MODE(grfMode))
|
|
|
|
{
|
|
|
|
case STGM_WRITE:
|
|
|
|
case STGM_READWRITE:
|
|
|
|
break;
|
|
|
|
default:
|
2005-03-09 12:44:59 +01:00
|
|
|
goto end;
|
2005-03-05 11:48:11 +01:00
|
|
|
}
|
2005-01-10 13:26:25 +01:00
|
|
|
|
2006-05-01 19:33:26 +02:00
|
|
|
/* in direct mode, can only use SHARE_EXCLUSIVE */
|
|
|
|
if (!(grfMode & STGM_TRANSACTED) && (STGM_SHARE_MODE(grfMode) != STGM_SHARE_EXCLUSIVE))
|
2005-03-09 12:44:59 +01:00
|
|
|
goto end;
|
2005-03-05 11:48:11 +01:00
|
|
|
|
2006-05-01 19:33:26 +02:00
|
|
|
/* but in transacted mode, any share mode is valid */
|
|
|
|
|
1999-03-13 13:48:27 +01:00
|
|
|
/*
|
|
|
|
* Generate a unique name.
|
|
|
|
*/
|
|
|
|
if (pwcsName == 0)
|
|
|
|
{
|
|
|
|
WCHAR tempPath[MAX_PATH];
|
2004-04-20 03:12:17 +02:00
|
|
|
static const WCHAR prefix[] = { 'S', 'T', 'O', 0 };
|
1999-03-13 13:48:27 +01:00
|
|
|
|
|
|
|
memset(tempPath, 0, sizeof(tempPath));
|
|
|
|
memset(tempFileName, 0, sizeof(tempFileName));
|
|
|
|
|
|
|
|
if ((GetTempPathW(MAX_PATH, tempPath)) == 0 )
|
|
|
|
tempPath[0] = '.';
|
|
|
|
|
|
|
|
if (GetTempFileNameW(tempPath, prefix, 0, tempFileName) != 0)
|
|
|
|
pwcsName = tempFileName;
|
|
|
|
else
|
2005-03-09 12:44:59 +01:00
|
|
|
{
|
|
|
|
hr = STG_E_INSUFFICIENTMEMORY;
|
|
|
|
goto end;
|
|
|
|
}
|
2001-03-31 02:51:54 +02:00
|
|
|
|
|
|
|
creationMode = TRUNCATE_EXISTING;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
creationMode = GetCreationModeFromSTGM(grfMode);
|
1999-03-13 13:48:27 +01:00
|
|
|
}
|
|
|
|
|
1999-02-13 13:10:15 +01:00
|
|
|
/*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Interpret the STGM value grfMode
|
1999-02-13 13:10:15 +01:00
|
|
|
*/
|
2008-08-19 06:33:09 +02:00
|
|
|
shareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
|
1999-02-13 13:10:15 +01:00
|
|
|
accessMode = GetAccessModeFromSTGM(grfMode);
|
|
|
|
|
|
|
|
if (grfMode & STGM_DELETEONRELEASE)
|
|
|
|
fileAttributes = FILE_FLAG_RANDOM_ACCESS | FILE_FLAG_DELETE_ON_CLOSE;
|
|
|
|
else
|
|
|
|
fileAttributes = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS;
|
|
|
|
|
2008-08-19 06:33:09 +02:00
|
|
|
if (STGM_SHARE_MODE(grfMode) && !(grfMode & STGM_SHARE_DENY_NONE))
|
|
|
|
FIXME("Storage share mode not implemented.\n");
|
|
|
|
|
1999-02-13 13:10:15 +01:00
|
|
|
if (grfMode & STGM_TRANSACTED)
|
1999-07-04 18:02:24 +02:00
|
|
|
FIXME("Transacted mode not implemented.\n");
|
1999-02-13 13:10:15 +01:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
*ppstgOpen = 0;
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
hFile = CreateFileW(pwcsName,
|
1999-02-13 13:10:15 +01:00
|
|
|
accessMode,
|
|
|
|
shareMode,
|
2005-03-05 11:48:11 +01:00
|
|
|
NULL,
|
1999-02-13 13:10:15 +01:00
|
|
|
creationMode,
|
|
|
|
fileAttributes,
|
2005-03-05 11:48:11 +01:00
|
|
|
0);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2005-01-10 13:26:25 +01:00
|
|
|
if(GetLastError() == ERROR_FILE_EXISTS)
|
2005-03-09 12:44:59 +01:00
|
|
|
hr = STG_E_FILEALREADYEXISTS;
|
|
|
|
else
|
|
|
|
hr = E_FAIL;
|
|
|
|
goto end;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate and initialize the new IStorage32object.
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
newStorage = HeapAlloc(GetProcessHeap(), 0, sizeof(StorageImpl));
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
if (newStorage == 0)
|
2005-03-09 12:44:59 +01:00
|
|
|
{
|
|
|
|
hr = STG_E_INSUFFICIENTMEMORY;
|
|
|
|
goto end;
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
hr = StorageImpl_Construct(
|
1999-01-30 14:24:23 +01:00
|
|
|
newStorage,
|
|
|
|
hFile,
|
2002-01-01 01:13:32 +01:00
|
|
|
pwcsName,
|
1999-05-08 12:05:08 +02:00
|
|
|
NULL,
|
|
|
|
grfMode,
|
2000-02-25 21:58:25 +01:00
|
|
|
TRUE,
|
1999-05-08 12:05:08 +02:00
|
|
|
TRUE);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
if (FAILED(hr))
|
1999-03-17 16:11:27 +01:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, newStorage);
|
2005-03-09 12:44:59 +01:00
|
|
|
goto end;
|
1999-03-17 16:11:27 +01:00
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get an "out" pointer for the caller.
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
hr = StorageBaseImpl_QueryInterface(
|
|
|
|
(IStorage*)newStorage,
|
2009-08-29 14:23:42 +02:00
|
|
|
&IID_IStorage,
|
1999-01-30 14:24:23 +01:00
|
|
|
(void**)ppstgOpen);
|
2005-03-09 12:44:59 +01:00
|
|
|
end:
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("<-- %p r = %08x\n", *ppstgOpen, hr);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2004-05-17 23:08:31 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* StgCreateStorageEx [OLE32.@]
|
|
|
|
*/
|
2004-04-30 20:32:20 +02:00
|
|
|
HRESULT WINAPI StgCreateStorageEx(const WCHAR* pwcsName, DWORD grfMode, DWORD stgfmt, DWORD grfAttrs, STGOPTIONS* pStgOptions, void* reserved, REFIID riid, void** ppObjectOpen)
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%s, %x, %x, %x, %p, %p, %p, %p)\n", debugstr_w(pwcsName),
|
2004-04-30 20:32:20 +02:00
|
|
|
grfMode, stgfmt, grfAttrs, pStgOptions, reserved, riid, ppObjectOpen);
|
2005-05-05 18:44:05 +02:00
|
|
|
|
|
|
|
if (stgfmt != STGFMT_FILE && grfAttrs != 0)
|
|
|
|
{
|
|
|
|
ERR("grfAttrs must be 0 if stgfmt != STGFMT_FILE\n");
|
|
|
|
return STG_E_INVALIDPARAMETER;
|
|
|
|
}
|
|
|
|
|
2006-05-03 23:23:29 +02:00
|
|
|
if (stgfmt == STGFMT_FILE && grfAttrs != 0 && grfAttrs != FILE_FLAG_NO_BUFFERING)
|
2005-05-05 18:44:05 +02:00
|
|
|
{
|
|
|
|
ERR("grfAttrs must be 0 or FILE_FLAG_NO_BUFFERING if stgfmt == STGFMT_FILE\n");
|
|
|
|
return STG_E_INVALIDPARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stgfmt == STGFMT_FILE)
|
|
|
|
{
|
|
|
|
ERR("Cannot use STGFMT_FILE - this is NTFS only\n");
|
|
|
|
return STG_E_INVALIDPARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stgfmt == STGFMT_STORAGE || stgfmt == STGFMT_DOCFILE)
|
|
|
|
{
|
|
|
|
FIXME("Stub: calling StgCreateDocfile, but ignoring pStgOptions and grfAttrs\n");
|
|
|
|
return StgCreateDocfile(pwcsName, grfMode, 0, (IStorage **)ppObjectOpen);
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR("Invalid stgfmt argument\n");
|
|
|
|
return STG_E_INVALIDPARAMETER;
|
2004-04-30 20:32:20 +02:00
|
|
|
}
|
|
|
|
|
2005-03-07 11:59:09 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* StgCreatePropSetStg [OLE32.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI StgCreatePropSetStg(IStorage *pstg, DWORD reserved,
|
|
|
|
IPropertySetStorage **ppPropSetStg)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p, 0x%x, %p)\n", pstg, reserved, ppPropSetStg);
|
2005-03-07 11:59:09 +01:00
|
|
|
if (reserved)
|
|
|
|
hr = STG_E_INVALIDPARAMETER;
|
|
|
|
else
|
|
|
|
hr = StorageBaseImpl_QueryInterface(pstg, &IID_IPropertySetStorage,
|
|
|
|
(void**)ppPropSetStg);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2005-05-06 16:32:30 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* StgOpenStorageEx [OLE32.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI StgOpenStorageEx(const WCHAR* pwcsName, DWORD grfMode, DWORD stgfmt, DWORD grfAttrs, STGOPTIONS* pStgOptions, void* reserved, REFIID riid, void** ppObjectOpen)
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%s, %x, %x, %x, %p, %p, %p, %p)\n", debugstr_w(pwcsName),
|
2005-05-06 16:32:30 +02:00
|
|
|
grfMode, stgfmt, grfAttrs, pStgOptions, reserved, riid, ppObjectOpen);
|
|
|
|
|
|
|
|
if (stgfmt != STGFMT_DOCFILE && grfAttrs != 0)
|
|
|
|
{
|
|
|
|
ERR("grfAttrs must be 0 if stgfmt != STGFMT_DOCFILE\n");
|
|
|
|
return STG_E_INVALIDPARAMETER;
|
|
|
|
}
|
|
|
|
|
2006-07-11 04:38:24 +02:00
|
|
|
switch (stgfmt)
|
2005-05-06 16:32:30 +02:00
|
|
|
{
|
2006-07-11 04:38:24 +02:00
|
|
|
case STGFMT_FILE:
|
2005-05-06 16:32:30 +02:00
|
|
|
ERR("Cannot use STGFMT_FILE - this is NTFS only\n");
|
|
|
|
return STG_E_INVALIDPARAMETER;
|
2006-07-11 04:38:24 +02:00
|
|
|
|
|
|
|
case STGFMT_STORAGE:
|
|
|
|
break;
|
2005-05-06 16:32:30 +02:00
|
|
|
|
2006-07-11 04:38:24 +02:00
|
|
|
case STGFMT_DOCFILE:
|
|
|
|
if (grfAttrs && grfAttrs != FILE_FLAG_NO_BUFFERING)
|
|
|
|
{
|
|
|
|
ERR("grfAttrs must be 0 or FILE_FLAG_NO_BUFFERING if stgfmt == STGFMT_DOCFILE\n");
|
|
|
|
return STG_E_INVALIDPARAMETER;
|
|
|
|
}
|
2005-05-06 16:32:30 +02:00
|
|
|
FIXME("Stub: calling StgOpenStorage, but ignoring pStgOptions and grfAttrs\n");
|
2006-07-11 04:38:24 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STGFMT_ANY:
|
|
|
|
WARN("STGFMT_ANY assuming storage\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return STG_E_INVALIDPARAMETER;
|
2005-05-06 16:32:30 +02:00
|
|
|
}
|
|
|
|
|
2008-11-02 00:25:54 +01:00
|
|
|
return StgOpenStorage(pwcsName, NULL, grfMode, NULL, 0, (IStorage **)ppObjectOpen);
|
2005-05-06 16:32:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/******************************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* StgOpenStorage [OLE32.@]
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
HRESULT WINAPI StgOpenStorage(
|
|
|
|
const OLECHAR *pwcsName,
|
|
|
|
IStorage *pstgPriority,
|
2006-09-22 04:40:49 +02:00
|
|
|
DWORD grfMode,
|
|
|
|
SNB snbExclude,
|
|
|
|
DWORD reserved,
|
|
|
|
IStorage **ppstgOpen)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2006-09-22 04:40:49 +02:00
|
|
|
StorageImpl* newStorage = 0;
|
1999-01-30 14:24:23 +01:00
|
|
|
HRESULT hr = S_OK;
|
2006-09-22 04:40:49 +02:00
|
|
|
HANDLE hFile = 0;
|
1999-02-13 13:10:15 +01:00
|
|
|
DWORD shareMode;
|
|
|
|
DWORD accessMode;
|
2002-01-31 22:01:35 +01:00
|
|
|
WCHAR fullname[MAX_PATH];
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%s, %p, %x, %p, %d, %p)\n",
|
1999-05-02 13:41:10 +02:00
|
|
|
debugstr_w(pwcsName), pstgPriority, grfMode,
|
|
|
|
snbExclude, reserved, ppstgOpen);
|
|
|
|
|
2005-01-11 16:08:08 +01:00
|
|
|
if (pwcsName == 0)
|
|
|
|
{
|
|
|
|
hr = STG_E_INVALIDNAME;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ppstgOpen == 0)
|
2002-01-31 22:01:35 +01:00
|
|
|
{
|
|
|
|
hr = STG_E_INVALIDPOINTER;
|
|
|
|
goto end;
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2005-01-11 16:08:08 +01:00
|
|
|
if (reserved)
|
|
|
|
{
|
|
|
|
hr = STG_E_INVALIDPARAMETER;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2006-04-03 11:52:11 +02:00
|
|
|
if (grfMode & STGM_PRIORITY)
|
|
|
|
{
|
2006-04-18 10:18:51 +02:00
|
|
|
if (grfMode & (STGM_TRANSACTED|STGM_SIMPLE|STGM_NOSCRATCH|STGM_NOSNAPSHOT))
|
|
|
|
return STG_E_INVALIDFLAG;
|
|
|
|
if (grfMode & STGM_DELETEONRELEASE)
|
|
|
|
return STG_E_INVALIDFUNCTION;
|
|
|
|
if(STGM_ACCESS_MODE(grfMode) != STGM_READ)
|
|
|
|
return STG_E_INVALIDFLAG;
|
2006-04-03 11:52:11 +02:00
|
|
|
grfMode &= ~0xf0; /* remove the existing sharing mode */
|
2006-05-03 23:23:12 +02:00
|
|
|
grfMode |= STGM_SHARE_DENY_NONE;
|
|
|
|
|
|
|
|
/* STGM_PRIORITY stops other IStorage objects on the same file from
|
|
|
|
* committing until the STGM_PRIORITY IStorage is closed. it also
|
|
|
|
* stops non-transacted mode StgOpenStorage calls with write access from
|
|
|
|
* succeeding. obviously, both of these cannot be achieved through just
|
|
|
|
* file share flags */
|
|
|
|
FIXME("STGM_PRIORITY mode not implemented correctly\n");
|
2006-04-03 11:52:11 +02:00
|
|
|
}
|
|
|
|
|
2005-01-11 16:08:08 +01:00
|
|
|
/*
|
|
|
|
* Validate the sharing mode
|
|
|
|
*/
|
2006-05-03 23:23:12 +02:00
|
|
|
if (!(grfMode & (STGM_TRANSACTED|STGM_PRIORITY)))
|
2005-09-07 11:22:15 +02:00
|
|
|
switch(STGM_SHARE_MODE(grfMode))
|
|
|
|
{
|
|
|
|
case STGM_SHARE_EXCLUSIVE:
|
|
|
|
case STGM_SHARE_DENY_WRITE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
hr = STG_E_INVALIDFLAG;
|
|
|
|
goto end;
|
|
|
|
}
|
2005-01-11 16:08:08 +01:00
|
|
|
|
|
|
|
if ( FAILED( validateSTGM(grfMode) ) ||
|
|
|
|
(grfMode&STGM_CREATE))
|
2002-01-31 22:01:35 +01:00
|
|
|
{
|
|
|
|
hr = STG_E_INVALIDFLAG;
|
|
|
|
goto end;
|
|
|
|
}
|
1999-02-13 13:10:15 +01:00
|
|
|
|
2005-03-11 14:17:10 +01:00
|
|
|
/* shared reading requires transacted mode */
|
|
|
|
if( STGM_SHARE_MODE(grfMode) == STGM_SHARE_DENY_WRITE &&
|
|
|
|
STGM_ACCESS_MODE(grfMode) == STGM_READWRITE &&
|
|
|
|
!(grfMode&STGM_TRANSACTED) )
|
|
|
|
{
|
|
|
|
hr = STG_E_INVALIDFLAG;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
1999-02-13 13:10:15 +01:00
|
|
|
/*
|
|
|
|
* Interpret the STGM value grfMode
|
|
|
|
*/
|
|
|
|
shareMode = GetShareModeFromSTGM(grfMode);
|
|
|
|
accessMode = GetAccessModeFromSTGM(grfMode);
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
*ppstgOpen = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2007-01-01 05:09:51 +01:00
|
|
|
hFile = CreateFileW( pwcsName,
|
|
|
|
accessMode,
|
|
|
|
shareMode,
|
|
|
|
NULL,
|
|
|
|
OPEN_EXISTING,
|
|
|
|
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
|
|
|
|
0);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
if (hFile==INVALID_HANDLE_VALUE)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2000-02-25 21:58:25 +01:00
|
|
|
DWORD last_error = GetLastError();
|
|
|
|
|
2002-01-31 22:01:35 +01:00
|
|
|
hr = E_FAIL;
|
|
|
|
|
2000-02-25 21:58:25 +01:00
|
|
|
switch (last_error)
|
|
|
|
{
|
|
|
|
case ERROR_FILE_NOT_FOUND:
|
|
|
|
hr = STG_E_FILENOTFOUND;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ERROR_PATH_NOT_FOUND:
|
|
|
|
hr = STG_E_PATHNOTFOUND;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ERROR_ACCESS_DENIED:
|
|
|
|
case ERROR_WRITE_PROTECT:
|
|
|
|
hr = STG_E_ACCESSDENIED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ERROR_SHARING_VIOLATION:
|
|
|
|
hr = STG_E_SHAREVIOLATION;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
hr = E_FAIL;
|
|
|
|
}
|
|
|
|
|
2002-01-31 22:01:35 +01:00
|
|
|
goto end;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
2005-03-11 14:17:10 +01:00
|
|
|
/*
|
|
|
|
* Refuse to open the file if it's too small to be a structured storage file
|
|
|
|
* FIXME: verify the file when reading instead of here
|
|
|
|
*/
|
2007-01-01 05:09:51 +01:00
|
|
|
if (GetFileSize(hFile, NULL) < 0x100)
|
2005-03-11 14:17:10 +01:00
|
|
|
{
|
|
|
|
CloseHandle(hFile);
|
|
|
|
hr = STG_E_FILEALREADYEXISTS;
|
|
|
|
goto end;
|
|
|
|
}
|
2005-01-11 16:08:08 +01:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Allocate and initialize the new IStorage32object.
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
newStorage = HeapAlloc(GetProcessHeap(), 0, sizeof(StorageImpl));
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
if (newStorage == 0)
|
2002-01-31 22:01:35 +01:00
|
|
|
{
|
|
|
|
hr = STG_E_INSUFFICIENTMEMORY;
|
|
|
|
goto end;
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2007-01-01 05:09:51 +01:00
|
|
|
/* Initialize the storage */
|
1999-02-26 12:11:13 +01:00
|
|
|
hr = StorageImpl_Construct(
|
1999-01-30 14:24:23 +01:00
|
|
|
newStorage,
|
|
|
|
hFile,
|
2006-09-22 04:40:49 +02:00
|
|
|
pwcsName,
|
1999-05-08 12:05:08 +02:00
|
|
|
NULL,
|
|
|
|
grfMode,
|
2000-02-25 21:58:25 +01:00
|
|
|
TRUE,
|
2007-01-01 05:09:51 +01:00
|
|
|
FALSE );
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
if (FAILED(hr))
|
1999-03-17 16:11:27 +01:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, newStorage);
|
2001-04-16 20:57:18 +02:00
|
|
|
/*
|
|
|
|
* According to the docs if the file is not a storage, return STG_E_FILEALREADYEXISTS
|
|
|
|
*/
|
|
|
|
if(hr == STG_E_INVALIDHEADER)
|
2002-01-31 22:01:35 +01:00
|
|
|
hr = STG_E_FILEALREADYEXISTS;
|
|
|
|
goto end;
|
1999-03-17 16:11:27 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-01-31 22:01:35 +01:00
|
|
|
/* prepare the file name string given in lieu of the root property name */
|
|
|
|
GetFullPathNameW(pwcsName, MAX_PATH, fullname, NULL);
|
2009-11-11 17:31:55 +01:00
|
|
|
memcpy(newStorage->filename, fullname, DIRENTRY_NAME_BUFFER_LEN);
|
|
|
|
newStorage->filename[DIRENTRY_NAME_BUFFER_LEN-1] = '\0';
|
2002-01-31 22:01:35 +01:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/*
|
|
|
|
* Get an "out" pointer for the caller.
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
hr = StorageBaseImpl_QueryInterface(
|
|
|
|
(IStorage*)newStorage,
|
2009-08-29 14:23:42 +02:00
|
|
|
&IID_IStorage,
|
1999-01-30 14:24:23 +01:00
|
|
|
(void**)ppstgOpen);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-01-31 22:01:35 +01:00
|
|
|
end:
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("<-- %08x, IStorage %p\n", hr, ppstgOpen ? *ppstgOpen : NULL);
|
1999-01-30 14:24:23 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* StgCreateDocfileOnILockBytes [OLE32.@]
|
1999-05-08 12:05:08 +02:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI StgCreateDocfileOnILockBytes(
|
|
|
|
ILockBytes *plkbyt,
|
|
|
|
DWORD grfMode,
|
|
|
|
DWORD reserved,
|
|
|
|
IStorage** ppstgOpen)
|
|
|
|
{
|
|
|
|
StorageImpl* newStorage = 0;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
if ((ppstgOpen == 0) || (plkbyt == 0))
|
|
|
|
return STG_E_INVALIDPOINTER;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate and initialize the new IStorage object.
|
|
|
|
*/
|
|
|
|
newStorage = HeapAlloc(GetProcessHeap(), 0, sizeof(StorageImpl));
|
|
|
|
|
|
|
|
if (newStorage == 0)
|
|
|
|
return STG_E_INSUFFICIENTMEMORY;
|
|
|
|
|
|
|
|
hr = StorageImpl_Construct(
|
|
|
|
newStorage,
|
|
|
|
0,
|
2002-01-01 01:13:32 +01:00
|
|
|
0,
|
1999-05-08 12:05:08 +02:00
|
|
|
plkbyt,
|
|
|
|
grfMode,
|
2000-02-25 21:58:25 +01:00
|
|
|
FALSE,
|
|
|
|
TRUE);
|
1999-05-08 12:05:08 +02:00
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, newStorage);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get an "out" pointer for the caller.
|
|
|
|
*/
|
|
|
|
hr = StorageBaseImpl_QueryInterface(
|
|
|
|
(IStorage*)newStorage,
|
2009-08-29 14:23:42 +02:00
|
|
|
&IID_IStorage,
|
1999-05-08 12:05:08 +02:00
|
|
|
(void**)ppstgOpen);
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
return hr;
|
1999-05-08 12:05:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* StgOpenStorageOnILockBytes [OLE32.@]
|
1999-05-08 12:05:08 +02:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI StgOpenStorageOnILockBytes(
|
|
|
|
ILockBytes *plkbyt,
|
|
|
|
IStorage *pstgPriority,
|
|
|
|
DWORD grfMode,
|
|
|
|
SNB snbExclude,
|
|
|
|
DWORD reserved,
|
|
|
|
IStorage **ppstgOpen)
|
|
|
|
{
|
|
|
|
StorageImpl* newStorage = 0;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
if ((plkbyt == 0) || (ppstgOpen == 0))
|
|
|
|
return STG_E_INVALIDPOINTER;
|
|
|
|
|
|
|
|
if ( FAILED( validateSTGM(grfMode) ))
|
|
|
|
return STG_E_INVALIDFLAG;
|
|
|
|
|
|
|
|
*ppstgOpen = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate and initialize the new IStorage object.
|
|
|
|
*/
|
|
|
|
newStorage = HeapAlloc(GetProcessHeap(), 0, sizeof(StorageImpl));
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-05-08 12:05:08 +02:00
|
|
|
if (newStorage == 0)
|
|
|
|
return STG_E_INSUFFICIENTMEMORY;
|
|
|
|
|
|
|
|
hr = StorageImpl_Construct(
|
|
|
|
newStorage,
|
|
|
|
0,
|
2002-08-16 21:55:14 +02:00
|
|
|
0,
|
1999-05-08 12:05:08 +02:00
|
|
|
plkbyt,
|
|
|
|
grfMode,
|
2000-02-25 21:58:25 +01:00
|
|
|
FALSE,
|
1999-05-08 12:05:08 +02:00
|
|
|
FALSE);
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, newStorage);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get an "out" pointer for the caller.
|
|
|
|
*/
|
|
|
|
hr = StorageBaseImpl_QueryInterface(
|
|
|
|
(IStorage*)newStorage,
|
2009-08-29 14:23:42 +02:00
|
|
|
&IID_IStorage,
|
1999-05-08 12:05:08 +02:00
|
|
|
(void**)ppstgOpen);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
1999-11-21 01:49:20 +01:00
|
|
|
/******************************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* StgSetTimes [ole32.@]
|
|
|
|
* StgSetTimes [OLE32.@]
|
1999-11-21 01:49:20 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2005-03-04 11:48:17 +01:00
|
|
|
HRESULT WINAPI StgSetTimes(OLECHAR const *str, FILETIME const *pctime,
|
|
|
|
FILETIME const *patime, FILETIME const *pmtime)
|
1999-11-21 01:49:20 +01:00
|
|
|
{
|
2005-03-04 11:48:17 +01:00
|
|
|
IStorage *stg = NULL;
|
|
|
|
HRESULT r;
|
|
|
|
|
|
|
|
TRACE("%s %p %p %p\n", debugstr_w(str), pctime, patime, pmtime);
|
|
|
|
|
|
|
|
r = StgOpenStorage(str, NULL, STGM_READWRITE | STGM_SHARE_DENY_WRITE,
|
|
|
|
0, 0, &stg);
|
|
|
|
if( SUCCEEDED(r) )
|
|
|
|
{
|
|
|
|
r = IStorage_SetElementTimes(stg, NULL, pctime, patime, pmtime);
|
|
|
|
IStorage_Release(stg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
1999-11-21 01:49:20 +01:00
|
|
|
}
|
|
|
|
|
1999-05-08 12:05:08 +02:00
|
|
|
/******************************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* StgIsStorageILockBytes [OLE32.@]
|
1999-05-08 12:05:08 +02:00
|
|
|
*
|
|
|
|
* Determines if the ILockBytes contains a storage object.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI StgIsStorageILockBytes(ILockBytes *plkbyt)
|
|
|
|
{
|
|
|
|
BYTE sig[8];
|
|
|
|
ULARGE_INTEGER offset;
|
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
offset.u.HighPart = 0;
|
|
|
|
offset.u.LowPart = 0;
|
1999-05-08 12:05:08 +02:00
|
|
|
|
|
|
|
ILockBytes_ReadAt(plkbyt, offset, sig, sizeof(sig), NULL);
|
|
|
|
|
|
|
|
if (memcmp(sig, STORAGE_magic, sizeof(STORAGE_magic)) == 0)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* WriteClassStg [OLE32.@]
|
1999-01-30 14:24:23 +01:00
|
|
|
*
|
|
|
|
* This method will store the specified CLSID in the specified storage object
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
HRESULT WINAPI WriteClassStg(IStorage* pStg, REFCLSID rclsid)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
HRESULT hRes;
|
|
|
|
|
2005-09-22 12:34:40 +02:00
|
|
|
if(!pStg)
|
|
|
|
return E_INVALIDARG;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2009-01-14 20:31:06 +01:00
|
|
|
if(!rclsid)
|
|
|
|
return STG_E_INVALIDPOINTER;
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
hRes = IStorage_SetClass(pStg, rclsid);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
return hRes;
|
|
|
|
}
|
|
|
|
|
2000-04-06 22:21:16 +02:00
|
|
|
/***********************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* ReadClassStg (OLE32.@)
|
1999-03-23 14:48:56 +01:00
|
|
|
*
|
2005-11-09 11:30:57 +01:00
|
|
|
* This method reads the CLSID previously written to a storage object with
|
|
|
|
* the WriteClassStg.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pstg [I] IStorage pointer
|
|
|
|
* pclsid [O] Pointer to where the CLSID is written
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK.
|
|
|
|
* Failure: HRESULT code.
|
1999-03-23 14:48:56 +01:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI ReadClassStg(IStorage *pstg,CLSID *pclsid){
|
|
|
|
|
|
|
|
STATSTG pstatstg;
|
|
|
|
HRESULT hRes;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-09-22 12:34:40 +02:00
|
|
|
TRACE("(%p, %p)\n", pstg, pclsid);
|
|
|
|
|
|
|
|
if(!pstg || !pclsid)
|
|
|
|
return E_INVALIDARG;
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* read a STATSTG structure (contains the clsid) from the storage
|
|
|
|
*/
|
2009-04-28 13:38:29 +02:00
|
|
|
hRes=IStorage_Stat(pstg,&pstatstg,STATFLAG_NONAME);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
if(SUCCEEDED(hRes))
|
|
|
|
*pclsid=pstatstg.clsid;
|
|
|
|
|
|
|
|
return hRes;
|
|
|
|
}
|
|
|
|
|
2000-04-06 22:21:16 +02:00
|
|
|
/***********************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* OleLoadFromStream (OLE32.@)
|
1999-03-23 14:48:56 +01:00
|
|
|
*
|
|
|
|
* This function loads an object from stream
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI OleLoadFromStream(IStream *pStm,REFIID iidInterface,void** ppvObj)
|
|
|
|
{
|
2000-10-28 02:30:42 +02:00
|
|
|
CLSID clsid;
|
|
|
|
HRESULT res;
|
|
|
|
LPPERSISTSTREAM xstm;
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2000-10-28 02:30:42 +02:00
|
|
|
TRACE("(%p,%s,%p)\n",pStm,debugstr_guid(iidInterface),ppvObj);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
res=ReadClassStm(pStm,&clsid);
|
2008-10-08 01:32:53 +02:00
|
|
|
if (FAILED(res))
|
2000-10-28 02:30:42 +02:00
|
|
|
return res;
|
|
|
|
res=CoCreateInstance(&clsid,NULL,CLSCTX_INPROC_SERVER,iidInterface,ppvObj);
|
2008-10-08 01:32:53 +02:00
|
|
|
if (FAILED(res))
|
2000-10-28 02:30:42 +02:00
|
|
|
return res;
|
2004-05-21 22:52:57 +02:00
|
|
|
res=IUnknown_QueryInterface((IUnknown*)*ppvObj,&IID_IPersistStream,(LPVOID*)&xstm);
|
2008-10-08 01:32:53 +02:00
|
|
|
if (FAILED(res)) {
|
2000-10-28 02:30:42 +02:00
|
|
|
IUnknown_Release((IUnknown*)*ppvObj);
|
|
|
|
return res;
|
1999-03-23 14:48:56 +01:00
|
|
|
}
|
2000-10-28 02:30:42 +02:00
|
|
|
res=IPersistStream_Load(xstm,pStm);
|
|
|
|
IPersistStream_Release(xstm);
|
|
|
|
/* FIXME: all refcounts ok at this point? I think they should be:
|
|
|
|
* pStm : unchanged
|
|
|
|
* ppvObj : 1
|
|
|
|
* xstm : 0 (released)
|
|
|
|
*/
|
1999-03-23 14:48:56 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2000-04-06 22:21:16 +02:00
|
|
|
/***********************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* OleSaveToStream (OLE32.@)
|
1999-03-23 14:48:56 +01:00
|
|
|
*
|
2000-04-06 22:21:16 +02:00
|
|
|
* This function saves an object with the IPersistStream interface on it
|
|
|
|
* to the specified stream.
|
1999-03-23 14:48:56 +01:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI OleSaveToStream(IPersistStream *pPStm,IStream *pStm)
|
|
|
|
{
|
|
|
|
|
|
|
|
CLSID clsid;
|
|
|
|
HRESULT res;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p,%p)\n",pPStm,pStm);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
res=IPersistStream_GetClassID(pPStm,&clsid);
|
|
|
|
|
|
|
|
if (SUCCEEDED(res)){
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
res=WriteClassStm(pStm,&clsid);
|
|
|
|
|
|
|
|
if (SUCCEEDED(res))
|
|
|
|
|
2000-03-08 19:49:36 +01:00
|
|
|
res=IPersistStream_Save(pPStm,pStm,TRUE);
|
1999-03-23 14:48:56 +01:00
|
|
|
}
|
|
|
|
|
2000-03-08 19:49:36 +01:00
|
|
|
TRACE("Finished Save\n");
|
1999-03-23 14:48:56 +01:00
|
|
|
return res;
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
1999-02-13 13:10:15 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* This method validate a STGM parameter that can contain the values below
|
|
|
|
*
|
2005-03-05 11:48:11 +01:00
|
|
|
* The stgm modes in 0x0000ffff are not bit masks, but distinct 4 bit values.
|
|
|
|
* The stgm values contained in 0xffff0000 are bitmasks.
|
|
|
|
*
|
1999-02-13 13:10:15 +01:00
|
|
|
* STGM_DIRECT 0x00000000
|
|
|
|
* STGM_TRANSACTED 0x00010000
|
|
|
|
* STGM_SIMPLE 0x08000000
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
1999-02-13 13:10:15 +01:00
|
|
|
* STGM_READ 0x00000000
|
|
|
|
* STGM_WRITE 0x00000001
|
|
|
|
* STGM_READWRITE 0x00000002
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
1999-02-13 13:10:15 +01:00
|
|
|
* STGM_SHARE_DENY_NONE 0x00000040
|
|
|
|
* STGM_SHARE_DENY_READ 0x00000030
|
|
|
|
* STGM_SHARE_DENY_WRITE 0x00000020
|
|
|
|
* STGM_SHARE_EXCLUSIVE 0x00000010
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
1999-02-13 13:10:15 +01:00
|
|
|
* STGM_PRIORITY 0x00040000
|
|
|
|
* STGM_DELETEONRELEASE 0x04000000
|
|
|
|
*
|
|
|
|
* STGM_CREATE 0x00001000
|
|
|
|
* STGM_CONVERT 0x00020000
|
|
|
|
* STGM_FAILIFTHERE 0x00000000
|
|
|
|
*
|
|
|
|
* STGM_NOSCRATCH 0x00100000
|
|
|
|
* STGM_NOSNAPSHOT 0x00200000
|
|
|
|
*/
|
|
|
|
static HRESULT validateSTGM(DWORD stgm)
|
|
|
|
{
|
2005-03-05 11:48:11 +01:00
|
|
|
DWORD access = STGM_ACCESS_MODE(stgm);
|
|
|
|
DWORD share = STGM_SHARE_MODE(stgm);
|
|
|
|
DWORD create = STGM_CREATE_MODE(stgm);
|
1999-02-13 13:10:15 +01:00
|
|
|
|
2005-03-05 11:48:11 +01:00
|
|
|
if (stgm&~STGM_KNOWN_FLAGS)
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
ERR("unknown flags %08x\n", stgm);
|
2005-03-05 11:48:11 +01:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
1999-02-13 13:10:15 +01:00
|
|
|
|
2005-03-05 11:48:11 +01:00
|
|
|
switch (access)
|
|
|
|
{
|
|
|
|
case STGM_READ:
|
|
|
|
case STGM_WRITE:
|
|
|
|
case STGM_READWRITE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
1999-02-13 13:10:15 +01:00
|
|
|
|
2005-03-05 11:48:11 +01:00
|
|
|
switch (share)
|
|
|
|
{
|
|
|
|
case STGM_SHARE_DENY_NONE:
|
|
|
|
case STGM_SHARE_DENY_READ:
|
|
|
|
case STGM_SHARE_DENY_WRITE:
|
|
|
|
case STGM_SHARE_EXCLUSIVE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-03-05 11:48:11 +01:00
|
|
|
switch (create)
|
|
|
|
{
|
|
|
|
case STGM_CREATE:
|
|
|
|
case STGM_FAILIFTHERE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
1999-02-13 13:10:15 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
1999-02-13 13:10:15 +01:00
|
|
|
* STGM_DIRECT | STGM_TRANSACTED | STGM_SIMPLE
|
|
|
|
*/
|
2005-03-05 11:48:11 +01:00
|
|
|
if ( (stgm & STGM_TRANSACTED) && (stgm & STGM_SIMPLE) )
|
1999-02-13 13:10:15 +01:00
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* STGM_CREATE | STGM_CONVERT
|
|
|
|
* if both are false, STGM_FAILIFTHERE is set to TRUE
|
|
|
|
*/
|
2005-03-05 11:48:11 +01:00
|
|
|
if ( create == STGM_CREATE && (stgm & STGM_CONVERT) )
|
1999-02-13 13:10:15 +01:00
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* STGM_NOSCRATCH requires STGM_TRANSACTED
|
|
|
|
*/
|
2005-03-11 14:17:10 +01:00
|
|
|
if ( (stgm & STGM_NOSCRATCH) && !(stgm & STGM_TRANSACTED) )
|
1999-02-13 13:10:15 +01:00
|
|
|
return E_FAIL;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-02-13 13:10:15 +01:00
|
|
|
/*
|
2002-06-01 01:06:46 +02:00
|
|
|
* STGM_NOSNAPSHOT requires STGM_TRANSACTED and
|
1999-02-13 13:10:15 +01:00
|
|
|
* not STGM_SHARE_EXCLUSIVE or STGM_SHARE_DENY_WRITE`
|
|
|
|
*/
|
2005-03-05 11:48:11 +01:00
|
|
|
if ( (stgm & STGM_NOSNAPSHOT) &&
|
|
|
|
(!(stgm & STGM_TRANSACTED) ||
|
|
|
|
share == STGM_SHARE_EXCLUSIVE ||
|
|
|
|
share == STGM_SHARE_DENY_WRITE) )
|
1999-02-13 13:10:15 +01:00
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* GetShareModeFromSTGM
|
|
|
|
*
|
|
|
|
* This method will return a share mode flag from a STGM value.
|
2002-06-01 01:06:46 +02:00
|
|
|
* The STGM value is assumed valid.
|
1999-02-13 13:10:15 +01:00
|
|
|
*/
|
|
|
|
static DWORD GetShareModeFromSTGM(DWORD stgm)
|
|
|
|
{
|
2005-03-05 11:48:11 +01:00
|
|
|
switch (STGM_SHARE_MODE(stgm))
|
|
|
|
{
|
|
|
|
case STGM_SHARE_DENY_NONE:
|
|
|
|
return FILE_SHARE_READ | FILE_SHARE_WRITE;
|
|
|
|
case STGM_SHARE_DENY_READ:
|
|
|
|
return FILE_SHARE_WRITE;
|
|
|
|
case STGM_SHARE_DENY_WRITE:
|
|
|
|
return FILE_SHARE_READ;
|
|
|
|
case STGM_SHARE_EXCLUSIVE:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ERR("Invalid share mode!\n");
|
|
|
|
assert(0);
|
|
|
|
return 0;
|
1999-02-13 13:10:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* GetAccessModeFromSTGM
|
|
|
|
*
|
|
|
|
* This method will return an access mode flag from a STGM value.
|
|
|
|
* The STGM value is assumed valid.
|
|
|
|
*/
|
|
|
|
static DWORD GetAccessModeFromSTGM(DWORD stgm)
|
|
|
|
{
|
2005-03-05 11:48:11 +01:00
|
|
|
switch (STGM_ACCESS_MODE(stgm))
|
|
|
|
{
|
|
|
|
case STGM_READ:
|
|
|
|
return GENERIC_READ;
|
|
|
|
case STGM_WRITE:
|
|
|
|
case STGM_READWRITE:
|
|
|
|
return GENERIC_READ | GENERIC_WRITE;
|
|
|
|
}
|
|
|
|
ERR("Invalid access mode!\n");
|
|
|
|
assert(0);
|
|
|
|
return 0;
|
1999-02-13 13:10:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* GetCreationModeFromSTGM
|
|
|
|
*
|
|
|
|
* This method will return a creation mode flag from a STGM value.
|
|
|
|
* The STGM value is assumed valid.
|
|
|
|
*/
|
|
|
|
static DWORD GetCreationModeFromSTGM(DWORD stgm)
|
|
|
|
{
|
2005-03-05 11:48:11 +01:00
|
|
|
switch(STGM_CREATE_MODE(stgm))
|
|
|
|
{
|
|
|
|
case STGM_CREATE:
|
1999-02-28 20:56:59 +01:00
|
|
|
return CREATE_ALWAYS;
|
2005-03-05 11:48:11 +01:00
|
|
|
case STGM_CONVERT:
|
1999-07-04 18:02:24 +02:00
|
|
|
FIXME("STGM_CONVERT not implemented!\n");
|
1999-02-28 20:56:59 +01:00
|
|
|
return CREATE_NEW;
|
2005-03-05 11:48:11 +01:00
|
|
|
case STGM_FAILIFTHERE:
|
|
|
|
return CREATE_NEW;
|
1999-02-13 13:10:15 +01:00
|
|
|
}
|
2005-03-05 11:48:11 +01:00
|
|
|
ERR("Invalid create mode!\n");
|
|
|
|
assert(0);
|
|
|
|
return 0;
|
1999-02-13 13:10:15 +01:00
|
|
|
}
|
2000-02-25 21:58:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* OLECONVERT_LoadOLE10 [Internal]
|
2000-02-25 21:58:25 +01:00
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Loads the OLE10 STREAM to memory
|
2000-02-25 21:58:25 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pOleStream [I] The OLESTREAM
|
|
|
|
* pData [I] Data Structure for the OLESTREAM Data
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK
|
|
|
|
* Failure: CONVERT10_E_OLESTREAM_GET for invalid Get
|
2008-04-09 21:33:37 +02:00
|
|
|
* CONVERT10_E_OLESTREAM_FMT if the OLEID is invalid
|
2000-02-25 21:58:25 +01:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* This function is used by OleConvertOLESTREAMToIStorage only.
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2000-02-25 21:58:25 +01:00
|
|
|
* Memory allocated for pData must be freed by the caller
|
|
|
|
*/
|
2005-07-24 19:11:59 +02:00
|
|
|
static HRESULT OLECONVERT_LoadOLE10(LPOLESTREAM pOleStream, OLECONVERT_OLESTREAM_DATA *pData, BOOL bStrem1)
|
2000-02-25 21:58:25 +01:00
|
|
|
{
|
|
|
|
DWORD dwSize;
|
|
|
|
HRESULT hRes = S_OK;
|
2000-02-29 23:03:14 +01:00
|
|
|
int nTryCnt=0;
|
|
|
|
int max_try = 6;
|
|
|
|
|
2000-02-25 21:58:25 +01:00
|
|
|
pData->pData = NULL;
|
2008-11-02 00:25:54 +01:00
|
|
|
pData->pstrOleObjFileName = NULL;
|
2000-02-25 21:58:25 +01:00
|
|
|
|
2000-02-29 23:03:14 +01:00
|
|
|
for( nTryCnt=0;nTryCnt < max_try; nTryCnt++)
|
|
|
|
{
|
2000-02-25 21:58:25 +01:00
|
|
|
/* Get the OleID */
|
|
|
|
dwSize = pOleStream->lpstbl->Get(pOleStream, (void *)&(pData->dwOleID), sizeof(pData->dwOleID));
|
|
|
|
if(dwSize != sizeof(pData->dwOleID))
|
|
|
|
{
|
|
|
|
hRes = CONVERT10_E_OLESTREAM_GET;
|
|
|
|
}
|
|
|
|
else if(pData->dwOleID != OLESTREAM_ID)
|
|
|
|
{
|
|
|
|
hRes = CONVERT10_E_OLESTREAM_FMT;
|
|
|
|
}
|
2000-02-29 23:03:14 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
hRes = S_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-02-25 21:58:25 +01:00
|
|
|
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
2008-11-25 17:42:38 +01:00
|
|
|
/* Get the TypeID... more info needed for this field */
|
2000-02-25 21:58:25 +01:00
|
|
|
dwSize = pOleStream->lpstbl->Get(pOleStream, (void *)&(pData->dwTypeID), sizeof(pData->dwTypeID));
|
|
|
|
if(dwSize != sizeof(pData->dwTypeID))
|
|
|
|
{
|
|
|
|
hRes = CONVERT10_E_OLESTREAM_GET;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
|
|
|
if(pData->dwTypeID != 0)
|
|
|
|
{
|
2003-07-09 04:52:57 +02:00
|
|
|
/* Get the length of the OleTypeName */
|
2000-02-25 21:58:25 +01:00
|
|
|
dwSize = pOleStream->lpstbl->Get(pOleStream, (void *) &(pData->dwOleTypeNameLength), sizeof(pData->dwOleTypeNameLength));
|
|
|
|
if(dwSize != sizeof(pData->dwOleTypeNameLength))
|
|
|
|
{
|
|
|
|
hRes = CONVERT10_E_OLESTREAM_GET;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
|
|
|
if(pData->dwOleTypeNameLength > 0)
|
|
|
|
{
|
|
|
|
/* Get the OleTypeName */
|
2009-02-11 10:48:38 +01:00
|
|
|
dwSize = pOleStream->lpstbl->Get(pOleStream, pData->strOleTypeName, pData->dwOleTypeNameLength);
|
2000-02-25 21:58:25 +01:00
|
|
|
if(dwSize != pData->dwOleTypeNameLength)
|
|
|
|
{
|
|
|
|
hRes = CONVERT10_E_OLESTREAM_GET;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-02-29 23:03:14 +01:00
|
|
|
if(bStrem1)
|
|
|
|
{
|
|
|
|
dwSize = pOleStream->lpstbl->Get(pOleStream, (void *)&(pData->dwOleObjFileNameLength), sizeof(pData->dwOleObjFileNameLength));
|
|
|
|
if(dwSize != sizeof(pData->dwOleObjFileNameLength))
|
|
|
|
{
|
|
|
|
hRes = CONVERT10_E_OLESTREAM_GET;
|
|
|
|
}
|
2000-02-25 21:58:25 +01:00
|
|
|
if(hRes == S_OK)
|
2000-02-29 23:03:14 +01:00
|
|
|
{
|
2000-03-24 21:42:08 +01:00
|
|
|
if(pData->dwOleObjFileNameLength < 1) /* there is no file name exist */
|
2000-02-29 23:03:14 +01:00
|
|
|
pData->dwOleObjFileNameLength = sizeof(pData->dwOleObjFileNameLength);
|
2005-03-21 12:25:13 +01:00
|
|
|
pData->pstrOleObjFileName = HeapAlloc(GetProcessHeap(), 0, pData->dwOleObjFileNameLength);
|
2000-02-29 23:03:14 +01:00
|
|
|
if(pData->pstrOleObjFileName)
|
|
|
|
{
|
2009-02-11 10:48:38 +01:00
|
|
|
dwSize = pOleStream->lpstbl->Get(pOleStream, pData->pstrOleObjFileName, pData->dwOleObjFileNameLength);
|
2000-02-29 23:03:14 +01:00
|
|
|
if(dwSize != pData->dwOleObjFileNameLength)
|
|
|
|
{
|
|
|
|
hRes = CONVERT10_E_OLESTREAM_GET;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hRes = CONVERT10_E_OLESTREAM_GET;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2000-02-25 21:58:25 +01:00
|
|
|
{
|
|
|
|
/* Get the Width of the Metafile */
|
|
|
|
dwSize = pOleStream->lpstbl->Get(pOleStream, (void *)&(pData->dwMetaFileWidth), sizeof(pData->dwMetaFileWidth));
|
|
|
|
if(dwSize != sizeof(pData->dwMetaFileWidth))
|
|
|
|
{
|
|
|
|
hRes = CONVERT10_E_OLESTREAM_GET;
|
|
|
|
}
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
|
|
|
/* Get the Height of the Metafile */
|
|
|
|
dwSize = pOleStream->lpstbl->Get(pOleStream, (void *)&(pData->dwMetaFileHeight), sizeof(pData->dwMetaFileHeight));
|
|
|
|
if(dwSize != sizeof(pData->dwMetaFileHeight))
|
|
|
|
{
|
|
|
|
hRes = CONVERT10_E_OLESTREAM_GET;
|
|
|
|
}
|
|
|
|
}
|
2000-02-29 23:03:14 +01:00
|
|
|
}
|
2000-02-25 21:58:25 +01:00
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
2003-07-09 04:52:57 +02:00
|
|
|
/* Get the Length of the Data */
|
2000-02-25 21:58:25 +01:00
|
|
|
dwSize = pOleStream->lpstbl->Get(pOleStream, (void *)&(pData->dwDataLength), sizeof(pData->dwDataLength));
|
|
|
|
if(dwSize != sizeof(pData->dwDataLength))
|
|
|
|
{
|
|
|
|
hRes = CONVERT10_E_OLESTREAM_GET;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-09 21:33:37 +02:00
|
|
|
if(hRes == S_OK) /* I don't know what this 8 byte information is. We have to figure out */
|
2000-02-29 23:03:14 +01:00
|
|
|
{
|
2000-03-24 21:42:08 +01:00
|
|
|
if(!bStrem1) /* if it is a second OLE stream data */
|
2000-02-29 23:03:14 +01:00
|
|
|
{
|
|
|
|
pData->dwDataLength -= 8;
|
2009-02-11 10:48:38 +01:00
|
|
|
dwSize = pOleStream->lpstbl->Get(pOleStream, pData->strUnknown, sizeof(pData->strUnknown));
|
2000-02-29 23:03:14 +01:00
|
|
|
if(dwSize != sizeof(pData->strUnknown))
|
|
|
|
{
|
|
|
|
hRes = CONVERT10_E_OLESTREAM_GET;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-02-25 21:58:25 +01:00
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
|
|
|
if(pData->dwDataLength > 0)
|
|
|
|
{
|
2005-03-21 12:25:13 +01:00
|
|
|
pData->pData = HeapAlloc(GetProcessHeap(),0,pData->dwDataLength);
|
2000-02-25 21:58:25 +01:00
|
|
|
|
|
|
|
/* Get Data (ex. IStorage, Metafile, or BMP) */
|
|
|
|
if(pData->pData)
|
|
|
|
{
|
|
|
|
dwSize = pOleStream->lpstbl->Get(pOleStream, (void *)pData->pData, pData->dwDataLength);
|
|
|
|
if(dwSize != pData->dwDataLength)
|
|
|
|
{
|
|
|
|
hRes = CONVERT10_E_OLESTREAM_GET;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hRes = CONVERT10_E_OLESTREAM_GET;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return hRes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* OLECONVERT_SaveOLE10 [Internal]
|
2000-02-25 21:58:25 +01:00
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Saves the OLE10 STREAM From memory
|
2000-02-25 21:58:25 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pData [I] Data Structure for the OLESTREAM Data
|
|
|
|
* pOleStream [I] The OLESTREAM to save
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK
|
|
|
|
* Failure: CONVERT10_E_OLESTREAM_PUT for invalid Put
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* This function is used by OleConvertIStorageToOLESTREAM only.
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2000-02-25 21:58:25 +01:00
|
|
|
*/
|
2005-07-24 19:11:59 +02:00
|
|
|
static HRESULT OLECONVERT_SaveOLE10(OLECONVERT_OLESTREAM_DATA *pData, LPOLESTREAM pOleStream)
|
2000-02-25 21:58:25 +01:00
|
|
|
{
|
|
|
|
DWORD dwSize;
|
|
|
|
HRESULT hRes = S_OK;
|
|
|
|
|
|
|
|
|
|
|
|
/* Set the OleID */
|
|
|
|
dwSize = pOleStream->lpstbl->Put(pOleStream, (void *)&(pData->dwOleID), sizeof(pData->dwOleID));
|
|
|
|
if(dwSize != sizeof(pData->dwOleID))
|
|
|
|
{
|
|
|
|
hRes = CONVERT10_E_OLESTREAM_PUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
|
|
|
/* Set the TypeID */
|
|
|
|
dwSize = pOleStream->lpstbl->Put(pOleStream, (void *)&(pData->dwTypeID), sizeof(pData->dwTypeID));
|
|
|
|
if(dwSize != sizeof(pData->dwTypeID))
|
|
|
|
{
|
|
|
|
hRes = CONVERT10_E_OLESTREAM_PUT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pData->dwOleID == OLESTREAM_ID && pData->dwTypeID != 0 && hRes == S_OK)
|
|
|
|
{
|
2003-07-09 04:52:57 +02:00
|
|
|
/* Set the Length of the OleTypeName */
|
2000-02-25 21:58:25 +01:00
|
|
|
dwSize = pOleStream->lpstbl->Put(pOleStream, (void *)&(pData->dwOleTypeNameLength), sizeof(pData->dwOleTypeNameLength));
|
|
|
|
if(dwSize != sizeof(pData->dwOleTypeNameLength))
|
|
|
|
{
|
|
|
|
hRes = CONVERT10_E_OLESTREAM_PUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
|
|
|
if(pData->dwOleTypeNameLength > 0)
|
|
|
|
{
|
|
|
|
/* Set the OleTypeName */
|
2009-02-11 10:48:38 +01:00
|
|
|
dwSize = pOleStream->lpstbl->Put(pOleStream, pData->strOleTypeName, pData->dwOleTypeNameLength);
|
2000-02-25 21:58:25 +01:00
|
|
|
if(dwSize != pData->dwOleTypeNameLength)
|
|
|
|
{
|
|
|
|
hRes = CONVERT10_E_OLESTREAM_PUT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
|
|
|
/* Set the width of the Metafile */
|
|
|
|
dwSize = pOleStream->lpstbl->Put(pOleStream, (void *)&(pData->dwMetaFileWidth), sizeof(pData->dwMetaFileWidth));
|
|
|
|
if(dwSize != sizeof(pData->dwMetaFileWidth))
|
|
|
|
{
|
|
|
|
hRes = CONVERT10_E_OLESTREAM_PUT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
|
|
|
/* Set the height of the Metafile */
|
|
|
|
dwSize = pOleStream->lpstbl->Put(pOleStream, (void *)&(pData->dwMetaFileHeight), sizeof(pData->dwMetaFileHeight));
|
|
|
|
if(dwSize != sizeof(pData->dwMetaFileHeight))
|
|
|
|
{
|
|
|
|
hRes = CONVERT10_E_OLESTREAM_PUT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
2003-07-09 04:52:57 +02:00
|
|
|
/* Set the length of the Data */
|
2000-02-25 21:58:25 +01:00
|
|
|
dwSize = pOleStream->lpstbl->Put(pOleStream, (void *)&(pData->dwDataLength), sizeof(pData->dwDataLength));
|
|
|
|
if(dwSize != sizeof(pData->dwDataLength))
|
|
|
|
{
|
|
|
|
hRes = CONVERT10_E_OLESTREAM_PUT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
|
|
|
if(pData->dwDataLength > 0)
|
|
|
|
{
|
|
|
|
/* Set the Data (eg. IStorage, Metafile, Bitmap) */
|
|
|
|
dwSize = pOleStream->lpstbl->Put(pOleStream, (void *) pData->pData, pData->dwDataLength);
|
|
|
|
if(dwSize != pData->dwDataLength)
|
|
|
|
{
|
|
|
|
hRes = CONVERT10_E_OLESTREAM_PUT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return hRes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* OLECONVERT_GetOLE20FromOLE10[Internal]
|
2000-02-25 21:58:25 +01:00
|
|
|
*
|
|
|
|
* This function copies OLE10 Data (the IStorage in the OLESTREAM) to disk,
|
2002-06-01 01:06:46 +02:00
|
|
|
* opens it, and copies the content to the dest IStorage for
|
2000-02-25 21:58:25 +01:00
|
|
|
* OleConvertOLESTREAMToIStorage
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2000-02-25 21:58:25 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pDestStorage [I] The IStorage to copy the data to
|
|
|
|
* pBuffer [I] Buffer that contains the IStorage from the OLESTREAM
|
|
|
|
* nBufferLength [I] The size of the buffer
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing
|
|
|
|
*
|
|
|
|
* NOTES
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
|
|
|
*
|
2000-02-25 21:58:25 +01:00
|
|
|
*/
|
2007-07-04 21:12:48 +02:00
|
|
|
static void OLECONVERT_GetOLE20FromOLE10(LPSTORAGE pDestStorage, const BYTE *pBuffer, DWORD nBufferLength)
|
2000-02-25 21:58:25 +01:00
|
|
|
{
|
|
|
|
HRESULT hRes;
|
|
|
|
HANDLE hFile;
|
|
|
|
IStorage *pTempStorage;
|
|
|
|
DWORD dwNumOfBytesWritten;
|
|
|
|
WCHAR wstrTempDir[MAX_PATH], wstrTempFile[MAX_PATH];
|
2004-04-20 03:12:17 +02:00
|
|
|
static const WCHAR wstrPrefix[] = {'s', 'i', 's', 0};
|
2000-02-25 21:58:25 +01:00
|
|
|
|
|
|
|
/* Create a temp File */
|
|
|
|
GetTempPathW(MAX_PATH, wstrTempDir);
|
|
|
|
GetTempFileNameW(wstrTempDir, wstrPrefix, 0, wstrTempFile);
|
2000-03-08 19:25:22 +01:00
|
|
|
hFile = CreateFileW(wstrTempFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
2000-02-25 21:58:25 +01:00
|
|
|
|
|
|
|
if(hFile != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
/* Write IStorage Data to File */
|
|
|
|
WriteFile(hFile, pBuffer, nBufferLength, &dwNumOfBytesWritten, NULL);
|
|
|
|
CloseHandle(hFile);
|
|
|
|
|
|
|
|
/* Open and copy temp storage to the Dest Storage */
|
|
|
|
hRes = StgOpenStorage(wstrTempFile, NULL, STGM_READ, NULL, 0, &pTempStorage);
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
2009-10-28 20:37:37 +01:00
|
|
|
hRes = IStorage_CopyTo(pTempStorage, 0, NULL, NULL, pDestStorage);
|
|
|
|
IStorage_Release(pTempStorage);
|
2000-02-25 21:58:25 +01:00
|
|
|
}
|
|
|
|
DeleteFileW(wstrTempFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* OLECONVERT_WriteOLE20ToBuffer [Internal]
|
2000-02-25 21:58:25 +01:00
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Saves the OLE10 STREAM From memory
|
2000-02-25 21:58:25 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pStorage [I] The Src IStorage to copy
|
|
|
|
* pData [I] The Dest Memory to write to.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The size in bytes allocated for pData
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Memory allocated for pData must be freed by the caller
|
|
|
|
*
|
|
|
|
* Used by OleConvertIStorageToOLESTREAM only.
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2000-02-25 21:58:25 +01:00
|
|
|
*/
|
2005-07-24 19:11:59 +02:00
|
|
|
static DWORD OLECONVERT_WriteOLE20ToBuffer(LPSTORAGE pStorage, BYTE **pData)
|
2000-02-25 21:58:25 +01:00
|
|
|
{
|
|
|
|
HANDLE hFile;
|
|
|
|
HRESULT hRes;
|
|
|
|
DWORD nDataLength = 0;
|
|
|
|
IStorage *pTempStorage;
|
|
|
|
WCHAR wstrTempDir[MAX_PATH], wstrTempFile[MAX_PATH];
|
2004-04-20 03:12:17 +02:00
|
|
|
static const WCHAR wstrPrefix[] = {'s', 'i', 's', 0};
|
2000-02-25 21:58:25 +01:00
|
|
|
|
|
|
|
*pData = NULL;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-02-25 21:58:25 +01:00
|
|
|
/* Create temp Storage */
|
|
|
|
GetTempPathW(MAX_PATH, wstrTempDir);
|
|
|
|
GetTempFileNameW(wstrTempDir, wstrPrefix, 0, wstrTempFile);
|
2000-03-08 19:25:22 +01:00
|
|
|
hRes = StgCreateDocfile(wstrTempFile, STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &pTempStorage);
|
2000-02-25 21:58:25 +01:00
|
|
|
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
|
|
|
/* Copy Src Storage to the Temp Storage */
|
2009-10-28 20:39:05 +01:00
|
|
|
IStorage_CopyTo(pStorage, 0, NULL, NULL, pTempStorage);
|
|
|
|
IStorage_Release(pTempStorage);
|
2000-02-25 21:58:25 +01:00
|
|
|
|
|
|
|
/* Open Temp Storage as a file and copy to memory */
|
2000-03-08 19:25:22 +01:00
|
|
|
hFile = CreateFileW(wstrTempFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
2000-02-25 21:58:25 +01:00
|
|
|
if(hFile != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
nDataLength = GetFileSize(hFile, NULL);
|
2005-03-21 12:25:13 +01:00
|
|
|
*pData = HeapAlloc(GetProcessHeap(),0,nDataLength);
|
2000-02-25 21:58:25 +01:00
|
|
|
ReadFile(hFile, *pData, nDataLength, &nDataLength, 0);
|
|
|
|
CloseHandle(hFile);
|
|
|
|
}
|
|
|
|
DeleteFileW(wstrTempFile);
|
|
|
|
}
|
|
|
|
return nDataLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* OLECONVERT_CreateOleStream [Internal]
|
2000-02-25 21:58:25 +01:00
|
|
|
*
|
2003-05-13 02:41:57 +02:00
|
|
|
* Creates the "\001OLE" stream in the IStorage if necessary.
|
2000-02-25 21:58:25 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pStorage [I] Dest storage to create the stream in
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* This function is used by OleConvertOLESTREAMToIStorage only.
|
|
|
|
*
|
|
|
|
* This stream is still unknown, MS Word seems to have extra data
|
|
|
|
* but since the data is stored in the OLESTREAM there should be
|
2002-06-01 01:06:46 +02:00
|
|
|
* no need to recreate the stream. If the stream is manually
|
2000-02-25 21:58:25 +01:00
|
|
|
* deleted it will create it with this default data.
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2000-02-25 21:58:25 +01:00
|
|
|
*/
|
|
|
|
void OLECONVERT_CreateOleStream(LPSTORAGE pStorage)
|
|
|
|
{
|
|
|
|
HRESULT hRes;
|
|
|
|
IStream *pStream;
|
2004-04-20 03:12:17 +02:00
|
|
|
static const WCHAR wstrStreamName[] = {1,'O', 'l', 'e', 0};
|
2002-06-01 01:06:46 +02:00
|
|
|
BYTE pOleStreamHeader [] =
|
2000-02-25 21:58:25 +01:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00
|
2000-02-25 21:58:25 +01:00
|
|
|
};
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-02-25 21:58:25 +01:00
|
|
|
/* Create stream if not present */
|
2002-06-01 01:06:46 +02:00
|
|
|
hRes = IStorage_CreateStream(pStorage, wstrStreamName,
|
2000-02-25 21:58:25 +01:00
|
|
|
STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &pStream );
|
|
|
|
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
|
|
|
/* Write default Data */
|
|
|
|
hRes = IStream_Write(pStream, pOleStreamHeader, sizeof(pOleStreamHeader), NULL);
|
|
|
|
IStream_Release(pStream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-11 04:40:29 +02:00
|
|
|
/* write a string to a stream, preceded by its length */
|
|
|
|
static HRESULT STREAM_WriteString( IStream *stm, LPCWSTR string )
|
|
|
|
{
|
|
|
|
HRESULT r;
|
|
|
|
LPSTR str;
|
|
|
|
DWORD len = 0;
|
|
|
|
|
|
|
|
if( string )
|
|
|
|
len = WideCharToMultiByte( CP_ACP, 0, string, -1, NULL, 0, NULL, NULL);
|
2003-06-18 21:45:22 +02:00
|
|
|
r = IStream_Write( stm, &len, sizeof(len), NULL);
|
2003-05-11 04:40:29 +02:00
|
|
|
if( FAILED( r ) )
|
|
|
|
return r;
|
|
|
|
if(len == 0)
|
|
|
|
return r;
|
|
|
|
str = CoTaskMemAlloc( len );
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, string, -1, str, len, NULL, NULL);
|
|
|
|
r = IStream_Write( stm, str, len, NULL);
|
|
|
|
CoTaskMemFree( str );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read a string preceded by its length from a stream */
|
|
|
|
static HRESULT STREAM_ReadString( IStream *stm, LPWSTR *string )
|
|
|
|
{
|
|
|
|
HRESULT r;
|
|
|
|
DWORD len, count = 0;
|
|
|
|
LPSTR str;
|
|
|
|
LPWSTR wstr;
|
|
|
|
|
2003-06-18 21:45:22 +02:00
|
|
|
r = IStream_Read( stm, &len, sizeof(len), &count );
|
2003-05-11 04:40:29 +02:00
|
|
|
if( FAILED( r ) )
|
|
|
|
return r;
|
2003-06-18 21:45:22 +02:00
|
|
|
if( count != sizeof(len) )
|
2003-05-11 04:40:29 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("%d bytes\n",len);
|
2003-05-11 04:40:29 +02:00
|
|
|
|
|
|
|
str = CoTaskMemAlloc( len );
|
|
|
|
if( !str )
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
count = 0;
|
|
|
|
r = IStream_Read( stm, str, len, &count );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
return r;
|
|
|
|
if( count != len )
|
|
|
|
{
|
|
|
|
CoTaskMemFree( str );
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Read string %s\n",debugstr_an(str,len));
|
|
|
|
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, str, count, NULL, 0 );
|
|
|
|
wstr = CoTaskMemAlloc( (len + 1)*sizeof (WCHAR) );
|
|
|
|
if( wstr )
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, str, count, wstr, len );
|
|
|
|
CoTaskMemFree( str );
|
|
|
|
|
|
|
|
*string = wstr;
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static HRESULT STORAGE_WriteCompObj( LPSTORAGE pstg, CLSID *clsid,
|
|
|
|
LPCWSTR lpszUserType, LPCWSTR szClipName, LPCWSTR szProgIDName )
|
|
|
|
{
|
|
|
|
IStream *pstm;
|
|
|
|
HRESULT r = S_OK;
|
2004-04-20 03:12:17 +02:00
|
|
|
static const WCHAR szwStreamName[] = {1, 'C', 'o', 'm', 'p', 'O', 'b', 'j', 0};
|
2003-05-11 04:40:29 +02:00
|
|
|
|
|
|
|
static const BYTE unknown1[12] =
|
|
|
|
{ 0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF};
|
|
|
|
static const BYTE unknown2[16] =
|
|
|
|
{ 0xF4, 0x39, 0xB2, 0x71, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
|
|
|
|
|
|
TRACE("%p %s %s %s %s\n", pstg, debugstr_guid(clsid),
|
|
|
|
debugstr_w(lpszUserType), debugstr_w(szClipName),
|
|
|
|
debugstr_w(szProgIDName));
|
|
|
|
|
2009-08-27 20:03:26 +02:00
|
|
|
/* Create a CompObj stream */
|
2003-05-11 04:40:29 +02:00
|
|
|
r = IStorage_CreateStream(pstg, szwStreamName,
|
2009-08-27 20:03:26 +02:00
|
|
|
STGM_CREATE | STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &pstm );
|
2003-05-11 04:40:29 +02:00
|
|
|
if( FAILED (r) )
|
|
|
|
return r;
|
|
|
|
|
|
|
|
/* Write CompObj Structure to stream */
|
2003-06-18 21:45:22 +02:00
|
|
|
r = IStream_Write(pstm, unknown1, sizeof(unknown1), NULL);
|
2003-05-11 04:40:29 +02:00
|
|
|
|
|
|
|
if( SUCCEEDED( r ) )
|
|
|
|
r = WriteClassStm( pstm, clsid );
|
|
|
|
|
|
|
|
if( SUCCEEDED( r ) )
|
|
|
|
r = STREAM_WriteString( pstm, lpszUserType );
|
|
|
|
if( SUCCEEDED( r ) )
|
|
|
|
r = STREAM_WriteString( pstm, szClipName );
|
|
|
|
if( SUCCEEDED( r ) )
|
|
|
|
r = STREAM_WriteString( pstm, szProgIDName );
|
|
|
|
if( SUCCEEDED( r ) )
|
2003-06-18 21:45:22 +02:00
|
|
|
r = IStream_Write(pstm, unknown2, sizeof(unknown2), NULL);
|
2003-05-11 04:40:29 +02:00
|
|
|
|
|
|
|
IStream_Release( pstm );
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* WriteFmtUserTypeStg (OLE32.@)
|
2003-05-11 04:40:29 +02:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI WriteFmtUserTypeStg(
|
|
|
|
LPSTORAGE pstg, CLIPFORMAT cf, LPOLESTR lpszUserType)
|
|
|
|
{
|
|
|
|
HRESULT r;
|
|
|
|
WCHAR szwClipName[0x40];
|
2005-03-29 20:56:22 +02:00
|
|
|
CLSID clsid = CLSID_NULL;
|
|
|
|
LPWSTR wstrProgID = NULL;
|
2003-05-11 04:40:29 +02:00
|
|
|
DWORD n;
|
|
|
|
|
|
|
|
TRACE("(%p,%x,%s)\n",pstg,cf,debugstr_w(lpszUserType));
|
|
|
|
|
|
|
|
/* get the clipboard format name */
|
2008-02-14 15:38:53 +01:00
|
|
|
n = GetClipboardFormatNameW( cf, szwClipName, sizeof(szwClipName)/sizeof(szwClipName[0]) );
|
2003-05-11 04:40:29 +02:00
|
|
|
szwClipName[n]=0;
|
|
|
|
|
|
|
|
TRACE("Clipboard name is %s\n", debugstr_w(szwClipName));
|
|
|
|
|
2005-03-29 20:56:22 +02:00
|
|
|
/* FIXME: There's room to save a CLSID and its ProgID, but
|
|
|
|
the CLSID is not looked up in the registry and in all the
|
|
|
|
tests I wrote it was CLSID_NULL. Where does it come from?
|
|
|
|
*/
|
2003-05-11 04:40:29 +02:00
|
|
|
|
2005-03-29 20:56:22 +02:00
|
|
|
/* get the real program ID. This may fail, but that's fine */
|
|
|
|
ProgIDFromCLSID(&clsid, &wstrProgID);
|
2003-05-11 04:40:29 +02:00
|
|
|
|
|
|
|
TRACE("progid is %s\n",debugstr_w(wstrProgID));
|
|
|
|
|
2005-03-29 20:56:22 +02:00
|
|
|
r = STORAGE_WriteCompObj( pstg, &clsid,
|
|
|
|
lpszUserType, szwClipName, wstrProgID );
|
2003-05-11 04:40:29 +02:00
|
|
|
|
2005-03-29 20:56:22 +02:00
|
|
|
CoTaskMemFree(wstrProgID);
|
2003-05-11 04:40:29 +02:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* ReadFmtUserTypeStg [OLE32.@]
|
2003-05-11 04:40:29 +02:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI ReadFmtUserTypeStg (LPSTORAGE pstg, CLIPFORMAT* pcf, LPOLESTR* lplpszUserType)
|
|
|
|
{
|
|
|
|
HRESULT r;
|
|
|
|
IStream *stm = 0;
|
2004-04-20 04:14:00 +02:00
|
|
|
static const WCHAR szCompObj[] = { 1, 'C','o','m','p','O','b','j', 0 };
|
2003-05-11 04:40:29 +02:00
|
|
|
unsigned char unknown1[12];
|
|
|
|
unsigned char unknown2[16];
|
|
|
|
DWORD count;
|
|
|
|
LPWSTR szProgIDName = NULL, szCLSIDName = NULL, szOleTypeName = NULL;
|
|
|
|
CLSID clsid;
|
|
|
|
|
|
|
|
TRACE("(%p,%p,%p)\n", pstg, pcf, lplpszUserType);
|
|
|
|
|
|
|
|
r = IStorage_OpenStream( pstg, szCompObj, NULL,
|
|
|
|
STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm );
|
|
|
|
if( FAILED ( r ) )
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
WARN("Failed to open stream r = %08x\n", r);
|
2003-05-11 04:40:29 +02:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read the various parts of the structure */
|
2003-06-18 21:45:22 +02:00
|
|
|
r = IStream_Read( stm, unknown1, sizeof(unknown1), &count );
|
|
|
|
if( FAILED( r ) || ( count != sizeof(unknown1) ) )
|
2003-05-11 04:40:29 +02:00
|
|
|
goto end;
|
|
|
|
r = ReadClassStm( stm, &clsid );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
r = STREAM_ReadString( stm, &szCLSIDName );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
r = STREAM_ReadString( stm, &szOleTypeName );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
r = STREAM_ReadString( stm, &szProgIDName );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
goto end;
|
|
|
|
|
2003-06-18 21:45:22 +02:00
|
|
|
r = IStream_Read( stm, unknown2, sizeof(unknown2), &count );
|
|
|
|
if( FAILED( r ) || ( count != sizeof(unknown2) ) )
|
2003-05-11 04:40:29 +02:00
|
|
|
goto end;
|
|
|
|
|
|
|
|
/* ok, success... now we just need to store what we found */
|
|
|
|
if( pcf )
|
|
|
|
*pcf = RegisterClipboardFormatW( szOleTypeName );
|
|
|
|
CoTaskMemFree( szOleTypeName );
|
|
|
|
|
|
|
|
if( lplpszUserType )
|
|
|
|
*lplpszUserType = szCLSIDName;
|
|
|
|
CoTaskMemFree( szProgIDName );
|
|
|
|
|
|
|
|
end:
|
|
|
|
IStream_Release( stm );
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2000-02-25 21:58:25 +01:00
|
|
|
|
|
|
|
/*************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* OLECONVERT_CreateCompObjStream [Internal]
|
2000-02-25 21:58:25 +01:00
|
|
|
*
|
|
|
|
* Creates a "\001CompObj" is the destination IStorage if necessary.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2002-06-01 01:06:46 +02:00
|
|
|
* pStorage [I] The dest IStorage to create the CompObj Stream
|
2000-02-25 21:58:25 +01:00
|
|
|
* if necessary.
|
|
|
|
* strOleTypeName [I] The ProgID
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK
|
|
|
|
* Failure: REGDB_E_CLASSNOTREG if cannot reconstruct the stream
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* This function is used by OleConvertOLESTREAMToIStorage only.
|
|
|
|
*
|
|
|
|
* The stream data is stored in the OLESTREAM and there should be
|
2002-06-01 01:06:46 +02:00
|
|
|
* no need to recreate the stream. If the stream is manually
|
2000-02-25 21:58:25 +01:00
|
|
|
* deleted it will attempt to create it by querying the registry.
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2000-02-25 21:58:25 +01:00
|
|
|
*/
|
|
|
|
HRESULT OLECONVERT_CreateCompObjStream(LPSTORAGE pStorage, LPCSTR strOleTypeName)
|
|
|
|
{
|
|
|
|
IStream *pStream;
|
|
|
|
HRESULT hStorageRes, hRes = S_OK;
|
|
|
|
OLECONVERT_ISTORAGE_COMPOBJ IStorageCompObj;
|
2004-04-20 03:12:17 +02:00
|
|
|
static const WCHAR wstrStreamName[] = {1,'C', 'o', 'm', 'p', 'O', 'b', 'j', 0};
|
2004-01-23 23:51:41 +01:00
|
|
|
WCHAR bufferW[OLESTREAM_MAX_STR_LEN];
|
2000-02-25 21:58:25 +01:00
|
|
|
|
|
|
|
BYTE pCompObjUnknown1[] = {0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF};
|
|
|
|
BYTE pCompObjUnknown2[] = {0xF4, 0x39, 0xB2, 0x71};
|
|
|
|
|
|
|
|
/* Initialize the CompObj structure */
|
|
|
|
memset(&IStorageCompObj, 0, sizeof(IStorageCompObj));
|
2008-07-11 11:41:44 +02:00
|
|
|
memcpy(IStorageCompObj.byUnknown1, pCompObjUnknown1, sizeof(pCompObjUnknown1));
|
|
|
|
memcpy(IStorageCompObj.byUnknown2, pCompObjUnknown2, sizeof(pCompObjUnknown2));
|
2000-02-25 21:58:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* Create a CompObj stream if it doesn't exist */
|
2002-06-01 01:06:46 +02:00
|
|
|
hStorageRes = IStorage_CreateStream(pStorage, wstrStreamName,
|
2000-02-25 21:58:25 +01:00
|
|
|
STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &pStream );
|
|
|
|
if(hStorageRes == S_OK)
|
|
|
|
{
|
|
|
|
/* copy the OleTypeName to the compobj struct */
|
|
|
|
IStorageCompObj.dwOleTypeNameLength = strlen(strOleTypeName)+1;
|
|
|
|
strcpy(IStorageCompObj.strOleTypeName, strOleTypeName);
|
|
|
|
|
|
|
|
/* copy the OleTypeName to the compobj struct */
|
2001-02-28 06:31:02 +01:00
|
|
|
/* Note: in the test made, these were Identical */
|
2000-02-25 21:58:25 +01:00
|
|
|
IStorageCompObj.dwProgIDNameLength = strlen(strOleTypeName)+1;
|
|
|
|
strcpy(IStorageCompObj.strProgIDName, strOleTypeName);
|
|
|
|
|
|
|
|
/* Get the CLSID */
|
2004-01-23 23:51:41 +01:00
|
|
|
MultiByteToWideChar( CP_ACP, 0, IStorageCompObj.strProgIDName, -1,
|
|
|
|
bufferW, OLESTREAM_MAX_STR_LEN );
|
|
|
|
hRes = CLSIDFromProgID(bufferW, &(IStorageCompObj.clsid));
|
2000-02-25 21:58:25 +01:00
|
|
|
|
2000-06-20 22:49:53 +02:00
|
|
|
if(hRes == S_OK)
|
2000-02-25 21:58:25 +01:00
|
|
|
{
|
|
|
|
HKEY hKey;
|
|
|
|
LONG hErr;
|
|
|
|
/* Get the CLSID Default Name from the Registry */
|
2002-06-01 01:06:46 +02:00
|
|
|
hErr = RegOpenKeyA(HKEY_CLASSES_ROOT, IStorageCompObj.strProgIDName, &hKey);
|
2000-02-25 21:58:25 +01:00
|
|
|
if(hErr == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
char strTemp[OLESTREAM_MAX_STR_LEN];
|
|
|
|
IStorageCompObj.dwCLSIDNameLength = OLESTREAM_MAX_STR_LEN;
|
2005-08-15 12:49:39 +02:00
|
|
|
hErr = RegQueryValueA(hKey, NULL, strTemp, (LONG*) &(IStorageCompObj.dwCLSIDNameLength));
|
2000-02-25 21:58:25 +01:00
|
|
|
if(hErr == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
strcpy(IStorageCompObj.strCLSIDName, strTemp);
|
|
|
|
}
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-20 22:49:53 +02:00
|
|
|
/* Write CompObj Structure to stream */
|
|
|
|
hRes = IStream_Write(pStream, IStorageCompObj.byUnknown1, sizeof(IStorageCompObj.byUnknown1), NULL);
|
|
|
|
|
|
|
|
WriteClassStm(pStream,&(IStorageCompObj.clsid));
|
|
|
|
|
|
|
|
hRes = IStream_Write(pStream, &(IStorageCompObj.dwCLSIDNameLength), sizeof(IStorageCompObj.dwCLSIDNameLength), NULL);
|
|
|
|
if(IStorageCompObj.dwCLSIDNameLength > 0)
|
2000-02-25 21:58:25 +01:00
|
|
|
{
|
2000-06-20 22:49:53 +02:00
|
|
|
hRes = IStream_Write(pStream, IStorageCompObj.strCLSIDName, IStorageCompObj.dwCLSIDNameLength, NULL);
|
|
|
|
}
|
|
|
|
hRes = IStream_Write(pStream, &(IStorageCompObj.dwOleTypeNameLength) , sizeof(IStorageCompObj.dwOleTypeNameLength), NULL);
|
|
|
|
if(IStorageCompObj.dwOleTypeNameLength > 0)
|
|
|
|
{
|
|
|
|
hRes = IStream_Write(pStream, IStorageCompObj.strOleTypeName , IStorageCompObj.dwOleTypeNameLength, NULL);
|
|
|
|
}
|
|
|
|
hRes = IStream_Write(pStream, &(IStorageCompObj.dwProgIDNameLength) , sizeof(IStorageCompObj.dwProgIDNameLength), NULL);
|
|
|
|
if(IStorageCompObj.dwProgIDNameLength > 0)
|
|
|
|
{
|
|
|
|
hRes = IStream_Write(pStream, IStorageCompObj.strProgIDName , IStorageCompObj.dwProgIDNameLength, NULL);
|
2000-02-25 21:58:25 +01:00
|
|
|
}
|
2000-06-20 22:49:53 +02:00
|
|
|
hRes = IStream_Write(pStream, IStorageCompObj.byUnknown2 , sizeof(IStorageCompObj.byUnknown2), NULL);
|
2000-02-25 21:58:25 +01:00
|
|
|
IStream_Release(pStream);
|
|
|
|
}
|
|
|
|
return hRes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* OLECONVERT_CreateOlePresStream[Internal]
|
2000-02-25 21:58:25 +01:00
|
|
|
*
|
|
|
|
* Creates the "\002OlePres000" Stream with the Metafile data
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pStorage [I] The dest IStorage to create \002OLEPres000 stream in.
|
|
|
|
* dwExtentX [I] Width of the Metafile
|
2002-06-01 01:06:46 +02:00
|
|
|
* dwExtentY [I] Height of the Metafile
|
2000-02-25 21:58:25 +01:00
|
|
|
* pData [I] Metafile data
|
|
|
|
* dwDataLength [I] Size of the Metafile data
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK
|
|
|
|
* Failure: CONVERT10_E_OLESTREAM_PUT for invalid Put
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* This function is used by OleConvertOLESTREAMToIStorage only.
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2000-02-25 21:58:25 +01:00
|
|
|
*/
|
2005-07-24 19:11:59 +02:00
|
|
|
static void OLECONVERT_CreateOlePresStream(LPSTORAGE pStorage, DWORD dwExtentX, DWORD dwExtentY , BYTE *pData, DWORD dwDataLength)
|
2000-02-25 21:58:25 +01:00
|
|
|
{
|
|
|
|
HRESULT hRes;
|
|
|
|
IStream *pStream;
|
2004-04-20 03:12:17 +02:00
|
|
|
static const WCHAR wstrStreamName[] = {2, 'O', 'l', 'e', 'P', 'r', 'e', 's', '0', '0', '0', 0};
|
2002-06-01 01:06:46 +02:00
|
|
|
BYTE pOlePresStreamHeader [] =
|
2000-02-25 21:58:25 +01:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00,
|
|
|
|
0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
2000-02-25 21:58:25 +01:00
|
|
|
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00
|
|
|
|
};
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
BYTE pOlePresStreamHeaderEmpty [] =
|
2000-02-25 21:58:25 +01:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
2000-02-25 21:58:25 +01:00
|
|
|
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00
|
|
|
|
};
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-02-25 21:58:25 +01:00
|
|
|
/* Create the OlePres000 Stream */
|
2002-06-01 01:06:46 +02:00
|
|
|
hRes = IStorage_CreateStream(pStorage, wstrStreamName,
|
2000-02-25 21:58:25 +01:00
|
|
|
STGM_CREATE | STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &pStream );
|
|
|
|
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
|
|
|
DWORD nHeaderSize;
|
|
|
|
OLECONVERT_ISTORAGE_OLEPRES OlePres;
|
|
|
|
|
|
|
|
memset(&OlePres, 0, sizeof(OlePres));
|
|
|
|
/* Do we have any metafile data to save */
|
|
|
|
if(dwDataLength > 0)
|
|
|
|
{
|
|
|
|
memcpy(OlePres.byUnknown1, pOlePresStreamHeader, sizeof(pOlePresStreamHeader));
|
|
|
|
nHeaderSize = sizeof(pOlePresStreamHeader);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memcpy(OlePres.byUnknown1, pOlePresStreamHeaderEmpty, sizeof(pOlePresStreamHeaderEmpty));
|
|
|
|
nHeaderSize = sizeof(pOlePresStreamHeaderEmpty);
|
|
|
|
}
|
|
|
|
/* Set width and height of the metafile */
|
|
|
|
OlePres.dwExtentX = dwExtentX;
|
|
|
|
OlePres.dwExtentY = -dwExtentY;
|
|
|
|
|
2003-07-09 04:52:57 +02:00
|
|
|
/* Set Data and Length */
|
2000-02-25 21:58:25 +01:00
|
|
|
if(dwDataLength > sizeof(METAFILEPICT16))
|
|
|
|
{
|
|
|
|
OlePres.dwSize = dwDataLength - sizeof(METAFILEPICT16);
|
|
|
|
OlePres.pData = &(pData[8]);
|
|
|
|
}
|
|
|
|
/* Save OlePres000 Data to Stream */
|
|
|
|
hRes = IStream_Write(pStream, OlePres.byUnknown1, nHeaderSize, NULL);
|
|
|
|
hRes = IStream_Write(pStream, &(OlePres.dwExtentX), sizeof(OlePres.dwExtentX), NULL);
|
|
|
|
hRes = IStream_Write(pStream, &(OlePres.dwExtentY), sizeof(OlePres.dwExtentY), NULL);
|
|
|
|
hRes = IStream_Write(pStream, &(OlePres.dwSize), sizeof(OlePres.dwSize), NULL);
|
|
|
|
if(OlePres.dwSize > 0)
|
|
|
|
{
|
|
|
|
hRes = IStream_Write(pStream, OlePres.pData, OlePres.dwSize, NULL);
|
|
|
|
}
|
|
|
|
IStream_Release(pStream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* OLECONVERT_CreateOle10NativeStream [Internal]
|
2000-02-25 21:58:25 +01:00
|
|
|
*
|
|
|
|
* Creates the "\001Ole10Native" Stream (should contain a BMP)
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pStorage [I] Dest storage to create the stream in
|
|
|
|
* pData [I] Ole10 Native Data (ex. bmp)
|
|
|
|
* dwDataLength [I] Size of the Ole10 Native Data
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* This function is used by OleConvertOLESTREAMToIStorage only.
|
|
|
|
*
|
|
|
|
* Might need to verify the data and return appropriate error message
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2000-02-25 21:58:25 +01:00
|
|
|
*/
|
2007-07-04 21:12:48 +02:00
|
|
|
static void OLECONVERT_CreateOle10NativeStream(LPSTORAGE pStorage, const BYTE *pData, DWORD dwDataLength)
|
2000-02-25 21:58:25 +01:00
|
|
|
{
|
|
|
|
HRESULT hRes;
|
|
|
|
IStream *pStream;
|
2004-04-20 03:12:17 +02:00
|
|
|
static const WCHAR wstrStreamName[] = {1, 'O', 'l', 'e', '1', '0', 'N', 'a', 't', 'i', 'v', 'e', 0};
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-02-25 21:58:25 +01:00
|
|
|
/* Create the Ole10Native Stream */
|
2002-06-01 01:06:46 +02:00
|
|
|
hRes = IStorage_CreateStream(pStorage, wstrStreamName,
|
2000-02-25 21:58:25 +01:00
|
|
|
STGM_CREATE | STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &pStream );
|
|
|
|
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
|
|
|
/* Write info to stream */
|
|
|
|
hRes = IStream_Write(pStream, &dwDataLength, sizeof(dwDataLength), NULL);
|
|
|
|
hRes = IStream_Write(pStream, pData, dwDataLength, NULL);
|
|
|
|
IStream_Release(pStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* OLECONVERT_GetOLE10ProgID [Internal]
|
2000-02-25 21:58:25 +01:00
|
|
|
*
|
|
|
|
* Finds the ProgID (or OleTypeID) from the IStorage
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pStorage [I] The Src IStorage to get the ProgID
|
|
|
|
* strProgID [I] the ProgID string to get
|
|
|
|
* dwSize [I] the size of the string
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK
|
|
|
|
* Failure: REGDB_E_CLASSNOTREG if cannot reconstruct the stream
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* This function is used by OleConvertIStorageToOLESTREAM only.
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2000-02-25 21:58:25 +01:00
|
|
|
*/
|
2005-07-24 19:11:59 +02:00
|
|
|
static HRESULT OLECONVERT_GetOLE10ProgID(LPSTORAGE pStorage, char *strProgID, DWORD *dwSize)
|
2000-02-25 21:58:25 +01:00
|
|
|
{
|
|
|
|
HRESULT hRes;
|
|
|
|
IStream *pStream;
|
|
|
|
LARGE_INTEGER iSeekPos;
|
|
|
|
OLECONVERT_ISTORAGE_COMPOBJ CompObj;
|
2004-04-20 03:12:17 +02:00
|
|
|
static const WCHAR wstrStreamName[] = {1,'C', 'o', 'm', 'p', 'O', 'b', 'j', 0};
|
2000-02-25 21:58:25 +01:00
|
|
|
|
|
|
|
/* Open the CompObj Stream */
|
2002-06-01 01:06:46 +02:00
|
|
|
hRes = IStorage_OpenStream(pStorage, wstrStreamName, NULL,
|
2000-02-25 21:58:25 +01:00
|
|
|
STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &pStream );
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
|
|
|
|
|
|
|
/*Get the OleType from the CompObj Stream */
|
2004-01-23 02:51:33 +01:00
|
|
|
iSeekPos.u.LowPart = sizeof(CompObj.byUnknown1) + sizeof(CompObj.clsid);
|
|
|
|
iSeekPos.u.HighPart = 0;
|
2000-02-25 21:58:25 +01:00
|
|
|
|
|
|
|
IStream_Seek(pStream, iSeekPos, STREAM_SEEK_SET, NULL);
|
|
|
|
IStream_Read(pStream, &CompObj.dwCLSIDNameLength, sizeof(CompObj.dwCLSIDNameLength), NULL);
|
2004-01-23 02:51:33 +01:00
|
|
|
iSeekPos.u.LowPart = CompObj.dwCLSIDNameLength;
|
2000-02-25 21:58:25 +01:00
|
|
|
IStream_Seek(pStream, iSeekPos, STREAM_SEEK_CUR , NULL);
|
|
|
|
IStream_Read(pStream, &CompObj.dwOleTypeNameLength, sizeof(CompObj.dwOleTypeNameLength), NULL);
|
2004-01-23 02:51:33 +01:00
|
|
|
iSeekPos.u.LowPart = CompObj.dwOleTypeNameLength;
|
2000-02-25 21:58:25 +01:00
|
|
|
IStream_Seek(pStream, iSeekPos, STREAM_SEEK_CUR , NULL);
|
|
|
|
|
|
|
|
IStream_Read(pStream, dwSize, sizeof(*dwSize), NULL);
|
|
|
|
if(*dwSize > 0)
|
|
|
|
{
|
|
|
|
IStream_Read(pStream, strProgID, *dwSize, NULL);
|
|
|
|
}
|
|
|
|
IStream_Release(pStream);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
STATSTG stat;
|
|
|
|
LPOLESTR wstrProgID;
|
|
|
|
|
|
|
|
/* Get the OleType from the registry */
|
|
|
|
REFCLSID clsid = &(stat.clsid);
|
|
|
|
IStorage_Stat(pStorage, &stat, STATFLAG_NONAME);
|
|
|
|
hRes = ProgIDFromCLSID(clsid, &wstrProgID);
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
|
|
|
*dwSize = WideCharToMultiByte(CP_ACP, 0, wstrProgID, -1, strProgID, *dwSize, NULL, FALSE);
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-02-25 21:58:25 +01:00
|
|
|
}
|
|
|
|
return hRes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* OLECONVERT_GetOle10PresData [Internal]
|
2000-02-25 21:58:25 +01:00
|
|
|
*
|
|
|
|
* Converts IStorage "/001Ole10Native" stream to a OLE10 Stream
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pStorage [I] Src IStroage
|
|
|
|
* pOleStream [I] Dest OleStream Mem Struct
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* This function is used by OleConvertIStorageToOLESTREAM only.
|
|
|
|
*
|
|
|
|
* Memory allocated for pData must be freed by the caller
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
|
|
|
*
|
2000-02-25 21:58:25 +01:00
|
|
|
*/
|
2005-07-24 19:11:59 +02:00
|
|
|
static void OLECONVERT_GetOle10PresData(LPSTORAGE pStorage, OLECONVERT_OLESTREAM_DATA *pOleStreamData)
|
2000-02-25 21:58:25 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
HRESULT hRes;
|
|
|
|
IStream *pStream;
|
2004-04-20 03:12:17 +02:00
|
|
|
static const WCHAR wstrStreamName[] = {1, 'O', 'l', 'e', '1', '0', 'N', 'a', 't', 'i', 'v', 'e', 0};
|
2000-02-25 21:58:25 +01:00
|
|
|
|
|
|
|
/* Initialize Default data for OLESTREAM */
|
|
|
|
pOleStreamData[0].dwOleID = OLESTREAM_ID;
|
|
|
|
pOleStreamData[0].dwTypeID = 2;
|
|
|
|
pOleStreamData[1].dwOleID = OLESTREAM_ID;
|
|
|
|
pOleStreamData[1].dwTypeID = 0;
|
|
|
|
pOleStreamData[0].dwMetaFileWidth = 0;
|
|
|
|
pOleStreamData[0].dwMetaFileHeight = 0;
|
|
|
|
pOleStreamData[0].pData = NULL;
|
|
|
|
pOleStreamData[1].pData = NULL;
|
|
|
|
|
|
|
|
/* Open Ole10Native Stream */
|
2002-06-01 01:06:46 +02:00
|
|
|
hRes = IStorage_OpenStream(pStorage, wstrStreamName, NULL,
|
2000-02-25 21:58:25 +01:00
|
|
|
STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &pStream );
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Read Size and Data */
|
|
|
|
IStream_Read(pStream, &(pOleStreamData->dwDataLength), sizeof(pOleStreamData->dwDataLength), NULL);
|
|
|
|
if(pOleStreamData->dwDataLength > 0)
|
|
|
|
{
|
2005-03-21 12:25:13 +01:00
|
|
|
pOleStreamData->pData = HeapAlloc(GetProcessHeap(),0,pOleStreamData->dwDataLength);
|
2000-02-25 21:58:25 +01:00
|
|
|
IStream_Read(pStream, pOleStreamData->pData, pOleStreamData->dwDataLength, NULL);
|
|
|
|
}
|
|
|
|
IStream_Release(pStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* OLECONVERT_GetOle20PresData[Internal]
|
2000-02-25 21:58:25 +01:00
|
|
|
*
|
|
|
|
* Converts IStorage "/002OlePres000" stream to a OLE10 Stream
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pStorage [I] Src IStroage
|
|
|
|
* pOleStreamData [I] Dest OleStream Mem Struct
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* This function is used by OleConvertIStorageToOLESTREAM only.
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2000-02-25 21:58:25 +01:00
|
|
|
* Memory allocated for pData must be freed by the caller
|
|
|
|
*/
|
2005-07-24 19:11:59 +02:00
|
|
|
static void OLECONVERT_GetOle20PresData(LPSTORAGE pStorage, OLECONVERT_OLESTREAM_DATA *pOleStreamData)
|
2000-02-25 21:58:25 +01:00
|
|
|
{
|
|
|
|
HRESULT hRes;
|
|
|
|
IStream *pStream;
|
|
|
|
OLECONVERT_ISTORAGE_OLEPRES olePress;
|
2004-04-20 03:12:17 +02:00
|
|
|
static const WCHAR wstrStreamName[] = {2, 'O', 'l', 'e', 'P', 'r', 'e', 's', '0', '0', '0', 0};
|
2000-02-25 21:58:25 +01:00
|
|
|
|
|
|
|
/* Initialize Default data for OLESTREAM */
|
|
|
|
pOleStreamData[0].dwOleID = OLESTREAM_ID;
|
|
|
|
pOleStreamData[0].dwTypeID = 2;
|
|
|
|
pOleStreamData[0].dwMetaFileWidth = 0;
|
|
|
|
pOleStreamData[0].dwMetaFileHeight = 0;
|
|
|
|
pOleStreamData[0].dwDataLength = OLECONVERT_WriteOLE20ToBuffer(pStorage, &(pOleStreamData[0].pData));
|
|
|
|
pOleStreamData[1].dwOleID = OLESTREAM_ID;
|
|
|
|
pOleStreamData[1].dwTypeID = 0;
|
|
|
|
pOleStreamData[1].dwOleTypeNameLength = 0;
|
|
|
|
pOleStreamData[1].strOleTypeName[0] = 0;
|
|
|
|
pOleStreamData[1].dwMetaFileWidth = 0;
|
|
|
|
pOleStreamData[1].dwMetaFileHeight = 0;
|
|
|
|
pOleStreamData[1].pData = NULL;
|
|
|
|
pOleStreamData[1].dwDataLength = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/* Open OlePress000 stream */
|
2002-06-01 01:06:46 +02:00
|
|
|
hRes = IStorage_OpenStream(pStorage, wstrStreamName, NULL,
|
2000-02-25 21:58:25 +01:00
|
|
|
STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &pStream );
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER iSeekPos;
|
|
|
|
METAFILEPICT16 MetaFilePict;
|
2004-05-04 06:13:05 +02:00
|
|
|
static const char strMetafilePictName[] = "METAFILEPICT";
|
2000-02-25 21:58:25 +01:00
|
|
|
|
|
|
|
/* Set the TypeID for a Metafile */
|
|
|
|
pOleStreamData[1].dwTypeID = 5;
|
|
|
|
|
|
|
|
/* Set the OleTypeName to Metafile */
|
|
|
|
pOleStreamData[1].dwOleTypeNameLength = strlen(strMetafilePictName) +1;
|
|
|
|
strcpy(pOleStreamData[1].strOleTypeName, strMetafilePictName);
|
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
iSeekPos.u.HighPart = 0;
|
|
|
|
iSeekPos.u.LowPart = sizeof(olePress.byUnknown1);
|
2000-02-25 21:58:25 +01:00
|
|
|
|
|
|
|
/* Get Presentation Data */
|
|
|
|
IStream_Seek(pStream, iSeekPos, STREAM_SEEK_SET, NULL);
|
|
|
|
IStream_Read(pStream, &(olePress.dwExtentX), sizeof(olePress.dwExtentX), NULL);
|
|
|
|
IStream_Read(pStream, &(olePress.dwExtentY), sizeof(olePress.dwExtentY), NULL);
|
|
|
|
IStream_Read(pStream, &(olePress.dwSize), sizeof(olePress.dwSize), NULL);
|
|
|
|
|
|
|
|
/*Set width and Height */
|
|
|
|
pOleStreamData[1].dwMetaFileWidth = olePress.dwExtentX;
|
|
|
|
pOleStreamData[1].dwMetaFileHeight = -olePress.dwExtentY;
|
|
|
|
if(olePress.dwSize > 0)
|
|
|
|
{
|
|
|
|
/* Set Length */
|
|
|
|
pOleStreamData[1].dwDataLength = olePress.dwSize + sizeof(METAFILEPICT16);
|
|
|
|
|
|
|
|
/* Set MetaFilePict struct */
|
|
|
|
MetaFilePict.mm = 8;
|
|
|
|
MetaFilePict.xExt = olePress.dwExtentX;
|
|
|
|
MetaFilePict.yExt = olePress.dwExtentY;
|
|
|
|
MetaFilePict.hMF = 0;
|
|
|
|
|
|
|
|
/* Get Metafile Data */
|
2005-03-21 12:25:13 +01:00
|
|
|
pOleStreamData[1].pData = HeapAlloc(GetProcessHeap(),0,pOleStreamData[1].dwDataLength);
|
2000-02-25 21:58:25 +01:00
|
|
|
memcpy(pOleStreamData[1].pData, &MetaFilePict, sizeof(MetaFilePict));
|
|
|
|
IStream_Read(pStream, &(pOleStreamData[1].pData[sizeof(MetaFilePict)]), pOleStreamData[1].dwDataLength-sizeof(METAFILEPICT16), NULL);
|
|
|
|
}
|
|
|
|
IStream_Release(pStream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* OleConvertOLESTREAMToIStorage [OLE32.@]
|
2000-02-25 21:58:25 +01:00
|
|
|
*
|
|
|
|
* Read info on MSDN
|
|
|
|
*
|
|
|
|
* TODO
|
2008-04-09 21:33:37 +02:00
|
|
|
* DVTARGETDEVICE parameter is not handled
|
2000-02-25 21:58:25 +01:00
|
|
|
* Still unsure of some mem fields for OLE 10 Stream
|
|
|
|
* Still some unknowns for the IStorage: "\002OlePres000", "\001CompObj",
|
|
|
|
* and "\001OLE" streams
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2000-02-25 21:58:25 +01:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI OleConvertOLESTREAMToIStorage (
|
2002-06-01 01:06:46 +02:00
|
|
|
LPOLESTREAM pOleStream,
|
|
|
|
LPSTORAGE pstg,
|
2000-02-25 21:58:25 +01:00
|
|
|
const DVTARGETDEVICE* ptd)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
HRESULT hRes=S_OK;
|
|
|
|
OLECONVERT_OLESTREAM_DATA pOleStreamData[2];
|
|
|
|
|
2006-07-29 10:13:53 +02:00
|
|
|
TRACE("%p %p %p\n", pOleStream, pstg, ptd);
|
|
|
|
|
2000-02-25 21:58:25 +01:00
|
|
|
memset(pOleStreamData, 0, sizeof(pOleStreamData));
|
|
|
|
|
|
|
|
if(ptd != NULL)
|
|
|
|
{
|
|
|
|
FIXME("DVTARGETDEVICE is not NULL, unhandled parameter\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pstg == NULL || pOleStream == NULL)
|
|
|
|
{
|
|
|
|
hRes = E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
|
|
|
/* Load the OLESTREAM to Memory */
|
2000-02-29 23:03:14 +01:00
|
|
|
hRes = OLECONVERT_LoadOLE10(pOleStream, &pOleStreamData[0], TRUE);
|
2000-02-25 21:58:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
|
|
|
/* Load the OLESTREAM to Memory (part 2)*/
|
2000-02-29 23:03:14 +01:00
|
|
|
hRes = OLECONVERT_LoadOLE10(pOleStream, &pOleStreamData[1], FALSE);
|
2000-02-25 21:58:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(pOleStreamData[0].dwDataLength > sizeof(STORAGE_magic))
|
|
|
|
{
|
|
|
|
/* Do we have the IStorage Data in the OLESTREAM */
|
|
|
|
if(memcmp(pOleStreamData[0].pData, STORAGE_magic, sizeof(STORAGE_magic)) ==0)
|
|
|
|
{
|
|
|
|
OLECONVERT_GetOLE20FromOLE10(pstg, pOleStreamData[0].pData, pOleStreamData[0].dwDataLength);
|
|
|
|
OLECONVERT_CreateOlePresStream(pstg, pOleStreamData[1].dwMetaFileWidth, pOleStreamData[1].dwMetaFileHeight, pOleStreamData[1].pData, pOleStreamData[1].dwDataLength);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* It must be an original OLE 1.0 source */
|
|
|
|
OLECONVERT_CreateOle10NativeStream(pstg, pOleStreamData[0].pData, pOleStreamData[0].dwDataLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* It must be an original OLE 1.0 source */
|
|
|
|
OLECONVERT_CreateOle10NativeStream(pstg, pOleStreamData[0].pData, pOleStreamData[0].dwDataLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create CompObj Stream if necessary */
|
|
|
|
hRes = OLECONVERT_CreateCompObjStream(pstg, pOleStreamData[0].strOleTypeName);
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
|
|
|
/*Create the Ole Stream if necessary */
|
|
|
|
OLECONVERT_CreateOleStream(pstg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Free allocated memory */
|
|
|
|
for(i=0; i < 2; i++)
|
|
|
|
{
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,pOleStreamData[i].pData);
|
|
|
|
HeapFree(GetProcessHeap(),0,pOleStreamData[i].pstrOleObjFileName);
|
|
|
|
pOleStreamData[i].pstrOleObjFileName = NULL;
|
2000-02-25 21:58:25 +01:00
|
|
|
}
|
|
|
|
return hRes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* OleConvertIStorageToOLESTREAM [OLE32.@]
|
2000-02-25 21:58:25 +01:00
|
|
|
*
|
|
|
|
* Read info on MSDN
|
|
|
|
*
|
|
|
|
* Read info on MSDN
|
|
|
|
*
|
|
|
|
* TODO
|
|
|
|
* Still unsure of some mem fields for OLE 10 Stream
|
|
|
|
* Still some unknowns for the IStorage: "\002OlePres000", "\001CompObj",
|
|
|
|
* and "\001OLE" streams.
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2000-02-25 21:58:25 +01:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI OleConvertIStorageToOLESTREAM (
|
2002-06-01 01:06:46 +02:00
|
|
|
LPSTORAGE pstg,
|
2000-02-25 21:58:25 +01:00
|
|
|
LPOLESTREAM pOleStream)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
HRESULT hRes = S_OK;
|
|
|
|
IStream *pStream;
|
|
|
|
OLECONVERT_OLESTREAM_DATA pOleStreamData[2];
|
2004-04-20 03:12:17 +02:00
|
|
|
static const WCHAR wstrStreamName[] = {1, 'O', 'l', 'e', '1', '0', 'N', 'a', 't', 'i', 'v', 'e', 0};
|
2000-02-25 21:58:25 +01:00
|
|
|
|
2006-07-29 10:13:53 +02:00
|
|
|
TRACE("%p %p\n", pstg, pOleStream);
|
2000-02-25 21:58:25 +01:00
|
|
|
|
|
|
|
memset(pOleStreamData, 0, sizeof(pOleStreamData));
|
|
|
|
|
|
|
|
if(pstg == NULL || pOleStream == NULL)
|
|
|
|
{
|
|
|
|
hRes = E_INVALIDARG;
|
|
|
|
}
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
|
|
|
/* Get the ProgID */
|
|
|
|
pOleStreamData[0].dwOleTypeNameLength = OLESTREAM_MAX_STR_LEN;
|
|
|
|
hRes = OLECONVERT_GetOLE10ProgID(pstg, pOleStreamData[0].strOleTypeName, &(pOleStreamData[0].dwOleTypeNameLength));
|
|
|
|
}
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
2002-01-31 22:01:35 +01:00
|
|
|
/* Was it originally Ole10 */
|
2002-06-01 01:06:46 +02:00
|
|
|
hRes = IStorage_OpenStream(pstg, wstrStreamName, 0, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &pStream);
|
2000-02-25 21:58:25 +01:00
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
|
|
|
IStream_Release(pStream);
|
2002-01-31 22:01:35 +01:00
|
|
|
/* Get Presentation Data for Ole10Native */
|
2000-02-25 21:58:25 +01:00
|
|
|
OLECONVERT_GetOle10PresData(pstg, pOleStreamData);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-01-31 22:01:35 +01:00
|
|
|
/* Get Presentation Data (OLE20) */
|
2000-02-25 21:58:25 +01:00
|
|
|
OLECONVERT_GetOle20PresData(pstg, pOleStreamData);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Save OLESTREAM */
|
|
|
|
hRes = OLECONVERT_SaveOLE10(&(pOleStreamData[0]), pOleStream);
|
|
|
|
if(hRes == S_OK)
|
|
|
|
{
|
|
|
|
hRes = OLECONVERT_SaveOLE10(&(pOleStreamData[1]), pOleStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free allocated memory */
|
|
|
|
for(i=0; i < 2; i++)
|
|
|
|
{
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,pOleStreamData[i].pData);
|
2000-02-25 21:58:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return hRes;
|
|
|
|
}
|
2001-04-09 20:33:03 +02:00
|
|
|
|
2001-04-25 21:54:21 +02:00
|
|
|
/***********************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* GetConvertStg (OLE32.@)
|
2001-04-25 21:54:21 +02:00
|
|
|
*/
|
2004-01-23 21:57:26 +01:00
|
|
|
HRESULT WINAPI GetConvertStg(IStorage *stg) {
|
|
|
|
FIXME("unimplemented stub!\n");
|
2001-04-09 20:33:03 +02:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
2002-11-18 20:43:58 +01:00
|
|
|
|
|
|
|
/******************************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* StgIsStorageFile [OLE32.@]
|
2006-02-24 18:06:35 +01:00
|
|
|
* Verify if the file contains a storage object
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* fn [ I] Filename
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* S_OK if file has magic bytes as a storage object
|
|
|
|
* S_FALSE if file is not storage
|
2002-11-18 20:43:58 +01:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI
|
|
|
|
StgIsStorageFile(LPCOLESTR fn)
|
|
|
|
{
|
|
|
|
HANDLE hf;
|
|
|
|
BYTE magic[8];
|
|
|
|
DWORD bytes_read;
|
|
|
|
|
2006-07-29 10:13:53 +02:00
|
|
|
TRACE("%s\n", debugstr_w(fn));
|
2002-11-18 20:43:58 +01:00
|
|
|
hf = CreateFileW(fn, GENERIC_READ,
|
|
|
|
FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
|
|
|
|
|
|
|
if (hf == INVALID_HANDLE_VALUE)
|
|
|
|
return STG_E_FILENOTFOUND;
|
|
|
|
|
|
|
|
if (!ReadFile(hf, magic, 8, &bytes_read, NULL))
|
|
|
|
{
|
|
|
|
WARN(" unable to read file\n");
|
|
|
|
CloseHandle(hf);
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(hf);
|
|
|
|
|
|
|
|
if (bytes_read != 8) {
|
|
|
|
WARN(" too short\n");
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!memcmp(magic,STORAGE_magic,8)) {
|
|
|
|
WARN(" -> YES\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN(" -> Invalid header.\n");
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
2006-08-16 14:00:02 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WriteClassStm (OLE32.@)
|
|
|
|
*
|
|
|
|
* Writes a CLSID to a stream.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pStm [I] Stream to write to.
|
|
|
|
* rclsid [I] CLSID to write.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK.
|
|
|
|
* Failure: HRESULT code.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI WriteClassStm(IStream *pStm,REFCLSID rclsid)
|
|
|
|
{
|
|
|
|
TRACE("(%p,%p)\n",pStm,rclsid);
|
|
|
|
|
2007-01-09 18:17:40 +01:00
|
|
|
if (!pStm || !rclsid)
|
2006-08-16 14:00:02 +02:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
return IStream_Write(pStm,rclsid,sizeof(CLSID),NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ReadClassStm (OLE32.@)
|
|
|
|
*
|
|
|
|
* Reads a CLSID from a stream.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pStm [I] Stream to read from.
|
|
|
|
* rclsid [O] CLSID to read.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK.
|
|
|
|
* Failure: HRESULT code.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI ReadClassStm(IStream *pStm,CLSID *pclsid)
|
|
|
|
{
|
|
|
|
ULONG nbByte;
|
|
|
|
HRESULT res;
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n",pStm,pclsid);
|
|
|
|
|
2007-01-09 18:17:40 +01:00
|
|
|
if (!pStm || !pclsid)
|
2006-08-16 14:00:02 +02:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2007-01-09 18:17:52 +01:00
|
|
|
/* clear the output args */
|
2008-03-10 22:58:43 +01:00
|
|
|
*pclsid = CLSID_NULL;
|
2007-01-09 18:17:52 +01:00
|
|
|
|
2006-08-16 14:00:02 +02:00
|
|
|
res = IStream_Read(pStm,(void*)pclsid,sizeof(CLSID),&nbByte);
|
|
|
|
|
|
|
|
if (FAILED(res))
|
|
|
|
return res;
|
|
|
|
|
|
|
|
if (nbByte != sizeof(CLSID))
|
2007-01-09 18:17:52 +01:00
|
|
|
return STG_E_READFAULT;
|
2006-08-16 14:00:02 +02:00
|
|
|
else
|
|
|
|
return S_OK;
|
|
|
|
}
|