From 7e87283f1ebf0e284bafebc09cf9c19e555ff22b Mon Sep 17 00:00:00 2001 From: 13xforever Date: Mon, 5 Dec 2022 12:54:06 +0500 Subject: [PATCH] update win32 error codes source handling --- CompatBot/CompatBot.csproj | 4 ++-- SourceGenerators/Win32ErrorsSourceGenerator.cs | 8 +++++--- win32_error_codes.txt => win32_error_codes_v19.0.txt | 0 3 files changed, 7 insertions(+), 5 deletions(-) rename win32_error_codes.txt => win32_error_codes_v19.0.txt (100%) diff --git a/CompatBot/CompatBot.csproj b/CompatBot/CompatBot.csproj index fda4c318..e9b52ed5 100644 --- a/CompatBot/CompatBot.csproj +++ b/CompatBot/CompatBot.csproj @@ -35,8 +35,8 @@ - - + + diff --git a/SourceGenerators/Win32ErrorsSourceGenerator.cs b/SourceGenerators/Win32ErrorsSourceGenerator.cs index 38c2fc41..87e4f9eb 100644 --- a/SourceGenerators/Win32ErrorsSourceGenerator.cs +++ b/SourceGenerators/Win32ErrorsSourceGenerator.cs @@ -29,13 +29,15 @@ public class Win32ErrorsSourceGenerator : ISourceGenerator public void Execute(GeneratorExecutionContext context) { - var resourceName = context.AdditionalFiles.FirstOrDefault(f => Path.GetFileName(f.Path).Equals("win32_error_codes.txt")); + var resourceName = context.AdditionalFiles + .OrderBy(f => f.Path, StringComparer.OrdinalIgnoreCase) + .LastOrDefault(f => Path.GetFileName(f.Path) is string fname && fname.StartsWith("win32_error_codes") && fname.EndsWith(".txt")); if (resourceName is null) - return; + throw new InvalidOperationException("Failed to locate win32_error_codes txt file"); using var stream = File.Open(resourceName.Path, FileMode.Open, FileAccess.Read, FileShare.Read); if (stream is null) - throw new InvalidOperationException("Failed to get win32_error_codes.txt stream"); + throw new InvalidOperationException("Failed to get win32_error_codes txt stream"); if (!context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.RootNamespace", out var ns)) ns = context.Compilation.AssemblyName; diff --git a/win32_error_codes.txt b/win32_error_codes_v19.0.txt similarity index 100% rename from win32_error_codes.txt rename to win32_error_codes_v19.0.txt