bool Installer::Install(const QString& appName, const QString& appVersion, eAppType type) { Logger::GetInstance()->AddLog(tr("Installing %1").arg(appName)); const AppsConfig::AppMap* apps = GetAppMap(type); if (!apps) return false; AppsConfig::AppMap::const_iterator appIter = apps->find(appName); if (appIter == apps->end()) return false; AppsConfig::AppVersion::const_iterator iter = appIter.value().find(appVersion); if (iter == appIter->end()) return false; const AppConfig& config = iter.value(); m_pReply = m_pNetworkManager->get(QNetworkRequest(config.m_Url)); connect(m_pReply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(OnDownloadProgress(qint64, qint64))); connect(m_pReply, SIGNAL(finished()), this, SLOT(OnAppDownloaded())); m_pReply->setProperty(INSTALL_TYPE, type); m_pReply->setProperty(INSTALL_NAME, appName); m_pReply->setProperty(INSTALL_VERISON, appVersion); emit StartDownload(); return true; }
PushDownloadTask::TaskState PushDownloadTask::GetTaskState() { if (state_ == TS_DOWNLOADING) { boost::int32_t total_size, download_progress; p2sp::ProxyModule::Inst()->QueryDownloadProgress(task_param_.rid_info_.rid_, boost::function<void()>(), &total_size, &download_progress); OnDownloadProgress(total_size,download_progress); } return state_; }
bool CFTP::Download(LPCTSTR strVideoName, LPCTSTR strDirectoryName) { ASSERT(m_pFtpConnection); ASSERT(m_pFtpFileFind); CInternetFile* pFile = 0; CFileFind* pFinder = 0; char* pBuffer = 0; DWORD dwBytesRead = 0, dwBytesWritten, dwFileSize = 0; __int64 i64TotalBytes = 0; HANDLE hFile; CString sFile, sRemoteFile; CString sDirectory; bool bReturn = true; m_bAbort = false; sDirectory = strDirectoryName; if (sDirectory.GetAt(sDirectory.GetLength() - 1) == '\\') sDirectory = sDirectory.Left(sDirectory.GetLength() - 1); m_sVideoName = strVideoName; sFile.Format("%s\\%s.mpg",sDirectory,m_sVideoName); hFile = CreateFile(sFile,GENERIC_WRITE,0,0,CREATE_ALWAYS,0,0); if (INVALID_HANDLE_VALUE == hFile) return false; try { sRemoteFile.Format("/r1/%s.mpg",m_sVideoName); if (0 != (pFinder = GetFileInfo(sRemoteFile))) dwFileSize = pFinder->GetLength(); pFile = m_pFtpConnection->OpenFile(sRemoteFile); if (pFile) { //dwFileSize = pFile->GetLength(); pBuffer = new char[dwUPLOADBUFFERSIZE]; do { dwBytesRead = pFile->Read(pBuffer,dwUPLOADBUFFERSIZE); //ReadFile(hFile,pBuffer,dwUPLOADBUFFERSIZE,&dwBytesRead,0); if (dwBytesRead > 0) { WriteFile(hFile,pBuffer,dwBytesRead,&dwBytesWritten,0); //pFile->Write(pBuffer,dwBytesRead); i64TotalBytes += dwBytesRead; OnDownloadProgress(sRemoteFile,i64TotalBytes,dwFileSize); } } while (dwBytesRead > 0 && !m_bAbort); } else { bReturn = false; } } catch (CInternetException* e) { char strError[2048]; e->GetErrorMessage(strError,2048); e->Delete(); bReturn = false; } if (pFile) { pFile->Close(); delete pFile; pFile = 0; } if (pBuffer) delete pBuffer; CloseHandle(hFile); return bReturn; }