2019-10-12 18:03:45 +00:00
|
|
|
|
using System;
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public AbstractDownloadState GetDownloaderState(dynamic archive_ini)
|
|
|
|
|
{
|
|
|
|
|
var url = archive_ini?.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-10-12 22:15:20 +00:00
|
|
|
|
public void Prepare()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-12 21:37:16 +00:00
|
|
|
|
public class State : HTTPDownloader.State
|
2019-10-12 18:03:45 +00:00
|
|
|
|
{
|
|
|
|
|
public override void Download(Archive a, string destination)
|
|
|
|
|
{
|
|
|
|
|
var client = new MegaApiClient();
|
|
|
|
|
Utils.Status("Logging into MEGA (as anonymous)");
|
|
|
|
|
client.LoginAnonymous();
|
|
|
|
|
var file_link = new Uri(Url);
|
|
|
|
|
var node = client.GetNodeFromLink(file_link);
|
|
|
|
|
Utils.Status($"Downloading MEGA file: {a.Name}");
|
|
|
|
|
client.DownloadFile(file_link, destination);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Verify()
|
|
|
|
|
{
|
|
|
|
|
var client = new MegaApiClient();
|
|
|
|
|
Utils.Status("Logging into MEGA (as anonymous)");
|
|
|
|
|
client.LoginAnonymous();
|
|
|
|
|
var file_link = new Uri(Url);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var node = client.GetNodeFromLink(file_link);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|