Commit c640e89a authored by Jay Dubb's avatar Jay Dubb
Browse files

v1.23.4

-- Simplify checking of toolboxes. For instance, we don't need to extra files with file names explicitly referring to 'Homer3' in the filename; this understood for all files under the Homer3 application folder, except the startup file itself Homer3.m.
-- Simplify generic utility function MessageBox.
parent 22edf957
Loading
Loading
Loading
Loading
+1 −49
Original line number Diff line number Diff line
function MessageBox(msg, title, hp)
function MessageBox(msg, title)

if nargin<2
    title = 'MessageBox';
end
if nargin<3
    hp = gcf;
end

% Save original units of parent figure
uf = get(hp, 'units');

% Display message box
hm = msgbox(msg, title);

% set(hm, 'visible','off');
% 
% % Set parent and child figures to same units
% set(hm, 'units', 'pixels');
% set(hp, 'units', 'pixels');
% 
% pm = get(hm, 'position');
% pf = get(hp, 'position');
% 
% % Set new position for our message box in relation to parent figure
% px = (pf(1)+pf(3))-pf(3)*.8;
% py = (pf(2)+pf(4))-pf(4)*.2;
% set(hm, 'position',[px, py, pm(3), pm(4)]);
% set(hm, 'visible','hmon');


% p = get(hm,'position');
% nchar = getMaxLineLength(msg);
% if nchar<40
%     p(3) = p(3)+.3*p(3);
%     hc = get(hm,'children');
% end
% set(hm, 'position',p);


% Set parent figure back to previous units
set(hm, 'units', uf);

% Wait for user to respond before exiting
t = 0;
while ishandles(hm)
@@ -51,17 +17,3 @@ while ishandles(hm)
    end
end



% -------------------------------------------------------------
function maxlen = getMaxLineLength(msg)
maxlen = 0;
lines = str2cell(msg);
for ii=1:length(lines)
    if length(lines{ii})>maxlen
        maxlen=length(lines{ii});
    end
end

+1 −1
Original line number Diff line number Diff line
@@ -2,5 +2,5 @@ function vrnnum = getVernum()

vrnnum{1} = '1';   % Major version #
vrnnum{2} = '23';  % Major sub-version #
vrnnum{3} = '3';   % Minor version #
vrnnum{3} = '4';   % Minor version #
vrnnum{4} = '0';   % Minor sub-version # or patch #: 'p1', 'p2', etc
+159 −12
Original line number Diff line number Diff line
function r = checkToolboxes(toolboxes, app)
function [r, toolboxes] = checkToolboxes(options)
% 
% Syntax:
%   [r, toolboxes] = checkToolboxes()
%   [r, toolboxes] = checkToolboxes(options)
%
% Description:
%   Checks if toolboxes required by Homer3 application in the current
%   folder are installed. It returns 1 if all required toolboxes are
%   installed, 0 if some or all required toolboxes are not installed, and -1
%   if the operation to discover which toolboxes are needed and whether they are 
%   installed failed     

r = true;
%   It first checks for the presense of the toolboxesRequired.txt file
%   for the list of required toolboxes to check for. If this file
%   does not exist, then it prompts the user to generate this file.
% 
%   NOTE: If generating toolboxesRequired.txt, make sure that this is done
%   with a full suite of Matlab toolboxes installed. This is because the discovery 
%   portion will NOT tell you that a toolbox is being used by your code 
%   UNLESS that toolbox is installed. Therefore there is no other way to tell
%   which toolboxes are required other than to first generate toolboxesRequired.txt 
%   in Matlab installation that has all toolboxes. 
%
%   The file toolboxesRequired.txt can be generated by calling checkToolboxes with 
%   the options argument set to 'regeneratelist'. 
%
% Examples:
%
%   [r, toolboxes] = checkToolboxes()
%   [r, toolboxes] = checkToolboxes('regeneratelist')
%
if nargin==0
    options = '';
end

% User might want to regenrate list of toolboxes if new scripts were added
% which might require new toolboxes.
if optionExists(options, 'regeneratelist')
    if exist('./toolboxesRequired.txt', 'file')==2
        delete('./toolboxesRequired.txt');
    end
end

toolboxes = {};

header{1} = sprintf('==============================================\n');
header{2} = sprintf('List of required toolboxes for Homer3:\n');
header{3} = sprintf('==============================================\n');

% Check for presence of file which already has all the toolboxes
if exist('./toolboxesRequired.txt', 'file')==2
    fid = fopen('./toolboxesRequired.txt');
    if(fid > 0)
        for ii=1:length(header)
            fprintf(header{ii});
        end
        kk=1;
        while 1
            line = fgetl(fid);
            if line==-1
                break;
            end
            toolboxes{kk,1} = line; %#ok<*AGROW>
            fprintf('%s\n', toolboxes{kk});
            kk=kk+1;
        end
        fclose(fid);
        fprintf('\n');
        r = toolboxesExist(toolboxes);
        return;
    end
end

if verLessThan('matlab','8.3')
    r = -1;
    return;
end

if ~exist('app','var')
    app = '';
msg{1} = sprintf('Unable to find required toolbox list for the current Matlab release. ');
msg{2} = sprintf('Do you want to run toolbox discovery to determine which are required? ');
msg{3} = sprintf('(It takes 5-10 minutes).');
q = MenuBox([msg{:}], {'YES','NO'});
if q==2
    r = -1;
    return;
elseif q==1
    msg{1} = sprintf('NOTE: Generating a new list of required toolboxes will miss toolboxes that are ');
    msg{2} = sprintf('used by your code unless they are already installed on your computer. '); 
    msg{3} = sprintf('Please make sure that this operation is performed in a Matlab installation with '); 
    msg{4} = sprintf('a full suite (or at least nearly-full suite) of toolboxes. Do you want to proceed?\n');
    q = MenuBox([msg{:}], {'YES','NO'});
    if q==2
        r = -1;
        return;
    end
end

exclList = {};

% Change curr folder to Homer3
currdir = pwd;
cd(strcat(pwd,'\Utils'));
if ~exist('dirnameApp','var') || isempty(dirnameApp)
    dirnameApp = ffpath('setpaths.m');
end
if dirnameApp(length(dirnameApp))~='/' && dirnameApp(length(dirnameApp))~='\'
    dirnameApp(length(dirnameApp)+1)='/';
end
cd(dirnameApp);

% Find all the .m files for Homer3
files = findDotMFiles('.', exclList);
nFiles = length(files);

hwait = waitbar(0, sprintf('Checking toolboxes for %d source files', nFiles));
for ii=1:nFiles
    fprintf('Checking ''%s'' for required toolboxes ...\n', files{ii});
    
    % Searching for Homer3 toolboxes takes a long time, so it was done
    % beforehand and is already included in toolboxes.
    [~,f,~] = fileparts(files{ii});
    if strcmp(f, 'Homer3')
        continue;
    end
    
    [~, q] = matlab.codetools.requiredFilesAndProducts(files{ii});
    for jj=1:length(q)
        if ~strcmpi(q(jj).Name, 'MATLAB')
            if ~strcellfind(toolboxes, q(jj).Name)
                fprintf('Adding ''%s'' to list of required toolboxes\n', q(jj).Name);
                toolboxes{end+1,1} = q(jj).Name;
            end
        end
    end
    waitbar(ii/length(files), hwait, sprintf('Checked %d of %d files', ii, nFiles));
end
close(hwait);
fprintf('\n');

cd(currdir);

fid = fopen('./toolboxesRequired.txt','wt');
for ii=1:length(header)
    fprintf(header{ii});
end
for jj=1:length(toolboxes)
    line = sprintf('%s\n', toolboxes{jj});
    fprintf(fid, line);
    fprintf(line);
end
fprintf('\n');
fclose(fid);

r = toolboxesExist(toolboxes);



% -------------------------------------------------------------------------
function r = toolboxesExist(toolboxes)
r = true;
missing = [];
kk = 1;
for ii=1:length(toolboxes)
@@ -14,17 +167,12 @@ for ii=1:length(toolboxes)
        kk=kk+1;
    end
end

if ~isempty(missing)
    msg1 = sprintf('WARNING: The following matlab toolboxes have not been installed:\n');
    msg2 = sprintf('\n');
    msg3 = '';
    msg4 = sprintf('\n');
    if isempty(app)
    msg5 = sprintf('SOME FUNCTIONS MAY NOT WORK PROPERLY.');
    else
        msg5 = sprintf('SOME FUNCTIONS IN %s MAY NOT WORK PROPERLY.', app);
    end
    for jj=1:length(missing)
        if isempty(msg3)
            msg3 = sprintf('%s\n', toolboxes{missing(jj)});
@@ -32,7 +180,6 @@ if ~isempty(missing)
            msg3 = sprintf('%s%s\n', msg3, toolboxes{missing(jj)});
        end
    end    
    
    msg = [msg1, msg2, msg3, msg4, msg5];
    menu(msg, 'OK');
    r = false;

checkToolboxes_Homer3.m

deleted100644 → 0
+0 −107
Original line number Diff line number Diff line
function [r, toolboxes] = checkToolboxes_Homer3()

toolboxes = {};

header{1} = sprintf('==============================================\n');
header{2} = sprintf('List of required toolboxes for Homer3:\n');
header{3} = sprintf('==============================================\n');

% Check for presence of file which already has all the toolboxes
r = true;
filename = getToolboxListFilename('Homer3');
if exist(filename,'file')==2
    fid = fopen(filename);
    if(fid > 0)
        for ii=1:length(header)
            fprintf(header{ii});
        end
        kk=1;
        while 1
            line = fgetl(fid);
            if line==-1
                break;
            end
            toolboxes{kk} = line;
            fprintf('%s\n', toolboxes{kk});
            kk=kk+1;
        end
        fclose(fid);
        fprintf('\n');
        r = checkToolboxes(toolboxes, 'Homer3');
        return;
    end
end

if verLessThan('matlab','8.3')
    r = 4;
    return;
end

msg{1} = sprintf('Unable to find matching toolbox list for the current Matlab release.\n');
msg{2} = sprintf('Do you want to run toolbox discovery to determine which toolboxes are required?\n');
msg{3} = sprintf('It takes 5-10 minutes.\n');
q = menu([msg{:}], 'YES','NO');
if q==2
    r = 3;
    return;
end

exclList = {};

% Change curr folder to Homer3
currdir = pwd;
cd(strcat(pwd,'\Utils'));
if ~exist('dirnameApp','var') || isempty(dirnameApp)
    dirnameApp = ffpath('setpaths.m');
end
if dirnameApp(length(dirnameApp))~='/' && dirnameApp(length(dirnameApp))~='\'
    dirnameApp(length(dirnameApp)+1)='/';
end
cd(dirnameApp);

% Find all the .m files for Homer3
files = findDotMFiles('.', exclList);
nFiles = length(files);

hwait = waitbar(0, sprintf('Checking toolboxes for %d source files', nFiles));
for ii=1:nFiles
    
    fprintf('Checking ''%s'' for required toolboxes ...\n', files{ii});
    
    % Searching for Homer3 toolboxes takes a long time, so it was done
    % beforehand and is already included in toolboxes.
    [~,f,~] = fileparts(files{ii});
    if strcmp(f, 'Homer3')
        continue;
    end
    
    [~, q] = matlab.codetools.requiredFilesAndProducts(files{ii});
    for jj=1:length(q)
        if ~strcmpi(q(jj).Name, 'MATLAB')
            if ~strcellfind(toolboxes, q(jj).Name)
                fprintf('Adding ''%s'' to list of required toolboxes\n', q(jj).Name);
                toolboxes{end+1} = q(jj).Name;
            end
        end
    end
    waitbar(ii/length(files), hwait, sprintf('Checked %d of %d files', ii, nFiles));
end
close(hwait);
fprintf('\n');

cd(currdir);

fid = fopen(filename,'wt');
for ii=1:length(header)
    fprintf(header{ii});
end
for jj=1:length(toolboxes)
    line = sprintf('%s\n', toolboxes{jj});
    fprintf(fid, line);
    fprintf(line);
end
fprintf('\n');
fclose(fid);

r = checkToolboxes(toolboxes, 'Homer3');

getToolboxListFilename.m

deleted100644 → 0
+0 −15
Original line number Diff line number Diff line
function filenameFinal = getToolboxListFilename(appName)

filenameFinal = '';
        
if isempty(filenameFinal)
    filename = sprintf('./toolboxesRequired_%s.txt', appName);
    if exist(filename, 'file')==2
        filenameFinal = filename;
    end
end

filenameFinal = filename;

end
Loading