waffle.lord 1354eeb06c update ziphelper to use 7z.dll
also updated cache to drop compression extensions for aki release and patcher in preparation for 3.8.0
2024-03-23 14:15:48 -04:00

41 lines
1.2 KiB
C#

using CG.Web.MegaApiClient;
using SPTInstaller.Helpers;
using System.Threading.Tasks;
using Serilog;
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);
var file = await DownloadCacheHelper.DownloadFileAsync("patcher", megaDownloadStream);
if (file == null)
return null;
return FileHashHelper.CheckHash(file, MirrorInfo.Hash) ? file : null;
}
catch(Exception ex)
{
Log.Error(ex, "Exception thrown while downloading from mega");
//most likely a 509 (Bandwidth limit exceeded) due to mega's user quotas.
return null;
}
}
}