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.

307 lines
7.5 KiB

  1. #include "asctlpch.h"
  2. #include "asinsctl.h"
  3. #include "resource.h"
  4. #include "util2.h"
  5. #define WM_LAUNCHCOMPLETE WM_USER+121
  6. CProgressDlg::CProgressDlg(HINSTANCE hInst, HWND hParent, HWND hGrandParent, CInstallEngineCtl *ctl)
  7. {
  8. RECT r;
  9. dwBigGoal = 0;
  10. dwLittleGoal = 0;
  11. dwOldMinutesLeft = 0xffffffff;
  12. hProgText = NULL;
  13. hBigProg = NULL;
  14. hLittleProg = NULL;
  15. dwOldBytes = 0;
  16. LPSTR pszTitle = NULL;
  17. hDlg = CreateDialog(hInst, MAKEINTRESOURCE(IDD_PROGRESS), hGrandParent, ProgressDlgProc);
  18. // Get the Display title from inseng
  19. ctl->_pinseng->GetDisplayName(NULL, &pszTitle);
  20. ctl->_pinseng->SetHWND(hDlg);
  21. if(pszTitle)
  22. {
  23. SetWindowText(hDlg, pszTitle);
  24. CoTaskMemFree(pszTitle);
  25. }
  26. SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR) this);
  27. if(hGrandParent)
  28. {
  29. GetWindowRect(hGrandParent, &r);
  30. SetWindowPos(hDlg, 0, r.left, r.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
  31. }
  32. pinsengctl = ctl;
  33. pinsengctl->_pinseng->QueryInterface(IID_IInstallEngineTiming, (void **) &ptimer);
  34. }
  35. CProgressDlg::~CProgressDlg()
  36. {
  37. if(ptimer)
  38. ptimer->Release();
  39. pinsengctl->_pinseng->SetHWND(GetParent(hDlg));
  40. DestroyWindow(hDlg);
  41. }
  42. void CProgressDlg::DisplayWindow(BOOL fShow)
  43. {
  44. if(fShow)
  45. ShowWindow(hDlg, SW_SHOWNORMAL);
  46. else
  47. ShowWindow(hDlg, SW_HIDE);
  48. }
  49. INT_PTR CALLBACK ProgressDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  50. {
  51. switch (uMsg)
  52. {
  53. case WM_INITDIALOG:
  54. // Do some init stuff
  55. SetFontForControl(hwnd, IDC_PROG_TEXT);
  56. Animate_Open( GetDlgItem( hwnd, IDC_ANIM ), MAKEINTRESOURCE(IDA_FILECOPY) );
  57. Animate_Play( GetDlgItem( hwnd, IDC_ANIM ), 0, -1, -1 );
  58. return FALSE;
  59. case WM_COMMAND:
  60. switch (wParam)
  61. {
  62. case IDCANCEL:
  63. {
  64. char szBuf[256];
  65. char szTitle[128];
  66. HRESULT hr = S_FALSE;
  67. int id;
  68. CProgressDlg *p = (CProgressDlg *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  69. LoadSz(IDS_TITLE, szTitle, sizeof(szTitle));
  70. if(p->pinsengctl)
  71. hr = p->pinsengctl->_pinseng->Suspend();
  72. if(hr == S_FALSE)
  73. id = IDS_CONFIRMCANCEL_UNSAFE;
  74. else
  75. id = IDS_CONFIRMCANCEL;
  76. LoadSz(id, szBuf, sizeof(szBuf));
  77. if(MessageBox(hwnd, szBuf, szTitle, MB_YESNO | MB_ICONQUESTION) == IDYES)
  78. {
  79. if(p->pinsengctl)
  80. p->pinsengctl->_FireCancel(ABORTINSTALL_NORMAL);
  81. EnableWindow(GetDlgItem(hwnd, IDCANCEL), FALSE);
  82. }
  83. if(p->pinsengctl)
  84. p->pinsengctl->_pinseng->Resume();
  85. }
  86. break;
  87. default:
  88. return FALSE;
  89. }
  90. break;
  91. default:
  92. return(FALSE);
  93. }
  94. return TRUE;
  95. }
  96. void CProgressDlg::SetInsProgGoal(DWORD dwKBytes)
  97. {
  98. dwBigFactor = dwKBytes / 65000 + 1;
  99. dwBigGoal = dwKBytes;
  100. if(dwBigGoal == 0)
  101. dwBigGoal = 1;
  102. if(hBigProg == NULL)
  103. hBigProg = GetDlgItem(hDlg, IDC_PROG_BIG);
  104. SendMessage(hBigProg, PBM_SETRANGE, 0, MAKELPARAM(0, dwKBytes/dwBigFactor));
  105. }
  106. void CProgressDlg::SetDownloadProgGoal(DWORD dwKBytes)
  107. {
  108. dwLittleFactor = dwKBytes / 65000 + 1;
  109. dwLittleGoal = dwKBytes;
  110. if(dwLittleGoal == 0)
  111. dwLittleGoal = 1;
  112. if(hLittleProg == NULL)
  113. hLittleProg = GetDlgItem(hDlg, IDC_PROG_LITTLE);
  114. SendMessage(hLittleProg,PBM_SETRANGE,0,MAKELPARAM(0,dwKBytes/dwLittleFactor));
  115. SetDlgItemText(hDlg, IDC_LITTLETIMELEFT, "");
  116. dwOldMinutesLeft = 0xffffffff;
  117. }
  118. void CProgressDlg::SetInsProgress(DWORD dwKBytes)
  119. {
  120. INSTALLPROGRESS pinsprog;
  121. DWORD progress;
  122. DWORD bytessofar;
  123. char szRes[256];
  124. char szBuf[256];
  125. DWORD remaining;
  126. if( (dwOldBytes == 0) && (dwKBytes != 0) )
  127. {
  128. ShowWindow(GetDlgItem(hDlg, IDC_BYTESLEFT), SW_HIDE);
  129. ShowWindow(GetDlgItem(hDlg, IDC_LITTLETIMELEFT), SW_HIDE);
  130. }
  131. ptimer->GetInstallProgress(&pinsprog);
  132. remaining = pinsprog.dwInstallKBRemaining;
  133. progress = (dwBigGoal - remaining)/dwBigFactor;
  134. // write out bytes remiaining
  135. if(dwBigGoal >= remaining)
  136. bytessofar = dwBigGoal - remaining;
  137. else
  138. bytessofar = 0;
  139. if(dwOldBytes != bytessofar)
  140. {
  141. LoadSz(IDS_PERCENT, szRes, sizeof(szRes));
  142. wsprintf(szBuf, szRes, 100*bytessofar/dwBigGoal);
  143. SetDlgItemText(hDlg, IDC_PERCENT, szBuf);
  144. dwOldBytes = bytessofar;
  145. }
  146. if(hBigProg == NULL)
  147. hBigProg = GetDlgItem(hDlg, IDC_PROG_BIG);
  148. SendMessage(hBigProg, PBM_SETPOS, progress, 0);
  149. }
  150. void CProgressDlg::SetDownloadProgress(DWORD dwKBytes)
  151. {
  152. char szBuf[128];
  153. char szRes[128];
  154. INSTALLPROGRESS pinsprog;
  155. DWORD remaining;
  156. DWORD progress;
  157. DWORD bytessofar;
  158. ptimer->GetInstallProgress(&pinsprog);
  159. remaining = pinsprog.dwDownloadKBRemaining;
  160. progress = (dwLittleGoal - remaining)/dwLittleFactor;
  161. // write out bytes remiaining
  162. if(dwLittleGoal >= remaining)
  163. bytessofar = dwLittleGoal - remaining;
  164. else
  165. bytessofar = 0;
  166. if(dwOldBytes != bytessofar)
  167. {
  168. LoadSz(IDS_KBYTES , szRes, sizeof(szRes));
  169. wsprintf(szBuf, szRes, bytessofar, dwLittleGoal);
  170. SetDlgItemText(hDlg, IDC_BYTESLEFT, szBuf);
  171. dwOldBytes = bytessofar;
  172. }
  173. SendMessage(hLittleProg, PBM_SETPOS, progress, 0);
  174. remaining = pinsprog.dwDownloadSecsRemaining;
  175. if(remaining != 0xffffffff)
  176. UpdateLittleTime(remaining);
  177. }
  178. void CProgressDlg::SetProgText(LPCSTR psz)
  179. {
  180. if(hProgText == NULL)
  181. hProgText = GetDlgItem(hDlg, IDC_PROG_TEXT);
  182. SetWindowText(hProgText, psz);
  183. }
  184. void CProgressDlg::UpdateLittleTime(DWORD dwSecsLeft)
  185. {
  186. char szBuf[128];
  187. char szRes[128];
  188. szBuf[0] = 0;
  189. UINT id;
  190. UINT numParams = 2;
  191. DWORD dwHoursLeft = dwSecsLeft / 3600;
  192. DWORD dwMinutesLeft = (dwSecsLeft % 3600) / 60;
  193. if(dwMinutesLeft == 59)
  194. {
  195. dwHoursLeft++;
  196. dwMinutesLeft = 0;
  197. }
  198. // no need to update ui
  199. if(dwOldMinutesLeft == dwMinutesLeft)
  200. return;
  201. if(dwHoursLeft > 0)
  202. {
  203. if(dwHoursLeft > 1)
  204. {
  205. if(dwMinutesLeft == 0)
  206. {
  207. id = IDS_HOURSLEFT;
  208. numParams = 1;
  209. }
  210. else if(dwMinutesLeft == 1)
  211. {
  212. id = IDS_HOURSMINUTELEFT;
  213. }
  214. else
  215. id = IDS_HOURSMINUTESLEFT;
  216. }
  217. else
  218. {
  219. if(dwMinutesLeft == 0)
  220. {
  221. id = IDS_HOURLEFT;
  222. numParams = 1;
  223. }
  224. else if(dwMinutesLeft == 1)
  225. {
  226. id = IDS_HOURMINUTELEFT;
  227. }
  228. else
  229. id = IDS_HOURMINUTESLEFT;
  230. }
  231. LoadSz(id, szRes, sizeof(szRes));
  232. if(numParams == 1)
  233. wsprintf(szBuf, szRes, dwHoursLeft);
  234. else
  235. wsprintf(szBuf, szRes, dwHoursLeft, dwMinutesLeft);
  236. }
  237. else if(dwMinutesLeft > 0)
  238. {
  239. LoadSz(IDS_MINUTESLEFT , szRes, sizeof(szRes));
  240. wsprintf(szBuf, szRes, dwMinutesLeft + 1);
  241. }
  242. else
  243. LoadSz(IDS_SECONDSLEFT, szBuf, sizeof(szBuf));
  244. dwOldMinutesLeft = dwMinutesLeft;
  245. SetDlgItemText(hDlg, IDC_LITTLETIMELEFT, szBuf);
  246. }