From e5c7aef12cea8bf14a09758e141d31d73eb68452 Mon Sep 17 00:00:00 2001 From: Oleg Lokhvitsky Date: Sun, 13 Oct 2024 19:06:15 -0700 Subject: [PATCH] Add retries to updater script --- src/main/worker/UpdaterAPI.ts | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main/worker/UpdaterAPI.ts b/src/main/worker/UpdaterAPI.ts index 12861df..8c65d55 100644 --- a/src/main/worker/UpdaterAPI.ts +++ b/src/main/worker/UpdaterAPI.ts @@ -167,11 +167,31 @@ async function applyUpdate( ); const updateScriptContent = ` - Echo "Waiting for D2RMM to exit..." + Write-Host "Waiting for D2RMM to exit..." Start-Sleep -Seconds 1 - Echo "Copying files..." - Copy-Item -Path "${updateDirectoryPath}\\*" -Destination "${appDirectoryPath}" -Recurse -Force - Echo "Restarting D2RMM..." + + $retries = 3 + $success = $false + + for ($i = 0; $i -lt $retries; $i++) { + Write-Host "Copying files..." + try { + Copy-Item -Path "${updateDirectoryPath}\\*" -Destination "${appDirectoryPath}" -Recurse -Force -ErrorAction Stop + $success = $true + break + } catch { + Write-Host "Failed to copy files. Retrying in 5 seconds..." + Start-Sleep -Seconds 5 + } + } + + if (-not $success) { + Write-Host "Failed to copy new files to D2RMM's directory. You may need to update manually." + Read-Host "Press Enter to exit..." + exit 1 + } + + Write-Host "Restarting D2RMM..." Start-Sleep -Seconds 1 Start-Process -FilePath "${appExecutablePath}" `;