gusucode.com > appdesigner工具箱matlab源码程序 > appdesigner/+appdesigner/+internal/+application/getAppDesignerAppDependencies.m

    function dependenciesList = getAppDesignerAppDependencies(mlappFileName)
    %GETAPPDESIGNERAPPDEPENDENCIES Return cell array of files the app depends on related to App Designer.

    %   Copyright 2015 The MathWorks, Inc

    dependenciesList = {};
    % Search for App Designer dependencies in the .mlapp file
    
    try
        fileReader = appdesigner.internal.serialization.FileReader(mlappFileName);
         appData = readAppDesignerData(fileReader);
         uiFigure  = appData.UIFigure;
         
        % Delete the loaded window object when finished. Since it's
        % attached to the root it won't be deleted when out of scope.        
        c = onCleanup(@()delete(uiFigure));

        if ~isempty(uiFigure.Children)
            dependenciesList = searchForDependenciesRecursively(uiFigure);
        end  
    catch
        % Catch all exceptions. Caller only gets list of dependencies that were successfully resolved.
    end
end

function newDependenciesList = searchForDependenciesRecursively(obj)
    %SEARCHFORDEPENDENCIESRECURSIVELY Recursively search Children
    % structures for App Designer dependencies

    % Note: currently, the only dependencies that App Designer has are icon
    % files for buttons. 

    newDependenciesList = {};
    for idx=1:length(obj.Children)
        child = obj.Children(idx);
        if isa(child, 'matlab.ui.control.internal.model.mixin.IconableComponent')
            if ~isempty(child.Icon)

                % Skip any files that have problems (e.g. cannot be found 
                % or not an image file).
                try
                    buttonIcon = imfinfo(child.Icon);
                catch
                    continue; % do not include this file in returned list
                end
                
                iconPath = buttonIcon.Filename;
                 % check for and do not add duplicates
                matches = strcmp(iconPath, newDependenciesList);
                if ~any(matches)
                    newDependenciesList = [ newDependenciesList, iconPath ];
                end
            end
        end
        if isprop(child, 'Children')
            childList = searchForDependenciesRecursively(child);
            for childIdx=1:length(childList)
                % check for and do not add duplicates
                matches = strcmp(childList(childIdx), newDependenciesList);
                if ~any(matches)
                    newDependenciesList = [ newDependenciesList, childList(childIdx)];
                end
            end
        end
    end

end