Commit f1fa28bd authored by sstucker's avatar sstucker
Browse files

diffnames setpath utility, getpaths no longer removes atlasviewer folders from path

parent 8ed9587b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ paths_excl_str = {};
if options.conflcheck
        
    % Get all workspace paths that have similar functions sets with current applications
    appmainfunc = {'AtlasViewerGUI.m','Homer2_UI.m','Homer3.m','brainScape.m','AcqDataClass.m'};
    appmainfunc = {'Homer2_UI.m','Homer3.m','brainScape.m'};
    
    kk=1;
    wsidx = [];
+64 −22
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ function setpaths(options_str)
%           {'mvpathconfl','rmpathconfl'}  (default: mvpathconfl) 'conflcheck' option must be selected
%                                                                  for this this option not to be ignored
%           {'quiet','verbose'}            (default: quiet)
%           {'nodiffnames','diffnames'}    (default: nodiffnames) Diffs files that share a name with a file already on the path
%
%
% EXAMPLES:
%
@@ -77,14 +79,45 @@ end
%     end
% end


% Add or remove paths for this application
rootpath = pwd;
rootpath(rootpath=='\')='/';
paths_str = '';

dnum = 0;
diffqueue = {};  % Files to be diff'd

for ii=1:length(paths)
    
    paths{ii} = [rootpath, paths{ii}];
    
    if options.diffnames
        % See if any of the imported functions already exist
        
        files = dir(fullfile(paths{ii},'*.m'));
        
        for f = 1:length(files)
            % When exists returns 2 but excluding the working dir
            if ( (exist(files(f).name(1:end-2),'file') == 2) & (~isequal(files(f).folder,pwd())))
                if options.verbose
                    fprintf("This file shadows one already on the path: %s\n",[files(f).folder '\' files(f).name(1:end-2)]);
                    fprintf("Here is the original: %s\n", which(files(f).name(1:end-2)));
                end
                if (strcmp( fileread([files(f).folder '\' files(f).name]), fileread(which(files(f).name(1:end-2))) ))
                    if options.verbose
                        fprintf("The files are the same.\n");
                    end
                else
                    if options.verbose
                        fprintf("The files have some differences.\n")
                    end
                    dnum = dnum + 1;
                    diffqueue{end+1} = {[files(f).folder '\' files(f).name], which(files(f).name(1:end-2))};
                end
            end
        end
    end
    
    if options.verbose
        if options.add
            fprintf('Adding path %s\n', paths{ii});
@@ -100,14 +133,25 @@ for ii=1:length(paths)
    end
    
    paths_str = [paths_str, delimiter, paths{ii}];
    
end

% If there are different files with same name
if dnum > 0  % True only if options.diffpaths is
    fprintf('There are %i files that shadow different files already on the path.\n', dnum);
    diffchoice = input(sprintf('Would you like to diff them now? y/n '),'s');
    if (size(diffchoice,2) > 0) & ((diffchoice == 'y') | (diffchoice == 'yes'))
        for i = 1:size(diffqueue,2)
            % Use visual diff tool
            visdiff(diffqueue{i}{1}, diffqueue{i}{2});
        end
    end
end

% Add current workspace at the top of the stack of conflicting workspaces
wspaths = [pwd; wspaths];
paths_excl_str = [paths_str, paths_excl_str];


% Either add all conflicting workspaces to the search path or remove the
% current one, depending on user selection
if options.add
@@ -120,8 +164,6 @@ else
end




% ---------------------------------------------------
function idx = findExePaths(paths)