2020-02-04 02:30:45 +00:00
|
|
|
|
using System;
|
2019-12-07 02:45:13 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2019-10-12 21:37:16 +00:00
|
|
|
|
using System.Web;
|
2020-02-04 02:30:45 +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
|
|
|
|
{
|
2019-10-16 11:44:45 +00:00
|
|
|
|
public class DropboxDownloader : IDownloader, IUrlDownloader
|
2019-10-12 21:37:16 +00:00
|
|
|
|
{
|
2020-04-09 20:20:34 +00:00
|
|
|
|
public async Task<AbstractDownloadState?> GetDownloaderState(dynamic archiveINI, bool quickMode)
|
2019-10-12 21:37:16 +00:00
|
|
|
|
{
|
2019-11-21 15:51:57 +00:00
|
|
|
|
var urlstring = archiveINI?.General?.directURL;
|
2019-10-16 11:44:45 +00:00
|
|
|
|
return GetDownloaderState(urlstring);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-25 12:37:55 +00:00
|
|
|
|
public AbstractDownloadState? GetDownloaderState(string? url)
|
2019-10-16 11:44:45 +00:00
|
|
|
|
{
|
2021-07-25 12:37:55 +00:00
|
|
|
|
if (url == null) return null;
|
|
|
|
|
|
2020-02-04 02:30:45 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var uri = new UriBuilder(url);
|
|
|
|
|
if (uri.Host != "www.dropbox.com") return null;
|
|
|
|
|
var query = HttpUtility.ParseQueryString(uri.Query);
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
2020-02-04 02:30:45 +00:00
|
|
|
|
if (query.GetValues("dl")?.Length > 0)
|
|
|
|
|
query.Remove("dl");
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
2020-02-04 02:30:45 +00:00
|
|
|
|
query.Set("dl", "1");
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
2020-02-04 02:30:45 +00:00
|
|
|
|
uri.Query = query.ToString();
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
2020-04-09 20:20:34 +00:00
|
|
|
|
return new HTTPDownloader.State(uri.ToString().Replace("dropbox.com:443/", "dropbox.com/"));
|
2020-02-04 02:30:45 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
2019-10-12 21:37:16 +00:00
|
|
|
|
{
|
2020-02-04 02:30:45 +00:00
|
|
|
|
Utils.Error($"Error downloading Dropbox link: {url}");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
2019-10-12 21:37:16 +00:00
|
|
|
|
}
|
2019-10-12 22:15:20 +00:00
|
|
|
|
|
2019-12-07 02:45:13 +00:00
|
|
|
|
public async Task Prepare()
|
2019-10-12 22:15:20 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
2019-10-12 21:37:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|