CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

WOL_DNLD.CPP (7446B)


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