00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "WGUrlReceiver.h"
00009 #include "CreateDownloadDlg.h"
00010 #include "MainFrm.h"
00011 #include "UIThread.h"
00012 #include "inetutil.h"
00013
00014 #include "DownloadsWnd.h"
00015 #include "SpiderWnd.h"
00016 #include "SpiderAddPageDlg.h"
00017
00018 extern CDownloadsWnd* _pwndDownloads;
00019 extern CSpiderWnd* _pwndSpider;
00020
00021 STDMETHODIMP CWGUrlReceiver::get_Url(BSTR *pVal)
00022 {
00023 *pVal = m_dlInfo.bstrUrl;
00024 return S_OK;
00025 }
00026
00027 STDMETHODIMP CWGUrlReceiver::put_Url(BSTR newVal)
00028 {
00029 LOG ("monitor: put_Url" << nl);
00030 m_dlInfo.bstrUrl = newVal;
00031 return S_OK;
00032 }
00033
00034 STDMETHODIMP CWGUrlReceiver::ShowAddDownloadDialog()
00035 {
00036 return AddDownload ();
00037 }
00038
00039 STDMETHODIMP CWGUrlReceiver::AddDownload()
00040 {
00041 LOG ("monitor: Adddownload" << nl);
00042
00043
00044 if (m_bCheckExt && is_ExtToSkip ())
00045 return E_NOTIMPL;
00046
00047 if (m_bIgnoreSize == FALSE)
00048 {
00049 UINT iSize = _App.Monitor_SkipSmaller ();
00050 if (iSize)
00051 {
00052 USES_CONVERSION;
00053 fsDownloadMgr mgr (NULL);
00054 mgr.CreateByUrl (W2A (m_dlInfo.bstrUrl), TRUE);
00055 mgr.QuerySize ();
00056 UINT64 uSize = mgr.GetDownloader ()->GetSSFileSize ();
00057 if (iSize >= uSize)
00058 return E_NOTIMPL;
00059 }
00060 }
00061
00062 StartJobThread (_threadAddDownload);
00063 return S_OK;
00064 }
00065
00066 STDMETHODIMP CWGUrlReceiver::ShowAddPageDownloadDialog()
00067 {
00068 StartJobThread (_threadAddPage);
00069 return S_OK;
00070 }
00071
00072 DWORD WINAPI CWGUrlReceiver::_threadAddDownload(LPVOID lp)
00073 {
00074 _ic_DownloadInfo* dlinfo = (_ic_DownloadInfo*) lp;
00075 DWORD dw = (DWORD)AddDownload_imp (dlinfo);
00076 delete dlinfo;
00077 return dw;
00078 }
00079
00080 DWORD WINAPI CWGUrlReceiver::_threadAddPage(LPVOID lp)
00081 {
00082 _ic_DownloadInfo* dlinfo = (_ic_DownloadInfo*) lp;
00083
00084 while (((CFdmApp*)AfxGetApp ())->Is_Starting ())
00085 Sleep (100);
00086
00087 USES_CONVERSION;
00088 HRESULT hr = _pwndSpider->AddWebPage (W2A (dlinfo->bstrUrl), TRUE) ? S_OK : S_FALSE;
00089 delete dlinfo;
00090 return hr;
00091 }
00092
00093 HRESULT CWGUrlReceiver::AddDownload_imp(_ic_DownloadInfo* dlinfo)
00094 {
00095 USES_CONVERSION;
00096
00097 LOG ("monitor: adddownload_imp" << nl);
00098 LOG ("monitor: waiting for frame initializated" << nl);
00099
00100 while (((CFdmApp*)AfxGetApp ())->Is_Starting ())
00101 Sleep (100);
00102
00103 LOG ("monitor: initialized ok." << nl);
00104 LOG ("monitor: checking silent flag" << nl);
00105
00106 UINT res;
00107 BOOL bSilent = dlinfo->bForceSilent ? TRUE : _App.Monitor_Silent ();
00108
00109 LOG ("monitor: calling createdownload" << nl);
00110
00111 vmsDWCD_AdditionalParameters ap;
00112 ap.dwMask = 0;
00113 if (dlinfo->bstrCookies.Length () != 0)
00114 {
00115 ap.dwMask |= DWCDAP_COOKIES;
00116 ap.strCookies = dlinfo->bstrCookies;
00117 }
00118 if (dlinfo->bstrPostData.Length () != 0)
00119 {
00120 ap.dwMask |= DWCDAP_POSTDATA;
00121 ap.strPostData = dlinfo->bstrPostData;
00122 }
00123
00124 if (dlinfo->bstrFileName.Length () != 0)
00125 {
00126 ap.dwMask |= DWCDAP_FILENAME;
00127 ap.strFileName = dlinfo->bstrFileName;
00128 }
00129
00130 ap.dwMask |= DWCDAP_FLAGS;
00131
00132 if (bSilent == FALSE)
00133 ap.dwFlags = DWDCDAP_F_SETFOCUSTOOKBTN;
00134 else
00135 ap.dwFlags = dlinfo->bForceSilent && dlinfo->bNoUIInForceSilentMode ? DWDCDAP_F_NO_UI : 0;
00136
00137 if (dlinfo->bForceAutoStart)
00138 ap.dwFlags |= DWDCDAP_F_FORCEAUTOSTART;
00139
00140 if (dlinfo->bDisableMaliciousChecking)
00141 ap.dwFlags |= DWDCDAP_F_DISABLEMALICIOUSCHECK;
00142
00143 if (dlinfo->bDisableURLExistsChecking)
00144 ap.dwFlags |= DWDCDAP_F_DONTCHECKURLALREADYEXISTS;
00145
00146 if (dlinfo->bFlashVideoDownload)
00147 {
00148 ap.dwFlags |= DWDCDAP_F_FLASHVIDEODOWNLOAD;
00149
00150 }
00151
00152 BOOL bAdded = _pwndDownloads->CreateDownload (W2A (dlinfo->bstrUrl), TRUE,
00153 W2A (dlinfo->bstrComment), W2A (dlinfo->bstrReferer), bSilent,
00154 DWCD_NOFORCEAUTOLAUNCH, NULL, &ap, &res);
00155
00156 LOG ("monitor: create download called ok" << nl);
00157
00158 if (bAdded && bSilent)
00159 CMainFrame::ShowTimeoutBalloon (W2A (dlinfo->bstrUrl), "Download added", NIIF_INFO, TRUE);
00160
00161 LOG ("monitor: do exit from _imp" << nl);
00162
00163
00164 if (res == ID_DLNOTADDED)
00165 bAdded = TRUE;
00166
00167 return bAdded ? S_OK : S_FALSE;
00168 }
00169
00170 STDMETHODIMP CWGUrlReceiver::get_Comment(BSTR *pVal)
00171 {
00172 *pVal = SysAllocString (m_dlInfo.bstrComment);
00173 return S_OK;
00174 }
00175
00176 STDMETHODIMP CWGUrlReceiver::put_Comment(BSTR newVal)
00177 {
00178 m_dlInfo.bstrComment = newVal;
00179 return S_OK;
00180 }
00181
00182 STDMETHODIMP CWGUrlReceiver::get_Referer(BSTR *pVal)
00183 {
00184 *pVal = SysAllocString (m_dlInfo.bstrReferer);
00185 return S_OK;
00186 }
00187
00188 STDMETHODIMP CWGUrlReceiver::put_Referer(BSTR newVal)
00189 {
00190 m_dlInfo.bstrReferer = newVal;
00191 return S_OK;
00192 }
00193
00194 STDMETHODIMP CWGUrlReceiver::get_CheckExtension(BOOL *pVal)
00195 {
00196 *pVal = m_bCheckExt;
00197 return S_OK;
00198 }
00199
00200 STDMETHODIMP CWGUrlReceiver::put_CheckExtension(BOOL newVal)
00201 {
00202 m_bCheckExt = newVal;
00203 return S_OK;
00204 }
00205
00206 BOOL CWGUrlReceiver::is_ExtToSkip()
00207 {
00208 USES_CONVERSION;
00209 fsURL url;
00210
00211 if (url.Crack (W2A (m_dlInfo.bstrUrl)) != IR_SUCCESS)
00212 return TRUE;
00213
00214 char szFile [MY_MAX_PATH];
00215 fsFileNameFromUrlPath (url.GetPath (), url.GetInternetScheme () == INTERNET_SCHEME_FTP,
00216 TRUE, szFile, sizeof (szFile));
00217
00218 if (*szFile == 0)
00219 return FALSE;
00220
00221 LPCSTR pszExt = strrchr (szFile, '.');
00222 if (pszExt == NULL)
00223 return FALSE;
00224
00225 return IsExtInExtsStr (_App.Monitor_SkipExts (), ++pszExt);
00226 }
00227
00228 STDMETHODIMP CWGUrlReceiver::get_IgnoreSize(BOOL *pVal)
00229 {
00230 *pVal = m_bIgnoreSize;
00231 return S_OK;
00232 }
00233
00234 STDMETHODIMP CWGUrlReceiver::put_IgnoreSize(BOOL newVal)
00235 {
00236 m_bIgnoreSize = newVal;
00237 return S_OK;
00238 }
00239
00240 void CWGUrlReceiver::FinalRelease()
00241 {
00242 if (m_hJobt)
00243 CloseHandle (m_hJobt);
00244 }
00245
00246 STDMETHODIMP CWGUrlReceiver::get_UIState(BSTR *pVal)
00247 {
00248 if (m_hJobt == NULL)
00249 {
00250 *pVal = NULL;
00251 return E_FAIL;
00252 }
00253
00254 DWORD dw;
00255 if (0 == GetExitCodeThread (m_hJobt, &dw))
00256 {
00257 *pVal = NULL;
00258 return E_FAIL;
00259 }
00260
00261 if (dw == STILL_ACTIVE)
00262 {
00263 *pVal = SysAllocString (L"in_progress");
00264 }
00265 else
00266 {
00267 if (dw != S_OK)
00268 *pVal = SysAllocString (L"cancelled");
00269 else
00270 *pVal = SysAllocString (L"added");
00271 }
00272
00273 return S_OK;
00274 }
00275
00276 void CWGUrlReceiver::StartJobThread(LPTHREAD_START_ROUTINE pfn)
00277 {
00278 UIThread *thr = (UIThread*) RUNTIME_CLASS (UIThread)->CreateObject ();
00279 _ic_DownloadInfo* dlinfo = new _ic_DownloadInfo;
00280 *dlinfo = m_dlInfo;
00281 thr->set_Thread (pfn, dlinfo);
00282 thr->CreateThread ();
00283
00284 if (m_hJobt)
00285 CloseHandle (m_hJobt);
00286
00287 DuplicateHandle (GetCurrentProcess (), thr->m_hThread, GetCurrentProcess (),
00288 &m_hJobt, 0, TRUE, DUPLICATE_SAME_ACCESS);
00289 }
00290
00291 STDMETHODIMP CWGUrlReceiver::get_ForceSilent(BOOL *pVal)
00292 {
00293 *pVal = m_dlInfo.bForceSilent;
00294 return S_OK;
00295 }
00296
00297 STDMETHODIMP CWGUrlReceiver::put_ForceSilent(BOOL newVal)
00298 {
00299 m_dlInfo.bForceSilent = newVal;
00300 m_dlInfo.bNoUIInForceSilentMode = FALSE;
00301 return S_OK;
00302 }
00303
00304 STDMETHODIMP CWGUrlReceiver::get_Cookies(BSTR *pVal)
00305 {
00306 *pVal = SysAllocString (m_dlInfo.bstrCookies);
00307 return S_OK;
00308 }
00309
00310 STDMETHODIMP CWGUrlReceiver::put_Cookies(BSTR newVal)
00311 {
00312 m_dlInfo.bstrCookies = newVal;
00313 return S_OK;
00314 }
00315
00316 STDMETHODIMP CWGUrlReceiver::get_PostData(BSTR *pVal)
00317 {
00318 *pVal = SysAllocString (m_dlInfo.bstrPostData);
00319 return S_OK;
00320 }
00321
00322 STDMETHODIMP CWGUrlReceiver::put_PostData(BSTR newVal)
00323 {
00324 m_dlInfo.bstrPostData = newVal;
00325 return S_OK;
00326 }
00327
00328 STDMETHODIMP CWGUrlReceiver::get_UseSkipExtsList(BOOL *pVal)
00329 {
00330 *pVal = TRUE;
00331 return S_OK;
00332 }
00333
00334 STDMETHODIMP CWGUrlReceiver::put_UseSkipExtsList(BOOL newVal)
00335 {
00336 return S_OK;
00337 }
00338
00339 STDMETHODIMP CWGUrlReceiver::get_ForceSilentEx(BOOL *pVal)
00340 {
00341 *pVal == m_dlInfo.bForceSilent && m_dlInfo.bNoUIInForceSilentMode;
00342 return S_OK;
00343 }
00344
00345 STDMETHODIMP CWGUrlReceiver::put_ForceSilentEx(BOOL newVal)
00346 {
00347 m_dlInfo.bForceSilent = newVal;
00348 m_dlInfo.bNoUIInForceSilentMode = newVal;
00349
00350 return S_OK;
00351 }
00352
00353 STDMETHODIMP CWGUrlReceiver::get_ForceDownloadAutoStart(BOOL *pVal)
00354 {
00355 *pVal = m_dlInfo.bForceAutoStart;
00356 return S_OK;
00357 }
00358
00359 STDMETHODIMP CWGUrlReceiver::put_ForceDownloadAutoStart(BOOL newVal)
00360 {
00361 m_dlInfo.bForceAutoStart = newVal;
00362 return S_OK;
00363 }
00364
00365 STDMETHODIMP CWGUrlReceiver::get_DisableMaliciousChecking(BOOL *pVal)
00366 {
00367 *pVal = m_dlInfo.bDisableMaliciousChecking;
00368 return S_OK;
00369 }
00370
00371 STDMETHODIMP CWGUrlReceiver::put_DisableMaliciousChecking(BOOL newVal)
00372 {
00373 m_dlInfo.bDisableMaliciousChecking = newVal;
00374 return S_OK;
00375 }
00376
00377 STDMETHODIMP CWGUrlReceiver::get_DisableURLExistsCheck(BOOL *pVal)
00378 {
00379 *pVal = m_dlInfo.bDisableURLExistsChecking;
00380 return S_OK;
00381 }
00382
00383 STDMETHODIMP CWGUrlReceiver::put_DisableURLExistsCheck(BOOL newVal)
00384 {
00385 m_dlInfo.bDisableURLExistsChecking = newVal;
00386 return S_OK;
00387 }
00388
00389 STDMETHODIMP CWGUrlReceiver::get_FileName(BSTR *pVal)
00390 {
00391 *pVal = SysAllocString (m_dlInfo.bstrFileName);
00392 return S_OK;
00393 }
00394
00395 STDMETHODIMP CWGUrlReceiver::put_FileName(BSTR newVal)
00396 {
00397 m_dlInfo.bstrFileName = newVal;
00398 return S_OK;
00399 }
00400
00401 STDMETHODIMP CWGUrlReceiver::get_FlashVideoDownload(BOOL *pVal)
00402 {
00403 *pVal = m_dlInfo.bFlashVideoDownload;
00404 return S_OK;
00405 }
00406
00407 STDMETHODIMP CWGUrlReceiver::put_FlashVideoDownload(BOOL newVal)
00408 {
00409 m_dlInfo.bFlashVideoDownload = newVal;
00410 return S_OK;
00411 }