diff --git a/Wabbajack.Common/Hash.cs b/Wabbajack.Common/Hash.cs index 973dffc4..59420d1b 100644 --- a/Wabbajack.Common/Hash.cs +++ b/Wabbajack.Common/Hash.cs @@ -23,6 +23,9 @@ namespace Wabbajack.Common _code = code; } + + public bool IsValid => _code != 0; + public override string ToString() { return BitConverter.GetBytes(_code).ToBase64(); diff --git a/Wabbajack.Common/Paths.cs b/Wabbajack.Common/Paths.cs index b6f65494..1d2a15e3 100644 --- a/Wabbajack.Common/Paths.cs +++ b/Wabbajack.Common/Paths.cs @@ -23,7 +23,7 @@ namespace Wabbajack.Common public RelativePath FileName { get; } } - public struct AbsolutePath : IPath + public struct AbsolutePath : IPath, IComparable { #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, IComparable diff --git a/Wabbajack.Lib/Data.cs b/Wabbajack.Lib/Data.cs index e8bdeea1..80223fc5 100644 --- a/Wabbajack.Lib/Data.cs +++ b/Wabbajack.Lib/Data.cs @@ -271,7 +271,7 @@ namespace Wabbajack.Lib public class Archive { /// - /// MurMur3 Hash of the archive + /// xxHash64 of the archive /// [Key(0)] public Hash Hash { get; set; } diff --git a/Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs b/Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs index 3eb4dff3..ccc86f01 100644 --- a/Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs +++ b/Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs @@ -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(); + [IgnoreMember] public override object[] PrimaryKey { get diff --git a/Wabbajack.Lib/Downloaders/DownloadDispatcher.cs b/Wabbajack.Lib/Downloaders/DownloadDispatcher.cs index a2c6b140..c44629e9 100644 --- a/Wabbajack.Lib/Downloaders/DownloadDispatcher.cs +++ b/Wabbajack.Lib/Downloaders/DownloadDispatcher.cs @@ -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; diff --git a/Wabbajack.Lib/Downloaders/NexusDownloader.cs b/Wabbajack.Lib/Downloaders/NexusDownloader.cs index f4b133cf..45a7d8aa 100644 --- a/Wabbajack.Lib/Downloaders/NexusDownloader.cs +++ b/Wabbajack.Lib/Downloaders/NexusDownloader.cs @@ -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 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) diff --git a/Wabbajack.Lib/Downloaders/TESAllianceDownloader.cs b/Wabbajack.Lib/Downloaders/TESAllianceDownloader.cs index 3885c816..af45bd19 100644 --- a/Wabbajack.Lib/Downloaders/TESAllianceDownloader.cs +++ b/Wabbajack.Lib/Downloaders/TESAllianceDownloader.cs @@ -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{} } } diff --git a/Wabbajack.Lib/Downloaders/VectorPlexusDownloader.cs b/Wabbajack.Lib/Downloaders/VectorPlexusDownloader.cs index 43a5d551..1e471485 100644 --- a/Wabbajack.Lib/Downloaders/VectorPlexusDownloader.cs +++ b/Wabbajack.Lib/Downloaders/VectorPlexusDownloader.cs @@ -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 { } diff --git a/Wabbajack.Lib/Downloaders/YouTubeDownloader.cs b/Wabbajack.Lib/Downloaders/YouTubeDownloader.cs index cdb4a752..4131c244 100644 --- a/Wabbajack.Lib/Downloaders/YouTubeDownloader.cs +++ b/Wabbajack.Lib/Downloaders/YouTubeDownloader.cs @@ -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 Tracks { get; set; } = new List(); + + [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; } } diff --git a/Wabbajack.Test/DownloaderTests.cs b/Wabbajack.Test/DownloaderTests.cs index 787dfe97..437b5640 100644 --- a/Wabbajack.Test/DownloaderTests.cs +++ b/Wabbajack.Test/DownloaderTests.cs @@ -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() })); 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()); }