forked from dscho/fiji
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InstallJava3D.m
135 lines (105 loc) · 4.83 KB
/
InstallJava3D.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
function InstallJava3D
%% Install Java3D.
% Use Miji and Fiji power to automatically download and install Java3D for
% the MATLAB JVM, so that we can play with accelerated 3D afterwards.
% Jean-Yves Tinevez, Johannes Schindelin, July 2011
%% Process
% First, silently launch Miji, which will make Fiji libs accessible.
Miji(false)
% Second, test if we have Java3D installed already. We do this by
% instantiating a Java3D class and checking if we raise an exception.
fprintf('Testing if Java3D is already installed...\n');
isJava3DInstalled = IsJava3DInstalled();
if isJava3DInstalled
j3dvsersionstr = char(ij3d.Install_J3D.getJava3DVersion());
fprintf('Java3D is already installed.\n')
fprintf('Installed version is %s.\n', j3dvsersionstr)
j3dvsersion = str2double(j3dvsersionstr);
if j3dvsersion >= 1.5
fprintf('This is good enough, you have nothing to do.\n');
fprintf('Exiting.\n');
fprintf('\n');
return
end
fprintf('We need at least version 1.5, so let us update it.\b')
fprintf('\n');
else
fprintf('Java3D is not installed.\n');
fprintf('Let us try to install it.\n');
fprintf('\n');
end
fprintf('Determining the target JVM ext folder...\n')
ext_path = char(ij3d.Install_J3D.getFirstExtDir());
fprintf('Target path is %s.\n', ext_path);
fprintf('\n');
fprintf('Determining if we have write access to JVM ext folder...\n')
[status attrib] = fileattrib(ext_path); %
if ~status
fprintf('Cannot determine the attributes of %s. Aborting.\n', ext_path);
return
end
canwrite = false;
if attrib.UserWrite
canwrite = true;
fprintf('MATLAB says that we can write to the path. Let us double check.\n');
% Indeed, under recent versions of Windows, the permissions reported
% by MATLAB can be erroneous because of UAC...
try
testfile = java.io.File([ext_path java.io.File.separatorChar 'test']);
if (testfile.exists())
testfile.delete()
end
testfile.createNewFile();
testfile.delete();
fprintf('Ok, we do have the right to write to %s.\n', ext_path)
catch ioe %#ok<NASGU>
fprintf('Writing test shows that we CANNOT write to the ext path.\n')
fprintf('We do not have the right to write to %s,\ninstallation CANNOT be done automatically.\n', ext_path)
canwrite = false;
end
% On windows versions, we also have to test that the bin folder is
% writable, for it is where the .dll files are going.
if ispc
bin_path = [ char(java.lang.System.getProperty('java.home')) java.io.File.separatorChar 'bin' ];
try
testfile = java.io.File([bin_path java.io.File.separatorChar 'test']);
if (testfile.exists())
testfile.delete()
end
testfile.createNewFile();
testfile.delete();
fprintf('Ok, we do have the right to write to %s.\n', bin_path)
catch ioe %#ok<NASGU>
fprintf('Writing test shows that we CANNOT write to the bin path.\n')
fprintf('We do not have the right to write to %s,\ninstallation CANNOT be done automatically.\n', bin_path)
canwrite = false;
end
end
end
if canwrite
fprintf('We can write to the path, installation will proceed.\n')
plugin = ij3d.Install_J3D();
plugin.run('')
fprintf('\n');
fprintf('OK, so the files are in place.\n');
fprintf('You still need to RELAUNCH MATLAB so that they can be sourced.\n');
fprintf('(It will NOT work if you do not restart MATLAB.)\n');
fprintf('Then, calling this script again should tell you that everyting is in place.\n');
fprintf('Exiting.\n');
fprintf('\n');
else
fprintf('\n');
fprintf('OK, so this is where you have to intervene manually.\n')
fprintf('You will have to ask or impersonate your computer''s administrator\n')
fprintf('so that it gives you WRITE PERMISSION to the following folder:\n')
fprintf('\t -> %s.\n', ext_path)
if ispc
fprintf('\t -> %s.\n', bin_path)
end
fprintf('\n');
fprintf('Once (s)he or you did that, relaunch this helper script, saying\n');
fprintf('''Yes'' to any question you might be asked.\n');
fprintf('\n');
fprintf('After that, of course, you will still need to relaunch MATLAB.\n');
end
end