2021-09-27 12:42:46 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Net.Http;
|
|
|
|
using System.Net.Http.Json;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
using System.Text.Json.Serialization;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using static System.Runtime.InteropServices.RuntimeInformation;
|
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
namespace Wabbajack.CLI.DTOs;
|
|
|
|
|
2021-09-27 12:42:46 +00:00
|
|
|
// Root myDeserializedClass = JsonSerializer.Deserialize<Root>(myJsonResponse);
|
2021-10-23 16:51:17 +00:00
|
|
|
public class File
|
|
|
|
{
|
|
|
|
[JsonPropertyName("last_modified")] public DateTime LastModified { get; set; } = default!;
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
[JsonPropertyName("name")] public string Name { get; set; } = "";
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
[JsonPropertyName("sha1")] public string Sha1 { get; set; } = "";
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
[JsonPropertyName("size")] public int Size { get; set; }
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
[JsonPropertyName("type")] public string Type { get; set; } = "";
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public class Version
|
|
|
|
{
|
|
|
|
[JsonPropertyName("cef_version")] public string CefVersion { get; set; } = "";
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
[JsonPropertyName("channel")] public string Channel { get; set; } = "";
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
[JsonPropertyName("chromium_version")] public string ChromiumVersion { get; set; } = "";
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
[JsonPropertyName("files")] public List<File> Files { get; set; } = new();
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public class Linux32
|
|
|
|
{
|
|
|
|
[JsonPropertyName("versions")] public List<Version> Versions { get; set; } = new();
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public class Linux64
|
|
|
|
{
|
|
|
|
[JsonPropertyName("versions")] public List<Version> Versions { get; set; } = new();
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public class Linuxarm
|
|
|
|
{
|
|
|
|
[JsonPropertyName("versions")] public List<Version> Versions { get; set; } = new();
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public class Linuxarm64
|
|
|
|
{
|
|
|
|
[JsonPropertyName("versions")] public List<Version> Versions { get; set; } = new();
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public class Macosarm64
|
|
|
|
{
|
|
|
|
[JsonPropertyName("versions")] public List<Version> Versions { get; set; } = new();
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public class Macosx64
|
|
|
|
{
|
|
|
|
[JsonPropertyName("versions")] public List<Version> Versions { get; set; } = new();
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public class Windows32
|
|
|
|
{
|
|
|
|
[JsonPropertyName("versions")] public List<Version> Versions { get; set; } = new();
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public class Windows64
|
|
|
|
{
|
|
|
|
[JsonPropertyName("versions")] public List<Version> Versions { get; set; } = new();
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public class Windowsarm64
|
|
|
|
{
|
|
|
|
[JsonPropertyName("versions")] public List<Version> Versions { get; set; } = new();
|
|
|
|
}
|
|
|
|
|
|
|
|
public class CefCDNResponse
|
|
|
|
{
|
|
|
|
[JsonPropertyName("linux32")] public Linux32 Linux32 { get; set; } = new();
|
|
|
|
|
|
|
|
[JsonPropertyName("linux64")] public Linux64 Linux64 { get; set; } = new();
|
|
|
|
|
|
|
|
[JsonPropertyName("linuxarm")] public Linuxarm Linuxarm { get; set; } = new();
|
|
|
|
|
|
|
|
[JsonPropertyName("linuxarm64")] public Linuxarm64 Linuxarm64 { get; set; } = new();
|
|
|
|
|
|
|
|
[JsonPropertyName("macosarm64")] public Macosarm64 Macosarm64 { get; set; } = new();
|
|
|
|
|
|
|
|
[JsonPropertyName("macosx64")] public Macosx64 Macosx64 { get; set; } = new();
|
|
|
|
|
|
|
|
[JsonPropertyName("windows32")] public Windows32 Windows32 { get; set; } = new();
|
|
|
|
|
|
|
|
[JsonPropertyName("windows64")] public Windows64 Windows64 { get; set; } = new();
|
|
|
|
|
|
|
|
[JsonPropertyName("windowsarm64")] public Windowsarm64 Windowsarm64 { get; set; } = new();
|
|
|
|
|
|
|
|
public static async Task<CefCDNResponse> Load(HttpClient client)
|
2021-09-27 12:42:46 +00:00
|
|
|
{
|
2021-10-23 16:51:17 +00:00
|
|
|
return (await client.GetFromJsonAsync<CefCDNResponse>("https://cef-builds.spotifycdn.com/index.json"))!;
|
2021-09-27 12:42:46 +00:00
|
|
|
}
|
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public File FindSource(string downloadVersion)
|
2021-09-27 12:42:46 +00:00
|
|
|
{
|
2021-10-23 16:51:17 +00:00
|
|
|
var os = "";
|
|
|
|
if (IsOSPlatform(OSPlatform.Linux))
|
|
|
|
os = "Linux";
|
|
|
|
if (IsOSPlatform(OSPlatform.Windows))
|
|
|
|
os = "Windows";
|
|
|
|
if (IsOSPlatform(OSPlatform.OSX))
|
|
|
|
os = "OSX";
|
|
|
|
|
|
|
|
var tuple = (os, ProcessArchitecture);
|
|
|
|
|
|
|
|
List<Version> versions = new();
|
|
|
|
|
|
|
|
if (tuple == ("Linux", Architecture.X64)) versions = Linux64.Versions;
|
|
|
|
else if (tuple == ("Linux", Architecture.X86)) versions = Linux32.Versions;
|
|
|
|
else if (tuple == ("Windows", Architecture.X64)) versions = Windows64.Versions;
|
|
|
|
else if (tuple == ("OSX", Architecture.X64)) versions = Macosx64.Versions;
|
|
|
|
|
|
|
|
var version = versions.Where(v => v.CefVersion.StartsWith(downloadVersion + "."))
|
|
|
|
.OrderByDescending(v => v.ChromiumVersion)
|
|
|
|
.First();
|
|
|
|
return version.Files.First(f => f.Type == "client");
|
2021-09-27 12:42:46 +00:00
|
|
|
}
|
|
|
|
}
|