From e6d7b2afe54f4be1d1b8f7c6b13e2f9a0785fc23 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Fri, 29 Sep 2023 17:59:31 +0300 Subject: [PATCH] Code fix --- .../BUTR.CrashReport.Bannerlord.Source.csproj | 1 + .../CrashReportHtmlRenderer.cs | 18 ++++++++---------- .../StringBuilderExtensions.cs | 10 +++++++--- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/BUTR.CrashReport.Bannerlord.Source/BUTR.CrashReport.Bannerlord.Source.csproj b/src/BUTR.CrashReport.Bannerlord.Source/BUTR.CrashReport.Bannerlord.Source.csproj index 9da0332..0ff4a6d 100644 --- a/src/BUTR.CrashReport.Bannerlord.Source/BUTR.CrashReport.Bannerlord.Source.csproj +++ b/src/BUTR.CrashReport.Bannerlord.Source/BUTR.CrashReport.Bannerlord.Source.csproj @@ -3,6 +3,7 @@ netstandard2.0 true + $(DefineConstants);BUTRCRASHREPORT_ENABLEWARNINGS diff --git a/src/BUTR.CrashReport.Bannerlord.Source/CrashReportHtmlRenderer.cs b/src/BUTR.CrashReport.Bannerlord.Source/CrashReportHtmlRenderer.cs index 6935670..d9cd129 100644 --- a/src/BUTR.CrashReport.Bannerlord.Source/CrashReportHtmlRenderer.cs +++ b/src/BUTR.CrashReport.Bannerlord.Source/CrashReportHtmlRenderer.cs @@ -36,6 +36,7 @@ // SOFTWARE. #endregion + #if !BUTRCRASHREPORT_DISABLE || BUTRCRASHREPORT_ENABLEHTMLRENDERER #nullable enable #if !BUTRCRASHREPORT_ENABLEWARNINGS @@ -44,6 +45,7 @@ namespace BUTR.CrashReport.Bannerlord { + using global::BUTR.CrashReport.Extensions; using global::BUTR.CrashReport.Models; using global::System; @@ -212,13 +214,13 @@ public static string Build(CrashReportModel crashReportModel, IEnumerable x.Key == "BUTRLoaderVersion").Value is { } butrLoaderVersionVal ? butrLoaderVersionVal : string.Empty; - var blseVersion = crashReportModel.Metadata.AdditionalMetadata.FirstOrDefault(x => x.Key == "BLSEVersion").Value is { } blseVersionVal ? blseVersionVal : string.Empty; - var launcherExVersion = crashReportModel.Metadata.AdditionalMetadata.FirstOrDefault(x => x.Key == "LauncherExVersion").Value is { } launcherExVersionVal ? launcherExVersionVal : string.Empty; + var butrLoaderVersion = crashReportModel.Metadata.AdditionalMetadata.FirstOrDefault(x => x.Key == "BUTRLoaderVersion")?.Value is { } butrLoaderVersionVal ? butrLoaderVersionVal : string.Empty; + var blseVersion = crashReportModel.Metadata.AdditionalMetadata.FirstOrDefault(x => x.Key == "BLSEVersion")?.Value is { } blseVersionVal ? blseVersionVal : string.Empty; + var launcherExVersion = crashReportModel.Metadata.AdditionalMetadata.FirstOrDefault(x => x.Key == "LauncherExVersion")?.Value is { } launcherExVersionVal ? launcherExVersionVal : string.Empty; #pragma warning disable format // @formatter:off return $$""" - + Bannerlord Crash Report @@ -582,12 +584,8 @@ void AppendDependencies(ModuleModel module) } dependenciesBuilder.Clear(); - foreach (var (_, line) in deps) - { - dependenciesBuilder.Append("
  • ") - .Append(line) - .Append("
  • "); - } + foreach (var dep in deps) + dependenciesBuilder.Append("
  • ").Append(dep.Value).Append("
  • "); } void AppendSubModules(ModuleModel module) diff --git a/src/BUTR.CrashReport.Bannerlord.Source/StringBuilderExtensions.cs b/src/BUTR.CrashReport.Bannerlord.Source/StringBuilderExtensions.cs index 217a966..61230d6 100644 --- a/src/BUTR.CrashReport.Bannerlord.Source/StringBuilderExtensions.cs +++ b/src/BUTR.CrashReport.Bannerlord.Source/StringBuilderExtensions.cs @@ -49,8 +49,12 @@ namespace BUTR.CrashReport.Bannerlord internal static class StringBuilderExtensions { - public static StringBuilder AppendJoin(this StringBuilder builder, string separator, IReadOnlyList lines) + public static StringBuilder AppendJoin(this StringBuilder builder, string separator, IReadOnlyList lines) => AppendJoinIf(builder, true, separator, lines); + public static StringBuilder AppendJoin(this StringBuilder builder, char separator, IReadOnlyList lines) => AppendJoinIf(builder, true, separator, lines); + public static StringBuilder AppendJoinIf(this StringBuilder builder, bool condition, string separator, IReadOnlyList lines) { + if (!condition) return builder; + for (var i = 0; i < lines.Count; i++) { builder.Append(lines[i]); @@ -58,7 +62,7 @@ public static StringBuilder AppendJoin(this StringBuilder builder, string separa } return builder; } - public static StringBuilder AppendJoinIf(this StringBuilder builder, bool condition, string separator, IReadOnlyList lines) + public static StringBuilder AppendJoinIf(this StringBuilder builder, bool condition, char separator, IReadOnlyList lines) { if (!condition) return builder; @@ -69,7 +73,7 @@ public static StringBuilder AppendJoinIf(this StringBuilder builder, bool condit } return builder; } - public static StringBuilder AppendIf(this StringBuilder builder, bool condition, string value) => condition ? builder.Append(value) : builder; + public static StringBuilder AppendIf(this StringBuilder builder, bool condition, string? value) => condition ? builder.Append(value) : builder; public static StringBuilder AppendIf(this StringBuilder builder, bool condition, int value) => condition ? builder.Append(value) : builder; public static StringBuilder AppendIf(this StringBuilder builder, bool condition, StringBuilder value) => condition ? builder.Append(value) : builder; public static StringBuilder AppendLineIf(this StringBuilder builder, bool condition) => condition ? builder.AppendLine() : builder;