2019-10-12 18:03:45 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-01-29 04:17:24 +00:00
|
|
|
|
using System.IO.Compression;
|
|
|
|
|
using System.Linq;
|
2019-12-06 05:29:17 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2019-12-08 17:00:22 +00:00
|
|
|
|
using System.Reactive.Linq;
|
2020-02-12 05:31:42 +00:00
|
|
|
|
using System.Reactive.Subjects;
|
|
|
|
|
using System.Threading;
|
2019-12-09 23:52:17 +00:00
|
|
|
|
using Alphaleonis.Win32.Filesystem;
|
2019-10-12 18:03:45 +00:00
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
using Wabbajack.Common;
|
2019-12-08 17:00:22 +00:00
|
|
|
|
using Wabbajack.Common.StatusFeed;
|
2019-10-16 03:10:34 +00:00
|
|
|
|
using Wabbajack.Lib;
|
|
|
|
|
using Wabbajack.Lib.Downloaders;
|
2019-12-07 17:39:22 +00:00
|
|
|
|
using Wabbajack.Lib.LibCefHelpers;
|
2019-11-05 05:08:47 +00:00
|
|
|
|
using Wabbajack.Lib.NexusApi;
|
2019-10-16 03:10:34 +00:00
|
|
|
|
using Wabbajack.Lib.Validation;
|
2020-02-12 05:31:42 +00:00
|
|
|
|
using Directory = System.IO.Directory;
|
2019-10-12 18:03:45 +00:00
|
|
|
|
using File = Alphaleonis.Win32.Filesystem.File;
|
2019-12-09 23:52:17 +00:00
|
|
|
|
using Game = Wabbajack.Common.Game;
|
2019-10-12 18:03:45 +00:00
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Test
|
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class DownloaderTests
|
|
|
|
|
{
|
2019-12-27 00:41:33 +00:00
|
|
|
|
static DownloaderTests()
|
|
|
|
|
{
|
|
|
|
|
Helpers.Init();
|
|
|
|
|
}
|
2019-12-08 17:00:22 +00:00
|
|
|
|
|
|
|
|
|
public TestContext TestContext { get; set; }
|
|
|
|
|
|
2019-11-05 05:08:47 +00:00
|
|
|
|
[TestInitialize]
|
2019-12-18 03:18:33 +00:00
|
|
|
|
public async Task Setup()
|
2019-11-05 05:08:47 +00:00
|
|
|
|
{
|
2019-12-27 00:41:33 +00:00
|
|
|
|
Helpers.Init();
|
2019-12-08 17:00:22 +00:00
|
|
|
|
Utils.LogMessages.OfType<IInfo>().Subscribe(onNext: msg => TestContext.WriteLine(msg.ShortDescription));
|
|
|
|
|
Utils.LogMessages.OfType<IUserIntervention>().Subscribe(msg =>
|
2020-01-13 21:11:07 +00:00
|
|
|
|
TestContext.WriteLine("ERROR: User intervention required: " + msg.ShortDescription));
|
2019-12-08 17:00:22 +00:00
|
|
|
|
|
2019-11-05 05:08:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-13 14:18:21 +00:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestAllPrepares()
|
|
|
|
|
{
|
|
|
|
|
DownloadDispatcher.Downloaders.Do(d => d.Prepare());
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-12 18:03:45 +00:00
|
|
|
|
[TestMethod]
|
2019-12-06 05:29:17 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(state);
|
|
|
|
|
|
2019-10-16 11:44:45 +00:00
|
|
|
|
var url_state = DownloadDispatcher.ResolveArchive(
|
|
|
|
|
"https://mega.nz/#!CsMSFaaJ!-uziC4mbJPRy2e4pPk8Gjb3oDT_38Be9fzZ6Ld4NL-k");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual("https://mega.nz/#!CsMSFaaJ!-uziC4mbJPRy2e4pPk8Gjb3oDT_38Be9fzZ6Ld4NL-k",
|
|
|
|
|
((MegaDownloader.State)url_state).Url);
|
|
|
|
|
|
|
|
|
|
|
2020-01-11 04:15:53 +00:00
|
|
|
|
var converted = await state.RoundTripState();
|
2020-01-13 22:55:55 +00:00
|
|
|
|
Assert.IsTrue(await converted.Verify(new Archive{Size = 20}));
|
2019-10-12 18:03:45 +00:00
|
|
|
|
var filename = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist {AllowedPrefixes = new List<string>{"https://mega.nz/#!CsMSFaaJ!-uziC4mbJPRy2e4pPk8Gjb3oDT_38Be9fzZ6Ld4NL-k" } }));
|
|
|
|
|
Assert.IsFalse(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>{ "blerg" }}));
|
|
|
|
|
|
2019-12-06 05:29:17 +00:00
|
|
|
|
await converted.Download(new Archive {Name = "MEGA Test.txt"}, filename);
|
2019-10-12 18:03:45 +00:00
|
|
|
|
|
2019-10-31 03:40:33 +00:00
|
|
|
|
Assert.AreEqual("eSIyd+KOG3s=", Utils.FileHash(filename));
|
2019-10-12 18:03:45 +00:00
|
|
|
|
|
|
|
|
|
Assert.AreEqual(File.ReadAllText(filename), "Cheese for Everyone!");
|
|
|
|
|
}
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2019-12-06 05:29:17 +00:00
|
|
|
|
public async Task DropboxTests()
|
2019-10-12 21:37:16 +00:00
|
|
|
|
{
|
|
|
|
|
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());
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(state);
|
|
|
|
|
|
2019-10-16 11:44:45 +00:00
|
|
|
|
var url_state = DownloadDispatcher.ResolveArchive(
|
|
|
|
|
"https://www.dropbox.com/s/5hov3m2pboppoc2/WABBAJACK_TEST_FILE.txt?dl=0");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual("https://www.dropbox.com/s/5hov3m2pboppoc2/WABBAJACK_TEST_FILE.txt?dl=1",
|
|
|
|
|
((HTTPDownloader.State)url_state).Url);
|
|
|
|
|
|
2020-01-11 04:15:53 +00:00
|
|
|
|
var converted = await state.RoundTripState();
|
2020-01-13 22:55:55 +00:00
|
|
|
|
Assert.IsTrue(await converted.Verify(new Archive{Size = 20}));
|
2019-10-12 21:37:16 +00:00
|
|
|
|
var filename = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string> { "https://www.dropbox.com/s/5hov3m2pboppoc2/WABBAJACK_TEST_FILE.txt?" } }));
|
|
|
|
|
Assert.IsFalse(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string> { "blerg" } }));
|
|
|
|
|
|
2019-12-06 05:29:17 +00:00
|
|
|
|
await converted.Download(new Archive { Name = "MEGA Test.txt" }, filename);
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
2019-10-31 03:40:33 +00:00
|
|
|
|
Assert.AreEqual("eSIyd+KOG3s=", Utils.FileHash(filename));
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
|
|
|
|
Assert.AreEqual(File.ReadAllText(filename), "Cheese for Everyone!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2019-12-06 05:29:17 +00:00
|
|
|
|
public async Task GoogleDriveTests()
|
2019-10-12 21:37:16 +00:00
|
|
|
|
{
|
|
|
|
|
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());
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(state);
|
|
|
|
|
|
2019-10-16 11:44:45 +00:00
|
|
|
|
var url_state = DownloadDispatcher.ResolveArchive(
|
|
|
|
|
"https://drive.google.com/file/d/1grLRTrpHxlg7VPxATTFNfq2OkU_Plvh_/view?usp=sharing");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual("1grLRTrpHxlg7VPxATTFNfq2OkU_Plvh_",
|
|
|
|
|
((GoogleDriveDownloader.State)url_state).Id);
|
|
|
|
|
|
2020-01-11 04:15:53 +00:00
|
|
|
|
var converted = await state.RoundTripState();
|
2020-01-13 22:55:55 +00:00
|
|
|
|
Assert.IsTrue(await converted.Verify(new Archive{Size = 20}));
|
2019-10-12 21:37:16 +00:00
|
|
|
|
var filename = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist { GoogleIDs = new List<string> { "1grLRTrpHxlg7VPxATTFNfq2OkU_Plvh_" } }));
|
|
|
|
|
Assert.IsFalse(converted.IsWhitelisted(new ServerWhitelist { GoogleIDs = new List<string>()}));
|
|
|
|
|
|
2019-12-06 05:29:17 +00:00
|
|
|
|
await converted.Download(new Archive { Name = "MEGA Test.txt" }, filename);
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
2019-10-31 03:40:33 +00:00
|
|
|
|
Assert.AreEqual("eSIyd+KOG3s=", Utils.FileHash(filename));
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
|
|
|
|
Assert.AreEqual(File.ReadAllText(filename), "Cheese for Everyone!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2019-12-06 05:29:17 +00:00
|
|
|
|
public async Task HttpDownload()
|
2019-10-12 21:37:16 +00:00
|
|
|
|
{
|
|
|
|
|
var ini = @"[General]
|
2019-10-24 01:19:11 +00:00
|
|
|
|
directURL=http://build.wabbajack.org/WABBAJACK_TEST_FILE.txt";
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
2019-12-13 13:02:58 +00:00
|
|
|
|
var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(state);
|
|
|
|
|
|
2019-10-24 01:19:11 +00:00
|
|
|
|
var url_state = DownloadDispatcher.ResolveArchive("http://build.wabbajack.org/WABBAJACK_TEST_FILE.txt");
|
2019-10-16 11:44:45 +00:00
|
|
|
|
|
2019-10-24 01:19:11 +00:00
|
|
|
|
Assert.AreEqual("http://build.wabbajack.org/WABBAJACK_TEST_FILE.txt",
|
2019-10-16 11:44:45 +00:00
|
|
|
|
((HTTPDownloader.State)url_state).Url);
|
|
|
|
|
|
2020-01-11 04:15:53 +00:00
|
|
|
|
var converted = await state.RoundTripState();
|
2020-01-13 22:55:55 +00:00
|
|
|
|
Assert.IsTrue(await converted.Verify(new Archive{Size = 20}));
|
2019-10-12 21:37:16 +00:00
|
|
|
|
var filename = Guid.NewGuid().ToString();
|
|
|
|
|
|
2019-10-24 01:19:11 +00:00
|
|
|
|
Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string> { "http://build.wabbajack.org/" } }));
|
|
|
|
|
Assert.IsFalse(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>() }));
|
|
|
|
|
|
2019-12-06 05:29:17 +00:00
|
|
|
|
await converted.Download(new Archive { Name = "MEGA Test.txt" }, filename);
|
2019-10-24 01:19:11 +00:00
|
|
|
|
|
2019-10-31 03:40:33 +00:00
|
|
|
|
Assert.AreEqual("eSIyd+KOG3s=", Utils.FileHash(filename));
|
2019-10-24 01:19:11 +00:00
|
|
|
|
|
|
|
|
|
Assert.AreEqual(File.ReadAllText(filename), "Cheese for Everyone!");
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-06 23:52:48 +00:00
|
|
|
|
[TestMethod]
|
2019-12-06 05:29:17 +00:00
|
|
|
|
public async Task ManualDownload()
|
2019-11-06 23:52:48 +00:00
|
|
|
|
{
|
|
|
|
|
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());
|
2019-11-06 23:52:48 +00:00
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(state);
|
|
|
|
|
|
2020-01-11 04:15:53 +00:00
|
|
|
|
var converted = await state.RoundTripState();
|
2020-01-13 22:55:55 +00:00
|
|
|
|
Assert.IsTrue(await converted.Verify(new Archive{Size = 20}));
|
2019-11-06 23:52:48 +00:00
|
|
|
|
var filename = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(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
|
|
|
|
|
//await converted.Download(new Archive { Name = "WABBAJACK_TEST_FILE.zip", Size = 20, Hash = "eSIyd+KOG3s="}, filename);
|
|
|
|
|
//Assert.AreEqual("eSIyd+KOG3s=", Utils.FileHash(filename));
|
|
|
|
|
//Assert.AreEqual(File.ReadAllText(filename), "Cheese for Everyone!");
|
2019-11-06 23:52:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-03 00:37:08 +00:00
|
|
|
|
/*
|
2019-10-24 01:19:11 +00:00
|
|
|
|
[TestMethod]
|
2019-12-06 05:29:17 +00:00
|
|
|
|
public async Task MediaFireDownload()
|
2019-10-24 01:19:11 +00:00
|
|
|
|
{
|
|
|
|
|
var ini = @"[General]
|
2019-11-05 05:08:47 +00:00
|
|
|
|
directURL=http://www.mediafire.com/file/agiqzm1xwebczpx/WABBAJACK_TEST_FILE.txt";
|
2019-10-24 01:19:11 +00:00
|
|
|
|
|
2019-12-13 13:02:58 +00:00
|
|
|
|
var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
|
2019-10-24 01:19:11 +00:00
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(state);
|
|
|
|
|
|
|
|
|
|
var url_state = DownloadDispatcher.ResolveArchive(
|
|
|
|
|
"http://www.mediafire.com/file/agiqzm1xwebczpx/WABBAJACK_TEST_FILE.txt");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual("http://www.mediafire.com/file/agiqzm1xwebczpx/WABBAJACK_TEST_FILE.txt",
|
2019-11-05 05:08:47 +00:00
|
|
|
|
((MediaFireDownloader.State) url_state).Url);
|
2019-10-24 01:19:11 +00:00
|
|
|
|
|
2020-01-11 04:15:53 +00:00
|
|
|
|
var converted = await state.RoundTripState();
|
2019-12-06 05:29:17 +00:00
|
|
|
|
Assert.IsTrue(await converted.Verify());
|
2019-10-24 01:19:11 +00:00
|
|
|
|
var filename = Guid.NewGuid().ToString();
|
|
|
|
|
|
2019-11-05 05:08:47 +00:00
|
|
|
|
Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist
|
|
|
|
|
{AllowedPrefixes = new List<string> {"http://www.mediafire.com/file/agiqzm1xwebczpx/"}}));
|
|
|
|
|
Assert.IsFalse(converted.IsWhitelisted(new ServerWhitelist {AllowedPrefixes = new List<string>()}));
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
2019-12-06 05:29:17 +00:00
|
|
|
|
await converted.Download(new Archive {Name = "Media Fire Test.txt"}, filename);
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
2019-10-24 01:19:11 +00:00
|
|
|
|
Assert.AreEqual(File.ReadAllText(filename), "Cheese for Everyone!");
|
2019-11-05 05:08:47 +00:00
|
|
|
|
|
2020-01-03 00:37:08 +00:00
|
|
|
|
}*/
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2019-12-06 05:29:17 +00:00
|
|
|
|
public async Task NexusDownload()
|
2019-10-12 21:37:16 +00:00
|
|
|
|
{
|
2020-01-01 16:19:06 +00:00
|
|
|
|
var old_val = NexusApiClient.CacheMethod;
|
2019-11-05 05:08:47 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2020-01-01 16:19:06 +00:00
|
|
|
|
NexusApiClient.CacheMethod = null;
|
2019-11-05 05:08:47 +00:00
|
|
|
|
var ini = @"[General]
|
2019-10-12 21:37:16 +00:00
|
|
|
|
gameName=SkyrimSE
|
|
|
|
|
modID = 12604
|
|
|
|
|
fileID=35407";
|
|
|
|
|
|
2019-12-13 13:02:58 +00:00
|
|
|
|
var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
2019-11-05 05:08:47 +00:00
|
|
|
|
Assert.IsNotNull(state);
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
2019-10-16 11:44:45 +00:00
|
|
|
|
|
2020-01-11 04:15:53 +00:00
|
|
|
|
var converted = await state.RoundTripState();
|
2020-01-13 22:55:55 +00:00
|
|
|
|
Assert.IsTrue(await converted.Verify(new Archive{Size = 20}));
|
2019-11-05 05:08:47 +00:00
|
|
|
|
// Exercise the cache code
|
2020-01-13 22:55:55 +00:00
|
|
|
|
Assert.IsTrue(await converted.Verify(new Archive{Size = 20}));
|
2019-11-05 05:08:47 +00:00
|
|
|
|
var filename = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string> () }));
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
2019-12-06 05:29:17 +00:00
|
|
|
|
await converted.Download(new Archive { Name = "SkyUI.7z" }, filename);
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
2019-11-05 05:08:47 +00:00
|
|
|
|
Assert.AreEqual(filename.FileHash(), "dF2yafV2Oks=");
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
2019-11-05 05:08:47 +00:00
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
2020-01-01 16:19:06 +00:00
|
|
|
|
NexusApiClient.CacheMethod = old_val;
|
2019-11-05 05:08:47 +00:00
|
|
|
|
}
|
2019-10-12 21:37:16 +00:00
|
|
|
|
}
|
2019-10-12 22:31:07 +00:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2019-12-06 05:29:17 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(state);
|
|
|
|
|
|
2019-10-16 11:44:45 +00:00
|
|
|
|
var url_state = DownloadDispatcher.ResolveArchive(
|
|
|
|
|
"https://www.moddb.com/downloads/start/124908?referer=https%3A%2F%2Fwww.moddb.com%2Fmods%2Fautopause");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual("https://www.moddb.com/downloads/start/124908?referer=https%3A%2F%2Fwww.moddb.com%2Fmods%2Fautopause",
|
|
|
|
|
((ModDBDownloader.State)url_state).Url);
|
|
|
|
|
|
2020-01-11 04:15:53 +00:00
|
|
|
|
var converted = await state.RoundTripState();
|
2020-01-13 22:55:55 +00:00
|
|
|
|
Assert.IsTrue(await converted.Verify(new Archive{Size = 20}));
|
2019-10-12 22:31:07 +00:00
|
|
|
|
var filename = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>() }));
|
|
|
|
|
|
2019-12-06 05:29:17 +00:00
|
|
|
|
await converted.Download(new Archive { Name = "moddbtest.7z" }, filename);
|
2019-10-12 22:31:07 +00:00
|
|
|
|
|
2019-10-31 03:40:33 +00:00
|
|
|
|
Assert.AreEqual("2lZt+1h6wxM=", filename.FileHash());
|
2019-10-12 22:31:07 +00:00
|
|
|
|
}
|
2019-12-08 17:00:22 +00:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2019-12-13 00:40:21 +00:00
|
|
|
|
public async Task LoversLabDownload()
|
2019-12-08 17:00:22 +00:00
|
|
|
|
{
|
2019-12-13 00:40:21 +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
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(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");
|
|
|
|
|
Assert.AreEqual("http://build.wabbajack.org/WABBAJACK_TEST_FILE.txt",
|
|
|
|
|
((HTTPDownloader.State)url_state).Url);
|
|
|
|
|
*/
|
2020-01-11 04:15:53 +00:00
|
|
|
|
var converted = await state.RoundTripState();
|
2020-01-13 22:55:55 +00:00
|
|
|
|
Assert.IsTrue(await converted.Verify(new Archive{Size = 20}));
|
2019-12-08 17:00:22 +00:00
|
|
|
|
var filename = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>() }));
|
|
|
|
|
|
2020-01-27 13:26:18 +00:00
|
|
|
|
await converted.Download(new Archive { Name = "LoversLab Test.txt" }, filename);
|
2019-12-08 17:00:22 +00:00
|
|
|
|
|
2020-01-27 13:32:20 +00:00
|
|
|
|
Assert.AreEqual("eSIyd+KOG3s=", filename.FileHash());
|
2019-12-08 17:00:22 +00:00
|
|
|
|
|
|
|
|
|
Assert.AreEqual(File.ReadAllText(filename), "Cheese for Everyone!");
|
2019-12-09 23:52:17 +00:00
|
|
|
|
}
|
2020-01-06 00:21:05 +00:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(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");
|
|
|
|
|
Assert.AreEqual("http://build.wabbajack.org/WABBAJACK_TEST_FILE.txt",
|
|
|
|
|
((HTTPDownloader.State)url_state).Url);
|
|
|
|
|
*/
|
2020-01-11 04:15:53 +00:00
|
|
|
|
var converted = await state.RoundTripState();
|
2020-01-13 22:55:55 +00:00
|
|
|
|
Assert.IsTrue(await converted.Verify(new Archive{Size = 20}));
|
2020-01-06 00:21:05 +00:00
|
|
|
|
var filename = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>() }));
|
|
|
|
|
|
|
|
|
|
await converted.Download(new Archive { Name = "Vector Plexus Test.zip" }, filename);
|
|
|
|
|
|
2020-01-27 13:32:20 +00:00
|
|
|
|
Assert.AreEqual("eSIyd+KOG3s=", filename.FileHash());
|
2020-01-06 00:21:05 +00:00
|
|
|
|
|
|
|
|
|
Assert.AreEqual(File.ReadAllText(filename), "Cheese for Everyone!");
|
|
|
|
|
}
|
2019-12-09 23:52:17 +00:00
|
|
|
|
|
2020-01-27 16:29:10 +00:00
|
|
|
|
|
2020-01-27 13:40:47 +00:00
|
|
|
|
[TestMethod]
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(state);
|
|
|
|
|
|
|
|
|
|
var converted = await state.RoundTripState();
|
|
|
|
|
Assert.IsTrue(await converted.Verify(new Archive{Size = 20}));
|
|
|
|
|
var filename = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>() }));
|
|
|
|
|
|
|
|
|
|
await converted.Download(new Archive { Name = "TESAlliance Test.zip" }, filename);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual("eSIyd+KOG3s=", filename.FileHash());
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(File.ReadAllText(filename), "Cheese for Everyone!");
|
2020-01-27 16:29:10 +00:00
|
|
|
|
}
|
2020-01-27 13:40:47 +00:00
|
|
|
|
|
|
|
|
|
/* WAITING FOR APPROVAL BY MODERATOR
|
2020-01-27 13:31:22 +00:00
|
|
|
|
[TestMethod]
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(state);
|
|
|
|
|
|
|
|
|
|
var converted = await state.RoundTripState();
|
|
|
|
|
Assert.IsTrue(await converted.Verify(new Archive{Size = 20}));
|
|
|
|
|
var filename = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>() }));
|
|
|
|
|
|
|
|
|
|
await converted.Download(new Archive { Name = "DeadlyStream Test.zip" }, filename);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual("eSIyd+KOG3s=", filename.FileHash());
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(File.ReadAllText(filename), "Cheese for Everyone!");
|
|
|
|
|
}*/
|
|
|
|
|
|
2019-12-09 23:52:17 +00:00
|
|
|
|
[TestMethod]
|
2019-12-13 00:40:21 +00:00
|
|
|
|
public async Task GameFileSourceDownload()
|
2019-12-09 23:52:17 +00:00
|
|
|
|
{
|
2019-12-26 18:21:57 +00:00
|
|
|
|
// Test mode off for this test
|
|
|
|
|
Consts.TestMode = false;
|
2019-12-13 00:40:21 +00:00
|
|
|
|
await DownloadDispatcher.GetInstance<LoversLabDownloader>().Prepare();
|
2019-12-09 23:52:17 +00:00
|
|
|
|
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());
|
2019-12-09 23:52:17 +00:00
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(state);
|
2019-12-08 17:00:22 +00:00
|
|
|
|
|
2020-01-11 04:15:53 +00:00
|
|
|
|
var converted = await state.RoundTripState();
|
2020-01-13 22:55:55 +00:00
|
|
|
|
Assert.IsTrue(await converted.Verify(new Archive{Size = 20}));
|
2019-12-09 23:52:17 +00:00
|
|
|
|
var filename = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>() }));
|
|
|
|
|
|
2019-12-13 00:40:21 +00:00
|
|
|
|
await converted.Download(new Archive { Name = "Update.esm" }, filename);
|
2019-12-09 23:52:17 +00:00
|
|
|
|
|
|
|
|
|
Assert.AreEqual("/DLG/LjdGXI=", Utils.FileHash(filename));
|
|
|
|
|
CollectionAssert.AreEqual(File.ReadAllBytes(Path.Combine(Game.SkyrimSpecialEdition.MetaData().GameLocation(), "Data/Update.esm")), File.ReadAllBytes(filename));
|
2019-12-26 18:21:57 +00:00
|
|
|
|
Consts.TestMode = true;
|
2019-12-08 17:00:22 +00:00
|
|
|
|
}
|
2020-02-11 22:14:59 +00:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task AFKModsDownloadTest()
|
|
|
|
|
{
|
|
|
|
|
await DownloadDispatcher.GetInstance<AFKModsDownloader>().Prepare();
|
|
|
|
|
const string ini = "[General]\n" +
|
|
|
|
|
"directURL=https://www.afkmods.com/index.php?/files/file/2120-skyrim-save-system-overhaul/&do=download&r=20112&confirm=1&t=1&csrfKey=840a4a373144097693171a79df77d521";
|
|
|
|
|
|
|
|
|
|
var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
|
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(state);
|
|
|
|
|
|
|
|
|
|
var converted = await state.RoundTripState();
|
|
|
|
|
Assert.IsTrue(await converted.Verify(new Archive{Size = 20}));
|
|
|
|
|
var filename = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>() }));
|
|
|
|
|
|
|
|
|
|
await converted.Download(new Archive { Name = "AFKMods Test.zip" }, filename);
|
|
|
|
|
}
|
2020-01-29 00:09:09 +00:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task BethesdaNetDownload()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var downloader = DownloadDispatcher.GetInstance<BethesdaNetDownloader>();
|
|
|
|
|
Assert.IsTrue(await downloader.IsLoggedIn.FirstAsync());
|
|
|
|
|
|
|
|
|
|
var ini = $@"[General]
|
2020-01-29 04:17:24 +00:00
|
|
|
|
directURL=https://bethesda.net/en/mods/skyrim/mod-detail/4145641";
|
2020-01-29 00:09:09 +00:00
|
|
|
|
|
2020-01-29 04:17:24 +00:00
|
|
|
|
var filename = Guid.NewGuid().ToString();
|
2020-01-29 00:09:09 +00:00
|
|
|
|
var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
|
|
|
|
|
Assert.IsNotNull(state);
|
|
|
|
|
|
|
|
|
|
var converted = state.ViaJSON();
|
|
|
|
|
Assert.IsTrue(await converted.Verify(new Archive {Name = "mod.ckm"}));
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>() }));
|
|
|
|
|
|
2020-01-29 04:17:24 +00:00
|
|
|
|
await converted.Download(new Archive { Name = "mod.zip" }, filename);
|
|
|
|
|
|
|
|
|
|
await using var fs = File.OpenRead(filename);
|
|
|
|
|
using var archive = new ZipArchive(fs);
|
|
|
|
|
var entries = archive.Entries.Select(e => e.FullName).ToList();
|
|
|
|
|
CollectionAssert.AreEqual(entries, new List<string> {@"Data\TestCK.esp", @"Data\TestCK.ini"});
|
2020-01-29 00:09:09 +00:00
|
|
|
|
}
|
2020-02-12 12:37:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that files from different sources don't overwrite eachother when downloaded by AInstaller
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[TestMethod]
|
|
|
|
|
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>()
|
|
|
|
|
{
|
|
|
|
|
new Archive {Hash = statea.Hash, Name = "Download.esm", State = statea}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var archivesb = new List<Archive>()
|
|
|
|
|
{
|
|
|
|
|
new Archive {Hash = stateb.Hash, Name = "Download.esm", State = stateb}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (Directory.Exists("DownloadTests"))
|
|
|
|
|
Utils.DeleteDirectory("DownloadTests");
|
|
|
|
|
Directory.CreateDirectory("DownloadTests");
|
|
|
|
|
|
|
|
|
|
var inst = new TestInstaller(null, null, null, "DownloadTests", null);
|
|
|
|
|
|
|
|
|
|
await inst.DownloadMissingArchives(archivesa, true);
|
|
|
|
|
await inst.DownloadMissingArchives(archivesb, true);
|
|
|
|
|
|
|
|
|
|
CollectionAssert.AreEqual(Directory.EnumerateFiles("DownloadTests").Select(Path.GetFileName).OrderBy(a => a).ToArray(),
|
|
|
|
|
new string[]
|
|
|
|
|
{
|
|
|
|
|
@"Download.esm",
|
|
|
|
|
@"Download.esm.xxHash",
|
|
|
|
|
@"Download_f80ee6d109516018308f62e2c862b7f061987ac4a8c2327a101ac6b8f80ec4ae_.esm",
|
|
|
|
|
@"Download_f80ee6d109516018308f62e2c862b7f061987ac4a8c2327a101ac6b8f80ec4ae_.esm.xxHash"
|
|
|
|
|
}.OrderBy(a => a).ToArray());
|
|
|
|
|
|
|
|
|
|
Consts.TestMode = true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class TestInstaller : AInstaller
|
|
|
|
|
{
|
|
|
|
|
public TestInstaller(string archive, ModList modList, string outputFolder, string downloadFolder, SystemParameters parameters) : base(archive, modList, outputFolder, downloadFolder, parameters)
|
|
|
|
|
{
|
|
|
|
|
ConfigureProcessor(1, new Subject<int>().StartWith(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
|
|
|
|
}
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-10-12 18:03:45 +00:00
|
|
|
|
}
|