~ubuntu-branches/ubuntu/trusty/psychtoolbox-3/trusty-proposed

« back to all changes in this revision

Viewing changes to Psychtoolbox/PsychtoolboxPostInstallRoutine.m

  • Committer: Package Import Robot
  • Author(s): Yaroslav Halchenko
  • Date: 2013-11-19 23:34:50 UTC
  • mfrom: (3.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20131119233450-f7nf92vb8qavjmk8
Tags: 3.0.11.20131017.dfsg1-3
Upload to unsable since fresh glew has arrived to sid!

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
%    working copy of Psychtoolbox.
20
20
% 3. Add the PsychJava subfolder to the static Matlab class-path if neccessary.
21
21
%    This enables the Java-based GetChar support on Matlab.
 
22
% 4. Add the PsychStartup.m routine to Matlab's startup.m file on Windows.
 
23
% 5. Perform post-installation checks and basic troubleshooting.
22
24
 
23
25
%
24
26
% History:
42
44
% 10/31/2011 Add call to SwitchToNewPsychtoolboxHoster for switch to
43
45
%            GoogleCode, if needed. (MK)
44
46
% 01/06/2012 Add support for calling PsychLinuxConfiguration on Linux. (MK)
45
 
%
 
47
% 04/30/2012 Add support for 64-Bit OSX. (MK)
 
48
% 06/13/2012 Removed call to SwitchToNewPsychtoolboxHoster, no longer needed (DN)
 
49
% 07/10/2012 Use textscan() on R2012a+ and verLessThan() to detect R2007a+ (MK)
 
50
% 09/05/2012 Update support for 64-Bit Octave and versions > 3.2. (MK)
 
51
% 09/13/2012 Add startup.m setup for 64-Bit Matlab + 64-Bit Windows. (MK)
 
52
% 09/14/2012 Cancel support for Octave on MS-Windows. (MK)
 
53
% 09/14/2012 Cancel support for 32-Bit Octave on OSX. (MK)
 
54
% 11/11/2012 More cleanup. E.g., don't warn about Octave > 3.2 anymore. (MK)
 
55
% 04/16/2013 Use javaclasspath.txt instead of classpath.txt on R2013a and later. (MK)
 
56
% 05/13/2013 Factor out Java classpath setup to call to PsychJaveTrouble(1). (MK)
 
57
% 07/02/2013 Drop support for 32-Bit Matlab on OSX, and thereby for 32-Bit OSX. (MK)
 
58
% 07/02/2013 Drop support for OSX versions older than 10.6 "Snow Leopard". (MK)
 
59
% 09/12/2013 Setup PsychStartup.m in startup.m for 32-Bit Windows as well. (MK)
46
60
 
47
61
fprintf('\n\nRunning post-install routine...\n\n');
48
62
 
49
 
if exist('SwitchToNewPsychtoolboxHoster.m', 'file')
50
 
   clear SwitchToNewPsychtoolboxHoster;
51
 
 
52
 
   % Check if we are still hosted on Berlios, switch to GoogleCode, if so:
53
 
   SwitchToNewPsychtoolboxHoster;
54
 
end;
55
 
 
56
63
if nargin < 1
57
64
   error('PsychtoolboxPostInstallRoutine: Required argument isUpdate missing!');
58
65
end;
87
94
                end
88
95
            end
89
96
        end
90
 
    catch
 
97
    catch %#ok<*CTCH>
91
98
        fprintf('Info: Failed to determine flavor of this Psychtoolbox. Not a big deal...\n');
92
99
    end
93
100
else
136
143
    fprintf('Info: Failed to remove .svn subfolders from path. Not a big deal...\n');
137
144
end
138
145
 
139
 
% Check for operating system minor version on Mac OS/X when running under
140
 
% Matlab:
 
146
% Octave on Windows? This is unsupported as of Version 3.0.10.
 
147
if IsWin && IsOctave
 
148
    error('Use of GNU/Octave on MS-Windows with Psychtoolbox 3.0.10 is no longer supported. Aborted.');
 
149
end
 
150
 
 
151
% 32-Bit Octave or 32-Bit Matlab on OSX? This is unsupported as of Version 3.0.11.
 
152
if IsOSX && ~Is64Bit
 
153
    fprintf('Psychtoolbox 3.0.11 and later do no longer work with 32-Bit versions of Octave or Matlab on OSX.\n');
 
154
    fprintf('You need to upgrade to a 64-Bit version of Octave or Matlab on OSX, which is fully supported.\n');
 
155
    fprintf('You can also use the alternate download function DownloadLegacyPsychtoolbox() to download\n');
 
156
    fprintf('an old legacy copy of Psychtoolbox-3.0.9, which did support 32-Bit Octave 3.2 on OSX, or use\n');
 
157
    fprintf('DownloadPsychtoolbox() with flavor ''Psychtoolbox-3.0.10'', which does support 32-Bit Matlab on OSX.\n');
 
158
    error('Tried to setup on 32-Bit Octave, which is no longer supported on OSX.');
 
159
end
 
160
 
 
161
% Check if our own startup function is part of the startup file and add it,
 
162
% if it isn't already part of it. Currently we only need this for MS-Windows.
 
163
if IsWin
 
164
    % Is it already implanted? Then we ain't nothing to do:
 
165
    if ~IsPsychStartupImplantedInStartup
 
166
        % Nope. Does a proper file already exist?
 
167
        whereisit = which('startup.m');
 
168
        if isempty(whereisit)
 
169
            % No: Create our own one.
 
170
            whereisit = [PsychtoolboxRoot 'PsychInitialize' filesep 'startup.m'];
 
171
            fprintf('Creating a startup.m file for Psychtoolbox at %s\n', whereisit);
 
172
        else
 
173
            fprintf('Adding PsychStartup() call to Matlab startup.m file for Psychtoolbox at %s\n', whereisit);            
 
174
        end
 
175
        
 
176
        % whereisit points to the location of the existing or to be created
 
177
        % file. Open (or create) it in append mode:
 
178
        try
 
179
            fd = fopen(whereisit, 'a');
 
180
            fprintf(fd, '\n');
 
181
            fprintf(fd, '%% Call Psychtoolbox-3 specific startup function:\n');
 
182
            fprintf(fd, 'if exist(''PsychStartup''), PsychStartup; end;\n');
 
183
            fprintf(fd, '\n');
 
184
            fclose(fd);
 
185
        catch
 
186
            fprintf('WARNING: Failed to update or create startup.m file to add a call to PsychStartup()! Trouble ahead.\n');
 
187
        end
 
188
    end
 
189
    
 
190
    % Execute our startup function once manually, so it works already for
 
191
    % this session:
 
192
    PsychStartup;
 
193
end
 
194
 
 
195
% Check for operating system minor version on Mac OS/X.
141
196
if IsOSX
142
 
    if ~IsOctave %#ok<AND2>
143
 
        % Running on Matlab + OS/X. Find the operating system minor version,
144
 
        % i.e., the 'y' in the x.y.z number, e.g., y=3 for 10.3.7:
145
 
 
146
 
        % Get 32-digit binary encoded minor version from Gestalt() MEX file:
147
 
        binminor = Gestalt('sys2');
148
 
 
149
 
        % Decode into decimal digit:
150
 
        minorver = 0;
151
 
        for i=1:32
152
 
            minorver = minorver + binminor(i) * 2^(32-i);
153
 
        end
 
197
    % Query kernel version via system() call:
 
198
    [s, did]=system('uname -r');
 
199
    if s == 0
 
200
        % Parse string for kernel major number, then translate to OS
 
201
        % minor version by subtracting 4:
 
202
        minorver = sscanf(did, '%i') - 4;
154
203
    else
155
 
        % Running on Octave + OS/X: Query kernel version via system() call:
156
 
        [s, did]=system('uname -r');
157
 
        if s == 0
158
 
            % Parse string for kernel major number, then translate to OS
159
 
            % minor version by subtracting 4:
160
 
            minorver = sscanf(did, '%i') - 4;
161
 
        else
162
 
            % Failed to query: Assume we're good for now...
163
 
            minorver = inf;
164
 
        end
 
204
        % Failed to query: Assume we're good for now...
 
205
        minorver = inf;
165
206
    end
166
207
    
167
 
    % Is the operating system minor version 'minorver' < 4?
168
 
    if minorver < 4
169
 
        % Yes. This is MacOS/X 10.3 or earlier, i.e., older than 10.4
170
 
        % Tiger. In all likelihood, this current PTB release won't work on
171
 
        % such a system anymore, because some of the binary MEX files are
172
 
        % linked against incompatible runtimes and frameworks. Output a
173
 
        % clear warning message about this, with tips on how to resolve the
174
 
        % problem:
 
208
    % Is the operating system minor version 'minorver' < 6?
 
209
    if minorver < 6
 
210
        % Yes. This is MacOSX 10.5 or earlier, i.e., older than 10.6
 
211
        % Snow Leopard. PTB will not work on such an old system:
175
212
        fprintf('\n\n\n\n\n\n\n\n==== WARNING WARNING WARNING WARNING ====\n\n');
176
213
        fprintf('Your operating system is Mac OS/X version 10.%i.\n\n', minorver);
177
 
        fprintf('This release of Psychtoolbox-3 is likely no longer compatible\n');
178
 
        fprintf('to OS/X versions older than 10.4 "Tiger".\n\n');
179
 
        fprintf('That means that some or many crucial functions will fail.\n');
180
 
        fprintf('You may encounter errors or failures during the remainder of\n');
181
 
        fprintf('this installation procedure, or later on during use of the toolkit.\n\n');
182
 
        fprintf('You can fix this problem by switching to the last Psychtoolbox version\n');
183
 
        fprintf('that was known to (mostly) work on your old operating system:\n\n');
184
 
        fprintf('1. Type clear all on the Matlab command prompt.\n\n');
185
 
        fprintf('2. Run the downloader script DownloadPsychtoolbox again,\n');
186
 
        fprintf('   (see help DownloadPsychtoolbox for usage information),\n');
187
 
        fprintf('   but specify the optional "flavor" argument as:\n\n');
188
 
        fprintf('   ''Psychtoolbox-3.0.8-PreTiger''\n\n');
189
 
        fprintf('   Example for a standard installation in standard location:\n\n');
190
 
        fprintf('   DownloadPsychtoolbox([],[],[],''Psychtoolbox-3.0.8-PreTiger'');\n\n\n');
191
 
        fprintf('This will delete your current copy of Psychtoolbox-3 and replace it\n');
192
 
        fprintf('by the last known good version for your system.\n\n');
193
 
        fprintf('Please note that we will no longer provide support, bug fixes or enhancements\n');
194
 
        fprintf('for this old release on your old and obsolete operating system - You are on your own.\n\n');
195
 
        fprintf('We strongly recommend that you upgrade your system to a more recent OS/X version soon.\n\n');
196
 
        fprintf('Thanks for your attention and good luck!');
 
214
        fprintf('This release of Psychtoolbox-3 is not compatible\n');
 
215
        fprintf('to OSX versions older than 10.6 "Snow Leopard".\n');
 
216
        fprintf('That means that almost all functionality will not work!\n\n');
 
217
        fprintf('You can either download an older version of Psychtoolbox\n');
 
218
        fprintf('onto your system to get better results. See our Wiki for help.\n');
 
219
        fprintf('Better though, update your operating system to at least version\n');
 
220
        fprintf('10.6.8 "Snow Leopard" or later.\n');
197
221
        fprintf('\n\n\n==== WARNING WARNING WARNING WARNING ====\n\n\n');
198
 
        fprintf('Press any key on keyboard to continue with setup...\n');
 
222
        fprintf('Press any key on keyboard to try to continue with setup, although\n');
 
223
        fprintf('this will likely fail soon and leave you with a dysfunctional toolbox.\n\n');
199
224
        pause;
200
225
    end
201
226
end
202
227
 
203
228
% Matlab specific setup:
204
229
if ~IsOctave
205
 
    % Check if this is Matlab of version prior to V 6.5:
 
230
    % Check if this is Matlab of version prior to V 7.4:
206
231
    v = ver('matlab');
207
232
    if ~isempty(v)
208
233
        v = v(1).Version; v = sscanf(v, '%i.%i.%i');
209
 
        if (v(1) < 6) | ((v(1) == 6) & (v(2) < 5)) %#ok<AND2,OR2>
210
 
            % Matlab version < 6.5 detected. This is no longer
 
234
        if (v(1) < 7) || ((v(1) == 7) && (v(2) < 4))
 
235
            % Matlab version < 7.4 detected. This is no longer
211
236
            % supported.
212
 
            fprintf('\n\nYou are using a Matlab version older than Version 6.5.\n');
 
237
            fprintf('\n\nYou are using a Matlab version older than Version 7.4.\n');
213
238
            fprintf('The current "beta" flavor is no longer compatible with your version of Matlab.\n');
214
 
            fprintf('Current "beta" only works on Matlab Version 6.5 or later.\n\n');
 
239
            fprintf('Current "beta" only works on Matlab Version 7.4 (R2007a) or later.\n\n');
215
240
            fprintf('I will try to finish setup, but most functions will not work for you.\n');
216
 
            fprintf('Please run the DownloadPsychtoolbox downloader now to download an outdated,\n');
217
 
            fprintf('but functional older version of Psychtoolbox for your Matlab setup or to\n');
 
241
            fprintf('Please run the legacy DownloadLegacyPsychtoolbox() downloader to download an outdated,\n');
 
242
            fprintf('but functional older version of Psychtoolbox (e.g., V3.0.9) for your Matlab setup or to\n');
218
243
            fprintf('receive further instructions.\n');
219
244
            fprintf('\n\nPress any key to continue after you have read and understood above message completely.\n\n');
220
245
            pause;
224
249
 
225
250
% Special case handling for Octave:
226
251
if IsOctave
227
 
    % OS/X or Linux under Octave. Need to prepend the proper folder with
 
252
    % GNU/Octave. Need to prepend the proper folder with
228
253
    % the pseudo-MEX files to path:
229
254
    rc = 0; %#ok<NASGU>
230
255
    rdir = '';
239
264
            rmpath([PsychtoolboxRoot 'PsychBasic' filesep 'Octave3LinuxFiles64']);
240
265
        end
241
266
        
 
267
        if exist([PsychtoolboxRoot 'PsychBasic' filesep 'Octave3LinuxFilesARM'], 'dir')
 
268
            rmpath([PsychtoolboxRoot 'PsychBasic' filesep 'Octave3LinuxFilesARM']);
 
269
        end
 
270
        
242
271
        if exist([PsychtoolboxRoot 'PsychBasic' filesep 'Octave3OSXFiles'], 'dir')
243
272
            rmpath([PsychtoolboxRoot 'PsychBasic' filesep 'Octave3OSXFiles']);
244
273
        end
245
274
        
 
275
        if exist([PsychtoolboxRoot 'PsychBasic' filesep 'Octave3OSXFiles64'], 'dir')
 
276
            rmpath([PsychtoolboxRoot 'PsychBasic' filesep 'Octave3OSXFiles64']);
 
277
        end
 
278
        
246
279
        if exist([PsychtoolboxRoot 'PsychBasic' filesep 'Octave3WindowsFiles'], 'dir')
247
280
            rmpath([PsychtoolboxRoot 'PsychBasic' filesep 'Octave3WindowsFiles']);
248
281
        end
259
292
            rdir = [rdir 'LinuxFiles'];
260
293
        end
261
294
        
262
 
        if IsLinux(1)
263
 
            % 64 bit Octave on 64 bit Linux. Select 64 bit mex file folder:
264
 
            rdir = [rdir '64'];
265
 
        end
266
 
        
267
295
        if IsOSX
268
296
            rdir = [rdir 'OSXFiles'];
269
297
        end
271
299
        if IsWin
272
300
            rdir = [rdir 'WindowsFiles'];
273
301
        end
 
302
        
 
303
        if IsARM
 
304
            % ARM processor architecture:
 
305
            rdir = [rdir 'ARM'];
 
306
        end
274
307
 
 
308
        if Is64Bit
 
309
            % 64 bit Octave. Select 64 bit mex file folder:
 
310
            rdir = [rdir '64'];
 
311
        end
 
312
        
275
313
        fprintf('Octave major version %i detected. Will prepend the following folder to your Octave path:\n', octavemajorv);
276
314
        fprintf(' %s ...\n', rdir);
277
315
        addpath(rdir);
278
316
        
279
 
        if exist('savepath') %#ok<EXIST>
280
 
            rc = savepath;
281
 
        else
282
 
            rc = path2rc;
283
 
        end
 
317
        rc = savepath;
284
318
    catch
285
319
        rc = 2;
286
320
    end
296
330
        fprintf('=====================================================================\n\n');
297
331
    end
298
332
    
299
 
    if octavemajorv < 3 | octaveminorv < 2 %#ok<OR2>
 
333
    if (octavemajorv < 3) || (octavemajorv == 3 && octaveminorv < 2)
300
334
        fprintf('\n\n=================================================================================\n');
301
335
        fprintf('WARNING: Your version %s of Octave is obsolete. We strongly recommend\n', version);
302
 
        fprintf('WARNING: using the latest stable version of the Octave 3.2.x series for use with Psychtoolbox.\n');
 
336
        if IsLinux
 
337
            % On Linux everything >= 3.2 is fine:
 
338
            fprintf('WARNING: using the latest stable version of the Octave 3.2.x series or later for use with Psychtoolbox.\n');
 
339
        else
 
340
            % On other OS'es we only care about >= 3.6 atm:
 
341
            fprintf('WARNING: using the latest stable version of the Octave 3.6.x series or later for use with Psychtoolbox.\n');
 
342
        end
303
343
        fprintf('WARNING: Stuff may not work at all or only suboptimal with earlier versions and we\n');
304
344
        fprintf('WARNING: don''t provide any support for such old versions.\n');
305
345
        fprintf('\nPress any key to continue with setup.\n');
307
347
        pause;
308
348
    end
309
349
    
310
 
    if octavemajorv > 3 | (octavemajorv == 3 & octaveminorv > 2) %#ok<AND2,OR2>
311
 
        fprintf('\n\n=================================================================================\n');
312
 
        fprintf('WARNING: Your version %s of Octave is version 3.3 or later.\n', version);
313
 
        fprintf('WARNING: Psychtoolbox is likely not yet compatible with this version and may fail to work.\n');
314
 
        fprintf('WARNING: We currently recommend the latest stable version of the Octave 3.2.x series for use with Psychtoolbox.\n');
315
 
        fprintf('\nPress any key to continue with setup.\n');
316
 
        fprintf('=================================================================================\n\n');
317
 
        pause;
318
 
    end
319
 
    
320
350
    try
321
351
        % Rehash the Octave toolbox cache:
322
352
        path(path);
328
358
    end
329
359
    
330
360
    try
331
 
        % Try if Screen MEX file works...
 
361
        % Try if WaitSecs MEX file works...
332
362
        WaitSecs(0.1);
333
363
    catch
334
364
        % Failed! Either screwed setup of path or missing runtime
335
365
        % libraries.
336
366
        fprintf('ERROR: WaitSecs-MEX does not work, most likely other MEX files will not work either.\n');
337
367
        fprintf('ERROR: One reason might be that your version %s of Octave is incompatible. We recommend\n', version);        
338
 
        fprintf('ERROR: use of the latest stable version of Octave-3.2.x as announced on www.octave.org website.\n');
 
368
        fprintf('ERROR: use of the latest stable version of Octave-3 as announced on the www.octave.org website.\n');
339
369
        fprintf('ERROR: Another conceivable reason would be missing or incompatible required system libraries on your system.\n\n');
340
370
        fprintf('ERROR: After fixing the problem, restart this installation/update routine.\n\n');
341
371
        fprintf('\n\nInstallation aborted. Fix the reported problem and retry.\n\n');
346
376
end
347
377
 
348
378
% Special case handling for different Matlab releases on MS-Windoze:
349
 
if IsWin & ~IsOctave %#ok<AND2>
 
379
if IsWin
350
380
    rc = 0; %#ok<NASGU>
351
381
    
352
382
    if strfind(cd,'system32')
353
 
        % the below code fails i've the current directory is system32 (e.g.
 
383
        % the below code fails if the current directory is system32 (e.g.
354
384
        % C:\Windows\system32), as it contains dlls like version.dll, which
355
385
        % get called instead of the built-in functions....
356
386
        cd(PsychtoolboxRoot);
357
387
    end
 
388
    
358
389
    try
359
390
        % Remove DLL folders from path:
360
 
        rmpath([PsychtoolboxRoot 'PsychBasic\MatlabWindowsFilesR11\']);
361
391
        rmpath([PsychtoolboxRoot 'PsychBasic\MatlabWindowsFilesR2007a\']);
362
392
        
363
 
        % Is this a Release2007a or later Matlab?
364
 
        if ~isempty(strfind(version, '2007')) | ~isempty(strfind(version, '2008')) | ...
365
 
           ~isempty(strfind(version, '2009')) | ~isempty(strfind(version, '2010')) | ...
366
 
           ~isempty(strfind(version, '2011')) | ~isempty(strfind(version, '2012')) | ...
367
 
           ~isempty(strfind(version, '2013')) | ~isempty(strfind(version, '2014')) %#ok<OR2>
368
 
           
 
393
        % Is this a Release2007a (Version 7.4.0) or later Matlab?
 
394
        if ~exist('verLessThan') || verLessThan('matlab', '7.4.0') %#ok<EXIST>
 
395
            % This is a pre-R2007a Matlab: No longer supported by V 3.0.10+
 
396
            fprintf('Matlab release prior to R2007a detected. This version is no longer\n');
 
397
            fprintf('supported by Psychtoolbox 3.0.10 and later. Aborted.');
 
398
            fprintf('\n\nInstallation aborted. Fix the reported problem and retry.\n\n');
 
399
            return;
 
400
        else
369
401
            % This is a R2007a or post R2007a Matlab:
370
402
            % Add PsychBasic/MatlabWindowsFilesR2007a/ subfolder to Matlab
371
403
            % path:
373
405
            fprintf('Matlab release 2007a or later detected. Will prepend the following\n');
374
406
            fprintf('folder to your Matlab path: %s ...\n', rdir);
375
407
            addpath(rdir);
376
 
        else
377
 
            % This is a pre-R2007a Matlab:
378
 
            % Add PsychBasic/MatlabWindowsFilesR11/ subfolder to Matlab
379
 
            % path:
380
 
            rdir = [PsychtoolboxRoot 'PsychBasic\MatlabWindowsFilesR11\'];
381
 
            fprintf('Matlab release prior to R2007a detected. Will prepend the following\n');
382
 
            fprintf('folder to your Matlab path: %s ...\n', rdir);
383
 
            addpath(rdir);
384
408
        end
385
409
 
386
 
        if exist('savepath') %#ok<EXIST>
387
 
            rc = savepath;
388
 
        else
389
 
            rc = path2rc;
390
 
        end
 
410
        rc = savepath;
391
411
    catch
392
412
        rc = 2;
393
413
    end
418
438
        % Try if WaitSecs MEX file works...
419
439
        WaitSecs('YieldSecs', 0.1)
420
440
    catch
421
 
        % Failed! Either screwed setup of path or missing VC++ 2005 runtime
422
 
        % libraries.
423
 
        %         fprintf('ERROR: WaitSecs-MEX does not work, most likely other MEX files will not work either.\n');
424
 
        %         fprintf('ERROR: Most likely cause: The Visual C++ 2005 runtime libraries are missing on your system.\n\n');
425
 
        %         fprintf('ERROR: Visit http://www.mathworks.com/support/solutions/data/1-2223MW.html for instructions how to\n');
426
 
        %         fprintf('ERROR: fix this problem. That document tells you how to download and install the required runtime\n');
427
 
        %         fprintf('ERROR: libraries. It is important that you download the libraries for Visual C++ 2005 SP1\n');
428
 
        %         fprintf('ERROR: - The Service Pack 1! Follow the link under the text "For VS 2005 SP1 vcredist_x86.exe:"\n');
429
 
        %         fprintf('ERROR: If you install the wrong runtime, it will still not work.\n\n');
430
 
        %         fprintf('ERROR: After fixing the problem, restart this installation/update routine.\n\n');
431
 
 
432
 
        fprintf('ERROR: Most likely cause: The most recent security updates to the Visual C++ 2005 runtime libraries\n');
433
 
        fprintf('ERROR: are missing on your system. Go to the following URL:\n\n');
434
 
        fprintf('http://www.microsoft.com/downloads/details.aspx?familyid=766A6AF7-EC73-40FF-B072-9112BAB119C2&displaylang=en#filelist\n\n');
435
 
        fprintf('ERROR: Download and install the required runtime libraries.\n\n');
436
 
        fprintf('ERROR: Use the download button right to vcredist_x86.exe - The file with a size of 2.6 MB.\n');
437
 
        fprintf('ERROR: Then double-click and run the downloaded vcredist_x86.exe installer to update your system.\n');
438
 
        fprintf('ERROR: If you install the wrong runtime, it will still not work.\n\n');
 
441
        % Failed! Either screwed setup of path or missing VC++ 2010 runtime libraries.
 
442
        fprintf('ERROR: Most likely cause: The Microsoft Visual C++ 2010 runtime libraries\n');
 
443
        fprintf('ERROR: are missing on your system.\n\n');
 
444
        if IsWin(1)
 
445
            % Need 64-Bit runtime:
 
446
            fprintf('ERROR: Execute the installer file vcredist_x64.exe, which is located in your Psychtoolbox/PsychContributed/ folder.\n');
 
447
        else
 
448
            % Need 32-Bit runtime:
 
449
            fprintf('ERROR: Execute the installer file vcredist_x86.exe, which is located in your Psychtoolbox/PsychContributed/ folder.\n');
 
450
        end
 
451
        fprintf('ERROR: You must execute that installer as an administrator user. Exit Matlab before the installation, then restart it.\n');
439
452
        fprintf('ERROR: After fixing the problem, restart this installation/update routine.\n\n');
440
 
        fprintf('ERROR: You can also just do a: cd(PsychtoolboxRoot); SetupPsychtoolbox;\n\n');
 
453
        fprintf('ERROR: You can also just do a: cd(PsychtoolboxRoot); SetupPsychtoolbox; PsychtoolboxRegistration(%i, ''%s'');\n\n', isUpdate, flavor);
441
454
        fprintf('ERROR: This will avoid a full download of Psychtoolbox over the internet and just finish the setup.\n');
442
455
        
443
 
        if strcmp(computer,'PCWIN64')
444
 
            % 64 bit Matlab running on 64 bit Windows?!? That won't work.
445
 
            fprintf('ERROR:\n');
446
 
            fprintf('ERROR: It seems that you are running a 64-bit version of Matlab on your system.\n');
447
 
            fprintf('ERROR: That won''t work at all! Psychtoolbox currently only supports 32-bit versions\n');
448
 
            fprintf('ERROR: of Matlab.\n');
449
 
            fprintf('ERROR: You can try to exit Matlab and then restart it in 32-bit emulation mode to\n');
450
 
            fprintf('ERROR: make Psychtoolbox work on your 64 bit Windows. You do this by adding the\n');
451
 
            fprintf('ERROR: startup option -win32 to the matlab.exe start command, ie.\n');
452
 
            fprintf('ERROR: matlab.exe -win32\n');
453
 
            fprintf('ERROR: If you do not know how to do this, consult the Matlab help about startup\n');
454
 
            fprintf('ERROR: options for Windows.\n');
455
 
            fprintf('ERROR: See also http://psychtoolbox.org/wikka.php?wakka=Faq64BitSupport.\n\n');
456
 
        end
457
 
        
458
456
        fprintf('\n\nInstallation aborted. Fix the reported problem and retry.\n\n');
459
457
        return;
460
458
    end
463
461
% If we're using Matlab then add the PsychJava stuff to the static
464
462
% Java classpath.
465
463
if ~IsOctave
466
 
    try
467
 
       % Figure out the PsychJava path we need to add to the static Java
468
 
        % classpath.
469
 
        path_PsychJava = [PsychtoolboxRoot, 'PsychJava'];
470
 
 
471
 
        % Open up the classpath.txt file and find any PsychJava entries.  If
472
 
        % they exist, remove them, and put the current one in the file.  This
473
 
        % only allows on PsychJava to be on the path.
474
 
        classpathFile = which('classpath.txt');
475
 
        bakclasspathFile = [classpathFile '.bak'];
476
 
        
477
 
        fileContents = textread(classpathFile, '%s');
478
 
        j = 1;
479
 
        newFileContents = {};
480
 
        pathInserted = 0;
481
 
        for i = 1:length(fileContents)
482
 
            % Look for the first instance of PsychJava in the classpath and
483
 
            % replace it with the new one.  All other instances will be
484
 
            % ignored.
485
 
            if isempty(findstr('PsychJava', fileContents{i}))
486
 
                newFileContents{j, 1} = fileContents{i}; %#ok<AGROW>
487
 
                j = j + 1;
488
 
            elseif ~isempty(findstr('PsychJava', fileContents{i})) & ~pathInserted %#ok<AND2>
489
 
                newFileContents{j, 1} = path_PsychJava; %#ok<AGROW>
490
 
                pathInserted = 1;
491
 
                j = j + 1;
492
 
            end
493
 
        end
494
 
 
495
 
        % If the PsychJava path wasn't inserted, then this must be a new
496
 
        % installation, so we append it to the classpath.
497
 
        if ~pathInserted
498
 
            newFileContents{end + 1, 1} = path_PsychJava;
499
 
        end
500
 
 
501
 
        % Now compare to see if the new and old classpath are the same.  If
502
 
        % they are, then there's no need to do anything.
503
 
        updateClasspath = 1;
504
 
        if length(fileContents) == length(newFileContents)
505
 
            if strcmp(fileContents, newFileContents)
506
 
                updateClasspath = 0;
507
 
            end
508
 
        end
509
 
 
510
 
        if updateClasspath
511
 
            % Make a backup of the old classpath.
512
 
            clear madeBackup;
513
 
 
514
 
            [s, w] = copyfile(classpathFile, bakclasspathFile, 'f');
515
 
 
516
 
            if s==0
517
 
                error(['Could not make a backup copy of Matlab''s JAVA path definition file ''classpath.txt''.\n' ...
518
 
                    'The system reports: ', w]);
519
 
            end
520
 
            madeBackup = 1; %#ok<NASGU>
521
 
 
522
 
            % Write out the new contents.
523
 
            FID = fopen(classpathFile, 'w');
524
 
            if FID == -1
525
 
                error('Could not open Matlab''s JAVA path definition file ''classpath.txt'' for write access.');
526
 
            end
527
 
            for i = 1:length(newFileContents)
528
 
                fprintf(FID, '%s\n', newFileContents{i});
529
 
            end
530
 
            fclose(FID);
531
 
 
532
 
            fprintf('\n\n');
533
 
            disp('*** Matlab''s Static Java classpath definition file modified. You will have to restart Matlab to enable use of the new Java components. ***');
534
 
            fprintf('\nPress RETURN or ENTER to confirm you read and understood the above message.\n');
535
 
            pause;
536
 
        end
537
 
    catch
538
 
        lerr = psychlasterror;
539
 
        fprintf('Could not update the Matlab JAVA classpath.txt file due to the following error:\n');
540
 
        fprintf('%s\n\n', lerr.message);
541
 
        fprintf('Either you have a very old Matlab version which does not support JAVA or, most\n');
542
 
        fprintf('likely, you do not have sufficient access permissions for the Matlab application folder\n');
543
 
        fprintf('or file itself to change the file %s .\n', classpathFile);
544
 
        fprintf('Please ask the system administrator to enable write-access to that file and its\n');        
545
 
        fprintf('containing folder and then repeat the update procedure.\n');
546
 
        fprintf('Alternatively, ask the administrator to add the following line:\n');
547
 
        fprintf('%s\n', path_PsychJava);
548
 
        fprintf('to the file: %s\n\n', classpathFile);        
549
 
        fprintf('If you skip this step, Psychtoolbox will still be mostly functional, \n');
550
 
        fprintf('but the Java-based commands ListenChar, CharAvail, GetChar and FlushEvents\n');
551
 
        fprintf('on Linux, MacOS-X and M$-Windows in Java mode will work less efficiently.\n');
552
 
        fprintf('For more info see ''help PsychJavaTrouble''.\n\n');
553
 
        fprintf('\nPress RETURN or ENTER to confirm you read and understood the above message.\n');
554
 
        pause;
555
 
 
556
 
        % Restore the old classpath file if necessary.
557
 
        if exist('madeBackup', 'var')
558
 
            [s, w] = copyfile(bakclasspathFile, classpathFile, 'f'); %#ok<NASGU>
559
 
        end
560
 
    end
561
 
end % if ~IsOctave
 
464
    % Try to setup Matlab static Java class path:
 
465
    PsychJavaTrouble(1);
 
466
end
562
467
 
563
468
% Check if Screen is functional:
564
469
try
596
501
        fprintf('If you receive an installation failure soon, then please read the output of\n');
597
502
        fprintf('"help GStreamer" first and follow the installation instructions for GStreamer\n');
598
503
        fprintf('on Linux. Psychtoolbox''s Screen() command will not work without GStreamer!\n\n');
 
504
 
 
505
        % Additional setup instructions for embedded/mobile devices with ARM cpu required?
 
506
        if IsARM
 
507
            fprintf('Additionally, as this is a device with ARM processor, the helper library\n');
 
508
            fprintf('libwaffle-1.so needs to be installed in a system library folder for Screen\n');
 
509
            fprintf('to work. You can find a copy of the library in the PsychContributed/ArmArch/\n');
 
510
            fprintf('subfolder of your Psychtoolbox main folder. Rename it to libwaffle-1.so.0 during\n');
 
511
            fprintf('the copy.\n');
 
512
            fprintf('Another requirement, at least as of April 2013 and Ubuntu 13.04 for the Nexus-7,\n');
 
513
            fprintf('is that you must start octave from the command line, or via some script, like this:\n');
 
514
            fprintf('LD_PRELOAD=/usr/lib/libGLESv1_CM.so octave\n');
 
515
            fprintf('This is a workaround for a small bug in octave for Nexus-7, which would cause Screen()\n');
 
516
            fprintf('to crash shortly after opening an onscreen window.\n\n');
 
517
            fprintf('\n');
 
518
            fprintf('If you run PTB on the Nexus7 make sure you do not use the "Unity" desktop since\n');
 
519
            fprintf('this might lead to unforeseen problems. Use a desktop without 3D desktop compositor instead.\n');
 
520
            fprintf('E.g. install and use XFCE (sudo apt-get install xfce4).\n');            
 
521
        end
599
522
    end
600
523
 
601
524
    % Check Screen:
602
525
    AssertOpenGL;
603
526
 
604
527
    if IsLinux
605
 
        % Setup Desktop compositor ("Compiz") to un-redirect fullscreen windows.
606
 
        % This allows to bypass desktop composition for PTB fullscreen onscreen windows,
607
 
        % so we get the deterministic timing and high performance we want for visual
608
 
        % stimulus presentation. The command is a no-op 
609
 
        PsychGPUControl('FullScreenWindowDisablesCompositor', 1);
 
528
        % Setup Desktop compositor ("Compiz") to un-redirect fullscreen windows.
 
529
        % This allows to bypass desktop composition for PTB fullscreen onscreen windows,
 
530
        % so we get the deterministic timing and high performance we want for visual
 
531
        % stimulus presentation. The command is a no-op
 
532
        PsychGPUControl('FullScreenWindowDisablesCompositor', 1);
610
533
    end
611
534
 
612
535
    % Try to execute online registration routine: This should be fail-safe in case
620
543
    
621
544
catch
622
545
    fprintf('\n\n');
623
 
    if IsOctave & IsWin %#ok<AND2>
624
 
        % Probably GStreamer runtime dll's missing:
625
 
        fprintf('Screen() or online registration failed to work under MS-Windows with GNU/Octave-3:\n\n');
626
 
        fprintf('Probably the required GStreamer multimedia framework is not yet installed on your system.\n\n');
627
 
        fprintf('Please type ''help GStreamer'' and follow the displayed installation instructions carefully.\n');
628
 
        fprintf('After this one-time setup, the Screen command should work properly.\n\n');
629
 
        fprintf('If this has been ruled out as a reason for failure, check the troubleshooting instructions on\n');
630
 
        fprintf('our Wiki (Download section and FAQ section, maybe also the Bugs section).\n\n');
631
 
    else
632
 
        fprintf('Screen() or online registration failed to work for some reason:\n\n');
633
 
        fprintf('Check the troubleshooting instructions on our Wiki (Download section \n');
634
 
        fprintf('and FAQ section, maybe also the Bugs section).\n\n');
635
 
    end
636
 
    
 
546
    fprintf('Screen() or online registration failed to work for some reason:\n\n');
 
547
    fprintf('Check the troubleshooting instructions on our Wiki (Download section \n');
 
548
    fprintf('and FAQ section, maybe also the Bugs section).\n\n');
637
549
    fprintf('Once you manage to fix the problem (simply type ''AssertOpenGL'' to verify\n');
638
550
    fprintf('that stuff works now), you do not need to run the installation routine again,\n');
639
551
    fprintf('but can start working immediately.\n\n');
648
560
% Run Linux post-configuration script try-catch protected:
649
561
if IsLinux
650
562
    try
651
 
        % This script modifies/extends system configuration files
652
 
        % to optimize the system for use with Psychtoolbox:
 
563
        % This script modifies/extends system configuration files
 
564
        % to optimize the system for use with Psychtoolbox:
653
565
        PsychLinuxConfiguration;
654
566
    catch
655
567
    end
705
617
fprintf('\nEnjoy!\n\n');
706
618
 
707
619
% Clear out everything:
708
 
if ~IsOctave & IsWin %#ok<AND2>
 
620
if IsWin
709
621
    clear all;
710
622
end
711
623