From 2d8670cf986bd2dcbf547a6b5c4a413d76482e8a Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Thu, 9 Jun 2022 15:05:26 -0600 Subject: [PATCH] Fix Moddb streamer --- .../ModDBDownloader.cs | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/Wabbajack.Downloaders.ModDB/ModDBDownloader.cs b/Wabbajack.Downloaders.ModDB/ModDBDownloader.cs index 70399256b..ce6810143 100644 --- a/Wabbajack.Downloaders.ModDB/ModDBDownloader.cs +++ b/Wabbajack.Downloaders.ModDB/ModDBDownloader.cs @@ -75,24 +75,30 @@ public Uri UnParse(IDownloadState state) public async Task DownloadStream(Archive archive, Func> fn, CancellationToken token) { var state = archive.State as DTOs.DownloadStates.ModDB; - var url = (await GetDownloadUrls(state!)).First(); - try + foreach (var url in await GetDownloadUrls(state!)) { - var msg = new HttpRequestMessage + try { - Method = HttpMethod.Get, - RequestUri = new Uri(url) - }; - using var response = await _httpClient.SendAsync(msg, token); - HttpException.ThrowOnFailure(response); - await using var stream = await response.Content.ReadAsStreamAsync(token); - return await fn(stream); - } - catch (Exception ex) - { - _logger.LogError(ex, "While downloading from ModDB"); - throw; + var msg = new HttpRequestMessage + { + Method = HttpMethod.Get, + RequestUri = new Uri(url) + }; + using var response = await _httpClient.SendAsync(msg, HttpCompletionOption.ResponseHeadersRead, token); + if (!response.IsSuccessStatusCode) + continue; + HttpException.ThrowOnFailure(response); + await using var stream = await response.Content.ReadAsStreamAsync(token); + return await fn(stream); + } + catch (Exception ex) + { + _logger.LogError(ex, "While downloading from ModDB"); + throw; + } } + _logger.LogError("All servers were invalid downloading from ModDB {Uri}", state.Url); + return default; } public override async Task Download(Archive archive, DTOs.DownloadStates.ModDB state,