]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/modelCDMApplication.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / modelCDMApplication.cpp
index c39b48d769677ca311727fe391180d14aa109244..e8af2cf6649aac6d578c2972aa63146c34aea20e 100644 (file)
@@ -45,25 +45,18 @@ modelCDMApplication::modelCDMApplication()
 {
 }
 
-modelCDMApplication::modelCDMApplication(const std::string& path, const int& level)
+modelCDMApplication::modelCDMApplication(const std::string& path, const std::string& name, const int& level)
 {
   //folder name
-  std::vector<std::string> words;
-  std::string delimiters;
-  //TODO::fix for windows
-  delimiters = "/";
-  CDMUtilities::splitter::split(words, path, delimiters, CDMUtilities::splitter::no_empties);
-  this->name = words[words.size()-1];
-
+  this->name = name;
   //path
   this->path = CDMUtilities::fixPath(path);
   //type
   this->type = wxDIR_DIRS;
   //level
   this->level = level;
-
   //open CMakeList
-  std::string pathMakeLists = path + "/CMakeLists.txt";
+  std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt";
 
   std::ifstream confFile;
   confFile.open((pathMakeLists).c_str());
@@ -89,7 +82,7 @@ modelCDMApplication::modelCDMApplication(const std::string& path, const int& lev
                   word += " " + wordBits[i];
                 }
 
-              this->nameApplication = this->executableName = word;
+              this->executableName = word;
             }
         }
     }
@@ -108,7 +101,7 @@ modelCDMApplication::modelCDMApplication(const std::string& path, const int& lev
         {
           std::string stdfileName = crea::wx2std(fileName);
 
-          modelCDMFolder* folder = new modelCDMFolder(this->path + "/" + stdfileName, this->level + 1);
+          modelCDMFolder* folder = new modelCDMFolder(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
           this->folders.push_back(folder);
           this->children.push_back(folder);
 
@@ -123,13 +116,13 @@ modelCDMApplication::modelCDMApplication(const std::string& path, const int& lev
           //if CMakeLists, create CMakeLists
           if(stdfileName == "CMakeLists.txt")
             {
-              this->CMakeLists = new modelCDMCMakeListsFile(this->path + "/" + stdfileName, this->level + 1);
+              this->CMakeLists = new modelCDMCMakeListsFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
               this->children.push_back(this->CMakeLists);
             }
           //if is an unknown file, create file
           else
             {
-              this->children.push_back(new modelCDMFile(this->path + "/" + stdfileName, this->level + 1));
+              this->children.push_back(new modelCDMFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
             }
 
           cont = dir.GetNext(&fileName);
@@ -142,11 +135,6 @@ modelCDMApplication::~modelCDMApplication()
 {
 }
 
-const std::string& modelCDMApplication::GetNameApplication() const
-{
-  return this->nameApplication;
-}
-
 const std::string& modelCDMApplication::GetExecutableName() const
 {
   return this->executableName;
@@ -164,14 +152,14 @@ bool modelCDMApplication::SetExecutableName(const std::string& fileName, std::st
 
   std::string line;
   //opening original cmakelists
-  std::ifstream in((this->path + "/CMakeLists.txt").c_str());
+  std::ifstream in((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str());
   if( !in.is_open())
     {
       result = new std::string("CMakeLists.txt file failed to open.");
       return false;
     }
   //opening temporal cmakelists
-  std::ofstream out((this->path + "/CMakeLists.txt.tmp").c_str());
+  std::ofstream out((this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str());
   if( !out.is_open())
     {
       result = new std::string("CMakeLists.txt.tmp file failed to open.");
@@ -187,27 +175,27 @@ bool modelCDMApplication::SetExecutableName(const std::string& fileName, std::st
   in.close();
   out.close();
   //delete old file and rename new file
-  std::string renameCommand = "mv " + this->path + "/CMakeLists.txt.tmp " + this->path + "/CMakeLists.txt";
+  std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
   if(system(renameCommand.c_str()))
     {
       result = new std::string("An error occurred while running '" + renameCommand + "'.");
       return false;
     }
 
-  this->executableName = this->nameApplication = fileNameReal;
+  this->executableName = fileNameReal;
   return true;
 }
 
 modelCDMFolder* modelCDMApplication::CreateFolder(const std::string& name, std::string*& result)
 {
   //TODO:: mkdir depending on OS
-  std::string command = "mkdir " + path + "/" + name;
+  std::string command = "mkdir " + path + CDMUtilities::SLASH + name;
   if(system(command.c_str()))
     {
       result = new std::string("Error executing: " + command + ".");
       return NULL;
     }
-  modelCDMFolder* folder = new modelCDMFolder(path + "/" + name, level + 1);
+  modelCDMFolder* folder = new modelCDMFolder(path + CDMUtilities::SLASH + name, name, level + 1);
   this->folders.push_back(folder);
   this->children.push_back(folder);
 
@@ -220,7 +208,7 @@ const bool modelCDMApplication::Refresh(std::string*& result)
   this->type = wxDIR_DIRS;
 
   //open CMakeList
-  std::string pathMakeLists = path + "/CMakeLists.txt";
+  std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt";
 
   std::ifstream confFile;
   confFile.open((pathMakeLists).c_str());
@@ -235,10 +223,10 @@ const bool modelCDMApplication::Refresh(std::string*& result)
 
       if(wordBits[wordBits.size()-1] == "SET")
         {
-          //get library name
+          //get app name
           std::getline(confFile,word,')');
           CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
-          if(wordBits[0] == "LIBRARY_NAME")
+          if(wordBits[0] == "EXE_NAME")
             {
               word = wordBits[1];
               for (int i = 2; i < wordBits.size(); i++)
@@ -246,7 +234,7 @@ const bool modelCDMApplication::Refresh(std::string*& result)
                   word += " " + wordBits[i];
                 }
 
-              this->nameApplication = this->executableName = word;
+              this->executableName = word;
             }
         }
     }
@@ -283,7 +271,7 @@ const bool modelCDMApplication::Refresh(std::string*& result)
             }
           if(!found)
             {
-              modelCDMFolder* folder = new modelCDMFolder(this->path + "/" + stdfileName, this->level + 1);
+              modelCDMFolder* folder = new modelCDMFolder(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
               this->folders.push_back(folder);
               this->children.push_back(folder);
             }
@@ -300,7 +288,7 @@ const bool modelCDMApplication::Refresh(std::string*& result)
             {
               if (this->CMakeLists == NULL)
                 {
-                  this->CMakeLists = new modelCDMCMakeListsFile(this->path + "/" + stdfileName, this->level + 1);
+                  this->CMakeLists = new modelCDMCMakeListsFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
                   this->children.push_back(this->CMakeLists);
                 }
               else
@@ -328,7 +316,7 @@ const bool modelCDMApplication::Refresh(std::string*& result)
 
               if(!found)
                 {
-                  modelCDMFile* file = new modelCDMFile(this->path + "/" + stdfileName, this->level + 1);
+                  modelCDMFile* file = new modelCDMFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
                   this->children.push_back(file);
                 }
             }