Skip to content

Commit

Permalink
Add: detection of download limit and removed beatmaps
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotrekol committed Jun 16, 2019
1 parent 1ba546e commit 195cd68
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using System.Net;
using System.Threading;
using System.Threading.Tasks;

namespace CollectionManagerExtensionsDll.Modules.DownloadManager.API
{
Expand Down Expand Up @@ -172,14 +173,46 @@ 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)
{
url.OtherError = true;
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 (<some url>)"
{
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);
Expand Down

0 comments on commit 195cd68

Please sign in to comment.