mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
69 lines
2.1 KiB
C#
69 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Runtime.InteropServices.WindowsRuntime;
|
|
using System.Security.Policy;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Alphaleonis.Win32.Filesystem;
|
|
using CG.Web.MegaApiClient;
|
|
using Wabbajack.Common;
|
|
using Wabbajack.Validation;
|
|
|
|
namespace Wabbajack.Downloaders
|
|
{
|
|
public class MegaDownloader : IDownloader
|
|
{
|
|
public void Init()
|
|
{
|
|
}
|
|
|
|
public AbstractDownloadState GetDownloaderState(dynamic archive_ini)
|
|
{
|
|
var url = archive_ini?.General?.directURL;
|
|
if (url != null && url.StartsWith(Consts.MegaPrefix))
|
|
return new State {Url = url};
|
|
return null;
|
|
}
|
|
|
|
public class State : AbstractDownloadState
|
|
{
|
|
public string Url { get; set; }
|
|
|
|
public override bool IsWhitelisted(ServerWhitelist whitelist)
|
|
{
|
|
return whitelist.AllowedPrefixes.Any(p => Url.StartsWith(p));
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|