Fix a ton of warnings

This commit is contained in:
Halgari 2022-10-07 14:53:55 -06:00
parent b664da2059
commit 6bf098668a
17 changed files with 24 additions and 211 deletions

View File

@ -15,10 +15,7 @@ namespace Wabbajack.CLI;
public partial class CommandLineBuilder
{
private readonly IConsole _console;
private readonly IEnumerable<IVerb> _verbs;
private static IServiceProvider _provider;
public CommandLineBuilder(IServiceProvider provider, IConsole console, LoggingRateLimiterReporter _)
{
_provider = provider;

View File

@ -1,132 +0,0 @@
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;
namespace Wabbajack.CLI.DTOs;
// Root myDeserializedClass = JsonSerializer.Deserialize<Root>(myJsonResponse);
public class File
{
[JsonPropertyName("last_modified")] public DateTime LastModified { get; set; } = default!;
[JsonPropertyName("name")] public string Name { get; set; } = "";
[JsonPropertyName("sha1")] public string Sha1 { get; set; } = "";
[JsonPropertyName("size")] public int Size { get; set; }
[JsonPropertyName("type")] public string Type { get; set; } = "";
}
public class Version
{
[JsonPropertyName("cef_version")] public string CefVersion { get; set; } = "";
[JsonPropertyName("channel")] public string Channel { get; set; } = "";
[JsonPropertyName("chromium_version")] public string ChromiumVersion { get; set; } = "";
[JsonPropertyName("files")] public List<File> Files { get; set; } = new();
}
public class Linux32
{
[JsonPropertyName("versions")] public List<Version> Versions { get; set; } = new();
}
public class Linux64
{
[JsonPropertyName("versions")] public List<Version> Versions { get; set; } = new();
}
public class Linuxarm
{
[JsonPropertyName("versions")] public List<Version> Versions { get; set; } = new();
}
public class Linuxarm64
{
[JsonPropertyName("versions")] public List<Version> Versions { get; set; } = new();
}
public class Macosarm64
{
[JsonPropertyName("versions")] public List<Version> Versions { get; set; } = new();
}
public class Macosx64
{
[JsonPropertyName("versions")] public List<Version> Versions { get; set; } = new();
}
public class Windows32
{
[JsonPropertyName("versions")] public List<Version> Versions { get; set; } = new();
}
public class Windows64
{
[JsonPropertyName("versions")] public List<Version> Versions { get; set; } = new();
}
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)
{
return (await client.GetFromJsonAsync<CefCDNResponse>("https://cef-builds.spotifycdn.com/index.json"))!;
}
public File FindSource(string downloadVersion)
{
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");
}
}

View File

@ -1,7 +1,6 @@
using System;
using System.CommandLine;
using System.CommandLine.IO;
using System.ComponentModel;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
@ -11,14 +10,9 @@ using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using NLog.Targets;
using Octokit;
using Wabbajack.CLI.TypeConverters;
using Wabbajack.CLI.Verbs;
using Wabbajack.DTOs.GitHub;
using Wabbajack.DTOs.Interventions;
using Wabbajack.Networking.Http;
using Wabbajack.Networking.Http.Interfaces;
using Wabbajack.Networking.WabbajackClientApi;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
using Wabbajack.Server.Lib;
using Wabbajack.Services.OSIntegrated;
@ -31,11 +25,6 @@ internal class Program
{
private static async Task<int> Main(string[] args)
{
TypeDescriptor.AddAttributes(typeof(AbsolutePath),
new TypeConverterAttribute(typeof(AbsolutePathTypeConverter)));
TypeDescriptor.AddAttributes(typeof(List),
new TypeConverterAttribute(typeof(ModListCategoryConverter)));
var host = Host.CreateDefaultBuilder(Array.Empty<string>())
.ConfigureLogging(AddLogging)
.ConfigureServices((host, services) =>

View File

@ -1,25 +0,0 @@
using System;
using System.ComponentModel;
using System.Globalization;
using Wabbajack.Paths;
namespace Wabbajack.CLI.TypeConverters;
public class AbsolutePathTypeConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value,
Type destinationType)
{
return (AbsolutePath) (string) value;
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
return (AbsolutePath) (string) value;
}
}

View File

@ -1,25 +0,0 @@
using System;
using System.ComponentModel;
using System.Globalization;
using Wabbajack.DTOs.GitHub;
namespace Wabbajack.CLI.TypeConverters;
public class ModListCategoryConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value,
Type destinationType)
{
throw new NotImplementedException();
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
return Enum.Parse<List>((string) value);
}
}

View File

@ -27,14 +27,13 @@ public class ListGames : IVerb
public static VerbDefinition Definition = new VerbDefinition("list-games",
"Lists all games Wabbajack recognizes, and their installed versions/locations (if any)", Array.Empty<OptionDefinition>());
internal async Task<int> Run(CancellationToken token)
internal Task<int> Run(CancellationToken token)
{
foreach (var game in GameRegistry.Games.OrderBy(g => g.Value.HumanFriendlyGameName))
{
if (_locator.IsInstalled(game.Key))
{
var location = _locator.GameLocation(game.Key);
var version = "unknown";
var mainFile = game.Value.MainExecutable!.Value.RelativeTo(location);
if (!mainFile.FileExists())
@ -50,6 +49,6 @@ public class ListGames : IVerb
}
}
return 0;
return Task.FromResult(0);
}
}

View File

@ -7,7 +7,6 @@ using System.Threading;
using System.Threading.Tasks;
using FluentFTP.Helpers;
using Microsoft.Extensions.Logging;
using Wabbajack.Downloaders.Bethesda;
using Wabbajack.DTOs;
using Wabbajack.Networking.WabbajackClientApi;
@ -17,7 +16,6 @@ public class ListModlists : IVerb
{
private readonly ILogger<ListCreationClubContent> _logger;
private readonly Client _client;
private readonly BethesdaDownloader _downloader;
public ListModlists(ILogger<ListCreationClubContent> logger, Client wjClient)
{

View File

@ -6,6 +6,7 @@ using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Nettle;
@ -37,8 +38,8 @@ public class ModlistReport : IVerb
private static async Task<string> ReportTemplate(object o)
{
var data = (typeof(ModlistReport).Assembly.GetManifestResourceStream("Wabbajack.CLI.Resources.ModlistReport.html")!).ReadAllText();
var func = NettleEngine.GetCompiler().Compile(data);
var data = await (typeof(ModlistReport).Assembly.GetManifestResourceStream("Wabbajack.CLI.Resources.ModlistReport.html")!).ReadAllAsync();
var func = NettleEngine.GetCompiler().Compile(Encoding.UTF8.GetString(data));
return func(o);
}

View File

@ -665,7 +665,7 @@ public class ValidateLists : IVerb
};
await using var tempFile = _temporaryFileManager.CreateFile(Ext.Wabbajack);
_logger.LogInformation("Downloading {primaryKeyString}", state.PrimaryKeyString);
_logger.LogInformation("Downloading {primaryKeyString}", state!.PrimaryKeyString);
var hash = await _dispatcher.Download(archive, tempFile.Path, token);
if (hash != modList.DownloadMetadata.Hash)

View File

@ -7,7 +7,7 @@ namespace Wabbajack.Hashing.xxHash64;
public static class ByteArrayExtensions
{
public static async ValueTask<Hash> Hash(this byte[] data, IJob job = null)
public static async ValueTask<Hash> Hash(this byte[] data, IJob? job = null)
{
return await new MemoryStream(data).HashingCopy(Stream.Null, CancellationToken.None, job);
}

View File

@ -6,6 +6,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<NoWarn>CS8600,CS8601,CS8618,CS8604</NoWarn>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60">
<HintPath>..\..\..\Program Files\dotnet\shared\Microsoft.AspNetCore.App\6.0.1\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>

View File

@ -7,6 +7,10 @@
<Version>$(VERSION)</Version>
</PropertyGroup>
<PropertyGroup>
<NoWarn>CS8600,CS8601,CS8618,CS8604</NoWarn>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Wabbajack.Networking.Http.Interfaces\Wabbajack.Networking.Http.Interfaces.csproj" />
</ItemGroup>

View File

@ -18,7 +18,6 @@ public class Client
private readonly GitHubClient _client;
private readonly DTOSerializer _dtos;
private readonly ILogger<Client> _logger;
private readonly GithubAuthTokenProvider _token;
private readonly HttpClient _httpClient;
public Client(ILogger<Client> logger, DTOSerializer dtos, GitHubClient client, HttpClient httpClient)

View File

@ -5,7 +5,7 @@ namespace Wabbajack.Networking.GitHub;
public abstract class GithubAuthTokenProvider : ITokenProvider<string>
{
public abstract ValueTask<string> Get();
public abstract ValueTask<string?> Get();
public abstract ValueTask SetToken(string val);
public abstract ValueTask<bool> Delete();
public abstract bool HaveToken();

View File

@ -7,6 +7,10 @@
<Version>$(VERSION)</Version>
</PropertyGroup>
<PropertyGroup>
<NoWarn>CS8600,CS8601,CS8618,CS8604</NoWarn>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Wabbajack.DTOs\Wabbajack.DTOs.csproj" />
<ProjectReference Include="..\Wabbajack.Networking.Http.Interfaces\Wabbajack.Networking.Http.Interfaces.csproj" />

View File

@ -155,7 +155,7 @@ public struct AbsolutePath : IPath, IComparable<AbsolutePath>, IEquatable<Absolu
return ArrayExtensions.AreEqualIgnoreCase(parent.Parts, 0, Parts, 0, parent.Parts.Length);
}
public readonly AbsolutePath Combine(params object[] paths)
public AbsolutePath Combine(params object[] paths)
{
var converted = paths.Select(p =>
{
@ -215,7 +215,7 @@ public struct AbsolutePath : IPath, IComparable<AbsolutePath>, IEquatable<Absolu
{
return (AbsolutePath) value;
}
catch (Exception ex)
catch (Exception)
{
return default;
}

View File

@ -10,7 +10,7 @@ public static class ArrayExtensions
if (startB + length > (b?.Length ?? 0)) return false;
for (var i = 0; i < length; i++)
if (!a[startA + i]!.Equals(b[startB + i]))
if (!a![startA + i]!.Equals(b![startB + i]))
return false;
return true;
}
@ -22,7 +22,7 @@ public static class ArrayExtensions
if (startB + length > (b?.Length ?? 0)) return false;
for (var i = 0; i < length; i++)
if (!a[startA + i]!.Equals(b[startB + i], StringComparison.InvariantCultureIgnoreCase))
if (!a![startA + i]!.Equals(b![startB + i], StringComparison.InvariantCultureIgnoreCase))
return false;
return true;
}