mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
All downloader tests pass
This commit is contained in:
parent
723f624d7a
commit
9d3af1db5c
@ -23,6 +23,9 @@ namespace Wabbajack.Common
|
||||
_code = code;
|
||||
}
|
||||
|
||||
|
||||
public bool IsValid => _code != 0;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return BitConverter.GetBytes(_code).ToBase64();
|
||||
|
@ -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>
|
||||
|
@ -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; }
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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>{}
|
||||
}
|
||||
}
|
||||
|
@ -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>
|
||||
{
|
||||
}
|
||||
|
@ -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; }
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user