From f0490818d36a09e4c78d0d1e8fc073b26edb5b13 Mon Sep 17 00:00:00 2001
From: Lab1 <account@vr.rwth-aachen.de>
Date: Thu, 9 Feb 2023 14:10:49 +0100
Subject: [PATCH] make VA Server launcher check whether python/py exists and
 give an error otherwise

---
 Source/VAPlugin/Private/VAServerLauncher.cpp | 33 ++++++++++++++++++--
 1 file changed, 30 insertions(+), 3 deletions(-)

diff --git a/Source/VAPlugin/Private/VAServerLauncher.cpp b/Source/VAPlugin/Private/VAServerLauncher.cpp
index a418dc2..5c69a80 100644
--- a/Source/VAPlugin/Private/VAServerLauncher.cpp
+++ b/Source/VAPlugin/Private/VAServerLauncher.cpp
@@ -128,9 +128,36 @@ bool FVAServerLauncher::StartVAServerLauncher()
   FString LauncherScript = TEXT("VirtualAcousticsStarterServer.py");
   if (FPaths::FileExists(FPaths::Combine(LauncherScriptDir, LauncherScript)))
   {
-    FString command = "cd/d "+ LauncherScriptDir+" & start python " + LauncherScript;
-    system(TCHAR_TO_ANSI(*command));
-    return true;
+		FString CMDCommand = "cd/d " + LauncherScriptDir + " & ";
+
+		//check whether py or python exist
+		auto DoesCommandExist = [&](FString Command)
+		{
+			//this checks whether a given command returns a result
+			FString TmpCmdResultFile = "tmpPyVersion.txt";
+			TmpCmdResultFile = FPaths::Combine(LauncherScriptDir, TmpCmdResultFile);
+			Command = Command + " >> " + TmpCmdResultFile;
+			system(TCHAR_TO_ANSI(*Command));
+			FString Result;
+			FFileHelper::LoadFileToString(Result, *TmpCmdResultFile);
+			IFileManager::Get().Delete(*TmpCmdResultFile);
+			return !Result.IsEmpty();
+		};
+
+		bool bPyExists = DoesCommandExist("py --version");
+		bool bPythonExists = DoesCommandExist("python --version");
+
+		if(bPythonExists || bPyExists)
+		{
+			FString Command = CMDCommand + "start " + (bPythonExists?"python":"py") + " " + LauncherScript;
+			system(TCHAR_TO_ANSI(*Command));
+			return true;
+		}
+		else
+		{
+			FVAUtils::OpenMessageBox("VA Launcher cannot be started since neither \"py\" nor \"python\" can be found. If it is installed add it to PATH (and restart Visual Studio)", true);
+			return false;
+		}
   }
   else
   {
-- 
GitLab