-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGenBuildInfo.ps1
More file actions
30 lines (25 loc) · 1.02 KB
/
GenBuildInfo.ps1
File metadata and controls
30 lines (25 loc) · 1.02 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
param($ConfigHashFile, $ConfigFile);
Write-Host "Putting default config hash into file '$ConfigHashFile'.";
$HashObj = New-Object -TypeName 'System.Security.Cryptography.MD5CryptoServiceProvider';
$FileStream = [System.IO.File]::Open((Resolve-Path $ConfigFile), [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::ReadWrite);
try
{
[byte[]] $HashBytes = $HashObj.ComputeHash($FileStream);
$HexBuilder = [System.Text.StringBuilder]::new($HashBytes.Length * 6);
foreach($b in $HashBytes) { $HexBuilder.AppendFormat('0x{0:X2}, ', $b) | Out-Null }
$HexBuilder.Remove($HexBuilder.Length - 2, 2);
[string] $Hash = $HexBuilder.ToString();
}
finally { $FileStream.Dispose(); }
Write-Host "Default config file MD5 is $Hash";
$Class =
@"
using System;
namespace ColorChord.NET.Config;
// This file is auto-generated by GenBuildInfo.ps1.
internal static class DefaultConfigInfo
{
internal static ReadOnlySpan<byte> DefaultConfigFileMD5 => [$Hash];
}
"@
Set-Content -Path $ConfigHashFile -Value $Class;