From 4c565f8088cb79df2a841d8fad58b3d249d698e3 Mon Sep 17 00:00:00 2001
From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch>
Date: Mon, 19 Feb 2018 23:40:12 +0100
Subject: [PATCH] Add Find-InstallationPackage function.

Refers to #28
---
 Updater/Update-Service.ps1 | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/Updater/Update-Service.ps1 b/Updater/Update-Service.ps1
index a29605c..9f2a170 100644
--- a/Updater/Update-Service.ps1
+++ b/Updater/Update-Service.ps1
@@ -336,6 +336,23 @@ function NewConfig-IsValid {
 }
 
 
+function Find-InstallationPackage {
+    Write-Verbose "Looking for installation package using pattern: $($Pattern)"
+    $PkgDir = Get-ChildItem -Path $UpdPathBinaries -Directory -Name |
+        Where-Object {$_ -match $Pattern} |
+        Sort-Object |
+        Select-Object -Last 1
+    
+    if ([string]::IsNullOrEmpty($PkgDir)) {
+        Log-Error "couldn't find installation package matching '$($Pattern)'!"
+        Exit
+    }
+    $PkgDir = "$($UpdPathBinaries)\$($PkgDir)"
+    Write-Verbose "Found update installation package: [$($PkgDir)]"
+    Return $PkgDir
+}
+
+
 function Copy-ServiceFiles {
     try {
         Write-Verbose "Looking for source package using pattern: $($Pattern)"
-- 
GitLab