-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added WinForms renderer with net45 support
- Loading branch information
Showing
13 changed files
with
418 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/BUTR.CrashReport.Renderer.Html/Extensions/AssemblyModelExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using BUTR.CrashReport.Models; | ||
using BUTR.CrashReport.Renderer.Html.Utils; | ||
|
||
namespace BUTR.CrashReport.Renderer.Html.Extensions; | ||
|
||
/// <summary> | ||
/// Extensions for <inheritdoc cref="BUTR.CrashReport.Models.AssemblyModel"/> | ||
/// </summary> | ||
internal static class AssemblyModelExtensions | ||
{ | ||
/// <summary> | ||
/// <inheritdoc cref="System.Reflection.AssemblyName.FullName"/> | ||
/// </summary> | ||
/// <returns><inheritdoc cref="System.Reflection.AssemblyName.FullName"/></returns> | ||
public static string GetFullName(this AssemblyModel model) => | ||
AssemblyNameFormatter.ComputeDisplayName(model.Id.Name, model.Id.Version, model.CultureName, model.Id.PublicKeyToken); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/BUTR.CrashReport.Renderer.Html/Utils/AssemblyNameFormatter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
|
||
namespace BUTR.CrashReport.Renderer.Html.Utils; | ||
|
||
internal static class AssemblyNameFormatter | ||
{ | ||
public static string ComputeDisplayName(string? name, string? version, string? cultureName, string? publicKeyToken) | ||
{ | ||
if (name == string.Empty) | ||
throw new FileLoadException(); | ||
|
||
var sb = new StringBuilder(); | ||
if (name != null) | ||
{ | ||
sb.AppendQuoted(name); | ||
} | ||
|
||
if (version != null) | ||
{ | ||
sb.Append(", Version="); | ||
sb.Append(version); | ||
} | ||
|
||
if (cultureName != null) | ||
{ | ||
if (cultureName == string.Empty) | ||
cultureName = "neutral"; | ||
sb.Append(", Culture="); | ||
sb.AppendQuoted(cultureName); | ||
} | ||
|
||
if (publicKeyToken != null) | ||
{ | ||
if (publicKeyToken == string.Empty) | ||
publicKeyToken = "null"; | ||
sb.Append(", PublicKeyToken=").Append(publicKeyToken); | ||
} | ||
|
||
// NOTE: By design (desktop compat) AssemblyName.FullName and ToString() do not include ProcessorArchitecture. | ||
|
||
return sb.ToString(); | ||
} | ||
|
||
private static void AppendQuoted(this StringBuilder sb, string s) | ||
{ | ||
var needsQuoting = false; | ||
const char quoteChar = '\"'; | ||
|
||
//@todo: App-compat: You can use double or single quotes to quote a name, and Fusion (or rather the IdentityAuthority) picks one | ||
// by some algorithm. Rather than guess at it, I'll just use double-quote consistently. | ||
if (s != s.Trim() || s.Contains("\"") || s.Contains("\'")) | ||
needsQuoting = true; | ||
|
||
if (needsQuoting) | ||
sb.Append(quoteChar); | ||
|
||
for (var i = 0; i < s.Length; i++) | ||
{ | ||
var addedEscape = false; | ||
foreach (var kv in EscapeSequences) | ||
{ | ||
var key = kv.Key; | ||
var escapeReplacement = kv.Value; | ||
|
||
if (s[i] != escapeReplacement[0]) | ||
continue; | ||
if (s.Length - i < escapeReplacement.Length) | ||
continue; | ||
if (s.Substring(i, escapeReplacement.Length) == escapeReplacement) | ||
{ | ||
sb.Append('\\'); | ||
sb.Append(key); | ||
addedEscape = true; | ||
} | ||
} | ||
|
||
if (!addedEscape) | ||
sb.Append(s[i]); | ||
} | ||
|
||
if (needsQuoting) | ||
sb.Append(quoteChar); | ||
} | ||
|
||
private static readonly KeyValuePair<char, string>[] EscapeSequences = | ||
[ | ||
new('\\', "\\"), | ||
new(',', ","), | ||
new('=', "="), | ||
new('\'', "'"), | ||
new('\"', "\""), | ||
new('n', Environment.NewLine), | ||
new('t', "\t") | ||
]; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/BUTR.CrashReport.Renderer.WinForms/BUTR.CrashReport.Renderer.WinForms.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net45;netcoreapp3.0</TargetFrameworks> | ||
<UseWindowsForms>true</UseWindowsForms> | ||
<LangVersion>preview</LangVersion> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\BUTR.CrashReport.Models\BUTR.CrashReport.Models.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="System.Windows.Forms" Condition="'$(TargetFramework)' == 'net45'" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.