Fix build warnings

This commit is contained in:
genteure 2022-05-17 00:53:37 +08:00
parent d29471406b
commit 4ded913bc2
22 changed files with 72 additions and 64 deletions

View File

@ -147,7 +147,7 @@ namespace BililiveRecorder.Cli.Configure
table.AddRow(room.RoomId.ToString(), room.AutoRecord ? "[green]Enabled[/]" : "[red]Disabled[/]");
}
AnsiConsole.Render(table);
AnsiConsole.Write(table);
}
private static void AddRoom(ConfigV3 config)

View File

@ -179,7 +179,7 @@ namespace BililiveRecorder.Core.Config.V3
/// <summary>
/// 自定义脚本
/// </summary>
public string UserScript => this.GetPropertyValue<string>();
public string? UserScript => this.GetPropertyValue<string>();
}
@ -381,10 +381,10 @@ namespace BililiveRecorder.Core.Config.V3
/// <summary>
/// 自定义脚本
/// </summary>
public string UserScript { get => this.GetPropertyValue<string>(); set => this.SetPropertyValue(value); }
public string? UserScript { get => this.GetPropertyValue<string>(); set => this.SetPropertyValue(value); }
public bool HasUserScript { get => this.GetPropertyHasValue(nameof(this.UserScript)); set => this.SetPropertyHasValue<string>(value, nameof(this.UserScript)); }
[JsonProperty(nameof(UserScript)), EditorBrowsable(EditorBrowsableState.Never)]
public Optional<string> OptionalUserScript { get => this.GetPropertyValueOptional<string>(nameof(this.UserScript)); set => this.SetPropertyValueOptional(value, nameof(this.UserScript)); }
public Optional<string?> OptionalUserScript { get => this.GetPropertyValueOptional<string>(nameof(this.UserScript)); set => this.SetPropertyValueOptional(value, nameof(this.UserScript)); }
}

View File

@ -52,7 +52,9 @@ namespace BililiveRecorder.Core
public event EventHandler<AggregatedRoomEventArgs<RecordFileClosedEventArgs>>? RecordFileClosed;
public event EventHandler<AggregatedRoomEventArgs<IOStatsEventArgs>>? IOStats;
public event EventHandler<AggregatedRoomEventArgs<RecordingStatsEventArgs>>? RecordingStats;
#pragma warning disable CS0067 // The event 'Recorder.PropertyChanged' is never used
public event PropertyChangedEventHandler? PropertyChanged;
#pragma warning restore CS0067 // The event 'Recorder.PropertyChanged' is never used
public ConfigV3 Config { get; }

View File

@ -97,7 +97,7 @@ namespace BililiveRecorder.Core.Recording
this.timer.Stop();
this.RequestStop();
RecordFileClosedEventArgs recordFileClosedEvent;
RecordFileClosedEventArgs? recordFileClosedEvent;
if (this.fileOpeningEventArgs is { } openingEventArgs)
recordFileClosedEvent = new RecordFileClosedEventArgs(this.room)
{

View File

@ -31,10 +31,10 @@ namespace BililiveRecorder.Core.Scripting.Runtime
? throw new JavaScriptException(this._engine.Realm.Intrinsics.Error, "The provided value is not of type 'RequestInit'.")
: arg1;
HttpClientHandler handler = new HttpClientHandler();
HttpClient? httpClient = new HttpClient(handler);
var handler = new HttpClientHandler();
var httpClient = new HttpClient(handler);
var requestMessage = new HttpRequestMessage(HttpMethod.Get, urlString.ToString());
bool throwOnRedirect = false;
var throwOnRedirect = false;
if (initObject is not null)
{
@ -101,7 +101,6 @@ namespace BililiveRecorder.Core.Scripting.Runtime
}
#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
#pragma warning disable VSTHRD104 // Offer async methods
var resp = httpClient.SendAsync(requestMessage).Result;
if (throwOnRedirect && (resp.StatusCode is (HttpStatusCode)301 or (HttpStatusCode)302 or (HttpStatusCode)303 or (HttpStatusCode)307 or (HttpStatusCode)308))
@ -110,7 +109,6 @@ namespace BililiveRecorder.Core.Scripting.Runtime
}
var respString = resp.Content.ReadAsStringAsync().Result;
#pragma warning restore VSTHRD104 // Offer async methods
#pragma warning restore VSTHRD002 // Avoid problematic synchronous waits
var respHeaders = new ObjectInstance(this._engine);

View File

@ -73,7 +73,7 @@ globalThis.recorderEvents = {};
return null;
}
var parser = new JavaScriptParser(source, new ParserOptions("userscript.js"));
var parser = new JavaScriptParser(source!, new ParserOptions("userscript.js"));
var script = parser.ParseScript();
this.cachedScript = script;

View File

@ -25,13 +25,13 @@ namespace BililiveRecorder.ToolBox.Tool.Analyze
public void PrintToConsole()
{
if (this.NeedFix)
AnsiConsole.Render(new FigletText("Need Fix").Color(Color.Red));
AnsiConsole.Write(new FigletText("Need Fix").Color(Color.Red));
else
AnsiConsole.Render(new FigletText("All Good").Color(Color.Green));
AnsiConsole.Write(new FigletText("All Good").Color(Color.Green));
if (this.Unrepairable)
{
AnsiConsole.Render(new Panel("This file contains error(s) that are identified as unrepairable (yet).\n" +
AnsiConsole.Write(new Panel("This file contains error(s) that are identified as unrepairable (yet).\n" +
"Please check if you're using the newest version.\n" +
"Please consider send a sample file to the developer.")
{
@ -41,7 +41,7 @@ namespace BililiveRecorder.ToolBox.Tool.Analyze
});
}
AnsiConsole.Render(new Panel(this.InputPath.EscapeMarkup())
AnsiConsole.Write(new Panel(this.InputPath.EscapeMarkup())
{
Header = new PanelHeader("Input"),
Border = BoxBorder.Rounded
@ -49,7 +49,7 @@ namespace BililiveRecorder.ToolBox.Tool.Analyze
AnsiConsole.MarkupLine("Will output [lime]{0}[/] file(s) if repaired", this.OutputFileCount);
AnsiConsole.Render(new Table()
AnsiConsole.Write(new Table()
.Border(TableBorder.Rounded)
.AddColumns("Category", "Count")
.AddRow("Unrepairable", this.IssueTypeUnrepairable.ToString())

View File

@ -16,7 +16,9 @@ namespace BililiveRecorder.ToolBox.Tool.DanmakuMerger
public string Name => "Merge Danmaku";
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
public async Task<CommandResponse<DanmakuMergerResponse>> Handle(DanmakuMergerRequest request, CancellationToken cancellationToken, ProgressCallback? progress)
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
{
var inputLength = request.Inputs.Length;
@ -90,16 +92,16 @@ namespace BililiveRecorder.ToolBox.Tool.DanmakuMerger
{
// 使用传递进来的参数作为时间差
timeDiff = request.Offsets.Select(x => TimeSpan.FromSeconds(x)).ToArray();
var b = startTimes[Array.IndexOf(timeDiff, timeDiff.Min())];
recordInfo = b.element;
baseTime = b.time;
var (time, element) = startTimes[Array.IndexOf(timeDiff, timeDiff.Min())];
recordInfo = element;
baseTime = time;
}
else
{
// 使用文件内的开始时间作为时间差
var b = startTimes.OrderBy(x => x.time).First();
recordInfo = b.element;
baseTime = b.time;
var (time, element) = startTimes.OrderBy(x => x.time).First();
recordInfo = element;
baseTime = time;
timeDiff = startTimes.Select(x => x.time - baseTime).ToArray();
}
}

View File

@ -12,7 +12,9 @@ namespace BililiveRecorder.ToolBox.Tool.DanmakuStartTime
{
public string Name => "Read Danmaku start_time";
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
public async Task<CommandResponse<DanmakuStartTimeResponse>> Handle(DanmakuStartTimeRequest request, CancellationToken cancellationToken, ProgressCallback? progress)
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
{
List<DanmakuStartTimeResponse.DanmakuStartTime> result = new();

View File

@ -18,7 +18,7 @@ namespace BililiveRecorder.ToolBox.Tool.DanmakuStartTime
t.AddRow(item.StartTime.ToString().EscapeMarkup(), item.Path.EscapeMarkup());
}
AnsiConsole.Render(t);
AnsiConsole.Write(t);
}
public class DanmakuStartTime

View File

@ -27,11 +27,11 @@ namespace BililiveRecorder.ToolBox.Tool.Fix
public void PrintToConsole()
{
AnsiConsole.Render(new FigletText("Done").Color(Color.Green));
AnsiConsole.Write(new FigletText("Done").Color(Color.Green));
if (this.Unrepairable)
{
AnsiConsole.Render(new Panel("This file contains error(s) that are identified as unrepairable (yet).\n" +
AnsiConsole.Write(new Panel("This file contains error(s) that are identified as unrepairable (yet).\n" +
"Please check if you're using the newest version.\n" +
"Please consider send a sample file to the developer.")
{
@ -41,7 +41,7 @@ namespace BililiveRecorder.ToolBox.Tool.Fix
});
}
AnsiConsole.Render(new Panel(this.InputPath.EscapeMarkup())
AnsiConsole.Write(new Panel(this.InputPath.EscapeMarkup())
{
Header = new PanelHeader("Input"),
Border = BoxBorder.Rounded
@ -54,9 +54,9 @@ namespace BililiveRecorder.ToolBox.Tool.Fix
for (var i = 0; i < this.OutputPaths.Length; i++)
table_output.AddRow(this.OutputPaths[i].EscapeMarkup());
AnsiConsole.Render(table_output);
AnsiConsole.Write(table_output);
AnsiConsole.Render(new Table()
AnsiConsole.Write(new Table()
.Border(TableBorder.Rounded)
.AddColumns("Category", "Count")
.AddRow("Unrepairable", this.IssueTypeUnrepairable.ToString())

View File

@ -86,7 +86,9 @@ namespace BililiveRecorder.ToolBox
{
var t = ctx.AddTask(handler.Name);
t.MaxValue = 1d;
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
var r = await handler.Handle(request, default, async p => t.Value = p).ConfigureAwait(false);
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
t.Value = 1d;
return r;
})
@ -107,7 +109,7 @@ namespace BililiveRecorder.ToolBox
}
else
{
AnsiConsole.Render(new FigletText("Error").Color(Color.Red));
AnsiConsole.Write(new FigletText("Error").Color(Color.Red));
var errorInfo = new Table
{
@ -116,10 +118,10 @@ namespace BililiveRecorder.ToolBox
errorInfo.AddColumn(new TableColumn("Error Code").Centered());
errorInfo.AddColumn(new TableColumn("Error Message").Centered());
errorInfo.AddRow("[red]" + response.Status.ToString().EscapeMarkup() + "[/]", "[red]" + (response.ErrorMessage ?? string.Empty) + "[/]");
AnsiConsole.Render(errorInfo);
AnsiConsole.Write(errorInfo);
if (response.Exception is not null)
AnsiConsole.Render(new Panel(response.Exception.GetRenderable(ExceptionFormats.ShortenPaths | ExceptionFormats.ShowLinks))
AnsiConsole.Write(new Panel(response.Exception.GetRenderable(ExceptionFormats.ShortenPaths | ExceptionFormats.ShowLinks))
{
Header = new PanelHeader("Exception Info"),
Border = BoxBorder.Rounded

View File

@ -1,16 +1,13 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
#nullable enable
namespace BililiveRecorder.WPF.Models
{
public class AboutModel : INotifyPropertyChanged
{
#pragma warning disable CS0067 // The event 'Recorder.PropertyChanged' is never used
public event PropertyChangedEventHandler? PropertyChanged;
#pragma warning restore CS0067 // The event 'Recorder.PropertyChanged' is never used
public string InformationalVersion => GitVersionInformation.InformationalVersion;
}

View File

@ -45,7 +45,7 @@ namespace BililiveRecorder.WPF
internal void CloseWithoutConfirmAction()
{
this.CloseConfirmed = true;
this.Dispatcher.BeginInvoke(this.Close, DispatcherPriority.Normal);
_ = this.Dispatcher.BeginInvoke(this.Close, DispatcherPriority.Normal);
}
internal void SuperActivateAction()

View File

@ -41,7 +41,7 @@ namespace BililiveRecorder.WPF.Pages
private int SettingsClickCount = 0;
internal static IServiceProvider? ServiceProvider { get; private set; }
private ServiceProvider serviceProvider;
private ServiceProvider serviceProvider = null!;
internal RootModel Model { get; private set; }
internal static Action? SwitchToSettingsPage { get; private set; }

View File

@ -44,7 +44,9 @@ namespace BililiveRecorder.WPF.Pages
this.CalculateOffsets();
}
#pragma warning disable VSTHRD100 // Avoid async void methods
private async void DragDrop(object sender, DragEventArgs e)
#pragma warning restore VSTHRD100 // Avoid async void methods
{
try
{
@ -58,7 +60,9 @@ namespace BililiveRecorder.WPF.Pages
{ }
}
#pragma warning disable VSTHRD100 // Avoid async void methods
private async void AddFile_Click(object sender, RoutedEventArgs e)
#pragma warning restore VSTHRD100 // Avoid async void methods
{
var d = new CommonOpenFileDialog
{
@ -112,7 +116,9 @@ namespace BililiveRecorder.WPF.Pages
this.listView.DataContext = this.Files;
}
#pragma warning disable VSTHRD100 // Avoid async void methods
private async void Merge_Click(object sender, RoutedEventArgs e)
#pragma warning restore VSTHRD100 // Avoid async void methods
{
AutoFixProgressDialog? progressDialog = null;

View File

@ -64,7 +64,7 @@ namespace BililiveRecorder.Web.Models
public Optional<uint>? OptionalRecordDanmakuFlushInterval { get; set; }
public Optional<bool>? OptionalNetworkTransportUseSystemProxy { get; set; }
public Optional<AllowedAddressFamily>? OptionalNetworkTransportAllowedAddressFamily { get; set; }
public Optional<string>? OptionalUserScript { get; set; }
public Optional<string?>? OptionalUserScript { get; set; }
public void ApplyTo(GlobalConfig config)
{
@ -140,7 +140,7 @@ namespace BililiveRecorder.Web.Models.Rest
public Optional<uint> OptionalRecordDanmakuFlushInterval { get; set; }
public Optional<bool> OptionalNetworkTransportUseSystemProxy { get; set; }
public Optional<AllowedAddressFamily> OptionalNetworkTransportAllowedAddressFamily { get; set; }
public Optional<string> OptionalUserScript { get; set; }
public Optional<string?> OptionalUserScript { get; set; }
}
}

View File

@ -237,7 +237,7 @@ export const data: Array<ConfigEntry> = [
{
name: "UserScript",
description: "自定义脚本",
type: "string",
type: "string?",
defaultValue: "string.Empty",
configType: "globalOnly",
advancedConfig: true,

View File

@ -1,11 +1,7 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using BililiveRecorder.Core.Api;
using BililiveRecorder.Core.Api.Danmaku;
using BililiveRecorder.Core.Api.Http;
using Newtonsoft.Json.Linq;
using Xunit;
namespace BililiveRecorder.Core.UnitTests.Danmaku
@ -15,7 +11,7 @@ namespace BililiveRecorder.Core.UnitTests.Danmaku
[Fact(Skip = "skip")]
public async Task TestAsync()
{
var client = new DanmakuClient(new HttpApiClient(null!), null);
var client = new DanmakuClient(new HttpApiClient(null!), null!);
client.StatusChanged += this.Client_StatusChanged;
client.DanmakuReceived += this.Client_DanmakuReceived;
@ -28,11 +24,11 @@ namespace BililiveRecorder.Core.UnitTests.Danmaku
// await Task.Delay(TimeSpan.FromMinutes(5)).ConfigureAwait(false);
}
private void Client_DanmakuReceived(object sender, DanmakuReceivedEventArgs e)
private void Client_DanmakuReceived(object? sender, DanmakuReceivedEventArgs e)
{
}
private void Client_StatusChanged(object sender, StatusChangedEventArgs e)
private void Client_StatusChanged(object? sender, StatusChangedEventArgs e)
{
}
}

View File

@ -169,7 +169,7 @@ namespace BililiveRecorder.Core.Config.V3
[Newtonsoft.Json.JsonProperty("TimingWatchdogTimeout")]
public HierarchicalPropertyDefault.Optional<uint> OptionalTimingWatchdogTimeout { get; set; }
[Newtonsoft.Json.JsonProperty("UserScript")]
public HierarchicalPropertyDefault.Optional<string> OptionalUserScript { get; set; }
public HierarchicalPropertyDefault.Optional<string?> OptionalUserScript { get; set; }
[Newtonsoft.Json.JsonProperty("WebHookUrls")]
public HierarchicalPropertyDefault.Optional<string?> OptionalWebHookUrls { get; set; }
[Newtonsoft.Json.JsonProperty("WebHookUrlsV2")]
@ -190,7 +190,7 @@ namespace BililiveRecorder.Core.Config.V3
public uint TimingStreamRetry { get; set; }
public uint TimingStreamRetryNoQn { get; set; }
public uint TimingWatchdogTimeout { get; set; }
public string UserScript { get; set; }
public string? UserScript { get; set; }
public string? WebHookUrls { get; set; }
public string? WebHookUrlsV2 { get; set; }
public string? WorkDirectory { get; set; }
@ -256,7 +256,7 @@ namespace BililiveRecorder.Core.Config.V3
public uint TimingStreamRetry { get; }
public uint TimingStreamRetryNoQn { get; }
public uint TimingWatchdogTimeout { get; }
public string UserScript { get; }
public string? UserScript { get; }
public string? WebHookUrls { get; }
public string? WebHookUrlsV2 { get; }
public string? WorkDirectory { get; }

View File

@ -6,10 +6,8 @@ namespace BililiveRecorder.Flv.Tests
{
public static class AssertTags
{
public static void ShouldHaveLinearTimestamps(List<Tag> tags)
{
public static void ShouldHaveLinearTimestamps(List<Tag> tags) =>
Assert.True(tags.Any2((a, b) => (a.Timestamp <= b.Timestamp) && (b.Timestamp - a.Timestamp < 50)));
}
public static void ShouldHaveFullHeaderTags(List<Tag> tags)
{

View File

@ -84,17 +84,12 @@ namespace BililiveRecorder.Flv.Tests.RuleTests
this.Count = count;
}
public override bool Equals(object? obj)
{
return obj is CommentCount other &&
public override bool Equals(object? obj) =>
obj is CommentCount other &&
this.Type == other.Type &&
this.Count == other.Count;
}
public override int GetHashCode()
{
return HashCode.Combine(this.Type, this.Count);
}
public override int GetHashCode() => HashCode.Combine(this.Type, this.Count);
public void Deconstruct(out CommentType type, out int count)
{
@ -111,6 +106,16 @@ namespace BililiveRecorder.Flv.Tests.RuleTests
{
return new CommentCount(value.Item1, value.Item2);
}
public static bool operator ==(CommentCount left, CommentCount right)
{
return left.Equals(right);
}
public static bool operator !=(CommentCount left, CommentCount right)
{
return !(left == right);
}
}
}
}