mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Implemented INeedsLogin in MegaDownloader
This commit is contained in:
parent
0dc18334ac
commit
9eac8d7641
@ -1,11 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Wabbajack.Lib.Downloaders
|
||||
|
@ -1,12 +1,29 @@
|
||||
using System;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CG.Web.MegaApiClient;
|
||||
using ReactiveUI;
|
||||
using Wabbajack.Common;
|
||||
|
||||
namespace Wabbajack.Lib.Downloaders
|
||||
{
|
||||
public class MegaDownloader : IDownloader, IUrlDownloader
|
||||
public class MegaDownloader : IUrlDownloader, INeedsLogin
|
||||
{
|
||||
public MegaApiClient MegaApiClient;
|
||||
private const string DataName = "mega-cred";
|
||||
|
||||
public MegaDownloader()
|
||||
{
|
||||
MegaApiClient = new MegaApiClient();
|
||||
|
||||
TriggerLogin = ReactiveCommand.Create(() => { },
|
||||
IsLoggedIn.Select(b => !b).ObserveOnGuiThread());
|
||||
|
||||
ClearLogin = ReactiveCommand.Create(() => Utils.CatchAndLog(() => Utils.DeleteEncryptedJson(DataName)),
|
||||
IsLoggedIn.ObserveOnGuiThread());
|
||||
}
|
||||
|
||||
public async Task<AbstractDownloadState> GetDownloaderState(dynamic archiveINI)
|
||||
{
|
||||
var url = archiveINI?.General?.directURL;
|
||||
@ -16,7 +33,7 @@ namespace Wabbajack.Lib.Downloaders
|
||||
public AbstractDownloadState GetDownloaderState(string url)
|
||||
{
|
||||
if (url != null && url.StartsWith(Consts.MegaPrefix))
|
||||
return new State { Url = url };
|
||||
return new State { Url = url, MegaApiClient = MegaApiClient};
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -26,27 +43,35 @@ namespace Wabbajack.Lib.Downloaders
|
||||
|
||||
public class State : HTTPDownloader.State
|
||||
{
|
||||
public MegaApiClient MegaApiClient;
|
||||
|
||||
public override async Task<bool> Download(Archive a, string destination)
|
||||
{
|
||||
var client = new MegaApiClient();
|
||||
Utils.Status("Logging into MEGA (as anonymous)");
|
||||
client.LoginAnonymous();
|
||||
if (!MegaApiClient.IsLoggedIn)
|
||||
{
|
||||
Utils.Status("Logging into MEGA (as anonymous)");
|
||||
MegaApiClient.LoginAnonymous();
|
||||
}
|
||||
|
||||
var fileLink = new Uri(Url);
|
||||
var node = client.GetNodeFromLink(fileLink);
|
||||
var node = MegaApiClient.GetNodeFromLink(fileLink);
|
||||
Utils.Status($"Downloading MEGA file: {a.Name}");
|
||||
client.DownloadFile(fileLink, destination);
|
||||
MegaApiClient.DownloadFile(fileLink, destination);
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task<bool> Verify(Archive a)
|
||||
{
|
||||
var client = new MegaApiClient();
|
||||
Utils.Status("Logging into MEGA (as anonymous)");
|
||||
client.LoginAnonymous();
|
||||
if (!MegaApiClient.IsLoggedIn)
|
||||
{
|
||||
Utils.Status("Logging into MEGA (as anonymous)");
|
||||
MegaApiClient.LoginAnonymous();
|
||||
}
|
||||
|
||||
var fileLink = new Uri(Url);
|
||||
try
|
||||
{
|
||||
var node = client.GetNodeFromLink(fileLink);
|
||||
var node = MegaApiClient.GetNodeFromLink(fileLink);
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
@ -55,5 +80,13 @@ namespace Wabbajack.Lib.Downloaders
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit> TriggerLogin { get; }
|
||||
public ReactiveCommand<Unit, Unit> ClearLogin { get; }
|
||||
public IObservable<bool> IsLoggedIn => Utils.HaveEncryptedJsonObservable(DataName);
|
||||
public string SiteName => "MEGA";
|
||||
public IObservable<string> MetaInfo => Observable.Return("");
|
||||
public Uri SiteURL => new Uri("https://mega.nz/");
|
||||
public Uri IconUri => new Uri("https://mega.nz/favicon.ico");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user