+bool modelCDMMain::OpenProject(
+ const std::string& path,
+ std::string*& result
+)
+{
+ //std::cout << "Open selection path: "<< path << std::endl;
+ //get fixed path
+ std::string pathFixed = CDMUtilities::fixPath(path);
+ std::cout << "Opening path: "<< pathFixed << std::endl;
+
+ //check if its binaries' folder
+ bool isBinary = false;
+ std::string pathBuild = "";
+
+ //check if Makefile file exists
+ std::string pathMakefile = pathFixed + CDMUtilities::SLASH + "Makefile";
+ FILE* pFile = fopen(pathMakefile.c_str(), "r");
+
+ //is the binary folder
+ if (pFile != NULL)
+ {
+ fclose(pFile);
+ std::ifstream readFile;
+ readFile.open(pathMakefile.c_str());
+ std::string word;
+
+ while(!isBinary && readFile >> word)
+ {
+ if(word == "CMAKE_SOURCE_DIR")
+ {
+ readFile >> word;
+ readFile.ignore();
+ getline(readFile, word, '\n');
+ pathBuild = pathFixed;
+ pathFixed = CDMUtilities::fixPath(word);
+ isBinary = true;
+ }
+ }
+ readFile.close();
+ }
+
+ //check if its source's folder
+ bool isSource = false;
+ std::string pathSource = "";
+ //check if CMakeLists file exists
+ std::string pathCMakeLists = pathFixed + CDMUtilities::SLASH + "CMakeLists.txt";
+ pFile = fopen(pathCMakeLists.c_str(), "r");
+
+ //is the source folder
+ if (pFile != NULL)
+ {
+ fclose(pFile);
+ std::ifstream readFile;
+ readFile.open(pathCMakeLists.c_str());
+ std::string word;
+
+
+ while(!isSource && !readFile.eof())
+ {
+ std::getline(readFile,word,'(');
+ std::vector<std::string> wordBits;
+ CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
+
+ if(wordBits[wordBits.size()-1] == "PROJECT")
+ {
+ isSource = true;
+ pathSource = pathFixed;
+ }
+ }
+ readFile.close();
+ }
+
+ //if is source folder
+ if(isSource)
+ {
+ if(this->project != NULL)
+ {
+ if (!CloseProject(result))
+ return false;
+ }
+ std::vector<std::string> words;
+ CDMUtilities::splitter::split(words, pathSource, CDMUtilities::SLASH, CDMUtilities::splitter::no_empties);
+
+ std::cout << "Project sources at: " << pathSource << std::endl;
+ if(isBinary)
+ {
+ std::cout << ", and built in: " << pathBuild << std::endl;
+
+ this->project = new modelCDMProject(pathSource, words[words.size()-1], pathBuild);
+ }
+ else
+ {
+ this->project = new modelCDMProject(pathSource, words[words.size()-1]);
+ }
+ }
+ else
+ {
+ result = new std::string("No source folder found. Please make sure to select either the project's build or source folder.");
+ return false;
+ }
+
+ return true;
+}
+
+bool modelCDMMain::RefreshProject(
+ std::string*& result
+)
+{
+ //recreate the project using the project's path
+ if (this->project != NULL)
+ {
+ return this->project->Refresh(result);
+ }
+ else
+ {
+ result = new std::string("There is no open project.");
+ return false;
+ }
+}
+
+std::map<wxTreeItemId, modelCDMIProjectTreeNode*>& modelCDMMain::GetModelElements()
+{
+ return this->modelElements;
+}
+
+bool modelCDMMain::CloseProject(
+ std::string*& result
+)
+{
+ //delete the project tree and leave it as NULL
+ if (this->project != NULL)
+ {
+ delete this->project;
+ this->project = NULL;
+ return true;
+ }
+ else
+ {
+ result = new std::string("There is no open project.");
+ return false;
+ }
+}