add logo downloader for modlist metadata

This commit is contained in:
Timothy Baldridge 2019-10-16 17:05:51 -06:00
parent 12cffd20cd
commit 7bc08df9bb
4 changed files with 35 additions and 1 deletions

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using Newtonsoft.Json;
using Wabbajack.Common;
@ -92,7 +93,7 @@ namespace Wabbajack.Lib.Downloaders
}
;
if (stream.IsFaulted)
if (stream.IsFaulted || response.StatusCode != HttpStatusCode.OK)
{
Utils.Log($"While downloading {Url} - {stream.Exception.ExceptionToString()}");
return false;

View File

@ -5,10 +5,13 @@ using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
using Wabbajack.Common;
using Wabbajack.Lib.Downloaders;
using Wabbajack.Lib.Validation;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
using File = System.IO.File;
using Game = Wabbajack.Common.Game;
namespace Wabbajack.Lib.ModListRegistry
@ -40,6 +43,9 @@ namespace Wabbajack.Lib.ModListRegistry
/// </summary>
public string LogoUrl { get; set; }
[YamlIgnore]
public BitmapSource Logo { get; set; }
/// <summary>
/// Download URL
/// </summary>
@ -57,5 +63,14 @@ namespace Wabbajack.Lib.ModListRegistry
return d.Deserialize<List<ModlistMetadata>>(result);
}
}
public ModlistMetadata LoadLogo()
{
// Todo: look at making this stream based instead of requiring a file
var temp_file = Path.GetTempFileName();
DownloadDispatcher.ResolveArchive(LogoUrl).Download(new Archive {Name = LogoUrl}, temp_file);
Logo = new BitmapImage(new Uri(temp_file));
return this;
}
}
}

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Wabbajack.Lib.Downloaders;
using Wabbajack.Lib.ModListRegistry;
namespace Wabbajack.Test
@ -17,5 +18,21 @@ namespace Wabbajack.Test
var modlists = ModlistMetadata.LoadFromGithub();
Assert.IsTrue(modlists.Count > 0);
}
[TestMethod]
public void VerifyLogoURLs()
{
var modlists = ModlistMetadata.LoadFromGithub();
foreach (var modlist in modlists)
{
var logo_state = DownloadDispatcher.ResolveArchive(modlist.LogoUrl);
Assert.IsNotNull(logo_state);
Assert.IsTrue(logo_state.Verify(), $"{modlist.LogoUrl} is not valid");
modlist.LoadLogo();
Assert.IsNotNull(modlist.Logo);
}
}
}
}

View File

@ -68,6 +68,7 @@
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />