00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "CreateDownloadsDlg.h"
00009 #include "CreateDownloadDlg.h"
00010 #include "HFE_FileList.h"
00011 #include "DownloadsWnd.h"
00012 #include "GroupDlg.h"
00013 #include "FolderBrowser.h"
00014 #include "ScheduleSheet.h"
00015 #include "inetutil.h"
00016 #include "DownloadPropertiesSheet.h"
00017
00018 #ifdef _DEBUG
00019 #define new DEBUG_NEW
00020 #undef THIS_FILE
00021 static char THIS_FILE[] = __FILE__;
00022 #endif
00023
00024 extern CDownloadsWnd* _pwndDownloads;
00025
00026 CCreateDownloadsDlg::CCreateDownloadsDlg(CWnd* pParent )
00027 : CDialog(CCreateDownloadsDlg::IDD, pParent)
00028 {
00029
00030
00031 m_bSort = TRUE;
00032 m_pGroup = NULL;
00033 }
00034
00035 void CCreateDownloadsDlg::DoDataExchange(CDataExchange* pDX)
00036 {
00037 CDialog::DoDataExchange(pDX);
00038
00039 DDX_Control(pDX, IDC_OUTFOLDER_SETDEFAULT, m_btnOutFolderSetDefault);
00040 DDX_Control(pDX, IDC_GROUPS, m_wndGroups);
00041 DDX_Control(pDX, IDC_SETTIME, m_btnSetTime);
00042 DDX_Control(pDX, IDC_CHOOSEFOLDER, m_btnChooseFolder);
00043 DDX_Control(pDX, IDC_CREATEGROUP, m_btnCreateGroup);
00044
00045
00046 DDX_Control(pDX, IDC_FILES, m_wndFiles);
00047 }
00048
00049 BEGIN_MESSAGE_MAP(CCreateDownloadsDlg, CDialog)
00050
00051 ON_CBN_SELCHANGE(IDC_GROUPS, OnSelchangeGroups)
00052 ON_BN_CLICKED(IDC_CREATEGROUP, OnCreategroup)
00053 ON_BN_CLICKED(IDC_CHOOSEFOLDER, OnChoosefolder)
00054 ON_BN_CLICKED(IDC_SETTIME, OnSettime)
00055 ON_BN_CLICKED(IDC_ADVANCED, OnAdvanced)
00056 ON_BN_CLICKED(IDC_STARTNOW, OnStartnow)
00057 ON_BN_CLICKED(IDC_STARTMANUAL, OnStartmanual)
00058 ON_BN_CLICKED(IDC_STARTSCHEDULE, OnStartschedule)
00059 ON_NOTIFY(TVN_SELCHANGED, IDC_FILES, OnSelchangedFiles)
00060 ON_BN_CLICKED(IDC_SELECTFOLDER, OnSelectfolder)
00061 ON_BN_CLICKED(IDC_UNSELECTFOLDER, OnUnselectfolder)
00062 ON_WM_CONTEXTMENU()
00063 ON_COMMAND(ID_WHATISTHIS, OnWhatisthis)
00064 ON_WM_HELPINFO()
00065 ON_BN_CLICKED(IDC_OUTFOLDER_SETDEFAULT, OnOutfolderSetdefault)
00066
00067 END_MESSAGE_MAP()
00068
00069 BOOL CCreateDownloadsDlg::OnInitDialog()
00070 {
00071 CDialog::OnInitDialog();
00072
00073 m_btnChooseFolder.SetIcon (SICO (IDI_CHOOSEFOLDER));
00074 m_btnCreateGroup.SetIcon (SICO (IDI_CREATEGROUP));
00075 m_btnSetTime.SetIcon (SICO (IDI_SETTIME));
00076 m_btnOutFolderSetDefault.SetIcon (SICO (IDI_SETFOLDERDEFAULT));
00077
00078 m_task.hts.enType = HTS_ONCE;
00079 m_task.hts.last.dwHighDateTime = m_task.hts.last.dwLowDateTime = UINT_MAX;
00080 m_task.dwFlags = SCHEDULE_ENABLED;
00081 SYSTEMTIME time;
00082 GetLocalTime (&time);
00083 if (++time.wHour > 23)
00084 time.wHour = 0;
00085 time.wMinute = 0;
00086 SystemTimeToFileTime (&time, &m_task.hts.next);
00087 m_task.uWaitForConfirmation = 0;
00088
00089 m_wndGroups.Fill ();
00090
00091 CComboBox *pDirs = (CComboBox*) GetDlgItem (IDC_OUTFOLDER);
00092 for (int i = 0; i < _LastFolders.GetRecordCount (); i++)
00093 pDirs->AddString (_LastFolders.GetRecord (i));
00094
00095 CheckRadioButton (IDC_STARTNOW, IDC_STARTSCHEDULE, IDC_STARTNOW);
00096
00097 CBitmap bmp; bmp.Attach (SBMP (IDB_CHECKS));
00098 BITMAP bm; bmp.GetBitmap (&bm);
00099 m_checks.Create (15, bm.bmHeight, ILC_COLOR24|ILC_MASK, 3, 1);
00100 m_checks.Add (&bmp, RGB (255, 0, 255));
00101 m_wndFiles.SetImageList (&m_checks, TVSIL_STATE);
00102
00103 AddToList (m_pFileList, TVI_ROOT);
00104
00105 BuildDownloads (m_pFileList, m_strRootUrl);
00106
00107 if (m_bSort)
00108 {
00109 TVSORTCB sort;
00110 sort.hParent = TVI_ROOT;
00111 sort.lParam = 0;
00112 sort.lpfnCompare = CHFE_FileList::_SortFunc;
00113 m_wndFiles.SortChildrenCB (&sort);
00114 }
00115
00116 m_wndGroups.SelectGroupById (_App.NewDL_GroupId ());
00117
00118 OnSelchangeGroups ();
00119
00120 ReadAutostart ();
00121 UpdateEnabled ();
00122 ApplyLanguage ();
00123
00124 return TRUE;
00125 }
00126
00127 void CCreateDownloadsDlg::AddToList(fs::tree <fsFileInfo*>* pTree, HTREEITEM hWhere)
00128 {
00129 fs::tree <fsFileInfo*> *pCur = pTree;
00130
00131 while (pCur)
00132 {
00133 fsFileInfo *file = pCur->Data ();
00134 HTREEITEM hItem = m_wndFiles.InsertItem (TVIF_TEXT|TVIF_PARAM, file->strName,
00135 0, 0, 0, 0, (LPARAM) file, hWhere, TVI_LAST);
00136 m_wndFiles.SetCheck (hItem);
00137
00138 if (pCur->Right ())
00139 AddToList (pCur->Right (), hItem);
00140
00141 pCur = pCur->Left ();
00142 }
00143 }
00144
00145 void CCreateDownloadsDlg::OnSelchangeGroups()
00146 {
00147 SetDlgItemText (IDC_OUTFOLDER, m_wndGroups.GetSelectedGroup ()->strOutFolder);
00148 }
00149
00150 void CCreateDownloadsDlg::OnCreategroup()
00151 {
00152 if (m_wndGroups.CreateNewGroup (m_wndGroups.GetSelectedGroup ()))
00153 OnSelchangeGroups ();
00154 }
00155
00156 void CCreateDownloadsDlg::OnChoosefolder()
00157 {
00158 CString str = "";
00159 GetDlgItemText (IDC_OUTFOLDER, str);
00160
00161 if (str.GetLength () > 3 && (str [str.GetLength () - 1] == '\\' || str [str.GetLength () - 1] == '/'))
00162 str.GetBuffer (0) [str.GetLength () - 1] = 0;
00163
00164 CFolderBrowser *fb = CFolderBrowser::Create (LS (L_CHOOSEOUTFOLDER), str, NULL, this);
00165 if (fb == NULL)
00166 return;
00167
00168 SetDlgItemText (IDC_OUTFOLDER, fb->GetPath ());
00169 GetDlgItem (IDC_OUTFOLDER)->SetFocus ();
00170 }
00171
00172 void CCreateDownloadsDlg::OnSettime()
00173 {
00174 CScheduleSheet sheet (LS (L_SCHEDULEDLDS), this);
00175
00176 sheet.Init (&m_task, FALSE);
00177
00178 _DlgMgr.OnDoModal (&sheet);
00179
00180 if (IDOK == sheet.DoModal ())
00181 {
00182 CheckRadioButton (IDC_STARTNOW, IDC_STARTSCHEDULE, IDC_STARTSCHEDULE);
00183 }
00184
00185 _DlgMgr.OnEndDialog (&sheet);
00186 GetDlgItem (IDC_STARTSCHEDULE)->SetFocus ();
00187 }
00188
00189 void CCreateDownloadsDlg::OnAdvanced()
00190 {
00191 CDownloadPropertiesSheet sheet (LS (L_ADVANCED), this);
00192 sheet.Init (&m_vpDlds, DPS_SHP_NOGENERALNOMIRR);
00193 _DlgMgr.OnDoModal (&sheet);
00194 sheet.DoModal ();
00195 _DlgMgr.OnEndDialog (&sheet);
00196 }
00197
00198 void CCreateDownloadsDlg::BuildDownloads(fs::tree <fsFileInfo*>* pTree, LPCSTR pszRootUrl)
00199 {
00200 fs::tree <fsFileInfo*> *pCur = pTree;
00201
00202 while (pCur)
00203 {
00204 fsFileInfo *file = pCur->Data ();
00205
00206 CString strUrl;
00207
00208 char* pszRes;
00209
00210 fsUrlToFullUrl (pszRootUrl, file->strName, &pszRes);
00211
00212 strUrl = pszRes;
00213 delete [] pszRes;
00214
00215 if (pCur->Right ())
00216 {
00217 if (strUrl [strUrl.GetLength () - 1] != '/')
00218 strUrl += '/';
00219 BuildDownloads (pCur->Right (), strUrl);
00220 }
00221 else if (file->bFolder == FALSE)
00222 {
00223
00224 vmsDownloadSmartPtr dld;
00225 Download_CreateInstance (dld);
00226
00227 dld->pMgr->GetDownloadMgr ()->CreateByUrl (strUrl);
00228 m_vpDlds.push_back (dld);
00229 }
00230
00231 pCur = pCur->Left ();
00232 }
00233 }
00234
00235 CCreateDownloadsDlg::~CCreateDownloadsDlg()
00236 {
00237
00238 }
00239
00240 void CCreateDownloadsDlg::UpdateEnabled()
00241 {
00242 HTREEITEM hItem = m_wndFiles.GetSelectedItem ();
00243 BOOL b = hItem && m_wndFiles.ItemHasChildren (hItem);
00244 GetDlgItem (IDC_SELECTFOLDER)->EnableWindow (b);
00245 GetDlgItem (IDC_UNSELECTFOLDER)->EnableWindow (b);
00246 }
00247
00248 void CCreateDownloadsDlg::OnStartnow()
00249 {
00250 UpdateEnabled ();
00251 m_iAutostart = 0;
00252 }
00253
00254 void CCreateDownloadsDlg::OnStartmanual()
00255 {
00256 UpdateEnabled ();
00257 m_iAutostart = 1;
00258 }
00259
00260 void CCreateDownloadsDlg::OnStartschedule()
00261 {
00262 UpdateEnabled ();
00263 m_iAutostart = 2;
00264 }
00265
00266 void CCreateDownloadsDlg::OnOK()
00267 {
00268
00269
00270 CString strFolder;
00271 GetDlgItemText (IDC_OUTFOLDER, strFolder);
00272 if (strFolder == "")
00273 {
00274 MessageBox (LS (L_ENTERFLRNAME), LS (L_INPERR), MB_ICONEXCLAMATION);
00275 GetDlgItem (IDC_OUTFOLDER)->SetFocus ();
00276 return;
00277 }
00278
00279 if (FALSE == CCreateDownloadDlg::_CheckFolderName (this, IDC_OUTFOLDER))
00280 return;
00281
00282 fsPathToGoodPath ((LPSTR)(LPCSTR)strFolder);
00283
00284 _LastFolders.AddRecord (strFolder);
00285 if (strFolder [strFolder.GetLength () - 1] != '\\' &&
00286 strFolder [strFolder.GetLength () - 1] != '/')
00287 strFolder += '\\';
00288
00289 m_wndGroups.RememberSelectedGroup ();
00290 m_bAutoStart = IsDlgButtonChecked (IDC_STARTNOW) == BST_CHECKED;
00291
00292 m_pGroup = m_wndGroups.GetSelectedGroup ();
00293
00294
00295 CreateDownloads (TVI_ROOT, strFolder, TRUE);
00296
00297 BOOL bScheduled = IsDlgButtonChecked (IDC_STARTSCHEDULE) == BST_CHECKED;
00298
00299
00300 _pwndDownloads->CreateDownloads (m_vpDldsToStart, bScheduled ? &m_task : NULL);
00301
00302 BOOL bUseZipPreview = _App.NewDL_UseZIPPreview ();
00303
00304 for (size_t i = 0; i < m_vpDldsToStart.size (); i++)
00305 {
00306 if (bUseZipPreview)
00307 m_vpDldsToStart [i]->pMgr->GetDownloadMgr ()->GetDP ()->dwFlags |= DPF_USEZIPPREVIEW;
00308 else
00309 m_vpDldsToStart [i]->pMgr->GetDownloadMgr ()->GetDP ()->dwFlags &= ~DPF_USEZIPPREVIEW;
00310 }
00311
00312 _App.Last_Autostart (m_iAutostart);
00313 _App.UseZipPreview (bUseZipPreview);
00314
00315 CDialog::OnOK();
00316 }
00317
00318 void CCreateDownloadsDlg::CreateDownloads(HTREEITEM hTree, LPCSTR pszRootDir, BOOL bCreate)
00319 {
00320 static int nDld;
00321
00322 if (hTree == NULL)
00323 return;
00324
00325 if (hTree == TVI_ROOT)
00326 nDld = 0;
00327
00328 HTREEITEM hCur = m_wndFiles.GetChildItem (hTree);
00329
00330 while (hCur)
00331 {
00332 fsFileInfo* file = (fsFileInfo*) m_wndFiles.GetItemData (hCur);
00333
00334 CString strDir;
00335
00336 strDir = pszRootDir;
00337
00338 if (m_wndFiles.ItemHasChildren (hCur))
00339 {
00340 strDir += file->strName;
00341
00342 if (strDir [strDir.GetLength () - 1] != '\\' || strDir [strDir.GetLength () - 1] != '/')
00343 strDir += '\\';
00344 BOOL b = m_wndFiles.IsChecked (hCur);
00345 CreateDownloads (hCur, strDir, b && bCreate);
00346 }
00347 else if (file->bFolder == FALSE)
00348 {
00349 if (m_wndFiles.IsChecked (hCur) && bCreate)
00350 {
00351 vmsDownloadSmartPtr dld = m_vpDlds [nDld];
00352 dld->pGroup = m_pGroup;
00353 dld->bAutoStart = m_bAutoStart;
00354 fsDownload_Properties *dp = dld->pMgr->GetDownloadMgr ()->GetDP ();
00355 fsnew (dp->pszFileName, char, strDir.GetLength () + 1);
00356 strcpy (dp->pszFileName, strDir);
00357
00358 m_vpDldsToStart.push_back (dld);
00359 }
00360
00361 nDld++;
00362 }
00363
00364 hCur = m_wndFiles.GetNextItem (hCur, TVGN_NEXT);
00365 }
00366 }
00367
00368 void CCreateDownloadsDlg::OnSelchangedFiles(NMHDR* , LRESULT* pResult)
00369 {
00370 UpdateEnabled ();
00371 *pResult = 0;
00372 }
00373
00374 void CCreateDownloadsDlg::OnSelectfolder()
00375 {
00376 HTREEITEM hItem = m_wndFiles.GetSelectedItem ();
00377 hItem = m_wndFiles.GetChildItem (hItem);
00378 while (hItem)
00379 {
00380 m_wndFiles.SetCheck (hItem, TRUE);
00381 hItem = m_wndFiles.GetNextItem (hItem, TVGN_NEXT);
00382 }
00383 }
00384
00385 void CCreateDownloadsDlg::OnUnselectfolder()
00386 {
00387 HTREEITEM hItem = m_wndFiles.GetSelectedItem ();
00388 hItem = m_wndFiles.GetChildItem (hItem);
00389 while (hItem)
00390 {
00391 m_wndFiles.SetCheck (hItem, FALSE);
00392 hItem = m_wndFiles.GetNextItem (hItem, TVGN_NEXT);
00393 }
00394 }
00395
00396 void CCreateDownloadsDlg::OnContextMenu(CWnd* , CPoint point)
00397 {
00398 PrepareCHMgr (point);
00399 _CHMgr.ShowMenu ();
00400 }
00401
00402 void CCreateDownloadsDlg::OnWhatisthis()
00403 {
00404 _CHMgr.OnWT ();
00405 }
00406
00407 void CCreateDownloadsDlg::ApplyLanguage()
00408 {
00409 fsDlgLngInfo lnginfo [] = {
00410 fsDlgLngInfo (IDC__SAVETO, L_SAVETO),
00411 fsDlgLngInfo (IDC__START, L_START),
00412 fsDlgLngInfo (IDC_STARTNOW, L_AUTOMATICALLY),
00413 fsDlgLngInfo (IDC_STARTMANUAL, L_MANUALLY),
00414 fsDlgLngInfo (IDC_STARTSCHEDULE, L_SCHEDULE),
00415 fsDlgLngInfo (IDC__GROUP, L_GROUP),
00416 fsDlgLngInfo (IDC_ADVANCED, L_ADVANCED),
00417 fsDlgLngInfo (IDCANCEL, L_CANCEL),
00418 fsDlgLngInfo (IDC__LIST, L_LISTOFDLDS),
00419 fsDlgLngInfo (IDC_SELECTFOLDER, L_SELECTCONTENT),
00420 fsDlgLngInfo (IDC_UNSELECTFOLDER, L_UNSELECTCONTENT),
00421 };
00422
00423 _LngMgr.ApplyLanguage (this, lnginfo, sizeof (lnginfo) / sizeof (fsDlgLngInfo), L_CREATEDLDS);
00424 }
00425
00426 void CCreateDownloadsDlg::ReadAutostart()
00427 {
00428 m_iAutostart = _App.Last_Autostart ();
00429
00430 switch (m_iAutostart)
00431 {
00432 case 0:
00433 CheckRadioButton (IDC_STARTNOW, IDC_STARTSCHEDULE, IDC_STARTNOW);
00434 break;
00435
00436 case 1:
00437 CheckRadioButton (IDC_STARTNOW, IDC_STARTSCHEDULE, IDC_STARTMANUAL);
00438 break;
00439
00440 case 2:
00441 CheckRadioButton (IDC_STARTNOW, IDC_STARTSCHEDULE, IDC_STARTSCHEDULE);
00442 break;
00443 }
00444 }
00445
00446 BOOL CCreateDownloadsDlg::OnHelpInfo(HELPINFO* pHelpInfo)
00447 {
00448 RECT rc;
00449 CWnd *pItem = GetDlgItem (pHelpInfo->iCtrlId);
00450 if (pItem == NULL)
00451 return TRUE;
00452 pItem->GetWindowRect (&rc);
00453 if (PtInRect (&rc, pHelpInfo->MousePos) == FALSE)
00454 {
00455 pHelpInfo->MousePos.x = rc.left + (rc.right - rc.left) / 2;
00456 pHelpInfo->MousePos.y = rc.top + (rc.bottom - rc.top) / 2;
00457 }
00458 PrepareCHMgr (pHelpInfo->MousePos);
00459 _CHMgr.OnWT ();
00460 return TRUE;
00461 }
00462
00463 void CCreateDownloadsDlg::PrepareCHMgr(CPoint point)
00464 {
00465 fsCtrlContextHelp aCH1 [] = {
00466 fsCtrlContextHelp (IDC__GROUP, LS (L_GROUPHERE)),
00467 fsCtrlContextHelp (IDC_GROUPS, LS (L_GROUPHERE)),
00468 fsCtrlContextHelp (IDC_CREATEGROUP, LS (L_CREATEGRP)),
00469 fsCtrlContextHelp (IDC__SAVETO, LS (L_DLDFOLDERHERE)),
00470 fsCtrlContextHelp (IDC_CHOOSEFOLDER, LS (L_BROWSEFOR)),
00471 fsCtrlContextHelp (IDC_STARTNOW, LS (L_STARTNOWHERE)),
00472 fsCtrlContextHelp (IDC_STARTMANUAL, LS (L_MANUALLYSTARTHERE)),
00473 fsCtrlContextHelp (IDC_STARTSCHEDULE, LS (L_SCHEDULESTARTHERE)),
00474 fsCtrlContextHelp (IDC_SETTIME, LS (L_SETTIMEHERE)),
00475 fsCtrlContextHelp (IDC_ADVANCED, LS (L_ADVANCEDHERE)),
00476 fsCtrlContextHelp (IDOK, LS (L_ACCEPTCHANGES)),
00477 fsCtrlContextHelp (IDCANCEL, LS (L_DONTACCEPTCHANGES)),
00478 fsCtrlContextHelp (IDC__LIST, LS (L_LISTOFDLDSHERE)),
00479 fsCtrlContextHelp (IDC_FILES, LS (L_LISTOFDLDSHERE)),
00480 fsCtrlContextHelp (IDC_SELECTFOLDER, LS (L_SELFOLDERHERE)),
00481 fsCtrlContextHelp (IDC_UNSELECTFOLDER, LS (L_UNSELFOLDERHERE)),
00482 };
00483
00484 static fsCtrlContextHelp aCH [sizeof (aCH1) / sizeof (fsCtrlContextHelp)];
00485 CopyMemory (aCH, aCH1, sizeof (aCH));
00486
00487 _CHMgr.PrepareContextMenu (this, point, aCH, sizeof (aCH) / sizeof (fsCtrlContextHelp));
00488 }
00489
00490 void CCreateDownloadsDlg::OnOutfolderSetdefault()
00491 {
00492 CString strOutFolder;
00493 GetDlgItemText (IDC_OUTFOLDER, strOutFolder);
00494
00495 CCreateDownloadDlg::_SetDownloadOutputFolderAsDefault (this, strOutFolder,
00496 m_wndGroups.GetSelectedGroup ());
00497 }