Skip to content

Commit

Permalink
Code fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed Sep 29, 2023
1 parent 85ca4c0 commit e6d7b2a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<IsPackable>true</IsPackable>
<DefineConstants>$(DefineConstants);BUTRCRASHREPORT_ENABLEWARNINGS</DefineConstants>
</PropertyGroup>

<PropertyGroup>
Expand Down
18 changes: 8 additions & 10 deletions src/BUTR.CrashReport.Bannerlord.Source/CrashReportHtmlRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
// SOFTWARE.
#endregion


#if !BUTRCRASHREPORT_DISABLE || BUTRCRASHREPORT_ENABLEHTMLRENDERER
#nullable enable
#if !BUTRCRASHREPORT_ENABLEWARNINGS
Expand All @@ -44,6 +45,7 @@

namespace BUTR.CrashReport.Bannerlord
{
using global::BUTR.CrashReport.Extensions;
using global::BUTR.CrashReport.Models;

using global::System;
Expand Down Expand Up @@ -212,13 +214,13 @@ public static string Build(CrashReportModel crashReportModel, IEnumerable<LogSou
var launcherType = crashReportModel.Metadata.LauncherType;
var launcherVersion = crashReportModel.Metadata.LauncherVersion;

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;
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 $$"""
<html>
<html>
<head>
<title>Bannerlord Crash Report</title>
<meta charset='utf-8' />
Expand Down Expand Up @@ -582,12 +584,8 @@ void AppendDependencies(ModuleModel module)
}

dependenciesBuilder.Clear();
foreach (var (_, line) in deps)
{
dependenciesBuilder.Append("<li>")
.Append(line)
.Append("</li>");
}
foreach (var dep in deps)
dependenciesBuilder.Append("<li>").Append(dep.Value).Append("</li>");
}

void AppendSubModules(ModuleModel module)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,20 @@ namespace BUTR.CrashReport.Bannerlord

internal static class StringBuilderExtensions
{
public static StringBuilder AppendJoin(this StringBuilder builder, string separator, IReadOnlyList<string> lines)
public static StringBuilder AppendJoin(this StringBuilder builder, string separator, IReadOnlyList<string> lines) => AppendJoinIf(builder, true, separator, lines);
public static StringBuilder AppendJoin(this StringBuilder builder, char separator, IReadOnlyList<string> lines) => AppendJoinIf(builder, true, separator, lines);
public static StringBuilder AppendJoinIf(this StringBuilder builder, bool condition, string separator, IReadOnlyList<string> lines)
{
if (!condition) return builder;

for (var i = 0; i < lines.Count; i++)
{
builder.Append(lines[i]);
if (lines.Count - 1 != i) builder.Append(separator);
}
return builder;
}
public static StringBuilder AppendJoinIf(this StringBuilder builder, bool condition, string separator, IReadOnlyList<string> lines)
public static StringBuilder AppendJoinIf(this StringBuilder builder, bool condition, char separator, IReadOnlyList<string> lines)
{
if (!condition) return builder;

Expand All @@ -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;
Expand Down

0 comments on commit e6d7b2a

Please sign in to comment.