00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "DlgExportDownloads.h"
00009 #include "DownloadsWnd.h"
00010
00011 extern CDownloadsWnd* _pwndDownloads;
00012
00013 #ifdef _DEBUG
00014 #define new DEBUG_NEW
00015 #undef THIS_FILE
00016 static char THIS_FILE[] = __FILE__;
00017 #endif
00018
00019 CDlgExportDownloads::CDlgExportDownloads(CWnd* pParent )
00020 : CDialog(CDlgExportDownloads::IDD, pParent)
00021 {
00022
00023
00024
00025 }
00026
00027 void CDlgExportDownloads::DoDataExchange(CDataExchange* pDX)
00028 {
00029 CDialog::DoDataExchange(pDX);
00030
00031
00032
00033 }
00034
00035 BEGIN_MESSAGE_MAP(CDlgExportDownloads, CDialog)
00036
00037
00038 END_MESSAGE_MAP()
00039
00040 BOOL CDlgExportDownloads::OnInitDialog()
00041 {
00042 CDialog::OnInitDialog();
00043
00044 CheckRadioButton (IDC_ALL, IDC_SELECTED, IDC_ALL + _App.Export_WhichDlds ());
00045 CheckDlgButton (IDC_NOCOMPLETED, _App.Export_DontExpCompleted () ? BST_CHECKED : BST_UNCHECKED);
00046 CheckDlgButton (IDC_APPEND, _App.Export_Append () ? BST_CHECKED : BST_UNCHECKED);
00047
00048 ApplyLanguage ();
00049
00050 return TRUE;
00051 }
00052
00053 void CDlgExportDownloads::ApplyLanguage()
00054 {
00055 fsDlgLngInfo lnginfo [] = {
00056 fsDlgLngInfo (IDC_ALL, L_EXPALLDLDS),
00057 fsDlgLngInfo (IDC_ALLINLIST, L_EXPDLDSINLIST),
00058 fsDlgLngInfo (IDC_SELECTED, L_EXPSELDLDS),
00059 fsDlgLngInfo (IDC_NOCOMPLETED, L_DONTEXPCOMPLDLDS),
00060 fsDlgLngInfo (IDC_APPEND, L_APPENDIFFILEEXISTS),
00061 fsDlgLngInfo (IDC__EXPORTOPTS, L_EXPORTOPTIONS),
00062 fsDlgLngInfo (IDCANCEL, L_CANCEL),
00063 };
00064
00065 CString str = _LngMgr.GetStringNP (L_EXPORT);
00066 str += "...";
00067 SetDlgItemText (IDC__EXPORT, str);
00068
00069 _LngMgr.ApplyLanguage (this, lnginfo, sizeof (lnginfo) / sizeof (fsDlgLngInfo), L_EXPORTLISTOFDLDS);
00070 }
00071
00072 void CDlgExportDownloads::OnOK()
00073 {
00074 int iWhich = 0;
00075 if (IsDlgButtonChecked (IDC_ALLINLIST) == BST_CHECKED)
00076 iWhich = 1;
00077 else if (IsDlgButtonChecked (IDC_SELECTED) == BST_CHECKED)
00078 iWhich = 2;
00079
00080 BOOL bNoDone = IsDlgButtonChecked (IDC_NOCOMPLETED) == BST_CHECKED;
00081 BOOL bAppend = IsDlgButtonChecked (IDC_APPEND) == BST_CHECKED;
00082
00083 _App.Export_WhichDlds (iWhich);
00084 _App.Export_DontExpCompleted (bNoDone);
00085 _App.Export_Append (bAppend);
00086
00087 ExportDownloads (iWhich, bNoDone, bAppend);
00088
00089 CDialog::OnOK();
00090 }
00091
00092 void CDlgExportDownloads::ExportDownloads(int iWhich, BOOL bNoDone, BOOL bAppend)
00093 {
00094 DLDS_LIST vpDlds;
00095
00096 switch (iWhich)
00097 {
00098 case 0:
00099 {
00100 for (size_t i = 0; i < _DldsMgr.GetCount (); i++)
00101 {
00102 vmsDownloadSmartPtr dld;
00103
00104 try {
00105 dld = _DldsMgr.GetDownload (i);
00106
00107 if (bNoDone && dld->pMgr->IsDone ())
00108 dld = NULL;
00109 }
00110 catch (...) {dld = NULL;}
00111
00112 if (dld)
00113 vpDlds.push_back (dld);
00114 }
00115 }
00116 break;
00117
00118 case 1:
00119 {
00120 CDownloads_Tasks* list = &_pwndDownloads->m_wndDownloads.m_tasks;
00121 int cItems = list->GetItemCount ();
00122 for (int i = 0; i < cItems; i++)
00123 {
00124 vmsDownloadSmartPtr dld;
00125
00126 try {
00127 dld = (fsDownload*) list->GetItemData (i);
00128
00129 if (bNoDone && dld->pMgr->IsDone ())
00130 dld = NULL;
00131 }
00132 catch (...) {dld = NULL;}
00133
00134 if (dld)
00135 vpDlds.push_back (dld);
00136 }
00137 }
00138 break;
00139
00140 case 2:
00141 {
00142 CDownloads_Tasks* list = &_pwndDownloads->m_wndDownloads.m_tasks;
00143 POSITION pos = list->GetFirstSelectedItemPosition ();
00144 while (pos)
00145 {
00146 int iItem = list->GetNextSelectedItem (pos);
00147 vmsDownloadSmartPtr dld;
00148
00149 try {
00150 dld = (fsDownload*) list->GetItemData (iItem);
00151
00152 if (bNoDone && dld->pMgr->IsDone ())
00153 dld = NULL;
00154 }
00155 catch (...) {dld = NULL;}
00156
00157 if (dld)
00158 vpDlds.push_back (dld);
00159 }
00160 }
00161 break;
00162 }
00163
00164 if (vpDlds.size ())
00165 {
00166 CString strFilter;
00167 strFilter.Format ("%s (*.txt)|*.txt|%s (*.xml)|*.xml||", LS (L_URLLISTFILES), LS (L_DLINFOLISTFILES));
00168 UINT flags = OFN_NOCHANGEDIR;
00169 if (bAppend == FALSE)
00170 flags |= OFN_OVERWRITEPROMPT;
00171 CFileDialog dlg (FALSE, "txt", NULL, flags, strFilter, NULL);
00172
00173 if (_DlgMgr.DoModal (&dlg) == IDCANCEL)
00174 return;
00175
00176
00177
00178 if (dlg.GetFileExt ().CollateNoCase ("txt") == 0)
00179 ExportDownloads_ToURLListFile (dlg.GetPathName (), &vpDlds, bAppend);
00180 else
00181 ExportDownloads_ToDLInfoListFile (dlg.GetPathName (), &vpDlds, bAppend);
00182 }
00183 }
00184
00185 BOOL CDlgExportDownloads::ExportDownloads_ToURLListFile(LPCSTR pszFile, DLDS_LIST* pvpDlds, BOOL bAppend)
00186 {
00187 CStdioFile file;
00188
00189 UINT mode = CFile::modeWrite;
00190
00191 if (bAppend == FALSE || GetFileAttributes (pszFile) == DWORD (-1))
00192 mode |= CFile::modeCreate;
00193
00194 if (FALSE == file.Open (pszFile, mode))
00195 {
00196 ::MessageBox (NULL, LS (L_CANTOPENFILE), LS (L_ERR), MB_ICONERROR);
00197 return FALSE;
00198 }
00199
00200 if ((mode & CFile::modeCreate) == 0)
00201 file.SeekToEnd ();
00202
00203 for (size_t i = 0; i < pvpDlds->size (); i++)
00204 {
00205 try {
00206 file.WriteString (pvpDlds->at (i)->pMgr->get_URL ());
00207 file.WriteString ("\n");
00208 }
00209 catch (...)
00210 {
00211 return FALSE;
00212 }
00213 }
00214
00215 return TRUE;
00216 }
00217
00218 BOOL CDlgExportDownloads::ExportDownloads_ToDLInfoListFile(LPCSTR pszFile, DLDS_LIST* pvpDlds, BOOL bAppend)
00219 {
00220 IXMLDOMDocumentPtr spXML;
00221 IXMLDOMNodePtr spNode, spNode2;
00222
00223 spXML.CreateInstance (__uuidof (DOMDocument));
00224
00225 if (spXML == NULL)
00226 return FALSE;
00227
00228 spXML->put_async (FALSE);
00229
00230 VARIANT_BOOL bRes = FALSE;
00231 if (bAppend)
00232 {
00233 spXML->load (COleVariant (pszFile), &bRes);
00234 if (bRes)
00235 {
00236 spXML->selectSingleNode (L"FDM_Downloads_Info_List", &spNode);
00237 if (spNode == NULL)
00238 bRes = FALSE;
00239 }
00240 }
00241
00242 if (bRes == FALSE)
00243 {
00244 spXML->createNode (COleVariant ((long)NODE_ELEMENT), L"FDM_Downloads_Info_List", NULL, &spNode);
00245 spXML->appendChild (spNode, &spNode2);
00246 }
00247
00248 for (size_t i = 0; i < pvpDlds->size (); i++)
00249 {
00250 ExportDownload_ToXML (spXML, spNode, pvpDlds->at (i));
00251 }
00252
00253 CComBSTR bstr;
00254 spXML->get_xml (&bstr);
00255
00256 CString str = bstr;
00257 str.Replace ("><", ">\n<");
00258
00259 bstr = str;
00260
00261 spXML->loadXML (bstr, &bRes);
00262
00263 spXML->save (COleVariant (pszFile));
00264
00265 return TRUE;
00266 }
00267
00268 BOOL CDlgExportDownloads::ExportDownload_ToXML(IXMLDOMDocument *pDoc, IXMLDOMNode *pRoot, vmsDownloadSmartPtr dld)
00269 {
00270
00271 static UINT _nLastGrpId = (UINT)-1;
00272 static fsString _strLastGrpFullName;
00273
00274 if (_nLastGrpId != dld->pGroup->nId)
00275 {
00276 _strLastGrpFullName = _DldsGrps.GetGroupFullName (dld->pGroup->nId);
00277 _nLastGrpId = dld->pGroup->nId;
00278 }
00279
00280
00281 IXMLDOMNodePtr spNode, spNodeDL, spNodeTmp;
00282
00283 pDoc->createNode (COleVariant ((long)NODE_ELEMENT), L"download", NULL, &spNode);
00284 pRoot->appendChild (spNode, &spNodeDL);
00285
00286 spNode = NULL;
00287 pDoc->createNode (COleVariant ((long)NODE_ELEMENT), L"url", NULL, &spNode);
00288 spNode->put_nodeTypedValue (COleVariant (dld->pMgr->get_URL ()));
00289 spNodeDL->appendChild (spNode, &spNodeTmp);
00290
00291 if (dld->strComment != "")
00292 {
00293 spNode = NULL; spNodeTmp = NULL;
00294 pDoc->createNode (COleVariant ((long)NODE_ELEMENT), L"comment", NULL, &spNode);
00295 spNode->put_nodeTypedValue (COleVariant (dld->strComment));
00296 spNodeDL->appendChild (spNode, &spNodeTmp);
00297 }
00298
00299 spNode = NULL; spNodeTmp = NULL;
00300 pDoc->createNode (COleVariant ((long)NODE_ELEMENT), L"group", NULL, &spNode);
00301 spNode->put_nodeTypedValue (COleVariant (_strLastGrpFullName));
00302 spNodeDL->appendChild (spNode, &spNodeTmp);
00303
00304 return TRUE;
00305 }