Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

405 lines
14 KiB

  1. // Storage.h -- Definition of class CStorage
  2. #ifndef __STORAGE_H__
  3. #define __STORAGE_H__
  4. class CStorage : public CITUnknown
  5. {
  6. public:
  7. static HRESULT __stdcall OpenStorage(IUnknown *pUnkOuter,
  8. IITFileSystem *pITFS,
  9. PathInfo *pPathInfo,
  10. DWORD grfMode,
  11. IStorageITEx **ppStg
  12. );
  13. static BOOL ValidStreamName(const WCHAR *pwcsName);
  14. ~CStorage(void);
  15. class CImpIStorage : public IIT_IStorageITEx
  16. {
  17. public:
  18. CImpIStorage(CStorage *pBackObj, IUnknown *punkOuter);
  19. ~CImpIStorage(void);
  20. static IStorage *FindStorage(const WCHAR * pwszFileName, DWORD grfMode);
  21. HRESULT __stdcall InitOpenStorage(IITFileSystem *pITFS, PathInfo *pPathInfo,
  22. DWORD grfMode);
  23. // IUnknown methods:
  24. STDMETHODIMP_(ULONG) Release(void);
  25. // IStorage methods:
  26. HRESULT __stdcall CreateStream(
  27. /* [string][in] */ const OLECHAR __RPC_FAR *pwcsName,
  28. /* [in] */ DWORD grfMode,
  29. /* [in] */ DWORD reserved1,
  30. /* [in] */ DWORD reserved2,
  31. /* [out] */ IStream __RPC_FAR *__RPC_FAR *ppstm);
  32. HRESULT __stdcall CreateStreamITEx(
  33. /* [string][in] */ const OLECHAR __RPC_FAR *pwcsName,
  34. /* [string][in] */ const WCHAR *pwcsDataSpaceName,
  35. /* [in] */ DWORD grfMode,
  36. /* [in] */ DWORD reserved1,
  37. /* [in] */ DWORD reserved2,
  38. /* [out] */ IStreamITEx __RPC_FAR *__RPC_FAR *ppstm);
  39. /* [local] */ HRESULT __stdcall OpenStream(
  40. /* [string][in] */ const OLECHAR __RPC_FAR *pwcsName,
  41. /* [unique][in] */ void __RPC_FAR *reserved1,
  42. /* [in] */ DWORD grfMode,
  43. /* [in] */ DWORD reserved2,
  44. /* [out] */ IStream __RPC_FAR *__RPC_FAR *ppstm);
  45. /* [local] */ HRESULT __stdcall OpenStreamITEx(
  46. /* [string][in] */ const OLECHAR __RPC_FAR *pwcsName,
  47. /* [unique][in] */ void __RPC_FAR *reserved1,
  48. /* [in] */ DWORD grfMode,
  49. /* [in] */ DWORD reserved2,
  50. /* [out] */ IStreamITEx __RPC_FAR *__RPC_FAR *ppstm);
  51. HRESULT __stdcall CreateStorage(
  52. /* [string][in] */ const OLECHAR __RPC_FAR *pwcsName,
  53. /* [in] */ DWORD grfMode,
  54. /* [in] */ DWORD dwStgFmt,
  55. /* [in] */ DWORD reserved2,
  56. /* [out] */ IStorage __RPC_FAR *__RPC_FAR *ppstg);
  57. HRESULT __stdcall OpenStorage(
  58. /* [string][unique][in] */ const OLECHAR __RPC_FAR *pwcsName,
  59. /* [unique][in] */ IStorage __RPC_FAR *pstgPriority,
  60. /* [in] */ DWORD grfMode,
  61. /* [unique][in] */ SNB snbExclude,
  62. /* [in] */ DWORD reserved,
  63. /* [out] */ IStorage __RPC_FAR *__RPC_FAR *ppstg);
  64. HRESULT __stdcall CopyTo(
  65. /* [in] */ DWORD ciidExclude,
  66. /* [size_is][unique][in] */ const IID __RPC_FAR *rgiidExclude,
  67. /* [unique][in] */ SNB snbExclude,
  68. /* [unique][in] */ IStorage __RPC_FAR *pstgDest);
  69. HRESULT __stdcall MoveElementTo(
  70. /* [string][in] */ const OLECHAR __RPC_FAR *pwcsName,
  71. /* [unique][in] */ IStorage __RPC_FAR *pstgDest,
  72. /* [string][in] */ const OLECHAR __RPC_FAR *pwcsNewName,
  73. /* [in] */ DWORD grfFlags);
  74. HRESULT __stdcall Commit(
  75. /* [in] */ DWORD grfCommitFlags);
  76. HRESULT __stdcall Revert( void);
  77. /* [local] */ HRESULT __stdcall EnumElements(
  78. /* [in] */ DWORD reserved1,
  79. /* [size_is][unique][in] */ void __RPC_FAR *reserved2,
  80. /* [in] */ DWORD reserved3,
  81. /* [out] */ IEnumSTATSTG __RPC_FAR *__RPC_FAR *ppenum);
  82. HRESULT __stdcall DestroyElement(
  83. /* [string][in] */ const OLECHAR __RPC_FAR *pwcsName);
  84. HRESULT __stdcall RenameElement(
  85. /* [string][in] */ const OLECHAR __RPC_FAR *pwcsOldName,
  86. /* [string][in] */ const OLECHAR __RPC_FAR *pwcsNewName);
  87. HRESULT __stdcall SetElementTimes(
  88. /* [string][in] */ const OLECHAR __RPC_FAR *pwcsName,
  89. /* [in] */ const FILETIME __RPC_FAR *pctime,
  90. /* [in] */ const FILETIME __RPC_FAR *patime,
  91. /* [in] */ const FILETIME __RPC_FAR *pmtime);
  92. HRESULT __stdcall SetClass(
  93. /* [in] */ REFCLSID clsid);
  94. HRESULT __stdcall SetStateBits(
  95. /* [in] */ DWORD grfStateBits,
  96. /* [in] */ DWORD grfMask);
  97. HRESULT __stdcall Stat(
  98. /* [out] */ STATSTG __RPC_FAR *pstatstg,
  99. /* [in] */ DWORD grfStatFlag);
  100. // IStorageITEx methods
  101. HRESULT STDMETHODCALLTYPE GetCheckSum(ULARGE_INTEGER *puli);
  102. HRESULT STDMETHODCALLTYPE CreateStream
  103. (const WCHAR * pwcsName, const WCHAR *pwcsDataSpaceName,
  104. DWORD grfMode, DWORD reserved1, DWORD reserved2,
  105. IStreamITEx ** ppstm
  106. );
  107. HRESULT STDMETHODCALLTYPE OpenStream
  108. (const WCHAR * pwcsName, void * reserved1, DWORD grfMode,
  109. DWORD reserved2, IStreamITEx ** ppstm
  110. );
  111. private:
  112. enum { MAX_KEY = MAX_UTF8_PATH + 5 }; // Extra bytes for leading pack-32
  113. // name length value.
  114. IITFileSystem *m_pITFS; // File system which contains this storage
  115. PathInfo m_PathInfo; // Path for this storage together with location info
  116. DWORD m_grfMode; // Access permissions for this storage.
  117. BOOL m_fWritable; // Can we write to this file system?
  118. DEBUGDEF(static LONG s_cInCriticalSection)
  119. };
  120. private:
  121. CStorage(IUnknown *pUnkOuter);
  122. CImpIStorage m_ImpIStorage;
  123. };
  124. extern GUID aIID_CStorage[];
  125. extern UINT cInterfaces_CStorage;
  126. inline CStorage::CStorage(IUnknown *pUnkOuter)
  127. : m_ImpIStorage(this, pUnkOuter),
  128. CITUnknown(aIID_CStorage, cInterfaces_CStorage, (IUnknown *) &m_ImpIStorage)
  129. {
  130. }
  131. inline CStorage::~CStorage(void)
  132. {
  133. }
  134. typedef CStorage *PCStorage;
  135. class CFSStorage : public CITUnknown
  136. {
  137. public:
  138. static HRESULT __stdcall CreateStorage
  139. (IUnknown *pUnkOuter, const WCHAR *pwcsPath, DWORD grfMode,
  140. IStorage **ppStg
  141. );
  142. static HRESULT __stdcall OpenStorage
  143. (IUnknown *pUnkOuter, const WCHAR *pwcsPath, DWORD grfMode,
  144. IStorage **ppStg
  145. );
  146. ~CFSStorage(void);
  147. class CImpIFSStorage : public IIT_IStorage
  148. {
  149. public:
  150. CImpIFSStorage(CFSStorage *pBackObj, IUnknown *punkOuter);
  151. ~CImpIFSStorage(void);
  152. static IStorage *FindStorage(const WCHAR * pwszFileName, DWORD grfMode);
  153. HRESULT __stdcall InitCreateStorage(const WCHAR *pwcsPath, DWORD grfMode);
  154. HRESULT __stdcall InitOpenStorage (const WCHAR *pwcsPath, DWORD grfMode);
  155. // IUnknown methods:
  156. STDMETHODIMP_(ULONG) Release(void);
  157. // IStorage methods:
  158. HRESULT __stdcall CreateStream(
  159. /* [string][in] */ const OLECHAR __RPC_FAR *pwcsName,
  160. /* [in] */ DWORD grfMode,
  161. /* [in] */ DWORD reserved1,
  162. /* [in] */ DWORD reserved2,
  163. /* [out] */ IStream __RPC_FAR *__RPC_FAR *ppstm);
  164. /* [local] */ HRESULT __stdcall OpenStream(
  165. /* [string][in] */ const OLECHAR __RPC_FAR *pwcsName,
  166. /* [unique][in] */ void __RPC_FAR *reserved1,
  167. /* [in] */ DWORD grfMode,
  168. /* [in] */ DWORD reserved2,
  169. /* [out] */ IStream __RPC_FAR *__RPC_FAR *ppstm);
  170. HRESULT __stdcall CreateStorage(
  171. /* [string][in] */ const OLECHAR __RPC_FAR *pwcsName,
  172. /* [in] */ DWORD grfMode,
  173. /* [in] */ DWORD dwStgFmt,
  174. /* [in] */ DWORD reserved2,
  175. /* [out] */ IStorage __RPC_FAR *__RPC_FAR *ppstg);
  176. HRESULT __stdcall OpenStorage(
  177. /* [string][unique][in] */ const OLECHAR __RPC_FAR *pwcsName,
  178. /* [unique][in] */ IStorage __RPC_FAR *pstgPriority,
  179. /* [in] */ DWORD grfMode,
  180. /* [unique][in] */ SNB snbExclude,
  181. /* [in] */ DWORD reserved,
  182. /* [out] */ IStorage __RPC_FAR *__RPC_FAR *ppstg);
  183. HRESULT __stdcall CopyTo(
  184. /* [in] */ DWORD ciidExclude,
  185. /* [size_is][unique][in] */ const IID __RPC_FAR *rgiidExclude,
  186. /* [unique][in] */ SNB snbExclude,
  187. /* [unique][in] */ IStorage __RPC_FAR *pstgDest);
  188. HRESULT __stdcall MoveElementTo(
  189. /* [string][in] */ const OLECHAR __RPC_FAR *pwcsName,
  190. /* [unique][in] */ IStorage __RPC_FAR *pstgDest,
  191. /* [string][in] */ const OLECHAR __RPC_FAR *pwcsNewName,
  192. /* [in] */ DWORD grfFlags);
  193. HRESULT __stdcall Commit(
  194. /* [in] */ DWORD grfCommitFlags);
  195. HRESULT __stdcall Revert( void);
  196. /* [local] */ HRESULT __stdcall EnumElements(
  197. /* [in] */ DWORD reserved1,
  198. /* [size_is][unique][in] */ void __RPC_FAR *reserved2,
  199. /* [in] */ DWORD reserved3,
  200. /* [out] */ IEnumSTATSTG __RPC_FAR *__RPC_FAR *ppenum);
  201. HRESULT __stdcall DestroyElement(
  202. /* [string][in] */ const OLECHAR __RPC_FAR *pwcsName);
  203. HRESULT __stdcall RenameElement(
  204. /* [string][in] */ const OLECHAR __RPC_FAR *pwcsOldName,
  205. /* [string][in] */ const OLECHAR __RPC_FAR *pwcsNewName);
  206. HRESULT __stdcall SetElementTimes(
  207. /* [string][in] */ const OLECHAR __RPC_FAR *pwcsName,
  208. /* [in] */ const FILETIME __RPC_FAR *pctime,
  209. /* [in] */ const FILETIME __RPC_FAR *patime,
  210. /* [in] */ const FILETIME __RPC_FAR *pmtime);
  211. HRESULT __stdcall SetClass(
  212. /* [in] */ REFCLSID clsid);
  213. HRESULT __stdcall SetStateBits(
  214. /* [in] */ DWORD grfStateBits,
  215. /* [in] */ DWORD grfMask);
  216. HRESULT __stdcall Stat(
  217. /* [out] */ STATSTG __RPC_FAR *pstatstg,
  218. /* [in] */ DWORD grfStatFlag);
  219. private:
  220. class CFSEnumStorage : public CITUnknown
  221. {
  222. public:
  223. static HRESULT NewEnumStorage
  224. (IUnknown *pUnkOuter,
  225. CONST WCHAR *pwcsPath,
  226. IEnumSTATSTG **ppEnumSTATSTG
  227. );
  228. ~CFSEnumStorage(void);
  229. private:
  230. CFSEnumStorage(IUnknown *pUnkOuter);
  231. class CImpIEnumStorage : public IITEnumSTATSTG
  232. {
  233. public:
  234. CImpIEnumStorage(CFSEnumStorage *pBackObj, IUnknown *punkOuter);
  235. ~CImpIEnumStorage(void);
  236. HRESULT Initial(CONST WCHAR *pwcsPath);
  237. // IEnumSTATSTG methods:
  238. /* [local] */ HRESULT __stdcall Next(
  239. /* [in] */ ULONG celt,
  240. /* [in] */ STATSTG __RPC_FAR *rgelt,
  241. /* [out] */ ULONG __RPC_FAR *pceltFetched);
  242. HRESULT __stdcall Skip(
  243. /* [in] */ ULONG celt);
  244. HRESULT __stdcall Reset( void);
  245. HRESULT __stdcall Clone(
  246. /* [out] */ IEnumSTATSTG __RPC_FAR *__RPC_FAR *ppenum);
  247. HRESULT STDMETHODCALLTYPE GetNextEntryInSeq(/* [in] */ULONG celt,
  248. /* [out] */ PathInfo *rgelt,
  249. /* [out] */ ULONG *pceltFetched);
  250. HRESULT STDMETHODCALLTYPE GetFirstEntryInSeq(
  251. /* [out] */ PathInfo *rgelt);
  252. private:
  253. HRESULT STDMETHODCALLTYPE NextEntry();
  254. enum EnumState { Before, During, After };
  255. WCHAR m_awszBasePath[MAX_PATH];
  256. HANDLE m_hEnum;
  257. enum EnumState m_State;
  258. WIN32_FIND_DATA m_w32fd;
  259. };
  260. CImpIEnumStorage m_ImpIEnumStorage;
  261. };
  262. WCHAR m_awcsPath[MAX_PATH]; // Path for this storage
  263. UINT m_CP; // Default code page
  264. DWORD m_grfMode; // Access permissions for this storage.
  265. BOOL m_fWritable; // Can we write to this file system?
  266. DEBUGDEF(static LONG s_cInCriticalSection)
  267. };
  268. private:
  269. CFSStorage(IUnknown *pUnkOuter);
  270. CImpIFSStorage m_ImpIFSStorage;
  271. };
  272. inline CFSStorage::CFSStorage(IUnknown *pUnkOuter)
  273. : m_ImpIFSStorage(this, pUnkOuter),
  274. CITUnknown(&IID_IStorage, 1, (IUnknown *) &m_ImpIFSStorage)
  275. {
  276. }
  277. inline CFSStorage::~CFSStorage(void)
  278. {
  279. }
  280. inline CFSStorage::CImpIFSStorage::CFSEnumStorage::CFSEnumStorage(IUnknown *pUnkOuter)
  281. : m_ImpIEnumStorage(this, pUnkOuter),
  282. CITUnknown(&IID_IEnumSTATSTG, 1, &m_ImpIEnumStorage)
  283. {
  284. }
  285. inline CFSStorage::CImpIFSStorage::CFSEnumStorage::~CFSEnumStorage(void)
  286. {
  287. }
  288. HRESULT __stdcall ResolvePath(PWCHAR pwcFullPath, const WCHAR *pwcBasePath,
  289. const WCHAR *pwcRelativePath,
  290. BOOL fStoragePath
  291. );
  292. HRESULT __stdcall BuildMultiBytePath(UINT codepage, PCHAR pszPath, PWCHAR pwcsPath);
  293. typedef CFSStorage *PCFSStorage;
  294. #endif // __STORAGE_H__