[String]$File_x86 = "<%= @curl_build_path %>\*i686-curl*.xz"
[String]$File_x64 = "<%= @curl_build_path %>\*x86_64-curl*.xz"
[Int]$MaxRetries = 720

$Retries = 0
$Found = $false

Start-Process "c:\msys64\msys2_shell.cmd" "-mingw64 -where <%= @cache_dir %> -no-start -f curl-bash-builder.sh" -Wait -PassThru -NoNewWindow
Start-Sleep 5

while (-not $Found) {
  if (Test-Path -Path $File_x64) {
    $Found = $true
  }
  else {
    if ($Retries -ge $MaxRetries) {
      throw "Failed to detect curl x64 build completion!"
    }
    else {
      Start-Sleep 5
      $Retries++
    }
  }
}

$Retries = 0
$Found = $false

while (-not $Found) {
  if (Test-Path -Path $File_x86) {
    $Found = $true
  }
  else {
    if ($Retries -ge $MaxRetries) {
      throw "Failed to detect curl x86 build completion!"
    }
    else {
      Start-Sleep 5
      $Retries++
    }
  }
}

Start-Sleep 120

[String]$File_x86 = "<%= @curl_build_path %>\*i686-curl*.xz"
[String]$File_x64 = "<%= @curl_build_path %>\*x86_64-curl*.xz"
[Int]$MaxRetries = 720

$Retries = 0
$Found = $false

Start-Process "c:\msys64\msys2_shell.cmd" "-mingw64 -where <%= @cache_dir %> -no-start -f curl-bash-builder.sh" -Wait -PassThru -NoNewWindow
Start-Sleep 5

while (-not $Found) {
  if (Test-Path -Path $File_x64) {
    $Found = $true
  }
  else {
    if ($Retries -ge $MaxRetries) {
      throw "Failed to detect curl x64 build completion!"
    }
    else {
      Start-Sleep 5
      $Retries++
    }
  }
}

$Retries = 0
$Found = $false

while (-not $Found) {
  if (Test-Path -Path $File_x86) {
    $Found = $true
  }
  else {
    if ($Retries -ge $MaxRetries) {
      throw "Failed to detect curl x86 build completion!"
    }
    else {
      Start-Sleep 5
      $Retries++
    }
  }
}

Remove post build pause on curl packages
Remove post build pause on curl packages
