public bool DownloadFile(ref structDownloadFile downloadFile) { clsDownloadFile cls_DownloadFile = new clsDownloadFile(ref downloadFile.m_arrMirrorURL, downloadFile.m_strFilename, 0); cls_DownloadFile.eCallFeedback += new clsDownloadFile.delCallFeedback(OnCallFeedbackFile); cls_DownloadFile.eCallTimeFeedback += new clsDownloadFile.delCallTimeFeedback(OnCallTimeFeedbackFile); m_TotalBytesTransfered = 0; if (downloadFile.m_nFileSize >= 0) { m_TotalBytes = downloadFile.m_nFileSize; cls_DownloadFile.SetFileSize(m_TotalBytes); } else { if (cls_DownloadFile.RequestFileSize(out m_TotalBytes) == false) { cls_DownloadFile = null; return(false); } cls_DownloadFile.SetFileSize(m_TotalBytes); } m_CurDownload = cls_DownloadFile; OnCallFeedback(m_TotalBytes, 0, cls_DownloadFile.GetFileName(), m_TotalBytes, 0); if (cls_DownloadFile.DownloadFile(m_TotalBytes) == false) { return(false); } OnCallTimeFeedback(0.0, 0.0, 0.0); return(true); }
public bool DownloadFiles(ref structDownloadFile[] arrDownloadFile) { System.Collections.ArrayList arrFiles = new System.Collections.ArrayList(); bool bError; m_TotalBytes = 0; // for (int i = 0; i < arrDownloadFile.Length; i++) // { // if (arrDownloadFile[i].m_nFileSize < 0) // { // // if (((clsDownloadFile) arrFiles[i]).RequestFileSize (out arrDownloadFile[i].m_nFileSize) == false) // { // return false; // } // } // } for (int i = 0; i < arrDownloadFile.Length; i++) { if (System.IO.File.Exists(arrDownloadFile[i].m_strFilename)) { if (arrDownloadFile[i].m_nFileSize >= 0) { System.IO.FileInfo fileInfo = new System.IO.FileInfo(arrDownloadFile[i].m_strFilename); if (fileInfo.Length == arrDownloadFile[i].m_nFileSize) { fileInfo = null; continue; } fileInfo = null; } else { continue; } } clsDownloadFile cls_DownloadFile = new clsDownloadFile(ref arrDownloadFile[i].m_arrMirrorURL, arrDownloadFile[i].m_strFilename, arrDownloadFile[i].m_nFileSize); cls_DownloadFile.RequestFileSize(out arrDownloadFile[i].m_nFileSize); cls_DownloadFile.Size = arrDownloadFile[i].m_nFileSize; cls_DownloadFile.eCallFeedback += new clsDownloadFile.delCallFeedback(OnCallFeedbackFile); cls_DownloadFile.eCallTimeFeedback += new clsDownloadFile.delCallTimeFeedback(OnCallTimeFeedbackFile); arrFiles.Add(cls_DownloadFile); } if (arrFiles.Count == 0) { return(true); } for (int i = 0; i < arrFiles.Count; i++) { clsDownloadFile cls_File = (clsDownloadFile)arrFiles[i]; m_TotalBytes += cls_File.GetFileSize(); } m_TotalBytesTransfered = 0; for (int tent = 0; tent < 3; tent++) { for (int i = 0; i < arrFiles.Count; i++) { m_CurDownload = (clsDownloadFile)arrFiles[i]; bError = false; if (m_CurDownload.GetOK()) { continue; } OnCallFeedback(m_TotalBytes, m_TotalBytesTransfered, m_CurDownload.GetFileName(), m_CurDownload.GetFileSize(), 0); if (m_CurDownload.DownloadFile(m_CurDownload.GetFileSize()) == false) { bError = true; if (m_CurDownload.GetTentativas() == 3) { OnCallFeedback(m_TotalBytes, m_TotalBytesTransfered + m_CurDownload.GetFileSize(), "", m_CurDownload.GetFileSize(), m_CurDownload.GetFileSize()); if (OnCallError(m_CurDownload.GetFileName())) { return(false); } } else { continue; } } m_TotalBytesTransfered += m_CurDownload.GetFileSize(); if (bError == false) { OnCallFeedback(m_TotalBytes, m_TotalBytesTransfered, m_CurDownload.GetFileName(), m_CurDownload.GetFileSize(), m_CurDownload.GetFileSize()); } } for (int i = arrFiles.Count - 1; i >= 0; i--) { m_CurDownload = (clsDownloadFile)arrFiles[i]; if (m_CurDownload.GetOK()) { arrFiles.RemoveAt(i); } } if (arrFiles.Count == 0) { break; } System.Threading.Thread.Sleep(5000); } OnCallTimeFeedback(0.0, 0.0, 0.0); return(true); }