wabbajack/Wabbajack.Lib/Downloaders/MEGADownloader.cs

59 lines
1.8 KiB
C#
Raw Normal View History

2019-10-12 18:03:45 +00:00
using System;
using System.Threading.Tasks;
2019-10-12 18:03:45 +00:00
using CG.Web.MegaApiClient;
using Wabbajack.Common;
namespace Wabbajack.Lib.Downloaders
2019-10-12 18:03:45 +00:00
{
public class MegaDownloader : IDownloader, IUrlDownloader
2019-10-12 18:03:45 +00:00
{
2019-12-07 03:50:50 +00:00
public async Task<AbstractDownloadState> GetDownloaderState(dynamic archiveINI)
2019-10-12 18:03:45 +00:00
{
2019-11-21 15:51:57 +00:00
var url = archiveINI?.General?.directURL;
return GetDownloaderState(url);
}
public AbstractDownloadState GetDownloaderState(string url)
{
2019-10-12 18:03:45 +00:00
if (url != null && url.StartsWith(Consts.MegaPrefix))
return new State { Url = url };
2019-10-12 18:03:45 +00:00
return null;
}
2019-12-07 02:45:13 +00:00
public async Task Prepare()
{
}
public class State : HTTPDownloader.State
2019-10-12 18:03:45 +00:00
{
public override async Task Download(Archive a, string destination)
2019-10-12 18:03:45 +00:00
{
var client = new MegaApiClient();
Utils.Status("Logging into MEGA (as anonymous)");
client.LoginAnonymous();
2019-11-21 15:51:57 +00:00
var fileLink = new Uri(Url);
var node = client.GetNodeFromLink(fileLink);
2019-10-12 18:03:45 +00:00
Utils.Status($"Downloading MEGA file: {a.Name}");
2019-11-21 15:51:57 +00:00
client.DownloadFile(fileLink, destination);
2019-10-12 18:03:45 +00:00
}
public override async Task<bool> Verify(Archive a)
2019-10-12 18:03:45 +00:00
{
var client = new MegaApiClient();
Utils.Status("Logging into MEGA (as anonymous)");
client.LoginAnonymous();
2019-11-21 15:51:57 +00:00
var fileLink = new Uri(Url);
2019-10-12 18:03:45 +00:00
try
{
2019-11-21 15:51:57 +00:00
var node = client.GetNodeFromLink(fileLink);
2019-10-12 18:03:45 +00:00
return true;
}
catch (Exception)
{
return false;
}
}
}
}
}