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
|
|
|
|
{
|
2020-04-03 03:57:59 +00:00
|
|
|
|
public async Task<AbstractDownloadState> GetDownloaderState(dynamic archiveINI, bool quickMode)
|
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
|
|
|
|
{
|
2020-03-25 22:30:43 +00:00
|
|
|
|
public override async Task<bool> Download(Archive a, AbsolutePath 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}");
|
2020-03-25 22:30:43 +00:00
|
|
|
|
client.DownloadFile(fileLink, (string)destination);
|
2020-01-18 19:57:26 +00:00
|
|
|
|
return true;
|
2019-10-12 18:03:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-13 22:55:55 +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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|