2019-12-29 22:57:01 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2019-12-06 05:29:17 +00:00
|
|
|
|
using Alphaleonis.Win32.Filesystem;
|
2019-10-16 03:10:34 +00:00
|
|
|
|
using Wabbajack.Lib.Validation;
|
2019-10-12 18:03:45 +00:00
|
|
|
|
|
2019-10-16 03:10:34 +00:00
|
|
|
|
namespace Wabbajack.Lib.Downloaders
|
2019-10-12 18:03:45 +00:00
|
|
|
|
{
|
|
|
|
|
public abstract class AbstractDownloadState
|
|
|
|
|
{
|
2019-12-29 22:57:01 +00:00
|
|
|
|
|
|
|
|
|
public static List<Type> KnownSubTypes = new List<Type>()
|
|
|
|
|
{
|
|
|
|
|
typeof(HTTPDownloader.State),
|
|
|
|
|
typeof(GameFileSourceDownloader.State),
|
|
|
|
|
typeof(GoogleDriveDownloader.State),
|
|
|
|
|
typeof(LoversLabDownloader.State),
|
|
|
|
|
typeof(ManualDownloader.State),
|
|
|
|
|
typeof(MediaFireDownloader.State),
|
|
|
|
|
typeof(MegaDownloader.State),
|
|
|
|
|
typeof(ModDBDownloader.State),
|
|
|
|
|
typeof(NexusDownloader.State),
|
|
|
|
|
typeof(SteamWorkshopDownloader.State)
|
|
|
|
|
};
|
|
|
|
|
public static Dictionary<string, Type> NameToType { get; set; }
|
|
|
|
|
public static Dictionary<Type, string> TypeToName { get; set; }
|
|
|
|
|
|
|
|
|
|
static AbstractDownloadState()
|
|
|
|
|
{
|
|
|
|
|
NameToType = KnownSubTypes.ToDictionary(t => t.FullName.Substring(t.Namespace.Length + 1), t => t);
|
|
|
|
|
TypeToName = NameToType.ToDictionary(k => k.Value, k => k.Key);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-01 16:19:06 +00:00
|
|
|
|
public abstract object[] PrimaryKey { get; }
|
|
|
|
|
|
2019-12-29 22:57:01 +00:00
|
|
|
|
|
|
|
|
|
|
2019-10-12 18:03:45 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns true if this file is allowed to be downloaded via whitelist
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="whitelist"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public abstract bool IsWhitelisted(ServerWhitelist whitelist);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Downloads this file to the given destination location
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="destination"></param>
|
2019-12-06 05:29:17 +00:00
|
|
|
|
public abstract Task Download(Archive a, string destination);
|
2019-10-12 18:03:45 +00:00
|
|
|
|
|
2019-12-06 05:29:17 +00:00
|
|
|
|
public async Task Download(string destination)
|
2019-10-29 21:30:27 +00:00
|
|
|
|
{
|
2020-01-03 19:21:27 +00:00
|
|
|
|
if (!Directory.Exists(Path.GetDirectoryName(destination)))
|
|
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(destination));
|
|
|
|
|
|
2019-12-06 05:29:17 +00:00
|
|
|
|
await Download(new Archive {Name = Path.GetFileName(destination)}, destination);
|
2019-10-29 21:30:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-12 18:03:45 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns true if this link is still valid
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2019-12-06 05:29:17 +00:00
|
|
|
|
public abstract Task<bool> Verify();
|
2019-10-12 22:15:20 +00:00
|
|
|
|
|
|
|
|
|
public abstract IDownloader GetDownloader();
|
2019-10-12 22:54:25 +00:00
|
|
|
|
|
|
|
|
|
public abstract string GetReportEntry(Archive a);
|
2019-10-12 18:03:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|