mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
AbstractDownloadState.Download returns bool
There's sort of a theoretical disagreement, still. Should a failed download throw an exception, or return false? Users of this function still need to handle/prep for either/or. Still, this is better than before, where some failures were being swallowed completely
This commit is contained in:
parent
32bb4cd8e9
commit
3bac5d2f00
@ -60,15 +60,15 @@ namespace Wabbajack.Lib.Downloaders
|
||||
/// Downloads this file to the given destination location
|
||||
/// </summary>
|
||||
/// <param name="destination"></param>
|
||||
public abstract Task Download(Archive a, string destination);
|
||||
public abstract Task<bool> Download(Archive a, string destination);
|
||||
|
||||
public async Task Download(string destination)
|
||||
public async Task<bool> Download(string destination)
|
||||
{
|
||||
var path = Path.GetDirectoryName(destination);
|
||||
if (!string.IsNullOrEmpty(path) && !Directory.Exists(path))
|
||||
Directory.CreateDirectory(path);
|
||||
|
||||
await Download(new Archive {Name = Path.GetFileName(destination)}, destination);
|
||||
return await Download(new Archive {Name = Path.GetFileName(destination)}, destination);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -56,13 +56,14 @@ namespace Wabbajack.Lib.Downloaders
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task Download(Archive a, string destination)
|
||||
public override async Task<bool> Download(Archive a, string destination)
|
||||
{
|
||||
var stream = await ResolveDownloadStream();
|
||||
using (var file = File.OpenWrite(destination))
|
||||
{
|
||||
stream.CopyTo(file);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task<Stream> ResolveDownloadStream()
|
||||
|
@ -62,7 +62,7 @@ namespace Wabbajack.Lib.Downloaders
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task Download(Archive a, string destination)
|
||||
public override async Task<bool> Download(Archive a, string destination)
|
||||
{
|
||||
using(var src = File.OpenRead(SourcePath))
|
||||
using (var dest = File.OpenWrite(destination))
|
||||
@ -70,6 +70,7 @@ namespace Wabbajack.Lib.Downloaders
|
||||
var size = new FileInfo(SourcePath).Length;
|
||||
src.CopyToWithStatus(size, dest, "Copying from Game folder");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task<bool> Verify(Archive a)
|
||||
|
@ -44,10 +44,10 @@ namespace Wabbajack.Lib.Downloaders
|
||||
return whitelist.GoogleIDs.Contains(Id);
|
||||
}
|
||||
|
||||
public override async Task Download(Archive a, string destination)
|
||||
public override async Task<bool> Download(Archive a, string destination)
|
||||
{
|
||||
var state = await ToHttpState();
|
||||
await state.Download(a, destination);
|
||||
return await state.Download(a, destination);
|
||||
}
|
||||
|
||||
private async Task<HTTPDownloader.State> ToHttpState()
|
||||
|
@ -70,7 +70,7 @@ namespace Wabbajack.Lib.Downloaders
|
||||
return whitelist.AllowedPrefixes.Any(p => Url.StartsWith(p));
|
||||
}
|
||||
|
||||
public override Task Download(Archive a, string destination)
|
||||
public override Task<bool> Download(Archive a, string destination)
|
||||
{
|
||||
return DoDownload(a, destination, true);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ namespace Wabbajack.Lib.Downloaders
|
||||
|
||||
public class State : HTTPDownloader.State
|
||||
{
|
||||
public override async Task Download(Archive a, string destination)
|
||||
public override async Task<bool> Download(Archive a, string destination)
|
||||
{
|
||||
var client = new MegaApiClient();
|
||||
Utils.Status("Logging into MEGA (as anonymous)");
|
||||
@ -35,6 +35,7 @@ namespace Wabbajack.Lib.Downloaders
|
||||
var node = client.GetNodeFromLink(fileLink);
|
||||
Utils.Status($"Downloading MEGA file: {a.Name}");
|
||||
client.DownloadFile(fileLink, destination);
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task<bool> Verify(Archive a)
|
||||
|
@ -80,7 +80,7 @@ namespace Wabbajack.Lib.Downloaders
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task Download(Archive a, string destination)
|
||||
public override async Task<bool> Download(Archive a, string destination)
|
||||
{
|
||||
var downloader = (ManualDownloader)GetDownloader();
|
||||
var absPath = Path.Combine(downloader._downloadfolder.Path, a.Name);
|
||||
@ -109,6 +109,7 @@ namespace Wabbajack.Lib.Downloaders
|
||||
downloader._watcher.EnableRaisingEvents = false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task<bool> Verify(Archive a)
|
||||
|
@ -31,10 +31,10 @@ namespace Wabbajack.Lib.Downloaders
|
||||
return whitelist.AllowedPrefixes.Any(p => Url.StartsWith(p));
|
||||
}
|
||||
|
||||
public override async Task Download(Archive a, string destination)
|
||||
public override async Task<bool> Download(Archive a, string destination)
|
||||
{
|
||||
var result = await Resolve();
|
||||
await result.Download(a, destination);
|
||||
return await result.Download(a, destination);
|
||||
}
|
||||
|
||||
public override async Task<bool> Verify(Archive a)
|
||||
|
@ -46,23 +46,25 @@ namespace Wabbajack.Lib.Downloaders
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task Download(Archive a, string destination)
|
||||
public override async Task<bool> Download(Archive a, string destination)
|
||||
{
|
||||
var urls = await GetDownloadUrls();
|
||||
Utils.Log($"Found {urls.Length} ModDB mirrors for {a.Name}");
|
||||
foreach (var (url, idx) in urls.Zip(Enumerable.Range(0, urls.Length), (s, i) => (s, i))) {
|
||||
foreach (var (url, idx) in urls.Zip(Enumerable.Range(0, urls.Length), (s, i) => (s, i)))
|
||||
{
|
||||
try
|
||||
{
|
||||
await new HTTPDownloader.State {Url = url}.Download(a, destination);
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception)
|
||||
{
|
||||
if (idx == urls.Length - 1)
|
||||
throw;
|
||||
Utils.Log($"Download from {url} failed, trying next mirror");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private async Task<string[]> GetDownloadUrls()
|
||||
|
@ -136,7 +136,7 @@ namespace Wabbajack.Lib.Downloaders
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task Download(Archive a, string destination)
|
||||
public override async Task<bool> Download(Archive a, string destination)
|
||||
{
|
||||
string url;
|
||||
try
|
||||
@ -147,16 +147,15 @@ namespace Wabbajack.Lib.Downloaders
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utils.Log($"{a.Name} - Error getting Nexus download URL - {ex.Message}");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
Utils.Log($"Downloading Nexus Archive - {a.Name} - {GameName} - {ModID} - {FileID}");
|
||||
|
||||
await new HTTPDownloader.State
|
||||
return await new HTTPDownloader.State
|
||||
{
|
||||
Url = url
|
||||
}.Download(a, destination);
|
||||
|
||||
}
|
||||
|
||||
public override async Task<bool> Verify(Archive a)
|
||||
|
@ -49,7 +49,7 @@ namespace Wabbajack.Lib.Downloaders
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task Download(Archive a, string destination)
|
||||
public override async Task<bool> Download(Archive a, string destination)
|
||||
{
|
||||
var currentLib = Item.Game.Universe;
|
||||
|
||||
@ -77,6 +77,8 @@ namespace Wabbajack.Lib.Downloaders
|
||||
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task<bool> Verify(Archive a)
|
||||
|
Loading…
Reference in New Issue
Block a user