diff --git a/Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs b/Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs index a2e637c9..1527c0b4 100644 --- a/Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs +++ b/Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs @@ -28,6 +28,19 @@ namespace Wabbajack.Lib.Downloaders var absolute = true; if (url == null || url.Host != SiteURL.Host) return null; + + if (url.PathAndQuery.StartsWith("/index.php?")) + { + var id2 = HttpUtility.ParseQueryString(url.Query)["r"]; + var parsed = HttpUtility.ParseQueryString(url.Query); + var name = parsed[null].Split("/", StringSplitOptions.RemoveEmptyEntries).Last(); + return new TState + { + FileID = id2, + FileName = name + }; + } + if (!url.PathAndQuery.StartsWith("/files/file/")) { if (string.IsNullOrWhiteSpace(url.Query)) return null; @@ -103,9 +116,10 @@ namespace Wabbajack.Lib.Downloaders if (csrfKey == null) return null; + var sep = Site.EndsWith("?") ? "&" : "?"; var url = FileID == null - ? $"{Site}/files/file/{FileName}/?do=download&confirm=1&t=1&csrfKey={csrfKey}" - : $"{Site}/files/file/{FileName}/?do=download&r={FileID}&confirm=1&t=1&csrfKey={csrfKey}"; + ? $"{Site}/files/file/{FileName}/{sep}do=download&confirm=1&t=1&csrfKey={csrfKey}" + : $"{Site}/files/file/{FileName}/{sep}do=download&r={FileID}&confirm=1&t=1&csrfKey={csrfKey}"; var streamResult = await downloader.AuthedClient.GetAsync(url); @@ -162,11 +176,22 @@ namespace Wabbajack.Lib.Downloaders public override string[] GetMetaIni() { if (FileID != null) + { + if (Site.EndsWith("?")) + { + return new[] + { + "[General]", $"directURL={Site}/files/file/{FileName}&do=download&r={FileID}&confirm=1&t=1" + }; + + } + return new[] { - "[General]", - $"directURL={Site}/files/file/{FileName}/?do=download&r={FileID}&confirm=1&t=1" + "[General]", $"directURL={Site}/files/file/{FileName}/?do=download&r={FileID}&confirm=1&t=1" }; + } + return new[] { "[General]", diff --git a/Wabbajack.Test/DownloaderTests.cs b/Wabbajack.Test/DownloaderTests.cs index 3b7911e4..f421adc6 100644 --- a/Wabbajack.Test/DownloaderTests.cs +++ b/Wabbajack.Test/DownloaderTests.cs @@ -413,6 +413,29 @@ namespace Wabbajack.Test CollectionAssert.AreEqual(File.ReadAllBytes(Path.Combine(Game.SkyrimSpecialEdition.MetaData().GameLocation(), "Data/Update.esm")), File.ReadAllBytes(filename)); Consts.TestMode = true; } + + [TestMethod] + public async Task AFKModsDownloadTest() + { + await DownloadDispatcher.GetInstance().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() })); + + await converted.Download(new Archive { Name = "AFKMods Test.zip" }, filename); + + Assert.AreEqual("GtjxHazwZ6s=", filename.FileHash()); + + } [TestMethod] public async Task BethesdaNetDownload()