From b43c2fbfb0f92ff0ac54573c76f193f552814afd Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Sun, 27 Feb 2022 14:31:13 -0700 Subject: [PATCH] Add manual downloader and supporting code --- Wabbajack.DTOs/DownloadStates/Manual.cs | 6 +- .../DownloaderTests.cs | 4 +- .../ServiceExtensions.cs | 2 + .../Wabbajack.Downloaders.Dispatcher.csproj | 1 + .../ManualDownloader.cs | 57 +++++++++++++++++++ .../ServiceExtensions.cs | 13 +++++ .../Wabbajack.Downloaders.Manual.csproj | 13 +++++ Wabbajack.sln | 7 +++ 8 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 Wabbajack.Downloaders.Manual/ManualDownloader.cs create mode 100644 Wabbajack.Downloaders.Manual/ServiceExtensions.cs create mode 100644 Wabbajack.Downloaders.Manual/Wabbajack.Downloaders.Manual.csproj diff --git a/Wabbajack.DTOs/DownloadStates/Manual.cs b/Wabbajack.DTOs/DownloadStates/Manual.cs index a4df0a0e..362abc05 100644 --- a/Wabbajack.DTOs/DownloadStates/Manual.cs +++ b/Wabbajack.DTOs/DownloadStates/Manual.cs @@ -3,11 +3,13 @@ using Wabbajack.DTOs.JsonConverters; namespace Wabbajack.DTOs.DownloadStates; -[JsonAlias("ManualDownloader, Wabbajack.Lib")] -[JsonName("Manual")] +[JsonName("ManualDownloader, Wabbajack.Lib")] +[JsonAlias("Manual")] public class Manual : ADownloadState { public Uri Url { get; init; } + + public string Prompt { get; init; } public override string TypeName => "ManualDownloader+State"; public override object[] PrimaryKey => new object[] {Url}; } \ No newline at end of file diff --git a/Wabbajack.Downloaders.Dispatcher.Test/DownloaderTests.cs b/Wabbajack.Downloaders.Dispatcher.Test/DownloaderTests.cs index 7964ebe7..d012a9d6 100644 --- a/Wabbajack.Downloaders.Dispatcher.Test/DownloaderTests.cs +++ b/Wabbajack.Downloaders.Dispatcher.Test/DownloaderTests.cs @@ -192,7 +192,7 @@ public class DownloaderTests Game = Game.SkyrimSpecialEdition, IsCCMod = true, ProductId = 4, - BranchID = 90898, + BranchId = 90898, ContentId = "4059054" } }, @@ -204,7 +204,7 @@ public class DownloaderTests Game = Game.SkyrimSpecialEdition, IsCCMod = true, ProductId = 6, - BranchID = 9898, + BranchId = 9898, ContentId = "059054" } }, diff --git a/Wabbajack.Downloaders.Dispatcher/ServiceExtensions.cs b/Wabbajack.Downloaders.Dispatcher/ServiceExtensions.cs index 67acd7d9..d3592f1f 100644 --- a/Wabbajack.Downloaders.Dispatcher/ServiceExtensions.cs +++ b/Wabbajack.Downloaders.Dispatcher/ServiceExtensions.cs @@ -2,6 +2,7 @@ using Microsoft.Extensions.DependencyInjection; using Wabbajack.Downloaders.Bethesda; using Wabbajack.Downloaders.Http; using Wabbajack.Downloaders.IPS4OAuth2Downloader; +using Wabbajack.Downloaders.Manual; using Wabbajack.Downloaders.MediaFire; using Wabbajack.Downloaders.ModDB; using Wabbajack.DTOs.JsonConverters; @@ -27,6 +28,7 @@ public static class ServiceExtensions .AddGameFileDownloader() .AddBethesdaDownloader() .AddWabbajackClient() + .AddManualDownloader() .AddSingleton(); } } \ No newline at end of file diff --git a/Wabbajack.Downloaders.Dispatcher/Wabbajack.Downloaders.Dispatcher.csproj b/Wabbajack.Downloaders.Dispatcher/Wabbajack.Downloaders.Dispatcher.csproj index 95fa78f6..54a368f5 100644 --- a/Wabbajack.Downloaders.Dispatcher/Wabbajack.Downloaders.Dispatcher.csproj +++ b/Wabbajack.Downloaders.Dispatcher/Wabbajack.Downloaders.Dispatcher.csproj @@ -14,6 +14,7 @@ + diff --git a/Wabbajack.Downloaders.Manual/ManualDownloader.cs b/Wabbajack.Downloaders.Manual/ManualDownloader.cs new file mode 100644 index 00000000..7c0b7dcb --- /dev/null +++ b/Wabbajack.Downloaders.Manual/ManualDownloader.cs @@ -0,0 +1,57 @@ +using Wabbajack.Downloaders.Interfaces; +using Wabbajack.DTOs; +using Wabbajack.DTOs.DownloadStates; +using Wabbajack.DTOs.Validation; +using Wabbajack.Hashing.xxHash64; +using Wabbajack.Paths; +using Wabbajack.RateLimiter; + +namespace Wabbajack.Downloaders.Manual; + +public class ManualDownloader : ADownloader +{ + public override Task Download(Archive archive, DTOs.DownloadStates.Manual state, AbsolutePath destination, IJob job, CancellationToken token) + { + throw new NotImplementedException(); + } + + public override async Task Prepare() + { + return true; + } + + public override bool IsAllowed(ServerAllowList allowList, IDownloadState state) + { + return allowList.AllowedPrefixes.Any(p => ((DTOs.DownloadStates.Manual) state).Url.ToString().StartsWith(p)); + } + + public override IDownloadState? Resolve(IReadOnlyDictionary iniData) + { + if (iniData.ContainsKey("manualURL") && Uri.TryCreate(iniData["manualURL"], UriKind.Absolute, out var uri)) + { + iniData.TryGetValue("prompt", out var prompt); + + var state = new DTOs.DownloadStates.Manual + { + Url = uri, + Prompt = prompt ?? "" + }; + + return state; + } + + return null; + } + + public override Priority Priority { get; } = Priority.Lowest; + public override async Task Verify(Archive archive, DTOs.DownloadStates.Manual archiveState, IJob job, CancellationToken token) + { + return true; + } + + public override IEnumerable MetaIni(Archive a, DTOs.DownloadStates.Manual state) + { + + return new[] {$"manualURL={state.Url}", $"prompt={state.Prompt}"}; + } +} \ No newline at end of file diff --git a/Wabbajack.Downloaders.Manual/ServiceExtensions.cs b/Wabbajack.Downloaders.Manual/ServiceExtensions.cs new file mode 100644 index 00000000..5c25811e --- /dev/null +++ b/Wabbajack.Downloaders.Manual/ServiceExtensions.cs @@ -0,0 +1,13 @@ +using Microsoft.Extensions.DependencyInjection; +using Wabbajack.Downloaders.Interfaces; +using Wabbajack.DTOs; + +namespace Wabbajack.Downloaders.Manual; + +public static class ServiceExtensions +{ + public static IServiceCollection AddManualDownloader(this IServiceCollection services) + { + return services.AddAllSingleton, ManualDownloader>(); + } +} \ No newline at end of file diff --git a/Wabbajack.Downloaders.Manual/Wabbajack.Downloaders.Manual.csproj b/Wabbajack.Downloaders.Manual/Wabbajack.Downloaders.Manual.csproj new file mode 100644 index 00000000..222ac4dd --- /dev/null +++ b/Wabbajack.Downloaders.Manual/Wabbajack.Downloaders.Manual.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Wabbajack.sln b/Wabbajack.sln index d2207d28..ef4fcfd1 100644 --- a/Wabbajack.sln +++ b/Wabbajack.sln @@ -137,6 +137,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.Networking.Bethes EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.Downloaders.Bethesda", "Wabbajack.Downloaders.Bethesda\Wabbajack.Downloaders.Bethesda.csproj", "{B10BB6D6-B3FC-4A76-8A07-6A0A0ADDE198}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.Downloaders.Manual", "Wabbajack.Downloaders.Manual\Wabbajack.Downloaders.Manual.csproj", "{7FC4F129-F0FA-46B7-B7C4-532E371A6326}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -375,6 +377,10 @@ Global {B10BB6D6-B3FC-4A76-8A07-6A0A0ADDE198}.Debug|Any CPU.Build.0 = Debug|Any CPU {B10BB6D6-B3FC-4A76-8A07-6A0A0ADDE198}.Release|Any CPU.ActiveCfg = Release|Any CPU {B10BB6D6-B3FC-4A76-8A07-6A0A0ADDE198}.Release|Any CPU.Build.0 = Release|Any CPU + {7FC4F129-F0FA-46B7-B7C4-532E371A6326}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7FC4F129-F0FA-46B7-B7C4-532E371A6326}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7FC4F129-F0FA-46B7-B7C4-532E371A6326}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7FC4F129-F0FA-46B7-B7C4-532E371A6326}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -422,6 +428,7 @@ Global {6D7EA87E-6ABE-4BA3-B93A-BE5E71A4DE7C} = {F677890D-5109-43BC-97C7-C4CD47C8EE0C} {A3813D73-9A8E-4CE7-861A-C59043DFFC14} = {F01F8595-5FD7-4506-8469-F4A5522DACC1} {B10BB6D6-B3FC-4A76-8A07-6A0A0ADDE198} = {98B731EE-4FC0-4482-A069-BCBA25497871} + {7FC4F129-F0FA-46B7-B7C4-532E371A6326} = {98B731EE-4FC0-4482-A069-BCBA25497871} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {0AA30275-0F38-4A7D-B645-F5505178DDE8}