32 lines
2.2 KiB
PowerShell
32 lines
2.2 KiB
PowerShell
param([string]$GameDirectory = "C:\Program Files (x86)\DODI-Repacks\American Truck Simulator")
|
|
$ErrorActionPreference = "Stop"
|
|
$taskPrincipal = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
|
|
if (-not $taskPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
|
$taskArgs = "-NoProfile -ExecutionPolicy Bypass -File ""$PSCommandPath"" -GameDirectory ""$GameDirectory"""
|
|
$taskProcess = Start-Process -FilePath "powershell.exe" -Verb RunAs -WindowStyle Hidden -ArgumentList $taskArgs -Wait -PassThru
|
|
exit $taskProcess.ExitCode
|
|
}
|
|
try {
|
|
$taskSource = Join-Path $PSScriptRoot "telemetry_plugin\release_v_1_12_1\Win64\scs-telemetry.dll"
|
|
$taskBinary = Join-Path $GameDirectory "bin\win_x64\amtrucks.exe"
|
|
if (-not (Test-Path -LiteralPath $taskSource)) { throw "Bundled telemetry DLL is missing." }
|
|
if (-not (Test-Path -LiteralPath $taskBinary)) { throw "ATS was not found at $taskBinary." }
|
|
if (Get-Process -Name amtrucks -ErrorAction SilentlyContinue) { throw "Close ATS before installing, then run the installer again." }
|
|
$taskPluginDirectory = Join-Path $GameDirectory "bin\win_x64\plugins"
|
|
$taskDestination = Join-Path $taskPluginDirectory "scs-telemetry.dll"
|
|
New-Item -ItemType Directory -Path $taskPluginDirectory -Force | Out-Null
|
|
$taskSourceHash = (Get-FileHash -LiteralPath $taskSource -Algorithm SHA256).Hash
|
|
if (Test-Path -LiteralPath $taskDestination) {
|
|
if ((Get-FileHash -LiteralPath $taskDestination -Algorithm SHA256).Hash -ne $taskSourceHash) {
|
|
Copy-Item -LiteralPath $taskDestination -Destination "$taskDestination.backup"
|
|
}
|
|
}
|
|
Copy-Item -LiteralPath $taskSource -Destination $taskDestination -Force
|
|
if ((Get-FileHash -LiteralPath $taskDestination -Algorithm SHA256).Hash -ne $taskSourceHash) { throw "DLL verification failed." }
|
|
Add-Content -LiteralPath (Join-Path $PSScriptRoot "install_log.txt") -Value ("SUCCESS " + (Get-Date).ToString("o") + " " + $taskDestination + " " + $taskSourceHash)
|
|
exit 0
|
|
} catch {
|
|
Add-Content -LiteralPath (Join-Path $PSScriptRoot "install_log.txt") -Value ("FAILED " + (Get-Date).ToString("o") + " " + $_.Exception.Message)
|
|
exit 1
|
|
}
|