00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "CreateBatchDownload.h"
00009 #include "DownloadsWnd.h"
00010 #include "inetutil.h"
00011 #include "GroupDlg.h"
00012 #include "FolderBrowser.h"
00013 #include "ScheduleSheet.h"
00014 #include "DownloadPropertiesSheet.h"
00015 #include "CBD_SeeResultsDlg.h"
00016 #include "WaitDlg.h"
00017 #include "CreateDownloadDlg.h"
00018 #include "Dlg_SetBatchNumbers.h"
00019 #include "vmsDownloadsGroupsMgr.h"
00020
00021 #ifdef _DEBUG
00022 #define new DEBUG_NEW
00023 #undef THIS_FILE
00024 static char THIS_FILE[] = __FILE__;
00025 #endif
00026
00027 extern CDownloadsWnd *_pwndDownloads;
00028
00029 CCreateBatchDownload::CCreateBatchDownload(CWnd* pParent )
00030 : CDialog(CCreateBatchDownload::IDD, pParent)
00031 {
00032 Download_CreateInstance (m_dld);
00033 m_iAlphaFrom = 0;
00034 m_iAlphaTo = 25;
00035 m_bBLParametersChanged = true;
00036 m_pvDownloads = NULL;
00037 }
00038
00039 void CCreateBatchDownload::DoDataExchange(CDataExchange* pDX)
00040 {
00041 CDialog::DoDataExchange(pDX);
00042
00043 DDX_Control(pDX, IDC_OUTFOLDER_SETDEFAULT, m_btnOutFolderSetDefault);
00044 DDX_Control(pDX, IDC_Z, m_wndZ);
00045 DDX_Control(pDX, IDC_A, m_wndA);
00046 DDX_Control(pDX, IDC_GROUPS, m_wndGroups);
00047 DDX_Control(pDX, IDC_SETTIME, m_btnSetTime);
00048 DDX_Control(pDX, IDC_CREATEGROUP, m_btnCreateGroup);
00049 DDX_Control(pDX, IDC_CHOOSEFOLDER, m_btnChooseFolder);
00050
00051 }
00052
00053 BEGIN_MESSAGE_MAP(CCreateBatchDownload, CDialog)
00054
00055 ON_CBN_SELCHANGE(IDC_GROUPS, OnSelchangeGroups)
00056 ON_CBN_EDITCHANGE(IDC_URL, OnEditchangeUrl)
00057 ON_CBN_SELCHANGE(IDC_URL, OnSelchangeUrl)
00058 ON_BN_CLICKED(IDC_USELOGIN, OnUselogin)
00059 ON_EN_CHANGE(IDC_USER, OnChangeUser)
00060 ON_EN_CHANGE(IDC_PASSWORD, OnChangePassword)
00061 ON_BN_CLICKED(IDC_STARTNOW, OnStartnow)
00062 ON_BN_CLICKED(IDC_STARTMANUAL, OnStartmanual)
00063 ON_BN_CLICKED(IDC_STARTSCHEDULE, OnStartschedule)
00064 ON_BN_CLICKED(IDC_CREATEGROUP, OnCreategroup)
00065 ON_BN_CLICKED(IDC_CHOOSEFOLDER, OnChoosefolder)
00066 ON_BN_CLICKED(IDC_SETTIME, OnSettime)
00067 ON_BN_CLICKED(IDC_ADVANCED, OnAdvanced)
00068 ON_WM_CONTEXTMENU()
00069 ON_WM_HELPINFO()
00070 ON_COMMAND(ID_WHATISTHIS, OnWhatisthis)
00071 ON_BN_CLICKED(IDC_RESULTS, OnResults)
00072 ON_BN_CLICKED(IDC_QUERYSIZE, OnQuerysize)
00073 ON_CBN_SELCHANGE(IDC_A, OnSelchangeA)
00074 ON_CBN_SELCHANGE(IDC_Z, OnSelchangeZ)
00075 ON_EN_CHANGE(IDC_NUMBERS, OnChangeNumbers)
00076 ON_BN_CLICKED(IDC_SETNUMBERS, OnSetnumbers)
00077 ON_BN_CLICKED(IDC_FILEAUTO, OnFileauto)
00078 ON_BN_CLICKED(IDC_OUTFOLDER_SETDEFAULT, OnOutfolderSetdefault)
00079
00080 END_MESSAGE_MAP()
00081
00082 BOOL CCreateBatchDownload::OnInitDialog()
00083 {
00084 CDialog::OnInitDialog();
00085
00086 m_btnChooseFolder.SetIcon (SICO (IDI_CHOOSEFOLDER));
00087 m_btnCreateGroup.SetIcon (SICO (IDI_CREATEGROUP));
00088 m_btnSetTime.SetIcon (SICO (IDI_SETTIME));
00089 m_btnOutFolderSetDefault.SetIcon (SICO (IDI_SETFOLDERDEFAULT));
00090
00091 m_task.hts.enType = HTS_ONCE;
00092 m_task.hts.last.dwHighDateTime = m_task.hts.last.dwLowDateTime = UINT_MAX;
00093 SYSTEMTIME time;
00094 GetLocalTime (&time);
00095 if (++time.wHour > 23)
00096 time.wHour = 0;
00097 time.wMinute = 0;
00098 SystemTimeToFileTime (&time, &m_task.hts.next);
00099 m_task.uWaitForConfirmation = 0;
00100
00101 LPCSTR pszUrl = _ClipbrdMgr.Text ();
00102 if (pszUrl && *pszUrl)
00103 {
00104 fsURL url;
00105 if (url.Crack (pszUrl) == IR_SUCCESS)
00106 m_strUrl = pszUrl;
00107 }
00108
00109 if (m_strUrl == "")
00110 m_strUrl = "http://";
00111
00112 CString strUser = _App.UserName ();
00113 m_bAuthorization = strUser.GetLength () != 0;
00114 SetDlgItemText (IDC_USER, strUser);
00115 SetDlgItemText (IDC_PASSWORD, _App.UserPassword ());
00116
00117 CheckDlgButton (IDC_USELOGIN, m_bAuthorization ? BST_CHECKED : BST_UNCHECKED);
00118
00119 m_wndGroups.Fill ();
00120
00121 CComboBox *pUrls = (CComboBox*) GetDlgItem (IDC_URL);
00122 for (int i = 0; i < _LastBatchUrls.GetRecordCount (); i++)
00123 pUrls->AddString (_LastBatchUrls.GetRecord (i));
00124
00125 CComboBox *pDirs = (CComboBox*) GetDlgItem (IDC_OUTFOLDER);
00126 for (i = 0; i < _LastFolders.GetRecordCount (); i++)
00127 pDirs->AddString (_LastFolders.GetRecord (i));
00128
00129 CheckRadioButton (IDC_STARTNOW, IDC_STARTSCHEDULE, IDC_STARTNOW);
00130 m_dld->bAutoStart = TRUE;
00131
00132 GetDlgItem (IDC_URL)->SetFocus ();
00133
00134 if (IR_SUCCESS != m_dld->pMgr->GetDownloadMgr ()->CreateByUrl (m_strUrl, TRUE) && m_strUrl != "http://")
00135 m_dld->pMgr->GetDownloadMgr ()->CreateByUrl ("http://", TRUE);
00136
00137 m_bGroupChanged = m_bAuthChanged = FALSE;
00138
00139 fsURL url;
00140 if (IR_SUCCESS == url.Crack (m_strUrl) && *url.GetHostName ())
00141 {
00142 fsURL u;
00143 char szUrl [10000];
00144 DWORD dwLen = 10000;
00145 u.Create (url.GetInternetScheme (), url.GetHostName (), url.GetPort (), NULL, NULL, url.GetPath (), szUrl, &dwLen);
00146 m_strUrl = szUrl;
00147
00148 if (*url.GetUserName ())
00149 m_bAuthChanged = TRUE;
00150 }
00151
00152 UpdateEnabled ();
00153
00154 Update_User_Password ();
00155
00156 SetDlgItemText (IDC_URL, m_strUrl == "http://url/" ? "http://" : m_strUrl);
00157 ((CEdit*) GetDlgItem (IDC_URL))->SetSel (0, -1);
00158
00159 UrlChanged ();
00160
00161 DWORD dwAtoZ = _App.CreateBD_LastAtoZ ();
00162 int az1 = LOWORD (dwAtoZ);
00163 int az2 = HIWORD (dwAtoZ);
00164
00165 if ((az1 < 0 || az2 >= 'Z' - 'A') ||
00166 (az2 < 0 || az2 > 'Z' - 'A' - 1))
00167 {
00168 az1 = 0; az2 = 'Z' - 'A' - 1;
00169 }
00170
00171 for (i = 0; i < 'Z' - 'A'; i++)
00172 {
00173 CString str = (char)('A' + i);
00174 m_wndA.AddString (str);
00175 }
00176 m_wndA.SetCurSel (az1);
00177 FillZ ();
00178 m_wndZ.SetCurSel (az2);
00179
00180 ReadAutostart ();
00181 ApplyLanguage ();
00182
00183 if (m_wndGroups.SelectGroupById (_App.NewDL_GroupId ()))
00184 m_bGroupChanged = TRUE;
00185
00186 OnChangeGroups ();
00187
00188 SetDlgItemText (IDC_NUMBERS, _App.CreateBD_LastNumbers ());
00189
00190 CString strSaveAs = _App.CreateBD_SaveAs_Template ();
00191 SetDlgItemText (IDC_SAVEAS, strSaveAs);
00192 if (strSaveAs == "") {
00193 CheckDlgButton (IDC_FILEAUTO, BST_CHECKED);
00194 UpdateEnabled ();
00195 }
00196
00197 m_dld->dwFlags |= DLD_BATCH;
00198
00199 return TRUE;
00200
00201 }
00202
00203 void CCreateBatchDownload::OnChangeGroups()
00204 {
00205 SetDlgItemText (IDC_OUTFOLDER, m_wndGroups.GetSelectedGroup ()->strOutFolder);
00206 }
00207
00208 void CCreateBatchDownload::OnSelchangeGroups()
00209 {
00210 OnChangeGroups ();
00211 m_bGroupChanged = TRUE;
00212 }
00213
00214 void CCreateBatchDownload::UpdateEnabled()
00215 {
00216 GetDlgItem (IDC__USER)->EnableWindow (m_bAuthorization);
00217 GetDlgItem (IDC_USER)->EnableWindow (m_bAuthorization);
00218 GetDlgItem (IDC__PASSWORD)->EnableWindow (m_bAuthorization);
00219 GetDlgItem (IDC_PASSWORD)->EnableWindow (m_bAuthorization);
00220
00221 BOOL b = IsDlgButtonChecked (IDC_FILEAUTO) == BST_UNCHECKED;
00222 GetDlgItem (IDC__SAVEAS)->EnableWindow (b);
00223 GetDlgItem (IDC_SAVEAS)->EnableWindow (b);
00224 }
00225
00226 void CCreateBatchDownload::Update_User_Password()
00227 {
00228 BOOL b = m_bAuthChanged;
00229
00230 fsDownload_NetworkProperties *dnp = m_dld->pMgr->GetDownloadMgr ()->GetDNP ();
00231 if (*dnp->pszUserName)
00232 {
00233 CheckDlgButton (IDC_USELOGIN, BST_CHECKED);
00234 m_bAuthorization = TRUE;
00235 }
00236 else
00237 {
00238 CheckDlgButton (IDC_USELOGIN, BST_UNCHECKED);
00239 m_bAuthorization = FALSE;
00240 }
00241
00242 SetDlgItemText (IDC_USER, dnp->pszUserName);
00243 SetDlgItemText (IDC_PASSWORD, dnp->pszPassword);
00244
00245 UpdateEnabled ();
00246
00247 m_bAuthChanged = b;
00248 }
00249
00250 void CCreateBatchDownload::UrlChanged()
00251 {
00252 CHAR szFile [10000];
00253 *szFile = 0;
00254 fsURL url;
00255
00256 m_bBLParametersChanged = true;
00257
00258 if (IR_SUCCESS != url.Crack (m_strUrl))
00259 return;
00260
00261 if (m_bGroupChanged == FALSE)
00262 {
00263 fsFileNameFromUrlPath (url.GetPath (), url.GetInternetScheme () == INTERNET_SCHEME_FTP,
00264 TRUE, szFile, sizeof (szFile));
00265
00266 int len = strlen (szFile);
00267 vmsDownloadsGroupSmartPtr grp;
00268
00269 if (len)
00270 {
00271 for (int i = len-1; i > 0; i--)
00272 if (szFile [i] == '.')
00273 break;
00274
00275 if (i && i < len-1)
00276 {
00277 i++;
00278 CHAR szExt [1000];
00279 strcpy (szExt, szFile + i);
00280 grp = _DldsGrps.FindGroupByExt (szExt);
00281 }
00282 }
00283
00284 if (grp == NULL)
00285 grp = _DldsGrps.FindGroup (GRP_OTHER_ID);
00286
00287 if (grp != NULL)
00288 {
00289 if (m_wndGroups.SelectGroup (grp))
00290 OnChangeGroups();
00291 }
00292 }
00293
00294 fsSiteInfo *site = _SitesMgr.FindSite2 (url.GetHostName (), fsNPToSiteValidFor (fsSchemeToNP (url.GetInternetScheme ())));
00295 if (site)
00296 {
00297 if (site->strUser != NULL && m_bAuthChanged == FALSE && *url.GetUserName () == 0)
00298 {
00299
00300 CheckDlgButton (IDC_USELOGIN, BST_CHECKED);
00301 SetDlgItemText (IDC_USER, site->strUser);
00302 if (site->strPassword)
00303 SetDlgItemText (IDC_PASSWORD, site->strPassword);
00304 m_bAuthorization = TRUE;
00305 UpdateEnabled ();
00306 }
00307
00308 if (site->pGroup && m_bGroupChanged == FALSE)
00309 {
00310 m_wndGroups.SelectGroup (site->pGroup);
00311 OnChangeGroups();
00312 }
00313 }
00314 }
00315
00316 void CCreateBatchDownload::ReadAutostart()
00317 {
00318 m_iAutostart = _App.Last_Autostart ();
00319
00320 switch (m_iAutostart)
00321 {
00322 case 0:
00323 CheckRadioButton (IDC_STARTNOW, IDC_STARTSCHEDULE, IDC_STARTNOW);
00324 m_dld->bAutoStart = TRUE;
00325 m_bScheduled = FALSE;
00326 break;
00327
00328 case 1:
00329 CheckRadioButton (IDC_STARTNOW, IDC_STARTSCHEDULE, IDC_STARTMANUAL);
00330 m_dld->bAutoStart = FALSE;
00331 m_bScheduled = FALSE;
00332 break;
00333
00334 case 2:
00335 CheckRadioButton (IDC_STARTNOW, IDC_STARTSCHEDULE, IDC_STARTSCHEDULE);
00336 m_dld->bAutoStart = FALSE;
00337 m_bScheduled = TRUE;
00338 break;
00339 }
00340 }
00341
00342 void CCreateBatchDownload::ApplyLanguage()
00343 {
00344 fsDlgLngInfo lnginfo [] = {
00345 fsDlgLngInfo (IDC_USELOGIN, L_AUTHORIZATION),
00346 fsDlgLngInfo (IDC__USER, L_USER),
00347 fsDlgLngInfo (IDC__PASSWORD, L_PASSWORD),
00348 fsDlgLngInfo (IDC__SAVETO, L_SAVETO),
00349 fsDlgLngInfo (IDC__START, L_START),
00350 fsDlgLngInfo (IDC_STARTNOW, L_AUTOMATICALLY),
00351 fsDlgLngInfo (IDC_STARTMANUAL, L_MANUALLY),
00352 fsDlgLngInfo (IDC_STARTSCHEDULE, L_SCHEDULE),
00353 fsDlgLngInfo (IDC__GROUP, L_GROUP),
00354 fsDlgLngInfo (IDC_ADVANCED, L_ADVANCED),
00355 fsDlgLngInfo (IDCANCEL, L_CANCEL),
00356 fsDlgLngInfo (IDC__FROM2, L_DLGFROM),
00357 fsDlgLngInfo (IDC__TO2, L_DLGTO),
00358 fsDlgLngInfo (IDC_RESULTS, L_SEERESULTS),
00359 fsDlgLngInfo (IDC__SAMPLE, L_DLGSAMPLE),
00360 fsDlgLngInfo (IDC_QUERYSIZE, L_QUERYSIZE),
00361 fsDlgLngInfo (IDC__SETOFNUMBERS, L_SETOFNUMBERS, TRUE),
00362 fsDlgLngInfo (IDC_SETNUMBERS, L_ASSIGN),
00363 fsDlgLngInfo (IDC_FILEAUTO, L_FILEAUTO),
00364 fsDlgLngInfo (IDC__SAVEAS, L_DLG_SAVE_AS_TEMPLATE),
00365 };
00366
00367 _LngMgr.ApplyLanguage (this, lnginfo, sizeof (lnginfo) / sizeof (fsDlgLngInfo), L_CREATEBATCHDLD);
00368 }
00369
00370 void CCreateBatchDownload::OnEditchangeUrl()
00371 {
00372 GetDlgItemText (IDC_URL, m_strUrl);
00373 UrlChanged ();
00374 }
00375
00376 void CCreateBatchDownload::OnSelchangeUrl()
00377 {
00378 CComboBox *pUrl = (CComboBox*) GetDlgItem (IDC_URL);
00379 pUrl->GetLBText (pUrl->GetCurSel (), m_strUrl);
00380 UrlChanged ();
00381 }
00382
00383 void CCreateBatchDownload::OnUselogin()
00384 {
00385 m_bAuthorization = IsDlgButtonChecked (IDC_USELOGIN) == BST_CHECKED;
00386 UpdateEnabled ();
00387 }
00388
00389 void CCreateBatchDownload::OnChangeUser()
00390 {
00391 m_bAuthChanged = TRUE;
00392 }
00393
00394 void CCreateBatchDownload::OnChangePassword()
00395 {
00396 m_bAuthChanged = TRUE;
00397 }
00398
00399 void CCreateBatchDownload::OnStartnow()
00400 {
00401 m_dld->bAutoStart = TRUE;
00402 m_bScheduled = FALSE;
00403 m_iAutostart = 0;
00404 }
00405
00406 void CCreateBatchDownload::OnStartmanual()
00407 {
00408 m_bScheduled = FALSE;
00409 m_dld->bAutoStart = FALSE;
00410 m_iAutostart = 1;
00411 }
00412
00413 void CCreateBatchDownload::OnStartschedule()
00414 {
00415 m_bScheduled = TRUE;
00416 m_dld->bAutoStart = FALSE;
00417 m_iAutostart = 2;
00418 }
00419
00420 void CCreateBatchDownload::OnCreategroup()
00421 {
00422 if (m_wndGroups.CreateNewGroup (m_wndGroups.GetSelectedGroup ()))
00423 OnChangeGroups ();
00424 }
00425
00426 void CCreateBatchDownload::OnChoosefolder()
00427 {
00428 CString str = "";
00429 GetDlgItemText (IDC_OUTFOLDER, str);
00430
00431 if (str.GetLength () > 3 && (str [str.GetLength () - 1] == '\\' || str [str.GetLength () - 1] == '/'))
00432 str.GetBuffer (0) [str.GetLength () - 1] = 0;
00433
00434 CFolderBrowser *fb = CFolderBrowser::Create (LS (L_CHOOSEOUTFOLDER), str, NULL, this);
00435 if (fb == NULL)
00436 return;
00437
00438 SetDlgItemText (IDC_OUTFOLDER, fb->GetPath ());
00439 GetDlgItem (IDC_OUTFOLDER)->SetFocus ();
00440 }
00441
00442 void CCreateBatchDownload::OnSettime()
00443 {
00444 CScheduleSheet sheet (LS (L_SCHEDULEDLDS), this);
00445
00446 sheet.Init (&m_task, FALSE);
00447
00448 _DlgMgr.OnDoModal (&sheet);
00449
00450 if (IDOK == sheet.DoModal ())
00451 {
00452 CheckRadioButton (IDC_STARTNOW, IDC_STARTSCHEDULE, IDC_STARTSCHEDULE);
00453 m_bScheduled = TRUE;
00454 m_dld->bAutoStart = FALSE;
00455 m_iAutostart = 2;
00456 }
00457
00458 _DlgMgr.OnEndDialog (&sheet);
00459 GetDlgItem (IDC_STARTSCHEDULE)->SetFocus ();
00460 }
00461
00462 void CCreateBatchDownload::OnAdvanced()
00463 {
00464 DLDS_LIST v;
00465 v.push_back (m_dld);
00466
00467 GetDlgItemText (IDC_URL, m_strUrl);
00468 fsURL url;
00469
00470 if (url.Crack (m_strUrl) != IR_SUCCESS)
00471 {
00472 WrongUrl ();
00473 return;
00474 }
00475
00476 m_dld->pMgr->GetDownloadMgr ()->GetDNP ()->enProtocol = fsSchemeToNP (url.GetInternetScheme ());
00477
00478 CDownloadPropertiesSheet sheet (LS (L_ADVANCED), this);
00479 sheet.Init (&v, DPS_SHP_NOGENERALNOMIRR);
00480 _DlgMgr.OnDoModal (&sheet);
00481 sheet.DoModal ();
00482 _DlgMgr.OnEndDialog (&sheet);
00483 }
00484
00485 void CCreateBatchDownload::OnContextMenu(CWnd* , CPoint point)
00486 {
00487 PrepareCHMgr (point);
00488 _CHMgr.ShowMenu ();
00489 }
00490
00491 BOOL CCreateBatchDownload::OnHelpInfo(HELPINFO* pHelpInfo)
00492 {
00493 RECT rc;
00494 CWnd *pItem = GetDlgItem (pHelpInfo->iCtrlId);
00495 if (pItem == NULL)
00496 return TRUE;
00497 pItem->GetWindowRect (&rc);
00498 if (PtInRect (&rc, pHelpInfo->MousePos) == FALSE)
00499 {
00500 pHelpInfo->MousePos.x = rc.left + (rc.right - rc.left) / 2;
00501 pHelpInfo->MousePos.y = rc.top + (rc.bottom - rc.top) / 2;
00502 }
00503 PrepareCHMgr (pHelpInfo->MousePos);
00504 _CHMgr.OnWT ();
00505 return TRUE;
00506 }
00507
00508 void CCreateBatchDownload::OnWhatisthis()
00509 {
00510 _CHMgr.OnWT ();
00511 }
00512
00513 void CCreateBatchDownload::PrepareCHMgr(CPoint point)
00514 {
00515 fsCtrlContextHelp aCH1 [] = {
00516 fsCtrlContextHelp (IDC__URL, LS (L_ADDROFFILE)),
00517 fsCtrlContextHelp (IDC_URL, LS (L_ADDROFFILE)),
00518 fsCtrlContextHelp (IDC__USER, LS (L_USERHERE)),
00519 fsCtrlContextHelp (IDC_USER, LS (L_USERHERE)),
00520 fsCtrlContextHelp (IDC__PASSWORD, LS (L_PWDHERE)),
00521 fsCtrlContextHelp (IDC_PASSWORD, LS (L_PWDHERE)),
00522 fsCtrlContextHelp (IDC_USELOGIN, LS (L_LOGINHERE)),
00523 fsCtrlContextHelp (IDC__GROUP, LS (L_GROUPHERE)),
00524 fsCtrlContextHelp (IDC_GROUPS, LS (L_GROUPHERE)),
00525 fsCtrlContextHelp (IDC_CREATEGROUP, LS (L_CREATEGRP)),
00526 fsCtrlContextHelp (IDC__SAVETO, LS (L_DLDFOLDERHERE)),
00527 fsCtrlContextHelp (IDC_OUTFOLDER, LS (L_DLDFOLDERHERE)),
00528 fsCtrlContextHelp (IDC_CHOOSEFOLDER, LS (L_BROWSEFOR)),
00529 fsCtrlContextHelp (IDC_STARTNOW, LS (L_STARTNOWHERE)),
00530 fsCtrlContextHelp (IDC_STARTMANUAL, LS (L_MANUALLYSTARTHERE)),
00531 fsCtrlContextHelp (IDC_STARTSCHEDULE, LS (L_SCHEDULESTARTHERE)),
00532 fsCtrlContextHelp (IDC_SETTIME, LS (L_SETTIMEHERE)),
00533 fsCtrlContextHelp (IDC_ADVANCED, LS (L_ADVANCEDHERE)),
00534 fsCtrlContextHelp (IDOK, LS (L_ACCEPTCHANGES)),
00535 fsCtrlContextHelp (IDCANCEL, LS (L_DONTACCEPTCHANGES)),
00536 fsCtrlContextHelp (IDC_RESULTS, LS (L_SEERESULTSHERE)),
00537 fsCtrlContextHelp (IDC_QUERYSIZE, LS (L_QUERYBATCHSIZEHERE)),
00538 fsCtrlContextHelp (IDC__SETOFNUMBERS, LS (L_SETOFNUMBERS_HERE)),
00539 fsCtrlContextHelp (IDC_NUMBERS, LS (L_SETOFNUMBERS_HERE)),
00540 fsCtrlContextHelp (IDC_SETNUMBERS, LS (L_ASSIGNSETOFNUMBERS_HERE)),
00541 };
00542
00543 static fsCtrlContextHelp aCH [sizeof (aCH1) / sizeof (fsCtrlContextHelp)];
00544 CopyMemory (aCH, aCH1, sizeof (aCH));
00545
00546 _CHMgr.PrepareContextMenu (this, point, aCH, sizeof (aCH) / sizeof (fsCtrlContextHelp));
00547 }
00548
00549 void CCreateBatchDownload::OnResults()
00550 {
00551 if (FALSE == BuildBatchList ())
00552 return;
00553
00554 CCBD_SeeResultsDlg dlg;
00555 dlg.m_bl = &m_bl;
00556
00557 _DlgMgr.DoModal (&dlg);
00558 }
00559
00560 BOOL CCreateBatchDownload::BuildBatchList()
00561 {
00562 if (m_bBLParametersChanged == false)
00563 return TRUE;
00564
00565 GetDlgItemText (IDC_URL, m_strUrl);
00566 if (FALSE == CheckUrl ())
00567 return FALSE;
00568
00569 m_iAlphaFrom = m_wndA.GetCurSel ();
00570 m_iAlphaTo = m_iAlphaFrom + m_wndZ.GetCurSel () + 1;
00571 CString strNumbers;
00572 GetDlgItemText (IDC_NUMBERS, strNumbers);
00573 if (false == m_bl.Create (m_strUrl, strNumbers, (char)('A' + m_iAlphaFrom),
00574 (char)('A' + m_iAlphaTo))) {
00575 MessageBox (LS (L_SYNTAXERROR), LS (L_INPERR), MB_ICONERROR);
00576 GetDlgItem (IDC_NUMBERS)->SetFocus ();
00577 return FALSE;
00578 }
00579
00580 FreeDownloads ();
00581 m_bBLParametersChanged = false;
00582
00583 return TRUE;
00584 }
00585
00586 void CCreateBatchDownload::WrongUrl()
00587 {
00588 MessageBox (LS (L_CHECKURL), LS (L_INPERR), MB_ICONEXCLAMATION);
00589 GetDlgItem (IDC_URL)->SetFocus ();
00590 }
00591
00592 BOOL CCreateBatchDownload::CheckUrl()
00593 {
00594 fsURL url;
00595 GetDlgItemText (IDC_URL, m_strUrl);
00596 if (url.Crack (m_strUrl) != IR_SUCCESS || *url.GetHostName () == 0 || *url.GetPath () == 0)
00597 {
00598 WrongUrl ();
00599 return FALSE;
00600 }
00601
00602 if (m_strUrl.Find ("(*)") == -1 &&
00603 m_strUrl.Find ("(*A)") == -1 &&
00604 m_strUrl.Find ("(*a)") == -1)
00605 {
00606 MessageBox (LS (L_USEBDS2), LS (L_INPERR), MB_ICONEXCLAMATION);
00607 GetDlgItem (IDC_URL)->SetFocus ();
00608 return FALSE;
00609 }
00610
00611 return TRUE;
00612 }
00613
00614 void CCreateBatchDownload::OnOK()
00615 {
00616 if (FALSE == ReadAuth ())
00617 return;
00618
00619 if (FALSE == BuildBatchList ())
00620 return;
00621
00622 CString strSaveAs;
00623 if (IsDlgButtonChecked (IDC_FILEAUTO) == BST_UNCHECKED)
00624 {
00625 GetDlgItemText (IDC_SAVEAS, strSaveAs);
00626 }
00627
00628 if (strSaveAs != "")
00629 {
00630 CString strNumbers;
00631 GetDlgItemText (IDC_NUMBERS, strNumbers);
00632
00633 m_blSaveAs.Create (strSaveAs, strNumbers, (char)('A' + m_iAlphaFrom),
00634 (char)('A' + m_iAlphaTo));
00635
00636 if (m_bl.get_ResultCount () != m_blSaveAs.get_ResultCount ())
00637 {
00638 MessageBox (LS (L_INVALID_SAVE_AS_TEMPLATE), LS (L_INPERR), MB_ICONERROR);
00639 GetDlgItem (IDC_SAVEAS)->SetFocus ();
00640 return;
00641 }
00642
00643 if (strcspn (m_blSaveAs.get_Result (0), "\\/:*?\"<>|") != strlen (m_blSaveAs.get_Result (0)))
00644 {
00645 MessageBox (LS (L_INVFILENAME), LS (L_INPERR), MB_ICONEXCLAMATION);
00646 GetDlgItem (IDC_SAVEAS)->SetFocus ();
00647 return;
00648 }
00649 }
00650 else {
00651 m_blSaveAs.Clear ();
00652 }
00653
00654 BOOL bUseZipPreview = _App.NewDL_UseZIPPreview ();
00655
00656 if (bUseZipPreview)
00657 m_dld->pMgr->GetDownloadMgr ()->GetDP ()->dwFlags |= DPF_USEZIPPREVIEW;
00658 else
00659 m_dld->pMgr->GetDownloadMgr ()->GetDP ()->dwFlags &= ~DPF_USEZIPPREVIEW;
00660
00661 CString strOutFolder;
00662
00663 if (FALSE == CCreateDownloadDlg::_CheckFolderName (this, IDC_OUTFOLDER))
00664 return;
00665
00666 GetDlgItemText (IDC_OUTFOLDER, strOutFolder);
00667
00668 fsPathToGoodPath ((LPSTR)(LPCSTR)strOutFolder);
00669
00670 if (strOutFolder.GetLength () == 0)
00671 {
00672 MessageBox (LS (L_ENTERFLRNAME), LS (L_INPERR), MB_ICONEXCLAMATION);
00673 GetDlgItem (IDC_OUTFOLDER)->SetFocus ();
00674 return;
00675 }
00676
00677 _LastFolders.AddRecord (strOutFolder);
00678 _LastBatchUrls.AddRecord (m_strUrl);
00679
00680 if (strOutFolder [strOutFolder.GetLength () - 1] != '\\' &&
00681 strOutFolder [strOutFolder.GetLength () - 1] != '/')
00682 strOutFolder += '\\';
00683
00684 if (_App.NewGrp_SelectWay () == NGSW_USE_ALWAYS_SAME_GROUP_WITH_OUTFOLDER_AUTO_UPDATE)
00685 {
00686 vmsDownloadsGroupSmartPtr pGrp = _DldsGrps.FindGroup (_App.NewDL_GroupId ());
00687 if (pGrp != NULL)
00688 pGrp->strOutFolder = strOutFolder;
00689 }
00690
00691 fsnew (m_dld->pMgr->GetDownloadMgr ()->GetDP ()->pszFileName, CHAR, strOutFolder.GetLength () + 1);
00692 strcpy (m_dld->pMgr->GetDownloadMgr ()->GetDP ()->pszFileName, strOutFolder);
00693
00694 m_dld->pGroup = m_wndGroups.GetSelectedGroup ();
00695
00696 m_wndGroups.RememberSelectedGroup ();
00697
00698 _App.Last_Autostart (m_iAutostart);
00699
00700 GenerateAndAddDownloads ();
00701
00702 _App.CreateBD_LastAtoZ (MAKELPARAM (m_wndA.GetCurSel (), m_wndZ.GetCurSel ()));
00703 CString str;
00704 GetDlgItemText (IDC_NUMBERS, str);
00705 _App.CreateBD_LastNumbers (str);
00706 _App.CreateBD_SaveAs_Template (strSaveAs);
00707
00708 if (m_dld->pMgr->GetDownloadMgr ()->GetDNP ()->pszUserName && *m_dld->pMgr->GetDownloadMgr ()->GetDNP ()->pszUserName)
00709 {
00710 fsURL url;
00711 url.Crack (m_strUrl);
00712 LPCSTR pszServer = url.GetHostName ();
00713 if (strstr (pszServer, "(*)") == NULL &&
00714 strstr (pszServer, "(*a)") == NULL &&
00715 strstr (pszServer, "(*A)") == NULL)
00716 {
00717 CCreateDownloadDlg::_SavePassword (pszServer, fsSchemeToNP (url.GetInternetScheme ()),
00718 m_dld->pMgr->GetDownloadMgr ()->GetDNP ()->pszUserName, m_dld->pMgr->GetDownloadMgr ()->GetDNP ()->pszPassword);
00719 }
00720 }
00721
00722 _App.OnDlHasBeenCreatedByUser ();
00723
00724 CDialog::OnOK();
00725 }
00726
00727 BOOL CCreateBatchDownload::ReadAuth()
00728 {
00729 CString strUser, strPassword;
00730
00731 if (IsDlgButtonChecked (IDC_USELOGIN) == BST_CHECKED)
00732 {
00733 GetDlgItemText (IDC_USER, strUser);
00734 GetDlgItemText (IDC_PASSWORD, strPassword);
00735
00736 if (strUser.GetLength () == 0)
00737 {
00738 MessageBox (LS (L_ENTERUSER), LS (L_INPERR), MB_ICONEXCLAMATION);
00739 GetDlgItem (IDC_USER)->SetFocus ();
00740 return FALSE;
00741 }
00742 }
00743 else
00744 {
00745 fsURL url;
00746 url.Crack (m_strUrl);
00747 strUser = url.GetUserName ();
00748 strPassword = url.GetPassword ();
00749 }
00750
00751 if (strUser != "")
00752 {
00753 fsDownload_NetworkProperties *dnp = m_dld->pMgr->GetDownloadMgr ()->GetDNP ();
00754
00755 SAFE_DELETE_ARRAY (dnp->pszUserName);
00756 SAFE_DELETE_ARRAY (dnp->pszPassword);
00757
00758 fsnew (dnp->pszUserName, CHAR, strUser.GetLength ()+1);
00759 fsnew (dnp->pszPassword, CHAR, strPassword.GetLength ()+1);
00760 strcpy (dnp->pszUserName, strUser);
00761 strcpy (dnp->pszPassword, strPassword);
00762 }
00763
00764 return TRUE;
00765 }
00766
00767 void CCreateBatchDownload::GenerateAndAddDownloads()
00768 {
00769
00770 if (m_pvDownloads == NULL)
00771 m_pvDownloads = GenerateDownloads ();
00772
00773
00774 ASSERT (m_blSaveAs.get_ResultCount () == 0 || m_blSaveAs.get_ResultCount () == (int)m_pvDownloads->size ());
00775 LPCSTR psz = m_dld->pMgr->GetDownloadMgr ()->GetDP ()->pszFileName;
00776 int len = lstrlen (psz);
00777 for (size_t i = 0; i < (size_t)m_blSaveAs.get_ResultCount (); i++)
00778 {
00779 fsDownload_Properties* dp = m_pvDownloads->at (i)->pMgr->GetDownloadMgr ()->GetDP ();
00780 LPCSTR pszAs = m_blSaveAs.get_Result (i);
00781
00782 if (dp->pszFileName)
00783 delete [] dp->pszFileName;
00784
00785 dp->pszFileName = new char [len + lstrlen (pszAs) + 1];
00786 lstrcpy (dp->pszFileName, psz);
00787 lstrcat (dp->pszFileName, pszAs);
00788 }
00789
00790 for (i = 0; i < m_pvDownloads->size (); i++)
00791 fsDownloadsMgr::Download_CloneSettings (m_pvDownloads->at (i), m_dld);
00792
00793 _pwndDownloads->CreateDownloads (*m_pvDownloads, m_bScheduled ? &m_task : NULL);
00794
00795 FreeDownloads ();
00796 }
00797
00798 DLDS_LIST* CCreateBatchDownload::GenerateDownloads()
00799 {
00800 DLDS_LIST *vpDlds = new DLDS_LIST;
00801
00802 for (int i = 0; i < m_bl.get_ResultCount (); i++)
00803 {
00804 vmsDownloadSmartPtr dld;
00805 Download_CreateInstance (dld);
00806
00807 dld->pMgr->GetDownloadMgr ()->CreateByUrl (m_bl.get_Result (i), TRUE);
00808 vpDlds->push_back (dld);
00809 }
00810
00811 return vpDlds;
00812 }
00813
00814 void CCreateBatchDownload::OnQuerysize()
00815 {
00816 if (FALSE == CheckUrl ())
00817 return;
00818
00819 if (FALSE == ReadAuth ())
00820 return;
00821
00822 if (m_bBLParametersChanged)
00823 {
00824 if (FALSE == BuildBatchList ())
00825 return;
00826
00827 m_pvDownloads = GenerateDownloads ();
00828 }
00829
00830 CWaitDlg dlg;
00831 dlg.StartWaiting (LS (L_QUERINGSIZE), _threadCalcSize, TRUE, this, &dlg);
00832 }
00833
00834 DWORD WINAPI CCreateBatchDownload::_threadCalcSize(LPVOID lp)
00835 {
00836 ProcWaitInfo *info = (ProcWaitInfo*) lp;
00837 CCreateBatchDownload* pThis = (CCreateBatchDownload*) info->lpParam1;
00838
00839 DWORD dw;
00840 CloseHandle (CreateThread (NULL, 0, _threadCalculateSize, lp, 0, &dw));
00841
00842 while (info->bWaitDone == FALSE)
00843 {
00844 if (info->bNeedStop)
00845 {
00846 for (size_t i = 0; i < pThis->m_pvDownloads->size (); i++)
00847 pThis->m_pvDownloads->at (i)->pMgr->GetDownloadMgr ()->StopQuering ();
00848
00849 break;
00850 }
00851
00852 Sleep (500);
00853 }
00854
00855 return 0;
00856 }
00857
00858 DWORD WINAPI CCreateBatchDownload::_threadCalculateSize(LPVOID lp)
00859 {
00860 ProcWaitInfo *info = (ProcWaitInfo*) lp;
00861 CWaitDlg* dlg = (CWaitDlg*) info->lpParam2;
00862 CCreateBatchDownload* pThis = (CCreateBatchDownload*) info->lpParam1;
00863
00864 int iFailed = 0;
00865 UINT64 uSummSize = 0;
00866
00867 for (size_t i = 0; i < pThis->m_pvDownloads->size () && info->bNeedStop == FALSE; i++)
00868 {
00869 vmsDownloadSmartPtr dld = pThis->m_pvDownloads->at (i);
00870 if (IR_SUCCESS != dld->pMgr->GetDownloadMgr ()->QuerySize ())
00871 iFailed ++;
00872
00873 UINT64 uSize = dld->pMgr->GetDownloadMgr ()->GetDownloader ()->GetSSFileSize ();
00874
00875
00876 if (uSize == _UI64_MAX)
00877 {
00878 uSummSize = _UI64_MAX;
00879 break;
00880 }
00881
00882 uSummSize += uSize;
00883
00884 CString str;
00885 str.Format ("%s (%d - %s, %d - %s)", LS (L_QUERINGSIZE), i+1, LS (L_DONE), iFailed, LS (L_ERR));
00886 dlg->SetDlgItemText (IDC_MESSAGE, str);
00887
00888 info->iProgress = (int) ((double) i / pThis->m_pvDownloads->size () * 100);
00889 }
00890
00891 if (info->bNeedStop == FALSE)
00892 {
00893 CString strSize;
00894
00895 if (uSummSize == _UI64_MAX)
00896 strSize = LS (L_UNKNOWN);
00897 else
00898 {
00899 if (_pwndDownloads->IsSizesInBytes () == FALSE)
00900 {
00901 char szDim [50];
00902 float fSize;
00903 BytesToXBytes (uSummSize, &fSize, szDim);
00904 strSize.Format ("%.*g %s", fSize > 999 ? 4 : 3, fSize, szDim);
00905 }
00906 else
00907 strSize = fsBytesToStr (uSummSize);
00908 }
00909
00910 pThis->SetDlgItemText (IDC_QUERYSIZE, strSize);
00911 }
00912 else
00913 pThis->SetDlgItemText (IDC_QUERYSIZE, LS (L_QUERYSIZE));
00914
00915 info->bWaitDone = TRUE;
00916
00917 return 0;
00918 }
00919
00920 void CCreateBatchDownload::OnCancel()
00921 {
00922 FreeDownloads ();
00923 CDialog::OnCancel();
00924 }
00925
00926 void CCreateBatchDownload::FreeDownloads()
00927 {
00928 if (m_pvDownloads)
00929 {
00930 delete m_pvDownloads;
00931 m_pvDownloads = NULL;
00932 }
00933 }
00934
00935 void CCreateBatchDownload::FillZ()
00936 {
00937 CString str;
00938 if (m_wndZ.GetCurSel () != LB_ERR)
00939 m_wndZ.GetLBText (m_wndZ.GetCurSel (), str);
00940
00941 m_wndZ.ResetContent ();
00942 for (int i = m_wndA.GetCurSel () + 1; i <= 'Z' - 'A'; i++)
00943 {
00944 CString str = (char)('A' + i);
00945 m_wndZ.AddString (str);
00946 }
00947
00948 if (str != "")
00949 m_wndZ.SelectString (-1, str);
00950 if (m_wndZ.GetCurSel () == LB_ERR)
00951 m_wndZ.SetCurSel (m_wndZ.GetCount ()-1);
00952 }
00953
00954 void CCreateBatchDownload::OnSelchangeA()
00955 {
00956 FillZ ();
00957 m_bBLParametersChanged = true;
00958 }
00959
00960 void CCreateBatchDownload::OnSelchangeZ()
00961 {
00962 m_bBLParametersChanged = true;
00963 }
00964
00965 void CCreateBatchDownload::OnChangeNumbers()
00966 {
00967 m_bBLParametersChanged = true;
00968 }
00969
00970 void CCreateBatchDownload::OnSetnumbers()
00971 {
00972 CDlg_SetBatchNumbers dlg;
00973 if (IDOK == _DlgMgr.DoModal (&dlg))
00974 SetDlgItemText (IDC_NUMBERS, dlg.m_strNumbers);
00975 }
00976
00977 void CCreateBatchDownload::OnFileauto()
00978 {
00979 UpdateEnabled ();
00980 }
00981
00982 void CCreateBatchDownload::OnOutfolderSetdefault()
00983 {
00984 CString strOutFolder;
00985 GetDlgItemText (IDC_OUTFOLDER, strOutFolder);
00986
00987 CCreateDownloadDlg::_SetDownloadOutputFolderAsDefault (this, strOutFolder,
00988 m_wndGroups.GetSelectedGroup ());
00989 }