From 4e3d5bd4581250a49974a19b37f55fc76165051a Mon Sep 17 00:00:00 2001
From: Oskar Manhart <52569953+oskardotglobal@users.noreply.github.com>
Date: Sat, 7 Sep 2024 13:28:43 +0200
Subject: [PATCH] fix: catch error if exe has no version info

---
 install/ExtractPrograms.ps1 | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/install/ExtractPrograms.ps1 b/install/ExtractPrograms.ps1
index b1587ea..3357f15 100644
--- a/install/ExtractPrograms.ps1
+++ b/install/ExtractPrograms.ps1
@@ -103,11 +103,9 @@ function GetApplicationName {
         [string]$exePath
     )
 
-    if ((Get-Item $exePath).VersionInfo.FileDescription) {
-        # Remove leading/trailing whitespace and replace multiple spaces with a single space.
+    try {
         $productName = (Get-Item $exePath).VersionInfo.FileDescription.Trim() -replace '\s+', ' '
-    } else {
-        # Get the executable file name without the file extension.
+    } catch {
         $productName = [System.IO.Path]::GetFileNameWithoutExtension($exePath)
     }
 
@@ -125,10 +123,7 @@ function GetUWPApplicationName {
 
     # Query the application executable for the application name.
     if (Test-Path $exePath) {
-        if ((Get-Item $exePath).VersionInfo.FileDescription) {
-            # Remove leading/trailing whitespace and replace multiple spaces with a single space.
-            $productName = (Get-Item $exePath).VersionInfo.FileDescription.Trim() -replace '\s+', ' '
-        }
+        $productName = GetApplicationName -exePath $exePath
     }
 
     # Use the 'DisplayName' (if available) if the previous method failed.
-- 
GitLab