From 7db3d35e86a7ba09fd948a60ce8c79adac77228f Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sat, 15 Jul 2023 19:37:30 +0200 Subject: [PATCH] Refactor function for waiting for download --- scripts/Windows/Scripts/BrowserAutomation.ps1 | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/scripts/Windows/Scripts/BrowserAutomation.ps1 b/scripts/Windows/Scripts/BrowserAutomation.ps1 index 69288b55..362d5a9a 100644 --- a/scripts/Windows/Scripts/BrowserAutomation.ps1 +++ b/scripts/Windows/Scripts/BrowserAutomation.ps1 @@ -28,19 +28,25 @@ function Start-AutomatedDownload() { $downloadChecker = { param() - foreach ($file in Get-ChildItem $tempDir) { - try { - $stream = [System.IO.File]::Open($file.FullName, [System.IO.FileMode]::Open, [System.IO.FileAccess]::ReadWrite, [System.IO.FileShare]::None); + $files = Get-ChildItem $tempDir; - if ($stream) { - $stream.Close(); + if ($(@($files)).Count -ge 0) { + foreach ($file in Get-ChildItem $tempDir) { + try { + $stream = [System.IO.File]::Open($file.FullName, [System.IO.FileMode]::Open, [System.IO.FileAccess]::ReadWrite, [System.IO.FileShare]::None); + + if ($stream) { + $stream.Close(); + } + + return $false; + } + catch { + return $true; } - - return $false; - } - catch { - return $true; } + } else { + return $false; } }