]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/modelCDMLibrary.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / modelCDMLibrary.cpp
index 560759e02a300eea0aeb851863020623b0ac2508..e16eeae0d0d32e4f1f053dde796ada9f0276abb3 100644 (file)
@@ -45,16 +45,10 @@ modelCDMLibrary::modelCDMLibrary()
 {
 }
 
-modelCDMLibrary::modelCDMLibrary(const std::string& path, const int& level)
+modelCDMLibrary::modelCDMLibrary(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
@@ -63,7 +57,7 @@ modelCDMLibrary::modelCDMLibrary(const std::string& path, const int& 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());
@@ -109,7 +103,7 @@ modelCDMLibrary::modelCDMLibrary(const std::string& path, const int& level)
         {
           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);
 
@@ -124,13 +118,13 @@ modelCDMLibrary::modelCDMLibrary(const std::string& path, const int& level)
           //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);
@@ -160,14 +154,14 @@ bool modelCDMLibrary::SetNameLibrary(const std::string& fileName, std::string*&
 
   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.");
@@ -183,7 +177,7 @@ bool modelCDMLibrary::SetNameLibrary(const std::string& fileName, std::string*&
   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 + "'.");
@@ -197,13 +191,13 @@ bool modelCDMLibrary::SetNameLibrary(const std::string& fileName, std::string*&
 modelCDMFolder* modelCDMLibrary::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);
 
@@ -216,7 +210,7 @@ const bool modelCDMLibrary::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());
@@ -279,7 +273,7 @@ const bool modelCDMLibrary::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);
             }
@@ -296,7 +290,7 @@ const bool modelCDMLibrary::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
@@ -324,7 +318,7 @@ const bool modelCDMLibrary::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);
                 }
             }