-
Notifications
You must be signed in to change notification settings - Fork 1
/
GenBuildInfo.ps1
28 lines (23 loc) · 966 Bytes
/
GenBuildInfo.ps1
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
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 * 2);
foreach($b in $HashBytes) { $HexBuilder.AppendFormat('{0:X2}', $b) | Out-Null }
[string] $Hash = $HexBuilder.ToString();
}
finally { $FileStream.Dispose(); }
Write-Host "Default config file MD5 is $Hash";
$Class =
@"
namespace ColorChord.NET.Config;
// This file is auto-generated by GenBuildInfo.ps1.
internal static class DefaultConfigInfo
{
internal const string DefaultConfigFileMD5 = "$Hash";
}
"@
Set-Content -Path $ConfigHashFile -Value $Class;