Leaked source code of windows server 2003
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.

165 lines
6.1 KiB

  1. // Contents: CStorageProcessor class def'n
  2. #pragma once
  3. #include "resource.h" // main symbols
  4. #include <dpa.h>
  5. //
  6. // Map of storage operations -> string resources
  7. //
  8. typedef struct tagSTC_CR_PAIR
  9. {
  10. STGTRANSCONFIRMATION stc;
  11. CONFIRMATIONRESPONSE cr;
  12. bool operator==(const STGTRANSCONFIRMATION & r_stc) const { return TRUE==IsEqualIID(stc, r_stc); }
  13. tagSTC_CR_PAIR(STGTRANSCONFIRMATION o_stc, CONFIRMATIONRESPONSE o_cr) { stc=o_stc; cr=o_cr; }
  14. } STC_CR_PAIR;
  15. typedef struct tagSTGOP_DETAIL
  16. {
  17. STGOP stgop;
  18. UINT idTitle;
  19. UINT idPrep;
  20. SPACTION spa;
  21. } STGOP_DETAIL;
  22. // Maximum number of advise sinks that can be registered with us at any one time
  23. const DWORD MAX_SINK_COUNT = 32;
  24. class CStorageProcessor :
  25. public IStorageProcessor,
  26. public ITransferAdviseSink,
  27. public ISupportErrorInfo,
  28. public IOleWindow,
  29. public CComObjectRoot,
  30. public CComCoClass<CStorageProcessor,&CLSID_StorageProcessor>
  31. {
  32. public:
  33. CStorageProcessor();
  34. virtual ~CStorageProcessor();
  35. BEGIN_COM_MAP(CStorageProcessor)
  36. COM_INTERFACE_ENTRY(IStorageProcessor)
  37. COM_INTERFACE_ENTRY(ISupportErrorInfo)
  38. COM_INTERFACE_ENTRY(IOleWindow)
  39. END_COM_MAP()
  40. DECLARE_REGISTRY_RESOURCEID(IDR_StorageProcessor)
  41. // ISupportsErrorInfo
  42. STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
  43. // IStorageProcessor
  44. STDMETHOD(SetProgress)(IActionProgress *pap);
  45. STDMETHOD(Run)(IEnumShellItems *penum, IShellItem *psiDest, STGOP dwOperation, DWORD dwOptions);
  46. STDMETHOD(SetLinkFactory)(REFCLSID clsid);
  47. STDMETHOD(Advise)(ITransferAdviseSink *pAdvise, DWORD *dwCookie);
  48. STDMETHOD(Unadvise)(DWORD dwCookie);
  49. // IStorageAdciseSink
  50. STDMETHOD(PreOperation)(const STGOP op, IShellItem *psiItem, IShellItem *psiDest);
  51. STDMETHOD(ConfirmOperation)(IShellItem *psiSource, IShellItem *psiDest, STGTRANSCONFIRMATION stc, LPCUSTOMCONFIRMATION pcc);
  52. STDMETHOD(OperationProgress)(const STGOP op, IShellItem *psiItem, IShellItem *psiDest, ULONGLONG ullTotal, ULONGLONG ullComplete);
  53. STDMETHOD(PostOperation)(const STGOP op, IShellItem *psiItem, IShellItem *psiDest, HRESULT hrResult);
  54. STDMETHOD(QueryContinue)();
  55. // IOleWindow
  56. STDMETHOD(GetWindow) (HWND * lphwnd);
  57. STDMETHOD(ContextSensitiveHelp) (BOOL fEnterMode) { return E_NOTIMPL; };
  58. private:
  59. // The operation and options originally passed in
  60. STGOP _dwOperation;
  61. DWORD _dwOptions;
  62. CComPtr<ITransferAdviseSink> _aspSinks[MAX_SINK_COUNT];
  63. STDMETHOD(_Run)(IEnumShellItems *penum, IShellItem *psiDest, ITransferDest *ptdDest, STGOP dwOperation, DWORD dwOptions);
  64. // Walks the storage(s) performing whatever main operation has been requested
  65. HRESULT _WalkStorage(IShellItem *psi, IShellItem *psiDest, ITransferDest *ptdDest);
  66. HRESULT _WalkStorage(IEnumShellItems *penum, IShellItem *psiDest, ITransferDest *ptdDest);
  67. // Worker functions that perform the bulk of the actual storage work. The
  68. // storage operations are recursive (ie: DoRemoveStorage will prune an entire branch).
  69. HRESULT _DoStats(IShellItem *psi);
  70. HRESULT _DoCopy(IShellItem *psi, IShellItem *psiDest, ITransferDest *ptdDest, DWORD dwStgXFlags);
  71. HRESULT _DoMove(IShellItem *psi, IShellItem *psiDest, ITransferDest *ptdDest);
  72. HRESULT _DoRemove(IShellItem *psi, IShellItem *psiDest, ITransferDest *ptdDest);
  73. HRESULT _GetDefaultResponse(STGTRANSCONFIRMATION stc, LPCONFIRMATIONRESPONSE pcrResponse);
  74. // Takes the current error code and massages it based on the result of
  75. // a current or previous user response to a confirmation dialog
  76. HRESULT _DoConfirmations(STGTRANSCONFIRMATION stc, CUSTOMCONFIRMATION *pcc, IShellItem *psiSource, IShellItem *psiDest);
  77. BOOL _IsStream(IShellItem *psi);
  78. BOOL _ShouldWalk(IShellItem *psi);
  79. ULONGLONG _GetSize(IShellItem *psi);
  80. HRESULT _BindToHandlerWithMode(IShellItem *psi, STGXMODE grfMode, REFIID riid, void **ppv);
  81. // Updates the time estimate, and if the dialog is being used, it as well
  82. void _UpdateProgress(ULONGLONG ullCurrentComplete, ULONGLONG ullCurrentTotal);
  83. // Starts the progress dialog
  84. HRESULT _StartProgressDialog(const STGOP_DETAIL *popid);
  85. // CStgStatistics
  86. //
  87. // Wrapper for STGSTATS that provides some accounting helper functions
  88. class CStgStatistics
  89. {
  90. public:
  91. CStgStatistics()
  92. {
  93. }
  94. ULONGLONG Bytes() const { return _cbSize; }
  95. DWORD Streams() const { return _cStreams; }
  96. DWORD Storages() const { return _cStorages; }
  97. ULONGLONG Cost(DWORD, ULONGLONG cbExtra) const;
  98. DWORD AddStream(ULONGLONG cbSize);
  99. DWORD AddStorage();
  100. private:
  101. ULONGLONG _cbSize;
  102. DWORD _cStreams;
  103. DWORD _cStorages;
  104. };
  105. CStgStatistics _statsTodo;
  106. CStgStatistics _statsDone;
  107. DWORD _msTicksLast; // Tick count at last point update
  108. DWORD _msStarted; // When we started tracking points
  109. ULONGLONG _cbCurrentSize;
  110. DWORD _StreamsToDo() const { return _statsTodo.Streams(); }
  111. DWORD _StoragesToDo() const { return _statsTodo.Storages(); }
  112. // Progress dialog. Pointer will be NULL if no progress is requrested.
  113. CComPtr<IActionProgress> _spProgress;
  114. CComPtr<IActionProgressDialog> _spShellProgress;
  115. CComPtr<ITransferDest> _spSrc;
  116. CComPtr<ITransferDest> _spDest;
  117. ITransferConfirmation *_ptc;
  118. const STATSTG *_pstatSrc;
  119. CLSID _clsidLinkFactory;
  120. // A tree (map) of responses given to various previous confirmations
  121. CDSA<STC_CR_PAIR> _dsaConfirmationResponses;
  122. };
  123. STDAPI CreateStg2StgExWrapper(IShellItem *psi, IStorageProcessor *pEngine, ITransferDest **pptd);
  124. HRESULT AutoCreateName(IShellItem *psiDest, IShellItem *psi, LPWSTR *ppszName);
  125. HRESULT TransferDataObject(IDataObject *pdoSource, IShellItem *psiDest, STGOP dwOperation, DWORD dwOptions, ITransferAdviseSink *ptas);