1- using System ;
2- using System . Collections . Generic ;
31using System . Globalization ;
4- using System . IO ;
5- using System . Linq ;
62using System . Text ;
3+
74using LogExpert . PluginRegistry ;
85
96namespace PluginHashGenerator . Tool ;
@@ -14,7 +11,9 @@ namespace PluginHashGenerator.Tool;
1411/// </summary>
1512internal class Program
1613{
17- private static int Main ( string [ ] args )
14+ [ System . Diagnostics . CodeAnalysis . SuppressMessage ( "Globalization" , "CA1303:Do not pass literals as localized parameters" , Justification = "Tool for Hash Generation does not need localization" ) ]
15+ [ System . Diagnostics . CodeAnalysis . SuppressMessage ( "Design" , "CA1031:Do not catch general exception types" , Justification = "Intentionally continue on error to process other plugins" ) ]
16+ private static int Main ( string [ ] args )
1817 {
1918 try
2019 {
@@ -37,7 +36,7 @@ private static int Main(string[] args)
3736
3837 // Find all plugin DLLs
3938 var pluginPaths = new List < string > ( ) ;
40-
39+
4140 // Check plugins folder
4241 var pluginsDir = Path . Join ( outputPath , "plugins" ) ;
4342 if ( Directory . Exists ( pluginsDir ) )
@@ -82,7 +81,7 @@ private static int Main(string[] args)
8281 foreach ( var pluginPath in pluginPaths . OrderBy ( p => p ) )
8382 {
8483 var fileName = Path . GetFileName ( pluginPath ) ;
85-
84+
8685 // Skip dependencies
8786 if ( knownDependencies . Contains ( fileName ) )
8887 {
@@ -93,14 +92,14 @@ private static int Main(string[] args)
9392 try
9493 {
9594 var hash = PluginHashCalculator . CalculateHash ( pluginPath ) ;
96-
95+
9796 // For x86 plugins, add suffix to distinguish them
9897 var key = fileName ;
9998 if ( pluginPath . Contains ( "pluginsx86" , StringComparison . OrdinalIgnoreCase ) )
10099 {
101100 key = $ "{ Path . GetFileNameWithoutExtension ( fileName ) } .dll (x86)";
102101 }
103-
102+
104103 // Handle duplicate keys (same plugin in both folders)
105104 if ( ! pluginHashes . ContainsKey ( key ) )
106105 {
@@ -110,6 +109,7 @@ private static int Main(string[] args)
110109 }
111110 catch ( Exception ex )
112111 {
112+ //Intentionally continue on error to process other plugins
113113 Console . Error . WriteLine ( $ " ✗ ERROR calculating hash for { fileName } : { ex . Message } ") ;
114114 }
115115 }
@@ -121,7 +121,7 @@ private static int Main(string[] args)
121121 var targetDir = Path . GetDirectoryName ( targetFile ) ;
122122 if ( ! string . IsNullOrEmpty ( targetDir ) && ! Directory . Exists ( targetDir ) )
123123 {
124- Directory . CreateDirectory ( targetDir ) ;
124+ _ = Directory . CreateDirectory ( targetDir ) ;
125125 }
126126
127127 // Write the file
@@ -140,43 +140,46 @@ private static int Main(string[] args)
140140 }
141141 }
142142
143- private static string GenerateSourceCode ( Dictionary < string , string > pluginHashes , string configuration )
143+ private static string GenerateSourceCode ( Dictionary < string , string > pluginHashes , string configuration )
144144 {
145145 var timestamp = DateTime . UtcNow . ToString ( "yyyy-MM-dd HH:mm:ss" , CultureInfo . InvariantCulture ) ;
146-
146+
147147 var sb = new StringBuilder ( ) ;
148- sb . AppendLine ( "// <auto-generated/>" ) ;
149- sb . AppendLine ( "// This file is auto-generated during build. Do not edit manually." ) ;
150- sb . AppendLine ( "// To regenerate, rebuild the project or run the GeneratePluginHashes MSBuild target." ) ;
151- sb . AppendLine ( ) ;
152- sb . AppendLine ( "using System.Collections.Generic;" ) ;
153- sb . AppendLine ( ) ;
154- sb . AppendLine ( "namespace LogExpert.PluginRegistry;" ) ;
155- sb . AppendLine ( ) ;
156- sb . AppendLine ( "public static partial class PluginValidator" ) ;
157- sb . AppendLine ( "{" ) ;
158- sb . AppendLine ( " /// <summary>" ) ;
159- sb . AppendLine ( " /// Gets pre-calculated SHA256 hashes for built-in plugins." ) ;
160- sb . AppendLine ( $ " /// Generated: { timestamp } UTC") ;
161- sb . AppendLine ( $ " /// Configuration: { configuration } ") ;
162- sb . AppendLine ( $ " /// Plugin count: { pluginHashes . Count } ") ;
163- sb . AppendLine ( " /// </summary>" ) ;
164- sb . AppendLine ( " public static Dictionary<string, string> GetBuiltInPluginHashes()" ) ;
165- sb . AppendLine ( " {" ) ;
166- sb . AppendLine ( " return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)" ) ;
167- sb . AppendLine ( " {" ) ;
168148
169149 foreach ( var kvp in pluginHashes . OrderBy ( kvp => kvp . Key ) )
170150 {
171151 // Properly escape the key for C# string literal
172- var escapedKey = kvp . Key . Replace ( "\\ " , "\\ \\ " ) . Replace ( "\" " , "\\ \" " ) ;
173- sb . AppendLine ( $ " [\" { escapedKey } \" ] = \" { kvp . Value } \" ,") ;
152+ var escapedKey = kvp . Key . Replace ( "\\ " , "\\ \\ " , StringComparison . OrdinalIgnoreCase ) . Replace ( "\" " , "\\ \" " , StringComparison . OrdinalIgnoreCase ) ;
153+ _ = sb . AppendLine ( CultureInfo . InvariantCulture , $ " [\" { escapedKey } \" ] = \" { kvp . Value } \" ,") ;
174154 }
175155
176- sb . AppendLine ( " };" ) ;
177- sb . AppendLine ( " }" ) ;
178- sb . AppendLine ( "}" ) ;
156+ string sourceCode = $$ """
157+ // <auto-generated/>
158+ // This file is auto-generated during build. Do not edit manually.
159+ // To regenerate, rebuild the project or run the GeneratePluginHashes MSBuild target.
160+
161+ using System.Collections.Generic;
162+
163+ namespace LogExpert.PluginRegistry;
164+
165+ public static partial class PluginValidator
166+ {
167+ /// <summary>
168+ /// Gets pre-calculated SHA256 hashes for built-in plugins.
169+ /// Generated: {{ timestamp }} UTC
170+ /// Configuration: {{ configuration }}
171+ /// Plugin count: {{ pluginHashes . Count }}
172+ /// </summary>
173+ public static Dictionary<string, string> GetBuiltInPluginHashes()
174+ {
175+ return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
176+ {
177+ {{ sb }}
178+ };
179+ }
180+ }
181+ """ ;
179182
180- return sb . ToString ( ) ;
183+ return sourceCode ;
181184 }
182- }
185+ }
0 commit comments