mirror of https://github.com/ospab/ostp.git
fix(installer): use rename trick to bypass file locks and ensure all bundled files (tun2socks, wintun) are copied
This commit is contained in:
parent
2f2f9ffdef
commit
2819a14189
|
|
@ -92,18 +92,29 @@ if (-not (Test-Path $zipPath)) {
|
||||||
if (Test-Path $extractPath) { Remove-Item $extractPath -Recurse -Force }
|
if (Test-Path $extractPath) { Remove-Item $extractPath -Recurse -Force }
|
||||||
Expand-Archive -Path $zipPath -DestinationPath $extractPath -Force
|
Expand-Archive -Path $zipPath -DestinationPath $extractPath -Force
|
||||||
|
|
||||||
$exeFile = Get-ChildItem -Path $extractPath -Filter "*.exe" -Recurse | Select-Object -First 1
|
$extractedFiles = Get-ChildItem -Path $extractPath -File -Recurse
|
||||||
if ($exeFile) {
|
if ($extractedFiles.Count -gt 0) {
|
||||||
Write-Host "Stopping any active instances of ostp to unlock binary target..."
|
Write-Host "Stopping any active instances of ostp to unlock binary targets..."
|
||||||
Stop-Process -Name "ostp" -ErrorAction SilentlyContinue
|
Stop-Process -Name "ostp", "tun2socks" -Force -ErrorAction SilentlyContinue
|
||||||
Start-Sleep -Seconds 1
|
Start-Sleep -Seconds 2
|
||||||
|
|
||||||
Copy-Item -Path $exeFile.FullName -Destination (Join-Path $InstallDir "ostp.exe") -Force
|
foreach ($file in $extractedFiles) {
|
||||||
# Force file system timestamps to current local time to reflect successful execution
|
$destPath = Join-Path $InstallDir $file.Name
|
||||||
(Get-Item (Join-Path $InstallDir "ostp.exe")).LastWriteTime = [DateTime]::Now
|
if (Test-Path $destPath) {
|
||||||
Write-Host "Executable successfully deployed to $(Join-Path $InstallDir 'ostp.exe')."
|
# Rename the existing executable out of the way to bypass file locks
|
||||||
|
$oldPath = $destPath + ".old_$PID"
|
||||||
|
Rename-Item -Path $destPath -NewName $oldPath -ErrorAction SilentlyContinue
|
||||||
|
}
|
||||||
|
Copy-Item -Path $file.FullName -Destination $destPath -Force
|
||||||
|
(Get-Item $destPath).LastWriteTime = [DateTime]::Now
|
||||||
|
}
|
||||||
|
|
||||||
|
# Try to clean up any leftover old files
|
||||||
|
Get-ChildItem -Path $InstallDir -Filter "*.old_*" | Remove-Item -Force -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
Write-Host "Executables and dependencies successfully deployed to $InstallDir."
|
||||||
} else {
|
} else {
|
||||||
Write-Error "Binary file ostp.exe not found in archive package."
|
Write-Error "No files found in archive package."
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue