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.

171 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. // Based on the user's answers to previous confirmations, returns the
  74. // appropriate CreateStorage() or OpenStorage() flags
  75. DWORD _GetCreateStorageFlags();
  76. DWORD _GetOpenStorageFlags();
  77. HRESULT _GetDefaultResponse(STGTRANSCONFIRMATION stc, LPCONFIRMATIONRESPONSE pcrResponse);
  78. // Takes the current error code and massages it based on the result of
  79. // a current or previous user response to a confirmation dialog
  80. HRESULT _DoConfirmations(STGTRANSCONFIRMATION stc, CUSTOMCONFIRMATION *pcc, IShellItem *psiSource, IShellItem *psiDest);
  81. BOOL _IsStream(IShellItem *psi);
  82. BOOL _ShouldWalk(IShellItem *psi);
  83. ULONGLONG _GetSize(IShellItem *psi);
  84. HRESULT _BindToHandlerWithMode(IShellItem *psi, STGXMODE grfMode, REFIID riid, void **ppv);
  85. // Updates the time estimate, and if the dialog is being used, it as well
  86. void _UpdateProgress(ULONGLONG ullCurrentComplete, ULONGLONG ullCurrentTotal);
  87. // Starts the progress dialog
  88. HRESULT _StartProgressDialog(const STGOP_DETAIL *popid);
  89. // CStgStatistics
  90. //
  91. // Wrapper for STGSTATS that provides some accounting helper functions
  92. class CStgStatistics
  93. {
  94. public:
  95. CStgStatistics()
  96. {
  97. }
  98. ULONGLONG Bytes() const { return _cbSize; }
  99. DWORD Streams() const { return _cStreams; }
  100. DWORD Storages() const { return _cStorages; }
  101. ULONGLONG Cost(DWORD, ULONGLONG cbExtra) const;
  102. DWORD AddStream(ULONGLONG cbSize);
  103. DWORD AddStorage();
  104. private:
  105. ULONGLONG _cbSize;
  106. DWORD _cStreams;
  107. DWORD _cStorages;
  108. };
  109. CStgStatistics _statsTodo;
  110. CStgStatistics _statsDone;
  111. DWORD _msTicksLast; // Tick count at last point update
  112. DWORD _msStarted; // When we started tracking points
  113. ULONGLONG _cbCurrentSize;
  114. DWORD _StreamsToDo() const { return _statsTodo.Streams(); }
  115. DWORD _StoragesToDo() const { return _statsTodo.Storages(); }
  116. // Progress dialog. Pointer will be NULL if no progress is requrested.
  117. CComPtr<IActionProgress> _spProgress;
  118. CComPtr<IActionProgressDialog> _spShellProgress;
  119. CComPtr<ITransferDest> _spSrc;
  120. CComPtr<ITransferDest> _spDest;
  121. ITransferConfirmation *_ptc;
  122. const STATSTG *_pstatSrc;
  123. CLSID _clsidLinkFactory;
  124. // A tree (map) of responses given to various previous confirmations
  125. CDSA<STC_CR_PAIR> _dsaConfirmationResponses;
  126. };
  127. STDAPI CreateStg2StgExWrapper(IShellItem *psi, IStorageProcessor *pEngine, ITransferDest **pptd);
  128. HRESULT AutoCreateName(IShellItem *psiDest, IShellItem *psi, LPWSTR *ppszName);
  129. HRESULT TransferDataObject(IDataObject *pdoSource, IShellItem *psiDest, STGOP dwOperation, DWORD dwOptions, ITransferAdviseSink *ptas);