wabbajack/Wabbajack.Test/DownloaderTests.cs

661 lines
27 KiB
C#
Raw Normal View History

2019-10-12 18:03:45 +00:00
using System;
using System.Collections.Generic;
2020-03-26 23:02:15 +00:00
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Threading.Tasks;
2019-12-08 17:00:22 +00:00
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Threading;
2019-10-12 18:03:45 +00:00
using Wabbajack.Common;
2019-12-08 17:00:22 +00:00
using Wabbajack.Common.StatusFeed;
using Wabbajack.Lib;
using Wabbajack.Lib.Downloaders;
2020-12-29 23:15:47 +00:00
using Wabbajack.Lib.Http;
2019-12-07 17:39:22 +00:00
using Wabbajack.Lib.LibCefHelpers;
using Wabbajack.Lib.NexusApi;
using Wabbajack.Lib.Validation;
2020-12-29 23:15:47 +00:00
using Wabbajack.Lib.WebAutomation;
2020-03-26 23:02:15 +00:00
using Xunit;
using Xunit.Abstractions;
using Directory = System.IO.Directory;
2019-10-12 18:03:45 +00:00
using File = Alphaleonis.Win32.Filesystem.File;
using Game = Wabbajack.Common.Game;
2020-03-26 23:02:15 +00:00
using Path = Alphaleonis.Win32.Filesystem.Path;
2019-10-12 18:03:45 +00:00
namespace Wabbajack.Test
{
2020-03-29 20:42:45 +00:00
public class DownloaderTests : XunitContextBase, IDisposable
2019-10-12 18:03:45 +00:00
{
2020-03-29 20:42:45 +00:00
private IDisposable _unsubMsgs;
private IDisposable _unsubErr;
public DownloaderTests(ITestOutputHelper helper) : base(helper)
{
2020-03-29 20:42:45 +00:00
Helpers.Init();
_unsubMsgs = Utils.LogMessages.OfType<IInfo>().Subscribe(onNext: msg => XunitContext.WriteLine(msg.ShortDescription));
_unsubErr = Utils.LogMessages.OfType<IUserIntervention>().Subscribe(msg =>
XunitContext.WriteLine("ERROR: User intervention required: " + msg.ShortDescription));
}
2020-03-29 20:42:45 +00:00
public override void Dispose()
{
base.Dispose();
_unsubErr.Dispose();
_unsubMsgs.Dispose();
}
2020-03-26 23:02:15 +00:00
2020-08-31 23:29:48 +00:00
/*
2020-03-26 23:02:15 +00:00
[Fact]
2020-04-10 19:06:32 +00:00
public async Task TestAllPrepares()
{
foreach (var downloader in DownloadDispatcher.Downloaders)
await downloader.Prepare();
2020-08-31 23:29:48 +00:00
}*/
2020-03-26 23:02:15 +00:00
[Fact]
public async Task MegaDownload()
2019-10-12 18:03:45 +00:00
{
var ini = @"[General]
directURL=https://mega.nz/#!CsMSFaaJ!-uziC4mbJPRy2e4pPk8Gjb3oDT_38Be9fzZ6Ld4NL-k";
2019-12-13 13:02:58 +00:00
var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
2019-10-12 18:03:45 +00:00
2020-03-26 23:02:15 +00:00
Assert.NotNull(state);
2019-10-12 18:03:45 +00:00
var url_state = DownloadDispatcher.ResolveArchive(
"https://mega.nz/#!CsMSFaaJ!-uziC4mbJPRy2e4pPk8Gjb3oDT_38Be9fzZ6Ld4NL-k");
2020-03-26 23:02:15 +00:00
Assert.Equal("https://mega.nz/#!CsMSFaaJ!-uziC4mbJPRy2e4pPk8Gjb3oDT_38Be9fzZ6Ld4NL-k",
((MegaDownloader.State)url_state).Url);
2020-03-26 23:02:15 +00:00
var converted = RoundTripState(state);
2020-04-10 01:29:53 +00:00
Assert.True(await converted.Verify(new Archive(state: null!){Size = 20}));
await using var filename = new TempFile();
2019-10-12 18:03:45 +00:00
2020-03-26 23:02:15 +00:00
Assert.True(converted.IsWhitelisted(new ServerWhitelist {AllowedPrefixes = new List<string>{"https://mega.nz/#!CsMSFaaJ!-uziC4mbJPRy2e4pPk8Gjb3oDT_38Be9fzZ6Ld4NL-k" } }));
Assert.False(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>{ "blerg" }}));
2019-10-12 18:03:45 +00:00
2020-04-10 01:29:53 +00:00
await converted.Download(new Archive(state: null!) {Name = "MEGA Test.txt"}, filename.Path);
2019-10-12 18:03:45 +00:00
2020-03-26 23:02:15 +00:00
Assert.Equal(Hash.FromBase64("eSIyd+KOG3s="), await filename.Path.FileHashAsync());
2019-10-12 18:03:45 +00:00
2020-03-26 23:02:15 +00:00
Assert.Equal("Cheese for Everyone!", await filename.Path.ReadAllTextAsync());
2019-10-12 18:03:45 +00:00
}
2020-03-26 23:02:15 +00:00
[Fact]
public async Task DropboxTests()
{
var ini = @"[General]
directURL=https://www.dropbox.com/s/5hov3m2pboppoc2/WABBAJACK_TEST_FILE.txt?dl=0";
2019-12-13 13:02:58 +00:00
var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
2020-03-26 23:02:15 +00:00
Assert.NotNull(state);
var url_state = DownloadDispatcher.ResolveArchive(
"https://www.dropbox.com/s/5hov3m2pboppoc2/WABBAJACK_TEST_FILE.txt?dl=0");
2020-03-26 23:02:15 +00:00
Assert.Equal("https://www.dropbox.com/s/5hov3m2pboppoc2/WABBAJACK_TEST_FILE.txt?dl=1",
((HTTPDownloader.State)url_state).Url);
2020-03-26 23:02:15 +00:00
var converted = RoundTripState(state);
2020-04-10 01:29:53 +00:00
Assert.True(await converted.Verify(new Archive(state: null!){Size = 20}));
await using var filename = new TempFile();
2020-03-26 23:02:15 +00:00
Assert.True(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string> { "https://www.dropbox.com/s/5hov3m2pboppoc2/WABBAJACK_TEST_FILE.txt?" } }));
Assert.False(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string> { "blerg" } }));
2020-04-10 01:29:53 +00:00
await converted.Download(new Archive(state: null!) { Name = "MEGA Test.txt" }, filename.Path);
2020-03-26 23:02:15 +00:00
Assert.Equal(Hash.FromBase64("eSIyd+KOG3s="), await filename.Path.FileHashAsync());
2020-03-26 23:02:15 +00:00
Assert.Equal("Cheese for Everyone!", await filename.Path.ReadAllTextAsync());
var newState = (AbstractDownloadState)new GoogleDriveDownloader.State("1Q_CdeYJStfoTZFLZ79RRVkxI2c_cG0dg");
Assert.True(await newState.Verify(new Archive(newState) {Size = 0}));
}
2020-03-26 23:02:15 +00:00
[Fact]
public async Task GoogleDriveTests()
{
var ini = @"[General]
directURL=https://drive.google.com/file/d/1grLRTrpHxlg7VPxATTFNfq2OkU_Plvh_/view?usp=sharing";
2019-12-13 13:02:58 +00:00
var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
2020-03-26 23:02:15 +00:00
Assert.NotNull(state);
var url_state = DownloadDispatcher.ResolveArchive(
"https://drive.google.com/file/d/1grLRTrpHxlg7VPxATTFNfq2OkU_Plvh_/view?usp=sharing");
2020-03-26 23:02:15 +00:00
Assert.Equal("1grLRTrpHxlg7VPxATTFNfq2OkU_Plvh_",
((GoogleDriveDownloader.State)url_state).Id);
2020-03-26 23:02:15 +00:00
var converted = RoundTripState(state);
2020-04-10 01:29:53 +00:00
Assert.True(await converted.Verify(new Archive(state: null!) { Size = 20}));
await using var filename = new TempFile();
2020-03-26 23:02:15 +00:00
Assert.True(converted.IsWhitelisted(new ServerWhitelist { GoogleIDs = new List<string> { "1grLRTrpHxlg7VPxATTFNfq2OkU_Plvh_" } }));
Assert.False(converted.IsWhitelisted(new ServerWhitelist { GoogleIDs = new List<string>()}));
2020-04-10 01:29:53 +00:00
await converted.Download(new Archive(state: null!) { Name = "MEGA Test.txt" }, filename.Path);
2020-03-26 23:02:15 +00:00
Assert.Equal(Hash.FromBase64("eSIyd+KOG3s="), await filename.Path.FileHashAsync());
2020-03-26 23:02:15 +00:00
Assert.Equal("Cheese for Everyone!", await filename.Path.ReadAllTextAsync());
}
2020-03-26 23:02:15 +00:00
[Fact]
public async Task HttpDownload()
{
var ini = @"[General]
directURL=http://build.wabbajack.org/WABBAJACK_TEST_FILE.txt";
2019-12-13 13:02:58 +00:00
var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
2020-03-26 23:02:15 +00:00
Assert.NotNull(state);
var url_state = DownloadDispatcher.ResolveArchive("http://build.wabbajack.org/WABBAJACK_TEST_FILE.txt");
2020-03-26 23:02:15 +00:00
Assert.Equal("http://build.wabbajack.org/WABBAJACK_TEST_FILE.txt",
((HTTPDownloader.State)url_state).Url);
2020-03-26 23:02:15 +00:00
var converted = RoundTripState(state);
2020-04-10 01:29:53 +00:00
Assert.True(await converted.Verify(new Archive(state: null!) { Size = 20}));
await using var filename = new TempFile();
2020-03-26 23:02:15 +00:00
Assert.True(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string> { "http://build.wabbajack.org/" } }));
Assert.False(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>() }));
2020-04-10 01:29:53 +00:00
await converted.Download(new Archive(state: null!) { Name = "MEGA Test.txt" }, filename.Path);
2020-03-26 23:02:15 +00:00
Assert.Equal(Hash.FromBase64("eSIyd+KOG3s="), await filename.Path.FileHashAsync());
2020-03-26 23:02:15 +00:00
Assert.Equal("Cheese for Everyone!", await filename.Path.ReadAllTextAsync());
}
2020-03-26 23:02:15 +00:00
[Fact]
public async Task ManualDownload()
{
var ini = @"[General]
manualURL=http://build.wabbajack.org/WABBAJACK_TEST_FILE.zip";
2019-12-13 13:02:58 +00:00
var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
2020-03-26 23:02:15 +00:00
Assert.NotNull(state);
2020-03-26 23:02:15 +00:00
var converted = RoundTripState(state);
2020-04-10 01:29:53 +00:00
Assert.True(await converted.Verify(new Archive(state: null!) { Size = 20}));
await using var filename = new TempFile();
2020-03-26 23:02:15 +00:00
Assert.True(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string> { "http://build.wabbajack.org/" } }));
2019-12-13 13:24:17 +00:00
// Doesn't work well on the test server, so we're disabling for now
2020-03-26 23:02:15 +00:00
//await converted.Download(new Archive { Name = "WABBAJACK_TEST_FILE.zip", Size = 20, Hash = "eSIyd+KOG3s="}, filename.Path);
//Assert.Equal("eSIyd+KOG3s=", Utils.FileHash(filename.Path));
//Assert.Equal(File.ReadAllText(filename.Path), "Cheese for Everyone!");
}
2020-04-22 23:11:32 +00:00
2020-03-26 23:02:15 +00:00
[Fact]
public async Task MediaFireDownload()
{
var ini = @"[General]
directURL=http://www.mediafire.com/file/agiqzm1xwebczpx/WABBAJACK_TEST_FILE.txt";
2019-12-13 13:02:58 +00:00
var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
2020-03-26 23:02:15 +00:00
Assert.NotNull(state);
var url_state = DownloadDispatcher.ResolveArchive(
"http://www.mediafire.com/file/agiqzm1xwebczpx/WABBAJACK_TEST_FILE.txt");
2020-03-26 23:02:15 +00:00
Assert.Equal("http://www.mediafire.com/file/agiqzm1xwebczpx/WABBAJACK_TEST_FILE.txt",
((MediaFireDownloader.State) url_state).Url);
2020-03-26 23:02:15 +00:00
var converted = RoundTripState(state);
2020-04-22 23:11:32 +00:00
Assert.True(await converted.Verify(new Archive(state: null!) { Size = 20 }));
await using var filename = new TempFile();
2020-03-26 23:02:15 +00:00
Assert.True(converted.IsWhitelisted(new ServerWhitelist
{AllowedPrefixes = new List<string> {"http://www.mediafire.com/file/agiqzm1xwebczpx/"}}));
2020-03-26 23:02:15 +00:00
Assert.False(converted.IsWhitelisted(new ServerWhitelist {AllowedPrefixes = new List<string>()}));
2020-04-22 23:11:32 +00:00
await converted.Download(new Archive(state: null!) { Name = "Media Fire Test.zip" }, filename.Path);
2020-04-22 23:11:32 +00:00
Assert.Equal("Cheese for Everyone!", await filename.Path.ReadAllTextAsync());
2020-04-22 23:11:32 +00:00
}
2020-03-26 23:02:15 +00:00
[Fact]
public async Task NexusDownload()
{
2020-04-10 01:29:53 +00:00
var ini = @"[General]
gameName=SkyrimSE
modID = 12604
fileID=35407";
2020-04-10 01:29:53 +00:00
var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
2021-01-06 21:30:25 +00:00
await DownloadDispatcher.PrepareAll(new[] {state});
2020-04-10 01:29:53 +00:00
Assert.NotNull(state);
2020-04-10 01:29:53 +00:00
var converted = RoundTripState(state);
Assert.True(await converted.Verify(new Archive(state: null!) { Size = 20 }));
// Exercise the cache code
Assert.True(await converted.Verify(new Archive(state: null!) { Size = 20 }));
await using var filename = new TempFile();
2020-04-10 01:29:53 +00:00
Assert.True(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>() }));
2020-04-10 01:29:53 +00:00
await converted.Download(new Archive(state: null!) { Name = "SkyUI.7z" }, filename.Path);
2020-04-10 01:29:53 +00:00
Assert.Equal(Hash.FromBase64("dF2yafV2Oks="), await filename.Path.FileHashAsync());
// Verify that we can see a older file
var data = await (await NexusApiClient.Get()).GetModFile(Game.SkyrimSpecialEdition, 45221, 185392, useCache:false);
Assert.Equal("Smooth Combat - Non Combat Animation System 2.3", data.name);
}
2019-10-12 22:31:07 +00:00
2020-03-26 23:02:15 +00:00
[Fact]
public async Task ModDbTests()
2019-10-12 22:31:07 +00:00
{
var ini = @"[General]
directURL=https://www.moddb.com/downloads/start/124908?referer=https%3A%2F%2Fwww.moddb.com%2Fmods%2Fautopause";
2019-12-13 13:02:58 +00:00
var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
2019-10-12 22:31:07 +00:00
2020-03-26 23:02:15 +00:00
Assert.NotNull(state);
2019-10-12 22:31:07 +00:00
var url_state = DownloadDispatcher.ResolveArchive(
"https://www.moddb.com/downloads/start/124908?referer=https%3A%2F%2Fwww.moddb.com%2Fmods%2Fautopause");
2020-03-26 23:02:15 +00:00
Assert.Equal("https://www.moddb.com/downloads/start/124908?referer=https%3A%2F%2Fwww.moddb.com%2Fmods%2Fautopause",
((ModDBDownloader.State)url_state).Url);
2020-03-26 23:02:15 +00:00
var converted = RoundTripState(state);
2020-04-10 01:29:53 +00:00
Assert.True(await converted.Verify(new Archive(state: null!) { Size = 20}));
await using var filename = new TempFile();
2019-10-12 22:31:07 +00:00
2020-03-26 23:02:15 +00:00
Assert.True(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>() }));
2019-10-12 22:31:07 +00:00
2020-04-10 01:29:53 +00:00
await converted.Download(new Archive(state: null!) { Name = "moddbtest.7z" }, filename.Path);
2019-10-12 22:31:07 +00:00
2020-03-26 23:02:15 +00:00
Assert.Equal(Hash.FromBase64("2lZt+1h6wxM="), await filename.Path.FileHashAsync());
2019-10-12 22:31:07 +00:00
}
2019-12-08 17:00:22 +00:00
2021-06-19 04:05:58 +00:00
[Fact]
public async Task CanFindOtherLLMods()
{
var downloader = DownloadDispatcher.GetInstance<LoversLabOAuthDownloader>();
await downloader.Prepare();
var ini = @"[General]
2021-06-19 04:05:58 +00:00
ips4Site=Lovers Lab
ips4Mod=11116
ips4File=ffooo.zip";
var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
2021-06-19 04:05:58 +00:00
var otherfiles = await ((LoversLabOAuthDownloader.State)state).GetFilesInGroup();
// Throws a NPE
var data = await downloader.GetDownloads(9023);
}
2021-06-19 04:05:58 +00:00
2020-12-31 17:51:24 +00:00
[Fact]
public async Task CanGetLLMetadata()
{
2021-06-19 04:05:58 +00:00
await DownloadDispatcher.GetInstance<LoversLabOAuthDownloader>().Prepare();
2020-12-31 17:51:24 +00:00
var ini = @"[General]
2021-06-19 04:05:58 +00:00
ips4Site=Lovers Lab
ips4Mod=11116
ips4File=WABBAJACK_TEST_FILE.zip";
2020-12-31 17:51:24 +00:00
2021-06-19 04:05:58 +00:00
var state = (LoversLabOAuthDownloader.State)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
2020-12-31 17:51:24 +00:00
Assert.True(await state.LoadMetaData());
Assert.Equal("halgari", state.Author);
}
2021-06-19 04:05:58 +00:00
2020-03-26 23:02:15 +00:00
[Fact]
public async Task LoversLabDownload()
2019-12-08 17:00:22 +00:00
{
2020-12-29 23:15:47 +00:00
2021-06-19 04:05:58 +00:00
await DownloadDispatcher.GetInstance<LoversLabOAuthDownloader>().Prepare();
2019-12-08 17:00:22 +00:00
var ini = @"[General]
2021-06-19 04:05:58 +00:00
ips4Site=Lovers Lab
ips4Mod=11116
ips4File=WABBAJACK_TEST_FILE.zip";
2019-12-08 17:00:22 +00:00
2019-12-13 13:02:58 +00:00
var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
2019-12-08 17:00:22 +00:00
2020-03-26 23:02:15 +00:00
Assert.NotNull(state);
2019-12-08 17:00:22 +00:00
2020-03-26 23:02:15 +00:00
var converted = RoundTripState(state);
2020-04-10 01:29:53 +00:00
Assert.True(await converted.Verify(new Archive(state: null!) { Size = 20}));
2019-12-08 17:00:22 +00:00
2020-04-24 01:58:18 +00:00
// Verify with different Size
Assert.False(await converted.Verify(new Archive(state: null!) { Size = 15}));
await using var filename = new TempFile();
2020-03-26 23:02:15 +00:00
Assert.True(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>() }));
2019-12-08 17:00:22 +00:00
2020-04-10 01:29:53 +00:00
await converted.Download(new Archive(state: null!) { Name = "LoversLab Test.txt" }, filename.Path);
2019-12-08 17:00:22 +00:00
2020-03-26 23:02:15 +00:00
Assert.Equal(Hash.FromBase64("eSIyd+KOG3s="), await filename.Path.FileHashAsync());
2019-12-08 17:00:22 +00:00
2020-03-26 23:02:15 +00:00
Assert.Equal("Cheese for Everyone!", await filename.Path.ReadAllTextAsync());
2020-08-12 22:23:02 +00:00
}
2021-06-27 14:05:45 +00:00
[Fact]
public async Task LoversLabAttachmentDownload()
{
await DownloadDispatcher.GetInstance<LoversLabOAuthDownloader>().Prepare();
var ini = @"[General]
ips4Site=Lovers Lab
ips4Attachment=853295";
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 = 1363396}));
// Verify with different Size
Assert.False(await converted.Verify(new Archive(state: null!) { Size = 15}));
await using var filename = new TempFile();
Assert.True(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>() }));
await converted.Download(new Archive(state: null!) { Name = "LoversLab Test.txt" }, filename.Path);
Assert.Equal(Hash.FromBase64("gLJDxGDaeQ0="), await filename.Path.FileHashAsync());
Assert.False(await ((LoversLabOAuthDownloader.State) state).LoadMetaData());
2021-06-27 14:05:45 +00:00
}
[Fact]
public async Task CanLoadOldLLMeta()
{
var state = (DeprecatedLoversLabDownloader.State)(AbsolutePath.EntryPoint.Combine(@"Resources\LoversLabState.json").FromJson<Archive>().State);
2021-06-19 22:42:24 +00:00
Assert.Equal("DeprecatedLoversLabDownloader+State|", state.PrimaryKeyString);
}
2021-06-19 04:05:58 +00:00
2020-03-26 23:02:15 +00:00
[Fact]
public async Task VectorPlexusDownload()
{
await DownloadDispatcher.GetInstance<VectorPlexusOAuthDownloader>().Prepare();
var ini = @"[General]
ips4Site=Vector Plexus
ips4Mod=290
ips4File=WABBAJACK_TEST_FILE.zip";
var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
2020-03-26 23:02:15 +00:00
Assert.NotNull(state);
2020-03-26 23:02:15 +00:00
var converted = RoundTripState(state);
2020-04-10 01:29:53 +00:00
Assert.True(await converted.Verify(new Archive(state: null!) { Size = 20}));
await using var filename = new TempFile();
2020-03-26 23:02:15 +00:00
Assert.True(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>() }));
var archive = new Archive(state: null!) {Name = "Vector Plexus Test.zip"};
await converted.Download(archive, filename.Path);
2020-03-26 23:02:15 +00:00
Assert.Equal(Hash.FromBase64("eSIyd+KOG3s="), await filename.Path.FileHashAsync());
2020-03-26 23:02:15 +00:00
Assert.Equal("Cheese for Everyone!", await filename.Path.ReadAllTextAsync());
Assert.True(converted is VectorPlexusOAuthDownloader.State);
var st = (VectorPlexusOAuthDownloader.State)converted;
Assert.True(await st.LoadMetaData());
Assert.Equal("halgari", st.Author);
Assert.Equal("Wabbajack Test File", st.Name);
Assert.True(st.IsNSFW);
Assert.Equal("1.0.0", st.Version);
Assert.Equal("https://vectorplexus.com/files/file/290-wabbajack-test-file/", st.GetManifestURL(archive));
Assert.True(st.ImageURL != null);
2020-08-12 22:23:02 +00:00
}
2020-05-28 22:31:01 +00:00
[Fact]
public async Task YandexDownloader()
{
await DownloadDispatcher.GetInstance<YandexDownloader>().Prepare();
var ini = @"[General]
directURL=https://yadi.sk/d/jqwQT4ByYtC9Tw";
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<string>() {"https://yadi.sk"} }));
await converted.Download(new Archive(state: null!) { Name = "WABBAJACK_TEST_FILE.txt" }, filename.Path);
Assert.Equal(Hash.FromBase64("eSIyd+KOG3s="), await filename.Path.FileHashAsync());
Assert.Equal("Cheese for Everyone!", await filename.Path.ReadAllTextAsync());
}
2021-07-11 23:54:49 +00:00
2020-03-26 23:02:15 +00:00
[Fact]
2020-01-27 13:40:47 +00:00
public async Task TESAllianceDownload()
{
await DownloadDispatcher.GetInstance<TESAllianceDownloader>().Prepare();
const string ini = "[General]\n" +
"directURL=http://tesalliance.org/forums/index.php?/files/file/2035-wabbajack-test-file/";
var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
2020-03-26 23:02:15 +00:00
Assert.NotNull(state);
2020-01-27 13:40:47 +00:00
2020-03-26 23:02:15 +00:00
var converted = RoundTripState(state);
2020-04-10 01:29:53 +00:00
Assert.True(await converted.Verify(new Archive(state: null!) { Size = 20}));
await using var filename = new TempFile();
2020-01-27 13:40:47 +00:00
2020-03-26 23:02:15 +00:00
Assert.True(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>() }));
2020-01-27 13:40:47 +00:00
2020-04-10 01:29:53 +00:00
await converted.Download(new Archive(state: null!) { Name = "TESAlliance Test.zip" }, filename.Path);
2020-01-27 13:40:47 +00:00
2020-03-26 23:02:15 +00:00
Assert.Equal(Hash.FromBase64("eSIyd+KOG3s="), await filename.Path.FileHashAsync());
2020-01-27 13:40:47 +00:00
2020-03-26 23:02:15 +00:00
Assert.Equal("Cheese for Everyone!", await filename.Path.ReadAllTextAsync());
2020-01-27 16:29:10 +00:00
}
2021-07-11 23:54:49 +00:00
/* Site is broken again
2020-05-28 23:44:58 +00:00
[Fact]
public async Task TESAllDownloader()
{
await DownloadDispatcher.GetInstance<TESAllDownloader>().Prepare();
const string ini = "[General]\n" +
2020-12-16 00:09:59 +00:00
"directURL=https://tesall.ru/files/download/594545";
2020-05-28 23:44:58 +00:00
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<string>() }));
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());
2021-07-11 23:54:49 +00:00
}*/
2020-01-27 13:40:47 +00:00
/* WAITING FOR APPROVAL BY MODERATOR
2020-03-26 23:02:15 +00:00
[Fact]
2020-01-27 13:31:22 +00:00
public async Task DeadlyStreamDownloader()
{
await DownloadDispatcher.GetInstance<DeadlyStreamDownloader>().Prepare();
const string ini = "[General]\n" +
"directURL=https://deadlystream.com/files/file/1550-wabbajack-test-file/";
var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
2020-03-26 23:02:15 +00:00
Assert.NotNull(state);
2020-01-27 13:31:22 +00:00
2020-03-26 23:02:15 +00:00
var converted = RoundTripState(state);
Assert.True(await converted.Verify(new Archive{Size = 20}));
using var filename = new TempFile();
2020-01-27 13:31:22 +00:00
2020-03-26 23:02:15 +00:00
Assert.True(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>() }));
2020-01-27 13:31:22 +00:00
2020-03-26 23:02:15 +00:00
await converted.Download(new Archive { Name = "DeadlyStream Test.zip" }, filename.Path);
2020-01-27 13:31:22 +00:00
2020-03-26 23:02:15 +00:00
Assert.Equal("eSIyd+KOG3s=", filename.FileHash());
2020-01-27 13:31:22 +00:00
2020-03-26 23:02:15 +00:00
Assert.Equal(File.ReadAllText(filename.Path), "Cheese for Everyone!");
2020-01-27 13:31:22 +00:00
}*/
2020-03-26 23:02:15 +00:00
[Fact]
public async Task GameFileSourceDownload()
{
2019-12-26 18:21:57 +00:00
// Test mode off for this test
Consts.TestMode = false;
var ini = $@"[General]
gameName={Game.SkyrimSpecialEdition.MetaData().MO2ArchiveName}
gameFile=Data/Update.esm";
2019-12-13 13:02:58 +00:00
var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
2020-03-26 23:02:15 +00:00
Assert.NotNull(state);
2019-12-08 17:00:22 +00:00
2020-03-26 23:02:15 +00:00
var converted = RoundTripState(state);
2020-04-10 01:29:53 +00:00
Assert.True(await converted.Verify(new Archive(state: null!) { Size = 20}));
await using var filename = new TempFile();
2020-03-26 23:02:15 +00:00
Assert.True(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>() }));
2020-04-10 01:29:53 +00:00
await converted.Download(new Archive(state: null!) { Name = "Update.esm" }, filename.Path);
Assert.Equal(Hash.FromBase64("/DLG/LjdGXI="), await filename.Path.FileHashAsync());
Assert.Equal(await filename.Path.ReadAllBytesAsync(), await Game.SkyrimSpecialEdition.MetaData().GameLocation().Combine("Data/Update.esm").ReadAllBytesAsync());
2019-12-26 18:21:57 +00:00
Consts.TestMode = true;
2019-12-08 17:00:22 +00:00
}
2020-01-29 00:09:09 +00:00
/// <summary>
/// Tests that files from different sources don't overwrite eachother when downloaded by AInstaller
/// </summary>
/// <returns></returns>
2020-03-26 23:02:15 +00:00
[Fact]
public async Task DownloadRenamingTests()
{
// Test mode off for this test
Consts.TestMode = false;
var inia = $@"[General]
gameName={Game.SkyrimSpecialEdition.MetaData().MO2ArchiveName}
gameFile=Data/Update.esm";
var statea = (GameFileSourceDownloader.State)await DownloadDispatcher.ResolveArchive(inia.LoadIniString());
var inib = $@"[General]
gameName={Game.SkyrimSpecialEdition.MetaData().MO2ArchiveName}
gameFile=Data/Skyrim.esm";
var stateb = (GameFileSourceDownloader.State)await DownloadDispatcher.ResolveArchive(inib.LoadIniString());
var archivesa = new List<Archive>()
{
2020-04-10 01:29:53 +00:00
new Archive(statea) {Hash = statea.Hash, Name = "Download.esm" }
};
var archivesb = new List<Archive>()
{
2020-04-10 01:29:53 +00:00
new Archive(stateb) {Hash = stateb.Hash, Name = "Download.esm" }
};
2020-03-26 23:02:15 +00:00
var folder = ((RelativePath)"DownloadTests").RelativeToEntryPoint();
2020-03-28 04:33:26 +00:00
await folder.DeleteDirectory();
2020-03-26 23:02:15 +00:00
folder.CreateDirectory();
var inst = new TestInstaller(default, new ModList {GameType = Game.SkyrimSpecialEdition}, default, folder, null);
await inst.DownloadMissingArchives(archivesa, true);
await inst.DownloadMissingArchives(archivesb, true);
2020-04-03 03:57:59 +00:00
Assert.Equal(new[]
{
2020-03-26 23:02:15 +00:00
(RelativePath)@"Download.esm",
2021-01-13 00:31:43 +00:00
(RelativePath)@"Download_c4047f2251d8eead22df4b4888cc4b833ae7d9a6766ff29128e083d944f9ec4b_.esm",
2020-04-03 03:57:59 +00:00
}.OrderBy(a => a).ToArray(),
folder.EnumerateFiles().Select(f => f.FileName).OrderBy(a => a).ToArray());
Consts.TestMode = true;
}
2020-03-26 23:02:15 +00:00
private T RoundTripState<T>(T state)
{
return state.ToJson().FromJsonString<T>();
2020-03-26 23:02:15 +00:00
}
/* TODO : Disabled for now
2020-03-26 23:02:15 +00:00
[Fact]
public async Task TestUpgrading()
{
await using var folder = await TempFolder.Create();
2020-03-26 23:02:15 +00:00
var dest = folder.Dir.Combine("Cori.7z");
2020-04-10 01:29:53 +00:00
var archive = new Archive(
new NexusDownloader.State
{
Game = Game.SkyrimSpecialEdition,
2020-04-03 03:57:59 +00:00
ModID = 24808,
FileID = 123501
2020-04-10 01:29:53 +00:00
})
{
Name = "Cori.7z",
Hash = Hash.FromBase64("gCRVrvzDNH0="),
};
Utils.Log($"Getting Hash for {(long)archive.Hash}");
2020-03-26 23:02:15 +00:00
Assert.True(await DownloadDispatcher.DownloadWithPossibleUpgrade(archive, dest));
Assert.Equal(Hash.FromBase64("gCRVrvzDNH0="), await dest.FileHashCachedAsync());
}*/
class TestInstaller : AInstaller
{
public TestInstaller(AbsolutePath archive, ModList modList, AbsolutePath outputFolder, AbsolutePath downloadFolder, SystemParameters parameters)
: base(archive, modList, outputFolder, downloadFolder, parameters, steps: 1, modList.GameType)
{
2020-09-12 20:23:03 +00:00
DesiredThreads.OnNext(1);
}
protected override Task<bool> _Begin(CancellationToken cancel)
{
throw new NotImplementedException();
}
public override ModManager ModManager { get => ModManager.MO2; }
}
2019-10-12 18:03:45 +00:00
}
}