X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcreaDevManagerLib%2FmodelCDMPackage.cpp;h=82a514c3f0d354d32af72758108fd201ad364dad;hb=2b6788596bc21c7942df4b0d6917eaf5b5d72277;hp=9ec218a6817fd7fa3e59fc144d1bc8d71059d61e;hpb=609d8d48cae96384e664ec6b000e8ecfcbad6459;p=crea.git diff --git a/lib/creaDevManagerLib/modelCDMPackage.cpp b/lib/creaDevManagerLib/modelCDMPackage.cpp index 9ec218a..82a514c 100644 --- a/lib/creaDevManagerLib/modelCDMPackage.cpp +++ b/lib/creaDevManagerLib/modelCDMPackage.cpp @@ -35,6 +35,7 @@ #include "modelCDMPackage.h" #include +#include #include "creaWx.h" #include "wx/dir.h" @@ -382,6 +383,229 @@ bool modelCDMPackage::CreateBlackBox( const bool modelCDMPackage::Refresh(std::string*& result) { - //TODO: implement method + std::cout << "refreshing package" << std::endl; + this->type = wxDIR_DIRS; + this->name = name; + this->level = level; + this->path = path; + + //Get Package Name + + //TODO: set pathMakeLists for windows + std::string pathMakeLists = path + "/CMakeLists.txt"; + + std::ifstream confFile; + confFile.open((pathMakeLists).c_str()); + + std::string word; + while(confFile.is_open() && !confFile.eof()) + { + //get sets + std::getline(confFile,word,'('); + std::vector wordBits; + CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties); + + if(wordBits[wordBits.size()-1] == "SET") + { + //get package name + std::getline(confFile,word,')'); + CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties); + if(wordBits[0] == "BBTK_PACKAGE_NAME") + { + word = wordBits[1]; + for (int i = 2; i < wordBits.size(); i++) + { + word += " " + wordBits[i]; + } + wordBits.clear(); + CDMUtilities::splitter::split(wordBits, word, "\"", CDMUtilities::splitter::no_empties); + + this->namePackage = wordBits[0]; + } + else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_AUTHOR") + { + word = wordBits[1]; + for (int i = 2; i < wordBits.size(); i++) + { + word += " " + wordBits[i]; + } + wordBits.clear(); + CDMUtilities::splitter::split(wordBits, word, "\"", CDMUtilities::splitter::no_empties); + + this->authors = wordBits[0]; + } + else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_DESCRIPTION") + { + word = wordBits[1]; + for (int i = 2; i < wordBits.size(); i++) + { + word += " " + wordBits[i]; + } + wordBits.clear(); + CDMUtilities::splitter::split(wordBits, word, "\"", CDMUtilities::splitter::no_empties); + + this->description = wordBits[0]; + } + else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_MAJOR_VERSION") + { + this->version = wordBits[1]; + } + else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_MINOR_VERSION") + { + this->version += "." + wordBits[1]; + } + else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_BUILD_VERSION") + { + this->version += "." + wordBits[1]; + } + } + } + + + + std::vector checked(this->children.size(), false); + std::vector checkedBlackBoxes(this->blackBoxes.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); + + + if(stdfileName == "src") + { + wxDir srcF(crea::std2wx((path + "/" + "src").c_str())); + if (srcF.IsOpened()) + { + wxString srcName; + bool innerCont = srcF.GetFirst(&srcName, wxT("*.h"), wxDIR_FILES); + while (innerCont) + { + std::string blackBoxName = crea::wx2std(srcName); + if(crea::wx2std(srcName.substr(0,2)) == "bb") + { + //check if box already exist + bool found = false; + for (int i = 0;!found && i < this->blackBoxes.size(); i++) + { + if (this->blackBoxes[i]->GetName() == blackBoxName) + { + found = true; + int pos = std::find(this->children.begin(), this->children.end(), this->blackBoxes[i]) - this->children.begin(); + checked[pos] = true; + checkedBlackBoxes[i] = true; + if(!this->blackBoxes[i]->Refresh(result)) + return false; + } + } + if(!found) + { + modelCDMBlackBox* blackBox = new modelCDMBlackBox(blackBoxName, path + "/" + "src", this->level +1); + this->blackBoxes.push_back(blackBox); + this->children.push_back(blackBox); + } + } + innerCont = srcF.GetNext(&srcName); + } + } + + } + //if not src + else + { + //check if they already exist + bool found = false; + for (int i = 0;!found && i < 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) + { + modelCDMFolder* folder = new modelCDMFolder(this->path + "/" + stdfileName, this->level + 1); + this->children.push_back(folder); + } + 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 < checkedBlackBoxes.size(); i++) + { + if(!checkedBlackBoxes[i]) + { + this->blackBoxes.erase(this->blackBoxes.begin()+i); + checkedBlackBoxes.erase(checkedBlackBoxes.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; }