private void dlItem_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { IGameFileDownloadable downloadable = sender as IGameFileDownloadable; if ((this.DownloadView != null) && (downloadable != null)) { this.DownloadView.UpdateDownload(sender, e.ProgressPercentage); this.DownloadView.UpdateDownload(sender, $"{downloadable.FileName} - {Math.Round((double) ((((double) e.TotalBytesToReceive) / 1024.0) / 1024.0), 2)}MB"); } }
private void dlItem_DownloadCompleted(object sender, AsyncCompletedEventArgs e) { IGameFileDownloadable item = sender as IGameFileDownloadable; if ((this.DownloadView != null) && (item != null)) { this.DownloadView.UpdateDownload(sender, $"{item.FileName} ({e.Cancelled ? "Cancelled" : "Complete"})"); this.m_currentDownloads.Remove(item); } }
void dlItem_DownloadCompleted(object sender, AsyncCompletedEventArgs e) { IGameFileDownloadable dlItem = sender as IGameFileDownloadable; if (DownloadView != null && dlItem != null) { DownloadView.UpdateDownload(sender, string.Format("{0} ({1})", dlItem.FileName, e.Cancelled ? "Cancelled" : "Complete")); m_currentDownloads.Remove(dlItem); } }
void dlItem_DownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e) { IGameFileDownloadable dlItem = sender as IGameFileDownloadable; if (DownloadView != null && dlItem != null && (e.ProgressPercentage == 100 || DateTime.Now.Subtract(m_dtLastDowanloadUpdate).TotalMilliseconds > 400)) { m_dtLastDowanloadUpdate = DateTime.Now; DownloadView.UpdateDownload(sender, e.ProgressPercentage); DownloadView.UpdateDownload(sender, string.Format("{0} - {1}/{2}MB", dlItem.FileName, Math.Round(e.BytesReceived / 1024.0 / 1024.0, 1), Math.Round(e.TotalBytesToReceive / 1024.0 / 1024.0, 1))); } }
private void view_DownloadCancelled(object sender, EventArgs e) { object[] cancelledDownloads = this.DownloadView.CancelledDownloads; for (int i = 0; i < cancelledDownloads.Length; i++) { IGameFileDownloadable item = cancelledDownloads[i] as IGameFileDownloadable; if (item != null) { item.Cancel(); this.m_currentDownloads.Remove(item); } } }
void view_DownloadCancelled(object sender, EventArgs e) { var cancelled = DownloadView.GetCancelledDownloads(); foreach (object obj in cancelled) { IGameFileDownloadable dlItem = obj as IGameFileDownloadable; if (dlItem != null) { dlItem.Cancel(); m_currentDownloads.Remove(dlItem); } } }
public void Download(IGameFileDataSourceAdapter adapter, IGameFileDownloadable dlItem) { if ((dlItem != null) && !this.IsDownloading(dlItem)) { try { this.m_currentDownloads.Add(dlItem); dlItem.DownloadProgressChanged += new DownloadProgressChangedEventHandler(this.dlItem_DownloadProgressChanged); dlItem.DownloadCompleted += new AsyncCompletedEventHandler(this.dlItem_DownloadCompleted); if (this.DownloadView != null) { this.DownloadView.AddDownload(dlItem, dlItem.FileName); } dlItem.Download(adapter, Path.Combine(this.DownloadDirectory.GetFullPath(), dlItem.FileName)); } catch { } } }
public void Download(IGameFileDataSourceAdapter adapter, IGameFileDownloadable dlItem) { if (dlItem != null && !IsDownloading(dlItem)) { try { m_currentDownloads.Add(dlItem); dlItem.DownloadProgressChanged += dlItem_DownloadProgressChanged; dlItem.DownloadCompleted += dlItem_DownloadCompleted; if (DownloadView != null) { DownloadView.AddDownload(dlItem, dlItem.FileName); } dlItem.Download(adapter, Path.Combine(DownloadDirectory.GetFullPath(), dlItem.FileName)); } catch { //failed, nothing to do } } }
public bool IsDownloading(IGameFileDownloadable dlItem) { return(m_currentDownloads.Contains(dlItem)); }
public bool IsDownloading(IGameFileDownloadable dlItem) => this.m_currentDownloads.Contains(dlItem);