X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcreaDevManagerLib%2FmodelCDMMain.cpp;h=8d69741da2b3d46229e93248e4ae5943355ad256;hb=5a17d994576296f2a5a85f3a01ad5631786a0c56;hp=7b47e90035841b8cafb42d19a26113b6246ba121;hpb=921c85646eb457d9e8cfc1a9031481df176970ce;p=crea.git diff --git a/lib/creaDevManagerLib/modelCDMMain.cpp b/lib/creaDevManagerLib/modelCDMMain.cpp index 7b47e90..8d69741 100644 --- a/lib/creaDevManagerLib/modelCDMMain.cpp +++ b/lib/creaDevManagerLib/modelCDMMain.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -175,20 +176,47 @@ bool modelCDMMain::OpenProject( std::string pathBuild = ""; //check if Makefile file exists +#ifdef _WIN32 + std::string pathMakefile = pathFixed + CDMUtilities::SLASH + "CMakeCache.txt"; + FILE* pFile; + errno_t errorOpen = fopen_s(&pFile, pathMakefile.c_str(), "r"); +#else std::string pathMakefile = pathFixed + CDMUtilities::SLASH + "Makefile"; - FILE* pFile = fopen(pathMakefile.c_str(), "r"); - + FILE* pFile; + pFile = fopen(pathMakefile.c_str(), "r"); + bool errorOpen = (pFile == NULL); +#endif //is the binary folder - if (pFile != NULL) + if (!errorOpen && pFile) { fclose(pFile); std::ifstream readFile; readFile.open(pathMakefile.c_str()); std::string word; + +#ifdef _WIN32 + while(!isBinary && !readFile.eof()) + { + getline(readFile, word, '\n'); + std::vector words; + CDMUtilities::splitter::split(words,word,"=",CDMUtilities::splitter::no_empties); + if(words.size() && words[0] == "CMAKE_HOME_DIRECTORY:INTERNAL") + { + pathBuild = pathFixed; + pathFixed = CDMUtilities::fixPath(words[1]); + for (int i = 0; i < (int)(pathFixed.size()); i++) + { + if (pathFixed[i]=='/') + pathFixed[i]='\\'; + } + isBinary = true; + } + } +#else while(!isBinary && readFile >> word) { - if(word == "CMAKE_SOURCE_DIR") + if(word == "CMAKE_SOURCE_DIR") { readFile >> word; readFile.ignore(); @@ -197,7 +225,8 @@ bool modelCDMMain::OpenProject( pathFixed = CDMUtilities::fixPath(word); isBinary = true; } - } + } +#endif readFile.close(); } @@ -206,10 +235,15 @@ bool modelCDMMain::OpenProject( std::string pathSource = ""; //check if CMakeLists file exists std::string pathCMakeLists = pathFixed + CDMUtilities::SLASH + "CMakeLists.txt"; +#ifdef _WIN32 + errorOpen = fopen_s(&pFile, pathCMakeLists.c_str(), "r"); +#else pFile = fopen(pathCMakeLists.c_str(), "r"); + errorOpen = (pFile == NULL); +#endif //is the source folder - if (pFile != NULL) + if (!errorOpen && pFile) { fclose(pFile); std::ifstream readFile; @@ -257,7 +291,7 @@ bool modelCDMMain::OpenProject( } else { - result = new std::string("No source folder found. Please make sure to select either the project's build or source folder."); + result = new std::string("No source folder found. Please make sure to select either the project's build or source folder. " + pathBuild + pathFixed); return false; } @@ -280,7 +314,7 @@ bool modelCDMMain::RefreshProject( } } -std::map& modelCDMMain::GetModelElements() +std::map& modelCDMMain::GetModelElements() { return this->modelElements; }