Add manual downloader and supporting code

This commit is contained in:
Timothy Baldridge 2022-02-27 14:31:13 -07:00
parent 97c14f6a7a
commit b43c2fbfb0
8 changed files with 99 additions and 4 deletions

View File

@ -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};
}

View File

@ -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"
}
},

View File

@ -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<DownloadDispatcher>();
}
}

View File

@ -14,6 +14,7 @@
<ProjectReference Include="..\Wabbajack.Downloaders.Http\Wabbajack.Downloaders.Http.csproj" />
<ProjectReference Include="..\Wabbajack.Downloaders.Interfaces\Wabbajack.Downloaders.Interfaces.csproj" />
<ProjectReference Include="..\Wabbajack.Downloaders.IPS4OAuth2Downloader\Wabbajack.Downloaders.IPS4OAuth2Downloader.csproj" />
<ProjectReference Include="..\Wabbajack.Downloaders.Manual\Wabbajack.Downloaders.Manual.csproj" />
<ProjectReference Include="..\Wabbajack.Downloaders.MediaFire\Wabbajack.Downloaders.MediaFire.csproj" />
<ProjectReference Include="..\Wabbajack.Downloaders.Mega\Wabbajack.Downloaders.Mega.csproj" />
<ProjectReference Include="..\Wabbajack.Downloaders.ModDB\Wabbajack.Downloaders.ModDB.csproj" />

View File

@ -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<DTOs.DownloadStates.Manual>
{
public override Task<Hash> Download(Archive archive, DTOs.DownloadStates.Manual state, AbsolutePath destination, IJob job, CancellationToken token)
{
throw new NotImplementedException();
}
public override async Task<bool> 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<string, string> 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<bool> Verify(Archive archive, DTOs.DownloadStates.Manual archiveState, IJob job, CancellationToken token)
{
return true;
}
public override IEnumerable<string> MetaIni(Archive a, DTOs.DownloadStates.Manual state)
{
return new[] {$"manualURL={state.Url}", $"prompt={state.Prompt}"};
}
}

View File

@ -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<IDownloader, IDownloader<DTOs.DownloadStates.Manual>, ManualDownloader>();
}
}

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Wabbajack.Downloaders.Interfaces\Wabbajack.Downloaders.Interfaces.csproj" />
</ItemGroup>
</Project>

View File

@ -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}