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.

133 lines
3.6 KiB

  1. /*-----------------------------------------------------------------------------
  2. progress.cpp
  3. Download thread and progress update. Part of CRefDial
  4. History:
  5. 1/11/98 DONALDM Moved to new ICW project and string
  6. and nuked 16 bit stuff
  7. -----------------------------------------------------------------------------*/
  8. #include "stdafx.h"
  9. #include "icwhelp.h"
  10. #include "refdial.h"
  11. #include "icwdl.h"
  12. #define MAX_EXIT_RETRIES 10
  13. extern BOOL MinimizeRNAWindowEx();
  14. void WINAPI MyProgressCallBack
  15. (
  16. HINTERNET hInternet,
  17. DWORD_PTR dwContext,
  18. DWORD dwInternetStatus,
  19. LPVOID lpvStatusInformation,
  20. DWORD dwStatusInformationLength
  21. )
  22. {
  23. CRefDial *pRefDial = (CRefDial *)dwContext;
  24. int prc;
  25. if (!dwContext)
  26. return;
  27. switch(dwInternetStatus)
  28. {
  29. case CALLBACK_TYPE_PROGRESS:
  30. prc = *(int*)lpvStatusInformation;\
  31. // Set the status string ID
  32. pRefDial->m_DownloadStatusID = IDS_RECEIVING_RESPONSE;
  33. // Post a message to fire an event
  34. PostMessage(pRefDial->m_hWnd, WM_DOWNLOAD_PROGRESS, prc, 0);
  35. break;
  36. case CALLBACK_TYPE_URL:
  37. if (lpvStatusInformation)
  38. lstrcpy(pRefDial->m_szRefServerURL, (LPTSTR)lpvStatusInformation);
  39. break;
  40. default:
  41. TraceMsg(TF_GENERAL, TEXT("CONNECT:Unknown Internet Status (%d).\n"),dwInternetStatus);
  42. pRefDial->m_DownloadStatusID = 0;
  43. break;
  44. }
  45. }
  46. DWORD WINAPI DownloadThreadInit(LPVOID lpv)
  47. {
  48. HRESULT hr = ERROR_NOT_ENOUGH_MEMORY;
  49. CRefDial *pRefDial = (CRefDial*)lpv;
  50. HINSTANCE hDLDLL = NULL; // Download .DLL
  51. HINSTANCE hADDll = NULL;
  52. FARPROC fp;
  53. MinimizeRNAWindowEx();
  54. hDLDLL = LoadLibrary(DOWNLOAD_LIBRARY);
  55. if (!hDLDLL)
  56. {
  57. hr = ERROR_DOWNLOAD_NOT_FOUND;
  58. AssertMsg(0,TEXT("icwdl missing"));
  59. goto ThreadInitExit;
  60. }
  61. // Set up for download
  62. //
  63. fp = GetProcAddress(hDLDLL,DOWNLOADINIT);
  64. AssertMsg(fp != NULL,TEXT("DownLoadInit API missing"));
  65. hr = ((PFNDOWNLOADINIT)fp)(pRefDial->m_szUrl, (DWORD_PTR FAR *)pRefDial, &pRefDial->m_dwDownLoad, pRefDial->m_hWnd);
  66. if (hr != ERROR_SUCCESS)
  67. goto ThreadInitExit;
  68. // Set up call back for progress dialog
  69. //
  70. fp = GetProcAddress(hDLDLL,DOWNLOADSETSTATUS);
  71. Assert(fp);
  72. hr = ((PFNDOWNLOADSETSTATUS)fp)(pRefDial->m_dwDownLoad,(INTERNET_STATUS_CALLBACK)MyProgressCallBack);
  73. // Download stuff MIME multipart
  74. //
  75. fp = GetProcAddress(hDLDLL,DOWNLOADEXECUTE);
  76. Assert(fp);
  77. hr = ((PFNDOWNLOADEXECUTE)fp)(pRefDial->m_dwDownLoad);
  78. if (hr)
  79. {
  80. goto ThreadInitExit;
  81. }
  82. fp = GetProcAddress(hDLDLL,DOWNLOADPROCESS);
  83. Assert(fp);
  84. hr = ((PFNDOWNLOADPROCESS)fp)(pRefDial->m_dwDownLoad);
  85. if (hr)
  86. {
  87. goto ThreadInitExit;
  88. }
  89. hr = ERROR_SUCCESS;
  90. ThreadInitExit:
  91. // Clean up
  92. //
  93. if (pRefDial->m_dwDownLoad)
  94. {
  95. fp = GetProcAddress(hDLDLL,DOWNLOADCLOSE);
  96. Assert(fp);
  97. ((PFNDOWNLOADCLOSE)fp)(pRefDial->m_dwDownLoad);
  98. pRefDial->m_dwDownLoad = 0;
  99. }
  100. // Call the OnDownLoadCompelete method
  101. PostMessage(pRefDial->m_hWnd, WM_DOWNLOAD_DONE, 0, 0);
  102. // Free the libs used to do the download
  103. if (hDLDLL)
  104. FreeLibrary(hDLDLL);
  105. if (hADDll)
  106. FreeLibrary(hADDll);
  107. return hr;
  108. }