int DownloadAddByUrl(DownloadEnum::Category cat, const char* filename, const char* url) { IDownload* dl = new IDownload(filename, url, cat); dl->addMirror(url); searchres.push_back(dl); return searchres.size(); }
bool CRapidDownloader::search(std::list<IDownload*>& result, const std::string& name, DownloadEnum::Category cat) { LOG_DEBUG("%s", name.c_str()); updateRepos(name); sdps.sort(list_compare); for (CSdp& sdp : sdps) { if (match_download_name(sdp.getShortName(), name) || (match_download_name(sdp.getName(), name))) { IDownload* dl = new IDownload(sdp.getName().c_str(), name, cat, IDownload::TYP_RAPID); dl->addMirror(sdp.getShortName().c_str()); result.push_back(dl); } } return true; }
bool CRepo::getDownload(IDownload& dl) { std::string tmp; urlToPath(repourl,tmp); LOG_DEBUG("%s",tmp.c_str()); this->tmpFile = fileSystem->getSpringDir() + PATH_DELIMITER + "rapid" + PATH_DELIMITER +tmp + PATH_DELIMITER +"versions.gz"; fileSystem->createSubdirs(tmpFile); //first try already downloaded file, as repo master file rarely changes if ((fileSystem->fileExists(tmpFile)) && fileSystem->isOlder(tmpFile,REPO_RECHECK_TIME)) return false; fileSystem->createSubdirs(tmpFile); dl = IDownload(tmpFile); dl.addMirror(repourl + "/versions.gz"); return true; }
void* CDTManager::NewTask(CAtlArray<CString>* urls,CString md5,CString localfile) { IDownload* down; CreateDownloadObject(__uuidof(IDownload),(void**)&down); _tks[down]=urls; size_t ppp=0; CString url; int64 len; int cu=0; if(GetContiInfo(localfile+L"c",url,len,cu)) { for (;ppp<urls->GetCount()&&url!=(*urls)[ppp];ppp++) { }; if(ppp==urls->GetCount()) { ppp=0; DeleteFile(localfile+DOWNLOAD_TEMP_FILE_SUFFIX); DeleteFile(localfile+DOWNLOAD_TEMP_FILE_INFO_SUFFIX); DeleteFile(localfile+L"c"); } } down->SetDownloadInfo((*urls)[ppp],localfile); LastDownInfo* lst=new LastDownInfo; lst->pos=ppp; lst->cur=cu; lst->urls=urls; lst->tk=down; _md5s[down]=md5; down->SetUserData((void*)lst); down->SetObserver(this); down->Start(cu); return down; }
DWORD CImplRepairVul::_ThreadFuncDownloadImpl() { do { m_thinfo.Reset(); INT nTotalFixItem = m_arrDownloadItem.GetSize(); if(nTotalFixItem==0) break; m_thinfo.totalNum = nTotalFixItem; // BOOL bImportLocal = m_dwRepairFlags&VULFLAG_REPAIR_IMPORT_LOCAL; BOOL bDownloadIfFailImport = m_dwRepairFlags&VULFLAG_REPAIR_DOWNLOAD_IF_FAIL_IMPORT; bImportLocal = bImportLocal && !m_strImportPath.IsEmpty(); // 1. Download CFileDownloader fdSingle; m_thinfo.m_pFileDownloaderSingle = &fdSingle; fdSingle.SetObserver( this ); IDownload *fd = NULL; ATLVERIFY( SUCCEEDED(CreateDownloadObject(__uuidof(IDownload), (VOID**)&fd)) ); m_thinfo.m_pFileDownloader = fd; fd->SetObserver( this ); m_thinfo.m_fileDownloadLocal.SetObserver(this); for(int i=0; i<m_arrDownloadItem.GetSize() && !m_bCanceled; ++i) { T_RepairItem &item = m_arrDownloadItem[i]; BOOL bNeedCheckCert = item.bCheckCert; DWORD dwDownfileStat = 0; Notify(EVulfix_DownloadBegin, item.nID, i, m_thinfo.totalNum); BOOL downSuccess = FALSE; if(item.type==VTYPE_SOFTLEAK && item.bDisableCOM) { downSuccess = TRUE; } else { downSuccess = FALSE; item.strFilename = m_strDownloadPath; CString strFilename; if(GetFileNameFromUrl(item.strURL, strFilename)) { // 兼容正常文件名 item.strFilename.Format(_T("%s\\%s"), m_strDownloadPath, strFilename); if(!IsFileExist(item.strFilename)) { item.strFilename.Format(_T("%s\\%s%s"), m_strDownloadPath, BK_FILE_PREFIX, strFilename); if(!IsFileExist(item.strFilename)) { item.strFilename.Format(_T("%s\\%s"), m_strDownloadPath, strFilename); // download if file not exists dwDownfileStat |= ERDOWN_LOCAL_NOT_EXISTS; BOOL toDownloadFromWeb = TRUE; if(bImportLocal) { m_thinfo.m_fileDownloadLocal.SetUserData((LPVOID)item.nID); CString strImportFilename; LPCTSTR lpszHttp = _T("http://"); if( _tcsnicmp(lpszHttp, m_strImportPath, _tcslen(lpszHttp))==0 ) { // 支持本地http 导入 strImportFilename.Format(_T("%s/%s"), m_strImportPath, strFilename); fd->SetUserData((LPVOID)item.nID); fd->SetDownloadInfo(strImportFilename, item.strFilename); fd->Fetch(); } else { // 本地路径导入 strImportFilename.Format(_T("%s\\%s"), m_strImportPath, strFilename); m_thinfo.m_fileDownloadLocal.SetDownloadInfo(strImportFilename, item.strFilename); if( !m_thinfo.m_fileDownloadLocal.Fetch() ) { if(!m_bCanceled) { strImportFilename.Format(_T("%s\\%s%s"), m_strImportPath, BK_FILE_PREFIX, strFilename); m_thinfo.m_fileDownloadLocal.SetDownloadInfo(strImportFilename, item.strFilename); m_thinfo.m_fileDownloadLocal.Fetch(); } } } if(PathFileExists(item.strFilename)) { toDownloadFromWeb = FALSE; dwDownfileStat |= ERDOWN_IMPORT_LOCAL; } else { toDownloadFromWeb = bDownloadIfFailImport; } } if(toDownloadFromWeb && !m_bCanceled && !IsFileExist(item.strFilename) ) { m_bDownloadHasReceivedData = FALSE; for (int i = 0; i < 3 && !downSuccess && !m_bCanceled; i ++) { // Download Fail, Wait for 3 seconds then to retry if(i>0) { DWORD dwTimeWaitEnd = 3*1000 + GetTickCount(); for(;!m_bCanceled && GetTickCount()<dwTimeWaitEnd;) { ::Sleep(100); } if(m_bCanceled) break; } fd->SetUserData((LPVOID)item.nID); fd->SetDownloadInfo(item.strURL, item.strFilename); downSuccess = fd->Fetch(); IDownStat *pdownstat = fd->GetDownloadStat(); if(pdownstat && pdownstat->Downloaded()>0) m_bDownloadHasReceivedData = TRUE; if (downSuccess && bNeedCheckCert) { // 校验补丁包数字签名 HRESULT hVerifyRet = _VerifyWinTrustCert(item.strFilename); if(!IsValidPatchFile(item.strFilename) || FAILED(hVerifyRet)) { dwDownfileStat |= ERDOWN_MULTIDOWN_ERRORSIGN; Notify(EVulfix_Download_Check_Error, item.nID, hVerifyRet, 0); #ifdef _DEBUG MessageBox(NULL, _T("下载文件签名验证失败!!!"), NULL, MB_OK); #else DeleteFile(item.strFilename); m_bDownloadHasReceivedData = TRUE; // 校验失败走单线程 downSuccess = fdSingle.Download(item.strURL, item.strFilename , NULL, (LPVOID)(INT_PTR)item.nID); #endif bNeedCheckCert = FALSE; break; } bNeedCheckCert = FALSE; } } if(!m_bDownloadHasReceivedData) dwDownfileStat |= ERDOWN_CANNOT_REACH_OFFICIAL; // 如果未收到任何数据 if (!downSuccess && !m_bCanceled && !m_bDownloadHasReceivedData && !item.strMirrorURL.IsEmpty()) { dwDownfileStat |= ERDOWN_MIRROR_USED; // 删除之前下载的所有文件?! , 因为如果一点数据都没有下载到的话, 就没必要删除临时文件了 fd->SetUserData((LPVOID)item.nID); fd->SetDownloadInfo(item.strMirrorURL, item.strFilename); fd->Fetch(1); } } } } downSuccess = IsFileExist(item.strFilename); if(downSuccess) { if (bNeedCheckCert) { // 校验补丁包数字签名 HRESULT hVerifyRet = _VerifyWinTrustCert(item.strFilename); if(FAILED(hVerifyRet)) { Notify(EVulfix_Download_Check_Error, item.nID, hVerifyRet, 1); DeleteFile(item.strFilename); downSuccess = FALSE; dwDownfileStat |= ERDOWN_ERRORSIGN; } } if(!IsValidPatchFile(item.strFilename)) { DeleteFile(item.strFilename); downSuccess = FALSE; } } } } item.stateDownload = downSuccess; Notify(downSuccess ? EVulfix_DownloadEnd : EVulfix_DownloadError, item.nID, m_bCanceled, dwDownfileStat); if( downSuccess ) { ++m_thinfo.nDownSuccess; SetEvent(m_thinfo.m_hInstallEvent); } } { CObjGuard __guard__(m_thinfo.m_objLockFileDownloader, TRUE); m_thinfo.m_pFileDownloaderSingle = NULL; m_thinfo.m_pFileDownloader = NULL; m_thinfo.m_pFileDownloaderSingle = NULL; m_thinfo.m_fileDownloadLocal.SetObserver(NULL); } fd->SetObserver( NULL ); fd->Release(); fd = NULL; } while (FALSE); m_thinfo.isDownloadDone = TRUE; SetEvent(m_thinfo.m_hInstallEvent); return 0; }
bool CPlasmaDownloader::search(std::list<IDownload*>& result, const std::string& name, IDownload::category category) { LOG_DEBUG("%s",name.c_str()); ContentServiceSoap12Proxy service; _Plasma__DownloadFile file; _Plasma__DownloadFileResponse fileResponse; std::string tmpname=name; file.internalName=&tmpname; int res; res=service.DownloadFile(&file, &fileResponse); if (res != SOAP_OK) { LOG_ERROR("Soap error: %d: %s",res, service.soap_fault_string()); return false; } if (!fileResponse.DownloadFileResult) { LOG_DEBUG("No file found for criteria %s",name.c_str()); return false; } std::vector<std::string>::iterator it; IDownload::category cat=category; std::string fileName=fileSystem->getSpringDir() + PATH_DELIMITER; switch (fileResponse.resourceType) { case Plasma__ResourceType__Map: cat=IDownload::CAT_MAPS; fileName.append("maps"); break; case Plasma__ResourceType__Mod: cat=IDownload::CAT_GAMES; fileName.append("games"); break; default: LOG_DEBUG("Unknown category in result: %d", cat); cat=IDownload::CAT_NONE; break; } fileName+=PATH_DELIMITER; if (fileResponse.links->string.size()==0) { LOG_DEBUG("No mirror in plasma result."); return false; } std::string torrent; torrent.assign((char*)fileResponse.torrent->__ptr,fileResponse.torrent->__size); IDownload* dl = new IDownload("",name); //parse torrent data and fill set values inside dl const bool bres = fileSystem->parseTorrent((char*)fileResponse.torrent->__ptr, fileResponse.torrent->__size, dl); if ( (dl->name == "") || (!bres)) { LOG_ERROR("Couldn't parse torrent filename"); return false; } //set full path name fileName.append(dl->name); dl->name=fileName; dl->cat=cat; LOG_DEBUG("Got filename \"%s\" from torrent",fileName.c_str()); for (it=fileResponse.links->string.begin(); it!=fileResponse.links->string.end(); ++it) { dl->addMirror((*it).c_str()); } for (it=fileResponse.dependencies->string.begin(); it!=fileResponse.dependencies->string.end(); ++it) { dl->addDepend((*it).c_str()); } result.push_back(dl); return true; }