mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
add modddb handler
This commit is contained in:
parent
bcb669ad60
commit
4e946facab
@ -130,6 +130,27 @@ namespace Wabbajack.Test
|
|||||||
|
|
||||||
Assert.AreEqual(filename.FileSHA256(), "U3Xg6RBR9XrUY9/jQSu6WKu5dfhHmpaN2dTl0ylDFmI=");
|
Assert.AreEqual(filename.FileSHA256(), "U3Xg6RBR9XrUY9/jQSu6WKu5dfhHmpaN2dTl0ylDFmI=");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ModDbTests()
|
||||||
|
{
|
||||||
|
var ini = @"[General]
|
||||||
|
directURL=https://www.moddb.com/downloads/start/124908?referer=https%3A%2F%2Fwww.moddb.com%2Fmods%2Fautopause";
|
||||||
|
|
||||||
|
var state = (AbstractDownloadState)DownloadDispatcher.ResolveArchive(ini.LoadIniString());
|
||||||
|
|
||||||
|
Assert.IsNotNull(state);
|
||||||
|
|
||||||
|
var converted = state.ViaJSON();
|
||||||
|
Assert.IsTrue(converted.Verify());
|
||||||
|
var filename = Guid.NewGuid().ToString();
|
||||||
|
|
||||||
|
Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>() }));
|
||||||
|
|
||||||
|
converted.Download(new Archive { Name = "moddbtest.7z" }, filename);
|
||||||
|
|
||||||
|
Assert.AreEqual("lUvpEjqxfyidBONSHcDy6EnZIPpAD2K4rkJ5ejCXc2k=", filename.FileSHA256());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,37 +9,32 @@ namespace Wabbajack.Downloaders
|
|||||||
{
|
{
|
||||||
public static class DownloadDispatcher
|
public static class DownloadDispatcher
|
||||||
{
|
{
|
||||||
private static List<IDownloader> _downloaders = new List<IDownloader>()
|
private static readonly List<IDownloader> Downloaders = new List<IDownloader>()
|
||||||
{
|
{
|
||||||
new MegaDownloader(),
|
new MegaDownloader(),
|
||||||
new DropboxDownloader(),
|
new DropboxDownloader(),
|
||||||
new GoogleDriveDownloader(),
|
new GoogleDriveDownloader(),
|
||||||
new HTTPDownloader(),
|
new ModDBDownloader(),
|
||||||
new NexusDownloader(),
|
new NexusDownloader(),
|
||||||
new ManualDownloader()
|
new ManualDownloader(),
|
||||||
|
new HTTPDownloader()
|
||||||
};
|
};
|
||||||
|
|
||||||
private static Dictionary<Type, IDownloader> _indexedDownloaders;
|
private static readonly Dictionary<Type, IDownloader> IndexedDownloaders;
|
||||||
|
|
||||||
static DownloadDispatcher()
|
static DownloadDispatcher()
|
||||||
{
|
{
|
||||||
_indexedDownloaders = _downloaders.ToDictionary(d => d.GetType());
|
IndexedDownloaders = Downloaders.ToDictionary(d => d.GetType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static T GetInstance<T>()
|
public static T GetInstance<T>()
|
||||||
{
|
{
|
||||||
return (T)_indexedDownloaders[typeof(T)];
|
return (T)IndexedDownloaders[typeof(T)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AbstractDownloadState ResolveArchive(dynamic ini)
|
public static AbstractDownloadState ResolveArchive(dynamic ini)
|
||||||
{
|
{
|
||||||
foreach (var d in _downloaders)
|
return Downloaders.Select(d => d.GetDownloaderState(ini)).FirstOrDefault(result => result != null);
|
||||||
{
|
|
||||||
var result = d.GetDownloaderState(ini);
|
|
||||||
if (result != null) return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
72
Wabbajack/Downloaders/ModDBDownloader.cs
Normal file
72
Wabbajack/Downloaders/ModDBDownloader.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Wabbajack.Common;
|
||||||
|
using Wabbajack.Validation;
|
||||||
|
|
||||||
|
namespace Wabbajack.Downloaders
|
||||||
|
{
|
||||||
|
public class ModDBDownloader : IDownloader
|
||||||
|
{
|
||||||
|
public AbstractDownloadState GetDownloaderState(dynamic archive_ini)
|
||||||
|
{
|
||||||
|
var url = archive_ini?.General?.directURL;
|
||||||
|
|
||||||
|
if (url != null && url.StartsWith("https://www.moddb.com/downloads/start"))
|
||||||
|
{
|
||||||
|
return new State
|
||||||
|
{
|
||||||
|
Url = url
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Prepare()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class State : AbstractDownloadState
|
||||||
|
{
|
||||||
|
public string Url { get; set; }
|
||||||
|
public override bool IsWhitelisted(ServerWhitelist whitelist)
|
||||||
|
{
|
||||||
|
// Everything from Moddb is whitelisted
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Download(Archive a, string destination)
|
||||||
|
{
|
||||||
|
var new_url = GetDownloadUrl();
|
||||||
|
new HTTPDownloader.State {Url = new_url}.Download(a, destination);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetDownloadUrl()
|
||||||
|
{
|
||||||
|
var client = new HttpClient();
|
||||||
|
var result = client.GetStringSync(Url);
|
||||||
|
var regex = new Regex("https:\\/\\/www\\.moddb\\.com\\/downloads\\/mirror\\/.*(?=\\\")");
|
||||||
|
var match = regex.Match(result);
|
||||||
|
var new_url = match.Value;
|
||||||
|
return new_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Verify()
|
||||||
|
{
|
||||||
|
var new_url = GetDownloadUrl();
|
||||||
|
return new HTTPDownloader.State { Url = new_url }.Verify();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IDownloader GetDownloader()
|
||||||
|
{
|
||||||
|
return DownloadDispatcher.GetInstance<ModDBDownloader>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -196,6 +196,7 @@
|
|||||||
<Compile Include="Downloaders\IDownloader.cs" />
|
<Compile Include="Downloaders\IDownloader.cs" />
|
||||||
<Compile Include="Downloaders\ManualDownloader.cs" />
|
<Compile Include="Downloaders\ManualDownloader.cs" />
|
||||||
<Compile Include="Downloaders\MegaDownloader.cs" />
|
<Compile Include="Downloaders\MegaDownloader.cs" />
|
||||||
|
<Compile Include="Downloaders\ModDBDownloader.cs" />
|
||||||
<Compile Include="Downloaders\NexusDownloader.cs" />
|
<Compile Include="Downloaders\NexusDownloader.cs" />
|
||||||
<Compile Include="LambdaCommand.cs" />
|
<Compile Include="LambdaCommand.cs" />
|
||||||
<Compile Include="UI\ModlistPropertiesWindow.xaml.cs">
|
<Compile Include="UI\ModlistPropertiesWindow.xaml.cs">
|
||||||
|
Loading…
Reference in New Issue
Block a user