function [installer,major,minor,update,platform,list]=mcrinstaller
%MCRINSTALLER Display version and location of available MATLAB Runtime Installers
%
%   This function displays version and location information for the MATLAB Runtime
%   installer corresponding to the current platform. 
%
%   [INSTALLER, MAJOR, MINOR, UPDATE, PLATFORM, LIST] = mcrinstaller;
%
%   INSTALLER: The full path to the installer for the current platform.
%   MAJOR: The major version number of the installer.
%   MINOR: The minor version number of the installer.
%   UPDATE: The update version number of the installer.
%   PLATFORM: The name of the current platform, all uppercase. (The value 
%             returned by UPPER(COMPUTER('arch'))).
%   LIST: A cell array of strings containing the full paths to MATLAB Runtime installers
%         for other platforms. This list is non-empty only in a multi-platform
%         MATLAB installation.
%
%   You must distribute the MATLAB Runtime library to your end 
%   users to enable them to run applications developed with the 
%   MATLAB Compiler.
% 
%   Prebuilt MATLAB Runtime installers for all your licensed platforms ship with the 
%   MATLAB Compiler. 
%
%   Run the DOC command and search for 'MATLAB Runtime Installer' for complete 
%   instructions.

% Copyright 2007-2014 The MathWorks, Inc.

% Locate the MATLAB Runtime installer on this machine
[installer, platform, deploy] = findmcrinstaller;
[major, minor, update] = mcrversion;

if (update==0)
    updateString = '';
else
    updateString = ['.' num2str(update)];
end
versionString = [ num2str(major) '.' num2str(minor) updateString];
disp(getString(message('Compiler:mcrinstaller:mcrVersion',platform, versionString, installer)));
disp(getString(message('Compiler:mcrinstaller:installerLoc',fullfile(deploy, '<ARCH>'))));
list=listmcrinstallers(deploy);
if ~isempty(list)
    disp(getString(message('Compiler:mcrinstaller:fullList')));
    for k=1:numel(list)
        disp(list{k});
    end
    disp(' ');
end
              
if (isempty(javachk('swing')) && desktop('-inuse'))
    disp(getString(message('Compiler:mcrinstaller:readLocalHelp')));
else
    disp(getString(message('Compiler:mcrinstaller:runDocForHelp')));
end

function [installer platform deployDir] = findmcrinstaller
% FINDMCRINSTALLER Return a string containing the location of the MATLAB Runtime installer
    platform = computer('arch');
    deployDir = fullfile(matlabroot, 'toolbox', 'compiler', 'deploy');
    platformDir = fullfile(deployDir, platform);
    platform = upper(platform);
    if ispc
        installer = fullfile(platformDir, 'MCRInstaller.exe');
    elseif ismac
        installer = fullfile(platformDir, 'MCRInstaller.zip');
    else
	installer = fullfile(platformDir, 'MCRInstaller.zip');
    end

function list=listmcrinstallers(deploy)
% LISTMCRINSTALLERS List the available MATLAB Runtime Installers (exclude cur. platform)

list = {};

d = dir(deploy);
for k=1:length(d)
    if (strcmp(d(k).name, '.') || strcmp(d(k).name, '..'))
        continue;
    end
    if (d(k).isdir == true)
    % Look for MCRInstaller.
	mcrinstaller = fullfile(deploy, d(k).name, 'MCRInstaller.*');
        f = dir(mcrinstaller);
        if (~isempty(f))
     	    list{end+1} = fullfile(deploy, d(k).name, f(1).name);
        end
    end
end
