function vipgetdemodata(blk,param)
% VIPGETDEMODATA Fetches video data for Computer Vision System Toolbox demos.
% VIPGETDEMODATA(BLK, PARAM) takes in a block name BLK and block parameter 
% name PARAM that specifies the input file name. It then opens up a dialog 
% asking if the file should be downloaded from MathWorks website.

% Copyright 2006 MathWorks, Inc.

%% check if the directory is valid
file_name = get_param(blk, param);
dir_name = fileparts(file_name);
if ~isempty(dir_name)
    if ~isdir(dir_name)
        errStr = sprintf('The directory %s specified by the %s block is invalid.',dir_name, blk);
        errordlg(errStr);
        set_param(gcs, 'SimulationCommand', 'stop');
        return;
    end
end

%% only ask if file is not on the path
if exist(file_name,'file') ~= 2
    button_name = questdlg(sprintf(['This demo requires that you download a video file ',...
                        ' from MathWorks Web site.  Would you like to connect' ,...
                        ' to this Web site?']),...
                           'Download demo files','Yes','No','Help','Yes');
    
    if strcmpi(button_name,'No') || isempty(button_name)
        %% simply stop the model from executing
        set_param(gcs, 'SimulationCommand', 'stop');
    elseif strcmpi(button_name,'Yes')
        lastwarn('');
        try
            web('http://www.mathworks.com/vipdemos','-browser');
        catch browserException
            errordlg(browserException.message);
        end
        
        if (lastwarn)
            errordlg(lastwarn);
        end
        set_param(gcs, 'SimulationCommand', 'stop')
    else
        try
            helpview(fullfile(docroot, 'toolbox', 'vision', 'vision.map'), 'missing_video_file','CSHelpWindow');
        catch %#ok
            eid = 'vipblks:vipgetdemodata:invalidDocroot';
            msg = 'Help not found.  Verify that your docroot is set to a valid location.';
            error(eid,'%s', msg);
        end
        set_param(gcs, 'SimulationCommand', 'stop');
    end
end
