-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJSteam_Install.m
284 lines (254 loc) · 9.33 KB
/
JSteam_Install.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
function JSteam_Install(savePath,runTests,openBrowser)
% JSteam Toolbox Installation File
%
% JSteam_Install(savePath, runTests, openBrowser)
%
% savePath: Save the paths added by JSteam to the MATLAB path
% runTests: Run the post-installation tests
% openBrowser: Whether to open the JSteam Toolbox Website after installation
%
% All arguments are optional and if not supplied, the user will be prompted
% to enter their selection in the MATLAB Command Window. True is the
% default option for each argument.
%
% You MUST be in the current directory of this file!
%
% Copyright (C) 2023 Jonathan Currie (Control Engineering)
% https://www.controlengineering.co.nz/Wikis/JSteam/pmwiki.php/Matlab/Main
% Handle missing input args
if (nargin < 3), openBrowser = []; end
if (nargin < 2), runTests = []; end
if (nargin < 1), savePath = []; end
cpath = cd;
try
cd('Utilities');
catch %#ok<CTCH>
error('You don''t appear to be in the JSteam Toolbox directory');
end
%Get current versions
cur_ver = JSteamver();
fprintf('\n------------------------------------------------\n')
fprintf([' INSTALLING JSTEAM MATLAB INTERFACE ver ' sprintf('%1.2f',cur_ver) '\n\n'])
%Perform pre-req check
cd(cpath);
if(~preReqChecks(cpath))
return;
end
%Uninstall previous versions
fprintf('\n- Checking for previous versions of JSteam Toolbox...\n');
no = JSteam_Uninstall('JSteam_Install.m',0);
if(no < 1)
fprintf('Could not find a previous installation of JSteam Toolbox\n');
else
fprintf('Successfully uninstalled previous version(s) of JSteam Toolbox\n');
end
%Add toolbox path to MATLAB
fprintf('\n- Adding JSteam Paths to MATLAB Search Path...');
genp = genpath(cd);
genp = regexp(genp,';','split');
%Folders to exclude from adding to Matlab path
i = 1;
rInd{:,:,i} = strfind(genp,'vti_cnf'); i = i + 1;
rInd{:,:,i} = strfind(genp,'vti_pvt'); i = i + 1;
rInd{:,:,i} = strfind(genp,'Source'); i = i + 1;
rInd{:,:,i} = strfind(genp,'Internal Tests'); i = i + 1;
rInd{:,:,i} = strfind(genp,'fluids'); i = i + 1;
rInd{:,:,i} = strfind(genp,'.git'); i = i + 1;
ind = NaN(length(rInd{1}),1);
%Track indices of paths to remove from list
for i = 1:length(rInd{1})
for j = 1:size(rInd,3)
if(any(rInd{j}{i}))
ind(i) = 1;
end
end
end
%Remove paths from above and add to matlab path
genp(ind == 1) = [];
addpath(genp{:});
rehash
fprintf('Done\n\n');
if (isempty(savePath))
in = input('- Would You Like To Save the Path Changes? (Recommended) (y/n): ','s');
else
in = bool2yn(savePath);
end
if(strcmpi(in,'y'))
try
savepath;
catch %#ok<CTCH>
warning('opti:install',['It appears you do not have administrator rights on your computer to save the Matlab path. '...
'In order to run JSteam Toolbox you will need to install it each time you wish to use it. To fix '...
'this please contact your system administrator to obtain administrator rights.']);
end
end
%Post Install Test if requested
if (isempty(runTests))
in = input('\n- Would You Like To Run Post Installation Tests? (Recommended) (y/n): ','s');
else
in = bool2yn(runTests);
end
if(strcmpi(in,'y'))
ok = JSteam_Install_Test(1);
else
ok = true;
end
if(ok)
%Launch Examples page
if (isempty(openBrowser) || (openBrowser == true))
web('https://www.controlengineering.co.nz/Wikis/JSteam/pmwiki.php/Matlab/Main','-browser');
end
%Finished
fprintf('\nJSteam Toolbox Installation Complete!\n');
end
disp('------------------------------------------------')
function no = JSteam_Uninstall(token,del)
%Check nargin in, default don't delete
if(nargin < 2 || isempty(del))
del = 0;
end
%Check if we have anything to remove
paths = which(token,'-all');
len = length(paths);
if(~len) %should always be at least 1 if we are in correct directory
error('Expected to find "%s" in the current directory - please ensure you are in the JSteam Toolbox directory');
elseif(len == 1)
%if len == 1, either we are in the correct folder with nothing to remove, or we are in the
%wrong folder and there are files to remove, check CD
if(any(strfind(paths{1},cd)))
no = 0;
return;
else
error('Expected to find "%s" in the current directory - please ensure you are in the JSteam Toolbox directory',token);
end
else %old ones to remove
%Remove each folder found, and all subdirs under
for n = 2:len
%Absolute path to remove
removeP = paths{n};
%Search backwards for first file separator (we don't want the filename)
for j = length(removeP):-1:1
if(removeP(j) == filesep)
break;
end
end
removeP = removeP(1:max(j-1,1));
%Everything is lowercase to aid matching
lrpath = lower(removeP);
opath = regexp(lower(path),';','split');
%Find & Remove Matching Paths
no = 0;
for i = 1:length(opath)
%If we find it in the current path string, remove it
fnd = strfind(opath{i},lrpath);
if(~isempty(fnd))
rmpath(opath{i});
no = no + 1;
end
end
%Check we aren't removing our development version
rehash;
if(isdir([removeP filesep 'Testing'])) %is this robust enough?
fprintf('Found development version in "%s", skipping.\n',removeP);
return;
end
%If delete is specified, also delete the directory
if(del)
stat = recycle; recycle('on'); %turn on recycling
rmdir(removeP,'s'); %not sure if we dont have permissions here
recycle(stat); %restore to original
end
end
end
function OK = preReqChecks(cpath)
%Search for each required prereq
% Note we no longer search the registry, simply check if we can load a mex
% file which requires each runtime
if(~isempty(strfind(computer,'64')))
arch = 'x64';
icarch = 'intel64';
else
arch = 'x86';
icarch = 'ia32';
end
mver = ver('MATLAB');
fprintf('- Checking MATLAB version and operating system...\n');
vv = regexp(mver.Version,'\.','split');
if(str2double(vv{1}) < 8)
if(str2double(vv{2}) < 12)
if(str2double(vv{2}) < 10)
error('MATLAB 2011a or above is required to run JSteam - sorry!');
else %2010a/b/sp1
fprintf(2,'JSteam is designed for MATLAB 2011a or above.\nIt will install into 2010a, but you may experience reliability problems.\nPlease upgrade to R2011a or later.\n');
end
end
end
switch(mexext)
case 'mexw32'
% fprintf('MATLAB %s 32bit (Windows x86) detected\n',mver.Release);
error('From v1.72 JSteam Toolbox only supports 64bit (Windows x64) platforms.');
case 'mexw64'
fprintf('MATLAB %s 64bit (Windows x64) detected\n',mver.Release);
otherwise
error('JSteam Toolbox is compiled only for Windows systems - sorry!');
end
fprintf('\n- Checking for required pre-requisites...\n');
missing = false;
havVC = true; havIF = true;
%Check for VC++ 2012
if(~isempty(strfind(computer,'64')))
cd('MEX/Win64');
else
cd('MEX/Win32');
end
try
a = vc19check; %#ok<NASGU>
catch
havVC = false;
end
try
a = JSteamMEX; %#ok<NASGU>
catch
havIF = false;
end
cd(cpath);
%See if missing anything
if(~havVC || ~havIF)
missing = true;
end
%Print Missing PreReqs
if(~havVC)
fprintf(2,'Cannot find the Microsoft VC++ 2019 %s Redistributable!\n',arch);
else
fprintf('Found the Microsoft VC++ 2019 %s Redistributable\n',arch);
end
if(~havIF)
fprintf(2,'Cannot find the Intel Fortran XE 2019 %s Redistributable!\n',arch);
else
fprintf('Found the Intel Fortran XE 2019 %s Redistributable\n',arch);
end
%Install Instructions for each Package
if(missing)
fprintf(2,'\nYou are missing one or more pre-requisites. Please read the instructions below carefully to install them:\n\n');
if(~havVC)
fprintf(2,' Microsoft VC++ 2019:\n - Download from: https://aka.ms/vs/17/release/vc_redist.x64.exe\n');
fprintf(2,' - When prompted, select the ''%s'' package. Once downloaded, install it.\n\n',arch);
fprintf(2,['NOTE: If you have already downloaded and installed VC++ 2019 (and restarted MATLAB) - it may be that you are missing the Universal C Runtime (Universal CRT).\nThis is automatically installed '...
'with Windows Updates - but if you don''t have those turned on, you can download it from here:\nhttps://www.microsoft.com/en-us/download/details.aspx?id=48234\n\n']);
end
if(~havIF)
fprintf(2,' Intel Fortran XE 2019:\n - Download from: https://software.intel.com/en-us/articles/redistributable-libraries-for-intel-c-and-fortran-2019-compilers-for-windows\n');
fprintf(2,' - The download page will contain multiple links. Download the latest (highest number) update from the ''Intel Fortran Compiler for Windows Table''\n');
fprintf(2,' - The download package will contain two files. Install the ''%s'' package.\n\n',icarch);
end
fprintf(2,'\nOnce you have downloaded AND installed all the above packages, you MUST restart MATLAB.\n\nIf this message appears again after installing the above packages, try restarting your computer.\n\n\n');
OK = false;
else
OK = true;
end
function in = bool2yn(val)
if (isempty(val) || val == true)
in = 'y';
else
in = 'n';
end