@@ -29,11 +29,40 @@ function setup(varargin)
2929 try
3030 ghtb .require(requiredToolboxes , ' prompt' , prompt );
3131 catch ME
32- if strcmp(ME .identifier , ' MATLAB:undefinedVarOrClass' )
32+ installPromptMsg = {
33+ ' Toolbox ''%s'' did not meet the minimum requirements.'
34+ ' Would you like to proceed with an upgrade?'
35+ };
36+ if strcmp(ME .identifier , ' MATLAB:undefinedVarOrClass' ) && (~prompt || strcmpi(' yes' ,...
37+ dj .internal .ask(sprintf(sprintf(' %s\n ' , installPromptMsg{: }), ' GHToolbox' ))))
38+ % fetch
39+ tmp_toolbox = [tempname ' .mltbx' ];
40+ websave(tmp_toolbox , [' https://github.com/' requiredToolboxes{1 }.ResolveTarget ...
41+ ' /releases/download/' ...
42+ subsref(webread([' https://api.github.com/repos/' ...
43+ requiredToolboxes{1 }.ResolveTarget ...
44+ ' /releases/latest' ], ...
45+ weboptions(' Timeout' , 60 )), ...
46+ substruct(' .' , ' tag_name' )) ...
47+ ' /GHToolbox.mltbx' ], weboptions(' Timeout' , 60 ));
48+ % install
49+ try
50+ matlab .addons .install(tmp_toolbox , ' overwrite' );
51+ catch ME
52+ if strcmp(ME .identifier , ' MATLAB:undefinedVarOrClass' )
53+ matlab .addons .toolbox .installToolbox(tmp_toolbox );
54+ else
55+ rethrow(ME );
56+ end
57+ end
58+ % remove temp toolbox file
59+ delete(tmp_toolbox );
60+ % retrigger dependency validation
61+ ghtb .require(requiredToolboxes , ' prompt' , prompt );
62+ elseif strcmp(ME .identifier , ' MATLAB:undefinedVarOrClass' )
3363 GHToolboxMsg = {
34- ' Toolbox '' GHToolbox'' did not meet the minimum minimum requirements.'
35- ' Please install it via instructions in '
36- ' '' https://github.com/datajoint/GHToolbox'' ' .'
64+ ' Toolbox '' GHToolbox'' did not meet the minimum requirements.'
65+ ' Please proceed to install it.'
3766 };
3867 error(' DataJoint:verifyGHToolbox:Failed' , ...
3968 sprintf(' %s\n ' , GHToolboxMsg{: }));
0 commit comments