From 3fe80726045aa223f86dcce0febebeb50e9b2a7a Mon Sep 17 00:00:00 2001 From: clodanSPT Date: Mon, 2 Jun 2025 17:56:06 +0100 Subject: [PATCH] Added checks.dat build script (#343) Co-authored-by: Alex --- SPTarkov.Server/SPTarkov.Server.csproj | 5 +++ SPTarkov.Server/postBuildScript.ps1 | 57 ++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 SPTarkov.Server/postBuildScript.ps1 diff --git a/SPTarkov.Server/SPTarkov.Server.csproj b/SPTarkov.Server/SPTarkov.Server.csproj index bce8f96e..b3106fc1 100644 --- a/SPTarkov.Server/SPTarkov.Server.csproj +++ b/SPTarkov.Server/SPTarkov.Server.csproj @@ -41,10 +41,15 @@ Always + + + + + diff --git a/SPTarkov.Server/postBuildScript.ps1 b/SPTarkov.Server/postBuildScript.ps1 new file mode 100644 index 00000000..4649f3b5 --- /dev/null +++ b/SPTarkov.Server/postBuildScript.ps1 @@ -0,0 +1,57 @@ +param ( + [string]$filepath, + [string]$output +) + +function Load-RecursiveAsync { + param ( + [string]$filepath + ) + + $result = @{} + + $filesList = Get-ChildItem -Path $filepath + + foreach ($file in $filesList) { + $curPath = $file.FullName + if ($file.PSIsContainer) { + $result[$file.BaseName] = Load-RecursiveAsync "$filepath\$($file.Name)" + } elseif ($file.Extension -eq ".json") { + $result[$file.BaseName] = Generate-HashForData (Get-Content -Raw -Path "$filepath\$($file.Name)") + } + } + + return $result +} + +function Generate-HashForData { + param ( + [string]$data + ) + + $sha1 = [System.Security.Cryptography.SHA1]::Create() + $hashBytes = $sha1.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($data)) + $hashHex = -join ($hashBytes | ForEach-Object { $_.ToString("x2") }) # Convert bytes to hex + + return $hashHex +} + +function Encode-Base64 { + param ( + [Parameter(ValueFromPipeline=$true)] + [string]$inputString + ) + + process { + if ($inputString -and $inputString -ne "") { + $bytes = [System.Text.Encoding]::UTF8.GetBytes($inputString) + $base64String = [Convert]::ToBase64String($bytes) + return $base64String + } else { + Write-Output "Error: No valid input received!" + } + } +} + +$results = Load-RecursiveAsync $filepath +$results | ConvertTo-Json -Depth 10 -Compress | Encode-Base64 | Out-File $output \ No newline at end of file