00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "CreateDownloadListDlg.h"
00009 #include "DownloadsWnd.h"
00010 #include "CreateDownloadDlg.h"
00011 #include "GroupDlg.h"
00012 #include "FolderBrowser.h"
00013 #include "ScheduleSheet.h"
00014 #include "DownloadPropertiesSheet.h"
00015 #include "WaitDlg.h"
00016 #include "DlgExtensionsFilter.h"
00017 #include "inetutil.h"
00018
00019 #ifdef _DEBUG
00020 #define new DEBUG_NEW
00021 #undef THIS_FILE
00022 static char THIS_FILE[] = __FILE__;
00023 #endif
00024
00025 extern CDownloadsWnd *_pwndDownloads;
00026
00027 CCreateDownloadListDlg::CCreateDownloadListDlg(CWnd* pParent )
00028 : CDialog(CCreateDownloadListDlg::IDD, pParent)
00029 {
00030
00031
00032
00033 Download_CreateInstance (m_dld);
00034 }
00035
00036 void CCreateDownloadListDlg::DoDataExchange(CDataExchange* pDX)
00037 {
00038 CDialog::DoDataExchange(pDX);
00039
00040 DDX_Control(pDX, IDC_URLLIST, m_wndUrlList);
00041 DDX_Control(pDX, IDC_GROUPS, m_wndGroups);
00042 DDX_Control(pDX, IDC_SETTIME, m_btnSetTime);
00043 DDX_Control(pDX, IDC_CREATEGROUP, m_btnCreateGroup);
00044 DDX_Control(pDX, IDC_CHOOSEFOLDER, m_btnChooseFolder);
00045
00046 }
00047
00048 BEGIN_MESSAGE_MAP(CCreateDownloadListDlg, CDialog)
00049
00050 ON_WM_CONTEXTMENU()
00051 ON_WM_HELPINFO()
00052 ON_COMMAND(ID_WHATISTHIS, OnWhatisthis)
00053 ON_NOTIFY(LVN_KEYDOWN, IDC_URLLIST, OnKeydownUrllist)
00054 ON_BN_CLICKED(IDC_DELSELECTED, OnDelselected)
00055 ON_NOTIFY(LVN_ITEMCHANGED, IDC_URLLIST, OnItemchangedUrllist)
00056 ON_CBN_SELCHANGE(IDC_GROUPS, OnSelchangeGroups)
00057 ON_BN_CLICKED(IDC_CREATEGROUP, OnCreategroup)
00058 ON_BN_CLICKED(IDC_CHOOSEFOLDER, OnChoosefolder)
00059 ON_BN_CLICKED(IDC_SETTIME, OnSettime)
00060 ON_BN_CLICKED(IDC_ADVANCED, OnAdvanced)
00061 ON_BN_CLICKED(IDC_QUERYSIZE, OnQuerysize)
00062 ON_BN_CLICKED(IDC_STARTNOW, OnStartnow)
00063 ON_BN_CLICKED(IDC_STARTMANUAL, OnStartmanual)
00064 ON_BN_CLICKED(IDC_STARTSCHEDULE, OnStartschedule)
00065 ON_BN_CLICKED(IDC_USELOGIN, OnUselogin)
00066 ON_BN_CLICKED(IDC_FILTER, OnFilter)
00067
00068 END_MESSAGE_MAP()
00069
00070 BOOL CCreateDownloadListDlg::OnInitDialog()
00071 {
00072 CDialog::OnInitDialog();
00073
00074 m_btnChooseFolder.SetIcon (SICO (IDI_CHOOSEFOLDER));
00075 m_btnCreateGroup.SetIcon (SICO (IDI_CREATEGROUP));
00076 m_btnSetTime.SetIcon (SICO (IDI_SETTIME));
00077
00078 m_task.hts.enType = HTS_ONCE;
00079 m_task.hts.last.dwHighDateTime = m_task.hts.last.dwLowDateTime = UINT_MAX;
00080 SYSTEMTIME time;
00081 GetLocalTime (&time);
00082 if (++time.wHour > 23)
00083 time.wHour = 0;
00084 time.wMinute = 0;
00085 SystemTimeToFileTime (&time, &m_task.hts.next);
00086 m_task.uWaitForConfirmation = 0;
00087
00088 CString strUser = _App.UserName ();
00089 if (strUser.GetLength ())
00090 {
00091 SetDlgItemText (IDC_USER, strUser);
00092 SetDlgItemText (IDC_PASSWORD, _App.UserPassword ());
00093 CheckDlgButton (IDC_USELOGIN, BST_CHECKED);
00094 }
00095
00096 m_wndGroups.Fill ();
00097
00098 CComboBox *pDirs = (CComboBox*) GetDlgItem (IDC_OUTFOLDER);
00099 for (int i = 0; i < _LastFolders.GetRecordCount (); i++)
00100 pDirs->AddString (_LastFolders.GetRecord (i));
00101
00102 CheckRadioButton (IDC_STARTNOW, IDC_STARTSCHEDULE, IDC_STARTNOW);
00103 m_dld->bAutoStart = TRUE;
00104
00105 m_dld->pMgr->GetDownloadMgr ()->CreateByUrl ("http://");
00106
00107 m_bGroupChanged = m_bAuthChanged = FALSE;
00108
00109 WriteUrlsToDialog ();
00110
00111 ReadAutostart ();
00112
00113 ApplyLanguage ();
00114
00115 if (m_wndGroups.SelectGroupById (_App.NewDL_GroupId ()))
00116 m_bGroupChanged = TRUE;
00117
00118 OnChangeGroups ();
00119
00120 fsSetForegroundWindow (m_hWnd);
00121
00122 UpdateEnabled ();
00123 return TRUE;
00124 }
00125
00126 void CCreateDownloadListDlg::ApplyLanguage()
00127 {
00128 fsDlgLngInfo lnginfo [] = {
00129 fsDlgLngInfo (IDC_DELSELECTED, L_DELETESELECTED),
00130 fsDlgLngInfo (IDC_FILTER, L_FILTER),
00131 fsDlgLngInfo (IDC_USELOGIN, L_AUTHORIZATION),
00132 fsDlgLngInfo (IDC__USER, L_USER),
00133 fsDlgLngInfo (IDC__PASSWORD, L_PASSWORD),
00134 fsDlgLngInfo (IDC__SAVETO, L_SAVETO),
00135 fsDlgLngInfo (IDC__START, L_START),
00136 fsDlgLngInfo (IDC_STARTNOW, L_AUTOMATICALLY),
00137 fsDlgLngInfo (IDC_STARTMANUAL, L_MANUALLY),
00138 fsDlgLngInfo (IDC_STARTSCHEDULE, L_SCHEDULE),
00139 fsDlgLngInfo (IDC__GROUP, L_GROUP),
00140 fsDlgLngInfo (IDC_ADVANCED, L_ADVANCED),
00141 fsDlgLngInfo (IDCANCEL, L_CANCEL),
00142 fsDlgLngInfo (IDC_QUERYSIZE, L_QUERYSIZE),
00143 };
00144
00145 _LngMgr.ApplyLanguage (this, lnginfo, sizeof (lnginfo) / sizeof (fsDlgLngInfo), L_ADDLISTOFDOWNLOADS);
00146 }
00147
00148 void CCreateDownloadListDlg::OnContextMenu(CWnd* , CPoint point)
00149 {
00150 PrepareCHMgr (point);
00151 _CHMgr.ShowMenu ();
00152 }
00153
00154 BOOL CCreateDownloadListDlg::OnHelpInfo(HELPINFO* pHelpInfo)
00155 {
00156 RECT rc;
00157 CWnd *pItem = GetDlgItem (pHelpInfo->iCtrlId);
00158 if (pItem == NULL)
00159 return TRUE;
00160 pItem->GetWindowRect (&rc);
00161 if (PtInRect (&rc, pHelpInfo->MousePos) == FALSE)
00162 {
00163 pHelpInfo->MousePos.x = rc.left + (rc.right - rc.left) / 2;
00164 pHelpInfo->MousePos.y = rc.top + (rc.bottom - rc.top) / 2;
00165 }
00166 PrepareCHMgr (pHelpInfo->MousePos);
00167 _CHMgr.OnWT ();
00168 return TRUE;
00169 }
00170
00171 void CCreateDownloadListDlg::PrepareCHMgr(CPoint point)
00172 {
00173 fsCtrlContextHelp aCH1 [] = {
00174 fsCtrlContextHelp (IDC_URLLIST, LS (L_URLLISTHERE)),
00175 fsCtrlContextHelp (IDC_DELSELECTED, LS (L_DELETESELECTEDHERE)),
00176 fsCtrlContextHelp (IDC__USER, LS (L_USERHERE)),
00177 fsCtrlContextHelp (IDC_USER, LS (L_USERHERE)),
00178 fsCtrlContextHelp (IDC__PASSWORD, LS (L_PWDHERE)),
00179 fsCtrlContextHelp (IDC_PASSWORD, LS (L_PWDHERE)),
00180 fsCtrlContextHelp (IDC_USELOGIN, LS (L_LOGINHERE)),
00181 fsCtrlContextHelp (IDC__GROUP, LS (L_GROUPHERE)),
00182 fsCtrlContextHelp (IDC_GROUPS, LS (L_GROUPHERE)),
00183 fsCtrlContextHelp (IDC_CREATEGROUP, LS (L_CREATEGRP)),
00184 fsCtrlContextHelp (IDC__SAVETO, LS (L_DLDFOLDERHERE)),
00185 fsCtrlContextHelp (IDC_OUTFOLDER, LS (L_DLDFOLDERHERE)),
00186 fsCtrlContextHelp (IDC_CHOOSEFOLDER, LS (L_BROWSEFOR)),
00187 fsCtrlContextHelp (IDC_STARTNOW, LS (L_STARTNOWHERE)),
00188 fsCtrlContextHelp (IDC_STARTMANUAL, LS (L_MANUALLYSTARTHERE)),
00189 fsCtrlContextHelp (IDC_STARTSCHEDULE, LS (L_SCHEDULESTARTHERE)),
00190 fsCtrlContextHelp (IDC_SETTIME, LS (L_SETTIMEHERE)),
00191 fsCtrlContextHelp (IDC_ADVANCED, LS (L_ADVANCEDHERE)),
00192 fsCtrlContextHelp (IDOK, LS (L_ACCEPTCHANGES)),
00193 fsCtrlContextHelp (IDCANCEL, LS (L_DONTACCEPTCHANGES)),
00194 fsCtrlContextHelp (IDC_QUERYSIZE, LS (L_QUERYBATCHSIZEHERE)),
00195 };
00196
00197 static fsCtrlContextHelp aCH [sizeof (aCH1) / sizeof (fsCtrlContextHelp)];
00198 CopyMemory (aCH, aCH1, sizeof (aCH));
00199
00200 _CHMgr.PrepareContextMenu (this, point, aCH, sizeof (aCH) / sizeof (fsCtrlContextHelp));
00201 }
00202
00203 void CCreateDownloadListDlg::OnWhatisthis()
00204 {
00205 _CHMgr.OnWT ();
00206 }
00207
00208 void CCreateDownloadListDlg::ReadAutostart()
00209 {
00210 m_iAutostart = _App.Last_Autostart ();
00211
00212 switch (m_iAutostart)
00213 {
00214 case 0:
00215 CheckRadioButton (IDC_STARTNOW, IDC_STARTSCHEDULE, IDC_STARTNOW);
00216 m_dld->bAutoStart = TRUE;
00217 m_bScheduled = FALSE;
00218 break;
00219
00220 case 1:
00221 CheckRadioButton (IDC_STARTNOW, IDC_STARTSCHEDULE, IDC_STARTMANUAL);
00222 m_dld->bAutoStart = FALSE;
00223 m_bScheduled = FALSE;
00224 break;
00225
00226 case 2:
00227 CheckRadioButton (IDC_STARTNOW, IDC_STARTSCHEDULE, IDC_STARTSCHEDULE);
00228 m_dld->bAutoStart = FALSE;
00229 m_bScheduled = TRUE;
00230 break;
00231 }
00232 }
00233
00234 void CCreateDownloadListDlg::OnChangeGroups()
00235 {
00236 SetDlgItemText (IDC_OUTFOLDER, m_wndGroups.GetSelectedGroup ()->strOutFolder);
00237 }
00238
00239 void CCreateDownloadListDlg::OnOK()
00240 {
00241 if (FALSE == ReadAuth ())
00242 return;
00243
00244 CString strOutFolder;
00245
00246 GetDlgItemText (IDC_OUTFOLDER, strOutFolder);
00247
00248 fsPathToGoodPath ((LPSTR)(LPCSTR)strOutFolder);
00249
00250 if (strOutFolder.GetLength () == 0)
00251 {
00252 MessageBox (LS (L_ENTERFLRNAME), LS (L_INPERR), MB_ICONEXCLAMATION);
00253 GetDlgItem (IDC_OUTFOLDER)->SetFocus ();
00254 return;
00255 }
00256
00257 if (FALSE == CCreateDownloadDlg::_CheckFolderName (this, IDC_OUTFOLDER))
00258 return;
00259
00260 _LastFolders.AddRecord (strOutFolder);
00261
00262 if (strOutFolder [strOutFolder.GetLength () - 1] != '\\' &&
00263 strOutFolder [strOutFolder.GetLength () - 1] != '/')
00264 strOutFolder += '\\';
00265
00266 if (_App.NewGrp_SelectWay () == NGSW_USE_ALWAYS_SAME_GROUP_WITH_OUTFOLDER_AUTO_UPDATE)
00267 {
00268 vmsDownloadsGroupSmartPtr pGrp = _DldsGrps.FindGroup (_App.NewDL_GroupId ());
00269 if (pGrp != NULL)
00270 pGrp->strOutFolder = strOutFolder;
00271 }
00272
00273 fsnew (m_dld->pMgr->GetDownloadMgr ()->GetDP ()->pszFileName, CHAR, strOutFolder.GetLength () + 1);
00274 strcpy (m_dld->pMgr->GetDownloadMgr ()->GetDP ()->pszFileName, strOutFolder);
00275
00276 m_dld->pGroup = m_wndGroups.GetSelectedGroup ();
00277
00278 BOOL bUseZipPreview = _App.NewDL_UseZIPPreview ();
00279
00280 if (bUseZipPreview)
00281 m_dld->pMgr->GetDownloadMgr ()->GetDP ()->dwFlags |= DPF_USEZIPPREVIEW;
00282 else
00283 m_dld->pMgr->GetDownloadMgr ()->GetDP ()->dwFlags &= ~DPF_USEZIPPREVIEW;
00284
00285 if (FALSE == AddDownloads ())
00286 return;
00287
00288 m_wndGroups.RememberSelectedGroup ();
00289 _App.Last_Autostart (m_iAutostart);
00290 _App.UseZipPreview (bUseZipPreview);
00291
00292 _App.OnDlHasBeenCreatedByUser ();
00293
00294 CDialog::OnOK();
00295 }
00296
00297 BOOL CCreateDownloadListDlg::ReadAuth()
00298 {
00299 CString strUser, strPassword;
00300
00301 if (IsDlgButtonChecked (IDC_USELOGIN) == BST_CHECKED)
00302 {
00303 GetDlgItemText (IDC_USER, strUser);
00304 GetDlgItemText (IDC_PASSWORD, strPassword);
00305
00306 if (strUser.GetLength () == 0)
00307 {
00308 MessageBox (LS (L_ENTERUSER), LS (L_INPERR), MB_ICONEXCLAMATION);
00309 GetDlgItem (IDC_USER)->SetFocus ();
00310 return FALSE;
00311 }
00312 }
00313
00314 if (strUser != "")
00315 {
00316 fsDownload_NetworkProperties *dnp = m_dld->pMgr->GetDownloadMgr ()->GetDNP ();
00317
00318 SAFE_DELETE_ARRAY (dnp->pszUserName);
00319 SAFE_DELETE_ARRAY (dnp->pszPassword);
00320
00321 fsnew (dnp->pszUserName, CHAR, strUser.GetLength ()+1);
00322 fsnew (dnp->pszPassword, CHAR, strPassword.GetLength ()+1);
00323 strcpy (dnp->pszUserName, strUser);
00324 strcpy (dnp->pszPassword, strPassword);
00325 }
00326
00327 return TRUE;
00328 }
00329
00330 BOOL CCreateDownloadListDlg::AddDownloads()
00331 {
00332 DLDS_LIST* pvpDlds = GenerateDownloads ();
00333
00334 if (pvpDlds == NULL)
00335 return FALSE;
00336
00337
00338 _pwndDownloads->CreateDownloads (*pvpDlds, m_bScheduled ? &m_task : NULL);
00339
00340 delete pvpDlds;
00341
00342 return TRUE;
00343 }
00344
00345 void CCreateDownloadListDlg::WriteUrlsToDialog()
00346 {
00347 m_wndUrlList.InsertColumn (0, "", LVCFMT_LEFT, 200);
00348
00349
00350 int wmax = 0;
00351 BOOL b1Server = TRUE;
00352 BOOL b1ServerESD = TRUE;
00353 CString strServer;
00354 DWORD dwVF = 0;
00355
00356 for (int i = 0, cItems = 0; i < m_pvUrls->size (); i++)
00357 {
00358 LPCSTR pszURL = m_pvUrls->at (i);
00359
00360 fsURL url;
00361 if (IR_SUCCESS != url.Crack (pszURL))
00362 continue;
00363
00364 if (i == 0) {
00365 strServer = url.GetHostName ();
00366 }
00367 else if (b1ServerESD) {
00368 b1Server = fsIsServersEqual (strServer, url.GetHostName (), FALSE);
00369 if (b1Server == false) {
00370 b1ServerESD = fsIsServersEqual (strServer, url.GetHostName (), TRUE);
00371 if (strServer.GetLength () < lstrlen (url.GetHostName ()))
00372 strServer = url.GetHostName ();
00373 }
00374 if (b1ServerESD)
00375 dwVF |= fsNPToSiteValidFor (fsSchemeToNP (url.GetInternetScheme ()));
00376 }
00377
00378 int w = m_wndUrlList.GetStringWidth (pszURL);
00379 if (w > wmax)
00380 wmax = w;
00381
00382
00383 m_wndUrlList.InsertItem (cItems, pszURL);
00384 m_wndUrlList.SetItemData (cItems, i);
00385
00386 cItems++;
00387 }
00388
00389 m_wndUrlList.SetColumnWidth (0, wmax+20);
00390
00391 m_wndUrlList.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP);
00392
00393 if (b1ServerESD)
00394 {
00395 fsSiteInfo* site = _SitesMgr.FindSite2 (strServer, dwVF, FALSE);
00396 if (site && site->strUser.GetLength ())
00397 {
00398 CheckDlgButton (IDC_USELOGIN, BST_CHECKED);
00399 SetDlgItemText (IDC_USER, site->strUser);
00400 SetDlgItemText (IDC_PASSWORD, site->strPassword);
00401 }
00402 }
00403 }
00404
00405 void CCreateDownloadListDlg::OnKeydownUrllist(NMHDR* pNMHDR, LRESULT* pResult)
00406 {
00407 LV_KEYDOWN* pLVKeyDown = (LV_KEYDOWN*)pNMHDR;
00408
00409 if (pLVKeyDown->wVKey == VK_DELETE)
00410 DeleteSelectedUrls ();
00411
00412 *pResult = 0;
00413 }
00414
00415 void CCreateDownloadListDlg::DeleteSelectedUrls()
00416 {
00417 if (m_wndUrlList.GetSelectedCount () == 0)
00418 return;
00419
00420 if (MessageBox (LS (L_AREYOUSURE), LS (L_CONFIRMATION), MB_YESNO) == IDNO)
00421 return;
00422
00423 std::vector <int> v;
00424
00425 POSITION pos = m_wndUrlList.GetFirstSelectedItemPosition ();
00426 while (pos)
00427 v.push_back (m_wndUrlList.GetNextSelectedItem (pos));
00428
00429 for (int i = v.size () - 1; i >= 0; i--)
00430 m_wndUrlList.DeleteItem (v [i]);
00431 }
00432
00433 void CCreateDownloadListDlg::OnDelselected()
00434 {
00435 DeleteSelectedUrls ();
00436 }
00437
00438 void CCreateDownloadListDlg::UpdateEnabled()
00439 {
00440 BOOL b = IsDlgButtonChecked (IDC_USELOGIN) == BST_CHECKED;
00441 GetDlgItem (IDC__USER)->EnableWindow (b);
00442 GetDlgItem (IDC_USER)->EnableWindow (b);
00443 GetDlgItem (IDC__PASSWORD)->EnableWindow (b);
00444 GetDlgItem (IDC_PASSWORD)->EnableWindow (b);
00445
00446 GetDlgItem (IDC_DELSELECTED)->EnableWindow (m_wndUrlList.GetSelectedCount ());
00447 }
00448
00449 void CCreateDownloadListDlg::OnItemchangedUrllist(NMHDR* pNMHDR, LRESULT* pResult)
00450 {
00451 UpdateEnabled ();
00452
00453 *pResult = 0;
00454 }
00455
00456 void CCreateDownloadListDlg::OnSelchangeGroups()
00457 {
00458 OnChangeGroups ();
00459 m_bGroupChanged = TRUE;
00460 }
00461
00462 void CCreateDownloadListDlg::OnCreategroup()
00463 {
00464 if (m_wndGroups.CreateNewGroup (m_wndGroups.GetSelectedGroup ()))
00465 OnChangeGroups ();
00466 }
00467
00468 void CCreateDownloadListDlg::OnChoosefolder()
00469 {
00470 CString str = "";
00471 GetDlgItemText (IDC_OUTFOLDER, str);
00472
00473 if (str.GetLength () > 3 && (str [str.GetLength () - 1] == '\\' || str [str.GetLength () - 1] == '/'))
00474 str.GetBuffer (0) [str.GetLength () - 1] = 0;
00475
00476 CFolderBrowser *fb = CFolderBrowser::Create (LS (L_CHOOSEOUTFOLDER), str, NULL, this);
00477 if (fb == NULL)
00478 return;
00479
00480 SetDlgItemText (IDC_OUTFOLDER, fb->GetPath ());
00481 GetDlgItem (IDC_OUTFOLDER)->SetFocus ();
00482 }
00483
00484 void CCreateDownloadListDlg::OnSettime()
00485 {
00486 CScheduleSheet sheet (LS (L_SCHEDULEDLDS), this);
00487
00488 sheet.Init (&m_task, FALSE);
00489
00490 _DlgMgr.OnDoModal (&sheet);
00491
00492 if (IDOK == sheet.DoModal ())
00493 {
00494 CheckRadioButton (IDC_STARTNOW, IDC_STARTSCHEDULE, IDC_STARTSCHEDULE);
00495 m_bScheduled = TRUE;
00496 m_dld->bAutoStart = FALSE;
00497 m_iAutostart = 2;
00498 }
00499
00500 _DlgMgr.OnEndDialog (&sheet);
00501 GetDlgItem (IDC_STARTSCHEDULE)->SetFocus ();
00502 }
00503
00504 void CCreateDownloadListDlg::OnAdvanced()
00505 {
00506 DLDS_LIST v;
00507 v.push_back (m_dld);
00508
00509 m_dld->pMgr->GetDownloadMgr ()->GetDNP ()->enProtocol = NP_HTTP;
00510
00511 CDownloadPropertiesSheet sheet (LS (L_ADVANCED), this);
00512 sheet.Init (&v, DPS_SHP_NOGENERALNOMIRR);
00513 _DlgMgr.OnDoModal (&sheet);
00514 sheet.DoModal ();
00515 _DlgMgr.OnEndDialog (&sheet);
00516 }
00517
00518 void CCreateDownloadListDlg::OnQuerysize()
00519 {
00520 if (FALSE == ReadAuth ())
00521 return;
00522
00523 DLDS_LIST* pvpDlds = GenerateDownloads (FALSE);
00524
00525 CWaitDlg dlg;
00526 dlg.StartWaiting (LS (L_QUERINGSIZE), _threadCalcSize, TRUE, this, &dlg, pvpDlds);
00527
00528 delete pvpDlds;
00529 }
00530
00531 DWORD WINAPI CCreateDownloadListDlg::_threadCalcSize(LPVOID lp)
00532 {
00533 ProcWaitInfo *info = (ProcWaitInfo*) lp;
00534
00535 DLDS_LIST* pvpDlds = (DLDS_LIST*) info->lpParam3;
00536
00537
00538 DWORD dw;
00539 CloseHandle (CreateThread (NULL, 0, _threadCalculateSize, lp, 0, &dw));
00540
00541
00542 while (info->bWaitDone == FALSE)
00543 {
00544 if (info->bNeedStop)
00545 {
00546 for (size_t i = 0; i < pvpDlds->size (); i++)
00547 pvpDlds->at (i)->pMgr->GetDownloadMgr ()->StopQuering ();
00548
00549 break;
00550 }
00551
00552 Sleep (500);
00553 }
00554
00555 return 0;
00556 }
00557
00558 DWORD WINAPI CCreateDownloadListDlg::_threadCalculateSize(LPVOID lp)
00559 {
00560 ProcWaitInfo *info = (ProcWaitInfo*) lp;
00561 CWaitDlg* dlg = (CWaitDlg*) info->lpParam2;
00562 CCreateDownloadListDlg* pThis = (CCreateDownloadListDlg*) info->lpParam1;
00563 DLDS_LIST* pvpDlds = (DLDS_LIST*) info->lpParam3;
00564
00565 int iFailed = 0;
00566 UINT64 uSummSize = 0;
00567
00568
00569 for (size_t i = 0; i < pvpDlds->size () && info->bNeedStop == FALSE; i++)
00570 {
00571 vmsDownloadSmartPtr dld = pvpDlds->at (i);
00572 if (IR_SUCCESS != dld->pMgr->GetDownloadMgr ()->QuerySize ())
00573 iFailed ++;
00574
00575 UINT64 uSize = dld->pMgr->GetDownloadMgr ()->GetDownloader ()->GetSSFileSize ();
00576
00577
00578 if (uSize == _UI64_MAX)
00579 {
00580 uSummSize = _UI64_MAX;
00581 break;
00582 }
00583
00584 uSummSize += uSize;
00585
00586 CString str;
00587 str.Format ("%s (%d - %s, %d - %s)", LS (L_QUERINGSIZE), i+1, LS (L_DONE), iFailed, LS (L_ERR));
00588 dlg->SetDlgItemText (IDC_MESSAGE, str);
00589
00590 info->iProgress = (int) ((double) i / pvpDlds->size () * 100);
00591 }
00592
00593 if (info->bNeedStop == FALSE)
00594 {
00595 CString strSize;
00596
00597 if (uSummSize == _UI64_MAX)
00598 strSize = LS (L_UNKNOWN);
00599 else
00600 {
00601 if (_pwndDownloads->IsSizesInBytes () == FALSE)
00602 {
00603 char szDim [50];
00604 float fSize;
00605 BytesToXBytes (uSummSize, &fSize, szDim);
00606 strSize.Format ("%.*g %s", fSize > 999 ? 4 : 3, fSize, szDim);
00607 }
00608 else
00609 strSize = fsBytesToStr (uSummSize);
00610 }
00611
00612
00613 pThis->SetDlgItemText (IDC_QUERYSIZE, strSize);
00614 }
00615 else
00616 pThis->SetDlgItemText (IDC_QUERYSIZE, LS (L_QUERYSIZE));
00617
00618 info->bWaitDone = TRUE;
00619
00620 return 0;
00621 }
00622
00623 DLDS_LIST* CCreateDownloadListDlg::GenerateDownloads(BOOL bCheckDldExistance)
00624 {
00625 DLDS_LIST* pvpDlds = new DLDS_LIST;
00626
00627 int cDownloads = m_wndUrlList.GetItemCount ();
00628 bool bNeedReferer = m_dld->pMgr->GetDownloadMgr ()->GetDNP ()->pszReferer == NULL || *m_dld->pMgr->GetDownloadMgr ()->GetDNP ()->pszReferer == 0;
00629
00630 for (int i = 0; i < cDownloads; i++)
00631 {
00632 vmsDownloadSmartPtr dld;
00633 Download_CreateInstance (dld);
00634
00635 LPCSTR pszUrl = m_pvUrls->at (m_wndUrlList.GetItemData (i));
00636 LPCSTR pszCookies = m_pvCookies->at (m_wndUrlList.GetItemData (i));
00637
00638 if (IR_SUCCESS != dld->pMgr->GetDownloadMgr ()->CreateByUrl (pszUrl, TRUE))
00639 continue;
00640
00641 if (bCheckDldExistance)
00642 {
00643 int ret = CCreateDownloadDlg::_CheckDownloadAlrExists (m_dld);
00644 if (ret)
00645 {
00646 if (ret == 1)
00647 continue;
00648
00649 return NULL;
00650 }
00651 }
00652
00653 fsDownloadsMgr::Download_CloneSettings (dld, m_dld);
00654
00655 if (bNeedReferer)
00656 {
00657 LPCSTR pszReferer = m_pvReferers->at (m_wndUrlList.GetItemData (i));
00658 int len = pszReferer ? lstrlen (pszReferer) : 0;
00659 if (len)
00660 {
00661 SAFE_DELETE_ARRAY (dld->pMgr->GetDownloadMgr ()->GetDNP ()->pszReferer);
00662 dld->pMgr->GetDownloadMgr ()->GetDNP ()->pszReferer = new char [len+1];
00663 lstrcpy (dld->pMgr->GetDownloadMgr ()->GetDNP ()->pszReferer, pszReferer);
00664 }
00665 }
00666
00667 if (pszCookies && *pszCookies)
00668 {
00669 SAFE_DELETE_ARRAY (dld->pMgr->GetDownloadMgr ()->GetDNP ()->pszCookies);
00670 dld->pMgr->GetDownloadMgr ()->GetDNP ()->pszCookies = new char [lstrlen (pszCookies) + 1];
00671 lstrcpy (dld->pMgr->GetDownloadMgr ()->GetDNP ()->pszCookies, pszCookies);
00672 }
00673
00674 pvpDlds->push_back (dld);
00675 }
00676
00677 return pvpDlds;
00678 }
00679
00680 void CCreateDownloadListDlg::OnStartnow()
00681 {
00682 m_dld->bAutoStart = TRUE;
00683 m_bScheduled = FALSE;
00684 m_iAutostart = 0;
00685 }
00686
00687 void CCreateDownloadListDlg::OnStartmanual()
00688 {
00689 m_bScheduled = FALSE;
00690 m_dld->bAutoStart = FALSE;
00691 m_iAutostart = 1;
00692 }
00693
00694 void CCreateDownloadListDlg::OnStartschedule()
00695 {
00696 m_bScheduled = TRUE;
00697 m_dld->bAutoStart = FALSE;
00698 m_iAutostart = 2;
00699 }
00700
00701 void CCreateDownloadListDlg::OnUselogin()
00702 {
00703 UpdateEnabled ();
00704 }
00705
00706 void CCreateDownloadListDlg::OnFilter()
00707 {
00708 CDlgExtensionsFilter dlg;
00709
00710 dlg.m_strExts = _App.DldListDlg_Filter_LastExts ();
00711 dlg.m_bRemove = _App.DldListDlg_Filter_LastExtsRemove ();
00712
00713 if (IDOK != _DlgMgr.DoModal (&dlg))
00714 return;
00715
00716 _App.DldListDlg_Filter_LastExts (dlg.m_strExts);
00717 _App.DldListDlg_Filter_LastExtsRemove (dlg.m_bRemove);
00718
00719 char szFile [10000];
00720
00721 std::vector <int> v;
00722
00723 for (int i = 0; i < m_wndUrlList.GetItemCount (); i++)
00724 {
00725 LPCSTR pszUrl = m_pvUrls->at (m_wndUrlList.GetItemData (i));
00726 fsURL url;
00727 if (IR_SUCCESS == url.Crack (pszUrl))
00728 {
00729 fsFileNameFromUrlPath (url.GetPath (), url.GetInternetScheme () == INTERNET_SCHEME_FTP,
00730 TRUE, szFile, sizeof (szFile));
00731
00732 BOOL bExtPresent = FALSE;
00733
00734 LPCSTR pszExt = strrchr (szFile, '.');
00735 if (pszExt && IsExtInExtsStr (dlg.m_strExts, pszExt+1))
00736 bExtPresent = TRUE;
00737
00738 if ((bExtPresent && dlg.m_bRemove) ||
00739 (FALSE == bExtPresent && FALSE == dlg.m_bRemove))
00740 v.push_back (i);
00741 }
00742 }
00743
00744 for (i = v.size () - 1; i >= 0; i--)
00745 m_wndUrlList.DeleteItem (v [i]);
00746 }