WOL_DNLD.CPP 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. #ifdef WOLAPI_INTEGRATION
  15. // Wol_Dnld.cpp - WW online patch download dialog.
  16. // ajw 10/12/98
  17. #include "function.h"
  18. #include "WolapiOb.h"
  19. #include "WolStrng.h"
  20. //***********************************************************************************************
  21. bool WOL_Download_Dialog( IDownload* pDownload, RADownloadEventSink* pDownloadSink, const char* szTitle )
  22. {
  23. // This dialog is presented for each file that is to be downloaded during a WOLAPI patch.
  24. bool bReturn = true;
  25. DWORD dwTimeNextPump = ::timeGetTime() + WOLAPIPUMPWAIT;
  26. /*
  27. ** Dialog & button dimensions
  28. */
  29. int d_dialog_w = 200*RESFACTOR; // dialog width
  30. int d_dialog_h = 90*RESFACTOR; // dialog height
  31. int d_dialog_x = ((320*RESFACTOR - d_dialog_w) / 2); // dialog x-coord
  32. int d_dialog_y = ((200*RESFACTOR - d_dialog_h) / 2); // centered y-coord
  33. int d_dialog_cx = d_dialog_x + (d_dialog_w / 2); // center x-coord
  34. int d_margin = 34;
  35. int d_txt6_h = 15;
  36. #if (GERMAN | FRENCH)
  37. int d_cancel_w = 50*RESFACTOR;
  38. #else
  39. int d_cancel_w = 40*RESFACTOR;
  40. #endif
  41. int d_cancel_h = 9*RESFACTOR;
  42. int d_cancel_x = d_dialog_cx - d_cancel_w / 2;
  43. int d_cancel_y = d_dialog_y + d_dialog_h - 20*RESFACTOR;
  44. int d_progress_w = 100*RESFACTOR;
  45. int d_progress_h = 10*RESFACTOR;
  46. int d_progress_x = (SeenBuff.Get_Width()/2) - d_progress_w/2;
  47. int d_progress_y = d_dialog_y + 45*RESFACTOR;
  48. // int width;
  49. // int height;
  50. // char* info_string = (char*)szTitle;
  51. Fancy_Text_Print( TXT_NONE, 0, 0, GadgetClass::Get_Color_Scheme(),
  52. TBLACK, TPF_CENTER|TPF_6PT_GRAD|TPF_USE_GRAD_PAL|TPF_NOSHADOW );
  53. // Format_Window_String( info_string, SeenBuff.Get_Height(), width, height );
  54. /*
  55. ** Button Enumerations
  56. */
  57. enum {
  58. BUTTON_CANCEL = 100,
  59. BUTTON_PROGRESS
  60. };
  61. /*
  62. ** Buttons
  63. */
  64. TextButtonClass cancelbtn( BUTTON_CANCEL, TXT_CANCEL, TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  65. #if (GERMAN | FRENCH)
  66. d_cancel_x, d_cancel_y );
  67. #else
  68. d_cancel_x, d_cancel_y, d_cancel_w, d_cancel_h );
  69. #endif
  70. GaugeClass progress_meter( BUTTON_PROGRESS, d_progress_x, d_progress_y, d_progress_w, d_progress_h );
  71. progress_meter.Use_Thumb( 0 );
  72. StaticButtonClass StatTitle( 0, szTitle, TPF_CENTER|TPF_TEXT, d_dialog_x + d_margin, d_dialog_y + 28, d_dialog_w - 2 * d_margin, d_txt6_h );
  73. StaticButtonClass StatStatus( 0, "", TPF_CENTER|TPF_TEXT, d_dialog_x + d_margin, d_dialog_y + 49, d_dialog_w - 2 * d_margin, d_txt6_h );
  74. StaticButtonClass StatBytes( 0, "", TPF_CENTER|TPF_TEXT, d_dialog_x + d_margin, d_dialog_y + 71, d_dialog_w - 2 * d_margin, d_txt6_h );
  75. StaticButtonClass StatTime( 0, "", TPF_CENTER|TPF_TEXT, d_dialog_x + d_margin, d_dialog_y + 117, d_dialog_w - 2 * d_margin, d_txt6_h );
  76. typedef enum {
  77. REDRAW_NONE = 0,
  78. REDRAW_PROGRESS,
  79. REDRAW_BUTTONS,
  80. REDRAW_BACKGROUND,
  81. REDRAW_ALL = REDRAW_BACKGROUND
  82. } RedrawType;
  83. bool process = true;
  84. RedrawType display = REDRAW_ALL; // redraw level
  85. KeyNumType input;
  86. GadgetClass* commands; // button list
  87. commands = &cancelbtn;
  88. progress_meter.Add_Tail(*commands);
  89. StatTitle.Add_Tail(*commands);
  90. StatBytes.Add_Tail(*commands);
  91. StatTime.Add_Tail(*commands);
  92. StatStatus.Add_Tail(*commands);
  93. progress_meter.Set_Maximum(100); // Max is 100%
  94. progress_meter.Set_Value(0); // Current is 0%
  95. do {
  96. #ifdef WIN32
  97. /*
  98. ** If we have just received input focus again after running in the background then
  99. ** we need to redraw.
  100. */
  101. if (AllSurfaces.SurfacesRestored) {
  102. AllSurfaces.SurfacesRestored=FALSE;
  103. display = REDRAW_ALL;
  104. }
  105. #endif
  106. if (display){
  107. if (display >= REDRAW_BACKGROUND){
  108. Hide_Mouse();
  109. /*
  110. ** Redraw backgound & dialog box
  111. */
  112. Load_Title_Page(true);
  113. Set_Palette(CCPalette);
  114. Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
  115. /*
  116. ** Dialog & Field labels
  117. */
  118. Draw_Caption (TXT_NONE, d_dialog_x, d_dialog_y, d_dialog_w);
  119. // Fancy_Text_Print(info_string, d_dialog_cx-width/2, d_dialog_y + 25*RESFACTOR,
  120. // GadgetClass::Get_Color_Scheme(), TBLACK,
  121. // TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  122. Show_Mouse();
  123. }
  124. if (display >= REDRAW_BUTTONS){
  125. commands->Draw_All();
  126. }
  127. if (display >= REDRAW_PROGRESS){
  128. progress_meter.Draw_Me(true);
  129. }
  130. display = REDRAW_NONE;
  131. }
  132. if (process){
  133. input = cancelbtn.Input();
  134. switch (input) {
  135. /*
  136. ** Cancel. Just return to the main menu
  137. */
  138. case (KN_ESC):
  139. case (BUTTON_CANCEL | KN_BUTTON):
  140. pDownload->Abort();
  141. process = false;
  142. bReturn = false;
  143. break;
  144. }
  145. }
  146. if( ::timeGetTime() > dwTimeNextPump )
  147. {
  148. pDownload->PumpMessages();
  149. if( pDownloadSink->bFlagEnd )
  150. {
  151. pDownloadSink->bFlagEnd = false;
  152. process = false;
  153. break;
  154. }
  155. if( pDownloadSink->bFlagError )
  156. {
  157. WWMessageBox().Process( TXT_WOL_DOWNLOADERROR );
  158. pDownloadSink->bFlagError = false;
  159. process = false;
  160. bReturn = false;
  161. break;
  162. }
  163. if( pDownloadSink->bFlagProgressUpdate )
  164. {
  165. pDownloadSink->bFlagProgressUpdate = false;
  166. progress_meter.Set_Value( ( pDownloadSink->iBytesRead * 100 ) / pDownloadSink->iTotalSize );
  167. char szText[200];
  168. sprintf( szText, TXT_WOL_DOWNLOADBYTES, pDownloadSink->iBytesRead, pDownloadSink->iTotalSize,
  169. ( pDownloadSink->iBytesRead * 100 ) / pDownloadSink->iTotalSize );
  170. StatBytes.Set_Text( szText );
  171. sprintf( szText, TXT_WOL_DOWNLOADTIME, pDownloadSink->iTimeLeft / 60, pDownloadSink->iTimeLeft % 60 );
  172. StatTime.Set_Text( szText );
  173. if( display < REDRAW_BUTTONS ) display = REDRAW_BUTTONS;
  174. }
  175. if( pDownloadSink->bFlagStatusUpdate )
  176. {
  177. pDownloadSink->bFlagStatusUpdate = false;
  178. switch( pDownloadSink->iStatus )
  179. {
  180. case DOWNLOADSTATUS_CONNECTING:
  181. StatStatus.Set_Text( TXT_WOL_DOWNLOADCONNECTING );
  182. break;
  183. case DOWNLOADSTATUS_FINDINGFILE:
  184. StatStatus.Set_Text( TXT_WOL_DOWNLOADLOCATING );
  185. break;
  186. case DOWNLOADSTATUS_DOWNLOADING:
  187. StatStatus.Set_Text( TXT_WOL_DOWNLOADDOWNLOADING );
  188. break;
  189. default:
  190. // debugprint( "Unknown status update!\n" );
  191. break;
  192. }
  193. if( display < REDRAW_BUTTONS ) display = REDRAW_BUTTONS;
  194. }
  195. if( pDownloadSink->bFlagQueryResume )
  196. {
  197. if( pDownloadSink->bResumed )
  198. {
  199. char szTitleNew[200];
  200. sprintf( szTitleNew, TXT_WOL_DOWNLOADRESUMED, szTitle );
  201. StatTitle.Set_Text( szTitleNew );
  202. if( display < REDRAW_BUTTONS ) display = REDRAW_BUTTONS;
  203. }
  204. }
  205. dwTimeNextPump = ::timeGetTime() + WOLAPIPUMPWAIT;
  206. }
  207. // Invoke game callback
  208. Call_Back();
  209. } while ( process );
  210. return bReturn;
  211. }
  212. #endif