]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/modelCDMAppli.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / modelCDMAppli.cpp
index ce3388e03d13722a4fc13102569990c566367635..ebd4de0170deefe08dd3e8d453bf5739a1325c44 100644 (file)
@@ -36,6 +36,7 @@
 
 #include <iostream>
 #include <fstream>
+#include <algorithm>
 
 #include "CDMUtilities.h"
 #include "creaWx.h"
@@ -140,6 +141,116 @@ modelCDMApplication* modelCDMAppli::CreateApplication(
 
 const bool modelCDMAppli::Refresh(std::string*& result)
 {
-  //TODO: implement method
+  std::cout << "refreshing appli" << std::endl;
+  this->type = wxDIR_DIRS;
+  this->name = "appli";
+  this->level = level;
+  this->path = path;
+
+
+
+  std::vector<bool> checked(this->children.size(), false);
+  std::vector<bool> checkedApplications(this->applications.size(), false);
+
+  //check all folders
+  wxDir dir(crea::std2wx((this->path).c_str()));
+  if (dir.IsOpened())
+    {
+      wxString fileName;
+      bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
+      while (cont)
+        {
+          std::string stdfileName = crea::wx2std(fileName);
+          std::string applicationName = stdfileName;
+          //check if they already exist
+          bool found = false;
+          for (int i = 0;!found && i < this->applications.size(); i++)
+            {
+              if (this->applications[i]->GetName() == applicationName)
+                {
+                  found = true;
+                  int pos = std::find(this->children.begin(), this->children.end(), this->applications[i]) - this->children.begin();
+                  checked[pos] = true;
+                  checkedApplications[i] = true;
+                  if(!this->applications[i]->Refresh(result))
+                    return false;
+                }
+            }
+          if(!found)
+            {
+              modelCDMApplication* application= new modelCDMApplication(this->path + "/" + stdfileName, this->level + 1);
+              this->applications.push_back(application);
+              this->children.push_back(application);
+            }
+          cont = dir.GetNext(&fileName);
+        }
+
+      cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
+      while (cont)
+        {
+          std::string stdfileName = crea::wx2std(fileName);
+
+          //if CMakeLists, create CMakeLists
+          if(stdfileName == "CMakeLists.txt")
+            {
+              if (this->CMakeLists == NULL)
+                {
+                  this->CMakeLists = new modelCDMCMakeListsFile(this->path + "/" + stdfileName, this->level + 1);
+                  this->children.push_back(this->CMakeLists);
+                }
+              else
+                {
+                  int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
+                  checked[pos] = true;
+                  if(!this->CMakeLists->Refresh(result))
+                    return false;
+                }
+            }
+          //if is an unknown file, create file
+          else
+            {
+              bool found = false;
+              for (int i = 0; i <!found && this->children.size(); i++)
+                {
+                  if (this->children[i]->GetName() == stdfileName)
+                    {
+                      found = true;
+                      checked[i] = true;
+                      if(!this->children[i]->Refresh(result))
+                        return false;
+                    }
+                }
+
+              if(!found)
+                {
+                  modelCDMFile* file = new modelCDMFile(this->path + "/" + stdfileName, this->level + 1);
+                  this->children.push_back(file);
+                }
+            }
+
+          cont = dir.GetNext(&fileName);
+        }
+    }
+
+  for (int i = 0; i < checkedApplications.size(); i++)
+    {
+      if(!checkedApplications[i])
+        {
+          this->applications.erase(this->applications.begin()+i);
+          checkedApplications.erase(checkedApplications.begin()+i);
+          i--;
+        }
+    }
+  for (int i = 0; i < checked.size(); i++)
+    {
+      if(!checked[i])
+        {
+          delete this->children[i];
+          this->children.erase(this->children.begin()+i);
+          checked.erase(checked.begin()+i);
+          i--;
+        }
+    }
+  this->SortChildren();
   return true;
 }