2020-02-08 23:53:11 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Reactive.Disposables;
|
|
|
|
|
using System.Reactive.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Alphaleonis.Win32.Filesystem;
|
|
|
|
|
using CommandLine;
|
|
|
|
|
using Wabbajack.Common;
|
|
|
|
|
using Wabbajack.Lib;
|
|
|
|
|
using Wabbajack.Lib.Downloaders;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.CLI.Verbs
|
|
|
|
|
{
|
|
|
|
|
[Verb("download-url", HelpText = "Infer a download state from a URL and download it")]
|
2020-02-11 05:04:56 +00:00
|
|
|
|
public class DownloadUrl : AVerb
|
2020-02-08 23:53:11 +00:00
|
|
|
|
{
|
|
|
|
|
[Option('u', "url", Required = true, HelpText = "Url to download")]
|
2020-04-06 12:04:40 +00:00
|
|
|
|
public Uri? Url { get; set; }
|
2020-02-08 23:53:11 +00:00
|
|
|
|
|
|
|
|
|
[Option('o', "output", Required = true, HelpText = "Output file name")]
|
2020-04-06 12:04:40 +00:00
|
|
|
|
public string? Output { get; set; }
|
2020-02-08 23:53:11 +00:00
|
|
|
|
|
2020-02-11 05:04:56 +00:00
|
|
|
|
protected override async Task<int> Run()
|
2020-02-08 23:53:11 +00:00
|
|
|
|
{
|
2020-03-03 21:53:29 +00:00
|
|
|
|
var state = await DownloadDispatcher.Infer(Url);
|
2020-02-08 23:53:11 +00:00
|
|
|
|
if (state == null)
|
2020-04-06 13:09:17 +00:00
|
|
|
|
return CLIUtils.Exit($"Could not find download source for URL {Url}", ExitCode.Error);
|
2020-02-24 17:05:42 +00:00
|
|
|
|
|
2020-02-08 23:53:11 +00:00
|
|
|
|
DownloadDispatcher.PrepareAll(new []{state});
|
|
|
|
|
|
|
|
|
|
using var queue = new WorkQueue();
|
|
|
|
|
queue.Status
|
|
|
|
|
.Where(s => s.ProgressPercent != Percent.Zero)
|
|
|
|
|
.Debounce(TimeSpan.FromSeconds(1))
|
|
|
|
|
.Subscribe(s => Console.WriteLine($"Downloading {s.ProgressPercent}"));
|
|
|
|
|
|
|
|
|
|
new[] {state}
|
|
|
|
|
.PMap(queue, async s =>
|
|
|
|
|
{
|
2020-02-11 05:04:56 +00:00
|
|
|
|
await s.Download(new Archive {Name = Path.GetFileName(Output)}, Output);
|
2020-02-08 23:53:11 +00:00
|
|
|
|
}).Wait();
|
|
|
|
|
|
2020-02-11 05:04:56 +00:00
|
|
|
|
File.WriteAllLines(Output + ".meta", state.GetMetaIni());
|
2020-02-08 23:53:11 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|