Multiple MEGA login fixes

This commit is contained in:
erri120 2020-04-26 11:31:00 +02:00
parent 3e71b072b2
commit 663b82f5a7
No known key found for this signature in database
GPG Key ID: A8C0A18D8D4D3135
2 changed files with 22 additions and 5 deletions

View File

@ -4,7 +4,6 @@ using System.Reactive.Linq;
using System.Security;
using System.Threading.Tasks;
using CG.Web.MegaApiClient;
using Newtonsoft.Json;
using ReactiveUI;
using Wabbajack.Common;
using Wabbajack.Common.Serialization.Json;
@ -97,7 +96,7 @@ namespace Wabbajack.Lib.Downloaders
private static MegaApiClient MegaApiClient => DownloadDispatcher.GetInstance<MegaDownloader>().MegaApiClient;
private void MegaLogin()
private static void MegaLogin()
{
if (MegaApiClient.IsLoggedIn)
return;
@ -132,7 +131,7 @@ namespace Wabbajack.Lib.Downloaders
var fileLink = new Uri(Url);
try
{
var node = MegaApiClient.GetNodeFromLink(fileLink);
var node = await MegaApiClient.GetNodeFromLinkAsync(fileLink);
return true;
}
catch (Exception)

View File

@ -1,4 +1,5 @@
using System.Reactive;
using System;
using System.Net.Mail;
using System.Reactive.Linq;
using System.Security;
using ReactiveUI;
@ -26,7 +27,7 @@ namespace Wabbajack
_downloader = downloader;
_loginEnabled = this.WhenAny(x => x.Username)
.Select(username => !string.IsNullOrWhiteSpace(username))
.Select(IsValidAddress)
.ToGuiProperty(this,
nameof(LoginEnabled));
}
@ -36,5 +37,22 @@ namespace Wabbajack
ReturnMessage = _downloader.LoginWithCredentials(Username, password);
password.Clear();
}
private static bool IsValidAddress(string s)
{
if (string.IsNullOrWhiteSpace(s))
return false;
try
{
var _ = new MailAddress(s);
}
catch (Exception)
{
return false;
}
return true;
}
}
}