From 195cd688be81698ce72eeb4521280b6a8be7f1c6 Mon Sep 17 00:00:00 2001 From: Piotrekol Date: Sun, 16 Jun 2019 12:21:40 +0200 Subject: [PATCH] Add: detection of download limit and removed beatmaps --- .../DownloadManager/API/DownloadManager.cs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/CollectionManagerExtensionsDll/Modules/DownloadManager/API/DownloadManager.cs b/CollectionManagerExtensionsDll/Modules/DownloadManager/API/DownloadManager.cs index f5a6fef..2f3eeaf 100644 --- a/CollectionManagerExtensionsDll/Modules/DownloadManager/API/DownloadManager.cs +++ b/CollectionManagerExtensionsDll/Modules/DownloadManager/API/DownloadManager.cs @@ -5,6 +5,7 @@ using System.IO; using System.Net; using System.Threading; +using System.Threading.Tasks; namespace CollectionManagerExtensionsDll.Modules.DownloadManager.API { @@ -172,7 +173,9 @@ private void Completed(object sender, AsyncCompletedEventArgs e) url.DownloadAborted = true;//Progress = "download cancelled"; error = true; lock (_urlsToDownload) + { _urlsToDownload.AddFirst(url); + } } else if (e.Error != null) { @@ -180,6 +183,36 @@ private void Completed(object sender, AsyncCompletedEventArgs e) url.Error = "Error: " + e.Error.ToString(); error = true; } + else if (url.BytesRecived<10000) + { + //check if that's a disabled dl or download cap + var tempFileLocation = GetFullTempLocation(url.FileName); + var tempFileContents = File.ReadAllText(tempFileLocation); + if (tempFileContents.Contains("disabled")) // "This download has been disabled ()" + { + error = true; + url.Error = tempFileContents; + } + else if(tempFileContents.Contains("slow down")) // "slow down, play more." + { + //We've hit download cap, lets chill a little + if (!_stopDownloads) + { + StopDownloads(); + Task.Run(async () => + { + //Stop downloads for 6 minutes - user can try to resume these earlier, but it'll just get paused again if limit is still in place. + await Task.Delay(60 * 1000 * 6); + ResumeNewDownloads(); + }); + } + + lock (_urlsToDownload) + { + _urlsToDownload.AddFirst(url); + } + } + } if (error) { string tempFileLocation = GetFullTempLocation(url.FileName);