2019-10-12 18:03:45 +00:00
|
|
|
|
using System;
|
2019-12-06 05:29:17 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2019-10-12 18:03:45 +00:00
|
|
|
|
using CG.Web.MegaApiClient;
|
|
|
|
|
using Wabbajack.Common;
|
|
|
|
|
|
2019-10-16 03:10:34 +00:00
|
|
|
|
namespace Wabbajack.Lib.Downloaders
|
2019-10-12 18:03:45 +00:00
|
|
|
|
{
|
2019-10-16 11:44: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;
|
2019-10-16 11:44:45 +00:00
|
|
|
|
return GetDownloaderState(url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AbstractDownloadState GetDownloaderState(string url)
|
|
|
|
|
{
|
2019-10-12 18:03:45 +00:00
|
|
|
|
if (url != null && url.StartsWith(Consts.MegaPrefix))
|
2019-10-16 11:44:45 +00:00
|
|
|
|
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()
|
2019-10-12 22:15:20 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-12 21:37:16 +00:00
|
|
|
|
public class State : HTTPDownloader.State
|
2019-10-12 18:03:45 +00:00
|
|
|
|
{
|
2019-12-06 05:29:17 +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
|
|
|
|
}
|
|
|
|
|
|
2019-12-06 05:29:17 +00:00
|
|
|
|
public override async Task<bool> Verify()
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|