wabbajack/Wabbajack.Lib/Downloaders/DownloadDispatcher.cs

53 lines
1.6 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
namespace Wabbajack.Lib.Downloaders
{
public static class DownloadDispatcher
{
public static readonly List<IDownloader> Downloaders = new List<IDownloader>()
{
new MegaDownloader(),
new DropboxDownloader(),
new GoogleDriveDownloader(),
2019-10-12 22:31:07 +00:00
new ModDBDownloader(),
new NexusDownloader(),
2019-10-12 22:31:07 +00:00
new ManualDownloader(),
new HTTPDownloader()
};
2019-10-12 22:31:07 +00:00
private static readonly Dictionary<Type, IDownloader> IndexedDownloaders;
static DownloadDispatcher()
{
2019-10-12 22:31:07 +00:00
IndexedDownloaders = Downloaders.ToDictionary(d => d.GetType());
}
public static T GetInstance<T>()
{
2019-10-12 22:31:07 +00:00
return (T)IndexedDownloaders[typeof(T)];
}
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);
}
/// <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);
}
}
}