Files
PupaMLupa/Server/sync-mods-from-client.ps1
T

114 lines
3.4 KiB
PowerShell

#!/usr/bin/env pwsh
# Копирует *.jar из ../mods в ./mods (тот же инстанс).
# Не копирует jar, если имя совпадает с одним из шаблонов ниже (только клиент).
# Шаблоны — как в PowerShell -like: * и ? (регистр не важен).
# Выключенные NeoForge (*.jar.disabled) фильтром *.jar не подхватываются.
# Односторонняя синхронизация: клиент -> сервер. Лишние jar на сервере не удаляются.
param(
[switch] $DryRun
)
$ErrorActionPreference = "Stop"
# Дополняй при установке новых клиентских модов.
# xaeroworldmap — часто оставляют на сервере (данные карты); minimap — только клиент.
$ClientOnlyJarLikePatterns = @(
'AmbientSounds*'
'BadOptimizations-*'
'BetterF3-*'
'BHMenu-*'
'catalogue-*'
'clientcrafting-*'
'Controlling-*'
'defaultoptions-*'
'dynamic-fps-*'
'enchdesc-*'
'enhancedbossbars-*'
'entity_model_features_*'
'entity_texture_features_*'
'entityculling-*'
'EuphoriaPatcher-*'
'fast-ip-ping-*'
'fastpaintings-*'
'fancymenu_*'
'gpumemleakfix-*'
'ImmediatelyFast-*'
'iris-*'
'JustEnoughProfessions-*'
'JustEnoughResources-*'
'konkrete_*'
'loadingbackgrounds-*'
'mace3d-*'
'melody_*'
'MouseTweaks-*'
'notenoughanimations-*'
'reeses-sodium-options-*'
'seasonhud-*'
'SimplyTooltips-*'
'sodium-neoforge-*'
'sodiumextras-*'
'sodiumoptionsapi-*'
'sound-physics-remastered-*'
'time_on_display-*'
'ToastControl-*'
'vulkanmod-*'
'xaerominimap-*'
'entity_model_features-*'
)
function Test-ClientOnlyJarName([string] $fileName) {
foreach ($pattern in $ClientOnlyJarLikePatterns) {
if ($fileName -like $pattern) {
return $true
}
}
return $false
}
$instanceRoot = Split-Path $PSScriptRoot -Parent
$src = Join-Path $instanceRoot "mods"
$dst = Join-Path $PSScriptRoot "mods"
if (-not (Test-Path -LiteralPath $src)) {
Write-Error "Клиентские моды не найдены: $src"
}
if (-not (Test-Path -LiteralPath $dst)) {
if ($DryRun) {
Write-Host "[dry-run] Создал бы папку: $dst"
} else {
New-Item -ItemType Directory -Path $dst -Force | Out-Null
}
}
$copied = [System.Collections.Generic.List[string]]::new()
$skippedClient = 0
foreach ($jar in Get-ChildItem -LiteralPath $src -File -Filter "*.jar") {
if (Test-ClientOnlyJarName $jar.Name) {
$skippedClient++
if ($DryRun) {
Write-Host "[dry-run] пропуск (клиент): $($jar.Name)"
}
continue
}
$destPath = Join-Path $dst $jar.Name
$copied.Add($jar.Name) | Out-Null
if ($DryRun) {
Write-Host "[dry-run] $($jar.FullName) -> $destPath"
continue
}
Copy-Item -LiteralPath $jar.FullName -Destination $destPath -Force
}
Write-Host ("Синхронизировано {0} jar: клиент -> Server/mods." -f $copied.Count)
if ($skippedClient -gt 0) {
Write-Host ("Пропущено клиентских (по списку в скрипте): {0}" -f $skippedClient)
}
if ($copied.Count -gt 0 -and $VerbosePreference -eq "Continue") {
$copied | Sort-Object | ForEach-Object { Write-Host " $_" }
}