From c5dd1d638852e309d35eeef7fcf20e3d4743442a Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Thu, 28 May 2020 17:44:58 -0600 Subject: [PATCH] Add TESAll download support --- .../Downloaders/AbstractDownloadState.cs | 1 + .../Downloaders/AbstractIPS4Downloader.cs | 13 ++++++++-- .../Downloaders/DownloadDispatcher.cs | 1 + Wabbajack.Lib/Downloaders/TESAllDownloader.cs | 22 +++++++++++++++++ Wabbajack.Test/DownloaderTests.cs | 24 +++++++++++++++++++ 5 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 Wabbajack.Lib/Downloaders/TESAllDownloader.cs diff --git a/Wabbajack.Lib/Downloaders/AbstractDownloadState.cs b/Wabbajack.Lib/Downloaders/AbstractDownloadState.cs index 9e0c2e63..635e6b6b 100644 --- a/Wabbajack.Lib/Downloaders/AbstractDownloadState.cs +++ b/Wabbajack.Lib/Downloaders/AbstractDownloadState.cs @@ -38,6 +38,7 @@ namespace Wabbajack.Lib.Downloaders typeof(VectorPlexusDownloader.State), typeof(DeadlyStreamDownloader.State), typeof(TESAllianceDownloader.State), + typeof(TESAllDownloader.State), typeof(BethesdaNetDownloader.State), typeof(YouTubeDownloader.State), typeof(WabbajackCDNDownloader.State) diff --git a/Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs b/Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs index 4567e4bc..a582ef64 100644 --- a/Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs +++ b/Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs @@ -19,8 +19,8 @@ namespace Wabbajack.Lib.Downloaders where TState : AbstractIPS4Downloader.State, new() where TDownloader : IDownloader { - protected AbstractIPS4Downloader(Uri loginUri, string encryptedKeyName, string cookieDomain) - : base(loginUri, encryptedKeyName, cookieDomain, "ips4_member_id") + protected AbstractIPS4Downloader(Uri loginUri, string encryptedKeyName, string cookieDomain, string loginCookie = "ips4_member_id") + : base(loginUri, encryptedKeyName, cookieDomain, loginCookie) { } @@ -52,6 +52,15 @@ namespace Wabbajack.Lib.Downloaders FileName = name }; } + + if (url.PathAndQuery.StartsWith("/files/getdownload")) + { + return new TState + { + FullURL = url.ToString(), + IsAttachment = true + }; + } if (!url.PathAndQuery.StartsWith("/files/file/")) { diff --git a/Wabbajack.Lib/Downloaders/DownloadDispatcher.cs b/Wabbajack.Lib/Downloaders/DownloadDispatcher.cs index f350fb93..e4737fb0 100644 --- a/Wabbajack.Lib/Downloaders/DownloadDispatcher.cs +++ b/Wabbajack.Lib/Downloaders/DownloadDispatcher.cs @@ -26,6 +26,7 @@ namespace Wabbajack.Lib.Downloaders new DeadlyStreamDownloader(), new BethesdaNetDownloader(), new TESAllianceDownloader(), + new TESAllDownloader(), new YouTubeDownloader(), new WabbajackCDNDownloader(), new HTTPDownloader(), diff --git a/Wabbajack.Lib/Downloaders/TESAllDownloader.cs b/Wabbajack.Lib/Downloaders/TESAllDownloader.cs new file mode 100644 index 00000000..8530e400 --- /dev/null +++ b/Wabbajack.Lib/Downloaders/TESAllDownloader.cs @@ -0,0 +1,22 @@ +using System; +using Wabbajack.Common.Serialization.Json; + +namespace Wabbajack.Lib.Downloaders +{ + public class TESAllDownloader : AbstractIPS4Downloader + { + #region INeedsDownload + public override string SiteName => "TESALL"; + public override Uri SiteURL => new Uri("http://tesall.ru"); + public override Uri IconUri => new Uri("http://tesall.ru/favicon.ico"); + #endregion + + public TESAllDownloader() : base(new Uri("https://tesall.ru/index.php?app=core&module=global§ion=login"), + "tesall", "tesall.ru", "member_id") + { + } + + [JsonName("TESAllDownloader")] + public class State : State{} + } +} diff --git a/Wabbajack.Test/DownloaderTests.cs b/Wabbajack.Test/DownloaderTests.cs index b5a1aac8..a1dbd761 100644 --- a/Wabbajack.Test/DownloaderTests.cs +++ b/Wabbajack.Test/DownloaderTests.cs @@ -362,6 +362,30 @@ namespace Wabbajack.Test Assert.Equal("Cheese for Everyone!", await filename.Path.ReadAllTextAsync()); } + + [Fact] + public async Task TESAllDownloader() + { + await DownloadDispatcher.GetInstance().Prepare(); + const string ini = "[General]\n" + + "directURL=https://tesall.ru/files/getdownload/594545-wabbajack-test-file/"; + + var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString()); + + Assert.NotNull(state); + + var converted = RoundTripState(state); + Assert.True(await converted.Verify(new Archive(state: null!) { Size = 20})); + await using var filename = new TempFile(); + + Assert.True(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List() })); + + await converted.Download(new Archive(state: null!) { Name = "TESAll Test.zip" }, filename.Path); + + Assert.Equal(Hash.FromBase64("eSIyd+KOG3s="), await filename.Path.FileHashAsync()); + + Assert.Equal("Cheese for Everyone!", await filename.Path.ReadAllTextAsync()); + } /* WAITING FOR APPROVAL BY MODERATOR [Fact]