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;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reactive;
|
using System.Reactive;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
|
|
||||||
namespace Wabbajack.Lib.Downloaders
|
namespace Wabbajack.Lib.Downloaders
|
||||||
|
@ -1,12 +1,29 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Reactive;
|
||||||
|
using System.Reactive.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using CG.Web.MegaApiClient;
|
using CG.Web.MegaApiClient;
|
||||||
|
using ReactiveUI;
|
||||||
using Wabbajack.Common;
|
using Wabbajack.Common;
|
||||||
|
|
||||||
namespace Wabbajack.Lib.Downloaders
|
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)
|
public async Task<AbstractDownloadState> GetDownloaderState(dynamic archiveINI)
|
||||||
{
|
{
|
||||||
var url = archiveINI?.General?.directURL;
|
var url = archiveINI?.General?.directURL;
|
||||||
@ -16,7 +33,7 @@ namespace Wabbajack.Lib.Downloaders
|
|||||||
public AbstractDownloadState GetDownloaderState(string url)
|
public AbstractDownloadState GetDownloaderState(string url)
|
||||||
{
|
{
|
||||||
if (url != null && url.StartsWith(Consts.MegaPrefix))
|
if (url != null && url.StartsWith(Consts.MegaPrefix))
|
||||||
return new State { Url = url };
|
return new State { Url = url, MegaApiClient = MegaApiClient};
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,27 +43,35 @@ namespace Wabbajack.Lib.Downloaders
|
|||||||
|
|
||||||
public class State : HTTPDownloader.State
|
public class State : HTTPDownloader.State
|
||||||
{
|
{
|
||||||
|
public MegaApiClient MegaApiClient;
|
||||||
|
|
||||||
public override async Task<bool> Download(Archive a, string destination)
|
public override async Task<bool> Download(Archive a, string destination)
|
||||||
{
|
{
|
||||||
var client = new MegaApiClient();
|
if (!MegaApiClient.IsLoggedIn)
|
||||||
Utils.Status("Logging into MEGA (as anonymous)");
|
{
|
||||||
client.LoginAnonymous();
|
Utils.Status("Logging into MEGA (as anonymous)");
|
||||||
|
MegaApiClient.LoginAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
var fileLink = new Uri(Url);
|
var fileLink = new Uri(Url);
|
||||||
var node = client.GetNodeFromLink(fileLink);
|
var node = MegaApiClient.GetNodeFromLink(fileLink);
|
||||||
Utils.Status($"Downloading MEGA file: {a.Name}");
|
Utils.Status($"Downloading MEGA file: {a.Name}");
|
||||||
client.DownloadFile(fileLink, destination);
|
MegaApiClient.DownloadFile(fileLink, destination);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<bool> Verify(Archive a)
|
public override async Task<bool> Verify(Archive a)
|
||||||
{
|
{
|
||||||
var client = new MegaApiClient();
|
if (!MegaApiClient.IsLoggedIn)
|
||||||
Utils.Status("Logging into MEGA (as anonymous)");
|
{
|
||||||
client.LoginAnonymous();
|
Utils.Status("Logging into MEGA (as anonymous)");
|
||||||
|
MegaApiClient.LoginAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
var fileLink = new Uri(Url);
|
var fileLink = new Uri(Url);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var node = client.GetNodeFromLink(fileLink);
|
var node = MegaApiClient.GetNodeFromLink(fileLink);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
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