add mirror downloaders to only handle downloading of a mirror
This commit is contained in:
parent
84c9f0975a
commit
f0e1abc9bf
9
SPTInstaller/Interfaces/IMirrorDownloader.cs
Normal file
9
SPTInstaller/Interfaces/IMirrorDownloader.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using SPTInstaller.Models.Mirrors;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SPTInstaller.Interfaces;
|
||||
public interface IMirrorDownloader
|
||||
{
|
||||
public DownloadMirror MirrorInfo { get; }
|
||||
public Task<FileInfo?> Download(IProgress<double> progress);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
namespace SPTInstaller.Models;
|
||||
namespace SPTInstaller.Models.Mirrors;
|
||||
|
||||
public class DownloadMirror
|
||||
{
|
@ -0,0 +1,15 @@
|
||||
using SPTInstaller.Helpers;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SPTInstaller.Models.Mirrors.Downloaders;
|
||||
public class HttpMirrorDownloader : MirrorDownloaderBase
|
||||
{
|
||||
public HttpMirrorDownloader(DownloadMirror mirror) : base(mirror)
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task<FileInfo?> Download(IProgress<double> progress)
|
||||
{
|
||||
return await DownloadCacheHelper.DownloadFileAsync("patcher.zip", MirrorInfo.Link, progress);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
using CG.Web.MegaApiClient;
|
||||
using SPTInstaller.Helpers;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SPTInstaller.Models.Mirrors.Downloaders;
|
||||
public class MegaMirrorDownloader : MirrorDownloaderBase
|
||||
{
|
||||
public MegaMirrorDownloader(DownloadMirror mirrorInfo) : base(mirrorInfo)
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task<FileInfo?> Download(IProgress<double> progress)
|
||||
{
|
||||
var megaClient = new MegaApiClient();
|
||||
await megaClient.LoginAnonymousAsync();
|
||||
|
||||
// if mega fails to connect, just return
|
||||
if (!megaClient.IsLoggedIn)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
using var megaDownloadStream = await megaClient.DownloadAsync(new Uri(MirrorInfo.Link), progress);
|
||||
|
||||
return await DownloadCacheHelper.DownloadFileAsync("patcher.zip", megaDownloadStream);
|
||||
}
|
||||
catch
|
||||
{
|
||||
//most likely a 509 (Bandwidth limit exceeded) due to mega's user quotas.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using SPTInstaller.Interfaces;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SPTInstaller.Models.Mirrors.Downloaders;
|
||||
public abstract class MirrorDownloaderBase : IMirrorDownloader
|
||||
{
|
||||
public DownloadMirror MirrorInfo { get; private set; }
|
||||
public abstract Task<FileInfo?> Download(IProgress<double> progress);
|
||||
public MirrorDownloaderBase(DownloadMirror mirrorInfo)
|
||||
{
|
||||
MirrorInfo = mirrorInfo;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user