-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_nvapi_interface_table.ps1
More file actions
85 lines (74 loc) · 3.03 KB
/
generate_nvapi_interface_table.ps1
File metadata and controls
85 lines (74 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
param(
[string]$HeaderPath = (Join-Path $PSScriptRoot "nvapi\\nvapi_interface.h"),
[string]$OutputPath = (Join-Path $PSScriptRoot "NVAPIWrapper\\NVAPIInterfaceTable.g.cs")
)
if (-not (Test-Path $HeaderPath)) {
throw "NVAPI interface header not found: $HeaderPath"
}
$lines = Get-Content -Path $HeaderPath
$inTable = $false
$entries = New-Object System.Collections.Generic.List[pscustomobject]
foreach ($line in $lines) {
if (-not $inTable) {
if ($line -match 'nvapi_interface_table\[\]\s*=') {
$inTable = $true
}
continue
}
if ($line -match "^\\s*\\};") {
$inTable = $false
break
}
if ($line -match '\{\s*"([^"]+)"\s*,\s*(0x[0-9a-fA-F]+)\s*\}') {
$entries.Add([pscustomobject]@{
Name = $matches[1]
Id = $matches[2]
}) | Out-Null
}
}
if ($entries.Count -eq 0) {
throw "No entries found in nvapi_interface_table in $HeaderPath"
}
$outputLines = New-Object System.Collections.Generic.List[string]
$outputLines.Add("// <auto-generated>")
$outputLines.Add("// Generated by generate_nvapi_interface_table.ps1 from nvapi_interface.h.")
$outputLines.Add("// </auto-generated>")
$outputLines.Add("namespace NVAPIWrapper")
$outputLines.Add("{")
$outputLines.Add(" /// <summary>Managed copy of nvapi_interface_table for QueryInterface lookups.</summary>")
$outputLines.Add(" public static class NVAPIInterfaceTable")
$outputLines.Add(" {")
$outputLines.Add(" /// <summary>Entry in the NVAPI interface table.</summary>")
$outputLines.Add(" public readonly struct Entry")
$outputLines.Add(" {")
$outputLines.Add(" /// <summary>Create a new interface table entry.</summary>")
$outputLines.Add(" public Entry(string name, uint id)")
$outputLines.Add(" {")
$outputLines.Add(" Name = name;")
$outputLines.Add(" Id = id;")
$outputLines.Add(" }")
$outputLines.Add("")
$outputLines.Add(" /// <summary>NVAPI function name.</summary>")
$outputLines.Add(" public string Name { get; }")
$outputLines.Add("")
$outputLines.Add(" /// <summary>NVAPI function ID for QueryInterface.</summary>")
$outputLines.Add(" public uint Id { get; }")
$outputLines.Add(" }")
$outputLines.Add("")
$outputLines.Add(" /// <summary>All known NVAPI interface table entries.</summary>")
$outputLines.Add(" public static readonly Entry[] Entries = new Entry[]")
$outputLines.Add(" {")
foreach ($entry in $entries) {
$idLiteral = $entry.Id.ToLowerInvariant() + "u"
$nameLiteral = $entry.Name.Replace('"', '\"')
$outputLines.Add(" new Entry(`"$nameLiteral`", $idLiteral),")
}
$outputLines.Add(" };")
$outputLines.Add(" }")
$outputLines.Add("}")
$outputDir = Split-Path -Path $OutputPath -Parent
if (-not (Test-Path $outputDir)) {
New-Item -Path $outputDir -ItemType Directory | Out-Null
}
Set-Content -Path $OutputPath -Value $outputLines -Encoding ASCII
Write-Output "Generated: $OutputPath"