]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/modelCDMPackage.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / modelCDMPackage.cpp
index 8d33e17c72b2c742c53838dee3ea39bf6073ac45..c589a8e5fb7206c676fa00231433139d87a3f241 100644 (file)
 
 #include "modelCDMPackage.h"
 
+#include "creaWx.h"
+#include "wx/dir.h"
+#include "CDMUtilities.h"
+
 modelCDMPackage::modelCDMPackage()
 {
 }
 
+modelCDMPackage::modelCDMPackage(const std::string& path, const int& level)
+{
+  this->type = wxDIR_DIRS;
+  //Get Package Name
+  std::vector<std::string> words;
+  std::string delimiters;
+  //TODO::fix for windows
+  delimiters = "/";
+  CDMUtilities::splitter::split(words, path, delimiters, CDMUtilities::splitter::no_empties);
+  this->name = words[words.size()-1];
+  this->namePackage = this->name;
+  this->level = level;
+  this->path = path;
+
+  //check all folders and files
+  wxDir dir(crea::std2wx((path).c_str()));
+  if (dir.IsOpened())
+    {
+      wxString fileName;
+
+      //folders
+      bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
+      while (cont)
+        {
+          std::string stdfileName = crea::wx2std(fileName);
+          //if src, check for black boxes
+          if(stdfileName == "src")
+            {
+              wxDir srcF(crea::std2wx((path + delimiters + "src").c_str()));
+              if (srcF.IsOpened())
+                {
+                  wxString srcName;
+                  bool innerCont = srcF.GetFirst(&srcName, wxT("*.h"), wxDIR_FILES);
+                  while (innerCont)
+                    {
+                      if(crea::wx2std(srcName.substr(0,2)) == "bb")
+                        {
+                          modelCDMBlackBox* blackbox = new modelCDMBlackBox(crea::wx2std(srcName), path + delimiters + "src", this->level + 1);
+                          this->blackBoxes.push_back(blackbox);
+                          this->children.push_back(blackbox);
+                        }
+                      innerCont = srcF.GetNext(&srcName);
+                    }
+                }
+            }
+          //if is an unknown folder, create folder
+          else
+            {
+              this->children.push_back(new modelCDMFolder(path + delimiters + stdfileName, this->level + 1));
+            }
+          cont = dir.GetNext(&fileName);
+        }
+
+      //files
+      cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
+      while (cont)
+        {
+          std::string stdfileName = crea::wx2std(fileName);
+
+          //if CMakeLists, create CMakeLists
+          if(stdfileName == "CMakeLists.txt")
+            {
+              this->CMakeLists = new modelCDMCMakeListsFile(path + delimiters + stdfileName, this->level + 1);
+              this->children.push_back(this->CMakeLists);
+            }
+          else
+            {
+              this->children.push_back(new modelCDMFile(path + delimiters + stdfileName, this->level + 1));
+            }
+          //if is an unknown file, create file
+          cont = dir.GetNext(&fileName);
+        }
+    }
+  this->SortChildren();
+}
+
 modelCDMPackage::~modelCDMPackage()
 {
 }
 
-const std::string& modelCDMPackage::GetName() const
+const std::string& modelCDMPackage::GetNamePackage() const
 {
-  return this->name;
+  return this->namePackage;
 }
 
 const std::string& modelCDMPackage::GetAuthors() const
@@ -82,7 +162,7 @@ bool modelCDMPackage::SetAuthorsEmail(const std::string& email, std::string*& re
 bool modelCDMPackage::SetVersion(const std::string& version, std::string*& result)
 {
   //TODO: implement method
-    return true;
+  return true;
 }
 
 bool modelCDMPackage::SetDescription(const std::string& description, std::string*& result)