wabbajack/Wabbajack.Test/DownloaderTests.cs

563 lines
24 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;
2019-12-07 17:39:22 +00:00
using Wabbajack.Lib.LibCefHelpers;
using Wabbajack.Lib.NexusApi;
using Wabbajack.Lib.Validation;
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
[Fact]
2020-04-10 19:06:32 +00:00
public async Task TestAllPrepares()
{
foreach (var downloader in DownloadDispatcher.Downloaders)
await downloader.Prepare();
}
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}));
2020-03-26 23:02:15 +00:00
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}));
2020-03-26 23:02:15 +00:00
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());
}
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}));
2020-03-26 23:02:15 +00:00
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}));
2020-03-26 23:02:15 +00:00
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}));
2020-03-26 23:02:15 +00:00
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 }));
2020-03-26 23:02:15 +00:00
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());
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 }));
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());
}
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}));
2020-03-26 23:02:15 +00:00
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
2020-03-26 23:02:15 +00:00
[Fact]
public async Task LoversLabDownload()
2019-12-08 17:00:22 +00:00
{
await DownloadDispatcher.GetInstance<LoversLabDownloader>().Prepare();
2019-12-08 17:00:22 +00:00
var ini = @"[General]
directURL=https://www.loverslab.com/files/file/11116-test-file-for-wabbajack-integration/?do=download&r=737123&confirm=1&t=1";
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
/*var url_state = DownloadDispatcher.ResolveArchive("https://www.loverslab.com/files/file/11116-test-file-for-wabbajack-integration/?do=download&r=737123&confirm=1&t=1");
2020-03-26 23:02:15 +00:00
Assert.Equal("http://build.wabbajack.org/WABBAJACK_TEST_FILE.txt",
2019-12-08 17:00:22 +00:00
((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}));
2020-03-26 23:02:15 +00:00
using var filename = new TempFile();
2019-12-08 17:00:22 +00:00
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-03-26 23:02:15 +00:00
[Fact]
public async Task VectorPlexusDownload()
{
await DownloadDispatcher.GetInstance<VectorPlexusDownloader>().Prepare();
var ini = @"[General]
directURL=https://vectorplexus.com/files/file/290-wabbajack-test-file";
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.loverslab.com/files/file/11116-test-file-for-wabbajack-integration/?do=download&r=737123&confirm=1&t=1");
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}));
2020-03-26 23:02:15 +00:00
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 = "Vector Plexus Test.zip" }, 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-01-27 16:29:10 +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}));
2020-03-26 23:02:15 +00:00
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
}
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;
await DownloadDispatcher.GetInstance<LoversLabDownloader>().Prepare();
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}));
2020-03-26 23:02:15 +00:00
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);
2020-03-29 20:42:45 +00:00
Assert.Equal(Hash.FromBase64("/DLG/LjdGXI="), await Utils.FileHashAsync(filename.Path));
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
2020-03-26 23:02:15 +00:00
[Fact]
2020-01-29 00:09:09 +00:00
public async Task BethesdaNetDownload()
{
var downloader = DownloadDispatcher.GetInstance<BethesdaNetDownloader>();
2020-03-26 23:02:15 +00:00
Assert.True(await downloader.IsLoggedIn.FirstAsync());
2020-01-29 00:09:09 +00:00
var ini = $@"[General]
directURL=https://bethesda.net/en/mods/skyrim/mod-detail/4145641";
2020-01-29 00:09:09 +00:00
2020-03-26 23:02:15 +00:00
using var filename = new TempFile();
2020-01-29 00:09:09 +00:00
var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
2020-03-26 23:02:15 +00:00
Assert.NotNull(state);
2020-01-29 00:09:09 +00:00
var converted = state.ViaJSON();
2020-04-10 01:29:53 +00:00
Assert.True(await converted.Verify(new Archive(state: null!) { Name = "mod.ckm"}));
2020-01-29 00:09:09 +00:00
2020-03-26 23:02:15 +00:00
Assert.True(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>() }));
2020-01-29 00:09:09 +00:00
2020-04-10 01:29:53 +00:00
await converted.Download(new Archive(state: null!) { Name = "mod.zip" }, filename.Path);
2020-03-26 23:02:15 +00:00
await using var fs = filename.Path.OpenRead();
using var archive = new ZipArchive(fs);
var entries = archive.Entries.Select(e => e.FullName).ToList();
2020-03-26 23:02:15 +00:00
Assert.Equal(entries, new List<string> {@"Data\TestCK.esp", @"Data\TestCK.ini"});
2020-01-29 00:09:09 +00:00
}
2020-03-26 23:02:15 +00:00
[Fact]
public async Task YoutubeDownloader()
{
var infered_ini = await DownloadDispatcher.Infer(new Uri("https://www.youtube.com/watch?v=4ceowgHn8BE"));
2020-03-26 23:02:15 +00:00
Assert.IsAssignableFrom<YouTubeDownloader.State>(infered_ini);
Assert.Equal(15, ((YouTubeDownloader.State)infered_ini).Tracks.Count);
var ini = string.Join("\n", infered_ini.GetMetaIni());
var state = (YouTubeDownloader.State)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
2020-03-26 23:02:15 +00:00
Assert.Equal(15, state.Tracks.Count);
Assert.NotNull(state);
2020-03-27 03:10:23 +00:00
var converted = RoundTripState(state);
2020-04-10 01:29:53 +00:00
Assert.True(await converted.Verify(new Archive(state: null!) { Name = "yt_test.zip"}));
2020-03-26 23:02:15 +00:00
Assert.True(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>() }));
using var tempFile = new TempFile();
2020-04-10 01:29:53 +00:00
await converted.Download(new Archive(state: null!) { Name = "yt_test.zip"}, tempFile.Path);
2020-04-02 21:46:11 +00:00
Assert.Equal(Hash.FromBase64("kD36zbA2X9Q="), await tempFile.Path.FileHashAsync());
}
/// <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, null, 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",
(RelativePath)@"Download.esm.xxHash",
2020-04-03 03:57:59 +00:00
(RelativePath)@"Download_ed33cbb256e5328361da8d9227df9cab1bb43a79a87dca2f223b2e2762ccaad1_.esm",
(RelativePath)@"Download_ed33cbb256e5328361da8d9227df9cab1bb43a79a87dca2f223b2e2762ccaad1_.esm.xxHash"
}.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
}
[Fact]
public async Task TestUpgrading()
{
await using var folder = new TempFolder();
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="),
};
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)
{
Queue.SetActiveThreadsObservable(Observable.Return(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
}
}