00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "UpdateDlg.h"
00009 #include "misc.h"
00010 #include "inetutil.h"
00011
00012 #ifdef _DEBUG
00013 #define new DEBUG_NEW
00014 #undef THIS_FILE
00015 static char THIS_FILE[] = __FILE__;
00016 #endif
00017
00018 CUpdateDlg::CUpdateDlg(CWnd* pParent )
00019 : CDialog(CUpdateDlg::IDD, pParent)
00020 {
00021
00022
00023
00024
00025 m_bCheckingByUser = true;
00026 }
00027
00028 void CUpdateDlg::DoDataExchange(CDataExchange* pDX)
00029 {
00030 CDialog::DoDataExchange(pDX);
00031
00032 DDX_Control(pDX, IDC_BPS, m_wndSpeed);
00033 DDX_Control(pDX, IDC_FILESIZE, m_wndSize);
00034 DDX_Control(pDX, IDC_TIMELEFT, m_wndTimeLeft);
00035 DDX_Control(pDX, IDC_PROGRESS, m_wndProgress);
00036 DDX_Control(pDX, IDC_MESSAGE, m_wndMsg);
00037
00038 }
00039
00040 BEGIN_MESSAGE_MAP(CUpdateDlg, CDialog)
00041
00042 ON_BN_CLICKED(IDC_DESC, OnDesc)
00043 ON_BN_CLICKED(ID_UPDATE, OnUpdate)
00044 ON_WM_TIMER()
00045 ON_WM_SYSCOMMAND()
00046 ON_WM_CONTEXTMENU()
00047 ON_COMMAND(ID_WHATISTHIS, OnWhatisthis)
00048 ON_BN_CLICKED(ID_HELP, OnHelp)
00049 ON_WM_HELPINFO()
00050
00051 END_MESSAGE_MAP()
00052
00053 BOOL CUpdateDlg::OnInitDialog()
00054 {
00055 CDialog::OnInitDialog();
00056
00057
00058 _UpdateMgr.SetEventsFunc (_UpdateMgrEvents, this);
00059 _UpdateMgr.SetDescEventsFunc (_UpdateMgrDescEvents, this);
00060
00061 if (_UpdateMgr.IsRunning () == FALSE)
00062 {
00063 CheckForUpdate ();
00064 }
00065
00066 m_wndProgress.SetRange (0, 100);
00067
00068 ApplyLanguage ();
00069
00070 return TRUE;
00071 }
00072
00073 void CUpdateDlg::OnDesc()
00074 {
00075 CString strWN;
00076 fs::list <CString>* pWN = _UpdateMgr.GetWhatNew ();
00077
00078 for (int i = 0; i < pWN->size (); i++)
00079 {
00080 strWN += pWN->at (i);
00081 strWN += '\n';
00082 }
00083
00084 MessageBox (strWN, LS (L_DESC), MB_ICONINFORMATION);
00085 }
00086
00087 void CUpdateDlg::OnUpdate()
00088 {
00089 GetDlgItem (ID_UPDATE)->EnableWindow (FALSE);
00090 ShowGroup (TRUE);
00091 _UpdateMgr.Update (IsDlgButtonChecked (IDC_FULLDISTRIB) == BST_CHECKED);
00092 m_wndProgress.SetPos (0);
00093 }
00094
00095 void CUpdateDlg::OnCancel()
00096 {
00097 _UpdateMgr.SetDescEventsFunc (NULL, 0);
00098 _UpdateMgr.SetEventsFunc (NULL, 0);
00099
00100 _UpdateMgr.Stop ();
00101 CDialog::OnCancel();
00102 }
00103
00104 void CUpdateDlg::_UpdateMgrEvents(fsUpdateMgrEvent ev, LPVOID lp)
00105 {
00106 CUpdateDlg *pThis = (CUpdateDlg*) lp;
00107
00108 switch (ev)
00109 {
00110 case UME_CONNECTING:
00111
00112 pThis->m_wndMsg.SetWindowText (LS (L_CONNECTINGTOSERV));
00113 break;
00114
00115 case UME_RETREIVINGUPDLST:
00116
00117 _UpdateMgr.m_dldr->GetDP ()->uMaxAttempts = UINT_MAX;
00118 _UpdateMgr.m_dldr->ApplyProperties ();
00119
00120 pThis->SetTimer (1, 1000, NULL);
00121 pThis->m_wndMsg.SetWindowText (LS (L_CHECKINGUPD));
00122 pThis->OnTimer (1);
00123 break;
00124
00125 case UME_UPDLSTDONE:
00126
00127 pThis->KillTimer (1);
00128 pThis->m_wndProgress.SetPos (100);
00129 break;
00130
00131 case UME_NEWVERSIONAVAIL:
00132
00133 pThis->ShowUpdateInfo ();
00134 if (pThis->m_bCheckingByUser == false && _UpdateMgr.m_enAUT == AUT_DLANDINST)
00135 pThis->PostMessage (WM_COMMAND, ID_UPDATE);
00136 break;
00137
00138 case UME_NEWVERSIONNOTAVAIL:
00139
00140 pThis->m_wndMsg.SetWindowText (LS (L_ALRNEWESTVER));
00141 pThis->SetDlgItemText (IDCANCEL, "OK");
00142 break;
00143
00144 case UME_FATALERROR:
00145
00146 char szErr [1000];
00147 fsIRToStr (_UpdateMgr.m_dldr->GetLastError (), szErr, sizeof (szErr));
00148 pThis->m_wndMsg.SetWindowText (szErr);
00149 pThis->KillTimer (1);
00150 break;
00151
00152 case UME_RETREIVINGUPDATE:
00153 {
00154
00155 _UpdateMgr.m_dldr->GetDP ()->uMaxAttempts = UINT_MAX;
00156 _UpdateMgr.m_dldr->ApplyProperties ();
00157 CString str;
00158 str.Format (LS (L_VERAVAIL), _UpdateMgr.GetVersion (), _UpdateMgr.GetBuildNumber ());
00159 str += ". "; str += LS (L_DOWNLOADING); str += "...";
00160 pThis->m_wndMsg.SetWindowText (str);
00161 pThis->SetTimer (1, 1000, NULL);
00162 pThis->OnTimer (1);
00163 }
00164 break;
00165
00166 case UME_UPDATEDONE:
00167
00168 CString str;
00169 str.Format (LS (L_VERAVAIL), _UpdateMgr.GetVersion (), _UpdateMgr.GetBuildNumber ());
00170 str += ". "; str += LS (L_DONE); str += '.';
00171 pThis->m_wndMsg.SetWindowText (str);
00172 pThis->KillTimer (1);
00173 pThis->m_wndProgress.SetPos (100);
00174 pThis->OnUpdateDone ();
00175 break;
00176 }
00177
00178 }
00179
00180 void CUpdateDlg::CheckForUpdate()
00181 {
00182 _UpdateMgr.CheckForUpdate (m_bCheckingByUser);
00183 GetDlgItem (ID_UPDATE)->EnableWindow (FALSE);
00184 GetDlgItem (IDC_DESC)->EnableWindow (FALSE);
00185
00186 ShowGroup (TRUE);
00187 }
00188
00189 void CUpdateDlg::ShowUpdateInfo()
00190 {
00191 GetDlgItem (ID_UPDATE)->EnableWindow ();
00192 GetDlgItem (IDC_DESC)->EnableWindow ();
00193
00194 CString str;
00195 str.Format (LS (L_VERAVAIL), _UpdateMgr.GetVersion (), _UpdateMgr.GetBuildNumber ());
00196 m_wndMsg.SetWindowText (str);
00197
00198 ShowGroup (FALSE);
00199
00200 str.Format (LS (L_FULLDISTR), _UpdateMgr.GetVersion (), _UpdateMgr.GetFullSize ());
00201 SetDlgItemText (IDC_FULLDISTRIB, str);
00202
00203 LPCSTR pszUpgSize = _UpdateMgr.GetUpgSize ();
00204
00205 if (*pszUpgSize == 0)
00206 {
00207 str.Format (LS (L_UPGTOVER), _UpdateMgr.GetVersion ());
00208 SetDlgItemText (IDC_UPGDISTRIB, str);
00209
00210 GetDlgItem (IDC_UPGDISTRIB)->EnableWindow (FALSE);
00211 CheckRadioButton (IDC_FULLDISTRIB, IDC_UPGDISTRIB, IDC_FULLDISTRIB);
00212 }
00213 else
00214 {
00215 str.Format (LS (L_UPGTOVER2), _UpdateMgr.GetVersion (), pszUpgSize);
00216 SetDlgItemText (IDC_UPGDISTRIB, str);
00217 CheckRadioButton (IDC_FULLDISTRIB, IDC_UPGDISTRIB, IDC_UPGDISTRIB);
00218 }
00219
00220 ShowWindow (SW_SHOW);
00221 SetFocus ();
00222 }
00223
00224 void CUpdateDlg::OnTimer(UINT )
00225 {
00226 UINT64 uBytesLeft = _UpdateMgr.m_dldr->GetDownloader ()->GetBytesLeft ();
00227 UINT uSpeed = _UpdateMgr.m_dldr->GetDownloader ()->GetSpeed ();
00228 UINT64 uSize = _UpdateMgr.m_dldr->GetDownloader ()->GetSSFileSize ();
00229
00230 if (uSize != _UI64_MAX && uSize != 0)
00231 {
00232 m_wndProgress.SetPos (100 - (int) (double ((INT64)uBytesLeft) / (INT64)uSize * 100));
00233 if (uSpeed)
00234 m_wndTimeLeft.SetWindowText (fsTimeInSecondsToStr (DWORD ((INT64)uBytesLeft / (INT64)uSpeed)));
00235 else
00236 m_wndTimeLeft.SetWindowText ("");
00237 }
00238 else
00239 {
00240 m_wndTimeLeft.SetWindowText ("");
00241 }
00242
00243 float val;
00244 char szDim [100];
00245 CString str;
00246
00247 if (uSize != _UI64_MAX)
00248 {
00249 BytesToXBytes (uSize, &val, szDim);
00250 str.Format ("%.*g %s", val > 999 ? 4 : 3, val, szDim);
00251 }
00252 else
00253 {
00254 str = LS (L_UNKNOWN);
00255 }
00256 m_wndSize.SetWindowText (str);
00257
00258 BytesToXBytes (uSpeed, &val, szDim);
00259 str.Format ("%.*g %s/s", val > 999 ? 4 : 3, val, szDim);
00260 m_wndSpeed.SetWindowText (str);
00261 }
00262
00263 void CUpdateDlg::_UpdateMgrDescEvents(LPCSTR , LPVOID )
00264 {
00265
00266 }
00267
00268 void CUpdateDlg::ShowGroup(BOOL bFirstGroup)
00269 {
00270 UINT n1show = bFirstGroup ? SW_SHOW : SW_HIDE;
00271 UINT n2show = bFirstGroup ? SW_HIDE : SW_SHOW;
00272
00273 GetDlgItem (IDC_FULLDISTRIB)->ShowWindow (n2show);
00274 GetDlgItem (IDC_UPGDISTRIB)->ShowWindow (n2show);
00275 GetDlgItem (IDC__TYPE)->ShowWindow (n2show);
00276
00277 GetDlgItem (IDC__SPEED)->ShowWindow (n1show);
00278 GetDlgItem (IDC__TIMELEFT)->ShowWindow (n1show);
00279 GetDlgItem (IDC__SIZE)->ShowWindow (n1show);
00280 m_wndSize.ShowWindow (n1show);
00281 m_wndSpeed.ShowWindow (n1show);
00282 m_wndTimeLeft.ShowWindow (n1show);
00283 }
00284
00285 void CUpdateDlg::OnSysCommand(UINT nID, LPARAM lParam)
00286 {
00287 if (nID == SC_CLOSE)
00288 {
00289 OnCancel ();
00290 return;
00291 }
00292
00293 CDialog::OnSysCommand(nID, lParam);
00294 }
00295
00296 void CUpdateDlg::OnUpdateDone()
00297 {
00298
00299 if (IDYES == MessageBox (LS (L_NEEDRESTART), LS (L_UPDDONE), MB_ICONQUESTION|MB_YESNO))
00300 {
00301
00302 if (_UpdateMgr.StartUpdater ())
00303 {
00304
00305 _DlgMgr.EndAllDialogs ();
00306 AfxGetApp ()->m_pMainWnd->PostMessage (WM_COMMAND, ID_NEED_EXIT);
00307 }
00308 else
00309 MessageBox (LS (L_CANTFINDUPDATER), LS (L_ERR), MB_ICONERROR);
00310 }
00311 else
00312 {
00313 _UpdateMgr.UpdateOnNextStart ();
00314 }
00315
00316 EndDialog (IDOK);
00317 }
00318
00319 void CUpdateDlg::OnContextMenu(CWnd* , CPoint point)
00320 {
00321 PrepareCHMgr (point);
00322 _CHMgr.ShowMenu ();
00323 }
00324
00325 void CUpdateDlg::OnWhatisthis()
00326 {
00327 _CHMgr.OnWT ();
00328 }
00329
00330 void CUpdateDlg::OnHelp()
00331 {
00332 HtmlHelp (AfxGetApp ()->m_pMainWnd->m_hWnd, "Help\\Open Download Manager.chm::/Update.htm", HH_DISPLAY_TOPIC, NULL);
00333 }
00334
00335 void CUpdateDlg::ApplyLanguage()
00336 {
00337 fsDlgLngInfo lnginfo [] = {
00338 fsDlgLngInfo (IDCANCEL, L_CANCEL),
00339 fsDlgLngInfo (ID_HELP, L_HELP),
00340 fsDlgLngInfo (ID_UPDATE, L_TOUPDATE),
00341 fsDlgLngInfo (IDC_DESC, L_DESC),
00342 fsDlgLngInfo (IDC__TYPE, L_UPDATEUSING),
00343 fsDlgLngInfo (IDC__SPEED, L_SPEED),
00344 fsDlgLngInfo (IDC__TIMELEFT, L_TIMELEFT),
00345 fsDlgLngInfo (IDC__SIZE, L_SIZE),
00346 };
00347
00348 _LngMgr.ApplyLanguage (this, lnginfo, sizeof (lnginfo) / sizeof (fsDlgLngInfo), L_UPDATE);
00349 }
00350
00351 void CUpdateDlg::PrepareCHMgr(CPoint point)
00352 {
00353 fsCtrlContextHelp aCH1 [] = {
00354 fsCtrlContextHelp (IDC__TYPE, LS (L_UPDTYPEHERE)),
00355 fsCtrlContextHelp (IDC_FULLDISTRIB, LS (L_USINGFULLHERE)),
00356 fsCtrlContextHelp (IDC_UPGDISTRIB, LS (L_USINGPARTHERE)),
00357 fsCtrlContextHelp (ID_HELP, LS (L_UPDHELPHERE)),
00358 fsCtrlContextHelp (IDC_DESC, LS (L_DESCHERE)),
00359 fsCtrlContextHelp (ID_UPDATE, LS (L_UPDATEHERE)),
00360 fsCtrlContextHelp (IDCANCEL, LS (L_UPDCANCELHERE)),
00361 };
00362
00363 static fsCtrlContextHelp aCH [sizeof (aCH1) / sizeof (fsCtrlContextHelp)];
00364 CopyMemory (aCH, aCH1, sizeof (aCH));
00365
00366 _CHMgr.PrepareContextMenu (this, point, aCH, sizeof (aCH) / sizeof (fsCtrlContextHelp));
00367 }
00368
00369 BOOL CUpdateDlg::OnHelpInfo(HELPINFO* pHelpInfo)
00370 {
00371 RECT rc;
00372 CWnd *pItem = GetDlgItem (pHelpInfo->iCtrlId);
00373 if (pItem == NULL)
00374 return TRUE;
00375 pItem->GetWindowRect (&rc);
00376 if (PtInRect (&rc, pHelpInfo->MousePos) == FALSE)
00377 {
00378 pHelpInfo->MousePos.x = rc.left + (rc.right - rc.left) / 2;
00379 pHelpInfo->MousePos.y = rc.top + (rc.bottom - rc.top) / 2;
00380 }
00381 PrepareCHMgr (pHelpInfo->MousePos);
00382 _CHMgr.OnWT ();
00383 return TRUE;
00384 }