2019-11-21 14:25:56 +00:00
|
|
|
|
using System.Net.Http;
|
2019-10-12 22:31:07 +00:00
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using Wabbajack.Common;
|
2019-10-16 03:10:34 +00:00
|
|
|
|
using Wabbajack.Lib.Validation;
|
2019-10-12 22:31:07 +00:00
|
|
|
|
|
2019-10-16 03:10:34 +00:00
|
|
|
|
namespace Wabbajack.Lib.Downloaders
|
2019-10-12 22:31:07 +00:00
|
|
|
|
{
|
2019-10-16 11:44:45 +00:00
|
|
|
|
public class ModDBDownloader : IDownloader, IUrlDownloader
|
2019-10-12 22:31:07 +00:00
|
|
|
|
{
|
2019-11-21 15:51:57 +00:00
|
|
|
|
public AbstractDownloadState GetDownloaderState(dynamic archiveINI)
|
2019-10-12 22:31:07 +00:00
|
|
|
|
{
|
2019-11-21 15:51:57 +00:00
|
|
|
|
var url = archiveINI?.General?.directURL;
|
2019-10-16 11:44:45 +00:00
|
|
|
|
return GetDownloaderState(url);
|
|
|
|
|
}
|
2019-10-12 22:31:07 +00:00
|
|
|
|
|
2019-10-16 11:44:45 +00:00
|
|
|
|
public AbstractDownloadState GetDownloaderState(string url)
|
|
|
|
|
{
|
2019-10-12 22:31:07 +00:00
|
|
|
|
if (url != null && url.StartsWith("https://www.moddb.com/downloads/start"))
|
|
|
|
|
{
|
|
|
|
|
return new State
|
|
|
|
|
{
|
|
|
|
|
Url = url
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Prepare()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2019-11-21 15:51:57 +00:00
|
|
|
|
var newURL = GetDownloadUrl();
|
|
|
|
|
new HTTPDownloader.State {Url = newURL}.Download(a, destination);
|
2019-10-12 22:31:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2019-11-21 15:51:57 +00:00
|
|
|
|
var newURL = match.Value;
|
|
|
|
|
return newURL;
|
2019-10-12 22:31:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Verify()
|
|
|
|
|
{
|
2019-11-21 15:51:57 +00:00
|
|
|
|
var newURL = GetDownloadUrl();
|
|
|
|
|
return new HTTPDownloader.State { Url = newURL }.Verify();
|
2019-10-12 22:31:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IDownloader GetDownloader()
|
|
|
|
|
{
|
|
|
|
|
return DownloadDispatcher.GetInstance<ModDBDownloader>();
|
|
|
|
|
}
|
2019-10-12 22:54:25 +00:00
|
|
|
|
|
|
|
|
|
public override string GetReportEntry(Archive a)
|
|
|
|
|
{
|
|
|
|
|
return $"* ModDB - [{a.Name}]({Url})";
|
|
|
|
|
}
|
2019-10-12 22:31:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|