mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Fixing issue with Velopack Flow assets not being deserialized to the correct type
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using NuGet.Versioning;
|
||||
using Velopack.Sources;
|
||||
using System.Collections.Generic;
|
||||
@@ -29,6 +29,7 @@ namespace Velopack.Json
|
||||
[JsonSerializable(typeof(List<GithubRelease>))]
|
||||
[JsonSerializable(typeof(List<GitlabRelease>))]
|
||||
[JsonSerializable(typeof(VelopackAssetFeed))]
|
||||
[JsonSerializable(typeof(VelopackFlowReleaseAsset[]))]
|
||||
#if NET8_0_OR_GREATER
|
||||
[JsonSourceGenerationOptions(UseStringEnumConverter = true)]
|
||||
#endif
|
||||
@@ -38,7 +39,7 @@ namespace Velopack.Json
|
||||
|
||||
internal static class CompiledJson
|
||||
{
|
||||
private static readonly JsonSerializerOptions Options = new JsonSerializerOptions {
|
||||
private static readonly JsonSerializerOptions Options = new() {
|
||||
AllowTrailingCommas = true,
|
||||
ReadCommentHandling = JsonCommentHandling.Skip,
|
||||
PropertyNameCaseInsensitive = true,
|
||||
@@ -52,7 +53,7 @@ namespace Velopack.Json
|
||||
},
|
||||
};
|
||||
|
||||
private static readonly CompiledJsonSourceGenerationContext Context = new CompiledJsonSourceGenerationContext(Options);
|
||||
private static readonly CompiledJsonSourceGenerationContext Context = new(Options);
|
||||
|
||||
public static List<GithubRelease>? DeserializeGithubReleaseList(string json)
|
||||
{
|
||||
@@ -69,6 +70,11 @@ namespace Velopack.Json
|
||||
return JsonSerializer.Deserialize(json, Context.VelopackAssetArray);
|
||||
}
|
||||
|
||||
public static VelopackFlowReleaseAsset[]? DeserializeVelopackFlowAssetArray(string json)
|
||||
{
|
||||
return JsonSerializer.Deserialize(json, Context.VelopackFlowReleaseAssetArray);
|
||||
}
|
||||
|
||||
public static VelopackAssetFeed? DeserializeVelopackAssetFeed(string json)
|
||||
{
|
||||
return JsonSerializer.Deserialize(json, Context.VelopackAssetFeed);
|
||||
@@ -123,6 +129,11 @@ namespace Velopack.Json
|
||||
return JsonConvert.DeserializeObject<VelopackAsset[]>(json, Options);
|
||||
}
|
||||
|
||||
public static VelopackFlowReleaseAsset[]? DeserializeVelopackFlowAssetArray(string json)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<VelopackFlowReleaseAsset[]>(json, Options);
|
||||
}
|
||||
|
||||
public static VelopackAssetFeed? DeserializeVelopackAssetFeed(string json)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<VelopackAssetFeed>(json, Options);
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace Velopack.Sources
|
||||
|
||||
var json = await Downloader.DownloadString(uriAndQuery.ToString()).ConfigureAwait(false);
|
||||
|
||||
var releaseAssets = CompiledJson.DeserializeVelopackAssetArray(json);
|
||||
var releaseAssets = CompiledJson.DeserializeVelopackFlowAssetArray(json);
|
||||
return new VelopackAssetFeed() {
|
||||
Assets = releaseAssets
|
||||
};
|
||||
@@ -68,8 +68,8 @@ namespace Velopack.Sources
|
||||
public async Task DownloadReleaseEntry(ILogger logger, VelopackAsset releaseEntry, string localFile, Action<int> progress, CancellationToken cancelToken = default)
|
||||
{
|
||||
if (releaseEntry is null) throw new ArgumentNullException(nameof(releaseEntry));
|
||||
if (releaseEntry is not VelopackReleaseAsset velopackRelease) {
|
||||
throw new ArgumentException($"Expected {nameof(releaseEntry)} to be {nameof(VelopackReleaseAsset)} but was {releaseEntry.GetType().FullName}");
|
||||
if (releaseEntry is not VelopackFlowReleaseAsset velopackRelease) {
|
||||
throw new ArgumentException($"Expected {nameof(releaseEntry)} to be {nameof(VelopackFlowReleaseAsset)} but was {releaseEntry.GetType().FullName}");
|
||||
}
|
||||
if (localFile is null) throw new ArgumentNullException(nameof(localFile));
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace Velopack.Sources
|
||||
}
|
||||
}
|
||||
|
||||
internal record VelopackReleaseAsset : VelopackAsset
|
||||
internal record VelopackFlowReleaseAsset : VelopackAsset
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user