Files
sb/change.bat
T

59 lines
2.2 KiB
Batchfile
Raw Normal View History

2026-04-15 19:29:59 +03:00
<# :
@echo off
chcp 65001 >nul
cd /d "%~dp0"
powershell -ExecutionPolicy Bypass -NoProfile -Command "Invoke-Command -ScriptBlock ([ScriptBlock]::Create((Get-Content -LiteralPath '%~f0' -Encoding UTF8 -Raw)))"
pause
exit /b
#>
# --- ЗДЕСЬ НАЧИНАЕТСЯ POWERSHELL ---
$PARAMS_FILE = "params.txt"
$paths = @(
".\conf_EE_eth\config.json",
".\conf_DE_eth\config.json"
2026-04-15 19:29:59 +03:00
)
# 1. Проверяем наличие файла с параметрами
if (-not (Test-Path $PARAMS_FILE)) {
Write-Host "ОШИБКА: Файл $PARAMS_FILE не найден!" -ForegroundColor Red
return
}
# 2. Читаем параметры из файла
$params = Get-Content $PARAMS_FILE -Raw | ConvertFrom-StringData
$LOCAL_ADDR = $params.LOCAL_ADDR
$PRIV_KEY = $params.PRIV_KEY
if (-not $LOCAL_ADDR -or -not $PRIV_KEY) {
Write-Host "ОШИБКА: В файле $PARAMS_FILE не найдены LOCAL_ADDR или PRIV_KEY!" -ForegroundColor Red
return
}
Write-Host "Параметры загружены: ADDR=$LOCAL_ADDR" -ForegroundColor Gray
# 3. Настройка кодировки UTF-8 без BOM
$utf8NoBom = New-Object System.Text.UTF8Encoding $False
foreach ($path in $paths) {
if (Test-Path $path) {
Write-Host "Обработка файла: $path" -ForegroundColor Cyan
$originalText = Get-Content $path -Raw -Encoding UTF8
# Регулярные выражения для замены значений внутри кавычек
$newText = [regex]::Replace($originalText, '("private_key"\s*:\s*")[^"]+(")', "`${1}$PRIV_KEY`$2")
$newText = [regex]::Replace($newText, '("local_address"\s*:\s*\[\s*")[^"]+("\s*\])', "`${1}$LOCAL_ADDR`$2")
if ($originalText -cne $newText) {
$fullPath = (Resolve-Path $path).Path
[System.IO.File]::WriteAllText($fullPath, $newText, $utf8NoBom)
Write-Host " [+] Успешно обновлено" -ForegroundColor Green
} else {
Write-Host " [-] Изменений не требуется (значения уже совпадают или поля не найдены)" -ForegroundColor Yellow
}
} else {
Write-Host "Файл не найден: $path" -ForegroundColor Red
}
}