From f81a288e88fd920b708eaf3e2abf73aaa1a997e4 Mon Sep 17 00:00:00 2001
From: Jonas Stienen <jst@akustik.rwth-aachen.de>
Date: Mon, 24 Oct 2016 18:24:53 +0200
Subject: [PATCH] Improving itaVA setup

---
 applications/VirtualAcoustics/VA/itaVA.m      |  6 ++--
 .../VirtualAcoustics/VA/itaVA_setup.m         | 32 +++++++++++++++----
 2 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/applications/VirtualAcoustics/VA/itaVA.m b/applications/VirtualAcoustics/VA/itaVA.m
index fabbaf11..96a18f6a 100644
--- a/applications/VirtualAcoustics/VA/itaVA.m
+++ b/applications/VirtualAcoustics/VA/itaVA.m
@@ -47,12 +47,14 @@ classdef itaVA < handle
         
         function [ ok ] = check_for_mex_file()
             % Checks if VAMatlab executable can be found.
-            if ~exist( 'VAMatlab', 'var' )
+            if ~exist( 'VAMatlab', 'file' )
                 disp( 'Matlab binding for VA not complete (missing VAMatlab executable).' )
-                ok = false;
                 
                 % file dialog
+                itaVA_setup()
                 
+                % Re-check
+                ok = exist( 'VAMatlab', 'file' ) > 0;
             else
                 ok = true;
             end
diff --git a/applications/VirtualAcoustics/VA/itaVA_setup.m b/applications/VirtualAcoustics/VA/itaVA_setup.m
index d195dc5a..98a60900 100644
--- a/applications/VirtualAcoustics/VA/itaVA_setup.m
+++ b/applications/VirtualAcoustics/VA/itaVA_setup.m
@@ -58,15 +58,27 @@ handles.output = hObject;
 % Update handles structure
 guidata(hObject, handles);
 
+% VAMatlab
 current_va_mex_dir = which( 'VAMatlab' );
-
 if ~isempty( current_va_mex_dir )
     [ va_mex_path, ~, ~ ] = fileparts( current_va_mex_dir );
-    set( handles.va_search_dir, 'String', fullfile( va_mex_path, '..' ) );
+    [ va_path, ~, ~ ] = fileparts( va_mex_path );
+    set( handles.va_search_dir, 'String', fullfile( va_path ) );
+    
+    set( handles.edit_vamatlab_full_path, 'String', current_va_mex_dir )
+    v = VAMatlab( 'getVersion' );
+    set( handles.edit_vamatlab_version, 'String', v )
+end
+
+% VAServer
+current_va_server_dir = which( 'VAServer.exe' );
+if ~isempty( current_va_server_dir )
+    set( handles.edit_vaserver_full_path, 'String', current_va_server_dir )
+    [ ~, v ] = system( [ current_va_server_dir ' --version' ] );
+    set( handles.edit_vaserver_version, 'String', strcat( v ) )
 end
 
-% UIWAIT makes itaVA_setup wait for user response (see UIRESUME)
-% uiwait(handles.figure1);
+uiwait( handles.figure1 );
 
 
 % --- Outputs from this function are returned to the command line.
@@ -77,7 +89,9 @@ function varargout = itaVA_setup_OutputFcn(hObject, eventdata, handles)
 % handles    structure with handles and user data (see GUIDATA)
 
 % Get default command line output from handles structure
-varargout{1} = handles.output;
+if ~isempty( handles )
+    varargout{1} = handles.output;
+end
 
 
 % --- Executes on button press in pushbutton_close.
@@ -197,8 +211,8 @@ if vaserver_found
     end
     vaserver_path = fullfile( vaserver_dir, 'VAServer.exe' );
     set( handles.edit_vaserver_full_path, 'String', vaserver_path )
-    v = system( [ vaserver_path ' --version' ] );
-    set( handles.edit_vamatlab_version, 'String', v )
+    [ ~, v ] = system( [ vaserver_path ' --version' ] );
+    set( handles.edit_vaserver_version, 'String', strcat( v ) )
 else
     set( handles.edit_vaserver_full_path, 'String', 'not found' )
 end
@@ -212,6 +226,10 @@ if exist( fullfile( va_search_dir, component ), 'file' )
     va_component_dir = fullfile( va_search_dir ); % Base path is one folder up
 end
 
+if isempty( va_search_dir )
+    return % something went wrong
+end
+
 if ~found && recursive
     listing = dir( va_search_dir );    
     for idx = 1:length( listing )
-- 
GitLab