X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcreaDevManagerLib%2FmodelCDMAppli.cpp;fp=lib%2FcreaDevManagerLib%2FmodelCDMAppli.cpp;h=ebd4de0170deefe08dd3e8d453bf5739a1325c44;hb=2b6788596bc21c7942df4b0d6917eaf5b5d72277;hp=ce3388e03d13722a4fc13102569990c566367635;hpb=609d8d48cae96384e664ec6b000e8ecfcbad6459;p=crea.git diff --git a/lib/creaDevManagerLib/modelCDMAppli.cpp b/lib/creaDevManagerLib/modelCDMAppli.cpp index ce3388e..ebd4de0 100644 --- a/lib/creaDevManagerLib/modelCDMAppli.cpp +++ b/lib/creaDevManagerLib/modelCDMAppli.cpp @@ -36,6 +36,7 @@ #include #include +#include #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 checked(this->children.size(), false); + std::vector 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 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; }