1
0

MyProgress.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #include "MyProgress.h"
  2. extern LPARAM ipc_transfer;
  3. MyProgress::MyProgress(TransferItem *_t)
  4. : t(_t), refcount(1), estTicks(0)
  5. {
  6. }
  7. MyProgress::~MyProgress() {}
  8. HRESULT MyProgress::Begin(DWORD dwEstimatedTicks)
  9. {
  10. estTicks = dwEstimatedTicks / 100;
  11. return S_OK;
  12. }
  13. HRESULT MyProgress::Progress(DWORD dwTranspiredTicks)
  14. {
  15. if (estTicks > 0) {
  16. int pc = dwTranspiredTicks / estTicks;
  17. if(pc > 100) pc = 100;
  18. t->pc = pc;
  19. }
  20. else t->pc = 0;
  21. wchar_t buf[100] = {0};
  22. wsprintf(buf,WASABI_API_LNGSTRINGW(IDS_TRANSFERRING_PERCENT), t->pc);
  23. t->callback(t->callbackContext,buf);
  24. if (*(t->killswitch))
  25. return WMDM_E_USER_CANCELLED;
  26. return S_OK;
  27. }
  28. #define PHASE_START 1
  29. #define PHASE_INPROGRESS 2
  30. #define PHASE_FINISH 3
  31. #define PHASE_DONE 4
  32. #define PHASE_ERROR 5
  33. HRESULT MyProgress::End()
  34. {
  35. t->phase = PHASE_FINISH;
  36. return S_OK;
  37. }
  38. #define IMPLEMENTS(ifc) if (riid == IID_ ## ifc) { ++refcount; *ppvObject = static_cast<ifc *>(this); return S_OK; }
  39. HRESULT MyProgress::QueryInterface(REFIID riid,void __RPC_FAR *__RPC_FAR *ppvObject)
  40. {
  41. IMPLEMENTS(IUnknown);
  42. IMPLEMENTS(IWMDMProgress);
  43. IMPLEMENTS(IWMDMProgress2);
  44. IMPLEMENTS(IWMDMProgress3);
  45. *ppvObject = NULL;
  46. return E_NOINTERFACE;
  47. }
  48. ULONG MyProgress::AddRef()
  49. {
  50. return ++refcount;
  51. }
  52. ULONG MyProgress::Release()
  53. {
  54. int x = --refcount;
  55. if (x == 0)
  56. delete this;
  57. return x;
  58. }
  59. HRESULT MyProgress::End2(HRESULT hrCompletionCode)
  60. {
  61. return End();
  62. }
  63. HRESULT MyProgress::Begin3(GUID EventId,DWORD dwEstimatedTicks,OPAQUECOMMAND* pContext)
  64. {
  65. return Begin(dwEstimatedTicks);
  66. }
  67. HRESULT MyProgress::Progress3(GUID EventId,DWORD dwTranspiredTicks,OPAQUECOMMAND* pContext)
  68. {
  69. return Progress(dwTranspiredTicks);
  70. }
  71. HRESULT MyProgress::End3(GUID EventId,HRESULT hrCompletionCode,OPAQUECOMMAND* pContext)
  72. {
  73. return End2( hrCompletionCode);
  74. }