www.gusucode.com > mbc 工具箱 matlab 源码程序 > mbc/mbcuninstalladdon.m

    function [ok, msg]=mbcuninstalladdon(pth, mode)
%MBCUNINSTALLADDON  Uninstall an add-on structure
%
%  [OK, MSG]=MBCUNINSTALLADDON(PATH)  uninstalls the add-on package located in the
%  folder PATH.  This includes removing it from the path.

%  OK=MBCUNINSTALLADDON(PATH, MODE) allows user to control whether the path
%  is made persistent via savepath of not. MODE can be -savepath or -nosave

%  Copyright 2000-2014 The MathWorks, Inc. and Ford Global Technologies, Inc.


ok = 0;
msg = '';

% default behaviour is to savepath
validmodes = {'-savepath', '-nosave'};
if nargin==1
    mode = validmodes{1};
elseif ~any(strcmpi(validmodes, mode))
    error(message('mbc:mbcinstalladdon:InvalidArgument1', validmodes{ 1 }, validmodes{ 2 }));
end

def_file = fullfile(pth,'mbcextras.mbc');
if exist(def_file,'file')
    try
        S = load(def_file,'-mat');
    catch
        ok = 0;
        msg = 'The addon definition file is not a valid MATLAB file.';
        return
    end
    if isfield(S,'MBC_EXTENSION_PACKAGE')
        if S.MBC_EXTENSION_PACKAGE
            % Execute uninstall function
            if isfield(S, 'UninstallFcn') && ~isempty(S.UninstallFcn)
                try
                    feval(S.UninstallFcn);
                catch
                    ok = 0;
                    msg = 'The custom uninstallation function caused an error.';
                    return
                end
            end
            
            % remove from path
            if ~isempty(S.Path)
                rm_pth = cell(size(S.Path));
                for n=1:length(S.Path)
                    rm_pth{n} = fullfile(pth, S.Path{n});
                end
                rmpath(rm_pth{:});
                if strcmpi(mode, '-savepath')
                    savepath;
                end
            end
            ok = 1;
            
            % update information about extensions
            mbcextensions.Extensions.update;
        end
    end
else
    msg = 'The specified addon definition file does not exist.';
end