update win32 error codes source handling

This commit is contained in:
13xforever
2022-12-05 12:54:06 +05:00
parent 8f8c1a697d
commit 7e87283f1e
3 changed files with 7 additions and 5 deletions
+2 -2
View File
@@ -35,8 +35,8 @@
</Content>
</ItemGroup>
<ItemGroup>
<None Remove="..\win32_error_codes.txt" />
<AdditionalFiles Include="..\win32_error_codes.txt" />
<None Remove="..\win32_error_codes*.txt" />
<AdditionalFiles Include="..\win32_error_codes*.txt" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="DSharpPlus" Version="4.3.0-nightly-01189" />
@@ -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;