All downloader tests pass

This commit is contained in:
Timothy Baldridge 2020-03-26 21:10:23 -06:00
parent 723f624d7a
commit 9d3af1db5c
10 changed files with 59 additions and 11 deletions

View File

@ -23,6 +23,9 @@ namespace Wabbajack.Common
_code = code;
}
public bool IsValid => _code != 0;
public override string ToString()
{
return BitConverter.GetBytes(_code).ToBase64();

View File

@ -23,7 +23,7 @@ namespace Wabbajack.Common
public RelativePath FileName { get; }
}
public struct AbsolutePath : IPath
public struct AbsolutePath : IPath, IComparable<AbsolutePath>
{
#region ObjectEquality
@ -59,6 +59,11 @@ namespace Wabbajack.Common
return _path != null ? _path.GetHashCode() : 0;
}
public override string ToString()
{
return _path;
}
private readonly string _path;
public AbsolutePath(string path)
@ -330,6 +335,11 @@ namespace Wabbajack.Common
{
WriteAllText(string.Join("\n",strings));
}
public int CompareTo(AbsolutePath other)
{
return string.Compare(_path, other._path, StringComparison.Ordinal);
}
}
public struct RelativePath : IPath, IEquatable<RelativePath>, IComparable<RelativePath>

View File

@ -271,7 +271,7 @@ namespace Wabbajack.Lib
public class Archive
{
/// <summary>
/// MurMur3 Hash of the archive
/// xxHash64 of the archive
/// </summary>
[Key(0)]
public Hash Hash { get; set; }

View File

@ -92,12 +92,14 @@ namespace Wabbajack.Lib.Downloaders
private static bool IsHTTPS => Downloader.SiteURL.AbsolutePath.StartsWith("https://");
private static string URLPrefix => IsHTTPS ? "https://" : "http://";
[IgnoreMember]
public static string Site => string.IsNullOrWhiteSpace(Downloader.SiteURL.Query)
? $"{URLPrefix}{Downloader.SiteURL.Host}"
: Downloader.SiteURL.ToString();
public static AbstractNeedsLoginDownloader Downloader => (AbstractNeedsLoginDownloader)(object)DownloadDispatcher.GetInstance<TDownloader>();
[IgnoreMember]
public override object[] PrimaryKey
{
get

View File

@ -143,7 +143,7 @@ namespace Wabbajack.Lib.Downloaders
var result = await archive.State.Download(archive, destination);
if (!result) return false;
if (archive.Hash == null) return true;
if (!archive.Hash.IsValid) return true;
var hash = await destination.FileHashCachedAsync();
if (hash == archive.Hash) return true;

View File

@ -3,6 +3,7 @@ using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using System.Threading.Tasks;
using MessagePack;
using MongoDB.Bson.Serialization.Attributes;
using ReactiveUI;
using Wabbajack.Common;
@ -119,31 +120,44 @@ namespace Wabbajack.Lib.Downloaders
}
[BsonIgnoreExtraElements]
[MessagePackObject]
public class State : AbstractDownloadState, IMetaState
{
[IgnoreMember]
public Uri URL => new Uri($"http://nexusmods.com/{NexusApiUtils.ConvertGameName(GameName)}/mods/{ModID}");
[Key(0)]
public string Name { get; set; }
[Key(1)]
public string Author { get; set; }
[Key(2)]
public string Version { get; set; }
[Key(3)]
public string ImageURL { get; set; }
[Key(4)]
public bool IsNSFW { get; set; }
[Key(5)]
public string Description { get; set; }
[Key(6)]
public string GameName { get; set; }
[Key(7)]
public string ModID { get; set; }
[Key(8)]
public string FileID { get; set; }
public async Task<bool> LoadMetaData()
{
return true;
}
public string GameName { get; set; }
public string ModID { get; set; }
public string FileID { get; set; }
[IgnoreMember]
public override object[] PrimaryKey { get => new object[]{GameName, ModID, FileID};}
public override bool IsWhitelisted(ServerWhitelist whitelist)

View File

@ -1,4 +1,5 @@
using System;
using MessagePack;
namespace Wabbajack.Lib.Downloaders
{
@ -15,6 +16,7 @@ namespace Wabbajack.Lib.Downloaders
{
}
[MessagePackObject]
public class State : State<TESAllianceDownloader>{}
}
}

View File

@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using MessagePack;
namespace Wabbajack.Lib.Downloaders
{
@ -15,6 +16,8 @@ namespace Wabbajack.Lib.Downloaders
"vectorplexus", "vectorplexus.com")
{
}
[MessagePackObject]
public class State : State<VectorPlexusDownloader>
{
}

View File

@ -7,6 +7,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using MessagePack;
using Wabbajack.Common;
using Wabbajack.Lib.Validation;
using YoutubeExplode;
@ -58,12 +59,19 @@ namespace Wabbajack.Lib.Downloaders
{
}
[MessagePackObject]
public class State : AbstractDownloadState
{
[Key(0)]
public string Key { get; set; }
[Key(1)]
public List<Track> Tracks { get; set; } = new List<Track>();
[IgnoreMember]
public override object[] PrimaryKey => new object[] {Key};
[MessagePackObject]
public class Track
{
public enum FormatEnum
@ -71,9 +79,16 @@ namespace Wabbajack.Lib.Downloaders
XWM,
WAV
}
[Key(0)]
public FormatEnum Format { get; set; }
[Key(1)]
public string Name { get; set; }
[Key(2)]
public TimeSpan Start { get; set; }
[Key(3)]
public TimeSpan End { get; set; }
}

View File

@ -456,15 +456,14 @@ namespace Wabbajack.Test
var converted = state.ViaJSON();
var converted = RoundTripState(state);
Assert.True(await converted.Verify(new Archive {Name = "yt_test.zip"}));
Assert.True(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>() }));
using var tempFile = new TempFile();
await converted.Download(new Archive {Name = "yt_test.zip"}, tempFile.Path);
File.Copy(tempFile.File.FullName, "c:\\tmp\\" + Path.GetFileName(tempFile.File.FullName) + ".zip");
Assert.Equal(Hash.FromBase64("kD36zbA2X9Q="), await tempFile.Path.FileHashAsync());
Assert.Equal(Hash.FromBase64("H166oHG0wpY="), await tempFile.Path.FileHashAsync());
}