mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
commit
c0d2f8f280
@ -13,11 +13,12 @@ namespace Wabbajack.Lib.Downloaders
|
||||
return GetDownloaderState(urlstring);
|
||||
}
|
||||
|
||||
public AbstractDownloadState? GetDownloaderState(string url)
|
||||
public AbstractDownloadState? GetDownloaderState(string? url)
|
||||
{
|
||||
if (url == null) return null;
|
||||
|
||||
try
|
||||
{
|
||||
if (url == null) return null;
|
||||
var uri = new UriBuilder(url);
|
||||
if (uri.Host != "www.dropbox.com") return null;
|
||||
var query = HttpUtility.ParseQueryString(uri.Query);
|
||||
|
@ -21,12 +21,15 @@ namespace Wabbajack.Lib.Downloaders
|
||||
}
|
||||
|
||||
private static readonly Regex GDriveRegex = new("((?<=id=)[a-zA-Z0-9_-]*)|(?<=\\/file\\/d\\/)[a-zA-Z0-9_-]*", RegexOptions.Compiled);
|
||||
public AbstractDownloadState? GetDownloaderState(string url)
|
||||
public AbstractDownloadState? GetDownloaderState(string? url)
|
||||
{
|
||||
if (url == null) return null;
|
||||
|
||||
if (!url.StartsWith("https://drive.google.com"))
|
||||
return null;
|
||||
|
||||
var match = GDriveRegex.Match(url);
|
||||
|
||||
return new State(match.ToString());
|
||||
|
||||
}
|
||||
|
@ -23,24 +23,23 @@ namespace Wabbajack.Lib.Downloaders
|
||||
return GetDownloaderState(url, archiveINI);
|
||||
}
|
||||
|
||||
public AbstractDownloadState? GetDownloaderState(string uri)
|
||||
public AbstractDownloadState? GetDownloaderState(string? uri)
|
||||
{
|
||||
return GetDownloaderState(uri, null);
|
||||
}
|
||||
|
||||
public AbstractDownloadState? GetDownloaderState(string url, dynamic? archiveINI)
|
||||
public AbstractDownloadState? GetDownloaderState(string? url, dynamic? archiveINI)
|
||||
{
|
||||
if (url != null)
|
||||
{
|
||||
var tmp = new State(url);
|
||||
if (archiveINI?.General?.directURLHeaders != null)
|
||||
{
|
||||
tmp.Headers.AddRange(archiveINI?.General.directURLHeaders.Split('|'));
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
if (url == null)
|
||||
return null;
|
||||
|
||||
var tmp = new State(url);
|
||||
if (archiveINI?.General?.directURLHeaders != null)
|
||||
{
|
||||
tmp.Headers.AddRange(archiveINI?.General.directURLHeaders.Split('|'));
|
||||
}
|
||||
return tmp;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task Prepare()
|
||||
|
@ -2,6 +2,6 @@
|
||||
{
|
||||
public interface IUrlDownloader : IDownloader
|
||||
{
|
||||
AbstractDownloadState? GetDownloaderState(string url);
|
||||
AbstractDownloadState? GetDownloaderState(string? url);
|
||||
}
|
||||
}
|
||||
|
@ -54,15 +54,9 @@ namespace Wabbajack.Lib.Downloaders
|
||||
{
|
||||
MegaApiClient.AuthInfos authInfos;
|
||||
|
||||
try
|
||||
{
|
||||
MegaApiClient.Logout();
|
||||
}
|
||||
catch (NotSupportedException)
|
||||
{
|
||||
// Not logged in, so ignore
|
||||
}
|
||||
|
||||
if (MegaApiClient.IsLoggedIn)
|
||||
await MegaApiClient.LogoutAsync();
|
||||
|
||||
try
|
||||
{
|
||||
authInfos = MegaApiClient.GenerateAuthInfos(username, password.ToNormalString(), mfa);
|
||||
@ -81,7 +75,7 @@ namespace Wabbajack.Lib.Downloaders
|
||||
|
||||
try
|
||||
{
|
||||
MegaApiClient.Login(authInfos);
|
||||
await MegaApiClient.LoginAsync(authInfos);
|
||||
}
|
||||
catch (ApiException e)
|
||||
{
|
||||
@ -98,37 +92,36 @@ namespace Wabbajack.Lib.Downloaders
|
||||
_ => new LoginReturnMessage($"Error during login: {e.Message}", LoginReturnCode.InternalError)
|
||||
};
|
||||
}
|
||||
|
||||
if (MegaApiClient.IsLoggedIn)
|
||||
{
|
||||
var infos = MEGAAuthInfos.ToMEGAAuthInfos(authInfos);
|
||||
await infos.ToEcryptedJson(DataName);
|
||||
}
|
||||
|
||||
return new LoginReturnMessage("Logged in successfully, you can now close this window.",
|
||||
!MegaApiClient.IsLoggedIn || !Utils.HaveEncryptedJson(DataName) ? LoginReturnCode.Success : LoginReturnCode.InternalError);
|
||||
|
||||
var infos = MEGAAuthInfos.ToMEGAAuthInfos(authInfos);
|
||||
await infos.ToEcryptedJson(DataName);
|
||||
return new LoginReturnMessage("Logged in successfully, you can now close this window.", LoginReturnCode.Success);
|
||||
}
|
||||
|
||||
public MegaDownloader()
|
||||
{
|
||||
MegaApiClient = new MegaApiClient();
|
||||
|
||||
TriggerLogin = ReactiveCommand.Create(() => { },
|
||||
TriggerLogin = ReactiveCommand
|
||||
.Create(() => { },
|
||||
IsLoggedIn.Select(b => !b).ObserveOnGuiThread());
|
||||
|
||||
ClearLogin = ReactiveCommand.CreateFromTask(() => Utils.CatchAndLog(async () => await Utils.DeleteEncryptedJson(DataName)),
|
||||
ClearLogin = ReactiveCommand
|
||||
.CreateFromTask(() => Utils.CatchAndLog(async () => await Utils.DeleteEncryptedJson(DataName)),
|
||||
IsLoggedIn.ObserveOnGuiThread());
|
||||
}
|
||||
|
||||
public async Task<AbstractDownloadState?> GetDownloaderState(dynamic archiveINI, bool quickMode)
|
||||
{
|
||||
var url = archiveINI?.General?.directURL;
|
||||
var url = archiveINI.General?.directURL;
|
||||
return GetDownloaderState(url);
|
||||
}
|
||||
|
||||
public AbstractDownloadState? GetDownloaderState(string url)
|
||||
public AbstractDownloadState? GetDownloaderState(string? url)
|
||||
{
|
||||
if (url != null && (url.StartsWith(Consts.MegaPrefix) || url.StartsWith(Consts.MegaFilePrefix)))
|
||||
if (url == null) return null;
|
||||
|
||||
if ((url.StartsWith(Consts.MegaPrefix) || url.StartsWith(Consts.MegaFilePrefix)))
|
||||
return new State(url);
|
||||
return null;
|
||||
}
|
||||
@ -147,10 +140,10 @@ namespace Wabbajack.Lib.Downloaders
|
||||
|
||||
private static MegaApiClient MegaApiClient => DownloadDispatcher.GetInstance<MegaDownloader>().MegaApiClient;
|
||||
|
||||
private static readonly AsyncLock _loginLock = new AsyncLock();
|
||||
private static readonly AsyncLock LoginLock = new();
|
||||
private static async Task MegaLogin()
|
||||
{
|
||||
using var _ = await _loginLock.WaitAsync();
|
||||
using var _ = await LoginLock.WaitAsync();
|
||||
|
||||
if (MegaApiClient.IsLoggedIn)
|
||||
return;
|
||||
@ -171,7 +164,8 @@ namespace Wabbajack.Lib.Downloaders
|
||||
|
||||
public override async Task<bool> Download(Archive a, AbsolutePath destination)
|
||||
{
|
||||
await MegaLogin();
|
||||
if (!MegaApiClient.IsLoggedIn)
|
||||
await MegaLogin();
|
||||
|
||||
var fileLink = new Uri(Url);
|
||||
Utils.Status($"Downloading MEGA file: {a.Name}");
|
||||
@ -183,7 +177,8 @@ namespace Wabbajack.Lib.Downloaders
|
||||
|
||||
public override async Task<bool> Verify(Archive a, CancellationToken? token)
|
||||
{
|
||||
await MegaLogin();
|
||||
if (!MegaApiClient.IsLoggedIn)
|
||||
await MegaLogin();
|
||||
|
||||
var fileLink = new Uri(Url);
|
||||
try
|
||||
@ -213,7 +208,7 @@ namespace Wabbajack.Lib.Downloaders
|
||||
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");
|
||||
public Uri SiteURL => new("https://mega.nz/");
|
||||
public Uri IconUri => new("https://mega.nz/favicon.ico");
|
||||
}
|
||||
}
|
||||
|
@ -92,12 +92,12 @@ namespace Wabbajack.Lib.Downloaders
|
||||
{
|
||||
}
|
||||
|
||||
public AbstractDownloadState? GetDownloaderState(string u)
|
||||
public AbstractDownloadState? GetDownloaderState(string? u)
|
||||
{
|
||||
if (u == null) return null;
|
||||
|
||||
var url = new Uri(u);
|
||||
if (url.Host != "www.mediafire.com") return null;
|
||||
|
||||
return new State(url.ToString());
|
||||
return url.Host != "www.mediafire.com" ? null : new State(url.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ namespace Wabbajack.Lib.Downloaders
|
||||
return GetDownloaderState(url);
|
||||
}
|
||||
|
||||
public AbstractDownloadState? GetDownloaderState(string url)
|
||||
public AbstractDownloadState? GetDownloaderState(string? url)
|
||||
{
|
||||
if (url != null && url.StartsWith("https://www.moddb.com/downloads/start"))
|
||||
{
|
||||
|
@ -40,9 +40,9 @@ namespace Wabbajack.Lib.Downloaders
|
||||
{
|
||||
}
|
||||
|
||||
public AbstractDownloadState? GetDownloaderState(string url)
|
||||
public AbstractDownloadState? GetDownloaderState(string? url)
|
||||
{
|
||||
return StateFromUrl(new Uri(url));
|
||||
return url == null ? null : StateFromUrl(new Uri(url));
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,15 +22,12 @@ namespace Wabbajack.Lib.Downloaders
|
||||
{
|
||||
}
|
||||
|
||||
public AbstractDownloadState? GetDownloaderState(string url)
|
||||
public AbstractDownloadState? GetDownloaderState(string? url)
|
||||
{
|
||||
if (url == null) return null;
|
||||
|
||||
var uri = new Uri(url);
|
||||
if (uri.Host == "yadi.sk")
|
||||
{
|
||||
return new State(uri);
|
||||
}
|
||||
|
||||
return null;
|
||||
return uri.Host == "yadi.sk" ? new State(uri) : null;
|
||||
}
|
||||
|
||||
[JsonName("YandexDownloader+State")]
|
||||
|
Loading…
Reference in New Issue
Block a user