From 5e3e7f0ecbafec9bf30267e2e2cd241dfa3bf1de Mon Sep 17 00:00:00 2001
From: Jan Lemmer <jan.lemmer@fst.tu-darmstadt.de>
Date: Mon, 21 Feb 2022 14:51:15 +0100
Subject: [PATCH] Implements #96

---
 +PlotID/copyUserFCN.m    | 25 +++++++++++++++++++++++++
 +PlotID/createFileCopy.m |  2 ++
 2 files changed, 27 insertions(+)

diff --git a/+PlotID/copyUserFCN.m b/+PlotID/copyUserFCN.m
index 26f5c7b..4525737 100644
--- a/+PlotID/copyUserFCN.m
+++ b/+PlotID/copyUserFCN.m
@@ -1,8 +1,19 @@
 function pList = copyUserFCN(scriptPath, folderName, storPath, ID)
+%COPYUSERFCN copies all user functions, classes and toolboxes that are used
+%by the base script (scriptpath).
+% folderName, storPath and ID are required for createfilecopy
    [fList,pList] = matlab.codetools.requiredFilesAndProducts(scriptPath);
    fList = fList(~ismember(fList,scriptPath)); % rmv plot script itself from list
    fList = fList(~contains(fList,'config.json')); % rmv config.json from list
    fList = removePltIdFiles(fList); % Do not copy files that are part of PlotID
+   
+   % copy Classes and Toolboxes as a whole
+    copyTBorClass(fList,'+', folderName, storPath, ID); % Toolboxes 
+    copyTBorClass(fList,'@', folderName, storPath, ID); % Classes
+    %remove class and toolbox files from flist
+    fList = fList(~contains(fList,{'@','+'}));
+    
+    % copy User FCN
    if ~isempty(fList)
        PlotID.createFileCopy(fList,folderName,storPath,ID,'userFcn');
    end
@@ -32,4 +43,18 @@ function [fListClean] = removePltIdFiles(fList)
     PltID_flist = [packageContent.m; Class_flist]; 
     % Comparison and filter
     fListClean = fList(~ismember(names,PltID_flist));
+end
+
+function [status, msg] = copyTBorClass(fList,leadChar, folderName, storPath, ID)
+%copyTBorClass copies the Toolboxes or Classes that are part of flist 
+% lead char must be either '@' for Classes or '+' for Toolboxes
+if any(contains(fList,leadChar))
+    list = fList(contains(fList, leadChar));
+    names = extractBetween(list,leadChar,filesep);
+    paths = extractBefore(list,strcat(leadChar,names));
+    fullPaths = strcat(paths,strcat(leadChar,names));
+    fullPaths = unique(fullPaths);
+    [~, status, msg] =PlotID.createFileCopy(fullPaths,...
+        folderName,storPath,ID,'class'); 
+end %if
 end
\ No newline at end of file
diff --git a/+PlotID/createFileCopy.m b/+PlotID/createFileCopy.m
index e876e70..10ac4e7 100644
--- a/+PlotID/createFileCopy.m
+++ b/+PlotID/createFileCopy.m
@@ -29,6 +29,8 @@ end
             case 'userFcn'
                 %keep original name
                 newfile = sprintf([name,ext]);
+            case {'class','toolbox'}
+                newfile = name; % copy whole folder
             otherwise 
                 error([type,' is not a valid type for createFileCopy'])
         end %switch 
-- 
GitLab