2019-10-12 21:37:16 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2019-11-04 23:21:58 +00:00
|
|
|
|
using Wabbajack.Common;
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
2019-10-16 03:10:34 +00:00
|
|
|
|
namespace Wabbajack.Lib.Downloaders
|
2019-10-12 21:37:16 +00:00
|
|
|
|
{
|
|
|
|
|
public static class DownloadDispatcher
|
|
|
|
|
{
|
2019-10-13 14:18:21 +00:00
|
|
|
|
public static readonly List<IDownloader> Downloaders = new List<IDownloader>()
|
2019-10-12 21:37:16 +00:00
|
|
|
|
{
|
|
|
|
|
new MegaDownloader(),
|
|
|
|
|
new DropboxDownloader(),
|
|
|
|
|
new GoogleDriveDownloader(),
|
2019-10-12 22:31:07 +00:00
|
|
|
|
new ModDBDownloader(),
|
2019-10-12 22:15:20 +00:00
|
|
|
|
new NexusDownloader(),
|
2019-10-24 01:19:11 +00:00
|
|
|
|
new MediaFireDownloader(),
|
2019-11-07 00:29:53 +00:00
|
|
|
|
new HTTPDownloader(),
|
2019-10-12 22:31:07 +00:00
|
|
|
|
new ManualDownloader(),
|
2019-10-12 21:37:16 +00:00
|
|
|
|
};
|
|
|
|
|
|
2019-10-12 22:31:07 +00:00
|
|
|
|
private static readonly Dictionary<Type, IDownloader> IndexedDownloaders;
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
|
|
|
|
static DownloadDispatcher()
|
|
|
|
|
{
|
2019-10-12 22:31:07 +00:00
|
|
|
|
IndexedDownloaders = Downloaders.ToDictionary(d => d.GetType());
|
2019-10-12 21:37:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static T GetInstance<T>()
|
|
|
|
|
{
|
2019-10-12 22:31:07 +00:00
|
|
|
|
return (T)IndexedDownloaders[typeof(T)];
|
2019-10-12 21:37:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static AbstractDownloadState ResolveArchive(dynamic ini)
|
|
|
|
|
{
|
2019-10-12 22:31:07 +00:00
|
|
|
|
return Downloaders.Select(d => d.GetDownloaderState(ini)).FirstOrDefault(result => result != null);
|
2019-10-12 21:37:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-16 11:44:45 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reduced version of Resolve archive that requires less information, but only works
|
|
|
|
|
/// with a single URL string
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ini"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static AbstractDownloadState ResolveArchive(string url)
|
|
|
|
|
{
|
|
|
|
|
return Downloaders.OfType<IUrlDownloader>().Select(d => d.GetDownloaderState(url)).FirstOrDefault(result => result != null);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-04 23:21:58 +00:00
|
|
|
|
public static void PrepareAll(IEnumerable<AbstractDownloadState> states)
|
|
|
|
|
{
|
|
|
|
|
states.Select(s => s.GetDownloader().GetType())
|
|
|
|
|
.Distinct()
|
|
|
|
|
.Do(t => Downloaders.First(d => d.GetType() == t).Prepare());
|
|
|
|
|
}
|
2019-10-12 21:37:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|