WOL_DNLD.CPP 7.2 KB

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